OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
SQLiteSimulationData.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors, http://opensimulator.org/
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSimulator Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 using System;
29 using System.Collections.Generic;
30 using System.Data;
31 using System.Drawing;
32 using System.IO;
33 using System.Reflection;
34 using log4net;
35 #if CSharpSqlite
36  using Community.CsharpSqlite.Sqlite;
37 #else
38 using Mono.Data.Sqlite;
39 #endif
40 using OpenMetaverse;
41 using OpenMetaverse.StructuredData;
42 using OpenSim.Framework;
43 using OpenSim.Region.Framework.Interfaces;
44 using OpenSim.Region.Framework.Scenes;
45 
46 namespace OpenSim.Data.SQLite
47 {
52  {
53  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54  private static readonly string LogHeader = "[REGION DB SQLITE]";
55 
56  private const string primSelect = "select * from prims";
57  private const string shapeSelect = "select * from primshapes";
58  private const string itemsSelect = "select * from primitems";
59  private const string terrainSelect = "select * from terrain limit 1";
60  private const string landSelect = "select * from land";
61  private const string landAccessListSelect = "select distinct * from landaccesslist";
62  private const string regionbanListSelect = "select * from regionban";
63  private const string regionSettingsSelect = "select * from regionsettings";
64  private const string regionWindlightSelect = "select * from regionwindlight";
65  private const string regionEnvironmentSelect = "select * from regionenvironment";
66  private const string regionSpawnPointsSelect = "select * from spawn_points";
67 
68  private DataSet ds;
69  private SqliteDataAdapter primDa;
70  private SqliteDataAdapter shapeDa;
71  private SqliteDataAdapter itemsDa;
72  private SqliteDataAdapter terrainDa;
73  private SqliteDataAdapter landDa;
74  private SqliteDataAdapter landAccessListDa;
75  private SqliteDataAdapter regionSettingsDa;
76  private SqliteDataAdapter regionWindlightDa;
77  private SqliteDataAdapter regionEnvironmentDa;
78  private SqliteDataAdapter regionSpawnPointsDa;
79 
80  private SqliteConnection m_conn;
81  private String m_connectionString;
82 
83  protected virtual Assembly Assembly
84  {
85  get { return GetType().Assembly; }
86  }
87 
89  {
90  }
91 
92  public SQLiteSimulationData(string connectionString)
93  {
94  Initialise(connectionString);
95  }
96 
97  // Temporary attribute while this is experimental
98 
99  /***********************************************************************
100  *
101  * Public Interface Functions
102  *
103  **********************************************************************/
104 
112  public void Initialise(string connectionString)
113  {
114  try
115  {
116  if (Util.IsWindows())
117  Util.LoadArchSpecificWindowsDll("sqlite3.dll");
118 
119  m_connectionString = connectionString;
120 
121  ds = new DataSet("Region");
122 
123  m_log.Info("[SQLITE REGION DB]: Sqlite - connecting: " + connectionString);
124  m_conn = new SqliteConnection(m_connectionString);
125  m_conn.Open();
126 
127  SqliteCommand primSelectCmd = new SqliteCommand(primSelect, m_conn);
128  primDa = new SqliteDataAdapter(primSelectCmd);
129 
130  SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, m_conn);
131  shapeDa = new SqliteDataAdapter(shapeSelectCmd);
132  // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa);
133 
134  SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, m_conn);
135  itemsDa = new SqliteDataAdapter(itemsSelectCmd);
136 
137  SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, m_conn);
138  terrainDa = new SqliteDataAdapter(terrainSelectCmd);
139 
140  SqliteCommand landSelectCmd = new SqliteCommand(landSelect, m_conn);
141  landDa = new SqliteDataAdapter(landSelectCmd);
142 
143  SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn);
144  landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd);
145 
146  SqliteCommand regionSettingsSelectCmd = new SqliteCommand(regionSettingsSelect, m_conn);
147  regionSettingsDa = new SqliteDataAdapter(regionSettingsSelectCmd);
148 
149  SqliteCommand regionWindlightSelectCmd = new SqliteCommand(regionWindlightSelect, m_conn);
150  regionWindlightDa = new SqliteDataAdapter(regionWindlightSelectCmd);
151 
152  SqliteCommand regionEnvironmentSelectCmd = new SqliteCommand(regionEnvironmentSelect, m_conn);
153  regionEnvironmentDa = new SqliteDataAdapter(regionEnvironmentSelectCmd);
154 
155  SqliteCommand regionSpawnPointsSelectCmd = new SqliteCommand(regionSpawnPointsSelect, m_conn);
156  regionSpawnPointsDa = new SqliteDataAdapter(regionSpawnPointsSelectCmd);
157 
158  // This actually does the roll forward assembly stuff
159  Migration m = new Migration(m_conn, Assembly, "RegionStore");
160  m.Update();
161 
162  lock (ds)
163  {
164  ds.Tables.Add(createPrimTable());
165  setupPrimCommands(primDa, m_conn);
166 
167  ds.Tables.Add(createShapeTable());
168  setupShapeCommands(shapeDa, m_conn);
169 
170  ds.Tables.Add(createItemsTable());
171  setupItemsCommands(itemsDa, m_conn);
172 
173  ds.Tables.Add(createTerrainTable());
174  setupTerrainCommands(terrainDa, m_conn);
175 
176  ds.Tables.Add(createLandTable());
177  setupLandCommands(landDa, m_conn);
178 
179  ds.Tables.Add(createLandAccessListTable());
180  setupLandAccessCommands(landAccessListDa, m_conn);
181 
182  ds.Tables.Add(createRegionSettingsTable());
183  setupRegionSettingsCommands(regionSettingsDa, m_conn);
184 
185  ds.Tables.Add(createRegionWindlightTable());
186  setupRegionWindlightCommands(regionWindlightDa, m_conn);
187 
188  ds.Tables.Add(createRegionEnvironmentTable());
189  setupRegionEnvironmentCommands(regionEnvironmentDa, m_conn);
190 
191  ds.Tables.Add(createRegionSpawnPointsTable());
192  setupRegionSpawnPointsCommands(regionSpawnPointsDa, m_conn);
193 
194  // WORKAROUND: This is a work around for sqlite on
195  // windows, which gets really unhappy with blob columns
196  // that have no sample data in them. At some point we
197  // need to actually find a proper way to handle this.
198  try
199  {
200  primDa.Fill(ds.Tables["prims"]);
201  }
202  catch (Exception e)
203  {
204  m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on prims table :{0}", e.Message);
205  }
206 
207  try
208  {
209  shapeDa.Fill(ds.Tables["primshapes"]);
210  }
211  catch (Exception e)
212  {
213  m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on primshapes table :{0}", e.Message);
214  }
215 
216  try
217  {
218  itemsDa.Fill(ds.Tables["primitems"]);
219  }
220  catch (Exception e)
221  {
222  m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on primitems table :{0}", e.Message);
223  }
224 
225  try
226  {
227  terrainDa.Fill(ds.Tables["terrain"]);
228  }
229  catch (Exception e)
230  {
231  m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on terrain table :{0}", e.Message);
232  }
233 
234  try
235  {
236  landDa.Fill(ds.Tables["land"]);
237  }
238  catch (Exception e)
239  {
240  m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on land table :{0}", e.Message);
241  }
242 
243  try
244  {
245  landAccessListDa.Fill(ds.Tables["landaccesslist"]);
246  }
247  catch (Exception e)
248  {
249  m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on landaccesslist table :{0}", e.Message);
250  }
251 
252  try
253  {
254  regionSettingsDa.Fill(ds.Tables["regionsettings"]);
255  }
256  catch (Exception e)
257  {
258  m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on regionsettings table :{0}", e.Message);
259  }
260 
261  try
262  {
263  regionWindlightDa.Fill(ds.Tables["regionwindlight"]);
264  }
265  catch (Exception e)
266  {
267  m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on regionwindlight table :{0}", e.Message);
268  }
269 
270  try
271  {
272  regionEnvironmentDa.Fill(ds.Tables["regionenvironment"]);
273  }
274  catch (Exception e)
275  {
276  m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on regionenvironment table :{0}", e.Message);
277  }
278 
279  try
280  {
281  regionSpawnPointsDa.Fill(ds.Tables["spawn_points"]);
282  }
283  catch (Exception e)
284  {
285  m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on spawn_points table :{0}", e.Message);
286  }
287 
288  // We have to create a data set mapping for every table, otherwise the IDataAdaptor.Update() will not populate rows with values!
289  // Not sure exactly why this is - this kind of thing was not necessary before - justincc 20100409
290  // Possibly because we manually set up our own DataTables before connecting to the database
291  CreateDataSetMapping(primDa, "prims");
292  CreateDataSetMapping(shapeDa, "primshapes");
293  CreateDataSetMapping(itemsDa, "primitems");
294  CreateDataSetMapping(terrainDa, "terrain");
295  CreateDataSetMapping(landDa, "land");
296  CreateDataSetMapping(landAccessListDa, "landaccesslist");
297  CreateDataSetMapping(regionSettingsDa, "regionsettings");
298  CreateDataSetMapping(regionWindlightDa, "regionwindlight");
299  CreateDataSetMapping(regionEnvironmentDa, "regionenvironment");
300  CreateDataSetMapping(regionSpawnPointsDa, "spawn_points");
301  }
302  }
303  catch (Exception e)
304  {
305  m_log.ErrorFormat("[SQLITE REGION DB]: {0} - {1}", e.Message, e.StackTrace);
306  Environment.Exit(23);
307  }
308  return;
309  }
310 
311  public void Dispose()
312  {
313  if (m_conn != null)
314  {
315  m_conn.Close();
316  m_conn = null;
317  }
318  if (ds != null)
319  {
320  ds.Dispose();
321  ds = null;
322  }
323  if (primDa != null)
324  {
325  primDa.Dispose();
326  primDa = null;
327  }
328  if (shapeDa != null)
329  {
330  shapeDa.Dispose();
331  shapeDa = null;
332  }
333  if (itemsDa != null)
334  {
335  itemsDa.Dispose();
336  itemsDa = null;
337  }
338  if (terrainDa != null)
339  {
340  terrainDa.Dispose();
341  terrainDa = null;
342  }
343  if (landDa != null)
344  {
345  landDa.Dispose();
346  landDa = null;
347  }
348  if (landAccessListDa != null)
349  {
350  landAccessListDa.Dispose();
351  landAccessListDa = null;
352  }
353  if (regionSettingsDa != null)
354  {
355  regionSettingsDa.Dispose();
356  regionSettingsDa = null;
357  }
358  if (regionWindlightDa != null)
359  {
360  regionWindlightDa.Dispose();
361  regionWindlightDa = null;
362  }
363  if (regionEnvironmentDa != null)
364  {
365  regionEnvironmentDa.Dispose();
366  regionEnvironmentDa = null;
367  }
368  if (regionSpawnPointsDa != null)
369  {
370  regionSpawnPointsDa.Dispose();
371  regionWindlightDa = null;
372  }
373  }
374 
376  {
377  lock (ds)
378  {
379  DataTable regionsettings = ds.Tables["regionsettings"];
380 
381  DataRow settingsRow = regionsettings.Rows.Find(rs.RegionUUID.ToString());
382  if (settingsRow == null)
383  {
384  settingsRow = regionsettings.NewRow();
385  fillRegionSettingsRow(settingsRow, rs);
386  regionsettings.Rows.Add(settingsRow);
387  }
388  else
389  {
390  fillRegionSettingsRow(settingsRow, rs);
391  }
392 
393  StoreSpawnPoints(rs);
394 
395  Commit();
396  }
397 
398  }
399 
401  {
402  lock (ds)
403  {
404  // DataTable spawnpoints = ds.Tables["spawn_points"];
405 
406  // remove region's spawnpoints
407  using (
408  SqliteCommand cmd =
409  new SqliteCommand("delete from spawn_points where RegionID=:RegionID",
410  m_conn))
411  {
412 
413  cmd.Parameters.Add(new SqliteParameter(":RegionID", rs.RegionUUID.ToString()));
414  cmd.ExecuteNonQuery();
415  }
416  }
417 
418  foreach (SpawnPoint sp in rs.SpawnPoints())
419  {
420  using (SqliteCommand cmd = new SqliteCommand("insert into spawn_points(RegionID, Yaw, Pitch, Distance)" +
421  "values ( :RegionID, :Yaw, :Pitch, :Distance)", m_conn))
422  {
423  cmd.Parameters.Add(new SqliteParameter(":RegionID", rs.RegionUUID.ToString()));
424  cmd.Parameters.Add(new SqliteParameter(":Yaw", sp.Yaw));
425  cmd.Parameters.Add(new SqliteParameter(":Pitch", sp.Pitch));
426  cmd.Parameters.Add(new SqliteParameter(":Distance", sp.Distance));
427  cmd.ExecuteNonQuery();
428  }
429  }
430  }
431 
437  {
438  RegionLightShareData wl = null;
439 
440  lock (ds)
441  {
442  DataTable windlightTable = ds.Tables["regionwindlight"];
443  DataRow windlightRow = windlightTable.Rows.Find(regionUUID.ToString());
444  if (windlightRow == null)
445  {
446  wl = new RegionLightShareData();
447  wl.regionID = regionUUID;
448  StoreRegionWindlightSettings(wl);
449  return wl;
450  }
451  wl = buildRegionWindlight(windlightRow);
452  return wl;
453  }
454  }
455 
460  public void RemoveRegionWindlightSettings(UUID regionID)
461  {
462  lock (ds)
463  {
464  DataTable windlightTable = ds.Tables["regionwindlight"];
465  DataRow windlightRow = windlightTable.Rows.Find(regionID.ToString());
466 
467  if (windlightRow != null)
468  {
469  windlightRow.Delete();
470  }
471  }
472  Commit();
473  }
474 
480  {
481  lock (ds)
482  {
483  DataTable windlightTable = ds.Tables["regionwindlight"];
484  DataRow windlightRow = windlightTable.Rows.Find(wl.regionID.ToString());
485 
486  if (windlightRow == null)
487  {
488  windlightRow = windlightTable.NewRow();
489  fillRegionWindlightRow(windlightRow, wl);
490  windlightTable.Rows.Add(windlightRow);
491  }
492  else
493  {
494  fillRegionWindlightRow(windlightRow, wl);
495  }
496 
497  Commit();
498  }
499  }
500 
501  #region Region Environment Settings
502  public string LoadRegionEnvironmentSettings(UUID regionUUID)
503  {
504  lock (ds)
505  {
506  DataTable environmentTable = ds.Tables["regionenvironment"];
507  DataRow row = environmentTable.Rows.Find(regionUUID.ToString());
508  if (row == null)
509  {
510  return String.Empty;
511  }
512 
513  return (String)row["llsd_settings"];
514  }
515  }
516 
517  public void StoreRegionEnvironmentSettings(UUID regionUUID, string settings)
518  {
519  lock (ds)
520  {
521  DataTable environmentTable = ds.Tables["regionenvironment"];
522  DataRow row = environmentTable.Rows.Find(regionUUID.ToString());
523 
524  if (row == null)
525  {
526  row = environmentTable.NewRow();
527  row["region_id"] = regionUUID.ToString();
528  row["llsd_settings"] = settings;
529  environmentTable.Rows.Add(row);
530  }
531  else
532  {
533  row["llsd_settings"] = settings;
534  }
535 
536  regionEnvironmentDa.Update(ds, "regionenvironment");
537  }
538  }
539 
540  public void RemoveRegionEnvironmentSettings(UUID regionUUID)
541  {
542  lock (ds)
543  {
544  DataTable environmentTable = ds.Tables["regionenvironment"];
545  DataRow row = environmentTable.Rows.Find(regionUUID.ToString());
546 
547  if (row != null)
548  {
549  row.Delete();
550  }
551 
552  regionEnvironmentDa.Update(ds, "regionenvironment");
553  }
554  }
555 
556  #endregion
557 
558  public RegionSettings LoadRegionSettings(UUID regionUUID)
559  {
560  lock (ds)
561  {
562  DataTable regionsettings = ds.Tables["regionsettings"];
563 
564  string searchExp = "regionUUID = '" + regionUUID.ToString() + "'";
565  DataRow[] rawsettings = regionsettings.Select(searchExp);
566  if (rawsettings.Length == 0)
567  {
568  RegionSettings rs = new RegionSettings();
569  rs.RegionUUID = regionUUID;
570  rs.OnSave += StoreRegionSettings;
571 
572  StoreRegionSettings(rs);
573 
574  return rs;
575  }
576  DataRow row = rawsettings[0];
577 
578  RegionSettings newSettings = buildRegionSettings(row);
579  newSettings.OnSave += StoreRegionSettings;
580 
581  LoadSpawnPoints(newSettings);
582 
583  return newSettings;
584  }
585  }
586 
587  private void LoadSpawnPoints(RegionSettings rs)
588  {
589  rs.ClearSpawnPoints();
590 
591  DataTable spawnpoints = ds.Tables["spawn_points"];
592  string byRegion = "RegionID = '" + rs.RegionUUID + "'";
593  DataRow[] spForRegion = spawnpoints.Select(byRegion);
594 
595  foreach (DataRow spRow in spForRegion)
596  {
597  SpawnPoint sp = new SpawnPoint();
598  sp.Pitch = (float)spRow["Pitch"];
599  sp.Yaw = (float)spRow["Yaw"];
600  sp.Distance = (float)spRow["Distance"];
601 
602  rs.AddSpawnPoint(sp);
603  }
604  }
605 
611  public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
612  {
613  uint flags = obj.RootPart.GetEffectiveObjectFlags();
614 
615  // Eligibility check
616  //
617  if ((flags & (uint)PrimFlags.Temporary) != 0)
618  return;
619  if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
620  return;
621 
622  lock (ds)
623  {
624  foreach (SceneObjectPart prim in obj.Parts)
625  {
626 // m_log.Info("[REGION DB]: Adding obj: " + obj.UUID + " to region: " + regionUUID);
627  addPrim(prim, obj.UUID, regionUUID);
628  }
629  }
630 
631  Commit();
632 // m_log.Info("[Dump of prims]: " + ds.GetXml());
633  }
634 
640  public void RemoveObject(UUID obj, UUID regionUUID)
641  {
642 // m_log.InfoFormat("[REGION DB]: Removing obj: {0} from region: {1}", obj.Guid, regionUUID);
643 
644  DataTable prims = ds.Tables["prims"];
645  DataTable shapes = ds.Tables["primshapes"];
646 
647  string selectExp = "SceneGroupID = '" + obj + "' and RegionUUID = '" + regionUUID + "'";
648  lock (ds)
649  {
650  DataRow[] primRows = prims.Select(selectExp);
651  foreach (DataRow row in primRows)
652  {
653  // Remove shape rows
654  UUID uuid = new UUID((string)row["UUID"]);
655  DataRow shapeRow = shapes.Rows.Find(uuid.ToString());
656  if (shapeRow != null)
657  {
658  shapeRow.Delete();
659  }
660 
661  RemoveItems(uuid);
662 
663  // Remove prim row
664  row.Delete();
665  }
666  }
667 
668  Commit();
669  }
670 
676  private void RemoveItems(UUID uuid)
677  {
678  DataTable items = ds.Tables["primitems"];
679 
680  String sql = String.Format("primID = '{0}'", uuid);
681  DataRow[] itemRows = items.Select(sql);
682 
683  foreach (DataRow itemRow in itemRows)
684  {
685  itemRow.Delete();
686  }
687  }
688 
694  public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
695  {
696  Dictionary<UUID, SceneObjectGroup> createdObjects = new Dictionary<UUID, SceneObjectGroup>();
697 
698  List<SceneObjectGroup> retvals = new List<SceneObjectGroup>();
699 
700  DataTable prims = ds.Tables["prims"];
701  DataTable shapes = ds.Tables["primshapes"];
702 
703  string byRegion = "RegionUUID = '" + regionUUID + "'";
704 
705  lock (ds)
706  {
707  DataRow[] primsForRegion = prims.Select(byRegion);
708 // m_log.Info("[SQLITE REGION DB]: Loaded " + primsForRegion.Length + " prims for region: " + regionUUID);
709 
710  // First, create all groups
711  foreach (DataRow primRow in primsForRegion)
712  {
713  try
714  {
715  SceneObjectPart prim = null;
716 
717  string uuid = (string)primRow["UUID"];
718  string objID = (string)primRow["SceneGroupID"];
719 
720  if (uuid == objID) //is new SceneObjectGroup ?
721  {
722  prim = buildPrim(primRow);
723  DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
724  if (shapeRow != null)
725  {
726  prim.Shape = buildShape(shapeRow);
727  }
728  else
729  {
730  m_log.Warn(
731  "[SQLITE REGION DB]: No shape found for prim in storage, so setting default box shape");
732  prim.Shape = PrimitiveBaseShape.Default;
733  }
734 
735  SceneObjectGroup group = new SceneObjectGroup(prim);
736 
737  createdObjects.Add(group.UUID, group);
738  retvals.Add(group);
739  LoadItems(prim);
740 
741 
742  }
743  }
744  catch (Exception e)
745  {
746  m_log.Error("[SQLITE REGION DB]: Failed create prim object in new group, exception and data follows");
747  m_log.Error("[SQLITE REGION DB]: ", e);
748  foreach (DataColumn col in prims.Columns)
749  {
750  m_log.Error("[SQLITE REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]);
751  }
752  }
753  }
754 
755  // Now fill the groups with part data
756  foreach (DataRow primRow in primsForRegion)
757  {
758  try
759  {
760  SceneObjectPart prim = null;
761 
762  string uuid = (string)primRow["UUID"];
763  string objID = (string)primRow["SceneGroupID"];
764  if (uuid != objID) //is new SceneObjectGroup ?
765  {
766  prim = buildPrim(primRow);
767  DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
768  if (shapeRow != null)
769  {
770  prim.Shape = buildShape(shapeRow);
771  }
772  else
773  {
774  m_log.Warn(
775  "[SQLITE REGION DB]: No shape found for prim in storage, so setting default box shape");
776  prim.Shape = PrimitiveBaseShape.Default;
777  }
778 
779  createdObjects[new UUID(objID)].AddPart(prim);
780  LoadItems(prim);
781  }
782  }
783  catch (Exception e)
784  {
785  m_log.Error("[SQLITE REGION DB]: Failed create prim object in group, exception and data follows");
786  m_log.Error("[SQLITE REGION DB]: ", e);
787  foreach (DataColumn col in prims.Columns)
788  {
789  m_log.Error("[SQLITE REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]);
790  }
791  }
792  }
793  }
794  return retvals;
795  }
796 
801  private void LoadItems(SceneObjectPart prim)
802  {
803 // m_log.DebugFormat("[SQLITE REGION DB]: Loading inventory for {0} {1}", prim.Name, prim.UUID);
804 
805  DataTable dbItems = ds.Tables["primitems"];
806  String sql = String.Format("primID = '{0}'", prim.UUID.ToString());
807  DataRow[] dbItemRows = dbItems.Select(sql);
808  IList<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
809 
810 // m_log.DebugFormat("[SQLITE REGION DB]: Found {0} items for {1} {2}", dbItemRows.Length, prim.Name, prim.UUID);
811 
812  foreach (DataRow row in dbItemRows)
813  {
814  TaskInventoryItem item = buildItem(row);
815  inventory.Add(item);
816 
817 // m_log.DebugFormat("[SQLITE REGION DB]: Restored item {0} {1}", item.Name, item.ItemID);
818  }
819 
820  prim.Inventory.RestoreInventoryItems(inventory);
821  }
822 
823  // Legacy entry point for when terrain was always a 256x256 hieghtmap
824  public void StoreTerrain(double[,] ter, UUID regionID)
825  {
826  StoreTerrain(new HeightmapTerrainData(ter), regionID);
827  }
828 
834  public void StoreTerrain(TerrainData terrData, UUID regionID)
835  {
836  lock (ds)
837  {
838  using (
839  SqliteCommand cmd = new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID", m_conn))
840  {
841  cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
842  cmd.ExecuteNonQuery();
843  }
844 
845  // the following is an work around for .NET. The perf
846  // issues associated with it aren't as bad as you think.
847  String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" +
848  " values(:RegionUUID, :Revision, :Heightfield)";
849 
850  int terrainDBRevision;
851  Array terrainDBblob;
852  terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
853 
854  m_log.DebugFormat("{0} Storing terrain revision r {1}", LogHeader, terrainDBRevision);
855 
856  using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
857  {
858  cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
859  cmd.Parameters.Add(new SqliteParameter(":Revision", terrainDBRevision));
860  cmd.Parameters.Add(new SqliteParameter(":Heightfield", terrainDBblob));
861  cmd.ExecuteNonQuery();
862  }
863  }
864  }
865 
871  public double[,] LoadTerrain(UUID regionID)
872  {
873  double[,] ret = null;
874  TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
875  if (terrData != null)
876  ret = terrData.GetDoubles();
877  return ret;
878  }
879 
880  // Returns 'null' if region not found
881  public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
882  {
883  TerrainData terrData = null;
884 
885  lock (ds)
886  {
887  String sql = "select RegionUUID, Revision, Heightfield from terrain" +
888  " where RegionUUID=:RegionUUID order by Revision desc";
889 
890  using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
891  {
892  cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
893 
894  using (IDataReader row = cmd.ExecuteReader())
895  {
896  int rev = 0;
897  if (row.Read())
898  {
899  rev = Convert.ToInt32(row["Revision"]);
900  byte[] blob = (byte[])row["Heightfield"];
901  terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
902  }
903  else
904  {
905  m_log.Warn("[SQLITE REGION DB]: No terrain found for region");
906  return null;
907  }
908 
909  m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString());
910  }
911  }
912  }
913  return terrData;
914  }
915 
916  public void RemoveLandObject(UUID globalID)
917  {
918  lock (ds)
919  {
920  // Can't use blanket SQL statements when using SqlAdapters unless you re-read the data into the adapter
921  // after you're done.
922  // replaced below code with the SqliteAdapter version.
923  //using (SqliteCommand cmd = new SqliteCommand("delete from land where UUID=:UUID", m_conn))
924  //{
925  // cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString()));
926  // cmd.ExecuteNonQuery();
927  //}
928 
929  //using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:UUID", m_conn))
930  //{
931  // cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString()));
932  // cmd.ExecuteNonQuery();
933  //}
934 
935  DataTable land = ds.Tables["land"];
936  DataTable landaccesslist = ds.Tables["landaccesslist"];
937  DataRow landRow = land.Rows.Find(globalID.ToString());
938  if (landRow != null)
939  {
940  landRow.Delete();
941  }
942  List<DataRow> rowsToDelete = new List<DataRow>();
943  foreach (DataRow rowToCheck in landaccesslist.Rows)
944  {
945  if (rowToCheck["LandUUID"].ToString() == globalID.ToString())
946  rowsToDelete.Add(rowToCheck);
947  }
948  for (int iter = 0; iter < rowsToDelete.Count; iter++)
949  {
950  rowsToDelete[iter].Delete();
951  }
952  }
953  Commit();
954  }
955 
960  public void StoreLandObject(ILandObject parcel)
961  {
962  lock (ds)
963  {
964  DataTable land = ds.Tables["land"];
965  DataTable landaccesslist = ds.Tables["landaccesslist"];
966 
967  DataRow landRow = land.Rows.Find(parcel.LandData.GlobalID.ToString());
968  if (landRow == null)
969  {
970  landRow = land.NewRow();
971  fillLandRow(landRow, parcel.LandData, parcel.RegionUUID);
972  land.Rows.Add(landRow);
973  }
974  else
975  {
976  fillLandRow(landRow, parcel.LandData, parcel.RegionUUID);
977  }
978 
979  // I know this caused someone issues before, but OpenSim is unusable if we leave this stuff around
980  //using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:LandUUID", m_conn))
981  //{
982  // cmd.Parameters.Add(new SqliteParameter(":LandUUID", parcel.LandData.GlobalID.ToString()));
983  // cmd.ExecuteNonQuery();
984 
985  // }
986 
987  // This is the slower.. but more appropriate thing to do
988 
989  // We can't modify the table with direct queries before calling Commit() and re-filling them.
990  List<DataRow> rowsToDelete = new List<DataRow>();
991  foreach (DataRow rowToCheck in landaccesslist.Rows)
992  {
993  if (rowToCheck["LandUUID"].ToString() == parcel.LandData.GlobalID.ToString())
994  rowsToDelete.Add(rowToCheck);
995  }
996  for (int iter = 0; iter < rowsToDelete.Count; iter++)
997  {
998  rowsToDelete[iter].Delete();
999  landaccesslist.Rows.Remove(rowsToDelete[iter]);
1000  }
1001  rowsToDelete.Clear();
1002  foreach (LandAccessEntry entry in parcel.LandData.ParcelAccessList)
1003  {
1004  DataRow newAccessRow = landaccesslist.NewRow();
1005  fillLandAccessRow(newAccessRow, entry, parcel.LandData.GlobalID);
1006  landaccesslist.Rows.Add(newAccessRow);
1007  }
1008  }
1009 
1010  Commit();
1011  }
1012 
1018  public List<LandData> LoadLandObjects(UUID regionUUID)
1019  {
1020  List<LandData> landDataForRegion = new List<LandData>();
1021  lock (ds)
1022  {
1023  DataTable land = ds.Tables["land"];
1024  DataTable landaccesslist = ds.Tables["landaccesslist"];
1025  string searchExp = "RegionUUID = '" + regionUUID + "'";
1026  DataRow[] rawDataForRegion = land.Select(searchExp);
1027  foreach (DataRow rawDataLand in rawDataForRegion)
1028  {
1029  LandData newLand = buildLandData(rawDataLand);
1030  string accessListSearchExp = "LandUUID = '" + newLand.GlobalID + "'";
1031  DataRow[] rawDataForLandAccessList = landaccesslist.Select(accessListSearchExp);
1032  foreach (DataRow rawDataLandAccess in rawDataForLandAccessList)
1033  {
1034  newLand.ParcelAccessList.Add(buildLandAccessData(rawDataLandAccess));
1035  }
1036 
1037  landDataForRegion.Add(newLand);
1038  }
1039  }
1040  return landDataForRegion;
1041  }
1042 
1046  public void Commit()
1047  {
1048 // m_log.Debug("[SQLITE]: Starting commit");
1049  lock (ds)
1050  {
1051  primDa.Update(ds, "prims");
1052  shapeDa.Update(ds, "primshapes");
1053 
1054  itemsDa.Update(ds, "primitems");
1055 
1056  terrainDa.Update(ds, "terrain");
1057  landDa.Update(ds, "land");
1058  landAccessListDa.Update(ds, "landaccesslist");
1059  try
1060  {
1061  regionSettingsDa.Update(ds, "regionsettings");
1062  regionWindlightDa.Update(ds, "regionwindlight");
1063  }
1064  catch (SqliteException SqlEx)
1065  {
1066  throw new Exception(
1067  "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!",
1068  SqlEx);
1069  }
1070  ds.AcceptChanges();
1071  }
1072  }
1073 
1077  public void Shutdown()
1078  {
1079  Commit();
1080  }
1081 
1082  /***********************************************************************
1083  *
1084  * Database Definition Functions
1085  *
1086  * This should be db agnostic as we define them in ADO.NET terms
1087  *
1088  **********************************************************************/
1089 
1090  protected void CreateDataSetMapping(IDataAdapter da, string tableName)
1091  {
1092  ITableMapping dbMapping = da.TableMappings.Add(tableName, tableName);
1093  foreach (DataColumn col in ds.Tables[tableName].Columns)
1094  {
1095  dbMapping.ColumnMappings.Add(col.ColumnName, col.ColumnName);
1096  }
1097  }
1098 
1105  private static void createCol(DataTable dt, string name, Type type)
1106  {
1107  DataColumn col = new DataColumn(name, type);
1108  dt.Columns.Add(col);
1109  }
1110 
1115  private static DataTable createTerrainTable()
1116  {
1117  DataTable terrain = new DataTable("terrain");
1118 
1119  createCol(terrain, "RegionUUID", typeof(String));
1120  createCol(terrain, "Revision", typeof(Int32));
1121  createCol(terrain, "Heightfield", typeof(Byte[]));
1122 
1123  return terrain;
1124  }
1125 
1130  private static DataTable createPrimTable()
1131  {
1132  DataTable prims = new DataTable("prims");
1133 
1134  createCol(prims, "UUID", typeof(String));
1135  createCol(prims, "RegionUUID", typeof(String));
1136  createCol(prims, "CreationDate", typeof(Int32));
1137  createCol(prims, "Name", typeof(String));
1138  createCol(prims, "SceneGroupID", typeof(String));
1139  // various text fields
1140  createCol(prims, "Text", typeof(String));
1141  createCol(prims, "ColorR", typeof(Int32));
1142  createCol(prims, "ColorG", typeof(Int32));
1143  createCol(prims, "ColorB", typeof(Int32));
1144  createCol(prims, "ColorA", typeof(Int32));
1145  createCol(prims, "Description", typeof(String));
1146  createCol(prims, "SitName", typeof(String));
1147  createCol(prims, "TouchName", typeof(String));
1148  // permissions
1149  createCol(prims, "ObjectFlags", typeof(Int32));
1150  createCol(prims, "CreatorID", typeof(String));
1151  createCol(prims, "OwnerID", typeof(String));
1152  createCol(prims, "GroupID", typeof(String));
1153  createCol(prims, "LastOwnerID", typeof(String));
1154  createCol(prims, "OwnerMask", typeof(Int32));
1155  createCol(prims, "NextOwnerMask", typeof(Int32));
1156  createCol(prims, "GroupMask", typeof(Int32));
1157  createCol(prims, "EveryoneMask", typeof(Int32));
1158  createCol(prims, "BaseMask", typeof(Int32));
1159  // vectors
1160  createCol(prims, "PositionX", typeof(Double));
1161  createCol(prims, "PositionY", typeof(Double));
1162  createCol(prims, "PositionZ", typeof(Double));
1163  createCol(prims, "GroupPositionX", typeof(Double));
1164  createCol(prims, "GroupPositionY", typeof(Double));
1165  createCol(prims, "GroupPositionZ", typeof(Double));
1166  createCol(prims, "VelocityX", typeof(Double));
1167  createCol(prims, "VelocityY", typeof(Double));
1168  createCol(prims, "VelocityZ", typeof(Double));
1169  createCol(prims, "AngularVelocityX", typeof(Double));
1170  createCol(prims, "AngularVelocityY", typeof(Double));
1171  createCol(prims, "AngularVelocityZ", typeof(Double));
1172  createCol(prims, "AccelerationX", typeof(Double));
1173  createCol(prims, "AccelerationY", typeof(Double));
1174  createCol(prims, "AccelerationZ", typeof(Double));
1175  // quaternions
1176  createCol(prims, "RotationX", typeof(Double));
1177  createCol(prims, "RotationY", typeof(Double));
1178  createCol(prims, "RotationZ", typeof(Double));
1179  createCol(prims, "RotationW", typeof(Double));
1180 
1181  // sit target
1182  createCol(prims, "SitTargetOffsetX", typeof(Double));
1183  createCol(prims, "SitTargetOffsetY", typeof(Double));
1184  createCol(prims, "SitTargetOffsetZ", typeof(Double));
1185 
1186  createCol(prims, "SitTargetOrientW", typeof(Double));
1187  createCol(prims, "SitTargetOrientX", typeof(Double));
1188  createCol(prims, "SitTargetOrientY", typeof(Double));
1189  createCol(prims, "SitTargetOrientZ", typeof(Double));
1190 
1191  createCol(prims, "PayPrice", typeof(Int32));
1192  createCol(prims, "PayButton1", typeof(Int32));
1193  createCol(prims, "PayButton2", typeof(Int32));
1194  createCol(prims, "PayButton3", typeof(Int32));
1195  createCol(prims, "PayButton4", typeof(Int32));
1196 
1197  createCol(prims, "LoopedSound", typeof(String));
1198  createCol(prims, "LoopedSoundGain", typeof(Double));
1199  createCol(prims, "TextureAnimation", typeof(String));
1200  createCol(prims, "ParticleSystem", typeof(String));
1201 
1202  createCol(prims, "OmegaX", typeof(Double));
1203  createCol(prims, "OmegaY", typeof(Double));
1204  createCol(prims, "OmegaZ", typeof(Double));
1205 
1206  createCol(prims, "CameraEyeOffsetX", typeof(Double));
1207  createCol(prims, "CameraEyeOffsetY", typeof(Double));
1208  createCol(prims, "CameraEyeOffsetZ", typeof(Double));
1209 
1210  createCol(prims, "CameraAtOffsetX", typeof(Double));
1211  createCol(prims, "CameraAtOffsetY", typeof(Double));
1212  createCol(prims, "CameraAtOffsetZ", typeof(Double));
1213 
1214  createCol(prims, "ForceMouselook", typeof(Int16));
1215 
1216  createCol(prims, "ScriptAccessPin", typeof(Int32));
1217 
1218  createCol(prims, "AllowedDrop", typeof(Int16));
1219  createCol(prims, "DieAtEdge", typeof(Int16));
1220 
1221  createCol(prims, "SalePrice", typeof(Int32));
1222  createCol(prims, "SaleType", typeof(Int16));
1223 
1224  // click action
1225  createCol(prims, "ClickAction", typeof(Byte));
1226 
1227  createCol(prims, "Material", typeof(Byte));
1228 
1229  createCol(prims, "CollisionSound", typeof(String));
1230  createCol(prims, "CollisionSoundVolume", typeof(Double));
1231 
1232  createCol(prims, "VolumeDetect", typeof(Int16));
1233 
1234  createCol(prims, "MediaURL", typeof(String));
1235 
1236  createCol(prims, "AttachedPosX", typeof(Double));
1237  createCol(prims, "AttachedPosY", typeof(Double));
1238  createCol(prims, "AttachedPosZ", typeof(Double));
1239 
1240  createCol(prims, "DynAttrs", typeof(String));
1241 
1242  createCol(prims, "PhysicsShapeType", typeof(Byte));
1243  createCol(prims, "Density", typeof(Double));
1244  createCol(prims, "GravityModifier", typeof(Double));
1245  createCol(prims, "Friction", typeof(Double));
1246  createCol(prims, "Restitution", typeof(Double));
1247 
1248  createCol(prims, "KeyframeMotion", typeof(Byte[]));
1249 
1250  // Add in contraints
1251  prims.PrimaryKey = new DataColumn[] { prims.Columns["UUID"] };
1252 
1253  return prims;
1254  }
1255 
1260  private static DataTable createShapeTable()
1261  {
1262  DataTable shapes = new DataTable("primshapes");
1263  createCol(shapes, "UUID", typeof(String));
1264  // shape is an enum
1265  createCol(shapes, "Shape", typeof(Int32));
1266  // vectors
1267  createCol(shapes, "ScaleX", typeof(Double));
1268  createCol(shapes, "ScaleY", typeof(Double));
1269  createCol(shapes, "ScaleZ", typeof(Double));
1270  // paths
1271  createCol(shapes, "PCode", typeof(Int32));
1272  createCol(shapes, "PathBegin", typeof(Int32));
1273  createCol(shapes, "PathEnd", typeof(Int32));
1274  createCol(shapes, "PathScaleX", typeof(Int32));
1275  createCol(shapes, "PathScaleY", typeof(Int32));
1276  createCol(shapes, "PathShearX", typeof(Int32));
1277  createCol(shapes, "PathShearY", typeof(Int32));
1278  createCol(shapes, "PathSkew", typeof(Int32));
1279  createCol(shapes, "PathCurve", typeof(Int32));
1280  createCol(shapes, "PathRadiusOffset", typeof(Int32));
1281  createCol(shapes, "PathRevolutions", typeof(Int32));
1282  createCol(shapes, "PathTaperX", typeof(Int32));
1283  createCol(shapes, "PathTaperY", typeof(Int32));
1284  createCol(shapes, "PathTwist", typeof(Int32));
1285  createCol(shapes, "PathTwistBegin", typeof(Int32));
1286  // profile
1287  createCol(shapes, "ProfileBegin", typeof(Int32));
1288  createCol(shapes, "ProfileEnd", typeof(Int32));
1289  createCol(shapes, "ProfileCurve", typeof(Int32));
1290  createCol(shapes, "ProfileHollow", typeof(Int32));
1291  createCol(shapes, "State", typeof(Int32));
1292  // text TODO: this isn't right, but I'm not sure the right
1293  // way to specify this as a blob atm
1294  createCol(shapes, "Texture", typeof(Byte[]));
1295  createCol(shapes, "ExtraParams", typeof(Byte[]));
1296  createCol(shapes, "Media", typeof(String));
1297 
1298  shapes.PrimaryKey = new DataColumn[] { shapes.Columns["UUID"] };
1299 
1300  return shapes;
1301  }
1302 
1307  private static DataTable createItemsTable()
1308  {
1309  DataTable items = new DataTable("primitems");
1310 
1311  createCol(items, "itemID", typeof(String));
1312  createCol(items, "primID", typeof(String));
1313  createCol(items, "assetID", typeof(String));
1314  createCol(items, "parentFolderID", typeof(String));
1315 
1316  createCol(items, "invType", typeof(Int32));
1317  createCol(items, "assetType", typeof(Int32));
1318 
1319  createCol(items, "name", typeof(String));
1320  createCol(items, "description", typeof(String));
1321 
1322  createCol(items, "creationDate", typeof(Int64));
1323  createCol(items, "creatorID", typeof(String));
1324  createCol(items, "ownerID", typeof(String));
1325  createCol(items, "lastOwnerID", typeof(String));
1326  createCol(items, "groupID", typeof(String));
1327 
1328  createCol(items, "nextPermissions", typeof(UInt32));
1329  createCol(items, "currentPermissions", typeof(UInt32));
1330  createCol(items, "basePermissions", typeof(UInt32));
1331  createCol(items, "everyonePermissions", typeof(UInt32));
1332  createCol(items, "groupPermissions", typeof(UInt32));
1333  createCol(items, "flags", typeof(UInt32));
1334 
1335  items.PrimaryKey = new DataColumn[] { items.Columns["itemID"] };
1336 
1337  return items;
1338  }
1339 
1344  private static DataTable createLandTable()
1345  {
1346  DataTable land = new DataTable("land");
1347  createCol(land, "UUID", typeof(String));
1348  createCol(land, "RegionUUID", typeof(String));
1349  createCol(land, "LocalLandID", typeof(UInt32));
1350 
1351  // Bitmap is a byte[512]
1352  createCol(land, "Bitmap", typeof(Byte[]));
1353 
1354  createCol(land, "Name", typeof(String));
1355  createCol(land, "Desc", typeof(String));
1356  createCol(land, "OwnerUUID", typeof(String));
1357  createCol(land, "IsGroupOwned", typeof(Boolean));
1358  createCol(land, "Area", typeof(Int32));
1359  createCol(land, "AuctionID", typeof(Int32)); //Unemplemented
1360  createCol(land, "Category", typeof(Int32)); //Enum OpenMetaverse.Parcel.ParcelCategory
1361  createCol(land, "ClaimDate", typeof(Int32));
1362  createCol(land, "ClaimPrice", typeof(Int32));
1363  createCol(land, "GroupUUID", typeof(string));
1364  createCol(land, "SalePrice", typeof(Int32));
1365  createCol(land, "LandStatus", typeof(Int32)); //Enum. OpenMetaverse.Parcel.ParcelStatus
1366  createCol(land, "LandFlags", typeof(UInt32));
1367  createCol(land, "LandingType", typeof(Byte));
1368  createCol(land, "MediaAutoScale", typeof(Byte));
1369  createCol(land, "MediaTextureUUID", typeof(String));
1370  createCol(land, "MediaURL", typeof(String));
1371  createCol(land, "MusicURL", typeof(String));
1372  createCol(land, "PassHours", typeof(Double));
1373  createCol(land, "PassPrice", typeof(UInt32));
1374  createCol(land, "SnapshotUUID", typeof(String));
1375  createCol(land, "UserLocationX", typeof(Double));
1376  createCol(land, "UserLocationY", typeof(Double));
1377  createCol(land, "UserLocationZ", typeof(Double));
1378  createCol(land, "UserLookAtX", typeof(Double));
1379  createCol(land, "UserLookAtY", typeof(Double));
1380  createCol(land, "UserLookAtZ", typeof(Double));
1381  createCol(land, "AuthbuyerID", typeof(String));
1382  createCol(land, "OtherCleanTime", typeof(Int32));
1383  createCol(land, "Dwell", typeof(Int32));
1384  createCol(land, "MediaType", typeof(String));
1385  createCol(land, "MediaDescription", typeof(String));
1386  createCol(land, "MediaSize", typeof(String));
1387  createCol(land, "MediaLoop", typeof(Boolean));
1388  createCol(land, "ObscureMedia", typeof(Boolean));
1389  createCol(land, "ObscureMusic", typeof(Boolean));
1390 
1391  land.PrimaryKey = new DataColumn[] { land.Columns["UUID"] };
1392 
1393  return land;
1394  }
1395 
1400  private static DataTable createLandAccessListTable()
1401  {
1402  DataTable landaccess = new DataTable("landaccesslist");
1403  createCol(landaccess, "LandUUID", typeof(String));
1404  createCol(landaccess, "AccessUUID", typeof(String));
1405  createCol(landaccess, "Flags", typeof(UInt32));
1406 
1407  return landaccess;
1408  }
1409 
1410  private static DataTable createRegionSettingsTable()
1411  {
1412  DataTable regionsettings = new DataTable("regionsettings");
1413  createCol(regionsettings, "regionUUID", typeof(String));
1414  createCol(regionsettings, "block_terraform", typeof(Int32));
1415  createCol(regionsettings, "block_fly", typeof(Int32));
1416  createCol(regionsettings, "allow_damage", typeof(Int32));
1417  createCol(regionsettings, "restrict_pushing", typeof(Int32));
1418  createCol(regionsettings, "allow_land_resell", typeof(Int32));
1419  createCol(regionsettings, "allow_land_join_divide", typeof(Int32));
1420  createCol(regionsettings, "block_show_in_search", typeof(Int32));
1421  createCol(regionsettings, "agent_limit", typeof(Int32));
1422  createCol(regionsettings, "object_bonus", typeof(Double));
1423  createCol(regionsettings, "maturity", typeof(Int32));
1424  createCol(regionsettings, "disable_scripts", typeof(Int32));
1425  createCol(regionsettings, "disable_collisions", typeof(Int32));
1426  createCol(regionsettings, "disable_physics", typeof(Int32));
1427  createCol(regionsettings, "terrain_texture_1", typeof(String));
1428  createCol(regionsettings, "terrain_texture_2", typeof(String));
1429  createCol(regionsettings, "terrain_texture_3", typeof(String));
1430  createCol(regionsettings, "terrain_texture_4", typeof(String));
1431  createCol(regionsettings, "elevation_1_nw", typeof(Double));
1432  createCol(regionsettings, "elevation_2_nw", typeof(Double));
1433  createCol(regionsettings, "elevation_1_ne", typeof(Double));
1434  createCol(regionsettings, "elevation_2_ne", typeof(Double));
1435  createCol(regionsettings, "elevation_1_se", typeof(Double));
1436  createCol(regionsettings, "elevation_2_se", typeof(Double));
1437  createCol(regionsettings, "elevation_1_sw", typeof(Double));
1438  createCol(regionsettings, "elevation_2_sw", typeof(Double));
1439  createCol(regionsettings, "water_height", typeof(Double));
1440  createCol(regionsettings, "terrain_raise_limit", typeof(Double));
1441  createCol(regionsettings, "terrain_lower_limit", typeof(Double));
1442  createCol(regionsettings, "use_estate_sun", typeof(Int32));
1443  createCol(regionsettings, "sandbox", typeof(Int32));
1444  createCol(regionsettings, "sunvectorx", typeof(Double));
1445  createCol(regionsettings, "sunvectory", typeof(Double));
1446  createCol(regionsettings, "sunvectorz", typeof(Double));
1447  createCol(regionsettings, "fixed_sun", typeof(Int32));
1448  createCol(regionsettings, "sun_position", typeof(Double));
1449  createCol(regionsettings, "covenant", typeof(String));
1450  createCol(regionsettings, "covenant_datetime", typeof(Int32));
1451  createCol(regionsettings, "map_tile_ID", typeof(String));
1452  createCol(regionsettings, "TelehubObject", typeof(String));
1453  createCol(regionsettings, "parcel_tile_ID", typeof(String));
1454  regionsettings.PrimaryKey = new DataColumn[] { regionsettings.Columns["regionUUID"] };
1455  return regionsettings;
1456  }
1457 
1462  private static DataTable createRegionWindlightTable()
1463  {
1464  DataTable regionwindlight = new DataTable("regionwindlight");
1465  createCol(regionwindlight, "region_id", typeof(String));
1466  createCol(regionwindlight, "water_color_r", typeof(Double));
1467  createCol(regionwindlight, "water_color_g", typeof(Double));
1468  createCol(regionwindlight, "water_color_b", typeof(Double));
1469  createCol(regionwindlight, "water_color_i", typeof(Double));
1470  createCol(regionwindlight, "water_fog_density_exponent", typeof(Double));
1471  createCol(regionwindlight, "underwater_fog_modifier", typeof(Double));
1472  createCol(regionwindlight, "reflection_wavelet_scale_1", typeof(Double));
1473  createCol(regionwindlight, "reflection_wavelet_scale_2", typeof(Double));
1474  createCol(regionwindlight, "reflection_wavelet_scale_3", typeof(Double));
1475  createCol(regionwindlight, "fresnel_scale", typeof(Double));
1476  createCol(regionwindlight, "fresnel_offset", typeof(Double));
1477  createCol(regionwindlight, "refract_scale_above", typeof(Double));
1478  createCol(regionwindlight, "refract_scale_below", typeof(Double));
1479  createCol(regionwindlight, "blur_multiplier", typeof(Double));
1480  createCol(regionwindlight, "big_wave_direction_x", typeof(Double));
1481  createCol(regionwindlight, "big_wave_direction_y", typeof(Double));
1482  createCol(regionwindlight, "little_wave_direction_x", typeof(Double));
1483  createCol(regionwindlight, "little_wave_direction_y", typeof(Double));
1484  createCol(regionwindlight, "normal_map_texture", typeof(String));
1485  createCol(regionwindlight, "horizon_r", typeof(Double));
1486  createCol(regionwindlight, "horizon_g", typeof(Double));
1487  createCol(regionwindlight, "horizon_b", typeof(Double));
1488  createCol(regionwindlight, "horizon_i", typeof(Double));
1489  createCol(regionwindlight, "haze_horizon", typeof(Double));
1490  createCol(regionwindlight, "blue_density_r", typeof(Double));
1491  createCol(regionwindlight, "blue_density_g", typeof(Double));
1492  createCol(regionwindlight, "blue_density_b", typeof(Double));
1493  createCol(regionwindlight, "blue_density_i", typeof(Double));
1494  createCol(regionwindlight, "haze_density", typeof(Double));
1495  createCol(regionwindlight, "density_multiplier", typeof(Double));
1496  createCol(regionwindlight, "distance_multiplier", typeof(Double));
1497  createCol(regionwindlight, "max_altitude", typeof(Int32));
1498  createCol(regionwindlight, "sun_moon_color_r", typeof(Double));
1499  createCol(regionwindlight, "sun_moon_color_g", typeof(Double));
1500  createCol(regionwindlight, "sun_moon_color_b", typeof(Double));
1501  createCol(regionwindlight, "sun_moon_color_i", typeof(Double));
1502  createCol(regionwindlight, "sun_moon_position", typeof(Double));
1503  createCol(regionwindlight, "ambient_r", typeof(Double));
1504  createCol(regionwindlight, "ambient_g", typeof(Double));
1505  createCol(regionwindlight, "ambient_b", typeof(Double));
1506  createCol(regionwindlight, "ambient_i", typeof(Double));
1507  createCol(regionwindlight, "east_angle", typeof(Double));
1508  createCol(regionwindlight, "sun_glow_focus", typeof(Double));
1509  createCol(regionwindlight, "sun_glow_size", typeof(Double));
1510  createCol(regionwindlight, "scene_gamma", typeof(Double));
1511  createCol(regionwindlight, "star_brightness", typeof(Double));
1512  createCol(regionwindlight, "cloud_color_r", typeof(Double));
1513  createCol(regionwindlight, "cloud_color_g", typeof(Double));
1514  createCol(regionwindlight, "cloud_color_b", typeof(Double));
1515  createCol(regionwindlight, "cloud_color_i", typeof(Double));
1516  createCol(regionwindlight, "cloud_x", typeof(Double));
1517  createCol(regionwindlight, "cloud_y", typeof(Double));
1518  createCol(regionwindlight, "cloud_density", typeof(Double));
1519  createCol(regionwindlight, "cloud_coverage", typeof(Double));
1520  createCol(regionwindlight, "cloud_scale", typeof(Double));
1521  createCol(regionwindlight, "cloud_detail_x", typeof(Double));
1522  createCol(regionwindlight, "cloud_detail_y", typeof(Double));
1523  createCol(regionwindlight, "cloud_detail_density", typeof(Double));
1524  createCol(regionwindlight, "cloud_scroll_x", typeof(Double));
1525  createCol(regionwindlight, "cloud_scroll_x_lock", typeof(Int32));
1526  createCol(regionwindlight, "cloud_scroll_y", typeof(Double));
1527  createCol(regionwindlight, "cloud_scroll_y_lock", typeof(Int32));
1528  createCol(regionwindlight, "draw_classic_clouds", typeof(Int32));
1529 
1530  regionwindlight.PrimaryKey = new DataColumn[] { regionwindlight.Columns["region_id"] };
1531  return regionwindlight;
1532  }
1533 
1534  private static DataTable createRegionEnvironmentTable()
1535  {
1536  DataTable regionEnvironment = new DataTable("regionenvironment");
1537  createCol(regionEnvironment, "region_id", typeof(String));
1538  createCol(regionEnvironment, "llsd_settings", typeof(String));
1539 
1540  regionEnvironment.PrimaryKey = new DataColumn[] { regionEnvironment.Columns["region_id"] };
1541 
1542  return regionEnvironment;
1543  }
1544 
1545  private static DataTable createRegionSpawnPointsTable()
1546  {
1547  DataTable spawn_points = new DataTable("spawn_points");
1548  createCol(spawn_points, "regionID", typeof(String));
1549  createCol(spawn_points, "Yaw", typeof(float));
1550  createCol(spawn_points, "Pitch", typeof(float));
1551  createCol(spawn_points, "Distance", typeof(float));
1552 
1553  return spawn_points;
1554  }
1555 
1556  /***********************************************************************
1557  *
1558  * Convert between ADO.NET <=> OpenSim Objects
1559  *
1560  * These should be database independant
1561  *
1562  **********************************************************************/
1563 
1569  private SceneObjectPart buildPrim(DataRow row)
1570  {
1571  // Code commented. Uncomment to test the unit test inline.
1572 
1573  // The unit test mentions this commented code for the purposes
1574  // of debugging a unit test failure
1575 
1576  // SceneObjectGroup sog = new SceneObjectGroup();
1577  // SceneObjectPart sop = new SceneObjectPart();
1578  // sop.LocalId = 1;
1579  // sop.Name = "object1";
1580  // sop.Description = "object1";
1581  // sop.Text = "";
1582  // sop.SitName = "";
1583  // sop.TouchName = "";
1584  // sop.UUID = UUID.Random();
1585  // sop.Shape = PrimitiveBaseShape.Default;
1586  // sog.SetRootPart(sop);
1587  // Add breakpoint in above line. Check sop fields.
1588 
1589  // TODO: this doesn't work yet because something more
1590  // interesting has to be done to actually get these values
1591  // back out. Not enough time to figure it out yet.
1592 
1594  prim.UUID = new UUID((String)row["UUID"]);
1595  // explicit conversion of integers is required, which sort
1596  // of sucks. No idea if there is a shortcut here or not.
1597  prim.CreationDate = Convert.ToInt32(row["CreationDate"]);
1598  prim.Name = row["Name"] == DBNull.Value ? string.Empty : (string)row["Name"];
1599  // various text fields
1600  prim.Text = (String)row["Text"];
1601  prim.Color = Color.FromArgb(Convert.ToInt32(row["ColorA"]),
1602  Convert.ToInt32(row["ColorR"]),
1603  Convert.ToInt32(row["ColorG"]),
1604  Convert.ToInt32(row["ColorB"]));
1605  prim.Description = (String)row["Description"];
1606  prim.SitName = (String)row["SitName"];
1607  prim.TouchName = (String)row["TouchName"];
1608  // permissions
1609  prim.Flags = (PrimFlags)Convert.ToUInt32(row["ObjectFlags"]);
1610  prim.CreatorIdentification = (String)row["CreatorID"];
1611  prim.OwnerID = new UUID((String)row["OwnerID"]);
1612  prim.GroupID = new UUID((String)row["GroupID"]);
1613  prim.LastOwnerID = new UUID((String)row["LastOwnerID"]);
1614  prim.OwnerMask = Convert.ToUInt32(row["OwnerMask"]);
1615  prim.NextOwnerMask = Convert.ToUInt32(row["NextOwnerMask"]);
1616  prim.GroupMask = Convert.ToUInt32(row["GroupMask"]);
1617  prim.EveryoneMask = Convert.ToUInt32(row["EveryoneMask"]);
1618  prim.BaseMask = Convert.ToUInt32(row["BaseMask"]);
1619  // vectors
1620  prim.OffsetPosition = new Vector3(
1621  Convert.ToSingle(row["PositionX"]),
1622  Convert.ToSingle(row["PositionY"]),
1623  Convert.ToSingle(row["PositionZ"])
1624  );
1625  prim.GroupPosition = new Vector3(
1626  Convert.ToSingle(row["GroupPositionX"]),
1627  Convert.ToSingle(row["GroupPositionY"]),
1628  Convert.ToSingle(row["GroupPositionZ"])
1629  );
1630  prim.Velocity = new Vector3(
1631  Convert.ToSingle(row["VelocityX"]),
1632  Convert.ToSingle(row["VelocityY"]),
1633  Convert.ToSingle(row["VelocityZ"])
1634  );
1635  prim.AngularVelocity = new Vector3(
1636  Convert.ToSingle(row["AngularVelocityX"]),
1637  Convert.ToSingle(row["AngularVelocityY"]),
1638  Convert.ToSingle(row["AngularVelocityZ"])
1639  );
1640  prim.Acceleration = new Vector3(
1641  Convert.ToSingle(row["AccelerationX"]),
1642  Convert.ToSingle(row["AccelerationY"]),
1643  Convert.ToSingle(row["AccelerationZ"])
1644  );
1645  // quaternions
1646  prim.RotationOffset = new Quaternion(
1647  Convert.ToSingle(row["RotationX"]),
1648  Convert.ToSingle(row["RotationY"]),
1649  Convert.ToSingle(row["RotationZ"]),
1650  Convert.ToSingle(row["RotationW"])
1651  );
1652 
1653  prim.SitTargetPositionLL = new Vector3(
1654  Convert.ToSingle(row["SitTargetOffsetX"]),
1655  Convert.ToSingle(row["SitTargetOffsetY"]),
1656  Convert.ToSingle(row["SitTargetOffsetZ"]));
1657  prim.SitTargetOrientationLL = new Quaternion(
1658  Convert.ToSingle(
1659  row["SitTargetOrientX"]),
1660  Convert.ToSingle(
1661  row["SitTargetOrientY"]),
1662  Convert.ToSingle(
1663  row["SitTargetOrientZ"]),
1664  Convert.ToSingle(
1665  row["SitTargetOrientW"]));
1666 
1667  prim.ClickAction = Convert.ToByte(row["ClickAction"]);
1668  prim.PayPrice[0] = Convert.ToInt32(row["PayPrice"]);
1669  prim.PayPrice[1] = Convert.ToInt32(row["PayButton1"]);
1670  prim.PayPrice[2] = Convert.ToInt32(row["PayButton2"]);
1671  prim.PayPrice[3] = Convert.ToInt32(row["PayButton3"]);
1672  prim.PayPrice[4] = Convert.ToInt32(row["PayButton4"]);
1673 
1674  prim.Sound = new UUID(row["LoopedSound"].ToString());
1675  prim.SoundGain = Convert.ToSingle(row["LoopedSoundGain"]);
1676  prim.SoundFlags = 1; // If it's persisted at all, it's looped
1677 
1678  if (!row.IsNull("TextureAnimation"))
1679  prim.TextureAnimation = Convert.FromBase64String(row["TextureAnimation"].ToString());
1680  if (!row.IsNull("ParticleSystem"))
1681  prim.ParticleSystem = Convert.FromBase64String(row["ParticleSystem"].ToString());
1682 
1683  prim.AngularVelocity = new Vector3(
1684  Convert.ToSingle(row["OmegaX"]),
1685  Convert.ToSingle(row["OmegaY"]),
1686  Convert.ToSingle(row["OmegaZ"])
1687  );
1688 
1689  prim.SetCameraEyeOffset(new Vector3(
1690  Convert.ToSingle(row["CameraEyeOffsetX"]),
1691  Convert.ToSingle(row["CameraEyeOffsetY"]),
1692  Convert.ToSingle(row["CameraEyeOffsetZ"])
1693  ));
1694 
1695  prim.SetCameraAtOffset(new Vector3(
1696  Convert.ToSingle(row["CameraAtOffsetX"]),
1697  Convert.ToSingle(row["CameraAtOffsetY"]),
1698  Convert.ToSingle(row["CameraAtOffsetZ"])
1699  ));
1700 
1701  if (Convert.ToInt16(row["ForceMouselook"]) != 0)
1702  prim.SetForceMouselook(true);
1703 
1704  prim.ScriptAccessPin = Convert.ToInt32(row["ScriptAccessPin"]);
1705 
1706  if (Convert.ToInt16(row["AllowedDrop"]) != 0)
1707  prim.AllowedDrop = true;
1708 
1709  if (Convert.ToInt16(row["DieAtEdge"]) != 0)
1710  prim.DIE_AT_EDGE = true;
1711 
1712  prim.SalePrice = Convert.ToInt32(row["SalePrice"]);
1713  prim.ObjectSaleType = Convert.ToByte(row["SaleType"]);
1714 
1715  prim.Material = Convert.ToByte(row["Material"]);
1716 
1717  prim.CollisionSound = new UUID(row["CollisionSound"].ToString());
1718  prim.CollisionSoundVolume = Convert.ToSingle(row["CollisionSoundVolume"]);
1719 
1720  if (Convert.ToInt16(row["VolumeDetect"]) != 0)
1721  prim.VolumeDetectActive = true;
1722 
1723  if (!(row["MediaURL"] is System.DBNull))
1724  {
1725 // m_log.DebugFormat("[SQLITE]: MediaUrl type [{0}]", row["MediaURL"].GetType());
1726  prim.MediaUrl = (string)row["MediaURL"];
1727  }
1728 
1729  prim.AttachedPos = new Vector3(
1730  Convert.ToSingle(row["AttachedPosX"]),
1731  Convert.ToSingle(row["AttachedPosY"]),
1732  Convert.ToSingle(row["AttachedPosZ"])
1733  );
1734 
1735  if (!(row["DynAttrs"] is System.DBNull))
1736  {
1737  //m_log.DebugFormat("[SQLITE]: DynAttrs type [{0}]", row["DynAttrs"].GetType());
1738  prim.DynAttrs = DAMap.FromXml((string)row["DynAttrs"]);
1739  }
1740  else
1741  {
1742  prim.DynAttrs = new DAMap();
1743  }
1744 
1745  prim.PhysicsShapeType = Convert.ToByte(row["PhysicsShapeType"]);
1746  prim.Density = Convert.ToSingle(row["Density"]);
1747  prim.GravityModifier = Convert.ToSingle(row["GravityModifier"]);
1748  prim.Friction = Convert.ToSingle(row["Friction"]);
1749  prim.Restitution = Convert.ToSingle(row["Restitution"]);
1750 
1751 
1752  if (!(row["KeyframeMotion"] is DBNull))
1753  {
1754  Byte[] data = (byte[])row["KeyframeMotion"];
1755  if (data.Length > 0)
1756  prim.KeyframeMotion = KeyframeMotion.FromData(null, data);
1757  else
1758  prim.KeyframeMotion = null;
1759  }
1760  else
1761  {
1762  prim.KeyframeMotion = null;
1763  }
1764 
1765  prim.PassCollisions = Convert.ToBoolean(row["PassCollisions"]);
1766  prim.PassTouches = Convert.ToBoolean(row["PassTouches"]);
1767  prim.RotationAxisLocks = Convert.ToByte(row["RotationAxisLocks"]);
1768 
1769  SOPVehicle vehicle = null;
1770  if (!(row["Vehicle"] is DBNull) && row["Vehicle"].ToString() != String.Empty)
1771  {
1772  vehicle = SOPVehicle.FromXml2(row["Vehicle"].ToString());
1773  if (vehicle != null)
1774  prim.VehicleParams = vehicle;
1775  }
1776  return prim;
1777  }
1778 
1784  private static TaskInventoryItem buildItem(DataRow row)
1785  {
1786  TaskInventoryItem taskItem = new TaskInventoryItem();
1787 
1788  taskItem.ItemID = new UUID((String)row["itemID"]);
1789  taskItem.ParentPartID = new UUID((String)row["primID"]);
1790  taskItem.AssetID = new UUID((String)row["assetID"]);
1791  taskItem.ParentID = new UUID((String)row["parentFolderID"]);
1792 
1793  taskItem.InvType = Convert.ToInt32(row["invType"]);
1794  taskItem.Type = Convert.ToInt32(row["assetType"]);
1795 
1796  taskItem.Name = (String)row["name"];
1797  taskItem.Description = (String)row["description"];
1798  taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
1799  taskItem.CreatorIdentification = (String)row["creatorID"];
1800  taskItem.OwnerID = new UUID((String)row["ownerID"]);
1801  taskItem.LastOwnerID = new UUID((String)row["lastOwnerID"]);
1802  taskItem.GroupID = new UUID((String)row["groupID"]);
1803 
1804  taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
1805  taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
1806  taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
1807  taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
1808  taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
1809  taskItem.Flags = Convert.ToUInt32(row["flags"]);
1810 
1811  return taskItem;
1812  }
1813 
1819  private LandData buildLandData(DataRow row)
1820  {
1821  LandData newData = new LandData();
1822 
1823  newData.GlobalID = new UUID((String)row["UUID"]);
1824  newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
1825 
1826  // Bitmap is a byte[512]
1827  newData.Bitmap = (Byte[])row["Bitmap"];
1828 
1829  newData.Name = (String)row["Name"];
1830  newData.Description = (String)row["Desc"];
1831  newData.OwnerID = (UUID)(String)row["OwnerUUID"];
1832  newData.IsGroupOwned = (Boolean)row["IsGroupOwned"];
1833  newData.Area = Convert.ToInt32(row["Area"]);
1834  newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
1835  newData.Category = (ParcelCategory)Convert.ToInt32(row["Category"]);
1836  //Enum OpenMetaverse.Parcel.ParcelCategory
1837  newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
1838  newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
1839  newData.GroupID = new UUID((String)row["GroupUUID"]);
1840  newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
1841  newData.Status = (ParcelStatus)Convert.ToInt32(row["LandStatus"]);
1842  //Enum. OpenMetaverse.Parcel.ParcelStatus
1843  newData.Flags = Convert.ToUInt32(row["LandFlags"]);
1844  newData.LandingType = (Byte)row["LandingType"];
1845  newData.MediaAutoScale = (Byte)row["MediaAutoScale"];
1846  newData.MediaID = new UUID((String)row["MediaTextureUUID"]);
1847  newData.MediaURL = (String)row["MediaURL"];
1848  newData.MusicURL = (String)row["MusicURL"];
1849  newData.PassHours = Convert.ToSingle(row["PassHours"]);
1850  newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
1851  newData.SnapshotID = (UUID)(String)row["SnapshotUUID"];
1852  newData.Dwell = Convert.ToInt32(row["Dwell"]);
1853  newData.MediaType = (String)row["MediaType"];
1854  newData.MediaDescription = (String)row["MediaDescription"];
1855  newData.MediaWidth = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[0]);
1856  newData.MediaHeight = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[1]);
1857  newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]);
1858  newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]);
1859  newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]);
1860  newData.SeeAVs = Convert.ToBoolean(row["SeeAVs"]);
1861  newData.AnyAVSounds = Convert.ToBoolean(row["AnyAVSounds"]);
1862  newData.GroupAVSounds = Convert.ToBoolean(row["GroupAVSounds"]);
1863 
1864  try
1865  {
1866  newData.UserLocation =
1867  new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
1868  Convert.ToSingle(row["UserLocationZ"]));
1869  newData.UserLookAt =
1870  new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
1871  Convert.ToSingle(row["UserLookAtZ"]));
1872 
1873  }
1874  catch (InvalidCastException)
1875  {
1876  m_log.ErrorFormat("[SQLITE REGION DB]: unable to get parcel telehub settings for {1}", newData.Name);
1877  newData.UserLocation = Vector3.Zero;
1878  newData.UserLookAt = Vector3.Zero;
1879  }
1880  newData.ParcelAccessList = new List<LandAccessEntry>();
1881  UUID authBuyerID = UUID.Zero;
1882 
1883  UUID.TryParse((string)row["AuthbuyerID"], out authBuyerID);
1884 
1885  newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
1886 
1887  return newData;
1888  }
1889 
1890  private RegionSettings buildRegionSettings(DataRow row)
1891  {
1892  RegionSettings newSettings = new RegionSettings();
1893 
1894  newSettings.RegionUUID = new UUID((string)row["regionUUID"]);
1895  newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
1896  newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
1897  newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
1898  newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
1899  newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
1900  newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
1901  newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
1902  newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
1903  newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
1904  newSettings.Maturity = Convert.ToInt32(row["maturity"]);
1905  newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
1906  newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
1907  newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
1908  newSettings.TerrainTexture1 = new UUID((String)row["terrain_texture_1"]);
1909  newSettings.TerrainTexture2 = new UUID((String)row["terrain_texture_2"]);
1910  newSettings.TerrainTexture3 = new UUID((String)row["terrain_texture_3"]);
1911  newSettings.TerrainTexture4 = new UUID((String)row["terrain_texture_4"]);
1912  newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
1913  newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
1914  newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
1915  newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
1916  newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
1917  newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
1918  newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
1919  newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
1920  newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
1921  newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
1922  newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
1923  newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
1924  newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
1925  newSettings.SunVector = new Vector3(
1926  Convert.ToSingle(row["sunvectorx"]),
1927  Convert.ToSingle(row["sunvectory"]),
1928  Convert.ToSingle(row["sunvectorz"])
1929  );
1930  newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
1931  newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
1932  newSettings.Covenant = new UUID((String)row["covenant"]);
1933  newSettings.CovenantChangedDateTime = Convert.ToInt32(row["covenant_datetime"]);
1934  newSettings.TerrainImageID = new UUID((String)row["map_tile_ID"]);
1935  newSettings.TelehubObject = new UUID((String)row["TelehubObject"]);
1936  newSettings.ParcelImageID = new UUID((String)row["parcel_tile_ID"]);
1937  newSettings.GodBlockSearch = Convert.ToBoolean(row["block_search"]);
1938  newSettings.Casino = Convert.ToBoolean(row["casino"]);
1939  return newSettings;
1940  }
1941 
1947  private RegionLightShareData buildRegionWindlight(DataRow row)
1948  {
1949  RegionLightShareData windlight = new RegionLightShareData();
1950 
1951  windlight.regionID = new UUID((string)row["region_id"]);
1952  windlight.waterColor.X = Convert.ToSingle(row["water_color_r"]);
1953  windlight.waterColor.Y = Convert.ToSingle(row["water_color_g"]);
1954  windlight.waterColor.Z = Convert.ToSingle(row["water_color_b"]);
1955  //windlight.waterColor.W = Convert.ToSingle(row["water_color_i"]); //not implemented
1956  windlight.waterFogDensityExponent = Convert.ToSingle(row["water_fog_density_exponent"]);
1957  windlight.underwaterFogModifier = Convert.ToSingle(row["underwater_fog_modifier"]);
1958  windlight.reflectionWaveletScale.X = Convert.ToSingle(row["reflection_wavelet_scale_1"]);
1959  windlight.reflectionWaveletScale.Y = Convert.ToSingle(row["reflection_wavelet_scale_2"]);
1960  windlight.reflectionWaveletScale.Z = Convert.ToSingle(row["reflection_wavelet_scale_3"]);
1961  windlight.fresnelScale = Convert.ToSingle(row["fresnel_scale"]);
1962  windlight.fresnelOffset = Convert.ToSingle(row["fresnel_offset"]);
1963  windlight.refractScaleAbove = Convert.ToSingle(row["refract_scale_above"]);
1964  windlight.refractScaleBelow = Convert.ToSingle(row["refract_scale_below"]);
1965  windlight.blurMultiplier = Convert.ToSingle(row["blur_multiplier"]);
1966  windlight.bigWaveDirection.X = Convert.ToSingle(row["big_wave_direction_x"]);
1967  windlight.bigWaveDirection.Y = Convert.ToSingle(row["big_wave_direction_y"]);
1968  windlight.littleWaveDirection.X = Convert.ToSingle(row["little_wave_direction_x"]);
1969  windlight.littleWaveDirection.Y = Convert.ToSingle(row["little_wave_direction_y"]);
1970  windlight.normalMapTexture = new UUID((string)row["normal_map_texture"]);
1971  windlight.horizon.X = Convert.ToSingle(row["horizon_r"]);
1972  windlight.horizon.Y = Convert.ToSingle(row["horizon_g"]);
1973  windlight.horizon.Z = Convert.ToSingle(row["horizon_b"]);
1974  windlight.horizon.W = Convert.ToSingle(row["horizon_i"]);
1975  windlight.hazeHorizon = Convert.ToSingle(row["haze_horizon"]);
1976  windlight.blueDensity.X = Convert.ToSingle(row["blue_density_r"]);
1977  windlight.blueDensity.Y = Convert.ToSingle(row["blue_density_g"]);
1978  windlight.blueDensity.Z = Convert.ToSingle(row["blue_density_b"]);
1979  windlight.blueDensity.W = Convert.ToSingle(row["blue_density_i"]);
1980  windlight.hazeDensity = Convert.ToSingle(row["haze_density"]);
1981  windlight.densityMultiplier = Convert.ToSingle(row["density_multiplier"]);
1982  windlight.distanceMultiplier = Convert.ToSingle(row["distance_multiplier"]);
1983  windlight.maxAltitude = Convert.ToUInt16(row["max_altitude"]);
1984  windlight.sunMoonColor.X = Convert.ToSingle(row["sun_moon_color_r"]);
1985  windlight.sunMoonColor.Y = Convert.ToSingle(row["sun_moon_color_g"]);
1986  windlight.sunMoonColor.Z = Convert.ToSingle(row["sun_moon_color_b"]);
1987  windlight.sunMoonColor.W = Convert.ToSingle(row["sun_moon_color_i"]);
1988  windlight.sunMoonPosition = Convert.ToSingle(row["sun_moon_position"]);
1989  windlight.ambient.X = Convert.ToSingle(row["ambient_r"]);
1990  windlight.ambient.Y = Convert.ToSingle(row["ambient_g"]);
1991  windlight.ambient.Z = Convert.ToSingle(row["ambient_b"]);
1992  windlight.ambient.W = Convert.ToSingle(row["ambient_i"]);
1993  windlight.eastAngle = Convert.ToSingle(row["east_angle"]);
1994  windlight.sunGlowFocus = Convert.ToSingle(row["sun_glow_focus"]);
1995  windlight.sunGlowSize = Convert.ToSingle(row["sun_glow_size"]);
1996  windlight.sceneGamma = Convert.ToSingle(row["scene_gamma"]);
1997  windlight.starBrightness = Convert.ToSingle(row["star_brightness"]);
1998  windlight.cloudColor.X = Convert.ToSingle(row["cloud_color_r"]);
1999  windlight.cloudColor.Y = Convert.ToSingle(row["cloud_color_g"]);
2000  windlight.cloudColor.Z = Convert.ToSingle(row["cloud_color_b"]);
2001  windlight.cloudColor.W = Convert.ToSingle(row["cloud_color_i"]);
2002  windlight.cloudXYDensity.X = Convert.ToSingle(row["cloud_x"]);
2003  windlight.cloudXYDensity.Y = Convert.ToSingle(row["cloud_y"]);
2004  windlight.cloudXYDensity.Z = Convert.ToSingle(row["cloud_density"]);
2005  windlight.cloudCoverage = Convert.ToSingle(row["cloud_coverage"]);
2006  windlight.cloudScale = Convert.ToSingle(row["cloud_scale"]);
2007  windlight.cloudDetailXYDensity.X = Convert.ToSingle(row["cloud_detail_x"]);
2008  windlight.cloudDetailXYDensity.Y = Convert.ToSingle(row["cloud_detail_y"]);
2009  windlight.cloudDetailXYDensity.Z = Convert.ToSingle(row["cloud_detail_density"]);
2010  windlight.cloudScrollX = Convert.ToSingle(row["cloud_scroll_x"]);
2011  windlight.cloudScrollXLock = Convert.ToBoolean(row["cloud_scroll_x_lock"]);
2012  windlight.cloudScrollY = Convert.ToSingle(row["cloud_scroll_y"]);
2013  windlight.cloudScrollYLock = Convert.ToBoolean(row["cloud_scroll_y_lock"]);
2014  windlight.drawClassicClouds = Convert.ToBoolean(row["draw_classic_clouds"]);
2015 
2016  return windlight;
2017  }
2018 
2024  private static LandAccessEntry buildLandAccessData(DataRow row)
2025  {
2026  LandAccessEntry entry = new LandAccessEntry();
2027  entry.AgentID = new UUID((string)row["AccessUUID"]);
2028  entry.Flags = (AccessList)row["Flags"];
2029  entry.Expires = 0;
2030  return entry;
2031  }
2032 
2033 
2041  private static void fillPrimRow(DataRow row, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
2042  {
2043  row["UUID"] = prim.UUID.ToString();
2044  row["RegionUUID"] = regionUUID.ToString();
2045  row["CreationDate"] = prim.CreationDate;
2046  row["Name"] = prim.Name;
2047  row["SceneGroupID"] = sceneGroupID.ToString();
2048  // the UUID of the root part for this SceneObjectGroup
2049  // various text fields
2050  row["Text"] = prim.Text;
2051  row["Description"] = prim.Description;
2052  row["SitName"] = prim.SitName;
2053  row["TouchName"] = prim.TouchName;
2054  // permissions
2055  row["ObjectFlags"] = (uint)prim.Flags;
2056  row["CreatorID"] = prim.CreatorIdentification.ToString();
2057  row["OwnerID"] = prim.OwnerID.ToString();
2058  row["GroupID"] = prim.GroupID.ToString();
2059  row["LastOwnerID"] = prim.LastOwnerID.ToString();
2060  row["OwnerMask"] = prim.OwnerMask;
2061  row["NextOwnerMask"] = prim.NextOwnerMask;
2062  row["GroupMask"] = prim.GroupMask;
2063  row["EveryoneMask"] = prim.EveryoneMask;
2064  row["BaseMask"] = prim.BaseMask;
2065  // vectors
2066  row["PositionX"] = prim.OffsetPosition.X;
2067  row["PositionY"] = prim.OffsetPosition.Y;
2068  row["PositionZ"] = prim.OffsetPosition.Z;
2069  row["GroupPositionX"] = prim.GroupPosition.X;
2070  row["GroupPositionY"] = prim.GroupPosition.Y;
2071  row["GroupPositionZ"] = prim.GroupPosition.Z;
2072  row["VelocityX"] = prim.Velocity.X;
2073  row["VelocityY"] = prim.Velocity.Y;
2074  row["VelocityZ"] = prim.Velocity.Z;
2075  row["AngularVelocityX"] = prim.AngularVelocity.X;
2076  row["AngularVelocityY"] = prim.AngularVelocity.Y;
2077  row["AngularVelocityZ"] = prim.AngularVelocity.Z;
2078  row["AccelerationX"] = prim.Acceleration.X;
2079  row["AccelerationY"] = prim.Acceleration.Y;
2080  row["AccelerationZ"] = prim.Acceleration.Z;
2081  // quaternions
2082  row["RotationX"] = prim.RotationOffset.X;
2083  row["RotationY"] = prim.RotationOffset.Y;
2084  row["RotationZ"] = prim.RotationOffset.Z;
2085  row["RotationW"] = prim.RotationOffset.W;
2086 
2087  // Sit target
2088  Vector3 sitTargetPos = prim.SitTargetPositionLL;
2089  row["SitTargetOffsetX"] = sitTargetPos.X;
2090  row["SitTargetOffsetY"] = sitTargetPos.Y;
2091  row["SitTargetOffsetZ"] = sitTargetPos.Z;
2092 
2093  Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
2094  row["SitTargetOrientW"] = sitTargetOrient.W;
2095  row["SitTargetOrientX"] = sitTargetOrient.X;
2096  row["SitTargetOrientY"] = sitTargetOrient.Y;
2097  row["SitTargetOrientZ"] = sitTargetOrient.Z;
2098  row["ColorR"] = Convert.ToInt32(prim.Color.R);
2099  row["ColorG"] = Convert.ToInt32(prim.Color.G);
2100  row["ColorB"] = Convert.ToInt32(prim.Color.B);
2101  row["ColorA"] = Convert.ToInt32(prim.Color.A);
2102  row["PayPrice"] = prim.PayPrice[0];
2103  row["PayButton1"] = prim.PayPrice[1];
2104  row["PayButton2"] = prim.PayPrice[2];
2105  row["PayButton3"] = prim.PayPrice[3];
2106  row["PayButton4"] = prim.PayPrice[4];
2107 
2108  row["TextureAnimation"] = Convert.ToBase64String(prim.TextureAnimation);
2109  row["ParticleSystem"] = Convert.ToBase64String(prim.ParticleSystem);
2110 
2111  row["OmegaX"] = prim.AngularVelocity.X;
2112  row["OmegaY"] = prim.AngularVelocity.Y;
2113  row["OmegaZ"] = prim.AngularVelocity.Z;
2114 
2115  row["CameraEyeOffsetX"] = prim.GetCameraEyeOffset().X;
2116  row["CameraEyeOffsetY"] = prim.GetCameraEyeOffset().Y;
2117  row["CameraEyeOffsetZ"] = prim.GetCameraEyeOffset().Z;
2118 
2119  row["CameraAtOffsetX"] = prim.GetCameraAtOffset().X;
2120  row["CameraAtOffsetY"] = prim.GetCameraAtOffset().Y;
2121  row["CameraAtOffsetZ"] = prim.GetCameraAtOffset().Z;
2122 
2123 
2124  if ((prim.SoundFlags & 1) != 0) // Looped
2125  {
2126  row["LoopedSound"] = prim.Sound.ToString();
2127  row["LoopedSoundGain"] = prim.SoundGain;
2128  }
2129  else
2130  {
2131  row["LoopedSound"] = UUID.Zero.ToString();
2132  row["LoopedSoundGain"] = 0.0f;
2133  }
2134 
2135  if (prim.GetForceMouselook())
2136  row["ForceMouselook"] = 1;
2137  else
2138  row["ForceMouselook"] = 0;
2139 
2140  row["ScriptAccessPin"] = prim.ScriptAccessPin;
2141 
2142  if (prim.AllowedDrop)
2143  row["AllowedDrop"] = 1;
2144  else
2145  row["AllowedDrop"] = 0;
2146 
2147  if (prim.DIE_AT_EDGE)
2148  row["DieAtEdge"] = 1;
2149  else
2150  row["DieAtEdge"] = 0;
2151 
2152  row["SalePrice"] = prim.SalePrice;
2153  row["SaleType"] = Convert.ToInt16(prim.ObjectSaleType);
2154 
2155  // click action
2156  row["ClickAction"] = prim.ClickAction;
2157 
2158  row["Material"] = prim.Material;
2159 
2160  row["CollisionSound"] = prim.CollisionSound.ToString();
2161  row["CollisionSoundVolume"] = prim.CollisionSoundVolume;
2162  if (prim.VolumeDetectActive)
2163  row["VolumeDetect"] = 1;
2164  else
2165  row["VolumeDetect"] = 0;
2166 
2167  row["MediaURL"] = prim.MediaUrl;
2168 
2169  row["AttachedPosX"] = prim.AttachedPos.X;
2170  row["AttachedPosY"] = prim.AttachedPos.Y;
2171  row["AttachedPosZ"] = prim.AttachedPos.Z;
2172 
2173  if (prim.DynAttrs.CountNamespaces > 0)
2174  row["DynAttrs"] = prim.DynAttrs.ToXml();
2175  else
2176  row["DynAttrs"] = null;
2177 
2178  row["PhysicsShapeType"] = prim.PhysicsShapeType;
2179  row["Density"] = (double)prim.Density;
2180  row["GravityModifier"] = (double)prim.GravityModifier;
2181  row["Friction"] = (double)prim.Friction;
2182  row["Restitution"] = (double)prim.Restitution;
2183 
2184  if (prim.KeyframeMotion != null)
2185  row["KeyframeMotion"] = prim.KeyframeMotion.Serialize();
2186  else
2187  row["KeyframeMotion"] = new Byte[0];
2188 
2189  row["PassTouches"] = prim.PassTouches;
2190  row["PassCollisions"] = prim.PassCollisions;
2191  row["RotationAxisLocks"] = prim.RotationAxisLocks;
2192 
2193  if (prim.VehicleParams != null)
2194  row["Vehicle"] = prim.VehicleParams.ToXml2();
2195  else
2196  row["Vehicle"] = String.Empty;
2197 
2198  }
2199 
2205  private static void fillItemRow(DataRow row, TaskInventoryItem taskItem)
2206  {
2207  row["itemID"] = taskItem.ItemID.ToString();
2208  row["primID"] = taskItem.ParentPartID.ToString();
2209  row["assetID"] = taskItem.AssetID.ToString();
2210  row["parentFolderID"] = taskItem.ParentID.ToString();
2211 
2212  row["invType"] = taskItem.InvType;
2213  row["assetType"] = taskItem.Type;
2214 
2215  row["name"] = taskItem.Name;
2216  row["description"] = taskItem.Description;
2217  row["creationDate"] = taskItem.CreationDate;
2218  row["creatorID"] = taskItem.CreatorIdentification.ToString();
2219  row["ownerID"] = taskItem.OwnerID.ToString();
2220  row["lastOwnerID"] = taskItem.LastOwnerID.ToString();
2221  row["groupID"] = taskItem.GroupID.ToString();
2222  row["nextPermissions"] = taskItem.NextPermissions;
2223  row["currentPermissions"] = taskItem.CurrentPermissions;
2224  row["basePermissions"] = taskItem.BasePermissions;
2225  row["everyonePermissions"] = taskItem.EveryonePermissions;
2226  row["groupPermissions"] = taskItem.GroupPermissions;
2227  row["flags"] = taskItem.Flags;
2228  }
2229 
2236  private static void fillLandRow(DataRow row, LandData land, UUID regionUUID)
2237  {
2238  row["UUID"] = land.GlobalID.ToString();
2239  row["RegionUUID"] = regionUUID.ToString();
2240  row["LocalLandID"] = land.LocalID;
2241 
2242  // Bitmap is a byte[512]
2243  row["Bitmap"] = land.Bitmap;
2244 
2245  row["Name"] = land.Name;
2246  row["Desc"] = land.Description;
2247  row["OwnerUUID"] = land.OwnerID.ToString();
2248  row["IsGroupOwned"] = land.IsGroupOwned;
2249  row["Area"] = land.Area;
2250  row["AuctionID"] = land.AuctionID; //Unemplemented
2251  row["Category"] = land.Category; //Enum OpenMetaverse.Parcel.ParcelCategory
2252  row["ClaimDate"] = land.ClaimDate;
2253  row["ClaimPrice"] = land.ClaimPrice;
2254  row["GroupUUID"] = land.GroupID.ToString();
2255  row["SalePrice"] = land.SalePrice;
2256  row["LandStatus"] = land.Status; //Enum. OpenMetaverse.Parcel.ParcelStatus
2257  row["LandFlags"] = land.Flags;
2258  row["LandingType"] = land.LandingType;
2259  row["MediaAutoScale"] = land.MediaAutoScale;
2260  row["MediaTextureUUID"] = land.MediaID.ToString();
2261  row["MediaURL"] = land.MediaURL;
2262  row["MusicURL"] = land.MusicURL;
2263  row["PassHours"] = land.PassHours;
2264  row["PassPrice"] = land.PassPrice;
2265  row["SnapshotUUID"] = land.SnapshotID.ToString();
2266  row["UserLocationX"] = land.UserLocation.X;
2267  row["UserLocationY"] = land.UserLocation.Y;
2268  row["UserLocationZ"] = land.UserLocation.Z;
2269  row["UserLookAtX"] = land.UserLookAt.X;
2270  row["UserLookAtY"] = land.UserLookAt.Y;
2271  row["UserLookAtZ"] = land.UserLookAt.Z;
2272  row["AuthbuyerID"] = land.AuthBuyerID.ToString();
2273  row["OtherCleanTime"] = land.OtherCleanTime;
2274  row["Dwell"] = land.Dwell;
2275  row["MediaType"] = land.MediaType;
2276  row["MediaDescription"] = land.MediaDescription;
2277  row["MediaSize"] = String.Format("{0},{1}", land.MediaWidth, land.MediaHeight);
2278  row["MediaLoop"] = land.MediaLoop;
2279  row["ObscureMusic"] = land.ObscureMusic;
2280  row["ObscureMedia"] = land.ObscureMedia;
2281  row["SeeAVs"] = land.SeeAVs;
2282  row["AnyAVSounds"] = land.AnyAVSounds;
2283  row["GroupAVSounds"] = land.GroupAVSounds;
2284 
2285  }
2286 
2293  private static void fillLandAccessRow(DataRow row, LandAccessEntry entry, UUID parcelID)
2294  {
2295  row["LandUUID"] = parcelID.ToString();
2296  row["AccessUUID"] = entry.AgentID.ToString();
2297  row["Flags"] = entry.Flags;
2298  }
2299 
2300  private static void fillRegionSettingsRow(DataRow row, RegionSettings settings)
2301  {
2302  row["regionUUID"] = settings.RegionUUID.ToString();
2303  row["block_terraform"] = settings.BlockTerraform;
2304  row["block_fly"] = settings.BlockFly;
2305  row["allow_damage"] = settings.AllowDamage;
2306  row["restrict_pushing"] = settings.RestrictPushing;
2307  row["allow_land_resell"] = settings.AllowLandResell;
2308  row["allow_land_join_divide"] = settings.AllowLandJoinDivide;
2309  row["block_show_in_search"] = settings.BlockShowInSearch;
2310  row["agent_limit"] = settings.AgentLimit;
2311  row["object_bonus"] = settings.ObjectBonus;
2312  row["maturity"] = settings.Maturity;
2313  row["disable_scripts"] = settings.DisableScripts;
2314  row["disable_collisions"] = settings.DisableCollisions;
2315  row["disable_physics"] = settings.DisablePhysics;
2316  row["terrain_texture_1"] = settings.TerrainTexture1.ToString();
2317  row["terrain_texture_2"] = settings.TerrainTexture2.ToString();
2318  row["terrain_texture_3"] = settings.TerrainTexture3.ToString();
2319  row["terrain_texture_4"] = settings.TerrainTexture4.ToString();
2320  row["elevation_1_nw"] = settings.Elevation1NW;
2321  row["elevation_2_nw"] = settings.Elevation2NW;
2322  row["elevation_1_ne"] = settings.Elevation1NE;
2323  row["elevation_2_ne"] = settings.Elevation2NE;
2324  row["elevation_1_se"] = settings.Elevation1SE;
2325  row["elevation_2_se"] = settings.Elevation2SE;
2326  row["elevation_1_sw"] = settings.Elevation1SW;
2327  row["elevation_2_sw"] = settings.Elevation2SW;
2328  row["water_height"] = settings.WaterHeight;
2329  row["terrain_raise_limit"] = settings.TerrainRaiseLimit;
2330  row["terrain_lower_limit"] = settings.TerrainLowerLimit;
2331  row["use_estate_sun"] = settings.UseEstateSun;
2332  row["sandbox"] = settings.Sandbox; // unlike other database modules, sqlite uses a lower case s for sandbox!
2333  row["sunvectorx"] = settings.SunVector.X;
2334  row["sunvectory"] = settings.SunVector.Y;
2335  row["sunvectorz"] = settings.SunVector.Z;
2336  row["fixed_sun"] = settings.FixedSun;
2337  row["sun_position"] = settings.SunPosition;
2338  row["covenant"] = settings.Covenant.ToString();
2339  row["covenant_datetime"] = settings.CovenantChangedDateTime;
2340  row["map_tile_ID"] = settings.TerrainImageID.ToString();
2341  row["TelehubObject"] = settings.TelehubObject.ToString();
2342  row["parcel_tile_ID"] = settings.ParcelImageID.ToString();
2343  row["block_search"] = settings.GodBlockSearch;
2344  row["casino"] = settings.Casino;
2345  }
2346 
2352  private static void fillRegionWindlightRow(DataRow row, RegionLightShareData windlight)
2353  {
2354  row["region_id"] = windlight.regionID.ToString();
2355  row["water_color_r"] = windlight.waterColor.X;
2356  row["water_color_g"] = windlight.waterColor.Y;
2357  row["water_color_b"] = windlight.waterColor.Z;
2358  row["water_color_i"] = 1; //windlight.waterColor.W; //not implemented
2359  row["water_fog_density_exponent"] = windlight.waterFogDensityExponent;
2360  row["underwater_fog_modifier"] = windlight.underwaterFogModifier;
2361  row["reflection_wavelet_scale_1"] = windlight.reflectionWaveletScale.X;
2362  row["reflection_wavelet_scale_2"] = windlight.reflectionWaveletScale.Y;
2363  row["reflection_wavelet_scale_3"] = windlight.reflectionWaveletScale.Z;
2364  row["fresnel_scale"] = windlight.fresnelScale;
2365  row["fresnel_offset"] = windlight.fresnelOffset;
2366  row["refract_scale_above"] = windlight.refractScaleAbove;
2367  row["refract_scale_below"] = windlight.refractScaleBelow;
2368  row["blur_multiplier"] = windlight.blurMultiplier;
2369  row["big_wave_direction_x"] = windlight.bigWaveDirection.X;
2370  row["big_wave_direction_y"] = windlight.bigWaveDirection.Y;
2371  row["little_wave_direction_x"] = windlight.littleWaveDirection.X;
2372  row["little_wave_direction_y"] = windlight.littleWaveDirection.Y;
2373  row["normal_map_texture"] = windlight.normalMapTexture.ToString();
2374  row["horizon_r"] = windlight.horizon.X;
2375  row["horizon_g"] = windlight.horizon.Y;
2376  row["horizon_b"] = windlight.horizon.Z;
2377  row["horizon_i"] = windlight.horizon.W;
2378  row["haze_horizon"] = windlight.hazeHorizon;
2379  row["blue_density_r"] = windlight.blueDensity.X;
2380  row["blue_density_g"] = windlight.blueDensity.Y;
2381  row["blue_density_b"] = windlight.blueDensity.Z;
2382  row["blue_density_i"] = windlight.blueDensity.W;
2383  row["haze_density"] = windlight.hazeDensity;
2384  row["density_multiplier"] = windlight.densityMultiplier;
2385  row["distance_multiplier"] = windlight.distanceMultiplier;
2386  row["max_altitude"] = windlight.maxAltitude;
2387  row["sun_moon_color_r"] = windlight.sunMoonColor.X;
2388  row["sun_moon_color_g"] = windlight.sunMoonColor.Y;
2389  row["sun_moon_color_b"] = windlight.sunMoonColor.Z;
2390  row["sun_moon_color_i"] = windlight.sunMoonColor.W;
2391  row["sun_moon_position"] = windlight.sunMoonPosition;
2392  row["ambient_r"] = windlight.ambient.X;
2393  row["ambient_g"] = windlight.ambient.Y;
2394  row["ambient_b"] = windlight.ambient.Z;
2395  row["ambient_i"] = windlight.ambient.W;
2396  row["east_angle"] = windlight.eastAngle;
2397  row["sun_glow_focus"] = windlight.sunGlowFocus;
2398  row["sun_glow_size"] = windlight.sunGlowSize;
2399  row["scene_gamma"] = windlight.sceneGamma;
2400  row["star_brightness"] = windlight.starBrightness;
2401  row["cloud_color_r"] = windlight.cloudColor.X;
2402  row["cloud_color_g"] = windlight.cloudColor.Y;
2403  row["cloud_color_b"] = windlight.cloudColor.Z;
2404  row["cloud_color_i"] = windlight.cloudColor.W;
2405  row["cloud_x"] = windlight.cloudXYDensity.X;
2406  row["cloud_y"] = windlight.cloudXYDensity.Y;
2407  row["cloud_density"] = windlight.cloudXYDensity.Z;
2408  row["cloud_coverage"] = windlight.cloudCoverage;
2409  row["cloud_scale"] = windlight.cloudScale;
2410  row["cloud_detail_x"] = windlight.cloudDetailXYDensity.X;
2411  row["cloud_detail_y"] = windlight.cloudDetailXYDensity.Y;
2412  row["cloud_detail_density"] = windlight.cloudDetailXYDensity.Z;
2413  row["cloud_scroll_x"] = windlight.cloudScrollX;
2414  row["cloud_scroll_x_lock"] = windlight.cloudScrollXLock;
2415  row["cloud_scroll_y"] = windlight.cloudScrollY;
2416  row["cloud_scroll_y_lock"] = windlight.cloudScrollYLock;
2417  row["draw_classic_clouds"] = windlight.drawClassicClouds;
2418  }
2419 
2425  private PrimitiveBaseShape buildShape(DataRow row)
2426  {
2428  s.Scale = new Vector3(
2429  Convert.ToSingle(row["ScaleX"]),
2430  Convert.ToSingle(row["ScaleY"]),
2431  Convert.ToSingle(row["ScaleZ"])
2432  );
2433  // paths
2434  s.PCode = Convert.ToByte(row["PCode"]);
2435  s.PathBegin = Convert.ToUInt16(row["PathBegin"]);
2436  s.PathEnd = Convert.ToUInt16(row["PathEnd"]);
2437  s.PathScaleX = Convert.ToByte(row["PathScaleX"]);
2438  s.PathScaleY = Convert.ToByte(row["PathScaleY"]);
2439  s.PathShearX = Convert.ToByte(row["PathShearX"]);
2440  s.PathShearY = Convert.ToByte(row["PathShearY"]);
2441  s.PathSkew = Convert.ToSByte(row["PathSkew"]);
2442  s.PathCurve = Convert.ToByte(row["PathCurve"]);
2443  s.PathRadiusOffset = Convert.ToSByte(row["PathRadiusOffset"]);
2444  s.PathRevolutions = Convert.ToByte(row["PathRevolutions"]);
2445  s.PathTaperX = Convert.ToSByte(row["PathTaperX"]);
2446  s.PathTaperY = Convert.ToSByte(row["PathTaperY"]);
2447  s.PathTwist = Convert.ToSByte(row["PathTwist"]);
2448  s.PathTwistBegin = Convert.ToSByte(row["PathTwistBegin"]);
2449  // profile
2450  s.ProfileBegin = Convert.ToUInt16(row["ProfileBegin"]);
2451  s.ProfileEnd = Convert.ToUInt16(row["ProfileEnd"]);
2452  s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]);
2453  s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]);
2454  s.State = Convert.ToByte(row["State"]);
2455  s.LastAttachPoint = Convert.ToByte(row["LastAttachPoint"]);
2456 
2457  byte[] textureEntry = (byte[])row["Texture"];
2458  s.TextureEntry = textureEntry;
2459 
2460  s.ExtraParams = (byte[])row["ExtraParams"];
2461 
2462  if (!(row["Media"] is System.DBNull))
2463  s.Media = PrimitiveBaseShape.MediaList.FromXml((string)row["Media"]);
2464 
2465  return s;
2466  }
2467 
2473  private static void fillShapeRow(DataRow row, SceneObjectPart prim)
2474  {
2475  PrimitiveBaseShape s = prim.Shape;
2476  row["UUID"] = prim.UUID.ToString();
2477  // shape is an enum
2478  row["Shape"] = 0;
2479  // vectors
2480  row["ScaleX"] = s.Scale.X;
2481  row["ScaleY"] = s.Scale.Y;
2482  row["ScaleZ"] = s.Scale.Z;
2483  // paths
2484  row["PCode"] = s.PCode;
2485  row["PathBegin"] = s.PathBegin;
2486  row["PathEnd"] = s.PathEnd;
2487  row["PathScaleX"] = s.PathScaleX;
2488  row["PathScaleY"] = s.PathScaleY;
2489  row["PathShearX"] = s.PathShearX;
2490  row["PathShearY"] = s.PathShearY;
2491  row["PathSkew"] = s.PathSkew;
2492  row["PathCurve"] = s.PathCurve;
2493  row["PathRadiusOffset"] = s.PathRadiusOffset;
2494  row["PathRevolutions"] = s.PathRevolutions;
2495  row["PathTaperX"] = s.PathTaperX;
2496  row["PathTaperY"] = s.PathTaperY;
2497  row["PathTwist"] = s.PathTwist;
2498  row["PathTwistBegin"] = s.PathTwistBegin;
2499  // profile
2500  row["ProfileBegin"] = s.ProfileBegin;
2501  row["ProfileEnd"] = s.ProfileEnd;
2502  row["ProfileCurve"] = s.ProfileCurve;
2503  row["ProfileHollow"] = s.ProfileHollow;
2504  row["State"] = s.State;
2505  row["LastAttachPoint"] = s.LastAttachPoint;
2506 
2507  row["Texture"] = s.TextureEntry;
2508  row["ExtraParams"] = s.ExtraParams;
2509 
2510  if (s.Media != null)
2511  row["Media"] = s.Media.ToXml();
2512  }
2513 
2520  private void addPrim(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
2521  {
2522  DataTable prims = ds.Tables["prims"];
2523  DataTable shapes = ds.Tables["primshapes"];
2524 
2525  DataRow primRow = prims.Rows.Find(prim.UUID.ToString());
2526  if (primRow == null)
2527  {
2528  primRow = prims.NewRow();
2529  fillPrimRow(primRow, prim, sceneGroupID, regionUUID);
2530  prims.Rows.Add(primRow);
2531  }
2532  else
2533  {
2534  fillPrimRow(primRow, prim, sceneGroupID, regionUUID);
2535  }
2536 
2537  DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
2538  if (shapeRow == null)
2539  {
2540  shapeRow = shapes.NewRow();
2541  fillShapeRow(shapeRow, prim);
2542  shapes.Rows.Add(shapeRow);
2543  }
2544  else
2545  {
2546  fillShapeRow(shapeRow, prim);
2547  }
2548  }
2549 
2554  public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
2555  {
2556 // m_log.DebugFormat("[SQLITE REGION DB]: Entered StorePrimInventory with prim ID {0}", primID);
2557 
2558  DataTable dbItems = ds.Tables["primitems"];
2559 
2560  // For now, we're just going to crudely remove all the previous inventory items
2561  // no matter whether they have changed or not, and replace them with the current set.
2562  lock (ds)
2563  {
2564  RemoveItems(primID);
2565 
2566  // repalce with current inventory details
2567  foreach (TaskInventoryItem newItem in items)
2568  {
2569  // m_log.InfoFormat(
2570  // "[DATASTORE]: ",
2571  // "Adding item {0}, {1} to prim ID {2}",
2572  // newItem.Name, newItem.ItemID, newItem.ParentPartID);
2573 
2574  DataRow newItemRow = dbItems.NewRow();
2575  fillItemRow(newItemRow, newItem);
2576  dbItems.Rows.Add(newItemRow);
2577  }
2578  }
2579 
2580  Commit();
2581  }
2582 
2583  /***********************************************************************
2584  *
2585  * SQL Statement Creation Functions
2586  *
2587  * These functions create SQL statements for update, insert, and create.
2588  * They can probably be factored later to have a db independant
2589  * portion and a db specific portion
2590  *
2591  **********************************************************************/
2592 
2608  private static SqliteCommand createInsertCommand(string table, DataTable dt)
2609  {
2610  string[] cols = new string[dt.Columns.Count];
2611  for (int i = 0; i < dt.Columns.Count; i++)
2612  {
2613  DataColumn col = dt.Columns[i];
2614  cols[i] = col.ColumnName;
2615  }
2616 
2617  string sql = "insert into " + table + "(";
2618  sql += String.Join(", ", cols);
2619  // important, the first ':' needs to be here, the rest get added in the join
2620  sql += ") values (:";
2621  sql += String.Join(", :", cols);
2622  sql += ")";
2623 // m_log.DebugFormat("[SQLITE]: Created insert command {0}", sql);
2624  SqliteCommand cmd = new SqliteCommand(sql);
2625 
2626  // this provides the binding for all our parameters, so
2627  // much less code than it used to be
2628  foreach (DataColumn col in dt.Columns)
2629  {
2630  cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
2631  }
2632  return cmd;
2633  }
2634 
2635 
2643  private static SqliteCommand createUpdateCommand(string table, string pk, DataTable dt)
2644  {
2645  string sql = "update " + table + " set ";
2646  string subsql = String.Empty;
2647  foreach (DataColumn col in dt.Columns)
2648  {
2649  if (subsql.Length > 0)
2650  {
2651  // a map function would rock so much here
2652  subsql += ", ";
2653  }
2654  subsql += col.ColumnName + "= :" + col.ColumnName;
2655  }
2656  sql += subsql;
2657  sql += " where " + pk;
2658  SqliteCommand cmd = new SqliteCommand(sql);
2659 
2660  // this provides the binding for all our parameters, so
2661  // much less code than it used to be
2662 
2663  foreach (DataColumn col in dt.Columns)
2664  {
2665  cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
2666  }
2667  return cmd;
2668  }
2669 
2677  private static SqliteCommand createUpdateCommand(string table, string pk1, string pk2, DataTable dt)
2678  {
2679  string sql = "update " + table + " set ";
2680  string subsql = String.Empty;
2681  foreach (DataColumn col in dt.Columns)
2682  {
2683  if (subsql.Length > 0)
2684  {
2685  // a map function would rock so much here
2686  subsql += ", ";
2687  }
2688  subsql += col.ColumnName + "= :" + col.ColumnName;
2689  }
2690  sql += subsql;
2691  sql += " where " + pk1 + " and " + pk2;
2692  SqliteCommand cmd = new SqliteCommand(sql);
2693 
2694  // this provides the binding for all our parameters, so
2695  // much less code than it used to be
2696 
2697  foreach (DataColumn col in dt.Columns)
2698  {
2699  cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
2700  }
2701  return cmd;
2702  }
2703 
2709  // private static string defineTable(DataTable dt)
2710  // {
2711  // string sql = "create table " + dt.TableName + "(";
2712  // string subsql = String.Empty;
2713  // foreach (DataColumn col in dt.Columns)
2714  // {
2715  // if (subsql.Length > 0)
2716  // {
2717  // // a map function would rock so much here
2718  // subsql += ",\n";
2719  // }
2720  // subsql += col.ColumnName + " " + sqliteType(col.DataType);
2721  // if (dt.PrimaryKey.Length > 0 && col == dt.PrimaryKey[0])
2722  // {
2723  // subsql += " primary key";
2724  // }
2725  // }
2726  // sql += subsql;
2727  // sql += ")";
2728  // return sql;
2729  // }
2730 
2731  /***********************************************************************
2732  *
2733  * Database Binding functions
2734  *
2735  * These will be db specific due to typing, and minor differences
2736  * in databases.
2737  *
2738  **********************************************************************/
2739 
2751  private static SqliteParameter createSqliteParameter(string name, Type type)
2752  {
2753  SqliteParameter param = new SqliteParameter();
2754  param.ParameterName = ":" + name;
2755  param.DbType = dbtypeFromType(type);
2756  param.SourceColumn = name;
2757  param.SourceVersion = DataRowVersion.Current;
2758  return param;
2759  }
2760 
2766  private void setupPrimCommands(SqliteDataAdapter da, SqliteConnection conn)
2767  {
2768  da.InsertCommand = createInsertCommand("prims", ds.Tables["prims"]);
2769  da.InsertCommand.Connection = conn;
2770 
2771  da.UpdateCommand = createUpdateCommand("prims", "UUID=:UUID", ds.Tables["prims"]);
2772  da.UpdateCommand.Connection = conn;
2773 
2774  SqliteCommand delete = new SqliteCommand("delete from prims where UUID = :UUID");
2775  delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
2776  delete.Connection = conn;
2777  da.DeleteCommand = delete;
2778  }
2779 
2785  private void setupItemsCommands(SqliteDataAdapter da, SqliteConnection conn)
2786  {
2787  da.InsertCommand = createInsertCommand("primitems", ds.Tables["primitems"]);
2788  da.InsertCommand.Connection = conn;
2789 
2790  da.UpdateCommand = createUpdateCommand("primitems", "itemID = :itemID", ds.Tables["primitems"]);
2791  da.UpdateCommand.Connection = conn;
2792 
2793  SqliteCommand delete = new SqliteCommand("delete from primitems where itemID = :itemID");
2794  delete.Parameters.Add(createSqliteParameter("itemID", typeof(String)));
2795  delete.Connection = conn;
2796  da.DeleteCommand = delete;
2797  }
2798 
2804  private void setupTerrainCommands(SqliteDataAdapter da, SqliteConnection conn)
2805  {
2806  da.InsertCommand = createInsertCommand("terrain", ds.Tables["terrain"]);
2807  da.InsertCommand.Connection = conn;
2808  }
2809 
2815  private void setupLandCommands(SqliteDataAdapter da, SqliteConnection conn)
2816  {
2817  da.InsertCommand = createInsertCommand("land", ds.Tables["land"]);
2818  da.InsertCommand.Connection = conn;
2819 
2820  da.UpdateCommand = createUpdateCommand("land", "UUID=:UUID", ds.Tables["land"]);
2821  da.UpdateCommand.Connection = conn;
2822 
2823  SqliteCommand delete = new SqliteCommand("delete from land where UUID=:UUID");
2824  delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
2825  da.DeleteCommand = delete;
2826  da.DeleteCommand.Connection = conn;
2827  }
2828 
2834  private void setupLandAccessCommands(SqliteDataAdapter da, SqliteConnection conn)
2835  {
2836  da.InsertCommand = createInsertCommand("landaccesslist", ds.Tables["landaccesslist"]);
2837  da.InsertCommand.Connection = conn;
2838 
2839  da.UpdateCommand = createUpdateCommand("landaccesslist", "LandUUID=:landUUID", "AccessUUID=:AccessUUID", ds.Tables["landaccesslist"]);
2840  da.UpdateCommand.Connection = conn;
2841 
2842  SqliteCommand delete = new SqliteCommand("delete from landaccesslist where LandUUID= :LandUUID and AccessUUID= :AccessUUID");
2843  delete.Parameters.Add(createSqliteParameter("LandUUID", typeof(String)));
2844  delete.Parameters.Add(createSqliteParameter("AccessUUID", typeof(String)));
2845  da.DeleteCommand = delete;
2846  da.DeleteCommand.Connection = conn;
2847  }
2848 
2849  private void setupRegionSettingsCommands(SqliteDataAdapter da, SqliteConnection conn)
2850  {
2851  da.InsertCommand = createInsertCommand("regionsettings", ds.Tables["regionsettings"]);
2852  da.InsertCommand.Connection = conn;
2853  da.UpdateCommand = createUpdateCommand("regionsettings", "regionUUID=:regionUUID", ds.Tables["regionsettings"]);
2854  da.UpdateCommand.Connection = conn;
2855  }
2856 
2862  private void setupRegionWindlightCommands(SqliteDataAdapter da, SqliteConnection conn)
2863  {
2864  da.InsertCommand = createInsertCommand("regionwindlight", ds.Tables["regionwindlight"]);
2865  da.InsertCommand.Connection = conn;
2866  da.UpdateCommand = createUpdateCommand("regionwindlight", "region_id=:region_id", ds.Tables["regionwindlight"]);
2867  da.UpdateCommand.Connection = conn;
2868  }
2869 
2870  private void setupRegionEnvironmentCommands(SqliteDataAdapter da, SqliteConnection conn)
2871  {
2872  da.InsertCommand = createInsertCommand("regionenvironment", ds.Tables["regionenvironment"]);
2873  da.InsertCommand.Connection = conn;
2874  da.UpdateCommand = createUpdateCommand("regionenvironment", "region_id=:region_id", ds.Tables["regionenvironment"]);
2875  da.UpdateCommand.Connection = conn;
2876  }
2877 
2878  private void setupRegionSpawnPointsCommands(SqliteDataAdapter da, SqliteConnection conn)
2879  {
2880  da.InsertCommand = createInsertCommand("spawn_points", ds.Tables["spawn_points"]);
2881  da.InsertCommand.Connection = conn;
2882  da.UpdateCommand = createUpdateCommand("spawn_points", "RegionID=:RegionID", ds.Tables["spawn_points"]);
2883  da.UpdateCommand.Connection = conn;
2884  }
2885 
2891  private void setupShapeCommands(SqliteDataAdapter da, SqliteConnection conn)
2892  {
2893  da.InsertCommand = createInsertCommand("primshapes", ds.Tables["primshapes"]);
2894  da.InsertCommand.Connection = conn;
2895 
2896  da.UpdateCommand = createUpdateCommand("primshapes", "UUID=:UUID", ds.Tables["primshapes"]);
2897  da.UpdateCommand.Connection = conn;
2898 
2899  SqliteCommand delete = new SqliteCommand("delete from primshapes where UUID = :UUID");
2900  delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
2901  delete.Connection = conn;
2902  da.DeleteCommand = delete;
2903  }
2904 
2905  /***********************************************************************
2906  *
2907  * Type conversion functions
2908  *
2909  **********************************************************************/
2910 
2916  private static DbType dbtypeFromType(Type type)
2917  {
2918  if (type == typeof(String))
2919  {
2920  return DbType.String;
2921  }
2922  else if (type == typeof(Int32))
2923  {
2924  return DbType.Int32;
2925  }
2926  else if (type == typeof(Double))
2927  {
2928  return DbType.Double;
2929  }
2930  else if (type == typeof(Byte))
2931  {
2932  return DbType.Byte;
2933  }
2934  else if (type == typeof(Double))
2935  {
2936  return DbType.Double;
2937  }
2938  else if (type == typeof(Byte[]))
2939  {
2940  return DbType.Binary;
2941  }
2942  else
2943  {
2944  return DbType.String;
2945  }
2946  }
2947 
2948  static void PrintDataSet(DataSet ds)
2949  {
2950  // Print out any name and extended properties.
2951  Console.WriteLine("DataSet is named: {0}", ds.DataSetName);
2952  foreach (System.Collections.DictionaryEntry de in ds.ExtendedProperties)
2953  {
2954  Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
2955  }
2956  Console.WriteLine();
2957  foreach (DataTable dt in ds.Tables)
2958  {
2959  Console.WriteLine("=> {0} Table:", dt.TableName);
2960  // Print out the column names.
2961  for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
2962  {
2963  Console.Write(dt.Columns[curCol].ColumnName + "\t");
2964  }
2965  Console.WriteLine("\n----------------------------------");
2966  // Print the DataTable.
2967  for (int curRow = 0; curRow < dt.Rows.Count; curRow++)
2968  {
2969  for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
2970  {
2971  Console.Write(dt.Rows[curRow][curCol].ToString() + "\t");
2972  }
2973  Console.WriteLine();
2974  }
2975  }
2976  }
2977 
2978  public UUID[] GetObjectIDs(UUID regionID)
2979  {
2980  return new UUID[0];
2981  }
2982 
2983  public void SaveExtra(UUID regionID, string name, string value)
2984  {
2985  }
2986 
2987  public void RemoveExtra(UUID regionID, string name)
2988  {
2989  }
2990 
2991  public Dictionary<string, string> GetExtra(UUID regionID)
2992  {
2993  return null;
2994  }
2995  }
2996 }
void SaveExtra(UUID regionID, string name, string value)
void RemoveExtra(UUID regionID, string name)
void StoreObject(SceneObjectGroup obj, UUID regionUUID)
Adds an object into region storage
List< SceneObjectGroup > LoadObjects(UUID regionUUID)
Load persisted objects from region storage.
List< LandAccessEntry > ParcelAccessList
List of access data for the parcel. User data, some bitflags, and a time
Definition: LandData.cs:566
void StoreRegionEnvironmentSettings(UUID regionUUID, string settings)
Store Environment settings into region storage
OpenSim.Framework.RegionSettings RegionSettings
void RemoveLandObject(UUID globalID)
delete from land where UUID=globalID delete from landaccesslist where LandUUID=globalID ...
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
PrimFlags Flags
Property flags. See OpenMetaverse.PrimFlags
MediaList Media
Entries to store media textures on each face
int CountNamespaces
Get the number of namespaces
Definition: DAMap.cs:183
Represents an item in a task inventory
Definition: LandData.cs:37
void RemoveRegionWindlightSettings(UUID regionID)
Remove windlight settings from region storage
string CreatorIdentification
Used by the DB layer to retrieve / store the entire user identification. The identification can eithe...
A RegionData Interface to the SQLite database
Dictionary< string, string > GetExtra(UUID regionID)
UUID GlobalID
Global ID for the parcel. (3rd Party Integration)
Definition: LandData.cs:327
void RemoveRegionEnvironmentSettings(UUID regionUUID)
Delete Environment settings from region storage
void StoreTerrain(double[,] ter, UUID regionID)
double[,] LoadTerrain(UUID regionID)
Load the latest terrain revision from region storage
This class stores and retrieves dynamic attributes.
Definition: DAMap.cs:53
void StoreRegionWindlightSettings(RegionLightShareData wl)
Adds an windlight into region storage
void StoreTerrain(TerrainData terrData, UUID regionID)
Store a terrain revision in region storage
Details of a Parcel of land
Definition: LandData.cs:47
TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
Load the latest terrain revision from region storage
void RemoveObject(UUID obj, UUID regionUUID)
Removes an object from region storage
void Initialise(string connectionString)
Initialises RegionData Interface Loads and initialises a new SQLite connection and maintains it...
List< LandData > LoadLandObjects(UUID regionUUID)
RegionSettings LoadRegionSettings(UUID regionUUID)
void StorePrimInventory(UUID primID, ICollection< TaskInventoryItem > items)
DAMap DynAttrs
Dynamic attributes can be created and deleted as required.
Material
Material type for a primitive
Definition: OdeScene.cs:79
void CreateDataSetMapping(IDataAdapter da, string tableName)
string LoadRegionEnvironmentSettings(UUID regionUUID)
Load Environment settings from region storage
RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID)
Load windlight settings from region storage