diff options
author | UbitUmarov | 2019-08-26 03:00:28 +0100 |
---|---|---|
committer | UbitUmarov | 2019-08-26 03:00:28 +0100 |
commit | ab92dff5be6bd9c6a632b9128f970b4793446bb2 (patch) | |
tree | f4bb932496accffbf35221b003050c06f5292fb7 /OpenSim/Data/MySQL/MySQLGenericTableHandler.cs | |
parent | Fix console outputting raw format strings (diff) | |
download | opensim-SC-ab92dff5be6bd9c6a632b9128f970b4793446bb2.zip opensim-SC-ab92dff5be6bd9c6a632b9128f970b4793446bb2.tar.gz opensim-SC-ab92dff5be6bd9c6a632b9128f970b4793446bb2.tar.bz2 opensim-SC-ab92dff5be6bd9c6a632b9128f970b4793446bb2.tar.xz |
a few changes to db generic tables
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLGenericTableHandler.cs | 83 |
1 files changed, 58 insertions, 25 deletions
diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs index 1564140..ce228b5 100644 --- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs +++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs | |||
@@ -116,8 +116,40 @@ namespace OpenSim.Data.MySQL | |||
116 | } | 116 | } |
117 | 117 | ||
118 | public virtual T[] Get(string field, string key) | 118 | public virtual T[] Get(string field, string key) |
119 | { | ||
120 | using (MySqlCommand cmd = new MySqlCommand()) | ||
121 | { | ||
122 | cmd.Parameters.AddWithValue(field, key); | ||
123 | cmd.CommandText = string.Format("select * from {0} where `{1}` = ?{1}", m_Realm, field); | ||
124 | return DoQuery(cmd); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | public virtual T[] Get(string field, string[] keys) | ||
119 | { | 129 | { |
120 | return Get(new string[] { field }, new string[] { key }); | 130 | int flen = keys.Length; |
131 | if(flen == 0) | ||
132 | return new T[0]; | ||
133 | |||
134 | int flast = flen - 1; | ||
135 | StringBuilder sb = new StringBuilder(1024); | ||
136 | sb.AppendFormat("select * from {0} where {1} IN (?", m_Realm, field); | ||
137 | using (MySqlCommand cmd = new MySqlCommand()) | ||
138 | { | ||
139 | for (int i = 0 ; i < flen ; i++) | ||
140 | { | ||
141 | string fname = field + i.ToString(); | ||
142 | cmd.Parameters.AddWithValue(fname, keys[i]); | ||
143 | |||
144 | sb.Append(fname); | ||
145 | if(i < flast) | ||
146 | sb.Append(",?"); | ||
147 | else | ||
148 | sb.Append(")"); | ||
149 | } | ||
150 | cmd.CommandText = sb.ToString(); | ||
151 | return DoQuery(cmd); | ||
152 | } | ||
121 | } | 153 | } |
122 | 154 | ||
123 | public virtual T[] Get(string[] fields, string[] keys) | 155 | public virtual T[] Get(string[] fields, string[] keys) |
@@ -140,7 +172,7 @@ namespace OpenSim.Data.MySQL | |||
140 | for (int i = 0 ; i < flen ; i++) | 172 | for (int i = 0 ; i < flen ; i++) |
141 | { | 173 | { |
142 | cmd.Parameters.AddWithValue(fields[i], keys[i]); | 174 | cmd.Parameters.AddWithValue(fields[i], keys[i]); |
143 | if(i< flast) | 175 | if(i < flast) |
144 | sb.AppendFormat("`{0}` = ?{0} and ", fields[i]); | 176 | sb.AppendFormat("`{0}` = ?{0} and ", fields[i]); |
145 | else | 177 | else |
146 | sb.AppendFormat("`{0}` = ?{0} ", fields[i]); | 178 | sb.AppendFormat("`{0}` = ?{0} ", fields[i]); |
@@ -323,25 +355,26 @@ namespace OpenSim.Data.MySQL | |||
323 | // "[MYSQL GENERIC TABLE HANDLER]: Delete(string[] fields, string[] keys) invoked with {0}:{1}", | 355 | // "[MYSQL GENERIC TABLE HANDLER]: Delete(string[] fields, string[] keys) invoked with {0}:{1}", |
324 | // string.Join(",", fields), string.Join(",", keys)); | 356 | // string.Join(",", fields), string.Join(",", keys)); |
325 | 357 | ||
326 | if (fields.Length != keys.Length) | 358 | int flen = fields.Length; |
359 | if (flen == 0 || flen != keys.Length) | ||
327 | return false; | 360 | return false; |
328 | 361 | ||
329 | List<string> terms = new List<string>(); | 362 | int flast = flen - 1; |
363 | StringBuilder sb = new StringBuilder(1024); | ||
364 | sb.AppendFormat("delete from {0} where ", m_Realm); | ||
330 | 365 | ||
331 | using (MySqlCommand cmd = new MySqlCommand()) | 366 | using (MySqlCommand cmd = new MySqlCommand()) |
332 | { | 367 | { |
333 | for (int i = 0 ; i < fields.Length ; i++) | 368 | for (int i = 0 ; i < flen ; i++) |
334 | { | 369 | { |
335 | cmd.Parameters.AddWithValue(fields[i], keys[i]); | 370 | cmd.Parameters.AddWithValue(fields[i], keys[i]); |
336 | terms.Add("`" + fields[i] + "` = ?" + fields[i]); | 371 | if(i < flast) |
372 | sb.AppendFormat("`{0}` = ?{0} and ", fields[i]); | ||
373 | else | ||
374 | sb.AppendFormat("`{0}` = ?{0}", fields[i]); | ||
337 | } | 375 | } |
338 | 376 | ||
339 | string where = String.Join(" and ", terms.ToArray()); | 377 | cmd.CommandText = sb.ToString(); |
340 | |||
341 | string query = String.Format("delete from {0} where {1}", m_Realm, where); | ||
342 | |||
343 | cmd.CommandText = query; | ||
344 | |||
345 | return ExecuteNonQuery(cmd) > 0; | 378 | return ExecuteNonQuery(cmd) > 0; |
346 | } | 379 | } |
347 | } | 380 | } |
@@ -353,27 +386,27 @@ namespace OpenSim.Data.MySQL | |||
353 | 386 | ||
354 | public long GetCount(string[] fields, string[] keys) | 387 | public long GetCount(string[] fields, string[] keys) |
355 | { | 388 | { |
356 | if (fields.Length != keys.Length) | 389 | int flen = fields.Length; |
390 | if (flen == 0 || flen != keys.Length) | ||
357 | return 0; | 391 | return 0; |
358 | 392 | ||
359 | List<string> terms = new List<string>(); | 393 | int flast = flen - 1; |
394 | StringBuilder sb = new StringBuilder(1024); | ||
395 | sb.AppendFormat("select count(*) from {0} where ", m_Realm); | ||
360 | 396 | ||
361 | using (MySqlCommand cmd = new MySqlCommand()) | 397 | using (MySqlCommand cmd = new MySqlCommand()) |
362 | { | 398 | { |
363 | for (int i = 0; i < fields.Length; i++) | 399 | for (int i = 0 ; i < flen ; i++) |
364 | { | 400 | { |
365 | cmd.Parameters.AddWithValue(fields[i], keys[i]); | 401 | cmd.Parameters.AddWithValue(fields[i], keys[i]); |
366 | terms.Add("`" + fields[i] + "` = ?" + fields[i]); | 402 | if(i < flast) |
403 | sb.AppendFormat("`{0}` = ?{0} and ", fields[i]); | ||
404 | else | ||
405 | sb.AppendFormat("`{0}` = ?{0}", fields[i]); | ||
367 | } | 406 | } |
368 | 407 | ||
369 | string where = String.Join(" and ", terms.ToArray()); | 408 | cmd.CommandText = sb.ToString(); |
370 | 409 | object result = DoQueryScalar(cmd); | |
371 | string query = String.Format("select count(*) from {0} where {1}", | ||
372 | m_Realm, where); | ||
373 | |||
374 | cmd.CommandText = query; | ||
375 | |||
376 | Object result = DoQueryScalar(cmd); | ||
377 | 410 | ||
378 | return Convert.ToInt64(result); | 411 | return Convert.ToInt64(result); |
379 | } | 412 | } |
@@ -403,7 +436,7 @@ namespace OpenSim.Data.MySQL | |||
403 | dbcon.Open(); | 436 | dbcon.Open(); |
404 | cmd.Connection = dbcon; | 437 | cmd.Connection = dbcon; |
405 | 438 | ||
406 | Object ret = cmd.ExecuteScalar(); | 439 | object ret = cmd.ExecuteScalar(); |
407 | cmd.Connection = null; | 440 | cmd.Connection = null; |
408 | dbcon.Close(); | 441 | dbcon.Close(); |
409 | return ret; | 442 | return ret; |