aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs
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/SQLiteAuthenticationData.cs
parentRestored mising m_Connection. (diff)
downloadopensim-SC_OLD-8a4947f8c75a2dbcd8c13dbff9ad2eff52711f0e.zip
opensim-SC_OLD-8a4947f8c75a2dbcd8c13dbff9ad2eff52711f0e.tar.gz
opensim-SC_OLD-8a4947f8c75a2dbcd8c13dbff9ad2eff52711f0e.tar.bz2
opensim-SC_OLD-8a4947f8c75a2dbcd8c13dbff9ad2eff52711f0e.tar.xz
SQLite connector for UserAccounts and Auth works. Yey!
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/SQLite/SQLiteAuthenticationData.cs69
1 files changed, 41 insertions, 28 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