aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/SQLite/SQLiteRegionData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/SQLite/SQLiteRegionData.cs')
-rw-r--r--OpenSim/Data/SQLite/SQLiteRegionData.cs311
1 files changed, 190 insertions, 121 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteRegionData.cs b/OpenSim/Data/SQLite/SQLiteRegionData.cs
index 5a4ee2a..4313db8 100644
--- a/OpenSim/Data/SQLite/SQLiteRegionData.cs
+++ b/OpenSim/Data/SQLite/SQLiteRegionData.cs
@@ -32,7 +32,7 @@ using System.Drawing;
32using System.IO; 32using System.IO;
33using System.Reflection; 33using System.Reflection;
34using log4net; 34using log4net;
35using Mono.Data.SqliteClient; 35using Mono.Data.Sqlite;
36using OpenMetaverse; 36using OpenMetaverse;
37using OpenSim.Framework; 37using OpenSim.Framework;
38using OpenSim.Region.Framework.Interfaces; 38using OpenSim.Region.Framework.Interfaces;
@@ -87,119 +87,151 @@ namespace OpenSim.Data.SQLite
87 /// <param name="connectionString">the connection string</param> 87 /// <param name="connectionString">the connection string</param>
88 public void Initialise(string connectionString) 88 public void Initialise(string connectionString)
89 { 89 {
90 m_connectionString = connectionString; 90 try
91 {
92 m_connectionString = connectionString;
91 93
92 ds = new DataSet(); 94 ds = new DataSet("Region");
93 95
94 m_log.Info("[REGION DB]: Sqlite - connecting: " + connectionString); 96 m_log.Info("[SQLITE REGION DB]: Sqlite - connecting: " + connectionString);
95 m_conn = new SqliteConnection(m_connectionString); 97 m_conn = new SqliteConnection(m_connectionString);
96 m_conn.Open(); 98 m_conn.Open();
97 99
100 SqliteCommand primSelectCmd = new SqliteCommand(primSelect, m_conn);
101 primDa = new SqliteDataAdapter(primSelectCmd);
98 102
103 SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, m_conn);
104 shapeDa = new SqliteDataAdapter(shapeSelectCmd);
105 // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa);
99 106
100 SqliteCommand primSelectCmd = new SqliteCommand(primSelect, m_conn); 107 SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, m_conn);
101 primDa = new SqliteDataAdapter(primSelectCmd); 108 itemsDa = new SqliteDataAdapter(itemsSelectCmd);
102 // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa);
103 109
104 SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, m_conn); 110 SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, m_conn);
105 shapeDa = new SqliteDataAdapter(shapeSelectCmd); 111 terrainDa = new SqliteDataAdapter(terrainSelectCmd);
106 // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa);
107 112
108 SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, m_conn); 113 SqliteCommand landSelectCmd = new SqliteCommand(landSelect, m_conn);
109 itemsDa = new SqliteDataAdapter(itemsSelectCmd); 114 landDa = new SqliteDataAdapter(landSelectCmd);
110 115
111 SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, m_conn); 116 SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn);
112 terrainDa = new SqliteDataAdapter(terrainSelectCmd); 117 landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd);
113 118
114 SqliteCommand landSelectCmd = new SqliteCommand(landSelect, m_conn); 119 SqliteCommand regionSettingsSelectCmd = new SqliteCommand(regionSettingsSelect, m_conn);
115 landDa = new SqliteDataAdapter(landSelectCmd); 120 regionSettingsDa = new SqliteDataAdapter(regionSettingsSelectCmd);
121 // This actually does the roll forward assembly stuff
122 Assembly assem = GetType().Assembly;
123 Migration m = new Migration(m_conn, assem, "RegionStore");
124 m.Update();
116 125
117 SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn); 126 lock (ds)
118 landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd); 127 {
128 ds.Tables.Add(createPrimTable());
129 setupPrimCommands(primDa, m_conn);
119 130
120 SqliteCommand regionSettingsSelectCmd = new SqliteCommand(regionSettingsSelect, m_conn); 131 ds.Tables.Add(createShapeTable());
121 regionSettingsDa = new SqliteDataAdapter(regionSettingsSelectCmd); 132 setupShapeCommands(shapeDa, m_conn);
122 // This actually does the roll forward assembly stuff
123 Assembly assem = GetType().Assembly;
124 Migration m = new Migration(m_conn, assem, "RegionStore");
125 m.Update();
126 133
127 lock (ds) 134 ds.Tables.Add(createItemsTable());
128 { 135 setupItemsCommands(itemsDa, m_conn);
129 ds.Tables.Add(createPrimTable());
130 setupPrimCommands(primDa, m_conn);
131 primDa.Fill(ds.Tables["prims"]);
132 136
133 ds.Tables.Add(createShapeTable()); 137 ds.Tables.Add(createTerrainTable());
134 setupShapeCommands(shapeDa, m_conn); 138 setupTerrainCommands(terrainDa, m_conn);
135 139
136 ds.Tables.Add(createItemsTable()); 140 ds.Tables.Add(createLandTable());
137 setupItemsCommands(itemsDa, m_conn); 141 setupLandCommands(landDa, m_conn);
138 itemsDa.Fill(ds.Tables["primitems"]);
139 142
140 ds.Tables.Add(createTerrainTable()); 143 ds.Tables.Add(createLandAccessListTable());
141 setupTerrainCommands(terrainDa, m_conn); 144 setupLandAccessCommands(landAccessListDa, m_conn);
142 145
143 ds.Tables.Add(createLandTable()); 146 ds.Tables.Add(createRegionSettingsTable());
144 setupLandCommands(landDa, m_conn); 147 setupRegionSettingsCommands(regionSettingsDa, m_conn);
145 148
146 ds.Tables.Add(createLandAccessListTable()); 149 // WORKAROUND: This is a work around for sqlite on
147 setupLandAccessCommands(landAccessListDa, m_conn); 150 // windows, which gets really unhappy with blob columns
151 // that have no sample data in them. At some point we
152 // need to actually find a proper way to handle this.
153 try
154 {
155 primDa.Fill(ds.Tables["prims"]);
156 }
157 catch (Exception)
158 {
159 m_log.Info("[SQLITE REGION DB]: Caught fill error on prims table");
160 }
148 161
149 ds.Tables.Add(createRegionSettingsTable()); 162 try
150 163 {
151 setupRegionSettingsCommands(regionSettingsDa, m_conn); 164 shapeDa.Fill(ds.Tables["primshapes"]);
165 }
166 catch (Exception)
167 {
168 m_log.Info("[SQLITE REGION DB]: Caught fill error on primshapes table");
169 }
152 170
153 // WORKAROUND: This is a work around for sqlite on 171 try
154 // windows, which gets really unhappy with blob columns 172 {
155 // that have no sample data in them. At some point we 173 itemsDa.Fill(ds.Tables["primitems"]);
156 // need to actually find a proper way to handle this. 174 }
157 try 175 catch (Exception)
158 { 176 {
159 shapeDa.Fill(ds.Tables["primshapes"]); 177 m_log.Info("[SQLITE REGION DB]: Caught fill error on primitems table");
160 } 178 }
161 catch (Exception) 179
162 { 180 try
163 m_log.Info("[REGION DB]: Caught fill error on primshapes table"); 181 {
164 } 182 terrainDa.Fill(ds.Tables["terrain"]);
183 }
184 catch (Exception)
185 {
186 m_log.Info("[SQLITE REGION DB]: Caught fill error on terrain table");
187 }
165 188
166 try 189 try
167 { 190 {
168 terrainDa.Fill(ds.Tables["terrain"]); 191 landDa.Fill(ds.Tables["land"]);
169 } 192 }
170 catch (Exception) 193 catch (Exception)
171 { 194 {
172 m_log.Info("[REGION DB]: Caught fill error on terrain table"); 195 m_log.Info("[SQLITE REGION DB]: Caught fill error on land table");
173 } 196 }
174 197
175 try 198 try
176 { 199 {
177 landDa.Fill(ds.Tables["land"]); 200 landAccessListDa.Fill(ds.Tables["landaccesslist"]);
178 } 201 }
179 catch (Exception) 202 catch (Exception)
180 { 203 {
181 m_log.Info("[REGION DB]: Caught fill error on land table"); 204 m_log.Info("[SQLITE REGION DB]: Caught fill error on landaccesslist table");
182 } 205 }
183 206
184 try 207 try
185 { 208 {
186 landAccessListDa.Fill(ds.Tables["landaccesslist"]); 209 regionSettingsDa.Fill(ds.Tables["regionsettings"]);
187 } 210 }
188 catch (Exception) 211 catch (Exception)
189 { 212 {
190 m_log.Info("[REGION DB]: Caught fill error on landaccesslist table"); 213 m_log.Info("[SQLITE REGION DB]: Caught fill error on regionsettings table");
191 } 214 }
192 215
193 try 216 // We have to create a data set mapping for every table, otherwise the IDataAdaptor.Update() will not populate rows with values!
194 { 217 // Not sure exactly why this is - this kind of thing was not necessary before - justincc 20100409
195 regionSettingsDa.Fill(ds.Tables["regionsettings"]); 218 // Possibly because we manually set up our own DataTables before connecting to the database
196 } 219 CreateDataSetMapping(primDa, "prims");
197 catch (Exception) 220 CreateDataSetMapping(shapeDa, "primshapes");
198 { 221 CreateDataSetMapping(itemsDa, "primitems");
199 m_log.Info("[REGION DB]: Caught fill error on regionsettings table"); 222 CreateDataSetMapping(terrainDa, "terrain");
223 CreateDataSetMapping(landDa, "land");
224 CreateDataSetMapping(landAccessListDa, "landaccesslist");
225 CreateDataSetMapping(regionSettingsDa, "regionsettings");
200 } 226 }
201 return;
202 } 227 }
228 catch (Exception e)
229 {
230 m_log.Error(e);
231 Environment.Exit(23);
232 }
233
234 return;
203 } 235 }
204 236
205 public void Dispose() 237 public void Dispose()
@@ -402,7 +434,7 @@ namespace OpenSim.Data.SQLite
402 lock (ds) 434 lock (ds)
403 { 435 {
404 DataRow[] primsForRegion = prims.Select(byRegion); 436 DataRow[] primsForRegion = prims.Select(byRegion);
405 m_log.Info("[REGION DB]: Loaded " + primsForRegion.Length + " prims for region: " + regionUUID); 437// m_log.Info("[SQLITE REGION DB]: Loaded " + primsForRegion.Length + " prims for region: " + regionUUID);
406 438
407 // First, create all groups 439 // First, create all groups
408 foreach (DataRow primRow in primsForRegion) 440 foreach (DataRow primRow in primsForRegion)
@@ -424,8 +456,8 @@ namespace OpenSim.Data.SQLite
424 } 456 }
425 else 457 else
426 { 458 {
427 m_log.Info( 459 m_log.Warn(
428 "[REGION DB]: No shape found for prim in storage, so setting default box shape"); 460 "[SQLITE REGION DB]: No shape found for prim in storage, so setting default box shape");
429 prim.Shape = PrimitiveBaseShape.Default; 461 prim.Shape = PrimitiveBaseShape.Default;
430 } 462 }
431 463
@@ -437,11 +469,11 @@ namespace OpenSim.Data.SQLite
437 } 469 }
438 catch (Exception e) 470 catch (Exception e)
439 { 471 {
440 m_log.Error("[REGION DB]: Failed create prim object in new group, exception and data follows"); 472 m_log.Error("[SQLITE REGION DB]: Failed create prim object in new group, exception and data follows");
441 m_log.Info("[REGION DB]: " + e.ToString()); 473 m_log.Error("[SQLITE REGION DB]: ", e);
442 foreach (DataColumn col in prims.Columns) 474 foreach (DataColumn col in prims.Columns)
443 { 475 {
444 m_log.Info("[REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]); 476 m_log.Error("[SQLITE REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]);
445 } 477 }
446 } 478 }
447 } 479 }
@@ -466,7 +498,7 @@ namespace OpenSim.Data.SQLite
466 else 498 else
467 { 499 {
468 m_log.Warn( 500 m_log.Warn(
469 "[REGION DB]: No shape found for prim in storage, so setting default box shape"); 501 "[SQLITE REGION DB]: No shape found for prim in storage, so setting default box shape");
470 prim.Shape = PrimitiveBaseShape.Default; 502 prim.Shape = PrimitiveBaseShape.Default;
471 } 503 }
472 504
@@ -476,11 +508,11 @@ namespace OpenSim.Data.SQLite
476 } 508 }
477 catch (Exception e) 509 catch (Exception e)
478 { 510 {
479 m_log.Error("[REGION DB]: Failed create prim object in group, exception and data follows"); 511 m_log.Error("[SQLITE REGION DB]: Failed create prim object in group, exception and data follows");
480 m_log.Info("[REGION DB]: " + e.ToString()); 512 m_log.Error("[SQLITE REGION DB]: ", e);
481 foreach (DataColumn col in prims.Columns) 513 foreach (DataColumn col in prims.Columns)
482 { 514 {
483 m_log.Info("[REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]); 515 m_log.Error("[SQLITE REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]);
484 } 516 }
485 } 517 }
486 } 518 }
@@ -493,20 +525,23 @@ namespace OpenSim.Data.SQLite
493 /// </summary> 525 /// </summary>
494 /// <param name="prim">the prim</param> 526 /// <param name="prim">the prim</param>
495 private void LoadItems(SceneObjectPart prim) 527 private void LoadItems(SceneObjectPart prim)
496 { 528 {
497 //m_log.DebugFormat("[DATASTORE]: Loading inventory for {0}, {1}", prim.Name, prim.UUID); 529// m_log.DebugFormat("[SQLITE REGION DB]: Loading inventory for {0} {1}", prim.Name, prim.UUID);
498 530
499 DataTable dbItems = ds.Tables["primitems"]; 531 DataTable dbItems = ds.Tables["primitems"];
500 String sql = String.Format("primID = '{0}'", prim.UUID.ToString()); 532 String sql = String.Format("primID = '{0}'", prim.UUID.ToString());
501 DataRow[] dbItemRows = dbItems.Select(sql); 533 DataRow[] dbItemRows = dbItems.Select(sql);
502 IList<TaskInventoryItem> inventory = new List<TaskInventoryItem>(); 534 IList<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
503 535
536// m_log.DebugFormat(
537// "[SQLITE REGION DB]: Found {0} items for {1} {2}", dbItemRows.Length, prim.Name, prim.UUID);
538
504 foreach (DataRow row in dbItemRows) 539 foreach (DataRow row in dbItemRows)
505 { 540 {
506 TaskInventoryItem item = buildItem(row); 541 TaskInventoryItem item = buildItem(row);
507 inventory.Add(item); 542 inventory.Add(item);
508 543
509 //m_log.DebugFormat("[DATASTORE]: Restored item {0}, {1}", item.Name, item.ItemID); 544// m_log.DebugFormat("[SQLITE REGION DB]: Restored item {0} {1}", item.Name, item.ItemID);
510 } 545 }
511 546
512 prim.Inventory.RestoreInventoryItems(inventory); 547 prim.Inventory.RestoreInventoryItems(inventory);
@@ -542,7 +577,7 @@ namespace OpenSim.Data.SQLite
542 577
543 // the following is an work around for .NET. The perf 578 // the following is an work around for .NET. The perf
544 // issues associated with it aren't as bad as you think. 579 // issues associated with it aren't as bad as you think.
545 m_log.Info("[REGION DB]: Storing terrain revision r" + revision.ToString()); 580 m_log.Debug("[SQLITE REGION DB]: Storing terrain revision r" + revision.ToString());
546 String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" + 581 String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" +
547 " values(:RegionUUID, :Revision, :Heightfield)"; 582 " values(:RegionUUID, :Revision, :Heightfield)";
548 583
@@ -594,15 +629,15 @@ namespace OpenSim.Data.SQLite
594 } 629 }
595 } 630 }
596 } 631 }
597 rev = (int) row["Revision"]; 632 rev = Convert.ToInt32(row["Revision"]);
598 } 633 }
599 else 634 else
600 { 635 {
601 m_log.Info("[REGION DB]: No terrain found for region"); 636 m_log.Warn("[SQLITE REGION DB]: No terrain found for region");
602 return null; 637 return null;
603 } 638 }
604 639
605 m_log.Info("[REGION DB]: Loaded terrain revision r" + rev.ToString()); 640 m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString());
606 } 641 }
607 } 642 }
608 return terret; 643 return terret;
@@ -746,6 +781,7 @@ namespace OpenSim.Data.SQLite
746 /// </summary> 781 /// </summary>
747 public void Commit() 782 public void Commit()
748 { 783 {
784 //m_log.Debug("[SQLITE]: Starting commit");
749 lock (ds) 785 lock (ds)
750 { 786 {
751 primDa.Update(ds, "prims"); 787 primDa.Update(ds, "prims");
@@ -760,18 +796,11 @@ namespace OpenSim.Data.SQLite
760 { 796 {
761 regionSettingsDa.Update(ds, "regionsettings"); 797 regionSettingsDa.Update(ds, "regionsettings");
762 } 798 }
763 catch (SqliteExecutionException SqlEx) 799 catch (SqliteException SqlEx)
764 { 800 {
765 if (SqlEx.Message.Contains("logic error")) 801 throw new Exception(
766 { 802 "There was a SQL error or connection string configuration error when saving the region settings. This could be a bug, it could also happen if ConnectionString is defined in the [DatabaseService] section of StandaloneCommon.ini in the config_include folder. This could also happen if the config_include folder doesn't exist or if the OpenSim.ini [Architecture] section isn't set. If this is your first time running OpenSimulator, please restart the simulator and bug a developer to fix this!",
767 throw new Exception( 803 SqlEx);
768 "There was a SQL error or connection string configuration error when saving the region settings. This could be a bug, it could also happen if ConnectionString is defined in the [DatabaseService] section of StandaloneCommon.ini in the config_include folder. This could also happen if the config_include folder doesn't exist or if the OpenSim.ini [Architecture] section isn't set. If this is your first time running OpenSimulator, please restart the simulator and bug a developer to fix this!",
769 SqlEx);
770 }
771 else
772 {
773 throw SqlEx;
774 }
775 } 804 }
776 ds.AcceptChanges(); 805 ds.AcceptChanges();
777 } 806 }
@@ -793,6 +822,15 @@ namespace OpenSim.Data.SQLite
793 * 822 *
794 **********************************************************************/ 823 **********************************************************************/
795 824
825 protected void CreateDataSetMapping(IDataAdapter da, string tableName)
826 {
827 ITableMapping dbMapping = da.TableMappings.Add(tableName, tableName);
828 foreach (DataColumn col in ds.Tables[tableName].Columns)
829 {
830 dbMapping.ColumnMappings.Add(col.ColumnName, col.ColumnName);
831 }
832 }
833
796 /// <summary> 834 /// <summary>
797 /// 835 ///
798 /// </summary> 836 /// </summary>
@@ -1381,7 +1419,7 @@ namespace OpenSim.Data.SQLite
1381 } 1419 }
1382 catch (InvalidCastException) 1420 catch (InvalidCastException)
1383 { 1421 {
1384 m_log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name); 1422 m_log.ErrorFormat("[SQLITE REGION DB]: unable to get parcel telehub settings for {1}", newData.Name);
1385 newData.UserLocation = Vector3.Zero; 1423 newData.UserLocation = Vector3.Zero;
1386 newData.UserLookAt = Vector3.Zero; 1424 newData.UserLookAt = Vector3.Zero;
1387 } 1425 }
@@ -1888,7 +1926,7 @@ namespace OpenSim.Data.SQLite
1888 /// <param name="items"></param> 1926 /// <param name="items"></param>
1889 public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items) 1927 public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
1890 { 1928 {
1891 m_log.InfoFormat("[REGION DB]: Entered StorePrimInventory with prim ID {0}", primID); 1929// m_log.DebugFormat("[SQLITE REGION DB]: Entered StorePrimInventory with prim ID {0}", primID);
1892 1930
1893 DataTable dbItems = ds.Tables["primitems"]; 1931 DataTable dbItems = ds.Tables["primitems"];
1894 1932
@@ -1955,6 +1993,7 @@ namespace OpenSim.Data.SQLite
1955 sql += ") values (:"; 1993 sql += ") values (:";
1956 sql += String.Join(", :", cols); 1994 sql += String.Join(", :", cols);
1957 sql += ")"; 1995 sql += ")";
1996 //m_log.DebugFormat("[SQLITE]: Created insert command {0}", sql);
1958 SqliteCommand cmd = new SqliteCommand(sql); 1997 SqliteCommand cmd = new SqliteCommand(sql);
1959 1998
1960 // this provides the binding for all our parameters, so 1999 // this provides the binding for all our parameters, so
@@ -2250,6 +2289,36 @@ namespace OpenSim.Data.SQLite
2250 return DbType.String; 2289 return DbType.String;
2251 } 2290 }
2252 } 2291 }
2292
2293 static void PrintDataSet(DataSet ds)
2294 {
2295 // Print out any name and extended properties.
2296 Console.WriteLine("DataSet is named: {0}", ds.DataSetName);
2297 foreach (System.Collections.DictionaryEntry de in ds.ExtendedProperties)
2298 {
2299 Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
2300 }
2301 Console.WriteLine();
2302 foreach (DataTable dt in ds.Tables)
2303 {
2304 Console.WriteLine("=> {0} Table:", dt.TableName);
2305 // Print out the column names.
2306 for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
2307 {
2308 Console.Write(dt.Columns[curCol].ColumnName + "\t");
2309 }
2310 Console.WriteLine("\n----------------------------------");
2311 // Print the DataTable.
2312 for (int curRow = 0; curRow < dt.Rows.Count; curRow++)
2313 {
2314 for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
2315 {
2316 Console.Write(dt.Rows[curRow][curCol].ToString() + "\t");
2317 }
2318 Console.WriteLine();
2319 }
2320 }
2321 }
2253 2322
2254 } 2323 }
2255} 2324}