aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.SQLite/SQLiteBase.cs
diff options
context:
space:
mode:
authorlbsa712007-10-30 09:05:31 +0000
committerlbsa712007-10-30 09:05:31 +0000
commit67e12b95ea7b68f4904a7484d77ecfd787d16d0c (patch)
tree20b00d24c8a7617017960432ec044852e3ad5fa9 /OpenSim/Framework/Data.SQLite/SQLiteBase.cs
parent* Deleted .user file (diff)
downloadopensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.zip
opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.gz
opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.bz2
opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.xz
* Optimized usings
* Shortened type references * Removed redundant 'this' qualifier
Diffstat (limited to 'OpenSim/Framework/Data.SQLite/SQLiteBase.cs')
-rw-r--r--OpenSim/Framework/Data.SQLite/SQLiteBase.cs102
1 files changed, 67 insertions, 35 deletions
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteBase.cs b/OpenSim/Framework/Data.SQLite/SQLiteBase.cs
index 4f237fd..157b4e6 100644
--- a/OpenSim/Framework/Data.SQLite/SQLiteBase.cs
+++ b/OpenSim/Framework/Data.SQLite/SQLiteBase.cs
@@ -26,13 +26,8 @@
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.IO;
30using libsecondlife;
31using OpenSim.Framework;
32using System.Data; 29using System.Data;
33using System.Data.SqlTypes;
34using Mono.Data.SqliteClient; 30using Mono.Data.SqliteClient;
35using OpenSim.Framework.Console;
36 31
37namespace OpenSim.Framework.Data.SQLite 32namespace OpenSim.Framework.Data.SQLite
38{ 33{
@@ -48,8 +43,8 @@ namespace OpenSim.Framework.Data.SQLite
48 * This should be db agnostic as we define them in ADO.NET terms 43 * This should be db agnostic as we define them in ADO.NET terms
49 * 44 *
50 **********************************************************************/ 45 **********************************************************************/
51 46
52 protected static void createCol(DataTable dt, string name, System.Type type) 47 protected static void createCol(DataTable dt, string name, Type type)
53 { 48 {
54 DataColumn col = new DataColumn(name, type); 49 DataColumn col = new DataColumn(name, type);
55 dt.Columns.Add(col); 50 dt.Columns.Add(col);
@@ -77,7 +72,8 @@ namespace OpenSim.Framework.Data.SQLite
77 * generate these strings instead of typing them out. 72 * generate these strings instead of typing them out.
78 */ 73 */
79 string[] cols = new string[dt.Columns.Count]; 74 string[] cols = new string[dt.Columns.Count];
80 for (int i = 0; i < dt.Columns.Count; i++) { 75 for (int i = 0; i < dt.Columns.Count; i++)
76 {
81 DataColumn col = dt.Columns[i]; 77 DataColumn col = dt.Columns[i];
82 cols[i] = col.ColumnName; 78 cols[i] = col.ColumnName;
83 } 79 }
@@ -92,7 +88,7 @@ namespace OpenSim.Framework.Data.SQLite
92 88
93 // this provides the binding for all our parameters, so 89 // this provides the binding for all our parameters, so
94 // much less code than it used to be 90 // much less code than it used to be
95 foreach (DataColumn col in dt.Columns) 91 foreach (DataColumn col in dt.Columns)
96 { 92 {
97 cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType)); 93 cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
98 } 94 }
@@ -106,7 +102,8 @@ namespace OpenSim.Framework.Data.SQLite
106 foreach (DataColumn col in dt.Columns) 102 foreach (DataColumn col in dt.Columns)
107 { 103 {
108 if (subsql.Length > 0) 104 if (subsql.Length > 0)
109 { // a map function would rock so much here 105 {
106 // a map function would rock so much here
110 subsql += ", "; 107 subsql += ", ";
111 } 108 }
112 subsql += col.ColumnName + "= :" + col.ColumnName; 109 subsql += col.ColumnName + "= :" + col.ColumnName;
@@ -118,7 +115,7 @@ namespace OpenSim.Framework.Data.SQLite
118 // this provides the binding for all our parameters, so 115 // this provides the binding for all our parameters, so
119 // much less code than it used to be 116 // much less code than it used to be
120 117
121 foreach (DataColumn col in dt.Columns) 118 foreach (DataColumn col in dt.Columns)
122 { 119 {
123 cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType)); 120 cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
124 } 121 }
@@ -133,11 +130,12 @@ namespace OpenSim.Framework.Data.SQLite
133 foreach (DataColumn col in dt.Columns) 130 foreach (DataColumn col in dt.Columns)
134 { 131 {
135 if (subsql.Length > 0) 132 if (subsql.Length > 0)
136 { // a map function would rock so much here 133 {
134 // a map function would rock so much here
137 subsql += ",\n"; 135 subsql += ",\n";
138 } 136 }
139 subsql += col.ColumnName + " " + sqliteType(col.DataType); 137 subsql += col.ColumnName + " " + sqliteType(col.DataType);
140 if(col == dt.PrimaryKey[0]) 138 if (col == dt.PrimaryKey[0])
141 { 139 {
142 subsql += " primary key"; 140 subsql += " primary key";
143 } 141 }
@@ -167,7 +165,7 @@ namespace OpenSim.Framework.Data.SQLite
167 /// for us. 165 /// for us.
168 ///</summary> 166 ///</summary>
169 ///<returns>a built sqlite parameter</returns> 167 ///<returns>a built sqlite parameter</returns>
170 protected static SqliteParameter createSqliteParameter(string name, System.Type type) 168 protected static SqliteParameter createSqliteParameter(string name, Type type)
171 { 169 {
172 SqliteParameter param = new SqliteParameter(); 170 SqliteParameter param = new SqliteParameter();
173 param.ParameterName = ":" + name; 171 param.ParameterName = ":" + name;
@@ -182,53 +180,87 @@ namespace OpenSim.Framework.Data.SQLite
182 * Type conversion functions 180 * Type conversion functions
183 * 181 *
184 **********************************************************************/ 182 **********************************************************************/
185 183
186 protected static DbType dbtypeFromType(Type type) 184 protected static DbType dbtypeFromType(Type type)
187 { 185 {
188 if (type == typeof(System.String)) { 186 if (type == typeof (String))
187 {
189 return DbType.String; 188 return DbType.String;
190 } else if (type == typeof(System.Int32)) { 189 }
190 else if (type == typeof (Int32))
191 {
191 return DbType.Int32; 192 return DbType.Int32;
192 } else if (type == typeof(System.UInt32)) { 193 }
194 else if (type == typeof (UInt32))
195 {
193 return DbType.UInt32; 196 return DbType.UInt32;
194 } else if (type == typeof(System.Int64)) { 197 }
198 else if (type == typeof (Int64))
199 {
195 return DbType.Int64; 200 return DbType.Int64;
196 } else if (type == typeof(System.UInt64)) { 201 }
202 else if (type == typeof (UInt64))
203 {
197 return DbType.UInt64; 204 return DbType.UInt64;
198 } else if (type == typeof(System.Double)) { 205 }
206 else if (type == typeof (Double))
207 {
199 return DbType.Double; 208 return DbType.Double;
200 } else if (type == typeof(System.Boolean)) { 209 }
210 else if (type == typeof (Boolean))
211 {
201 return DbType.Boolean; 212 return DbType.Boolean;
202 } else if (type == typeof(System.Byte[])) { 213 }
214 else if (type == typeof (Byte[]))
215 {
203 return DbType.Binary; 216 return DbType.Binary;
204 } else { 217 }
218 else
219 {
205 return DbType.String; 220 return DbType.String;
206 } 221 }
207 } 222 }
208 223
209 // this is something we'll need to implement for each db 224 // this is something we'll need to implement for each db
210 // slightly differently. 225 // slightly differently.
211 protected static string sqliteType(Type type) 226 protected static string sqliteType(Type type)
212 { 227 {
213 if (type == typeof(System.String)) { 228 if (type == typeof (String))
229 {
214 return "varchar(255)"; 230 return "varchar(255)";
215 } else if (type == typeof(System.Int32)) { 231 }
232 else if (type == typeof (Int32))
233 {
216 return "integer"; 234 return "integer";
217 } else if (type == typeof(System.UInt32)) { 235 }
236 else if (type == typeof (UInt32))
237 {
218 return "integer"; 238 return "integer";
219 } else if (type == typeof(System.Int64)) { 239 }
240 else if (type == typeof (Int64))
241 {
220 return "varchar(255)"; 242 return "varchar(255)";
221 } else if (type == typeof(System.UInt64)) { 243 }
244 else if (type == typeof (UInt64))
245 {
222 return "varchar(255)"; 246 return "varchar(255)";
223 } else if (type == typeof(System.Double)) { 247 }
248 else if (type == typeof (Double))
249 {
224 return "float"; 250 return "float";
225 } else if (type == typeof(System.Boolean)) { 251 }
252 else if (type == typeof (Boolean))
253 {
226 return "integer"; 254 return "integer";
227 } else if (type == typeof(System.Byte[])) { 255 }
256 else if (type == typeof (Byte[]))
257 {
228 return "blob"; 258 return "blob";
229 } else { 259 }
260 else
261 {
230 return "string"; 262 return "string";
231 } 263 }
232 } 264 }
233 } 265 }
234} 266} \ No newline at end of file