sbSQLUpdateBuilder.cpp
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
27 #include "sbSQLUpdateBuilder.h"
28 #include "sbSQLWhereBuilder.h"
29 
33 
35 {
36 }
37 
38 NS_IMETHODIMP
39 sbSQLUpdateBuilder::GetTableName(nsAString& aTableName)
40 {
41  aTableName = mTableName;
42  return NS_OK;
43 }
44 NS_IMETHODIMP
45 sbSQLUpdateBuilder::SetTableName(const nsAString& aTableName)
46 {
47  mTableName = aTableName;
48  return NS_OK;
49 }
50 
51 NS_IMETHODIMP
52 sbSQLUpdateBuilder::AddAssignmentString(const nsAString& aColumnName,
53  const nsAString& aValue)
54 {
55  Assignment* a = mAssignments.AppendElement();
56  NS_ENSURE_TRUE(a, NS_ERROR_OUT_OF_MEMORY);
57 
58  a->type = eString;
59  a->columnName = aColumnName;
60  a->stringValue = aValue;
61 
62  return NS_OK;
63 }
64 
65 NS_IMETHODIMP
66 sbSQLUpdateBuilder::AddAssignmentParameter(const nsAString& aColumnName)
67 {
68  Assignment* a = mAssignments.AppendElement();
69  NS_ENSURE_TRUE(a, NS_ERROR_OUT_OF_MEMORY);
70 
71  a->type = eParameter;
72  a->columnName = aColumnName;
73 
74  return NS_OK;
75 }
76 
77 NS_IMETHODIMP
79 {
81  mTableName.Truncate();
82  mAssignments.Clear();
83  return NS_OK;
84 }
85 
86 NS_IMETHODIMP
87 sbSQLUpdateBuilder::ToString(nsAString& _retval)
88 {
89  nsresult rv;
90  nsAutoString buff;
91 
92  buff.AssignLiteral("update ");
93 
94  buff.Append(mTableName);
95 
96  buff.AppendLiteral(" set ");
97 
98  PRUint32 len = mAssignments.Length();
99  for (PRUint32 i = 0; i < len; i++) {
100  const Assignment& a = mAssignments[i];
101 
102  buff.Append(a.columnName);
103  buff.AppendLiteral(" = ");
104 
105  switch(a.type) {
106  case eIsNull:
107  buff.AppendLiteral("null");
108  break;
109  case eString:
110  {
111  nsAutoString escapedValue(a.stringValue);
112  SB_EscapeSQL(escapedValue);
113 
114  buff.AppendLiteral("'");
115  buff.Append(escapedValue);
116  buff.AppendLiteral("'");
117  break;
118  }
119  case eInteger32:
120  buff.AppendInt(a.int32Value);
121  break;
122  case eParameter:
123  buff.AppendLiteral("?");
124  break;
125  }
126 
127  if (i + 1 < len) {
128  buff.AppendLiteral(", ");
129  }
130  }
131 
132  rv = AppendWhere(buff);
133  NS_ENSURE_SUCCESS(rv, rv);
134 
135  _retval.Assign(buff);
136  return NS_OK;
137 }
138 
return NS_OK
NS_DECL_SBISQLUPDATEBUILDER NS_IMETHOD ToString(nsAString &_result)
onPageChanged aValue
Definition: FeedWriter.js:1395
NS_IMPL_ISUPPORTS_INHERITED1(sbSQLUpdateBuilder, sbSQLWhereBuilder, sbISQLUpdateBuilder) sbSQLUpdateBuilder
nsresult SB_EscapeSQL(nsAString &str)
nsresult AppendWhere(nsAString &aBuffer)
Interface for building UPDATE statements.
_getSelectedPageStyle s i