aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite
diff options
context:
space:
mode:
authorSean Dague2007-10-22 15:37:54 +0000
committerSean Dague2007-10-22 15:37:54 +0000
commit6acaabefc32525aed7ded45fc15e6152895d5382 (patch)
tree1350ddbde54e72c8d96719580a416cc2f0d85d24 /OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite
parent* Major ass commit. (diff)
downloadopensim-SC_OLD-6acaabefc32525aed7ded45fc15e6152895d5382.zip
opensim-SC_OLD-6acaabefc32525aed7ded45fc15e6152895d5382.tar.gz
opensim-SC_OLD-6acaabefc32525aed7ded45fc15e6152895d5382.tar.bz2
opensim-SC_OLD-6acaabefc32525aed7ded45fc15e6152895d5382.tar.xz
revert r2162 as it completely clobbered all the work on
the ChatModule by MW and myself. Couldn't find Adam online after that rev went in.
Diffstat (limited to 'OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite')
-rw-r--r--OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs121
1 files changed, 4 insertions, 117 deletions
diff --git a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs
index cc0ff7a..733e4c4 100644
--- a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs
+++ b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs
@@ -43,12 +43,10 @@ namespace OpenSim.DataStore.MonoSqlite
43 { 43 {
44 private const string primSelect = "select * from prims"; 44 private const string primSelect = "select * from prims";
45 private const string shapeSelect = "select * from primshapes"; 45 private const string shapeSelect = "select * from primshapes";
46 private const string terrainSelect = "select * from terrain";
47 46
48 private DataSet ds; 47 private DataSet ds;
49 private SqliteDataAdapter primDa; 48 private SqliteDataAdapter primDa;
50 private SqliteDataAdapter shapeDa; 49 private SqliteDataAdapter shapeDa;
51 private SqliteDataAdapter terrainDa;
52 50
53 /*********************************************************************** 51 /***********************************************************************
54 * 52 *
@@ -72,8 +70,6 @@ namespace OpenSim.DataStore.MonoSqlite
72 shapeDa = new SqliteDataAdapter(shapeSelectCmd); 70 shapeDa = new SqliteDataAdapter(shapeSelectCmd);
73 // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa); 71 // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa);
74 72
75 SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, conn);
76 terrainDa = new SqliteDataAdapter(terrainSelectCmd);
77 73
78 // We fill the data set, now we've got copies in memory for the information 74 // We fill the data set, now we've got copies in memory for the information
79 // TODO: see if the linkage actually holds. 75 // TODO: see if the linkage actually holds.
@@ -87,10 +83,6 @@ namespace OpenSim.DataStore.MonoSqlite
87 83
88 ds.Tables.Add(createShapeTable()); 84 ds.Tables.Add(createShapeTable());
89 setupShapeCommands(shapeDa, conn); 85 setupShapeCommands(shapeDa, conn);
90
91 ds.Tables.Add(createTerrainTable());
92 setupTerrainCommands(terrainDa, conn);
93 terrainDa.Fill(ds.Tables["terrain"]);
94 86
95 // WORKAROUND: This is a work around for sqlite on 87 // WORKAROUND: This is a work around for sqlite on
96 // windows, which gets really unhappy with blob columns 88 // windows, which gets really unhappy with blob columns
@@ -218,57 +210,14 @@ namespace OpenSim.DataStore.MonoSqlite
218 } 210 }
219 211
220 212
221 public void StoreTerrain(double[,] ter, LLUUID regionID) 213 public void StoreTerrain(double[,] ter)
222 { 214 {
223 int revision = OpenSim.Framework.Utilities.Util.UnixTimeSinceEpoch();
224
225 MainLog.Instance.Verbose("DATASTORE", "Storing terrain revision r" + revision.ToString());
226
227 DataTable terrain = ds.Tables["terrain"];
228
229 DataRow newrow = terrain.NewRow();
230 fillTerrainRow(newrow, regionID, revision, ter);
231 terrain.Rows.Add(newrow);
232 215
233 Commit();
234 } 216 }
235 217
236 public double[,] LoadTerrain(LLUUID regionID) 218 public double[,] LoadTerrain()
237 { 219 {
238 double[,] terret = new double[256, 256]; 220 return null;
239 terret.Initialize();
240
241 DataTable terrain = ds.Tables["terrain"];
242
243 DataRow[] rows = terrain.Select("RegionUUID = '" + regionID.ToString() + "'","Revision DESC");
244
245 int rev = 0;
246
247 if (rows.Length > 0)
248 {
249 DataRow row = rows[0];
250
251 byte[] heightmap = (byte[])row["Heightfield"];
252 for (int x = 0; x < 256; x++)
253 {
254 for (int y = 0; y < 256; y++)
255 {
256 terret[x, y] = BitConverter.ToDouble(heightmap, ((x * 256) + y) * 8);
257 }
258 }
259
260 rev = (int)row["Revision"];
261 }
262 else
263 {
264 MainLog.Instance.Verbose("DATASTORE", "No terrain found for region");
265 return null;
266 }
267
268
269 MainLog.Instance.Verbose("DATASTORE", "Loaded terrain revision r" + rev.ToString());
270
271 return terret;
272 } 221 }
273 222
274 public void RemoveLandObject(uint id) 223 public void RemoveLandObject(uint id)
@@ -291,7 +240,6 @@ namespace OpenSim.DataStore.MonoSqlite
291 lock (ds) { 240 lock (ds) {
292 primDa.Update(ds, "prims"); 241 primDa.Update(ds, "prims");
293 shapeDa.Update(ds, "primshapes"); 242 shapeDa.Update(ds, "primshapes");
294 terrainDa.Update(ds, "terrain");
295 ds.AcceptChanges(); 243 ds.AcceptChanges();
296 } 244 }
297 } 245 }
@@ -315,22 +263,6 @@ namespace OpenSim.DataStore.MonoSqlite
315 dt.Columns.Add(col); 263 dt.Columns.Add(col);
316 } 264 }
317 265
318 private DataTable createTerrainTable()
319 {
320 DataTable terrain = new DataTable("terrain");
321
322 createCol(terrain, "RegionUUID", typeof(System.String));
323 createCol(terrain, "Revision", typeof(System.Int32));
324 createCol(terrain, "Heightfield", typeof(System.Byte[]));
325
326 /* // Attempting to work out requirements to get SQLite to actually *save* the data.
327 createCol(terrain, "PrIndex", typeof(System.String));
328 terrain.PrimaryKey = new DataColumn[] { terrain.Columns["PrIndex"] };
329 */
330
331 return terrain;
332 }
333
334 private DataTable createPrimTable() 266 private DataTable createPrimTable()
335 { 267 {
336 DataTable prims = new DataTable("prims"); 268 DataTable prims = new DataTable("prims");
@@ -499,22 +431,6 @@ namespace OpenSim.DataStore.MonoSqlite
499 return prim; 431 return prim;
500 } 432 }
501 433
502 private void fillTerrainRow(DataRow row, LLUUID regionUUID, int rev, double[,] val)
503 {
504 row["RegionUUID"] = regionUUID;
505 row["Revision"] = rev;
506
507 System.IO.MemoryStream str = new System.IO.MemoryStream(65536 * sizeof(double));
508 System.IO.BinaryWriter bw = new System.IO.BinaryWriter(str);
509
510 // TODO: COMPATIBILITY - Add byte-order conversions
511 for (int x = 0; x < 256; x++)
512 for (int y = 0; y < 256; y++)
513 bw.Write(val[x, y]);
514
515 row["Heightfield"] = str.ToArray();
516 }
517
518 private void fillPrimRow(DataRow row, SceneObjectPart prim, LLUUID sceneGroupID, LLUUID regionUUID) 434 private void fillPrimRow(DataRow row, SceneObjectPart prim, LLUUID sceneGroupID, LLUUID regionUUID)
519 { 435 {
520 row["UUID"] = prim.UUID; 436 row["UUID"] = prim.UUID;
@@ -776,7 +692,7 @@ namespace OpenSim.DataStore.MonoSqlite
776 subsql += ",\n"; 692 subsql += ",\n";
777 } 693 }
778 subsql += col.ColumnName + " " + sqliteType(col.DataType); 694 subsql += col.ColumnName + " " + sqliteType(col.DataType);
779 if (dt.PrimaryKey.Length > 0 && col == dt.PrimaryKey[0]) 695 if (col == dt.PrimaryKey[0])
780 { 696 {
781 subsql += " primary key"; 697 subsql += " primary key";
782 } 698 }
@@ -830,12 +746,6 @@ namespace OpenSim.DataStore.MonoSqlite
830 da.DeleteCommand = delete; 746 da.DeleteCommand = delete;
831 } 747 }
832 748
833 private void setupTerrainCommands(SqliteDataAdapter da, SqliteConnection conn)
834 {
835 da.InsertCommand = createInsertCommand("terrain", ds.Tables["terrain"]);
836 da.InsertCommand.Connection = conn;
837 }
838
839 private void setupShapeCommands(SqliteDataAdapter da, SqliteConnection conn) 749 private void setupShapeCommands(SqliteDataAdapter da, SqliteConnection conn)
840 { 750 {
841 da.InsertCommand = createInsertCommand("primshapes", ds.Tables["primshapes"]); 751 da.InsertCommand = createInsertCommand("primshapes", ds.Tables["primshapes"]);
@@ -854,15 +764,12 @@ namespace OpenSim.DataStore.MonoSqlite
854 { 764 {
855 string createPrims = defineTable(createPrimTable()); 765 string createPrims = defineTable(createPrimTable());
856 string createShapes = defineTable(createShapeTable()); 766 string createShapes = defineTable(createShapeTable());
857 string createTerrain = defineTable(createTerrainTable());
858 767
859 SqliteCommand pcmd = new SqliteCommand(createPrims, conn); 768 SqliteCommand pcmd = new SqliteCommand(createPrims, conn);
860 SqliteCommand scmd = new SqliteCommand(createShapes, conn); 769 SqliteCommand scmd = new SqliteCommand(createShapes, conn);
861 SqliteCommand tcmd = new SqliteCommand(createTerrain, conn);
862 conn.Open(); 770 conn.Open();
863 pcmd.ExecuteNonQuery(); 771 pcmd.ExecuteNonQuery();
864 scmd.ExecuteNonQuery(); 772 scmd.ExecuteNonQuery();
865 tcmd.ExecuteNonQuery();
866 conn.Close(); 773 conn.Close();
867 } 774 }
868 775
@@ -872,15 +779,12 @@ namespace OpenSim.DataStore.MonoSqlite
872 SqliteDataAdapter pDa = new SqliteDataAdapter(primSelectCmd); 779 SqliteDataAdapter pDa = new SqliteDataAdapter(primSelectCmd);
873 SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, conn); 780 SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, conn);
874 SqliteDataAdapter sDa = new SqliteDataAdapter(shapeSelectCmd); 781 SqliteDataAdapter sDa = new SqliteDataAdapter(shapeSelectCmd);
875 SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, conn);
876 SqliteDataAdapter tDa = new SqliteDataAdapter(terrainSelectCmd);
877 782
878 DataSet tmpDS = new DataSet(); 783 DataSet tmpDS = new DataSet();
879 try 784 try
880 { 785 {
881 pDa.Fill(tmpDS, "prims"); 786 pDa.Fill(tmpDS, "prims");
882 sDa.Fill(tmpDS, "primshapes"); 787 sDa.Fill(tmpDS, "primshapes");
883 tDa.Fill(tmpDS, "terrain");
884 } 788 }
885 catch (Mono.Data.SqliteClient.SqliteSyntaxException) 789 catch (Mono.Data.SqliteClient.SqliteSyntaxException)
886 { 790 {
@@ -890,7 +794,6 @@ namespace OpenSim.DataStore.MonoSqlite
890 794
891 pDa.Fill(tmpDS, "prims"); 795 pDa.Fill(tmpDS, "prims");
892 sDa.Fill(tmpDS, "primshapes"); 796 sDa.Fill(tmpDS, "primshapes");
893 tDa.Fill(tmpDS, "terrain");
894 797
895 foreach (DataColumn col in createPrimTable().Columns) 798 foreach (DataColumn col in createPrimTable().Columns)
896 { 799 {
@@ -908,14 +811,6 @@ namespace OpenSim.DataStore.MonoSqlite
908 return false; 811 return false;
909 } 812 }
910 } 813 }
911 foreach (DataColumn col in createTerrainTable().Columns)
912 {
913 if (!tmpDS.Tables["terrain"].Columns.Contains(col.ColumnName))
914 {
915 MainLog.Instance.Verbose("DATASTORE", "Missing require column:" + col.ColumnName);
916 return false;
917 }
918 }
919 return true; 814 return true;
920 } 815 }
921 816
@@ -939,14 +834,6 @@ namespace OpenSim.DataStore.MonoSqlite
939 { 834 {
940 return DbType.Double; 835 return DbType.Double;
941 } 836 }
942 else if (type == typeof(System.Byte))
943 {
944 return DbType.Byte;
945 }
946 else if (type == typeof(System.Double))
947 {
948 return DbType.Double;
949 }
950 else if (type == typeof(System.Byte[])) 837 else if (type == typeof(System.Byte[]))
951 { 838 {
952 return DbType.Binary; 839 return DbType.Binary;