aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/SQLite
diff options
context:
space:
mode:
authorDiva Canto2010-02-21 08:47:24 -0800
committerDiva Canto2010-02-21 08:47:24 -0800
commit8a4947f8c75a2dbcd8c13dbff9ad2eff52711f0e (patch)
tree6f64f4d6f07eadd8e65296bbe85e3d49cdf20ea4 /OpenSim/Data/SQLite
parentRestored mising m_Connection. (diff)
downloadopensim-SC-8a4947f8c75a2dbcd8c13dbff9ad2eff52711f0e.zip
opensim-SC-8a4947f8c75a2dbcd8c13dbff9ad2eff52711f0e.tar.gz
opensim-SC-8a4947f8c75a2dbcd8c13dbff9ad2eff52711f0e.tar.bz2
opensim-SC-8a4947f8c75a2dbcd8c13dbff9ad2eff52711f0e.tar.xz
SQLite connector for UserAccounts and Auth works. Yey!
Diffstat (limited to 'OpenSim/Data/SQLite')
-rw-r--r--OpenSim/Data/SQLite/SQLiteAuthenticationData.cs69
-rw-r--r--OpenSim/Data/SQLite/SQLiteFramework.cs31
-rw-r--r--OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs16
-rw-r--r--OpenSim/Data/SQLite/SQLiteXInventoryData.cs6
4 files changed, 69 insertions, 53 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs b/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs
index d71c7eb..84ce775 100644
--- a/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs
+++ b/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs
@@ -42,6 +42,7 @@ namespace OpenSim.Data.SQLite
42 private int m_LastExpire; 42 private int m_LastExpire;
43 private string m_connectionString; 43 private string m_connectionString;
44 44
45 protected static SqliteConnection m_Connection;
45 private static bool m_initialized = false; 46 private static bool m_initialized = false;
46 47
47 public SQLiteAuthenticationData(string connectionString, string realm) 48 public SQLiteAuthenticationData(string connectionString, string realm)
@@ -55,11 +56,12 @@ namespace OpenSim.Data.SQLite
55 m_Connection = new SqliteConnection(connectionString); 56 m_Connection = new SqliteConnection(connectionString);
56 m_Connection.Open(); 57 m_Connection.Open();
57 58
58 using (SqliteConnection dbcon = new SqliteConnection(m_connectionString)) 59 using (SqliteConnection dbcon = (SqliteConnection)((ICloneable)m_Connection).Clone())
59 { 60 {
60 //dbcon.Open(); 61 dbcon.Open();
61 Migration m = new Migration(m_Connection, GetType().Assembly, "AuthStore"); 62 Migration m = new Migration(dbcon, GetType().Assembly, "AuthStore");
62 m.Update(); 63 m.Update();
64 dbcon.Close();
63 } 65 }
64 66
65 m_initialized = true; 67 m_initialized = true;
@@ -71,13 +73,13 @@ namespace OpenSim.Data.SQLite
71 AuthenticationData ret = new AuthenticationData(); 73 AuthenticationData ret = new AuthenticationData();
72 ret.Data = new Dictionary<string, object>(); 74 ret.Data = new Dictionary<string, object>();
73 75
74 using (SqliteConnection dbcon = new SqliteConnection(m_connectionString)) 76 SqliteCommand cmd = new SqliteCommand("select * from `" + m_Realm + "` where UUID = :PrincipalID");
75 { 77 cmd.Parameters.Add(new SqliteParameter(":PrincipalID", principalID.ToString()));
76 dbcon.Open();
77 SqliteCommand cmd = new SqliteCommand("select * from `" + m_Realm + "` where UUID = '" + principalID.ToString() + "'", dbcon);
78 78
79 IDataReader result = cmd.ExecuteReader(); 79 IDataReader result = ExecuteReader(cmd, m_Connection);
80 80
81 try
82 {
81 if (result.Read()) 83 if (result.Read())
82 { 84 {
83 ret.PrincipalID = principalID; 85 ret.PrincipalID = principalID;
@@ -106,6 +108,15 @@ namespace OpenSim.Data.SQLite
106 return null; 108 return null;
107 } 109 }
108 } 110 }
111 catch
112 {
113 }
114 finally
115 {
116 CloseCommand(cmd);
117 }
118
119 return null;
109 } 120 }
110 121
111 public bool Store(AuthenticationData data) 122 public bool Store(AuthenticationData data)
@@ -131,28 +142,28 @@ namespace OpenSim.Data.SQLite
131 { 142 {
132 if (!first) 143 if (!first)
133 update += ", "; 144 update += ", ";
134 update += "`" + field + "` = '" + data.Data[field] + "'"; 145 update += "`" + field + "` = :" + field;
146 cmd.Parameters.Add(new SqliteParameter(":" + field, data.Data[field]));
135 147
136 first = false; 148 first = false;
137
138 } 149 }
139 150
140 update += " where UUID = '" + data.PrincipalID.ToString() + "'"; 151 update += " where UUID = :UUID";
152 cmd.Parameters.Add(new SqliteParameter(":UUID", data.PrincipalID.ToString()));
141 153
142 cmd.CommandText = update; 154 cmd.CommandText = update;
143 Console.WriteLine("XXX " + cmd.CommandText);
144 try 155 try
145 { 156 {
146 if (ExecuteNonQuery(cmd) < 1) 157 if (ExecuteNonQuery(cmd, m_Connection) < 1)
147 { 158 {
148 cmd.Dispose(); 159 CloseCommand(cmd);
149 return false; 160 return false;
150 } 161 }
151 } 162 }
152 catch (Exception e) 163 catch (Exception e)
153 { 164 {
154 Console.WriteLine(e.ToString()); 165 Console.WriteLine(e.ToString());
155 cmd.Dispose(); 166 CloseCommand(cmd);
156 return false; 167 return false;
157 } 168 }
158 } 169 }
@@ -161,29 +172,31 @@ namespace OpenSim.Data.SQLite
161 { 172 {
162 string insert = "insert into `" + m_Realm + "` (`UUID`, `" + 173 string insert = "insert into `" + m_Realm + "` (`UUID`, `" +
163 String.Join("`, `", fields) + 174 String.Join("`, `", fields) +
164 "`) values ('" + data.PrincipalID.ToString() + "', '" + String.Join("', '", values) + "')"; 175 "`) values (:UUID, :" + String.Join(", :", fields) + ")";
165 176
166 cmd.CommandText = insert; 177 cmd.Parameters.Add(new SqliteParameter(":UUID", data.PrincipalID.ToString()));
178 foreach (string field in fields)
179 cmd.Parameters.Add(new SqliteParameter(":" + field, data.Data[field]));
167 180
168 Console.WriteLine("XXX " + cmd.CommandText); 181 cmd.CommandText = insert;
169 182
170 try 183 try
171 { 184 {
172 if (ExecuteNonQuery(cmd) < 1) 185 if (ExecuteNonQuery(cmd, m_Connection) < 1)
173 { 186 {
174 cmd.Dispose(); 187 CloseCommand(cmd);
175 return false; 188 return false;
176 } 189 }
177 } 190 }
178 catch (Exception e) 191 catch (Exception e)
179 { 192 {
180 Console.WriteLine(e.ToString()); 193 Console.WriteLine(e.ToString());
181 cmd.Dispose(); 194 CloseCommand(cmd);
182 return false; 195 return false;
183 } 196 }
184 } 197 }
185 198
186 cmd.Dispose(); 199 CloseCommand(cmd);
187 200
188 return true; 201 return true;
189 } 202 }
@@ -193,7 +206,7 @@ namespace OpenSim.Data.SQLite
193 SqliteCommand cmd = new SqliteCommand("update `" + m_Realm + 206 SqliteCommand cmd = new SqliteCommand("update `" + m_Realm +
194 "` set `" + item + "` = " + value + " where UUID = '" + principalID.ToString() + "'"); 207 "` set `" + item + "` = " + value + " where UUID = '" + principalID.ToString() + "'");
195 208
196 if (ExecuteNonQuery(cmd) > 0) 209 if (ExecuteNonQuery(cmd, m_Connection) > 0)
197 return true; 210 return true;
198 211
199 return false; 212 return false;
@@ -205,9 +218,9 @@ namespace OpenSim.Data.SQLite
205 DoExpire(); 218 DoExpire();
206 219
207 SqliteCommand cmd = new SqliteCommand("insert into tokens (UUID, token, validity) values ('" + principalID.ToString() + 220 SqliteCommand cmd = new SqliteCommand("insert into tokens (UUID, token, validity) values ('" + principalID.ToString() +
208 "', '" + token + "', datetime('now, 'localtime', '+" + lifetime.ToString() + " minutes'))"); 221 "', '" + token + "', datetime('now', 'localtime', '+" + lifetime.ToString() + " minutes'))");
209 222
210 if (ExecuteNonQuery(cmd) > 0) 223 if (ExecuteNonQuery(cmd, m_Connection) > 0)
211 { 224 {
212 cmd.Dispose(); 225 cmd.Dispose();
213 return true; 226 return true;
@@ -225,7 +238,7 @@ namespace OpenSim.Data.SQLite
225 SqliteCommand cmd = new SqliteCommand("update tokens set validity = datetime('now, 'localtime', '+" + lifetime.ToString() + 238 SqliteCommand cmd = new SqliteCommand("update tokens set validity = datetime('now, 'localtime', '+" + lifetime.ToString() +
226 " minutes') where UUID = '" + principalID.ToString() + "' and token = '" + token + "' and validity > datetime('now', 'localtime')"); 239 " minutes') where UUID = '" + principalID.ToString() + "' and token = '" + token + "' and validity > datetime('now', 'localtime')");
227 240
228 if (ExecuteNonQuery(cmd) > 0) 241 if (ExecuteNonQuery(cmd, m_Connection) > 0)
229 { 242 {
230 cmd.Dispose(); 243 cmd.Dispose();
231 return true; 244 return true;
@@ -238,8 +251,8 @@ namespace OpenSim.Data.SQLite
238 251
239 private void DoExpire() 252 private void DoExpire()
240 { 253 {
241 SqliteCommand cmd = new SqliteCommand("delete from tokens where validity < datetime('now, 'localtime')"); 254 SqliteCommand cmd = new SqliteCommand("delete from tokens where validity < datetime('now', 'localtime')");
242 ExecuteNonQuery(cmd); 255 ExecuteNonQuery(cmd, m_Connection);
243 256
244 cmd.Dispose(); 257 cmd.Dispose();
245 258
diff --git a/OpenSim/Data/SQLite/SQLiteFramework.cs b/OpenSim/Data/SQLite/SQLiteFramework.cs
index 54b104b..20b5085 100644
--- a/OpenSim/Data/SQLite/SQLiteFramework.cs
+++ b/OpenSim/Data/SQLite/SQLiteFramework.cs
@@ -42,7 +42,6 @@ namespace OpenSim.Data.SQLite
42 { 42 {
43 protected Object m_lockObject = new Object(); 43 protected Object m_lockObject = new Object();
44 44
45 protected static SqliteConnection m_Connection;
46 protected SQLiteFramework(string connectionString) 45 protected SQLiteFramework(string connectionString)
47 { 46 {
48 } 47 }
@@ -52,43 +51,41 @@ namespace OpenSim.Data.SQLite
52 // All non queries are funneled through one connection 51 // All non queries are funneled through one connection
53 // to increase performance a little 52 // to increase performance a little
54 // 53 //
55 protected int ExecuteNonQuery(SqliteCommand cmd) 54 protected int ExecuteNonQuery(SqliteCommand cmd, SqliteConnection connection)
56 { 55 {
57 lock (m_lockObject) 56 lock (connection)
58 { 57 {
59 SqliteConnection newConnection = 58 SqliteConnection newConnection =
60 (SqliteConnection)((ICloneable)m_Connection).Clone(); 59 (SqliteConnection)((ICloneable)connection).Clone();
61 newConnection.Open(); 60 newConnection.Open();
62 61
63 cmd.Connection = newConnection; 62 cmd.Connection = newConnection;
64 Console.WriteLine("XXX " + cmd.CommandText); 63 //Console.WriteLine("XXX " + cmd.CommandText);
65 64
66 return cmd.ExecuteNonQuery(); 65 return cmd.ExecuteNonQuery();
67 } 66 }
68 } 67 }
69 68
70 protected IDataReader ExecuteReader(SqliteCommand cmd) 69 protected IDataReader ExecuteReader(SqliteCommand cmd, SqliteConnection connection)
71 { 70 {
72 lock (m_lockObject) 71 lock (connection)
73 { 72 {
74 SqliteConnection newConnection = 73 SqliteConnection newConnection =
75 (SqliteConnection)((ICloneable)m_Connection).Clone(); 74 (SqliteConnection)((ICloneable)connection).Clone();
76 newConnection.Open(); 75 newConnection.Open();
77 76
78 cmd.Connection = newConnection; 77 cmd.Connection = newConnection;
79 Console.WriteLine("XXX " + cmd.CommandText); 78 //Console.WriteLine("XXX " + cmd.CommandText);
79
80 return cmd.ExecuteReader(); 80 return cmd.ExecuteReader();
81 } 81 }
82 } 82 }
83 83
84 protected void CloseReaderCommand(SqliteCommand cmd) 84 protected void CloseCommand(SqliteCommand cmd)
85 { 85 {
86 lock (m_lockObject) 86 cmd.Connection.Close();
87 { 87 cmd.Connection.Dispose();
88 cmd.Connection.Close(); 88 cmd.Dispose();
89 cmd.Connection.Dispose();
90 cmd.Dispose();
91 }
92 } 89 }
93 } 90 }
94} 91}
diff --git a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs
index e7e158d..b39bb19 100644
--- a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs
+++ b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs
@@ -48,6 +48,7 @@ namespace OpenSim.Data.SQLite
48 protected string m_Realm; 48 protected string m_Realm;
49 protected FieldInfo m_DataField = null; 49 protected FieldInfo m_DataField = null;
50 50
51 protected static SqliteConnection m_Connection;
51 private static bool m_initialized; 52 private static bool m_initialized;
52 53
53 public SQLiteGenericTableHandler(string connectionString, 54 public SQLiteGenericTableHandler(string connectionString,
@@ -63,9 +64,14 @@ namespace OpenSim.Data.SQLite
63 if (storeName != String.Empty) 64 if (storeName != String.Empty)
64 { 65 {
65 Assembly assem = GetType().Assembly; 66 Assembly assem = GetType().Assembly;
67 SqliteConnection newConnection =
68 (SqliteConnection)((ICloneable)m_Connection).Clone();
69 newConnection.Open();
66 70
67 Migration m = new Migration(m_Connection, assem, storeName); 71 Migration m = new Migration(newConnection, assem, storeName);
68 m.Update(); 72 m.Update();
73 newConnection.Close();
74 newConnection.Dispose();
69 } 75 }
70 76
71 m_initialized = true; 77 m_initialized = true;
@@ -136,7 +142,7 @@ namespace OpenSim.Data.SQLite
136 142
137 protected T[] DoQuery(SqliteCommand cmd) 143 protected T[] DoQuery(SqliteCommand cmd)
138 { 144 {
139 IDataReader reader = ExecuteReader(cmd); 145 IDataReader reader = ExecuteReader(cmd, m_Connection);
140 if (reader == null) 146 if (reader == null)
141 return new T[0]; 147 return new T[0];
142 148
@@ -191,7 +197,7 @@ namespace OpenSim.Data.SQLite
191 result.Add(row); 197 result.Add(row);
192 } 198 }
193 199
194 CloseReaderCommand(cmd); 200 CloseCommand(cmd);
195 201
196 return result.ToArray(); 202 return result.ToArray();
197 } 203 }
@@ -240,7 +246,7 @@ namespace OpenSim.Data.SQLite
240 246
241 cmd.CommandText = query; 247 cmd.CommandText = query;
242 248
243 if (ExecuteNonQuery(cmd) > 0) 249 if (ExecuteNonQuery(cmd, m_Connection) > 0)
244 return true; 250 return true;
245 251
246 return false; 252 return false;
@@ -253,7 +259,7 @@ namespace OpenSim.Data.SQLite
253 cmd.CommandText = String.Format("delete from {0} where `{1}` = :{1}", m_Realm, field); 259 cmd.CommandText = String.Format("delete from {0} where `{1}` = :{1}", m_Realm, field);
254 cmd.Parameters.Add(new SqliteParameter(field, val)); 260 cmd.Parameters.Add(new SqliteParameter(field, val));
255 261
256 if (ExecuteNonQuery(cmd) > 0) 262 if (ExecuteNonQuery(cmd, m_Connection) > 0)
257 return true; 263 return true;
258 264
259 return false; 265 return false;
diff --git a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs
index 5c93f88..a66e0c6 100644
--- a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs
+++ b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs
@@ -115,7 +115,7 @@ namespace OpenSim.Data.SQLite
115 cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParent)); 115 cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParent));
116 cmd.Parameters.Add(new SqliteParameter(":InventoryID", id)); 116 cmd.Parameters.Add(new SqliteParameter(":InventoryID", id));
117 117
118 return ExecuteNonQuery(cmd) == 0 ? false : true; 118 return ExecuteNonQuery(cmd, m_Connection) == 0 ? false : true;
119 } 119 }
120 120
121 public XInventoryItem[] GetActiveGestures(UUID principalID) 121 public XInventoryItem[] GetActiveGestures(UUID principalID)
@@ -137,7 +137,7 @@ namespace OpenSim.Data.SQLite
137 cmd.Parameters.Add(new SqliteParameter(":PrincipalID", principalID.ToString())); 137 cmd.Parameters.Add(new SqliteParameter(":PrincipalID", principalID.ToString()));
138 cmd.Parameters.Add(new SqliteParameter(":AssetID", assetID.ToString())); 138 cmd.Parameters.Add(new SqliteParameter(":AssetID", assetID.ToString()));
139 139
140 IDataReader reader = ExecuteReader(cmd); 140 IDataReader reader = ExecuteReader(cmd, m_Connection);
141 141
142 int perms = 0; 142 int perms = 0;
143 143
@@ -147,7 +147,7 @@ namespace OpenSim.Data.SQLite
147 } 147 }
148 148
149 reader.Close(); 149 reader.Close();
150 CloseReaderCommand(cmd); 150 CloseCommand(cmd);
151 151
152 return perms; 152 return perms;
153 } 153 }