diff options
author | Diva Canto | 2010-02-20 20:13:38 -0800 |
---|---|---|
committer | Diva Canto | 2010-02-20 20:13:38 -0800 |
commit | df59d098b319367394bdeb898d7fd7dacd7104ec (patch) | |
tree | 04d6b7214a1773a686d6fab6f53e8ecddd6a7bf7 /OpenSim/Data | |
parent | Added UserAccountData and auth to the SQLite connector. Compiles, runs, but a... (diff) | |
download | opensim-SC-df59d098b319367394bdeb898d7fd7dacd7104ec.zip opensim-SC-df59d098b319367394bdeb898d7fd7dacd7104ec.tar.gz opensim-SC-df59d098b319367394bdeb898d7fd7dacd7104ec.tar.bz2 opensim-SC-df59d098b319367394bdeb898d7fd7dacd7104ec.tar.xz |
SQLite connector better, but access to tables still doesn't work.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteAuthenticationData.cs | 61 | ||||
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteFramework.cs | 13 | ||||
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs | 16 |
3 files changed, 62 insertions, 28 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs b/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs index 271ed47..7dab6bf 100644 --- a/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs +++ b/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs | |||
@@ -52,12 +52,16 @@ namespace OpenSim.Data.SQLite | |||
52 | 52 | ||
53 | if (!m_initialized) | 53 | if (!m_initialized) |
54 | { | 54 | { |
55 | m_Connection = new SqliteConnection(connectionString); | ||
56 | m_Connection.Open(); | ||
57 | |||
55 | using (SqliteConnection dbcon = new SqliteConnection(m_connectionString)) | 58 | using (SqliteConnection dbcon = new SqliteConnection(m_connectionString)) |
56 | { | 59 | { |
57 | dbcon.Open(); | 60 | dbcon.Open(); |
58 | Migration m = new Migration(dbcon, GetType().Assembly, "AuthStore"); | 61 | Migration m = new Migration(dbcon, GetType().Assembly, "AuthStore"); |
59 | m.Update(); | 62 | m.Update(); |
60 | } | 63 | } |
64 | |||
61 | m_initialized = true; | 65 | m_initialized = true; |
62 | } | 66 | } |
63 | } | 67 | } |
@@ -105,7 +109,7 @@ namespace OpenSim.Data.SQLite | |||
105 | } | 109 | } |
106 | 110 | ||
107 | public bool Store(AuthenticationData data) | 111 | public bool Store(AuthenticationData data) |
108 | { | 112 | { |
109 | if (data.Data.ContainsKey("UUID")) | 113 | if (data.Data.ContainsKey("UUID")) |
110 | data.Data.Remove("UUID"); | 114 | data.Data.Remove("UUID"); |
111 | 115 | ||
@@ -117,31 +121,60 @@ namespace OpenSim.Data.SQLite | |||
117 | 121 | ||
118 | SqliteCommand cmd = new SqliteCommand(); | 122 | SqliteCommand cmd = new SqliteCommand(); |
119 | 123 | ||
120 | string update = "update `"+m_Realm+"` set "; | 124 | if (Get(data.PrincipalID) != null) |
121 | bool first = true; | ||
122 | foreach (string field in fields) | ||
123 | { | 125 | { |
124 | if (!first) | ||
125 | update += ", "; | ||
126 | update += "`" + field + "` = " + data.Data[field]; | ||
127 | 126 | ||
128 | first = false; | ||
129 | 127 | ||
130 | } | 128 | string update = "update `" + m_Realm + "` set "; |
129 | bool first = true; | ||
130 | foreach (string field in fields) | ||
131 | { | ||
132 | if (!first) | ||
133 | update += ", "; | ||
134 | update += "`" + field + "` = '" + data.Data[field] + "'"; | ||
131 | 135 | ||
132 | update += " where UUID = '" + data.PrincipalID.ToString() + "'"; | 136 | first = false; |
133 | 137 | ||
134 | cmd.CommandText = update; | 138 | } |
139 | |||
140 | update += " where UUID = '" + data.PrincipalID.ToString() + "'"; | ||
141 | |||
142 | cmd.CommandText = update; | ||
143 | Console.WriteLine("XXX " + cmd.CommandText); | ||
144 | try | ||
145 | { | ||
146 | if (ExecuteNonQuery(cmd) < 1) | ||
147 | { | ||
148 | cmd.Dispose(); | ||
149 | return false; | ||
150 | } | ||
151 | } | ||
152 | catch | ||
153 | { | ||
154 | cmd.Dispose(); | ||
155 | return false; | ||
156 | } | ||
157 | } | ||
135 | 158 | ||
136 | if (ExecuteNonQuery(cmd) < 1) | 159 | else |
137 | { | 160 | { |
138 | string insert = "insert into `" + m_Realm + "` (`UUID`, `" + | 161 | string insert = "insert into `" + m_Realm + "` (`UUID`, `" + |
139 | String.Join("`, `", fields) + | 162 | String.Join("`, `", fields) + |
140 | "`) values ('" + data.PrincipalID.ToString() + "', " + String.Join(", '", values) + "')"; | 163 | "`) values ('" + data.PrincipalID.ToString() + "', '" + String.Join("', '", values) + "')"; |
141 | 164 | ||
142 | cmd.CommandText = insert; | 165 | cmd.CommandText = insert; |
143 | 166 | ||
144 | if (ExecuteNonQuery(cmd) < 1) | 167 | Console.WriteLine("XXX " + cmd.CommandText); |
168 | |||
169 | try | ||
170 | { | ||
171 | if (ExecuteNonQuery(cmd) < 1) | ||
172 | { | ||
173 | cmd.Dispose(); | ||
174 | return false; | ||
175 | } | ||
176 | } | ||
177 | catch | ||
145 | { | 178 | { |
146 | cmd.Dispose(); | 179 | cmd.Dispose(); |
147 | return false; | 180 | return false; |
diff --git a/OpenSim/Data/SQLite/SQLiteFramework.cs b/OpenSim/Data/SQLite/SQLiteFramework.cs index d745c92..2a8a022 100644 --- a/OpenSim/Data/SQLite/SQLiteFramework.cs +++ b/OpenSim/Data/SQLite/SQLiteFramework.cs | |||
@@ -40,17 +40,12 @@ namespace OpenSim.Data.SQLite | |||
40 | /// </summary> | 40 | /// </summary> |
41 | public class SQLiteFramework | 41 | public class SQLiteFramework |
42 | { | 42 | { |
43 | protected static SqliteConnection m_Connection; | 43 | protected SqliteConnection m_Connection; |
44 | private bool m_initialized; | ||
45 | 44 | ||
46 | protected SQLiteFramework(string connectionString) | 45 | protected SQLiteFramework(string connectionString) |
47 | { | 46 | { |
48 | if (!m_initialized) | 47 | //m_Connection = new SqliteConnection(connectionString); |
49 | { | 48 | //m_Connection.Open(); |
50 | m_Connection = new SqliteConnection(connectionString); | ||
51 | m_Connection.Open(); | ||
52 | m_initialized = true; | ||
53 | } | ||
54 | } | 49 | } |
55 | 50 | ||
56 | ////////////////////////////////////////////////////////////// | 51 | ////////////////////////////////////////////////////////////// |
@@ -63,6 +58,7 @@ namespace OpenSim.Data.SQLite | |||
63 | lock (m_Connection) | 58 | lock (m_Connection) |
64 | { | 59 | { |
65 | cmd.Connection = m_Connection; | 60 | cmd.Connection = m_Connection; |
61 | Console.WriteLine("XXX " + cmd.CommandText); | ||
66 | 62 | ||
67 | return cmd.ExecuteNonQuery(); | 63 | return cmd.ExecuteNonQuery(); |
68 | } | 64 | } |
@@ -75,6 +71,7 @@ namespace OpenSim.Data.SQLite | |||
75 | newConnection.Open(); | 71 | newConnection.Open(); |
76 | 72 | ||
77 | cmd.Connection = newConnection; | 73 | cmd.Connection = newConnection; |
74 | Console.WriteLine("XXX " + cmd.CommandText); | ||
78 | return cmd.ExecuteReader(); | 75 | return cmd.ExecuteReader(); |
79 | } | 76 | } |
80 | 77 | ||
diff --git a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs index d29efa0..98943a0 100644 --- a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs +++ b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs | |||
@@ -57,6 +57,9 @@ namespace OpenSim.Data.SQLite | |||
57 | 57 | ||
58 | if (!m_initialized) | 58 | if (!m_initialized) |
59 | { | 59 | { |
60 | m_Connection = new SqliteConnection(connectionString); | ||
61 | m_Connection.Open(); | ||
62 | |||
60 | if (storeName != String.Empty) | 63 | if (storeName != String.Empty) |
61 | { | 64 | { |
62 | Assembly assem = GetType().Assembly; | 65 | Assembly assem = GetType().Assembly; |
@@ -64,6 +67,7 @@ namespace OpenSim.Data.SQLite | |||
64 | Migration m = new Migration(m_Connection, assem, storeName); | 67 | Migration m = new Migration(m_Connection, assem, storeName); |
65 | m.Update(); | 68 | m.Update(); |
66 | } | 69 | } |
70 | |||
67 | m_initialized = true; | 71 | m_initialized = true; |
68 | } | 72 | } |
69 | 73 | ||
@@ -117,7 +121,7 @@ namespace OpenSim.Data.SQLite | |||
117 | for (int i = 0 ; i < fields.Length ; i++) | 121 | for (int i = 0 ; i < fields.Length ; i++) |
118 | { | 122 | { |
119 | cmd.Parameters.Add(new SqliteParameter(":" + fields[i], keys[i])); | 123 | cmd.Parameters.Add(new SqliteParameter(":" + fields[i], keys[i])); |
120 | terms.Add("`" + fields[i] + "` = :" + fields[i]); | 124 | terms.Add("`" + fields[i] + "`='" + keys[i] + "'"); |
121 | } | 125 | } |
122 | 126 | ||
123 | string where = String.Join(" and ", terms.ToArray()); | 127 | string where = String.Join(" and ", terms.ToArray()); |
@@ -215,8 +219,8 @@ namespace OpenSim.Data.SQLite | |||
215 | foreach (FieldInfo fi in m_Fields.Values) | 219 | foreach (FieldInfo fi in m_Fields.Values) |
216 | { | 220 | { |
217 | names.Add(fi.Name); | 221 | names.Add(fi.Name); |
218 | values.Add(":" + fi.Name); | 222 | values.Add(fi.GetValue(row).ToString()); |
219 | cmd.Parameters.Add(new SqliteParameter(":" + fi.Name, fi.GetValue(row).ToString())); | 223 | cmd.Parameters.Add(new SqliteParameter(fi.Name, fi.GetValue(row).ToString())); |
220 | } | 224 | } |
221 | 225 | ||
222 | if (m_DataField != null) | 226 | if (m_DataField != null) |
@@ -227,12 +231,12 @@ namespace OpenSim.Data.SQLite | |||
227 | foreach (KeyValuePair<string, string> kvp in data) | 231 | foreach (KeyValuePair<string, string> kvp in data) |
228 | { | 232 | { |
229 | names.Add(kvp.Key); | 233 | names.Add(kvp.Key); |
230 | values.Add(":" + kvp.Key); | 234 | values.Add(kvp.Value); |
231 | cmd.Parameters.Add(new SqliteParameter(":" + kvp.Key, kvp.Value)); | 235 | cmd.Parameters.Add(new SqliteParameter(kvp.Key, kvp.Value)); |
232 | } | 236 | } |
233 | } | 237 | } |
234 | 238 | ||
235 | query = String.Format("replace into {0} (`", m_Realm) + String.Join("`,`", names.ToArray()) + "`) values (" + String.Join(",", values.ToArray()) + ")"; | 239 | query = String.Format("replace into {0} (`", m_Realm) + String.Join("`,`", names.ToArray()) + "`) values ('" + String.Join("', '", values.ToArray()) + "')"; |
236 | 240 | ||
237 | cmd.CommandText = query; | 241 | cmd.CommandText = query; |
238 | 242 | ||