diff options
author | Melanie | 2010-02-08 15:53:20 +0000 |
---|---|---|
committer | Melanie | 2010-02-08 15:53:38 +0000 |
commit | baaf660511214e52ea4ed20b8e80ec8e1ff06a3a (patch) | |
tree | 1e90c7a22ea3354d6bfd5d2b3f8f64f199dbd477 /OpenSim/Data/MySQL/MySQLManager.cs | |
parent | Added missing configs to Standalone.ini (diff) | |
parent | Adding the Careminster "Configger" tool to OpenSim. The tool will, when launched (diff) | |
download | opensim-SC-baaf660511214e52ea4ed20b8e80ec8e1ff06a3a.zip opensim-SC-baaf660511214e52ea4ed20b8e80ec8e1ff06a3a.tar.gz opensim-SC-baaf660511214e52ea4ed20b8e80ec8e1ff06a3a.tar.bz2 opensim-SC-baaf660511214e52ea4ed20b8e80ec8e1ff06a3a.tar.xz |
Merge branch 'master' into presence-refactor
This was a large, heavily conflicted merge and things MAY have got broken.
Please check!
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLManager.cs')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLManager.cs | 428 |
1 files changed, 211 insertions, 217 deletions
diff --git a/OpenSim/Data/MySQL/MySQLManager.cs b/OpenSim/Data/MySQL/MySQLManager.cs index 243394e..ace2027 100644 --- a/OpenSim/Data/MySQL/MySQLManager.cs +++ b/OpenSim/Data/MySQL/MySQLManager.cs | |||
@@ -46,15 +46,12 @@ namespace OpenSim.Data.MySQL | |||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
47 | 47 | ||
48 | /// <summary> | 48 | /// <summary> |
49 | /// The database connection object | ||
50 | /// </summary> | ||
51 | private MySqlConnection dbcon; | ||
52 | |||
53 | /// <summary> | ||
54 | /// Connection string for ADO.net | 49 | /// Connection string for ADO.net |
55 | /// </summary> | 50 | /// </summary> |
56 | private string connectionString; | 51 | private string connectionString; |
57 | 52 | ||
53 | private object m_dbLock = new object(); | ||
54 | |||
58 | private const string m_waitTimeoutSelect = "select @@wait_timeout"; | 55 | private const string m_waitTimeoutSelect = "select @@wait_timeout"; |
59 | 56 | ||
60 | /// <summary> | 57 | /// <summary> |
@@ -109,11 +106,11 @@ namespace OpenSim.Data.MySQL | |||
109 | try | 106 | try |
110 | { | 107 | { |
111 | connectionString = connect; | 108 | connectionString = connect; |
112 | dbcon = new MySqlConnection(connectionString); | 109 | //dbcon = new MySqlConnection(connectionString); |
113 | 110 | ||
114 | try | 111 | try |
115 | { | 112 | { |
116 | dbcon.Open(); | 113 | //dbcon.Open(); |
117 | } | 114 | } |
118 | catch(Exception e) | 115 | catch(Exception e) |
119 | { | 116 | { |
@@ -134,18 +131,21 @@ namespace OpenSim.Data.MySQL | |||
134 | /// </summary> | 131 | /// </summary> |
135 | protected void GetWaitTimeout() | 132 | protected void GetWaitTimeout() |
136 | { | 133 | { |
137 | MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, dbcon); | 134 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) |
138 | |||
139 | using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) | ||
140 | { | 135 | { |
141 | if (dbReader.Read()) | 136 | dbcon.Open(); |
137 | |||
138 | using (MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, dbcon)) | ||
142 | { | 139 | { |
143 | m_waitTimeout | 140 | using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) |
144 | = Convert.ToInt32(dbReader["@@wait_timeout"]) * TimeSpan.TicksPerSecond + m_waitTimeoutLeeway; | 141 | { |
142 | if (dbReader.Read()) | ||
143 | { | ||
144 | m_waitTimeout | ||
145 | = Convert.ToInt32(dbReader["@@wait_timeout"]) * TimeSpan.TicksPerSecond + m_waitTimeoutLeeway; | ||
146 | } | ||
147 | } | ||
145 | } | 148 | } |
146 | |||
147 | dbReader.Close(); | ||
148 | cmd.Dispose(); | ||
149 | } | 149 | } |
150 | 150 | ||
151 | m_lastConnectionUse = DateTime.Now.Ticks; | 151 | m_lastConnectionUse = DateTime.Now.Ticks; |
@@ -154,66 +154,9 @@ namespace OpenSim.Data.MySQL | |||
154 | "[REGION DB]: Connection wait timeout {0} seconds", m_waitTimeout / TimeSpan.TicksPerSecond); | 154 | "[REGION DB]: Connection wait timeout {0} seconds", m_waitTimeout / TimeSpan.TicksPerSecond); |
155 | } | 155 | } |
156 | 156 | ||
157 | /// <summary> | 157 | public string ConnectionString |
158 | /// Should be called before any db operation. This checks to see if the connection has not timed out | ||
159 | /// </summary> | ||
160 | public void CheckConnection() | ||
161 | { | 158 | { |
162 | //m_log.Debug("[REGION DB]: Checking connection"); | 159 | get { return connectionString; } |
163 | |||
164 | long timeNow = DateTime.Now.Ticks; | ||
165 | if (timeNow - m_lastConnectionUse > m_waitTimeout || dbcon.State != ConnectionState.Open) | ||
166 | { | ||
167 | m_log.DebugFormat("[REGION DB]: Database connection has gone away - reconnecting"); | ||
168 | Reconnect(); | ||
169 | } | ||
170 | |||
171 | // Strictly, we should set this after the actual db operation. But it's more convenient to set here rather | ||
172 | // than require the code to call another method - the timeout leeway should be large enough to cover the | ||
173 | // inaccuracy. | ||
174 | m_lastConnectionUse = timeNow; | ||
175 | } | ||
176 | |||
177 | /// <summary> | ||
178 | /// Get the connection being used | ||
179 | /// </summary> | ||
180 | /// <returns>MySqlConnection Object</returns> | ||
181 | public MySqlConnection Connection | ||
182 | { | ||
183 | get { return dbcon; } | ||
184 | } | ||
185 | |||
186 | /// <summary> | ||
187 | /// Shuts down the database connection | ||
188 | /// </summary> | ||
189 | public void Close() | ||
190 | { | ||
191 | dbcon.Close(); | ||
192 | dbcon = null; | ||
193 | } | ||
194 | |||
195 | /// <summary> | ||
196 | /// Reconnects to the database | ||
197 | /// </summary> | ||
198 | public void Reconnect() | ||
199 | { | ||
200 | m_log.Info("[REGION DB] Reconnecting database"); | ||
201 | |||
202 | lock (dbcon) | ||
203 | { | ||
204 | try | ||
205 | { | ||
206 | // Close the DB connection | ||
207 | dbcon.Close(); | ||
208 | // Try reopen it | ||
209 | dbcon = new MySqlConnection(connectionString); | ||
210 | dbcon.Open(); | ||
211 | } | ||
212 | catch (Exception e) | ||
213 | { | ||
214 | m_log.Error("Unable to reconnect to database " + e.ToString()); | ||
215 | } | ||
216 | } | ||
217 | } | 160 | } |
218 | 161 | ||
219 | /// <summary> | 162 | /// <summary> |
@@ -264,9 +207,13 @@ namespace OpenSim.Data.MySQL | |||
264 | /// <param name="name">name of embedded resource</param> | 207 | /// <param name="name">name of embedded resource</param> |
265 | public void ExecuteResourceSql(string name) | 208 | public void ExecuteResourceSql(string name) |
266 | { | 209 | { |
267 | CheckConnection(); | 210 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) |
268 | MySqlCommand cmd = new MySqlCommand(getResourceString(name), dbcon); | 211 | { |
269 | cmd.ExecuteNonQuery(); | 212 | dbcon.Open(); |
213 | |||
214 | MySqlCommand cmd = new MySqlCommand(getResourceString(name), dbcon); | ||
215 | cmd.ExecuteNonQuery(); | ||
216 | } | ||
270 | } | 217 | } |
271 | 218 | ||
272 | /// <summary> | 219 | /// <summary> |
@@ -275,22 +222,29 @@ namespace OpenSim.Data.MySQL | |||
275 | /// <param name="sql">sql string to execute</param> | 222 | /// <param name="sql">sql string to execute</param> |
276 | public void ExecuteSql(string sql) | 223 | public void ExecuteSql(string sql) |
277 | { | 224 | { |
278 | CheckConnection(); | 225 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) |
279 | MySqlCommand cmd = new MySqlCommand(sql, dbcon); | 226 | { |
280 | cmd.ExecuteNonQuery(); | 227 | dbcon.Open(); |
228 | |||
229 | MySqlCommand cmd = new MySqlCommand(sql, dbcon); | ||
230 | cmd.ExecuteNonQuery(); | ||
231 | } | ||
281 | } | 232 | } |
282 | 233 | ||
283 | public void ExecuteParameterizedSql(string sql, Dictionary<string, string> parameters) | 234 | public void ExecuteParameterizedSql(string sql, Dictionary<string, string> parameters) |
284 | { | 235 | { |
285 | CheckConnection(); | 236 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) |
286 | |||
287 | MySqlCommand cmd = (MySqlCommand)dbcon.CreateCommand(); | ||
288 | cmd.CommandText = sql; | ||
289 | foreach (KeyValuePair<string, string> param in parameters) | ||
290 | { | 237 | { |
291 | cmd.Parameters.AddWithValue(param.Key, param.Value); | 238 | dbcon.Open(); |
239 | |||
240 | MySqlCommand cmd = (MySqlCommand)dbcon.CreateCommand(); | ||
241 | cmd.CommandText = sql; | ||
242 | foreach (KeyValuePair<string, string> param in parameters) | ||
243 | { | ||
244 | cmd.Parameters.AddWithValue(param.Key, param.Value); | ||
245 | } | ||
246 | cmd.ExecuteNonQuery(); | ||
292 | } | 247 | } |
293 | cmd.ExecuteNonQuery(); | ||
294 | } | 248 | } |
295 | 249 | ||
296 | /// <summary> | 250 | /// <summary> |
@@ -299,35 +253,37 @@ namespace OpenSim.Data.MySQL | |||
299 | /// <param name="tableList"></param> | 253 | /// <param name="tableList"></param> |
300 | public void GetTableVersion(Dictionary<string, string> tableList) | 254 | public void GetTableVersion(Dictionary<string, string> tableList) |
301 | { | 255 | { |
302 | lock (dbcon) | 256 | lock (m_dbLock) |
303 | { | 257 | { |
304 | CheckConnection(); | 258 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) |
305 | |||
306 | MySqlCommand tablesCmd = | ||
307 | new MySqlCommand( | ||
308 | "SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname", | ||
309 | dbcon); | ||
310 | tablesCmd.Parameters.AddWithValue("?dbname", dbcon.Database); | ||
311 | |||
312 | using (MySqlDataReader tables = tablesCmd.ExecuteReader()) | ||
313 | { | 259 | { |
314 | while (tables.Read()) | 260 | dbcon.Open(); |
261 | |||
262 | using (MySqlCommand tablesCmd = new MySqlCommand( | ||
263 | "SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname", dbcon)) | ||
315 | { | 264 | { |
316 | try | 265 | tablesCmd.Parameters.AddWithValue("?dbname", dbcon.Database); |
266 | |||
267 | using (MySqlDataReader tables = tablesCmd.ExecuteReader()) | ||
317 | { | 268 | { |
318 | string tableName = (string) tables["TABLE_NAME"]; | 269 | while (tables.Read()) |
319 | string comment = (string) tables["TABLE_COMMENT"]; | ||
320 | if (tableList.ContainsKey(tableName)) | ||
321 | { | 270 | { |
322 | tableList[tableName] = comment; | 271 | try |
272 | { | ||
273 | string tableName = (string)tables["TABLE_NAME"]; | ||
274 | string comment = (string)tables["TABLE_COMMENT"]; | ||
275 | if (tableList.ContainsKey(tableName)) | ||
276 | { | ||
277 | tableList[tableName] = comment; | ||
278 | } | ||
279 | } | ||
280 | catch (Exception e) | ||
281 | { | ||
282 | m_log.Error(e.Message, e); | ||
283 | } | ||
323 | } | 284 | } |
324 | } | 285 | } |
325 | catch (Exception e) | ||
326 | { | ||
327 | m_log.Error(e.ToString()); | ||
328 | } | ||
329 | } | 286 | } |
330 | tables.Close(); | ||
331 | } | 287 | } |
332 | } | 288 | } |
333 | } | 289 | } |
@@ -337,28 +293,27 @@ namespace OpenSim.Data.MySQL | |||
337 | /// <summary> | 293 | /// <summary> |
338 | /// Runs a query with protection against SQL Injection by using parameterised input. | 294 | /// Runs a query with protection against SQL Injection by using parameterised input. |
339 | /// </summary> | 295 | /// </summary> |
296 | /// <param name="dbcon">Database connection</param> | ||
340 | /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> | 297 | /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> |
341 | /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param> | 298 | /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param> |
342 | /// <returns>A MySQL DB Command</returns> | 299 | /// <returns>A MySQL DB Command</returns> |
343 | public IDbCommand Query(string sql, Dictionary<string, object> parameters) | 300 | public IDbCommand Query(MySqlConnection dbcon, string sql, Dictionary<string, object> parameters) |
344 | { | 301 | { |
345 | try | 302 | try |
346 | { | 303 | { |
347 | CheckConnection(); // Not sure if this one is necessary | 304 | MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand(); |
348 | |||
349 | MySqlCommand dbcommand = (MySqlCommand) dbcon.CreateCommand(); | ||
350 | dbcommand.CommandText = sql; | 305 | dbcommand.CommandText = sql; |
351 | foreach (KeyValuePair<string, object> param in parameters) | 306 | foreach (KeyValuePair<string, object> param in parameters) |
352 | { | 307 | { |
353 | dbcommand.Parameters.AddWithValue(param.Key, param.Value); | 308 | dbcommand.Parameters.AddWithValue(param.Key, param.Value); |
354 | } | 309 | } |
355 | 310 | ||
356 | return (IDbCommand) dbcommand; | 311 | return (IDbCommand)dbcommand; |
357 | } | 312 | } |
358 | catch (Exception e) | 313 | catch (Exception e) |
359 | { | 314 | { |
360 | // Return null if it fails. | 315 | // Return null if it fails. |
361 | m_log.Error("Failed during Query generation: " + e.ToString()); | 316 | m_log.Error("Failed during Query generation: " + e.Message, e); |
362 | return null; | 317 | return null; |
363 | } | 318 | } |
364 | } | 319 | } |
@@ -694,8 +649,6 @@ namespace OpenSim.Data.MySQL | |||
694 | ret.Add(attachpoint, item); | 649 | ret.Add(attachpoint, item); |
695 | } | 650 | } |
696 | 651 | ||
697 | r.Close(); | ||
698 | |||
699 | return ret; | 652 | return ret; |
700 | } | 653 | } |
701 | 654 | ||
@@ -727,12 +680,17 @@ namespace OpenSim.Data.MySQL | |||
727 | 680 | ||
728 | try | 681 | try |
729 | { | 682 | { |
730 | IDbCommand result = Query(sql, parameters); | 683 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) |
684 | { | ||
685 | dbcon.Open(); | ||
686 | |||
687 | IDbCommand result = Query(dbcon, sql, parameters); | ||
731 | 688 | ||
732 | if (result.ExecuteNonQuery() == 1) | 689 | if (result.ExecuteNonQuery() == 1) |
733 | returnval = true; | 690 | returnval = true; |
734 | 691 | ||
735 | result.Dispose(); | 692 | result.Dispose(); |
693 | } | ||
736 | } | 694 | } |
737 | catch (Exception e) | 695 | catch (Exception e) |
738 | { | 696 | { |
@@ -828,12 +786,17 @@ namespace OpenSim.Data.MySQL | |||
828 | 786 | ||
829 | try | 787 | try |
830 | { | 788 | { |
831 | IDbCommand result = Query(sql, parameters); | 789 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) |
790 | { | ||
791 | dbcon.Open(); | ||
832 | 792 | ||
833 | if (result.ExecuteNonQuery() == 1) | 793 | IDbCommand result = Query(dbcon, sql, parameters); |
834 | returnval = true; | ||
835 | 794 | ||
836 | result.Dispose(); | 795 | if (result.ExecuteNonQuery() == 1) |
796 | returnval = true; | ||
797 | |||
798 | result.Dispose(); | ||
799 | } | ||
837 | } | 800 | } |
838 | catch (Exception e) | 801 | catch (Exception e) |
839 | { | 802 | { |
@@ -927,12 +890,17 @@ namespace OpenSim.Data.MySQL | |||
927 | bool returnval = false; | 890 | bool returnval = false; |
928 | try | 891 | try |
929 | { | 892 | { |
930 | IDbCommand result = Query(sql, parameters); | 893 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) |
894 | { | ||
895 | dbcon.Open(); | ||
931 | 896 | ||
932 | if (result.ExecuteNonQuery() == 1) | 897 | IDbCommand result = Query(dbcon, sql, parameters); |
933 | returnval = true; | ||
934 | 898 | ||
935 | result.Dispose(); | 899 | if (result.ExecuteNonQuery() == 1) |
900 | returnval = true; | ||
901 | |||
902 | result.Dispose(); | ||
903 | } | ||
936 | } | 904 | } |
937 | catch (Exception e) | 905 | catch (Exception e) |
938 | { | 906 | { |
@@ -1030,18 +998,23 @@ namespace OpenSim.Data.MySQL | |||
1030 | 998 | ||
1031 | try | 999 | try |
1032 | { | 1000 | { |
1033 | IDbCommand result = Query(sql, parameters); | 1001 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) |
1034 | |||
1035 | // int x; | ||
1036 | // if ((x = result.ExecuteNonQuery()) > 0) | ||
1037 | // { | ||
1038 | // returnval = true; | ||
1039 | // } | ||
1040 | if (result.ExecuteNonQuery() > 0) | ||
1041 | { | 1002 | { |
1042 | returnval = true; | 1003 | dbcon.Open(); |
1004 | |||
1005 | IDbCommand result = Query(dbcon, sql, parameters); | ||
1006 | |||
1007 | // int x; | ||
1008 | // if ((x = result.ExecuteNonQuery()) > 0) | ||
1009 | // { | ||
1010 | // returnval = true; | ||
1011 | // } | ||
1012 | if (result.ExecuteNonQuery() > 0) | ||
1013 | { | ||
1014 | returnval = true; | ||
1015 | } | ||
1016 | result.Dispose(); | ||
1043 | } | 1017 | } |
1044 | result.Dispose(); | ||
1045 | } | 1018 | } |
1046 | catch (Exception e) | 1019 | catch (Exception e) |
1047 | { | 1020 | { |
@@ -1070,18 +1043,23 @@ namespace OpenSim.Data.MySQL | |||
1070 | { | 1043 | { |
1071 | parameters["?uuid"] = uuid; | 1044 | parameters["?uuid"] = uuid; |
1072 | 1045 | ||
1073 | IDbCommand result = Query(sql, parameters); | 1046 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) |
1074 | |||
1075 | // int x; | ||
1076 | // if ((x = result.ExecuteNonQuery()) > 0) | ||
1077 | // { | ||
1078 | // returnval = true; | ||
1079 | // } | ||
1080 | if (result.ExecuteNonQuery() > 0) | ||
1081 | { | 1047 | { |
1082 | returnval = true; | 1048 | dbcon.Open(); |
1049 | |||
1050 | IDbCommand result = Query(dbcon, sql, parameters); | ||
1051 | |||
1052 | // int x; | ||
1053 | // if ((x = result.ExecuteNonQuery()) > 0) | ||
1054 | // { | ||
1055 | // returnval = true; | ||
1056 | // } | ||
1057 | if (result.ExecuteNonQuery() > 0) | ||
1058 | { | ||
1059 | returnval = true; | ||
1060 | } | ||
1061 | result.Dispose(); | ||
1083 | } | 1062 | } |
1084 | result.Dispose(); | ||
1085 | } | 1063 | } |
1086 | catch (Exception e) | 1064 | catch (Exception e) |
1087 | { | 1065 | { |
@@ -1122,18 +1100,23 @@ namespace OpenSim.Data.MySQL | |||
1122 | 1100 | ||
1123 | try | 1101 | try |
1124 | { | 1102 | { |
1125 | IDbCommand result = Query(sql, parameters); | 1103 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) |
1126 | |||
1127 | // int x; | ||
1128 | // if ((x = result.ExecuteNonQuery()) > 0) | ||
1129 | // { | ||
1130 | // returnval = true; | ||
1131 | // } | ||
1132 | if (result.ExecuteNonQuery() > 0) | ||
1133 | { | 1104 | { |
1134 | returnval = true; | 1105 | dbcon.Open(); |
1106 | |||
1107 | IDbCommand result = Query(dbcon, sql, parameters); | ||
1108 | |||
1109 | // int x; | ||
1110 | // if ((x = result.ExecuteNonQuery()) > 0) | ||
1111 | // { | ||
1112 | // returnval = true; | ||
1113 | // } | ||
1114 | if (result.ExecuteNonQuery() > 0) | ||
1115 | { | ||
1116 | returnval = true; | ||
1117 | } | ||
1118 | result.Dispose(); | ||
1135 | } | 1119 | } |
1136 | result.Dispose(); | ||
1137 | } | 1120 | } |
1138 | catch (Exception e) | 1121 | catch (Exception e) |
1139 | { | 1122 | { |
@@ -1167,45 +1150,51 @@ namespace OpenSim.Data.MySQL | |||
1167 | bool returnval = false; | 1150 | bool returnval = false; |
1168 | 1151 | ||
1169 | // we want to send in byte data, which means we can't just pass down strings | 1152 | // we want to send in byte data, which means we can't just pass down strings |
1170 | try { | 1153 | try |
1171 | MySqlCommand cmd = (MySqlCommand) dbcon.CreateCommand(); | 1154 | { |
1172 | cmd.CommandText = sql; | 1155 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) |
1173 | cmd.Parameters.AddWithValue("?owner", appearance.Owner.ToString()); | 1156 | { |
1174 | cmd.Parameters.AddWithValue("?serial", appearance.Serial); | 1157 | dbcon.Open(); |
1175 | cmd.Parameters.AddWithValue("?visual_params", appearance.VisualParams); | 1158 | |
1176 | cmd.Parameters.AddWithValue("?texture", appearance.Texture.GetBytes()); | 1159 | using (MySqlCommand cmd = (MySqlCommand)dbcon.CreateCommand()) |
1177 | cmd.Parameters.AddWithValue("?avatar_height", appearance.AvatarHeight); | 1160 | { |
1178 | cmd.Parameters.AddWithValue("?body_item", appearance.BodyItem.ToString()); | 1161 | cmd.CommandText = sql; |
1179 | cmd.Parameters.AddWithValue("?body_asset", appearance.BodyAsset.ToString()); | 1162 | cmd.Parameters.AddWithValue("?owner", appearance.Owner.ToString()); |
1180 | cmd.Parameters.AddWithValue("?skin_item", appearance.SkinItem.ToString()); | 1163 | cmd.Parameters.AddWithValue("?serial", appearance.Serial); |
1181 | cmd.Parameters.AddWithValue("?skin_asset", appearance.SkinAsset.ToString()); | 1164 | cmd.Parameters.AddWithValue("?visual_params", appearance.VisualParams); |
1182 | cmd.Parameters.AddWithValue("?hair_item", appearance.HairItem.ToString()); | 1165 | cmd.Parameters.AddWithValue("?texture", appearance.Texture.GetBytes()); |
1183 | cmd.Parameters.AddWithValue("?hair_asset", appearance.HairAsset.ToString()); | 1166 | cmd.Parameters.AddWithValue("?avatar_height", appearance.AvatarHeight); |
1184 | cmd.Parameters.AddWithValue("?eyes_item", appearance.EyesItem.ToString()); | 1167 | cmd.Parameters.AddWithValue("?body_item", appearance.BodyItem.ToString()); |
1185 | cmd.Parameters.AddWithValue("?eyes_asset", appearance.EyesAsset.ToString()); | 1168 | cmd.Parameters.AddWithValue("?body_asset", appearance.BodyAsset.ToString()); |
1186 | cmd.Parameters.AddWithValue("?shirt_item", appearance.ShirtItem.ToString()); | 1169 | cmd.Parameters.AddWithValue("?skin_item", appearance.SkinItem.ToString()); |
1187 | cmd.Parameters.AddWithValue("?shirt_asset", appearance.ShirtAsset.ToString()); | 1170 | cmd.Parameters.AddWithValue("?skin_asset", appearance.SkinAsset.ToString()); |
1188 | cmd.Parameters.AddWithValue("?pants_item", appearance.PantsItem.ToString()); | 1171 | cmd.Parameters.AddWithValue("?hair_item", appearance.HairItem.ToString()); |
1189 | cmd.Parameters.AddWithValue("?pants_asset", appearance.PantsAsset.ToString()); | 1172 | cmd.Parameters.AddWithValue("?hair_asset", appearance.HairAsset.ToString()); |
1190 | cmd.Parameters.AddWithValue("?shoes_item", appearance.ShoesItem.ToString()); | 1173 | cmd.Parameters.AddWithValue("?eyes_item", appearance.EyesItem.ToString()); |
1191 | cmd.Parameters.AddWithValue("?shoes_asset", appearance.ShoesAsset.ToString()); | 1174 | cmd.Parameters.AddWithValue("?eyes_asset", appearance.EyesAsset.ToString()); |
1192 | cmd.Parameters.AddWithValue("?socks_item", appearance.SocksItem.ToString()); | 1175 | cmd.Parameters.AddWithValue("?shirt_item", appearance.ShirtItem.ToString()); |
1193 | cmd.Parameters.AddWithValue("?socks_asset", appearance.SocksAsset.ToString()); | 1176 | cmd.Parameters.AddWithValue("?shirt_asset", appearance.ShirtAsset.ToString()); |
1194 | cmd.Parameters.AddWithValue("?jacket_item", appearance.JacketItem.ToString()); | 1177 | cmd.Parameters.AddWithValue("?pants_item", appearance.PantsItem.ToString()); |
1195 | cmd.Parameters.AddWithValue("?jacket_asset", appearance.JacketAsset.ToString()); | 1178 | cmd.Parameters.AddWithValue("?pants_asset", appearance.PantsAsset.ToString()); |
1196 | cmd.Parameters.AddWithValue("?gloves_item", appearance.GlovesItem.ToString()); | 1179 | cmd.Parameters.AddWithValue("?shoes_item", appearance.ShoesItem.ToString()); |
1197 | cmd.Parameters.AddWithValue("?gloves_asset", appearance.GlovesAsset.ToString()); | 1180 | cmd.Parameters.AddWithValue("?shoes_asset", appearance.ShoesAsset.ToString()); |
1198 | cmd.Parameters.AddWithValue("?undershirt_item", appearance.UnderShirtItem.ToString()); | 1181 | cmd.Parameters.AddWithValue("?socks_item", appearance.SocksItem.ToString()); |
1199 | cmd.Parameters.AddWithValue("?undershirt_asset", appearance.UnderShirtAsset.ToString()); | 1182 | cmd.Parameters.AddWithValue("?socks_asset", appearance.SocksAsset.ToString()); |
1200 | cmd.Parameters.AddWithValue("?underpants_item", appearance.UnderPantsItem.ToString()); | 1183 | cmd.Parameters.AddWithValue("?jacket_item", appearance.JacketItem.ToString()); |
1201 | cmd.Parameters.AddWithValue("?underpants_asset", appearance.UnderPantsAsset.ToString()); | 1184 | cmd.Parameters.AddWithValue("?jacket_asset", appearance.JacketAsset.ToString()); |
1202 | cmd.Parameters.AddWithValue("?skirt_item", appearance.SkirtItem.ToString()); | 1185 | cmd.Parameters.AddWithValue("?gloves_item", appearance.GlovesItem.ToString()); |
1203 | cmd.Parameters.AddWithValue("?skirt_asset", appearance.SkirtAsset.ToString()); | 1186 | cmd.Parameters.AddWithValue("?gloves_asset", appearance.GlovesAsset.ToString()); |
1204 | 1187 | cmd.Parameters.AddWithValue("?undershirt_item", appearance.UnderShirtItem.ToString()); | |
1205 | if (cmd.ExecuteNonQuery() > 0) | 1188 | cmd.Parameters.AddWithValue("?undershirt_asset", appearance.UnderShirtAsset.ToString()); |
1206 | returnval = true; | 1189 | cmd.Parameters.AddWithValue("?underpants_item", appearance.UnderPantsItem.ToString()); |
1207 | 1190 | cmd.Parameters.AddWithValue("?underpants_asset", appearance.UnderPantsAsset.ToString()); | |
1208 | cmd.Dispose(); | 1191 | cmd.Parameters.AddWithValue("?skirt_item", appearance.SkirtItem.ToString()); |
1192 | cmd.Parameters.AddWithValue("?skirt_asset", appearance.SkirtAsset.ToString()); | ||
1193 | |||
1194 | if (cmd.ExecuteNonQuery() > 0) | ||
1195 | returnval = true; | ||
1196 | } | ||
1197 | } | ||
1209 | } | 1198 | } |
1210 | catch (Exception e) | 1199 | catch (Exception e) |
1211 | { | 1200 | { |
@@ -1221,33 +1210,38 @@ namespace OpenSim.Data.MySQL | |||
1221 | { | 1210 | { |
1222 | string sql = "delete from avatarattachments where UUID = ?uuid"; | 1211 | string sql = "delete from avatarattachments where UUID = ?uuid"; |
1223 | 1212 | ||
1224 | MySqlCommand cmd = (MySqlCommand) dbcon.CreateCommand(); | 1213 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) |
1225 | cmd.CommandText = sql; | 1214 | { |
1226 | cmd.Parameters.AddWithValue("?uuid", agentID.ToString()); | 1215 | dbcon.Open(); |
1216 | |||
1217 | MySqlCommand cmd = (MySqlCommand)dbcon.CreateCommand(); | ||
1218 | cmd.CommandText = sql; | ||
1219 | cmd.Parameters.AddWithValue("?uuid", agentID.ToString()); | ||
1227 | 1220 | ||
1228 | cmd.ExecuteNonQuery(); | 1221 | cmd.ExecuteNonQuery(); |
1229 | 1222 | ||
1230 | if (data == null) | 1223 | if (data == null) |
1231 | return; | 1224 | return; |
1232 | 1225 | ||
1233 | sql = "insert into avatarattachments (UUID, attachpoint, item, asset) values (?uuid, ?attachpoint, ?item, ?asset)"; | 1226 | sql = "insert into avatarattachments (UUID, attachpoint, item, asset) values (?uuid, ?attachpoint, ?item, ?asset)"; |
1234 | 1227 | ||
1235 | cmd = (MySqlCommand) dbcon.CreateCommand(); | 1228 | cmd = (MySqlCommand)dbcon.CreateCommand(); |
1236 | cmd.CommandText = sql; | 1229 | cmd.CommandText = sql; |
1237 | 1230 | ||
1238 | foreach (DictionaryEntry e in data) | 1231 | foreach (DictionaryEntry e in data) |
1239 | { | 1232 | { |
1240 | int attachpoint = Convert.ToInt32(e.Key); | 1233 | int attachpoint = Convert.ToInt32(e.Key); |
1241 | 1234 | ||
1242 | Hashtable item = (Hashtable)e.Value; | 1235 | Hashtable item = (Hashtable)e.Value; |
1243 | 1236 | ||
1244 | cmd.Parameters.Clear(); | 1237 | cmd.Parameters.Clear(); |
1245 | cmd.Parameters.AddWithValue("?uuid", agentID.ToString()); | 1238 | cmd.Parameters.AddWithValue("?uuid", agentID.ToString()); |
1246 | cmd.Parameters.AddWithValue("?attachpoint", attachpoint); | 1239 | cmd.Parameters.AddWithValue("?attachpoint", attachpoint); |
1247 | cmd.Parameters.AddWithValue("?item", item["item"]); | 1240 | cmd.Parameters.AddWithValue("?item", item["item"]); |
1248 | cmd.Parameters.AddWithValue("?asset", item["asset"]); | 1241 | cmd.Parameters.AddWithValue("?asset", item["asset"]); |
1249 | 1242 | ||
1250 | cmd.ExecuteNonQuery(); | 1243 | cmd.ExecuteNonQuery(); |
1244 | } | ||
1251 | } | 1245 | } |
1252 | } | 1246 | } |
1253 | } | 1247 | } |