diff options
author | Melanie Thielker | 2008-09-14 13:23:02 +0000 |
---|---|---|
committer | Melanie Thielker | 2008-09-14 13:23:02 +0000 |
commit | 281955949910eb257b5f7e42e54535ba7812418e (patch) | |
tree | 8c62c0006f2567983a686e811513c8c009061aac /OpenSim/Data/MSSQL/MSSQLManager.cs | |
parent | * Converted a number of methods within the login processes from private to pr... (diff) | |
download | opensim-SC-281955949910eb257b5f7e42e54535ba7812418e.zip opensim-SC-281955949910eb257b5f7e42e54535ba7812418e.tar.gz opensim-SC-281955949910eb257b5f7e42e54535ba7812418e.tar.bz2 opensim-SC-281955949910eb257b5f7e42e54535ba7812418e.tar.xz |
Mantis #2124
Thank you, RuudL, for a patch that brings MSSQL up to the same
implementation level as MySQL.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/MSSQL/MSSQLManager.cs | 374 |
1 files changed, 44 insertions, 330 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLManager.cs b/OpenSim/Data/MSSQL/MSSQLManager.cs index abbcddf..b3e9b6e 100644 --- a/OpenSim/Data/MSSQL/MSSQLManager.cs +++ b/OpenSim/Data/MSSQL/MSSQLManager.cs | |||
@@ -33,7 +33,6 @@ using System.IO; | |||
33 | using System.Reflection; | 33 | using System.Reflection; |
34 | using OpenMetaverse; | 34 | using OpenMetaverse; |
35 | using log4net; | 35 | using log4net; |
36 | using OpenSim.Framework; | ||
37 | 36 | ||
38 | namespace OpenSim.Data.MSSQL | 37 | namespace OpenSim.Data.MSSQL |
39 | { | 38 | { |
@@ -83,49 +82,7 @@ namespace OpenSim.Data.MSSQL | |||
83 | return conn; | 82 | return conn; |
84 | } | 83 | } |
85 | 84 | ||
86 | //private DataTable createRegionsTable() | 85 | #region Obsolete functions, can be removed! |
87 | //{ | ||
88 | // DataTable regions = new DataTable("regions"); | ||
89 | |||
90 | // createCol(regions, "regionHandle", typeof (ulong)); | ||
91 | // createCol(regions, "regionName", typeof (String)); | ||
92 | // createCol(regions, "uuid", typeof (String)); | ||
93 | |||
94 | // createCol(regions, "regionRecvKey", typeof (String)); | ||
95 | // createCol(regions, "regionSecret", typeof (String)); | ||
96 | // createCol(regions, "regionSendKey", typeof (String)); | ||
97 | |||
98 | // createCol(regions, "regionDataURI", typeof (String)); | ||
99 | // createCol(regions, "serverIP", typeof (String)); | ||
100 | // createCol(regions, "serverPort", typeof (String)); | ||
101 | // createCol(regions, "serverURI", typeof (String)); | ||
102 | |||
103 | |||
104 | // createCol(regions, "locX", typeof (uint)); | ||
105 | // createCol(regions, "locY", typeof (uint)); | ||
106 | // createCol(regions, "locZ", typeof (uint)); | ||
107 | |||
108 | // createCol(regions, "eastOverrideHandle", typeof (ulong)); | ||
109 | // createCol(regions, "westOverrideHandle", typeof (ulong)); | ||
110 | // createCol(regions, "southOverrideHandle", typeof (ulong)); | ||
111 | // createCol(regions, "northOverrideHandle", typeof (ulong)); | ||
112 | |||
113 | // createCol(regions, "regionAssetURI", typeof (String)); | ||
114 | // createCol(regions, "regionAssetRecvKey", typeof (String)); | ||
115 | // createCol(regions, "regionAssetSendKey", typeof (String)); | ||
116 | |||
117 | // createCol(regions, "regionUserURI", typeof (String)); | ||
118 | // createCol(regions, "regionUserRecvKey", typeof (String)); | ||
119 | // createCol(regions, "regionUserSendKey", typeof (String)); | ||
120 | |||
121 | // createCol(regions, "regionMapTexture", typeof (String)); | ||
122 | // createCol(regions, "serverHttpPort", typeof (String)); | ||
123 | // createCol(regions, "serverRemotingPort", typeof (uint)); | ||
124 | |||
125 | // // Add in contraints | ||
126 | // regions.PrimaryKey = new DataColumn[] {regions.Columns["UUID"]}; | ||
127 | // return regions; | ||
128 | //} | ||
129 | 86 | ||
130 | /// <summary> | 87 | /// <summary> |
131 | /// | 88 | /// |
@@ -133,6 +90,7 @@ namespace OpenSim.Data.MSSQL | |||
133 | /// <param name="dt"></param> | 90 | /// <param name="dt"></param> |
134 | /// <param name="name"></param> | 91 | /// <param name="name"></param> |
135 | /// <param name="type"></param> | 92 | /// <param name="type"></param> |
93 | [Obsolete("Do not use!")] | ||
136 | protected static void createCol(DataTable dt, string name, Type type) | 94 | protected static void createCol(DataTable dt, string name, Type type) |
137 | { | 95 | { |
138 | DataColumn col = new DataColumn(name, type); | 96 | DataColumn col = new DataColumn(name, type); |
@@ -144,6 +102,7 @@ namespace OpenSim.Data.MSSQL | |||
144 | /// </summary> | 102 | /// </summary> |
145 | /// <param name="dt"></param> | 103 | /// <param name="dt"></param> |
146 | /// <returns></returns> | 104 | /// <returns></returns> |
105 | [Obsolete("Do not use!")] | ||
147 | protected static string defineTable(DataTable dt) | 106 | protected static string defineTable(DataTable dt) |
148 | { | 107 | { |
149 | string sql = "create table " + dt.TableName + "("; | 108 | string sql = "create table " + dt.TableName + "("; |
@@ -167,34 +126,34 @@ namespace OpenSim.Data.MSSQL | |||
167 | return sql; | 126 | return sql; |
168 | } | 127 | } |
169 | 128 | ||
129 | #endregion | ||
130 | |||
170 | /// <summary> | 131 | /// <summary> |
171 | /// Type conversion function | 132 | /// Type conversion function |
172 | /// </summary> | 133 | /// </summary> |
173 | /// <param name="type">a type</param> | 134 | /// <param name="type">a type</param> |
174 | /// <returns>a sqltype</returns> | 135 | /// <returns>a sqltype</returns> |
175 | /// <remarks>this is something we'll need to implement for each db slightly differently.</remarks> | 136 | /// <remarks>this is something we'll need to implement for each db slightly differently.</remarks> |
137 | [Obsolete("Used by a obsolete methods")] | ||
176 | public static string SqlType(Type type) | 138 | public static string SqlType(Type type) |
177 | { | 139 | { |
178 | if (type == typeof(String)) | 140 | if (type == typeof(String)) |
179 | { | 141 | { |
180 | return "varchar(255)"; | 142 | return "varchar(255)"; |
181 | } | 143 | } |
182 | else if (type == typeof(Int32)) | 144 | if (type == typeof(Int32)) |
183 | { | 145 | { |
184 | return "integer"; | 146 | return "integer"; |
185 | } | 147 | } |
186 | else if (type == typeof(Double)) | 148 | if (type == typeof(Double)) |
187 | { | 149 | { |
188 | return "float"; | 150 | return "float"; |
189 | } | 151 | } |
190 | else if (type == typeof(Byte[])) | 152 | if (type == typeof(Byte[])) |
191 | { | 153 | { |
192 | return "image"; | 154 | return "image"; |
193 | } | 155 | } |
194 | else | 156 | return "varchar(255)"; |
195 | { | ||
196 | return "varchar(255)"; | ||
197 | } | ||
198 | } | 157 | } |
199 | 158 | ||
200 | /// <summary> | 159 | /// <summary> |
@@ -224,14 +183,22 @@ namespace OpenSim.Data.MSSQL | |||
224 | { | 183 | { |
225 | return SqlDbType.VarChar; | 184 | return SqlDbType.VarChar; |
226 | } | 185 | } |
186 | if (type == typeof(sbyte)) | ||
187 | { | ||
188 | return SqlDbType.TinyInt; | ||
189 | } | ||
227 | if (type == typeof(Byte[])) | 190 | if (type == typeof(Byte[])) |
228 | { | 191 | { |
229 | return SqlDbType.Image; | 192 | return SqlDbType.Image; |
230 | } | 193 | } |
231 | if (type == typeof(uint)) | 194 | if (type == typeof(uint) || type == typeof(ushort)) |
232 | { | 195 | { |
233 | return SqlDbType.Int; | 196 | return SqlDbType.Int; |
234 | } | 197 | } |
198 | if (type == typeof(ulong)) | ||
199 | { | ||
200 | return SqlDbType.BigInt; | ||
201 | } | ||
235 | return SqlDbType.VarChar; | 202 | return SqlDbType.VarChar; |
236 | } | 203 | } |
237 | 204 | ||
@@ -282,6 +249,9 @@ namespace OpenSim.Data.MSSQL | |||
282 | //Tweak so we dont always have to add @ sign | 249 | //Tweak so we dont always have to add @ sign |
283 | if (!parameterName.StartsWith("@")) parameterName = "@" + parameterName; | 250 | if (!parameterName.StartsWith("@")) parameterName = "@" + parameterName; |
284 | 251 | ||
252 | //HACK if object is null, it is turned into a string, there are no nullable type till now | ||
253 | if (parameterObject == null) parameterObject = ""; | ||
254 | |||
285 | SqlParameter parameter = new SqlParameter(parameterName, DbtypeFromType(parameterObject.GetType())); | 255 | SqlParameter parameter = new SqlParameter(parameterName, DbtypeFromType(parameterObject.GetType())); |
286 | 256 | ||
287 | if (parameterOut) | 257 | if (parameterOut) |
@@ -298,6 +268,7 @@ namespace OpenSim.Data.MSSQL | |||
298 | } | 268 | } |
299 | 269 | ||
300 | private static readonly Dictionary<string, string> emptyDictionary = new Dictionary<string, string>(); | 270 | private static readonly Dictionary<string, string> emptyDictionary = new Dictionary<string, string>(); |
271 | |||
301 | internal AutoClosingSqlCommand Query(string sql) | 272 | internal AutoClosingSqlCommand Query(string sql) |
302 | { | 273 | { |
303 | return Query(sql, emptyDictionary); | 274 | return Query(sql, emptyDictionary); |
@@ -322,238 +293,38 @@ namespace OpenSim.Data.MSSQL | |||
322 | } | 293 | } |
323 | 294 | ||
324 | /// <summary> | 295 | /// <summary> |
325 | /// Runs a database reader object and returns a region row | 296 | /// Runs a query with protection against SQL Injection by using parameterised input. |
326 | /// </summary> | ||
327 | /// <param name="reader">An active database reader</param> | ||
328 | /// <returns>A region row</returns> | ||
329 | public RegionProfileData getRegionRow(IDataReader reader) | ||
330 | { | ||
331 | RegionProfileData regionprofile = new RegionProfileData(); | ||
332 | |||
333 | if (reader.Read()) | ||
334 | { | ||
335 | // Region Main | ||
336 | regionprofile.regionHandle = Convert.ToUInt64(reader["regionHandle"]); | ||
337 | regionprofile.regionName = (string)reader["regionName"]; | ||
338 | regionprofile.UUID = new UUID((string)reader["uuid"]); | ||
339 | |||
340 | // Secrets | ||
341 | regionprofile.regionRecvKey = (string)reader["regionRecvKey"]; | ||
342 | regionprofile.regionSecret = (string)reader["regionSecret"]; | ||
343 | regionprofile.regionSendKey = (string)reader["regionSendKey"]; | ||
344 | |||
345 | // Region Server | ||
346 | regionprofile.regionDataURI = (string)reader["regionDataURI"]; | ||
347 | regionprofile.regionOnline = false; // Needs to be pinged before this can be set. | ||
348 | regionprofile.serverIP = (string)reader["serverIP"]; | ||
349 | regionprofile.serverPort = Convert.ToUInt32(reader["serverPort"]); | ||
350 | regionprofile.serverURI = (string)reader["serverURI"]; | ||
351 | regionprofile.httpPort = Convert.ToUInt32(reader["serverHttpPort"]); | ||
352 | regionprofile.remotingPort = Convert.ToUInt32(reader["serverRemotingPort"]); | ||
353 | |||
354 | |||
355 | // Location | ||
356 | regionprofile.regionLocX = Convert.ToUInt32(reader["locX"]); | ||
357 | regionprofile.regionLocY = Convert.ToUInt32(reader["locY"]); | ||
358 | regionprofile.regionLocZ = Convert.ToUInt32(reader["locZ"]); | ||
359 | |||
360 | // Neighbours - 0 = No Override | ||
361 | regionprofile.regionEastOverrideHandle = Convert.ToUInt64(reader["eastOverrideHandle"]); | ||
362 | regionprofile.regionWestOverrideHandle = Convert.ToUInt64(reader["westOverrideHandle"]); | ||
363 | regionprofile.regionSouthOverrideHandle = Convert.ToUInt64(reader["southOverrideHandle"]); | ||
364 | regionprofile.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"]); | ||
365 | |||
366 | // Assets | ||
367 | regionprofile.regionAssetURI = (string)reader["regionAssetURI"]; | ||
368 | regionprofile.regionAssetRecvKey = (string)reader["regionAssetRecvKey"]; | ||
369 | regionprofile.regionAssetSendKey = (string)reader["regionAssetSendKey"]; | ||
370 | |||
371 | // Userserver | ||
372 | regionprofile.regionUserURI = (string)reader["regionUserURI"]; | ||
373 | regionprofile.regionUserRecvKey = (string)reader["regionUserRecvKey"]; | ||
374 | regionprofile.regionUserSendKey = (string)reader["regionUserSendKey"]; | ||
375 | regionprofile.owner_uuid = new UUID((string) reader["owner_uuid"]); | ||
376 | // World Map Addition | ||
377 | string tempRegionMap = reader["regionMapTexture"].ToString(); | ||
378 | if (tempRegionMap != String.Empty) | ||
379 | { | ||
380 | regionprofile.regionMapTextureID = new UUID(tempRegionMap); | ||
381 | } | ||
382 | else | ||
383 | { | ||
384 | regionprofile.regionMapTextureID = new UUID(); | ||
385 | } | ||
386 | } | ||
387 | else | ||
388 | { | ||
389 | reader.Close(); | ||
390 | throw new Exception("No rows to return"); | ||
391 | } | ||
392 | return regionprofile; | ||
393 | } | ||
394 | |||
395 | /// <summary> | ||
396 | /// Reads a user profile from an active data reader | ||
397 | /// </summary> | 297 | /// </summary> |
398 | /// <param name="reader">An active database reader</param> | 298 | /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> |
399 | /// <returns>A user profile</returns> | 299 | /// <param name="sqlParameter">A parameter - use createparameter to create parameter</param> |
400 | public UserProfileData readUserRow(IDataReader reader) | 300 | /// <returns></returns> |
301 | internal AutoClosingSqlCommand Query(string sql, SqlParameter sqlParameter) | ||
401 | { | 302 | { |
402 | UserProfileData retval = new UserProfileData(); | 303 | SqlCommand dbcommand = DatabaseConnection().CreateCommand(); |
304 | dbcommand.CommandText = sql; | ||
305 | dbcommand.Parameters.Add(sqlParameter); | ||
403 | 306 | ||
404 | if (reader.Read()) | 307 | return new AutoClosingSqlCommand(dbcommand); |
405 | { | ||
406 | retval.ID = new UUID((string)reader["UUID"]); | ||
407 | retval.FirstName = (string)reader["username"]; | ||
408 | retval.SurName = (string)reader["lastname"]; | ||
409 | |||
410 | retval.PasswordHash = (string)reader["passwordHash"]; | ||
411 | retval.PasswordSalt = (string)reader["passwordSalt"]; | ||
412 | |||
413 | retval.HomeRegion = Convert.ToUInt64(reader["homeRegion"].ToString()); | ||
414 | retval.HomeLocation = new Vector3( | ||
415 | Convert.ToSingle(reader["homeLocationX"].ToString()), | ||
416 | Convert.ToSingle(reader["homeLocationY"].ToString()), | ||
417 | Convert.ToSingle(reader["homeLocationZ"].ToString())); | ||
418 | retval.HomeLookAt = new Vector3( | ||
419 | Convert.ToSingle(reader["homeLookAtX"].ToString()), | ||
420 | Convert.ToSingle(reader["homeLookAtY"].ToString()), | ||
421 | Convert.ToSingle(reader["homeLookAtZ"].ToString())); | ||
422 | |||
423 | retval.Created = Convert.ToInt32(reader["created"].ToString()); | ||
424 | retval.LastLogin = Convert.ToInt32(reader["lastLogin"].ToString()); | ||
425 | |||
426 | retval.UserInventoryURI = (string)reader["userInventoryURI"]; | ||
427 | retval.UserAssetURI = (string)reader["userAssetURI"]; | ||
428 | |||
429 | retval.CanDoMask = Convert.ToUInt32(reader["profileCanDoMask"].ToString()); | ||
430 | retval.WantDoMask = Convert.ToUInt32(reader["profileWantDoMask"].ToString()); | ||
431 | |||
432 | retval.AboutText = (string)reader["profileAboutText"]; | ||
433 | retval.FirstLifeAboutText = (string)reader["profileFirstText"]; | ||
434 | |||
435 | retval.Image = new UUID((string)reader["profileImage"]); | ||
436 | retval.FirstLifeImage = new UUID((string)reader["profileFirstImage"]); | ||
437 | retval.WebLoginKey = new UUID((string)reader["webLoginKey"]); | ||
438 | } | ||
439 | else | ||
440 | { | ||
441 | return null; | ||
442 | } | ||
443 | return retval; | ||
444 | } | 308 | } |
445 | 309 | ||
446 | /// <summary> | 310 | /// <summary> |
447 | /// Reads an agent row from a database reader | 311 | /// Checks if we need to do some migrations to the database |
448 | /// </summary> | 312 | /// </summary> |
449 | /// <param name="reader">An active database reader</param> | 313 | /// <param name="migrationStore">migrationStore.</param> |
450 | /// <returns>A user session agent</returns> | 314 | public void CheckMigration(string migrationStore) |
451 | public UserAgentData readAgentRow(IDataReader reader) | ||
452 | { | 315 | { |
453 | UserAgentData retval = new UserAgentData(); | 316 | using (SqlConnection connection = DatabaseConnection()) |
454 | |||
455 | if (reader.Read()) | ||
456 | { | 317 | { |
457 | // Agent IDs | 318 | Assembly assem = GetType().Assembly; |
458 | retval.ProfileID = new UUID((string)reader["UUID"]); | 319 | MSSQLMigration migration = new MSSQLMigration(connection, assem, migrationStore); |
459 | retval.SessionID = new UUID((string)reader["sessionID"]); | ||
460 | retval.SecureSessionID = new UUID((string)reader["secureSessionID"]); | ||
461 | |||
462 | // Agent Who? | ||
463 | retval.AgentIP = (string)reader["agentIP"]; | ||
464 | retval.AgentPort = Convert.ToUInt32(reader["agentPort"].ToString()); | ||
465 | retval.AgentOnline = Convert.ToInt32(reader["agentOnline"].ToString()) != 0; | ||
466 | |||
467 | // Login/Logout times (UNIX Epoch) | ||
468 | retval.LoginTime = Convert.ToInt32(reader["loginTime"].ToString()); | ||
469 | retval.LogoutTime = Convert.ToInt32(reader["logoutTime"].ToString()); | ||
470 | |||
471 | // Current position | ||
472 | retval.Region = (string)reader["currentRegion"]; | ||
473 | retval.Handle = Convert.ToUInt64(reader["currentHandle"].ToString()); | ||
474 | Vector3 tmp_v; | ||
475 | Vector3.TryParse((string)reader["currentPos"], out tmp_v); | ||
476 | retval.Position = tmp_v; | ||
477 | 320 | ||
478 | } | 321 | migration.Update(); |
479 | else | ||
480 | { | ||
481 | return null; | ||
482 | } | ||
483 | return retval; | ||
484 | } | ||
485 | 322 | ||
486 | /// <summary> | 323 | connection.Close(); |
487 | /// | ||
488 | /// </summary> | ||
489 | /// <param name="reader"></param> | ||
490 | /// <returns></returns> | ||
491 | public AssetBase getAssetRow(IDataReader reader) | ||
492 | { | ||
493 | AssetBase asset = new AssetBase(); | ||
494 | if (reader.Read()) | ||
495 | { | ||
496 | // Region Main | ||
497 | asset = new AssetBase(); | ||
498 | asset.Data = (byte[])reader["data"]; | ||
499 | asset.Description = (string)reader["description"]; | ||
500 | asset.FullID = new UUID((string)reader["id"]); | ||
501 | asset.Local = Convert.ToBoolean(reader["local"]); // ((sbyte)reader["local"]) != 0 ? true : false; | ||
502 | asset.Name = (string)reader["name"]; | ||
503 | asset.Type = Convert.ToSByte(reader["assetType"]); | ||
504 | } | 324 | } |
505 | else | ||
506 | { | ||
507 | return null; // throw new Exception("No rows to return"); | ||
508 | } | ||
509 | return asset; | ||
510 | } | 325 | } |
511 | 326 | ||
512 | 327 | #region Old Testtable functions | |
513 | /// <summary> | ||
514 | /// Inserts a new row into the log database | ||
515 | /// </summary> | ||
516 | /// <param name="serverDaemon">The daemon which triggered this event</param> | ||
517 | /// <param name="target">Who were we operating on when this occured (region UUID, user UUID, etc)</param> | ||
518 | /// <param name="methodCall">The method call where the problem occured</param> | ||
519 | /// <param name="arguments">The arguments passed to the method</param> | ||
520 | /// <param name="priority">How critical is this?</param> | ||
521 | /// <param name="logMessage">Extra message info</param> | ||
522 | /// <returns>Saved successfully?</returns> | ||
523 | public bool insertLogRow(string serverDaemon, string target, string methodCall, string arguments, int priority, | ||
524 | string logMessage) | ||
525 | { | ||
526 | string sql = "INSERT INTO logs ([target], [server], [method], [arguments], [priority], [message]) VALUES "; | ||
527 | sql += "(@target, @server, @method, @arguments, @priority, @message);"; | ||
528 | |||
529 | Dictionary<string, string> parameters = new Dictionary<string, string>(); | ||
530 | parameters["server"] = serverDaemon; | ||
531 | parameters["target"] = target; | ||
532 | parameters["method"] = methodCall; | ||
533 | parameters["arguments"] = arguments; | ||
534 | parameters["priority"] = priority.ToString(); | ||
535 | parameters["message"] = logMessage; | ||
536 | |||
537 | bool returnval = false; | ||
538 | |||
539 | using (IDbCommand result = Query(sql, parameters)) | ||
540 | { | ||
541 | try | ||
542 | { | ||
543 | |||
544 | if (result.ExecuteNonQuery() == 1) | ||
545 | returnval = true; | ||
546 | |||
547 | } | ||
548 | catch (Exception e) | ||
549 | { | ||
550 | m_log.Error(e.ToString()); | ||
551 | return false; | ||
552 | } | ||
553 | } | ||
554 | |||
555 | return returnval; | ||
556 | } | ||
557 | 328 | ||
558 | /// <summary> | 329 | /// <summary> |
559 | /// Execute a SQL statement stored in a resource, as a string | 330 | /// Execute a SQL statement stored in a resource, as a string |
@@ -561,13 +332,12 @@ namespace OpenSim.Data.MSSQL | |||
561 | /// <param name="name">the ressource string</param> | 332 | /// <param name="name">the ressource string</param> |
562 | public void ExecuteResourceSql(string name) | 333 | public void ExecuteResourceSql(string name) |
563 | { | 334 | { |
564 | using (IDbCommand cmd = Query(getResourceString(name), new Dictionary<string,string>())) | 335 | using (IDbCommand cmd = Query(getResourceString(name), new Dictionary<string, string>())) |
565 | { | 336 | { |
566 | cmd.ExecuteNonQuery(); | 337 | cmd.ExecuteNonQuery(); |
567 | } | 338 | } |
568 | } | 339 | } |
569 | 340 | ||
570 | |||
571 | /// <summary> | 341 | /// <summary> |
572 | /// Given a list of tables, return the version of the tables, as seen in the database | 342 | /// Given a list of tables, return the version of the tables, as seen in the database |
573 | /// </summary> | 343 | /// </summary> |
@@ -622,6 +392,8 @@ namespace OpenSim.Data.MSSQL | |||
622 | throw new Exception(string.Format("Resource '{0}' was not found", name)); | 392 | throw new Exception(string.Format("Resource '{0}' was not found", name)); |
623 | } | 393 | } |
624 | 394 | ||
395 | #endregion | ||
396 | |||
625 | /// <summary> | 397 | /// <summary> |
626 | /// Returns the version of this DB provider | 398 | /// Returns the version of this DB provider |
627 | /// </summary> | 399 | /// </summary> |
@@ -636,63 +408,5 @@ namespace OpenSim.Data.MSSQL | |||
636 | string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, | 408 | string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, |
637 | dllVersion.Revision); | 409 | dllVersion.Revision); |
638 | } | 410 | } |
639 | |||
640 | public bool insertAgentRow(UserAgentData agentdata) | ||
641 | { | ||
642 | string sql = @" | ||
643 | |||
644 | IF EXISTS (SELECT * FROM agents WHERE UUID = @UUID) | ||
645 | BEGIN | ||
646 | UPDATE agents SET UUID = @UUID, sessionID = @sessionID, secureSessionID = @secureSessionID, agentIP = @agentIP, agentPort = @agentPort, agentOnline = @agentOnline, loginTime = @loginTime, logoutTime = @logoutTime, currentRegion = @currentRegion, currentHandle = @currentHandle, currentPos = @currentPos | ||
647 | WHERE UUID = @UUID | ||
648 | END | ||
649 | ELSE | ||
650 | BEGIN | ||
651 | INSERT INTO | ||
652 | agents (UUID, sessionID, secureSessionID, agentIP, agentPort, agentOnline, loginTime, logoutTime, currentRegion, currentHandle, currentPos) VALUES | ||
653 | (@UUID, @sessionID, @secureSessionID, @agentIP, @agentPort, @agentOnline, @loginTime, @logoutTime, @currentRegion, @currentHandle, @currentPos) | ||
654 | END | ||
655 | "; | ||
656 | |||
657 | Dictionary<string, string> parameters = new Dictionary<string, string>(); | ||
658 | |||
659 | parameters["@UUID"] = agentdata.ProfileID.ToString(); | ||
660 | parameters["@sessionID"] = agentdata.SessionID.ToString(); | ||
661 | parameters["@secureSessionID"] = agentdata.SecureSessionID.ToString(); | ||
662 | parameters["@agentIP"] = agentdata.AgentIP.ToString(); | ||
663 | parameters["@agentPort"] = agentdata.AgentPort.ToString(); | ||
664 | parameters["@agentOnline"] = (agentdata.AgentOnline == true) ? "1" : "0"; | ||
665 | parameters["@loginTime"] = agentdata.LoginTime.ToString(); | ||
666 | parameters["@logoutTime"] = agentdata.LogoutTime.ToString(); | ||
667 | parameters["@currentRegion"] = agentdata.Region.ToString(); | ||
668 | parameters["@currentHandle"] = agentdata.Handle.ToString(); | ||
669 | parameters["@currentPos"] = "<" + ((int)agentdata.Position.X).ToString() + "," + ((int)agentdata.Position.Y).ToString() + "," + ((int)agentdata.Position.Z).ToString() + ">"; | ||
670 | |||
671 | |||
672 | using (IDbCommand result = Query(sql, parameters)) | ||
673 | { | ||
674 | result.Transaction = result.Connection.BeginTransaction(IsolationLevel.Serializable); | ||
675 | try | ||
676 | { | ||
677 | if (result.ExecuteNonQuery() > 0) | ||
678 | { | ||
679 | result.Transaction.Commit(); | ||
680 | return true; | ||
681 | } | ||
682 | else | ||
683 | { | ||
684 | result.Transaction.Rollback(); | ||
685 | return false; | ||
686 | } | ||
687 | } | ||
688 | catch (Exception e) | ||
689 | { | ||
690 | result.Transaction.Rollback(); | ||
691 | m_log.Error(e.ToString()); | ||
692 | return false; | ||
693 | } | ||
694 | } | ||
695 | |||
696 | } | ||
697 | } | 411 | } |
698 | } | 412 | } |