aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.SQLite
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
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')
-rw-r--r--OpenSim/Framework/Data.SQLite/Properties/AssemblyInfo.cs31
-rw-r--r--OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs125
-rw-r--r--OpenSim/Framework/Data.SQLite/SQLiteBase.cs102
-rw-r--r--OpenSim/Framework/Data.SQLite/SQLiteGridData.cs2
-rw-r--r--OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs189
-rw-r--r--OpenSim/Framework/Data.SQLite/SQLiteManager.cs132
-rw-r--r--OpenSim/Framework/Data.SQLite/SQLiteUserData.cs261
7 files changed, 458 insertions, 384 deletions
diff --git a/OpenSim/Framework/Data.SQLite/Properties/AssemblyInfo.cs b/OpenSim/Framework/Data.SQLite/Properties/AssemblyInfo.cs
index 75bb53d..6693c98 100644
--- a/OpenSim/Framework/Data.SQLite/Properties/AssemblyInfo.cs
+++ b/OpenSim/Framework/Data.SQLite/Properties/AssemblyInfo.cs
@@ -1,24 +1,28 @@
1using System.Reflection; 1using System.Reflection;
2using System.Runtime.InteropServices; 2using System.Runtime.InteropServices;
3
3// General Information about an assembly is controlled through the following 4// General Information about an assembly is controlled through the following
4// set of attributes. Change these attribute values to modify the information 5// set of attributes. Change these attribute values to modify the information
5// associated with an assembly. 6// associated with an assembly.
6[assembly: AssemblyTitle("OpenSim.Framework.Data.SQLite")] 7
7[assembly: AssemblyDescription("")] 8[assembly : AssemblyTitle("OpenSim.Framework.Data.SQLite")]
8[assembly: AssemblyConfiguration("")] 9[assembly : AssemblyDescription("")]
9[assembly: AssemblyCompany("")] 10[assembly : AssemblyConfiguration("")]
10[assembly: AssemblyProduct("OpenSim.Framework.Data.SQLite")] 11[assembly : AssemblyCompany("")]
11[assembly: AssemblyCopyright("Copyright © 2007")] 12[assembly : AssemblyProduct("OpenSim.Framework.Data.SQLite")]
12[assembly: AssemblyTrademark("")] 13[assembly : AssemblyCopyright("Copyright © 2007")]
13[assembly: AssemblyCulture("")] 14[assembly : AssemblyTrademark("")]
15[assembly : AssemblyCulture("")]
14 16
15// Setting ComVisible to false makes the types in this assembly not visible 17// Setting ComVisible to false makes the types in this assembly not visible
16// to COM components. If you need to access a type in this assembly from 18// to COM components. If you need to access a type in this assembly from
17// COM, set the ComVisible attribute to true on that type. 19// COM, set the ComVisible attribute to true on that type.
18[assembly: ComVisible(false)] 20
21[assembly : ComVisible(false)]
19 22
20// The following GUID is for the ID of the typelib if this project is exposed to COM 23// The following GUID is for the ID of the typelib if this project is exposed to COM
21[assembly: Guid("6113d5ce-4547-49f4-9236-0dcc503457b1")] 24
25[assembly : Guid("6113d5ce-4547-49f4-9236-0dcc503457b1")]
22 26
23// Version information for an assembly consists of the following four values: 27// Version information for an assembly consists of the following four values:
24// 28//
@@ -29,5 +33,6 @@ using System.Runtime.InteropServices;
29// 33//
30// You can specify all the values or you can default the Revision and Build Numbers 34// You can specify all the values or you can default the Revision and Build Numbers
31// by using the '*' as shown below: 35// by using the '*' as shown below:
32[assembly: AssemblyVersion("0.4.0.0")] 36
33[assembly: AssemblyFileVersion("1.0.0.0")] 37[assembly : AssemblyVersion("0.4.0.0")]
38[assembly : AssemblyFileVersion("1.0.0.0")] \ No newline at end of file
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs b/OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs
index a85ab4d..4187078 100644
--- a/OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs
+++ b/OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs
@@ -26,15 +26,11 @@
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; 30using System.Reflection;
31using libsecondlife;
34using Mono.Data.SqliteClient; 32using Mono.Data.SqliteClient;
35using OpenSim.Framework.Console; 33using OpenSim.Framework.Console;
36using OpenSim.Framework;
37using OpenSim.Framework.Interfaces;
38 34
39namespace OpenSim.Framework.Data.SQLite 35namespace OpenSim.Framework.Data.SQLite
40{ 36{
@@ -46,11 +42,11 @@ namespace OpenSim.Framework.Data.SQLite
46 /// <summary> 42 /// <summary>
47 /// The database manager 43 /// The database manager
48 /// </summary> 44 /// </summary>
49
50 /// <summary> 45 /// <summary>
51 /// Artificial constructor called upon plugin load 46 /// Artificial constructor called upon plugin load
52 /// </summary> 47 /// </summary>
53 private const string assetSelect = "select * from assets"; 48 private const string assetSelect = "select * from assets";
49
54 private DataSet ds; 50 private DataSet ds;
55 private SqliteDataAdapter da; 51 private SqliteDataAdapter da;
56 52
@@ -58,13 +54,14 @@ namespace OpenSim.Framework.Data.SQLite
58 { 54 {
59 SqliteConnection conn = new SqliteConnection("URI=file:" + dbfile + ",version=3"); 55 SqliteConnection conn = new SqliteConnection("URI=file:" + dbfile + ",version=3");
60 TestTables(conn); 56 TestTables(conn);
61 57
62 ds = new DataSet(); 58 ds = new DataSet();
63 da = new SqliteDataAdapter(new SqliteCommand(assetSelect, conn)); 59 da = new SqliteDataAdapter(new SqliteCommand(assetSelect, conn));
64 60
65 lock (ds) { 61 lock (ds)
62 {
66 ds.Tables.Add(createAssetsTable()); 63 ds.Tables.Add(createAssetsTable());
67 64
68 setupAssetCommands(da, conn); 65 setupAssetCommands(da, conn);
69 try 66 try
70 { 67 {
@@ -75,11 +72,11 @@ namespace OpenSim.Framework.Data.SQLite
75 MainLog.Instance.Verbose("AssetStorage", "Caught fill error on asset table"); 72 MainLog.Instance.Verbose("AssetStorage", "Caught fill error on asset table");
76 } 73 }
77 } 74 }
78 75
79 return; 76 return;
80 } 77 }
81 78
82 public AssetBase FetchAsset(LLUUID uuid) 79 public AssetBase FetchAsset(LLUUID uuid)
83 { 80 {
84 AssetBase asset = new AssetBase(); 81 AssetBase asset = new AssetBase();
85 DataRow row = ds.Tables["assets"].Rows.Find(uuid); 82 DataRow row = ds.Tables["assets"].Rows.Find(uuid);
@@ -92,27 +89,28 @@ namespace OpenSim.Framework.Data.SQLite
92 return null; 89 return null;
93 } 90 }
94 } 91 }
95 92
96 public void CreateAsset(AssetBase asset) 93 public void CreateAsset(AssetBase asset)
97 { 94 {
98 // no difference for now 95 // no difference for now
99 UpdateAsset(asset); 96 UpdateAsset(asset);
100 } 97 }
101 98
102 public void UpdateAsset(AssetBase asset) 99 public void UpdateAsset(AssetBase asset)
103 { 100 {
104 LogAssetLoad(asset); 101 LogAssetLoad(asset);
105 102
106 DataTable assets = ds.Tables["assets"]; 103 DataTable assets = ds.Tables["assets"];
107 lock(ds) { 104 lock (ds)
105 {
108 DataRow row = assets.Rows.Find(asset.FullID); 106 DataRow row = assets.Rows.Find(asset.FullID);
109 if (row == null) 107 if (row == null)
110 { 108 {
111 row = assets.NewRow(); 109 row = assets.NewRow();
112 fillAssetRow(row, asset); 110 fillAssetRow(row, asset);
113 assets.Rows.Add(row); 111 assets.Rows.Add(row);
114 } 112 }
115 else 113 else
116 { 114 {
117 fillAssetRow(row, asset); 115 fillAssetRow(row, asset);
118 } 116 }
@@ -124,9 +122,10 @@ namespace OpenSim.Framework.Data.SQLite
124 string temporary = asset.Temporary ? "Temporary" : "Stored"; 122 string temporary = asset.Temporary ? "Temporary" : "Stored";
125 string local = asset.Local ? "Local" : "Remote"; 123 string local = asset.Local ? "Local" : "Remote";
126 124
127 MainLog.Instance.Verbose("ASSETSTORAGE", 125 MainLog.Instance.Verbose("ASSETSTORAGE",
128 string.Format("Loaded {6} {5} Asset: [{0}][{3}/{4}] \"{1}\":{2} ({7} bytes)", 126 string.Format("Loaded {6} {5} Asset: [{0}][{3}/{4}] \"{1}\":{2} ({7} bytes)",
129 asset.FullID, asset.Name, asset.Description, asset.Type, asset.InvType, temporary, local, asset.Data.Length) ); 127 asset.FullID, asset.Name, asset.Description, asset.Type,
128 asset.InvType, temporary, local, asset.Data.Length));
130 } 129 }
131 130
132 public bool ExistsAsset(LLUUID uuid) 131 public bool ExistsAsset(LLUUID uuid)
@@ -137,23 +136,26 @@ namespace OpenSim.Framework.Data.SQLite
137 136
138 public void DeleteAsset(LLUUID uuid) 137 public void DeleteAsset(LLUUID uuid)
139 { 138 {
140 lock (ds) { 139 lock (ds)
140 {
141 DataRow row = ds.Tables["assets"].Rows.Find(uuid); 141 DataRow row = ds.Tables["assets"].Rows.Find(uuid);
142 if (row != null) { 142 if (row != null)
143 {
143 row.Delete(); 144 row.Delete();
144 } 145 }
145 } 146 }
146 } 147 }
147 148
148 public void CommitAssets() // force a sync to the database 149 public void CommitAssets() // force a sync to the database
149 { 150 {
150 MainLog.Instance.Verbose("AssetStorage", "Attempting commit"); 151 MainLog.Instance.Verbose("AssetStorage", "Attempting commit");
151 lock (ds) { 152 lock (ds)
153 {
152 da.Update(ds, "assets"); 154 da.Update(ds, "assets");
153 ds.AcceptChanges(); 155 ds.AcceptChanges();
154 } 156 }
155 } 157 }
156 158
157 /*********************************************************************** 159 /***********************************************************************
158 * 160 *
159 * Database Definition Functions 161 * Database Definition Functions
@@ -161,24 +163,24 @@ namespace OpenSim.Framework.Data.SQLite
161 * This should be db agnostic as we define them in ADO.NET terms 163 * This should be db agnostic as we define them in ADO.NET terms
162 * 164 *
163 **********************************************************************/ 165 **********************************************************************/
164 166
165 private DataTable createAssetsTable() 167 private DataTable createAssetsTable()
166 { 168 {
167 DataTable assets = new DataTable("assets"); 169 DataTable assets = new DataTable("assets");
168 170
169 createCol(assets, "UUID", typeof(System.String)); 171 createCol(assets, "UUID", typeof (String));
170 createCol(assets, "Name", typeof(System.String)); 172 createCol(assets, "Name", typeof (String));
171 createCol(assets, "Description", typeof(System.String)); 173 createCol(assets, "Description", typeof (String));
172 createCol(assets, "Type", typeof(System.Int32)); 174 createCol(assets, "Type", typeof (Int32));
173 createCol(assets, "InvType", typeof(System.Int32)); 175 createCol(assets, "InvType", typeof (Int32));
174 createCol(assets, "Local", typeof(System.Boolean)); 176 createCol(assets, "Local", typeof (Boolean));
175 createCol(assets, "Temporary", typeof(System.Boolean)); 177 createCol(assets, "Temporary", typeof (Boolean));
176 createCol(assets, "Data", typeof(System.Byte[])); 178 createCol(assets, "Data", typeof (Byte[]));
177 // Add in contraints 179 // Add in contraints
178 assets.PrimaryKey = new DataColumn[] { assets.Columns["UUID"] }; 180 assets.PrimaryKey = new DataColumn[] {assets.Columns["UUID"]};
179 return assets; 181 return assets;
180 } 182 }
181 183
182 /*********************************************************************** 184 /***********************************************************************
183 * 185 *
184 * Convert between ADO.NET <=> OpenSim Objects 186 * Convert between ADO.NET <=> OpenSim Objects
@@ -193,19 +195,19 @@ namespace OpenSim.Framework.Data.SQLite
193 // interesting has to be done to actually get these values 195 // interesting has to be done to actually get these values
194 // back out. Not enough time to figure it out yet. 196 // back out. Not enough time to figure it out yet.
195 AssetBase asset = new AssetBase(); 197 AssetBase asset = new AssetBase();
196 198
197 asset.FullID = new LLUUID((String)row["UUID"]); 199 asset.FullID = new LLUUID((String) row["UUID"]);
198 asset.Name = (String)row["Name"]; 200 asset.Name = (String) row["Name"];
199 asset.Description = (String)row["Description"]; 201 asset.Description = (String) row["Description"];
200 asset.Type = Convert.ToSByte(row["Type"]); 202 asset.Type = Convert.ToSByte(row["Type"]);
201 asset.InvType = Convert.ToSByte(row["InvType"]); 203 asset.InvType = Convert.ToSByte(row["InvType"]);
202 asset.Local = Convert.ToBoolean(row["Local"]); 204 asset.Local = Convert.ToBoolean(row["Local"]);
203 asset.Temporary = Convert.ToBoolean(row["Temporary"]); 205 asset.Temporary = Convert.ToBoolean(row["Temporary"]);
204 asset.Data = (byte[])row["Data"]; 206 asset.Data = (byte[]) row["Data"];
205 return asset; 207 return asset;
206 } 208 }
207 209
208 210
209 private void fillAssetRow(DataRow row, AssetBase asset) 211 private void fillAssetRow(DataRow row, AssetBase asset)
210 { 212 {
211 row["UUID"] = asset.FullID; 213 row["UUID"] = asset.FullID;
@@ -225,8 +227,10 @@ namespace OpenSim.Framework.Data.SQLite
225 row["Data"] = asset.Data; 227 row["Data"] = asset.Data;
226 228
227 // ADO.NET doesn't handle NULL very well 229 // ADO.NET doesn't handle NULL very well
228 foreach (DataColumn col in ds.Tables["assets"].Columns) { 230 foreach (DataColumn col in ds.Tables["assets"].Columns)
229 if (row[col] == null) { 231 {
232 if (row[col] == null)
233 {
230 row[col] = ""; 234 row[col] = "";
231 } 235 }
232 } 236 }
@@ -250,18 +254,18 @@ namespace OpenSim.Framework.Data.SQLite
250 da.UpdateCommand.Connection = conn; 254 da.UpdateCommand.Connection = conn;
251 255
252 SqliteCommand delete = new SqliteCommand("delete from assets where UUID = :UUID"); 256 SqliteCommand delete = new SqliteCommand("delete from assets where UUID = :UUID");
253 delete.Parameters.Add(createSqliteParameter("UUID", typeof(System.String))); 257 delete.Parameters.Add(createSqliteParameter("UUID", typeof (String)));
254 delete.Connection = conn; 258 delete.Connection = conn;
255 da.DeleteCommand = delete; 259 da.DeleteCommand = delete;
256 } 260 }
257 261
258 private void InitDB(SqliteConnection conn) 262 private void InitDB(SqliteConnection conn)
259 { 263 {
260 string createAssets = defineTable(createAssetsTable()); 264 string createAssets = defineTable(createAssetsTable());
261 SqliteCommand pcmd = new SqliteCommand(createAssets, conn); 265 SqliteCommand pcmd = new SqliteCommand(createAssets, conn);
262 conn.Open(); 266 conn.Open();
263 pcmd.ExecuteNonQuery(); 267 pcmd.ExecuteNonQuery();
264 conn.Close(); 268 conn.Close();
265 } 269 }
266 270
267 private bool TestTables(SqliteConnection conn) 271 private bool TestTables(SqliteConnection conn)
@@ -269,9 +273,12 @@ namespace OpenSim.Framework.Data.SQLite
269 SqliteCommand cmd = new SqliteCommand(assetSelect, conn); 273 SqliteCommand cmd = new SqliteCommand(assetSelect, conn);
270 SqliteDataAdapter pDa = new SqliteDataAdapter(cmd); 274 SqliteDataAdapter pDa = new SqliteDataAdapter(cmd);
271 DataSet tmpDS = new DataSet(); 275 DataSet tmpDS = new DataSet();
272 try { 276 try
277 {
273 pDa.Fill(tmpDS, "assets"); 278 pDa.Fill(tmpDS, "assets");
274 } catch (Mono.Data.SqliteClient.SqliteSyntaxException) { 279 }
280 catch (SqliteSyntaxException)
281 {
275 MainLog.Instance.Verbose("DATASTORE", "SQLite Database doesn't exist... creating"); 282 MainLog.Instance.Verbose("DATASTORE", "SQLite Database doesn't exist... creating");
276 InitDB(conn); 283 InitDB(conn);
277 } 284 }
@@ -279,14 +286,18 @@ namespace OpenSim.Framework.Data.SQLite
279 } 286 }
280 287
281 #region IPlugin interface 288 #region IPlugin interface
282 public string Version { 289
290 public string Version
291 {
283 get 292 get
284 { 293 {
285 System.Reflection.Module module = this.GetType().Module; 294 Module module = GetType().Module;
286 string dllName = module.Assembly.ManifestModule.Name; 295 string dllName = module.Assembly.ManifestModule.Name;
287 Version dllVersion = module.Assembly.GetName().Version; 296 Version dllVersion = module.Assembly.GetName().Version;
288 297
289 return string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision); 298 return
299 string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build,
300 dllVersion.Revision);
290 } 301 }
291 } 302 }
292 303
@@ -295,9 +306,11 @@ namespace OpenSim.Framework.Data.SQLite
295 Initialise("AssetStorage.db", ""); 306 Initialise("AssetStorage.db", "");
296 } 307 }
297 308
298 public string Name { 309 public string Name
310 {
299 get { return "SQLite Asset storage engine"; } 311 get { return "SQLite Asset storage engine"; }
300 } 312 }
313
301 #endregion 314 #endregion
302 } 315 }
303} 316} \ No newline at end of file
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
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteGridData.cs b/OpenSim/Framework/Data.SQLite/SQLiteGridData.cs
index 2fc80b4..8f3e8aa 100644
--- a/OpenSim/Framework/Data.SQLite/SQLiteGridData.cs
+++ b/OpenSim/Framework/Data.SQLite/SQLiteGridData.cs
@@ -192,4 +192,4 @@ namespace OpenSim.Framework.Data.SQLite
192 return null; 192 return null;
193 } 193 }
194 } 194 }
195} 195} \ No newline at end of file
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs b/OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs
index 82a8434..5e95878 100644
--- a/OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs
+++ b/OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs
@@ -28,22 +28,14 @@
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Data;
32using System.Reflection; 32using System.Reflection;
33
34using OpenSim.Framework.Console;
35using OpenSim.Framework;
36using OpenSim.Framework;
37using libsecondlife; 33using libsecondlife;
38
39using System.Data;
40using System.Data.SqlTypes;
41
42using Mono.Data.SqliteClient; 34using Mono.Data.SqliteClient;
35using OpenSim.Framework.Console;
43 36
44namespace OpenSim.Framework.Data.SQLite 37namespace OpenSim.Framework.Data.SQLite
45{ 38{
46
47 public class SQLiteInventoryStore : SQLiteBase, IInventoryData 39 public class SQLiteInventoryStore : SQLiteBase, IInventoryData
48 { 40 {
49 private const string invItemsSelect = "select * from inventoryitems"; 41 private const string invItemsSelect = "select * from inventoryitems";
@@ -96,14 +88,14 @@ namespace OpenSim.Framework.Data.SQLite
96 public InventoryItemBase buildItem(DataRow row) 88 public InventoryItemBase buildItem(DataRow row)
97 { 89 {
98 InventoryItemBase item = new InventoryItemBase(); 90 InventoryItemBase item = new InventoryItemBase();
99 item.inventoryID = new LLUUID((string)row["UUID"]); 91 item.inventoryID = new LLUUID((string) row["UUID"]);
100 item.assetID = new LLUUID((string)row["assetID"]); 92 item.assetID = new LLUUID((string) row["assetID"]);
101 item.assetType = Convert.ToInt32(row["assetType"]); 93 item.assetType = Convert.ToInt32(row["assetType"]);
102 item.invType = Convert.ToInt32(row["invType"]); 94 item.invType = Convert.ToInt32(row["invType"]);
103 item.parentFolderID = new LLUUID((string)row["parentFolderID"]); 95 item.parentFolderID = new LLUUID((string) row["parentFolderID"]);
104 item.avatarID = new LLUUID((string)row["avatarID"]); 96 item.avatarID = new LLUUID((string) row["avatarID"]);
105 item.creatorsID = new LLUUID((string)row["creatorsID"]); 97 item.creatorsID = new LLUUID((string) row["creatorsID"]);
106 item.inventoryName =(string) row["inventoryName"]; 98 item.inventoryName = (string) row["inventoryName"];
107 item.inventoryDescription = (string) row["inventoryDescription"]; 99 item.inventoryDescription = (string) row["inventoryDescription"];
108 100
109 item.inventoryNextPermissions = Convert.ToUInt32(row["inventoryNextPermissions"]); 101 item.inventoryNextPermissions = Convert.ToUInt32(row["inventoryNextPermissions"]);
@@ -147,7 +139,7 @@ namespace OpenSim.Framework.Data.SQLite
147 fillFolderRow(inventoryRow, folder); 139 fillFolderRow(inventoryRow, folder);
148 } 140 }
149 141
150 this.invFoldersDa.Update(ds, "inventoryfolders"); 142 invFoldersDa.Update(ds, "inventoryfolders");
151 } 143 }
152 144
153 private void addItem(InventoryItemBase item) 145 private void addItem(InventoryItemBase item)
@@ -165,7 +157,7 @@ namespace OpenSim.Framework.Data.SQLite
165 { 157 {
166 fillItemRow(inventoryRow, item); 158 fillItemRow(inventoryRow, item);
167 } 159 }
168 this.invItemsDa.Update(ds, "inventoryitems"); 160 invItemsDa.Update(ds, "inventoryitems");
169 } 161 }
170 162
171 public void Shutdown() 163 public void Shutdown()
@@ -195,12 +187,14 @@ namespace OpenSim.Framework.Data.SQLite
195 /// <returns>A string containing the plugin version</returns> 187 /// <returns>A string containing the plugin version</returns>
196 public string getVersion() 188 public string getVersion()
197 { 189 {
198 System.Reflection.Module module = this.GetType().Module; 190 Module module = GetType().Module;
199 string dllName = module.Assembly.ManifestModule.Name; 191 string dllName = module.Assembly.ManifestModule.Name;
200 Version dllVersion = module.Assembly.GetName().Version; 192 Version dllVersion = module.Assembly.GetName().Version;
201 193
202 194
203 return string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision); 195 return
196 string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build,
197 dllVersion.Revision);
204 } 198 }
205 199
206 /// <summary> 200 /// <summary>
@@ -306,7 +300,7 @@ namespace OpenSim.Framework.Data.SQLite
306 List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); 300 List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
307 getInventoryFolders(ref folders, parentID); 301 getInventoryFolders(ref folders, parentID);
308 302
309 for(int i=0; i<folders.Count; i++) 303 for (int i = 0; i < folders.Count; i++)
310 getInventoryFolders(ref folders, folders[i].folderID); 304 getInventoryFolders(ref folders, folders[i].folderID);
311 305
312 return folders; 306 return folders;
@@ -320,9 +314,12 @@ namespace OpenSim.Framework.Data.SQLite
320 public InventoryItemBase getInventoryItem(LLUUID item) 314 public InventoryItemBase getInventoryItem(LLUUID item)
321 { 315 {
322 DataRow row = ds.Tables["inventoryitems"].Rows.Find(item); 316 DataRow row = ds.Tables["inventoryitems"].Rows.Find(item);
323 if (row != null) { 317 if (row != null)
318 {
324 return buildItem(row); 319 return buildItem(row);
325 } else { 320 }
321 else
322 {
326 return null; 323 return null;
327 } 324 }
328 } 325 }
@@ -334,19 +331,21 @@ namespace OpenSim.Framework.Data.SQLite
334 /// <returns>A class containing folder information</returns> 331 /// <returns>A class containing folder information</returns>
335 public InventoryFolderBase getInventoryFolder(LLUUID folder) 332 public InventoryFolderBase getInventoryFolder(LLUUID folder)
336 { 333 {
337 334 // TODO: Deep voodoo here. If you enable this code then
338 // TODO: Deep voodoo here. If you enable this code then 335 // multi region breaks. No idea why, but I figured it was
339 // multi region breaks. No idea why, but I figured it was 336 // better to leave multi region at this point. It does mean
340 // better to leave multi region at this point. It does mean 337 // that you don't get to see system textures why creating
341 // that you don't get to see system textures why creating 338 // clothes and the like. :(
342 // clothes and the like. :( 339
343 340 DataRow row = ds.Tables["inventoryfolders"].Rows.Find(folder);
344 DataRow row = ds.Tables["inventoryfolders"].Rows.Find(folder); 341 if (row != null)
345 if (row != null) { 342 {
346 return buildFolder(row); 343 return buildFolder(row);
347 } else { 344 }
345 else
346 {
348 return null; 347 return null;
349 } 348 }
350 } 349 }
351 350
352 /// <summary> 351 /// <summary>
@@ -355,7 +354,7 @@ namespace OpenSim.Framework.Data.SQLite
355 /// <param name="item">The item to be created</param> 354 /// <param name="item">The item to be created</param>
356 public void addInventoryItem(InventoryItemBase item) 355 public void addInventoryItem(InventoryItemBase item)
357 { 356 {
358 this.addItem(item); 357 addItem(item);
359 } 358 }
360 359
361 /// <summary> 360 /// <summary>
@@ -364,7 +363,7 @@ namespace OpenSim.Framework.Data.SQLite
364 /// <param name="item">The updated item</param> 363 /// <param name="item">The updated item</param>
365 public void updateInventoryItem(InventoryItemBase item) 364 public void updateInventoryItem(InventoryItemBase item)
366 { 365 {
367 this.addItem(item); 366 addItem(item);
368 } 367 }
369 368
370 /// <summary> 369 /// <summary>
@@ -376,12 +375,12 @@ namespace OpenSim.Framework.Data.SQLite
376 DataTable inventoryItemTable = ds.Tables["inventoryitems"]; 375 DataTable inventoryItemTable = ds.Tables["inventoryitems"];
377 376
378 DataRow inventoryRow = inventoryItemTable.Rows.Find(itemID); 377 DataRow inventoryRow = inventoryItemTable.Rows.Find(itemID);
379 if (inventoryRow != null) 378 if (inventoryRow != null)
380 { 379 {
381 inventoryRow.Delete(); 380 inventoryRow.Delete();
382 } 381 }
383 382
384 this.invItemsDa.Update(ds, "inventoryitems"); 383 invItemsDa.Update(ds, "inventoryitems");
385 } 384 }
386 385
387 386
@@ -394,7 +393,7 @@ namespace OpenSim.Framework.Data.SQLite
394 { 393 {
395 List<InventoryItemBase> items = getInventoryInFolder(folderId); 394 List<InventoryItemBase> items = getInventoryInFolder(folderId);
396 395
397 foreach(InventoryItemBase i in items) 396 foreach (InventoryItemBase i in items)
398 deleteInventoryItem(i.inventoryID); 397 deleteInventoryItem(i.inventoryID);
399 } 398 }
400 399
@@ -404,7 +403,7 @@ namespace OpenSim.Framework.Data.SQLite
404 /// <param name="folder">The inventory folder</param> 403 /// <param name="folder">The inventory folder</param>
405 public void addInventoryFolder(InventoryFolderBase folder) 404 public void addInventoryFolder(InventoryFolderBase folder)
406 { 405 {
407 this.addFolder(folder); 406 addFolder(folder);
408 } 407 }
409 408
410 /// <summary> 409 /// <summary>
@@ -413,7 +412,7 @@ namespace OpenSim.Framework.Data.SQLite
413 /// <param name="folder">The inventory folder</param> 412 /// <param name="folder">The inventory folder</param>
414 public void updateInventoryFolder(InventoryFolderBase folder) 413 public void updateInventoryFolder(InventoryFolderBase folder)
415 { 414 {
416 this.addFolder(folder); 415 addFolder(folder);
417 } 416 }
418 417
419 418
@@ -427,7 +426,7 @@ namespace OpenSim.Framework.Data.SQLite
427 public void deleteInventoryFolder(LLUUID folderID) 426 public void deleteInventoryFolder(LLUUID folderID)
428 { 427 {
429 List<InventoryFolderBase> subFolders = getFolderHierarchy(folderID); 428 List<InventoryFolderBase> subFolders = getFolderHierarchy(folderID);
430 429
431 DataTable inventoryFolderTable = ds.Tables["inventoryfolders"]; 430 DataTable inventoryFolderTable = ds.Tables["inventoryfolders"];
432 DataRow inventoryRow; 431 DataRow inventoryRow;
433 432
@@ -450,7 +449,7 @@ namespace OpenSim.Framework.Data.SQLite
450 inventoryRow.Delete(); 449 inventoryRow.Delete();
451 } 450 }
452 451
453 this.invFoldersDa.Update(ds, "inventoryfolders"); 452 invFoldersDa.Update(ds, "inventoryfolders");
454 } 453 }
455 454
456 /*********************************************************************** 455 /***********************************************************************
@@ -458,43 +457,43 @@ namespace OpenSim.Framework.Data.SQLite
458 * Data Table definitions 457 * Data Table definitions
459 * 458 *
460 **********************************************************************/ 459 **********************************************************************/
461 460
462 private static DataTable createInventoryItemsTable() 461 private static DataTable createInventoryItemsTable()
463 { 462 {
464 DataTable inv = new DataTable("inventoryitems"); 463 DataTable inv = new DataTable("inventoryitems");
465 464
466 createCol(inv, "UUID", typeof(System.String)); //inventoryID 465 createCol(inv, "UUID", typeof (String)); //inventoryID
467 createCol(inv, "assetID", typeof(System.String)); 466 createCol(inv, "assetID", typeof (String));
468 createCol(inv, "assetType", typeof(System.Int32)); 467 createCol(inv, "assetType", typeof (Int32));
469 createCol(inv, "invType", typeof(System.Int32)); 468 createCol(inv, "invType", typeof (Int32));
470 createCol(inv, "parentFolderID", typeof(System.String)); 469 createCol(inv, "parentFolderID", typeof (String));
471 createCol(inv, "avatarID", typeof(System.String)); 470 createCol(inv, "avatarID", typeof (String));
472 createCol(inv, "creatorsID", typeof(System.String)); 471 createCol(inv, "creatorsID", typeof (String));
473 472
474 createCol(inv, "inventoryName", typeof(System.String)); 473 createCol(inv, "inventoryName", typeof (String));
475 createCol(inv, "inventoryDescription", typeof(System.String)); 474 createCol(inv, "inventoryDescription", typeof (String));
476 // permissions 475 // permissions
477 createCol(inv, "inventoryNextPermissions", typeof(System.Int32)); 476 createCol(inv, "inventoryNextPermissions", typeof (Int32));
478 createCol(inv, "inventoryCurrentPermissions", typeof(System.Int32)); 477 createCol(inv, "inventoryCurrentPermissions", typeof (Int32));
479 createCol(inv, "inventoryBasePermissions", typeof(System.Int32)); 478 createCol(inv, "inventoryBasePermissions", typeof (Int32));
480 createCol(inv, "inventoryEveryOnePermissions", typeof(System.Int32)); 479 createCol(inv, "inventoryEveryOnePermissions", typeof (Int32));
481 480
482 inv.PrimaryKey = new DataColumn[] { inv.Columns["UUID"] }; 481 inv.PrimaryKey = new DataColumn[] {inv.Columns["UUID"]};
483 return inv; 482 return inv;
484 } 483 }
485 484
486 private DataTable createInventoryFoldersTable() 485 private DataTable createInventoryFoldersTable()
487 { 486 {
488 DataTable fol = new DataTable("inventoryfolders"); 487 DataTable fol = new DataTable("inventoryfolders");
489 488
490 createCol(fol, "UUID", typeof(System.String)); //folderID 489 createCol(fol, "UUID", typeof (String)); //folderID
491 createCol(fol, "name", typeof(System.String)); 490 createCol(fol, "name", typeof (String));
492 createCol(fol, "agentID", typeof(System.String)); 491 createCol(fol, "agentID", typeof (String));
493 createCol(fol, "parentID", typeof(System.String)); 492 createCol(fol, "parentID", typeof (String));
494 createCol(fol, "type", typeof(System.Int32)); 493 createCol(fol, "type", typeof (Int32));
495 createCol(fol, "version", typeof(System.Int32)); 494 createCol(fol, "version", typeof (Int32));
496 495
497 fol.PrimaryKey = new DataColumn[] { fol.Columns["UUID"] }; 496 fol.PrimaryKey = new DataColumn[] {fol.Columns["UUID"]};
498 return fol; 497 return fol;
499 } 498 }
500 499
@@ -507,7 +506,7 @@ namespace OpenSim.Framework.Data.SQLite
507 da.UpdateCommand.Connection = conn; 506 da.UpdateCommand.Connection = conn;
508 507
509 SqliteCommand delete = new SqliteCommand("delete from inventoryitems where UUID = :UUID"); 508 SqliteCommand delete = new SqliteCommand("delete from inventoryitems where UUID = :UUID");
510 delete.Parameters.Add(createSqliteParameter("UUID", typeof(System.String))); 509 delete.Parameters.Add(createSqliteParameter("UUID", typeof (String)));
511 delete.Connection = conn; 510 delete.Connection = conn;
512 da.DeleteCommand = delete; 511 da.DeleteCommand = delete;
513 } 512 }
@@ -521,7 +520,7 @@ namespace OpenSim.Framework.Data.SQLite
521 da.UpdateCommand.Connection = conn; 520 da.UpdateCommand.Connection = conn;
522 521
523 SqliteCommand delete = new SqliteCommand("delete from inventoryfolders where UUID = :UUID"); 522 SqliteCommand delete = new SqliteCommand("delete from inventoryfolders where UUID = :UUID");
524 delete.Parameters.Add(createSqliteParameter("UUID", typeof(System.String))); 523 delete.Parameters.Add(createSqliteParameter("UUID", typeof (String)));
525 delete.Connection = conn; 524 delete.Connection = conn;
526 da.DeleteCommand = delete; 525 da.DeleteCommand = delete;
527 } 526 }
@@ -529,10 +528,10 @@ namespace OpenSim.Framework.Data.SQLite
529 private InventoryFolderBase buildFolder(DataRow row) 528 private InventoryFolderBase buildFolder(DataRow row)
530 { 529 {
531 InventoryFolderBase folder = new InventoryFolderBase(); 530 InventoryFolderBase folder = new InventoryFolderBase();
532 folder.folderID = new LLUUID((string)row["UUID"]); 531 folder.folderID = new LLUUID((string) row["UUID"]);
533 folder.name = (string)row["name"]; 532 folder.name = (string) row["name"];
534 folder.agentID = new LLUUID((string)row["agentID"]); 533 folder.agentID = new LLUUID((string) row["agentID"]);
535 folder.parentID = new LLUUID((string)row["parentID"]); 534 folder.parentID = new LLUUID((string) row["parentID"]);
536 folder.type = Convert.ToInt16(row["type"]); 535 folder.type = Convert.ToInt16(row["type"]);
537 folder.version = Convert.ToUInt16(row["version"]); 536 folder.version = Convert.ToUInt16(row["version"]);
538 return folder; 537 return folder;
@@ -554,17 +553,18 @@ namespace OpenSim.Framework.Data.SQLite
554 * Test and Initialization code 553 * Test and Initialization code
555 * 554 *
556 **********************************************************************/ 555 **********************************************************************/
556
557 private void InitDB(SqliteConnection conn) 557 private void InitDB(SqliteConnection conn)
558 { 558 {
559 string createInventoryItems = defineTable(createInventoryItemsTable()); 559 string createInventoryItems = defineTable(createInventoryItemsTable());
560 string createInventoryFolders = defineTable(createInventoryFoldersTable()); 560 string createInventoryFolders = defineTable(createInventoryFoldersTable());
561 561
562 SqliteCommand pcmd = new SqliteCommand(createInventoryItems, conn); 562 SqliteCommand pcmd = new SqliteCommand(createInventoryItems, conn);
563 SqliteCommand scmd = new SqliteCommand(createInventoryFolders, conn); 563 SqliteCommand scmd = new SqliteCommand(createInventoryFolders, conn);
564 conn.Open(); 564 conn.Open();
565 pcmd.ExecuteNonQuery(); 565 pcmd.ExecuteNonQuery();
566 scmd.ExecuteNonQuery(); 566 scmd.ExecuteNonQuery();
567 conn.Close(); 567 conn.Close();
568 } 568 }
569 569
570 private bool TestTables(SqliteConnection conn) 570 private bool TestTables(SqliteConnection conn)
@@ -575,10 +575,13 @@ namespace OpenSim.Framework.Data.SQLite
575 SqliteDataAdapter sDa = new SqliteDataAdapter(invFoldersSelectCmd); 575 SqliteDataAdapter sDa = new SqliteDataAdapter(invFoldersSelectCmd);
576 576
577 DataSet tmpDS = new DataSet(); 577 DataSet tmpDS = new DataSet();
578 try { 578 try
579 {
579 pDa.Fill(tmpDS, "inventoryitems"); 580 pDa.Fill(tmpDS, "inventoryitems");
580 sDa.Fill(tmpDS, "inventoryfolders"); 581 sDa.Fill(tmpDS, "inventoryfolders");
581 } catch (Mono.Data.SqliteClient.SqliteSyntaxException) { 582 }
583 catch (SqliteSyntaxException)
584 {
582 MainLog.Instance.Verbose("DATASTORE", "SQLite Database doesn't exist... creating"); 585 MainLog.Instance.Verbose("DATASTORE", "SQLite Database doesn't exist... creating");
583 InitDB(conn); 586 InitDB(conn);
584 } 587 }
@@ -586,14 +589,18 @@ namespace OpenSim.Framework.Data.SQLite
586 pDa.Fill(tmpDS, "inventoryitems"); 589 pDa.Fill(tmpDS, "inventoryitems");
587 sDa.Fill(tmpDS, "inventoryfolders"); 590 sDa.Fill(tmpDS, "inventoryfolders");
588 591
589 foreach (DataColumn col in createInventoryItemsTable().Columns) { 592 foreach (DataColumn col in createInventoryItemsTable().Columns)
590 if (! tmpDS.Tables["inventoryitems"].Columns.Contains(col.ColumnName) ) { 593 {
594 if (! tmpDS.Tables["inventoryitems"].Columns.Contains(col.ColumnName))
595 {
591 MainLog.Instance.Verbose("DATASTORE", "Missing required column:" + col.ColumnName); 596 MainLog.Instance.Verbose("DATASTORE", "Missing required column:" + col.ColumnName);
592 return false; 597 return false;
593 } 598 }
594 } 599 }
595 foreach (DataColumn col in createInventoryFoldersTable().Columns) { 600 foreach (DataColumn col in createInventoryFoldersTable().Columns)
596 if (! tmpDS.Tables["inventoryfolders"].Columns.Contains(col.ColumnName) ) { 601 {
602 if (! tmpDS.Tables["inventoryfolders"].Columns.Contains(col.ColumnName))
603 {
597 MainLog.Instance.Verbose("DATASTORE", "Missing required column:" + col.ColumnName); 604 MainLog.Instance.Verbose("DATASTORE", "Missing required column:" + col.ColumnName);
598 return false; 605 return false;
599 } 606 }
@@ -601,8 +608,4 @@ namespace OpenSim.Framework.Data.SQLite
601 return true; 608 return true;
602 } 609 }
603 } 610 }
604} 611} \ No newline at end of file
605
606
607
608
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteManager.cs b/OpenSim/Framework/Data.SQLite/SQLiteManager.cs
index 5954fba..e102da3 100644
--- a/OpenSim/Framework/Data.SQLite/SQLiteManager.cs
+++ b/OpenSim/Framework/Data.SQLite/SQLiteManager.cs
@@ -30,13 +30,14 @@ using System.Collections.Generic;
30using System.Data; 30using System.Data;
31using System.Data.SQLite; 31using System.Data.SQLite;
32using libsecondlife; 32using libsecondlife;
33using Mono.Data.SqliteClient;
33using OpenSim.Framework.Console; 34using OpenSim.Framework.Console;
34 35
35namespace OpenSim.Framework.Data.SQLite 36namespace OpenSim.Framework.Data.SQLite
36{ 37{
37 class SQLiteManager : SQLiteBase 38 internal class SQLiteManager : SQLiteBase
38 { 39 {
39 IDbConnection dbcon; 40 private IDbConnection dbcon;
40 41
41 /// <summary> 42 /// <summary>
42 /// Initialises and creates a new SQLite connection and maintains it. 43 /// Initialises and creates a new SQLite connection and maintains it.
@@ -78,15 +79,15 @@ namespace OpenSim.Framework.Data.SQLite
78 /// <returns>A SQLite DB Command</returns> 79 /// <returns>A SQLite DB Command</returns>
79 public IDbCommand Query(string sql, Dictionary<string, string> parameters) 80 public IDbCommand Query(string sql, Dictionary<string, string> parameters)
80 { 81 {
81 SQLiteCommand dbcommand = (SQLiteCommand)dbcon.CreateCommand(); 82 SQLiteCommand dbcommand = (SQLiteCommand) dbcon.CreateCommand();
82 dbcommand.CommandText = sql; 83 dbcommand.CommandText = sql;
83 foreach (KeyValuePair<string, string> param in parameters) 84 foreach (KeyValuePair<string, string> param in parameters)
84 { 85 {
85 SQLiteParameter paramx = new SQLiteParameter(param.Key,param.Value); 86 SQLiteParameter paramx = new SQLiteParameter(param.Key, param.Value);
86 dbcommand.Parameters.Add(paramx); 87 dbcommand.Parameters.Add(paramx);
87 } 88 }
88 89
89 return (IDbCommand)dbcommand; 90 return (IDbCommand) dbcommand;
90 } 91 }
91 92
92 private bool TestTables(SQLiteConnection conn) 93 private bool TestTables(SQLiteConnection conn)
@@ -98,7 +99,7 @@ namespace OpenSim.Framework.Data.SQLite
98 { 99 {
99 pDa.Fill(tmpDS, "regions"); 100 pDa.Fill(tmpDS, "regions");
100 } 101 }
101 catch (Mono.Data.SqliteClient.SqliteSyntaxException) 102 catch (SqliteSyntaxException)
102 { 103 {
103 MainLog.Instance.Verbose("DATASTORE", "SQLite Database doesn't exist... creating"); 104 MainLog.Instance.Verbose("DATASTORE", "SQLite Database doesn't exist... creating");
104 InitDB(conn); 105 InitDB(conn);
@@ -110,39 +111,39 @@ namespace OpenSim.Framework.Data.SQLite
110 { 111 {
111 DataTable regions = new DataTable("regions"); 112 DataTable regions = new DataTable("regions");
112 113
113 createCol(regions, "regionHandle", typeof(ulong)); 114 createCol(regions, "regionHandle", typeof (ulong));
114 createCol(regions, "regionName", typeof(System.String)); 115 createCol(regions, "regionName", typeof (String));
115 createCol(regions, "uuid", typeof(System.String)); 116 createCol(regions, "uuid", typeof (String));
116 117
117 createCol(regions, "regionRecvKey", typeof(System.String)); 118 createCol(regions, "regionRecvKey", typeof (String));
118 createCol(regions, "regionSecret", typeof(System.String)); 119 createCol(regions, "regionSecret", typeof (String));
119 createCol(regions, "regionSendKey", typeof(System.String)); 120 createCol(regions, "regionSendKey", typeof (String));
120 121
121 createCol(regions, "regionDataURI", typeof(System.String)); 122 createCol(regions, "regionDataURI", typeof (String));
122 createCol(regions, "serverIP", typeof(System.String)); 123 createCol(regions, "serverIP", typeof (String));
123 createCol(regions, "serverPort", typeof(System.String)); 124 createCol(regions, "serverPort", typeof (String));
124 createCol(regions, "serverURI", typeof(System.String)); 125 createCol(regions, "serverURI", typeof (String));
125 126
126 127
127 createCol(regions, "locX", typeof( uint)); 128 createCol(regions, "locX", typeof (uint));
128 createCol(regions, "locY", typeof( uint)); 129 createCol(regions, "locY", typeof (uint));
129 createCol(regions, "locZ", typeof( uint)); 130 createCol(regions, "locZ", typeof (uint));
130 131
131 createCol(regions, "eastOverrideHandle", typeof( ulong )); 132 createCol(regions, "eastOverrideHandle", typeof (ulong));
132 createCol(regions, "westOverrideHandle", typeof( ulong )); 133 createCol(regions, "westOverrideHandle", typeof (ulong));
133 createCol(regions, "southOverrideHandle", typeof( ulong )); 134 createCol(regions, "southOverrideHandle", typeof (ulong));
134 createCol(regions, "northOverrideHandle", typeof( ulong )); 135 createCol(regions, "northOverrideHandle", typeof (ulong));
135 136
136 createCol(regions, "regionAssetURI", typeof(System.String)); 137 createCol(regions, "regionAssetURI", typeof (String));
137 createCol(regions, "regionAssetRecvKey", typeof(System.String)); 138 createCol(regions, "regionAssetRecvKey", typeof (String));
138 createCol(regions, "regionAssetSendKey", typeof(System.String)); 139 createCol(regions, "regionAssetSendKey", typeof (String));
139 140
140 createCol(regions, "regionUserURI", typeof(System.String)); 141 createCol(regions, "regionUserURI", typeof (String));
141 createCol(regions, "regionUserRecvKey", typeof(System.String)); 142 createCol(regions, "regionUserRecvKey", typeof (String));
142 createCol(regions, "regionUserSendKey", typeof(System.String)); 143 createCol(regions, "regionUserSendKey", typeof (String));
143 144
144 // Add in contraints 145 // Add in contraints
145 regions.PrimaryKey = new DataColumn[] { regions.Columns["UUID"] }; 146 regions.PrimaryKey = new DataColumn[] {regions.Columns["UUID"]};
146 return regions; 147 return regions;
147 } 148 }
148 149
@@ -168,42 +169,42 @@ namespace OpenSim.Framework.Data.SQLite
168 if (reader.Read()) 169 if (reader.Read())
169 { 170 {
170 // Region Main 171 // Region Main
171 retval.regionHandle = (ulong)reader["regionHandle"]; 172 retval.regionHandle = (ulong) reader["regionHandle"];
172 retval.regionName = (string)reader["regionName"]; 173 retval.regionName = (string) reader["regionName"];
173 retval.UUID = new LLUUID((string)reader["uuid"]); 174 retval.UUID = new LLUUID((string) reader["uuid"]);
174 175
175 // Secrets 176 // Secrets
176 retval.regionRecvKey = (string)reader["regionRecvKey"]; 177 retval.regionRecvKey = (string) reader["regionRecvKey"];
177 retval.regionSecret = (string)reader["regionSecret"]; 178 retval.regionSecret = (string) reader["regionSecret"];
178 retval.regionSendKey = (string)reader["regionSendKey"]; 179 retval.regionSendKey = (string) reader["regionSendKey"];
179 180
180 // Region Server 181 // Region Server
181 retval.regionDataURI = (string)reader["regionDataURI"]; 182 retval.regionDataURI = (string) reader["regionDataURI"];
182 retval.regionOnline = false; // Needs to be pinged before this can be set. 183 retval.regionOnline = false; // Needs to be pinged before this can be set.
183 retval.serverIP = (string)reader["serverIP"]; 184 retval.serverIP = (string) reader["serverIP"];
184 retval.serverPort = (uint)reader["serverPort"]; 185 retval.serverPort = (uint) reader["serverPort"];
185 retval.serverURI = (string)reader["serverURI"]; 186 retval.serverURI = (string) reader["serverURI"];
186 187
187 // Location 188 // Location
188 retval.regionLocX = (uint)((int)reader["locX"]); 189 retval.regionLocX = (uint) ((int) reader["locX"]);
189 retval.regionLocY = (uint)((int)reader["locY"]); 190 retval.regionLocY = (uint) ((int) reader["locY"]);
190 retval.regionLocZ = (uint)((int)reader["locZ"]); 191 retval.regionLocZ = (uint) ((int) reader["locZ"]);
191 192
192 // Neighbours - 0 = No Override 193 // Neighbours - 0 = No Override
193 retval.regionEastOverrideHandle = (ulong)reader["eastOverrideHandle"]; 194 retval.regionEastOverrideHandle = (ulong) reader["eastOverrideHandle"];
194 retval.regionWestOverrideHandle = (ulong)reader["westOverrideHandle"]; 195 retval.regionWestOverrideHandle = (ulong) reader["westOverrideHandle"];
195 retval.regionSouthOverrideHandle = (ulong)reader["southOverrideHandle"]; 196 retval.regionSouthOverrideHandle = (ulong) reader["southOverrideHandle"];
196 retval.regionNorthOverrideHandle = (ulong)reader["northOverrideHandle"]; 197 retval.regionNorthOverrideHandle = (ulong) reader["northOverrideHandle"];
197 198
198 // Assets 199 // Assets
199 retval.regionAssetURI = (string)reader["regionAssetURI"]; 200 retval.regionAssetURI = (string) reader["regionAssetURI"];
200 retval.regionAssetRecvKey = (string)reader["regionAssetRecvKey"]; 201 retval.regionAssetRecvKey = (string) reader["regionAssetRecvKey"];
201 retval.regionAssetSendKey = (string)reader["regionAssetSendKey"]; 202 retval.regionAssetSendKey = (string) reader["regionAssetSendKey"];
202 203
203 // Userserver 204 // Userserver
204 retval.regionUserURI = (string)reader["regionUserURI"]; 205 retval.regionUserURI = (string) reader["regionUserURI"];
205 retval.regionUserRecvKey = (string)reader["regionUserRecvKey"]; 206 retval.regionUserRecvKey = (string) reader["regionUserRecvKey"];
206 retval.regionUserSendKey = (string)reader["regionUserSendKey"]; 207 retval.regionUserSendKey = (string) reader["regionUserSendKey"];
207 } 208 }
208 else 209 else
209 { 210 {
@@ -219,12 +220,15 @@ namespace OpenSim.Framework.Data.SQLite
219 /// <returns>Success?</returns> 220 /// <returns>Success?</returns>
220 public bool insertRow(RegionProfileData profile) 221 public bool insertRow(RegionProfileData profile)
221 { 222 {
222 string sql = "REPLACE INTO regions VALUES (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, "; 223 string sql =
223 sql += "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, "; 224 "REPLACE INTO regions VALUES (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, ";
225 sql +=
226 "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, ";
224 sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES "; 227 sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES ";
225 228
226 sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, "; 229 sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, ";
227 sql += "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, "; 230 sql +=
231 "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, ";
228 sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey);"; 232 sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey);";
229 233
230 Dictionary<string, string> parameters = new Dictionary<string, string>(); 234 Dictionary<string, string> parameters = new Dictionary<string, string>();
@@ -271,4 +275,4 @@ namespace OpenSim.Framework.Data.SQLite
271 return returnval; 275 return returnval;
272 } 276 }
273 } 277 }
274} 278} \ No newline at end of file
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs b/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
index 37a8be5..d7a6b39 100644
--- a/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
+++ b/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
@@ -26,12 +26,8 @@
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.IO;
30using libsecondlife;
31using OpenSim.Framework;
32using OpenSim.Framework;
33using System.Data; 29using System.Data;
34using System.Data.SqlTypes; 30using libsecondlife;
35using Mono.Data.SqliteClient; 31using Mono.Data.SqliteClient;
36using OpenSim.Framework.Console; 32using OpenSim.Framework.Console;
37 33
@@ -45,30 +41,31 @@ namespace OpenSim.Framework.Data.SQLite
45 /// <summary> 41 /// <summary>
46 /// The database manager 42 /// The database manager
47 /// </summary> 43 /// </summary>
48
49 /// <summary> 44 /// <summary>
50 /// Artificial constructor called upon plugin load 45 /// Artificial constructor called upon plugin load
51 /// </summary> 46 /// </summary>
52 private const string userSelect = "select * from users"; 47 private const string userSelect = "select * from users";
48
53 private DataSet ds; 49 private DataSet ds;
54 private SqliteDataAdapter da; 50 private SqliteDataAdapter da;
55 51
56 public void Initialise() 52 public void Initialise()
57 { 53 {
58 SqliteConnection conn = new SqliteConnection("URI=file:userprofiles.db,version=3"); 54 SqliteConnection conn = new SqliteConnection("URI=file:userprofiles.db,version=3");
59 TestTables(conn); 55 TestTables(conn);
60 56
61 ds = new DataSet(); 57 ds = new DataSet();
62 da = new SqliteDataAdapter(new SqliteCommand(userSelect, conn)); 58 da = new SqliteDataAdapter(new SqliteCommand(userSelect, conn));
63 59
64 lock (ds) { 60 lock (ds)
61 {
65 ds.Tables.Add(createUsersTable()); 62 ds.Tables.Add(createUsersTable());
66 ds.Tables.Add(createUserAgentsTable()); 63 ds.Tables.Add(createUserAgentsTable());
67 64
68 setupUserCommands(da, conn); 65 setupUserCommands(da, conn);
69 da.Fill(ds.Tables["users"]); 66 da.Fill(ds.Tables["users"]);
70 } 67 }
71 68
72 return; 69 return;
73 } 70 }
74 71
@@ -79,16 +76,21 @@ namespace OpenSim.Framework.Data.SQLite
79 /// <returns>A user profile</returns> 76 /// <returns>A user profile</returns>
80 public UserProfileData GetUserByUUID(LLUUID uuid) 77 public UserProfileData GetUserByUUID(LLUUID uuid)
81 { 78 {
82 lock (ds) { 79 lock (ds)
80 {
83 DataRow row = ds.Tables["users"].Rows.Find(uuid); 81 DataRow row = ds.Tables["users"].Rows.Find(uuid);
84 if(row != null) { 82 if (row != null)
83 {
85 UserProfileData user = buildUserProfile(row); 84 UserProfileData user = buildUserProfile(row);
86 row = ds.Tables["useragents"].Rows.Find(uuid); 85 row = ds.Tables["useragents"].Rows.Find(uuid);
87 if(row != null) { 86 if (row != null)
87 {
88 user.currentAgent = buildUserAgent(row); 88 user.currentAgent = buildUserAgent(row);
89 } 89 }
90 return user; 90 return user;
91 } else { 91 }
92 else
93 {
92 return null; 94 return null;
93 } 95 }
94 } 96 }
@@ -113,16 +115,21 @@ namespace OpenSim.Framework.Data.SQLite
113 public UserProfileData GetUserByName(string fname, string lname) 115 public UserProfileData GetUserByName(string fname, string lname)
114 { 116 {
115 string select = "surname = '" + lname + "' and username = '" + fname + "'"; 117 string select = "surname = '" + lname + "' and username = '" + fname + "'";
116 lock (ds) { 118 lock (ds)
119 {
117 DataRow[] rows = ds.Tables["users"].Select(select); 120 DataRow[] rows = ds.Tables["users"].Select(select);
118 if(rows.Length > 0) { 121 if (rows.Length > 0)
122 {
119 UserProfileData user = buildUserProfile(rows[0]); 123 UserProfileData user = buildUserProfile(rows[0]);
120 DataRow row = ds.Tables["useragents"].Rows.Find(user.UUID); 124 DataRow row = ds.Tables["useragents"].Rows.Find(user.UUID);
121 if(row != null) { 125 if (row != null)
126 {
122 user.currentAgent = buildUserAgent(row); 127 user.currentAgent = buildUserAgent(row);
123 } 128 }
124 return user; 129 return user;
125 } else { 130 }
131 else
132 {
126 return null; 133 return null;
127 } 134 }
128 } 135 }
@@ -134,7 +141,7 @@ namespace OpenSim.Framework.Data.SQLite
134 /// <param name="uuid">The users account ID</param> 141 /// <param name="uuid">The users account ID</param>
135 /// <returns>A matching users profile</returns> 142 /// <returns>A matching users profile</returns>
136 public UserAgentData GetAgentByUUID(LLUUID uuid) 143 public UserAgentData GetAgentByUUID(LLUUID uuid)
137 { 144 {
138 try 145 try
139 { 146 {
140 return GetUserByUUID(uuid).currentAgent; 147 return GetUserByUUID(uuid).currentAgent;
@@ -165,7 +172,7 @@ namespace OpenSim.Framework.Data.SQLite
165 { 172 {
166 try 173 try
167 { 174 {
168 return GetUserByName(fname,lname).currentAgent; 175 return GetUserByName(fname, lname).currentAgent;
169 } 176 }
170 catch (Exception) 177 catch (Exception)
171 { 178 {
@@ -180,8 +187,9 @@ namespace OpenSim.Framework.Data.SQLite
180 public void AddNewUserProfile(UserProfileData user) 187 public void AddNewUserProfile(UserProfileData user)
181 { 188 {
182 DataTable users = ds.Tables["users"]; 189 DataTable users = ds.Tables["users"];
183 lock (ds) { 190 lock (ds)
184 DataRow row = users.Rows.Find(user.UUID); 191 {
192 DataRow row = users.Rows.Find(user.UUID);
185 if (row == null) 193 if (row == null)
186 { 194 {
187 row = users.NewRow(); 195 row = users.NewRow();
@@ -192,10 +200,11 @@ namespace OpenSim.Framework.Data.SQLite
192 { 200 {
193 fillUserRow(row, user); 201 fillUserRow(row, user);
194 } 202 }
195 203
196 if(user.currentAgent != null) { 204 if (user.currentAgent != null)
205 {
197 DataTable ua = ds.Tables["useragents"]; 206 DataTable ua = ds.Tables["useragents"];
198 row = ua.Rows.Find(user.UUID); 207 row = ua.Rows.Find(user.UUID);
199 if (row == null) 208 if (row == null)
200 { 209 {
201 row = ua.NewRow(); 210 row = ua.NewRow();
@@ -207,12 +216,13 @@ namespace OpenSim.Framework.Data.SQLite
207 fillUserAgentRow(row, user.currentAgent); 216 fillUserAgentRow(row, user.currentAgent);
208 } 217 }
209 } 218 }
210 MainLog.Instance.Verbose("SQLITE", "Syncing user database: " + ds.Tables["users"].Rows.Count + " users stored"); 219 MainLog.Instance.Verbose("SQLITE",
220 "Syncing user database: " + ds.Tables["users"].Rows.Count + " users stored");
211 // save changes off to disk 221 // save changes off to disk
212 da.Update(ds, "users"); 222 da.Update(ds, "users");
213 } 223 }
214 } 224 }
215 225
216 /// <summary> 226 /// <summary>
217 /// Creates a new user profile 227 /// Creates a new user profile
218 /// </summary> 228 /// </summary>
@@ -220,10 +230,13 @@ namespace OpenSim.Framework.Data.SQLite
220 /// <returns>True on success, false on error</returns> 230 /// <returns>True on success, false on error</returns>
221 public bool UpdateUserProfile(UserProfileData user) 231 public bool UpdateUserProfile(UserProfileData user)
222 { 232 {
223 try { 233 try
234 {
224 AddNewUserProfile(user); 235 AddNewUserProfile(user);
225 return true; 236 return true;
226 } catch (Exception) { 237 }
238 catch (Exception)
239 {
227 return false; 240 return false;
228 } 241 }
229 } 242 }
@@ -279,51 +292,51 @@ namespace OpenSim.Framework.Data.SQLite
279 { 292 {
280 return "0.1"; 293 return "0.1";
281 } 294 }
282 295
283 /*********************************************************************** 296 /***********************************************************************
284 * 297 *
285 * DataTable creation 298 * DataTable creation
286 * 299 *
287 **********************************************************************/ 300 **********************************************************************/
288 /*********************************************************************** 301 /***********************************************************************
289 * 302 *
290 * Database Definition Functions 303 * Database Definition Functions
291 * 304 *
292 * This should be db agnostic as we define them in ADO.NET terms 305 * This should be db agnostic as we define them in ADO.NET terms
293 * 306 *
294 **********************************************************************/ 307 **********************************************************************/
295 308
296 private DataTable createUsersTable() 309 private DataTable createUsersTable()
297 { 310 {
298 DataTable users = new DataTable("users"); 311 DataTable users = new DataTable("users");
299 312
300 createCol(users, "UUID", typeof(System.String)); 313 createCol(users, "UUID", typeof (String));
301 createCol(users, "username", typeof(System.String)); 314 createCol(users, "username", typeof (String));
302 createCol(users, "surname", typeof(System.String)); 315 createCol(users, "surname", typeof (String));
303 createCol(users, "passwordHash", typeof(System.String)); 316 createCol(users, "passwordHash", typeof (String));
304 createCol(users, "passwordSalt", typeof(System.String)); 317 createCol(users, "passwordSalt", typeof (String));
305 318
306 createCol(users, "homeRegionX", typeof(System.Int32)); 319 createCol(users, "homeRegionX", typeof (Int32));
307 createCol(users, "homeRegionY", typeof(System.Int32)); 320 createCol(users, "homeRegionY", typeof (Int32));
308 createCol(users, "homeLocationX", typeof(System.Double)); 321 createCol(users, "homeLocationX", typeof (Double));
309 createCol(users, "homeLocationY", typeof(System.Double)); 322 createCol(users, "homeLocationY", typeof (Double));
310 createCol(users, "homeLocationZ", typeof(System.Double)); 323 createCol(users, "homeLocationZ", typeof (Double));
311 createCol(users, "homeLookAtX", typeof(System.Double)); 324 createCol(users, "homeLookAtX", typeof (Double));
312 createCol(users, "homeLookAtY", typeof(System.Double)); 325 createCol(users, "homeLookAtY", typeof (Double));
313 createCol(users, "homeLookAtZ", typeof(System.Double)); 326 createCol(users, "homeLookAtZ", typeof (Double));
314 createCol(users, "created", typeof(System.Int32)); 327 createCol(users, "created", typeof (Int32));
315 createCol(users, "lastLogin", typeof(System.Int32)); 328 createCol(users, "lastLogin", typeof (Int32));
316 createCol(users, "rootInventoryFolderID", typeof(System.String)); 329 createCol(users, "rootInventoryFolderID", typeof (String));
317 createCol(users, "userInventoryURI", typeof(System.String)); 330 createCol(users, "userInventoryURI", typeof (String));
318 createCol(users, "userAssetURI", typeof(System.String)); 331 createCol(users, "userAssetURI", typeof (String));
319 createCol(users, "profileCanDoMask", typeof(System.Int32)); 332 createCol(users, "profileCanDoMask", typeof (Int32));
320 createCol(users, "profileWantDoMask", typeof(System.Int32)); 333 createCol(users, "profileWantDoMask", typeof (Int32));
321 createCol(users, "profileAboutText", typeof(System.String)); 334 createCol(users, "profileAboutText", typeof (String));
322 createCol(users, "profileFirstText", typeof(System.String)); 335 createCol(users, "profileFirstText", typeof (String));
323 createCol(users, "profileImage", typeof(System.String)); 336 createCol(users, "profileImage", typeof (String));
324 createCol(users, "profileFirstImage", typeof(System.String)); 337 createCol(users, "profileFirstImage", typeof (String));
325 // Add in contraints 338 // Add in contraints
326 users.PrimaryKey = new DataColumn[] { users.Columns["UUID"] }; 339 users.PrimaryKey = new DataColumn[] {users.Columns["UUID"]};
327 return users; 340 return users;
328 } 341 }
329 342
@@ -331,27 +344,27 @@ namespace OpenSim.Framework.Data.SQLite
331 { 344 {
332 DataTable ua = new DataTable("useragents"); 345 DataTable ua = new DataTable("useragents");
333 // this is the UUID of the user 346 // this is the UUID of the user
334 createCol(ua, "UUID", typeof(System.String)); 347 createCol(ua, "UUID", typeof (String));
335 createCol(ua, "agentIP", typeof(System.String)); 348 createCol(ua, "agentIP", typeof (String));
336 createCol(ua, "agentPort", typeof(System.Int32)); 349 createCol(ua, "agentPort", typeof (Int32));
337 createCol(ua, "agentOnline", typeof(System.Boolean)); 350 createCol(ua, "agentOnline", typeof (Boolean));
338 createCol(ua, "sessionID", typeof(System.String)); 351 createCol(ua, "sessionID", typeof (String));
339 createCol(ua, "secureSessionID", typeof(System.String)); 352 createCol(ua, "secureSessionID", typeof (String));
340 createCol(ua, "regionID", typeof(System.String)); 353 createCol(ua, "regionID", typeof (String));
341 createCol(ua, "loginTime", typeof(System.Int32)); 354 createCol(ua, "loginTime", typeof (Int32));
342 createCol(ua, "logoutTime", typeof(System.Int32)); 355 createCol(ua, "logoutTime", typeof (Int32));
343 createCol(ua, "currentRegion", typeof(System.String)); 356 createCol(ua, "currentRegion", typeof (String));
344 createCol(ua, "currentHandle", typeof(System.Int32)); 357 createCol(ua, "currentHandle", typeof (Int32));
345 // vectors 358 // vectors
346 createCol(ua, "currentPosX", typeof(System.Double)); 359 createCol(ua, "currentPosX", typeof (Double));
347 createCol(ua, "currentPosY", typeof(System.Double)); 360 createCol(ua, "currentPosY", typeof (Double));
348 createCol(ua, "currentPosZ", typeof(System.Double)); 361 createCol(ua, "currentPosZ", typeof (Double));
349 // constraints 362 // constraints
350 ua.PrimaryKey = new DataColumn[] { ua.Columns["UUID"] }; 363 ua.PrimaryKey = new DataColumn[] {ua.Columns["UUID"]};
351 364
352 return ua; 365 return ua;
353 } 366 }
354 367
355 /*********************************************************************** 368 /***********************************************************************
356 * 369 *
357 * Convert between ADO.NET <=> OpenSim Objects 370 * Convert between ADO.NET <=> OpenSim Objects
@@ -366,35 +379,35 @@ namespace OpenSim.Framework.Data.SQLite
366 // interesting has to be done to actually get these values 379 // interesting has to be done to actually get these values
367 // back out. Not enough time to figure it out yet. 380 // back out. Not enough time to figure it out yet.
368 UserProfileData user = new UserProfileData(); 381 UserProfileData user = new UserProfileData();
369 user.UUID = new LLUUID((String)row["UUID"]); 382 user.UUID = new LLUUID((String) row["UUID"]);
370 user.username = (String)row["username"]; 383 user.username = (String) row["username"];
371 user.surname = (String)row["surname"]; 384 user.surname = (String) row["surname"];
372 user.passwordHash = (String)row["passwordHash"]; 385 user.passwordHash = (String) row["passwordHash"];
373 user.passwordSalt = (String)row["passwordSalt"]; 386 user.passwordSalt = (String) row["passwordSalt"];
374 387
375 user.homeRegionX = Convert.ToUInt32(row["homeRegionX"]); 388 user.homeRegionX = Convert.ToUInt32(row["homeRegionX"]);
376 user.homeRegionY = Convert.ToUInt32(row["homeRegionY"]); 389 user.homeRegionY = Convert.ToUInt32(row["homeRegionY"]);
377 user.homeLocation = new LLVector3( 390 user.homeLocation = new LLVector3(
378 Convert.ToSingle(row["homeLocationX"]), 391 Convert.ToSingle(row["homeLocationX"]),
379 Convert.ToSingle(row["homeLocationY"]), 392 Convert.ToSingle(row["homeLocationY"]),
380 Convert.ToSingle(row["homeLocationZ"]) 393 Convert.ToSingle(row["homeLocationZ"])
381 ); 394 );
382 user.homeLookAt = new LLVector3( 395 user.homeLookAt = new LLVector3(
383 Convert.ToSingle(row["homeLookAtX"]), 396 Convert.ToSingle(row["homeLookAtX"]),
384 Convert.ToSingle(row["homeLookAtY"]), 397 Convert.ToSingle(row["homeLookAtY"]),
385 Convert.ToSingle(row["homeLookAtZ"]) 398 Convert.ToSingle(row["homeLookAtZ"])
386 ); 399 );
387 user.created = Convert.ToInt32(row["created"]); 400 user.created = Convert.ToInt32(row["created"]);
388 user.lastLogin = Convert.ToInt32(row["lastLogin"]); 401 user.lastLogin = Convert.ToInt32(row["lastLogin"]);
389 user.rootInventoryFolderID = new LLUUID((String)row["rootInventoryFolderID"]); 402 user.rootInventoryFolderID = new LLUUID((String) row["rootInventoryFolderID"]);
390 user.userInventoryURI = (String)row["userInventoryURI"]; 403 user.userInventoryURI = (String) row["userInventoryURI"];
391 user.userAssetURI = (String)row["userAssetURI"]; 404 user.userAssetURI = (String) row["userAssetURI"];
392 user.profileCanDoMask = Convert.ToUInt32(row["profileCanDoMask"]); 405 user.profileCanDoMask = Convert.ToUInt32(row["profileCanDoMask"]);
393 user.profileWantDoMask = Convert.ToUInt32(row["profileWantDoMask"]); 406 user.profileWantDoMask = Convert.ToUInt32(row["profileWantDoMask"]);
394 user.profileAboutText = (String)row["profileAboutText"]; 407 user.profileAboutText = (String) row["profileAboutText"];
395 user.profileFirstText = (String)row["profileFirstText"]; 408 user.profileFirstText = (String) row["profileFirstText"];
396 user.profileImage = new LLUUID((String)row["profileImage"]); 409 user.profileImage = new LLUUID((String) row["profileImage"]);
397 user.profileFirstImage = new LLUUID((String)row["profileFirstImage"]); 410 user.profileFirstImage = new LLUUID((String) row["profileFirstImage"]);
398 return user; 411 return user;
399 } 412 }
400 413
@@ -405,8 +418,8 @@ namespace OpenSim.Framework.Data.SQLite
405 row["surname"] = user.surname; 418 row["surname"] = user.surname;
406 row["passwordHash"] = user.passwordHash; 419 row["passwordHash"] = user.passwordHash;
407 row["passwordSalt"] = user.passwordSalt; 420 row["passwordSalt"] = user.passwordSalt;
408 421
409 422
410 row["homeRegionX"] = user.homeRegionX; 423 row["homeRegionX"] = user.homeRegionX;
411 row["homeRegionY"] = user.homeRegionY; 424 row["homeRegionY"] = user.homeRegionY;
412 row["homeLocationX"] = user.homeLocation.X; 425 row["homeLocationX"] = user.homeLocation.X;
@@ -427,10 +440,12 @@ namespace OpenSim.Framework.Data.SQLite
427 row["profileFirstText"] = user.profileFirstText; 440 row["profileFirstText"] = user.profileFirstText;
428 row["profileImage"] = user.profileImage; 441 row["profileImage"] = user.profileImage;
429 row["profileFirstImage"] = user.profileFirstImage; 442 row["profileFirstImage"] = user.profileFirstImage;
430 443
431 // ADO.NET doesn't handle NULL very well 444 // ADO.NET doesn't handle NULL very well
432 foreach (DataColumn col in ds.Tables["users"].Columns) { 445 foreach (DataColumn col in ds.Tables["users"].Columns)
433 if (row[col] == null) { 446 {
447 if (row[col] == null)
448 {
434 row[col] = ""; 449 row[col] = "";
435 } 450 }
436 } 451 }
@@ -439,33 +454,33 @@ namespace OpenSim.Framework.Data.SQLite
439 private UserAgentData buildUserAgent(DataRow row) 454 private UserAgentData buildUserAgent(DataRow row)
440 { 455 {
441 UserAgentData ua = new UserAgentData(); 456 UserAgentData ua = new UserAgentData();
442 457
443 ua.UUID = new LLUUID((String)row["UUID"]); 458 ua.UUID = new LLUUID((String) row["UUID"]);
444 ua.agentIP = (String)row["agentIP"]; 459 ua.agentIP = (String) row["agentIP"];
445 ua.agentPort = Convert.ToUInt32(row["agentPort"]); 460 ua.agentPort = Convert.ToUInt32(row["agentPort"]);
446 ua.agentOnline = Convert.ToBoolean(row["agentOnline"]); 461 ua.agentOnline = Convert.ToBoolean(row["agentOnline"]);
447 ua.sessionID = new LLUUID((String)row["sessionID"]); 462 ua.sessionID = new LLUUID((String) row["sessionID"]);
448 ua.secureSessionID = new LLUUID((String)row["secureSessionID"]); 463 ua.secureSessionID = new LLUUID((String) row["secureSessionID"]);
449 ua.regionID = new LLUUID((String)row["regionID"]); 464 ua.regionID = new LLUUID((String) row["regionID"]);
450 ua.loginTime = Convert.ToInt32(row["loginTime"]); 465 ua.loginTime = Convert.ToInt32(row["loginTime"]);
451 ua.logoutTime = Convert.ToInt32(row["logoutTime"]); 466 ua.logoutTime = Convert.ToInt32(row["logoutTime"]);
452 ua.currentRegion = new LLUUID((String)row["currentRegion"]); 467 ua.currentRegion = new LLUUID((String) row["currentRegion"]);
453 ua.currentHandle = Convert.ToUInt32(row["currentHandle"]); 468 ua.currentHandle = Convert.ToUInt32(row["currentHandle"]);
454 ua.currentPos = new LLVector3( 469 ua.currentPos = new LLVector3(
455 Convert.ToSingle(row["currentPosX"]), 470 Convert.ToSingle(row["currentPosX"]),
456 Convert.ToSingle(row["currentPosY"]), 471 Convert.ToSingle(row["currentPosY"]),
457 Convert.ToSingle(row["currentPosZ"]) 472 Convert.ToSingle(row["currentPosZ"])
458 ); 473 );
459 return ua; 474 return ua;
460 } 475 }
461 476
462 private void fillUserAgentRow(DataRow row, UserAgentData ua) 477 private void fillUserAgentRow(DataRow row, UserAgentData ua)
463 { 478 {
464 row["UUID"] = ua.UUID; 479 row["UUID"] = ua.UUID;
465 row["agentIP"] = ua.agentIP; 480 row["agentIP"] = ua.agentIP;
466 row["agentPort"] = ua.agentPort; 481 row["agentPort"] = ua.agentPort;
467 row["agentOnline"] = ua.agentOnline; 482 row["agentOnline"] = ua.agentOnline;
468 row["sessionID"] = ua.sessionID; 483 row["sessionID"] = ua.sessionID;
469 row["secureSessionID"] = ua.secureSessionID; 484 row["secureSessionID"] = ua.secureSessionID;
470 row["regionID"] = ua.regionID; 485 row["regionID"] = ua.regionID;
471 row["loginTime"] = ua.loginTime; 486 row["loginTime"] = ua.loginTime;
@@ -496,18 +511,18 @@ namespace OpenSim.Framework.Data.SQLite
496 da.UpdateCommand.Connection = conn; 511 da.UpdateCommand.Connection = conn;
497 512
498 SqliteCommand delete = new SqliteCommand("delete from users where UUID = :UUID"); 513 SqliteCommand delete = new SqliteCommand("delete from users where UUID = :UUID");
499 delete.Parameters.Add(createSqliteParameter("UUID", typeof(System.String))); 514 delete.Parameters.Add(createSqliteParameter("UUID", typeof (String)));
500 delete.Connection = conn; 515 delete.Connection = conn;
501 da.DeleteCommand = delete; 516 da.DeleteCommand = delete;
502 } 517 }
503 518
504 private void InitDB(SqliteConnection conn) 519 private void InitDB(SqliteConnection conn)
505 { 520 {
506 string createUsers = defineTable(createUsersTable()); 521 string createUsers = defineTable(createUsersTable());
507 SqliteCommand pcmd = new SqliteCommand(createUsers, conn); 522 SqliteCommand pcmd = new SqliteCommand(createUsers, conn);
508 conn.Open(); 523 conn.Open();
509 pcmd.ExecuteNonQuery(); 524 pcmd.ExecuteNonQuery();
510 conn.Close(); 525 conn.Close();
511 } 526 }
512 527
513 private bool TestTables(SqliteConnection conn) 528 private bool TestTables(SqliteConnection conn)
@@ -515,14 +530,16 @@ namespace OpenSim.Framework.Data.SQLite
515 SqliteCommand cmd = new SqliteCommand(userSelect, conn); 530 SqliteCommand cmd = new SqliteCommand(userSelect, conn);
516 SqliteDataAdapter pDa = new SqliteDataAdapter(cmd); 531 SqliteDataAdapter pDa = new SqliteDataAdapter(cmd);
517 DataSet tmpDS = new DataSet(); 532 DataSet tmpDS = new DataSet();
518 try { 533 try
534 {
519 pDa.Fill(tmpDS, "users"); 535 pDa.Fill(tmpDS, "users");
520 } catch (Mono.Data.SqliteClient.SqliteSyntaxException) { 536 }
537 catch (SqliteSyntaxException)
538 {
521 MainLog.Instance.Verbose("DATASTORE", "SQLite Database doesn't exist... creating"); 539 MainLog.Instance.Verbose("DATASTORE", "SQLite Database doesn't exist... creating");
522 InitDB(conn); 540 InitDB(conn);
523 } 541 }
524 return true; 542 return true;
525 } 543 }
526
527 } 544 }
528} 545} \ No newline at end of file