aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/SQLite/SQLiteRegionData.cs
diff options
context:
space:
mode:
authorJohn Hurliman2010-09-11 20:43:06 -0700
committerJohn Hurliman2010-09-11 20:43:06 -0700
commit109b51758398d24a96a16900e8feb24361aee29d (patch)
treeaa696571c44fcf7afdad1931137a51f3074cd524 /OpenSim/Data/SQLite/SQLiteRegionData.cs
parentRe-enabled asset last access time logging in MySQL (diff)
downloadopensim-SC_OLD-109b51758398d24a96a16900e8feb24361aee29d.zip
opensim-SC_OLD-109b51758398d24a96a16900e8feb24361aee29d.tar.gz
opensim-SC_OLD-109b51758398d24a96a16900e8feb24361aee29d.tar.bz2
opensim-SC_OLD-109b51758398d24a96a16900e8feb24361aee29d.tar.xz
Fixed the naming mess around data connectors for simulation data
Diffstat (limited to 'OpenSim/Data/SQLite/SQLiteRegionData.cs')
-rw-r--r--OpenSim/Data/SQLite/SQLiteRegionData.cs2355
1 files changed, 0 insertions, 2355 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteRegionData.cs b/OpenSim/Data/SQLite/SQLiteRegionData.cs
deleted file mode 100644
index 88699a7..0000000
--- a/OpenSim/Data/SQLite/SQLiteRegionData.cs
+++ /dev/null
@@ -1,2355 +0,0 @@
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
28using System;
29using System.Collections.Generic;
30using System.Data;
31using System.Drawing;
32using System.IO;
33using System.Reflection;
34using log4net;
35using Mono.Data.Sqlite;
36using OpenMetaverse;
37using OpenMetaverse.StructuredData;
38using OpenSim.Framework;
39using OpenSim.Region.Framework.Interfaces;
40using OpenSim.Region.Framework.Scenes;
41
42namespace OpenSim.Data.SQLite
43{
44 /// <summary>
45 /// A RegionData Interface to the SQLite database
46 /// </summary>
47 public class SQLiteRegionData : IRegionDataStore
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private const string primSelect = "select * from prims";
52 private const string shapeSelect = "select * from primshapes";
53 private const string itemsSelect = "select * from primitems";
54 private const string terrainSelect = "select * from terrain limit 1";
55 private const string landSelect = "select * from land";
56 private const string landAccessListSelect = "select distinct * from landaccesslist";
57 private const string regionbanListSelect = "select * from regionban";
58 private const string regionSettingsSelect = "select * from regionsettings";
59
60 private DataSet ds;
61 private SqliteDataAdapter primDa;
62 private SqliteDataAdapter shapeDa;
63 private SqliteDataAdapter itemsDa;
64 private SqliteDataAdapter terrainDa;
65 private SqliteDataAdapter landDa;
66 private SqliteDataAdapter landAccessListDa;
67 private SqliteDataAdapter regionSettingsDa;
68
69 private SqliteConnection m_conn;
70
71 private String m_connectionString;
72
73 // Temporary attribute while this is experimental
74
75 /***********************************************************************
76 *
77 * Public Interface Functions
78 *
79 **********************************************************************/
80
81 /// <summary>
82 /// See IRegionDataStore
83 /// <list type="bullet">
84 /// <item>Initialises RegionData Interface</item>
85 /// <item>Loads and initialises a new SQLite connection and maintains it.</item>
86 /// </list>
87 /// </summary>
88 /// <param name="connectionString">the connection string</param>
89 public void Initialise(string connectionString)
90 {
91 try
92 {
93 m_connectionString = connectionString;
94
95 ds = new DataSet("Region");
96
97 m_log.Info("[SQLITE REGION DB]: Sqlite - connecting: " + connectionString);
98 m_conn = new SqliteConnection(m_connectionString);
99 m_conn.Open();
100
101 SqliteCommand primSelectCmd = new SqliteCommand(primSelect, m_conn);
102 primDa = new SqliteDataAdapter(primSelectCmd);
103
104 SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, m_conn);
105 shapeDa = new SqliteDataAdapter(shapeSelectCmd);
106 // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa);
107
108 SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, m_conn);
109 itemsDa = new SqliteDataAdapter(itemsSelectCmd);
110
111 SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, m_conn);
112 terrainDa = new SqliteDataAdapter(terrainSelectCmd);
113
114 SqliteCommand landSelectCmd = new SqliteCommand(landSelect, m_conn);
115 landDa = new SqliteDataAdapter(landSelectCmd);
116
117 SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn);
118 landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd);
119
120 SqliteCommand regionSettingsSelectCmd = new SqliteCommand(regionSettingsSelect, m_conn);
121 regionSettingsDa = new SqliteDataAdapter(regionSettingsSelectCmd);
122 // This actually does the roll forward assembly stuff
123 Assembly assem = GetType().Assembly;
124 Migration m = new Migration(m_conn, assem, "RegionStore");
125 m.Update();
126
127 lock (ds)
128 {
129 ds.Tables.Add(createPrimTable());
130 setupPrimCommands(primDa, m_conn);
131
132 ds.Tables.Add(createShapeTable());
133 setupShapeCommands(shapeDa, m_conn);
134
135 ds.Tables.Add(createItemsTable());
136 setupItemsCommands(itemsDa, m_conn);
137
138 ds.Tables.Add(createTerrainTable());
139 setupTerrainCommands(terrainDa, m_conn);
140
141 ds.Tables.Add(createLandTable());
142 setupLandCommands(landDa, m_conn);
143
144 ds.Tables.Add(createLandAccessListTable());
145 setupLandAccessCommands(landAccessListDa, m_conn);
146
147 ds.Tables.Add(createRegionSettingsTable());
148 setupRegionSettingsCommands(regionSettingsDa, m_conn);
149
150 // WORKAROUND: This is a work around for sqlite on
151 // windows, which gets really unhappy with blob columns
152 // that have no sample data in them. At some point we
153 // need to actually find a proper way to handle this.
154 try
155 {
156 primDa.Fill(ds.Tables["prims"]);
157 }
158 catch (Exception)
159 {
160 m_log.Info("[SQLITE REGION DB]: Caught fill error on prims table");
161 }
162
163 try
164 {
165 shapeDa.Fill(ds.Tables["primshapes"]);
166 }
167 catch (Exception)
168 {
169 m_log.Info("[SQLITE REGION DB]: Caught fill error on primshapes table");
170 }
171
172 try
173 {
174 itemsDa.Fill(ds.Tables["primitems"]);
175 }
176 catch (Exception)
177 {
178 m_log.Info("[SQLITE REGION DB]: Caught fill error on primitems table");
179 }
180
181 try
182 {
183 terrainDa.Fill(ds.Tables["terrain"]);
184 }
185 catch (Exception)
186 {
187 m_log.Info("[SQLITE REGION DB]: Caught fill error on terrain table");
188 }
189
190 try
191 {
192 landDa.Fill(ds.Tables["land"]);
193 }
194 catch (Exception)
195 {
196 m_log.Info("[SQLITE REGION DB]: Caught fill error on land table");
197 }
198
199 try
200 {
201 landAccessListDa.Fill(ds.Tables["landaccesslist"]);
202 }
203 catch (Exception)
204 {
205 m_log.Info("[SQLITE REGION DB]: Caught fill error on landaccesslist table");
206 }
207
208 try
209 {
210 regionSettingsDa.Fill(ds.Tables["regionsettings"]);
211 }
212 catch (Exception)
213 {
214 m_log.Info("[SQLITE REGION DB]: Caught fill error on regionsettings table");
215 }
216
217 // We have to create a data set mapping for every table, otherwise the IDataAdaptor.Update() will not populate rows with values!
218 // Not sure exactly why this is - this kind of thing was not necessary before - justincc 20100409
219 // Possibly because we manually set up our own DataTables before connecting to the database
220 CreateDataSetMapping(primDa, "prims");
221 CreateDataSetMapping(shapeDa, "primshapes");
222 CreateDataSetMapping(itemsDa, "primitems");
223 CreateDataSetMapping(terrainDa, "terrain");
224 CreateDataSetMapping(landDa, "land");
225 CreateDataSetMapping(landAccessListDa, "landaccesslist");
226 CreateDataSetMapping(regionSettingsDa, "regionsettings");
227 }
228 }
229 catch (Exception e)
230 {
231 m_log.Error(e);
232 Environment.Exit(23);
233 }
234
235 return;
236 }
237
238 public void Dispose()
239 {
240 if (m_conn != null)
241 {
242 m_conn.Close();
243 m_conn = null;
244 }
245 if (ds != null)
246 {
247 ds.Dispose();
248 ds = null;
249 }
250 if (primDa != null)
251 {
252 primDa.Dispose();
253 primDa = null;
254 }
255 if (shapeDa != null)
256 {
257 shapeDa.Dispose();
258 shapeDa = null;
259 }
260 if (itemsDa != null)
261 {
262 itemsDa.Dispose();
263 itemsDa = null;
264 }
265 if (terrainDa != null)
266 {
267 terrainDa.Dispose();
268 terrainDa = null;
269 }
270 if (landDa != null)
271 {
272 landDa.Dispose();
273 landDa = null;
274 }
275 if (landAccessListDa != null)
276 {
277 landAccessListDa.Dispose();
278 landAccessListDa = null;
279 }
280 if (regionSettingsDa != null)
281 {
282 regionSettingsDa.Dispose();
283 regionSettingsDa = null;
284 }
285 }
286
287 public void StoreRegionSettings(RegionSettings rs)
288 {
289 lock (ds)
290 {
291 DataTable regionsettings = ds.Tables["regionsettings"];
292
293 DataRow settingsRow = regionsettings.Rows.Find(rs.RegionUUID.ToString());
294 if (settingsRow == null)
295 {
296 settingsRow = regionsettings.NewRow();
297 fillRegionSettingsRow(settingsRow, rs);
298 regionsettings.Rows.Add(settingsRow);
299 }
300 else
301 {
302 fillRegionSettingsRow(settingsRow, rs);
303 }
304
305 Commit();
306 }
307 }
308 public RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID)
309 {
310 //This connector doesn't support the windlight module yet
311 //Return default LL windlight settings
312 return new RegionLightShareData();
313 }
314 public void StoreRegionWindlightSettings(RegionLightShareData wl)
315 {
316 //This connector doesn't support the windlight module yet
317 }
318 public RegionSettings LoadRegionSettings(UUID regionUUID)
319 {
320 lock (ds)
321 {
322 DataTable regionsettings = ds.Tables["regionsettings"];
323
324 string searchExp = "regionUUID = '" + regionUUID.ToString() + "'";
325 DataRow[] rawsettings = regionsettings.Select(searchExp);
326 if (rawsettings.Length == 0)
327 {
328 RegionSettings rs = new RegionSettings();
329 rs.RegionUUID = regionUUID;
330 rs.OnSave += StoreRegionSettings;
331
332 StoreRegionSettings(rs);
333
334 return rs;
335 }
336 DataRow row = rawsettings[0];
337
338 RegionSettings newSettings = buildRegionSettings(row);
339 newSettings.OnSave += StoreRegionSettings;
340
341 return newSettings;
342 }
343 }
344
345 /// <summary>
346 /// Adds an object into region storage
347 /// </summary>
348 /// <param name="obj">the object</param>
349 /// <param name="regionUUID">the region UUID</param>
350 public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
351 {
352 uint flags = obj.RootPart.GetEffectiveObjectFlags();
353
354 // Eligibility check
355 //
356 if ((flags & (uint)PrimFlags.Temporary) != 0)
357 return;
358 if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
359 return;
360
361 lock (ds)
362 {
363 foreach (SceneObjectPart prim in obj.Children.Values)
364 {
365// m_log.Info("[REGION DB]: Adding obj: " + obj.UUID + " to region: " + regionUUID);
366 addPrim(prim, obj.UUID, regionUUID);
367 }
368 }
369
370 Commit();
371 // m_log.Info("[Dump of prims]: " + ds.GetXml());
372 }
373
374 /// <summary>
375 /// Removes an object from region storage
376 /// </summary>
377 /// <param name="obj">the object</param>
378 /// <param name="regionUUID">the region UUID</param>
379 public void RemoveObject(UUID obj, UUID regionUUID)
380 {
381 // m_log.InfoFormat("[REGION DB]: Removing obj: {0} from region: {1}", obj.Guid, regionUUID);
382
383 DataTable prims = ds.Tables["prims"];
384 DataTable shapes = ds.Tables["primshapes"];
385
386 string selectExp = "SceneGroupID = '" + obj + "' and RegionUUID = '" + regionUUID + "'";
387 lock (ds)
388 {
389 DataRow[] primRows = prims.Select(selectExp);
390 foreach (DataRow row in primRows)
391 {
392 // Remove shape rows
393 UUID uuid = new UUID((string) row["UUID"]);
394 DataRow shapeRow = shapes.Rows.Find(uuid.ToString());
395 if (shapeRow != null)
396 {
397 shapeRow.Delete();
398 }
399
400 RemoveItems(uuid);
401
402 // Remove prim row
403 row.Delete();
404 }
405 }
406
407 Commit();
408 }
409
410 /// <summary>
411 /// Remove all persisted items of the given prim.
412 /// The caller must acquire the necessrary synchronization locks and commit or rollback changes.
413 /// </summary>
414 /// <param name="uuid">The item UUID</param>
415 private void RemoveItems(UUID uuid)
416 {
417 DataTable items = ds.Tables["primitems"];
418
419 String sql = String.Format("primID = '{0}'", uuid);
420 DataRow[] itemRows = items.Select(sql);
421
422 foreach (DataRow itemRow in itemRows)
423 {
424 itemRow.Delete();
425 }
426 }
427
428 /// <summary>
429 /// Load persisted objects from region storage.
430 /// </summary>
431 /// <param name="regionUUID">The region UUID</param>
432 /// <returns>List of loaded groups</returns>
433 public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
434 {
435 Dictionary<UUID, SceneObjectGroup> createdObjects = new Dictionary<UUID, SceneObjectGroup>();
436
437 List<SceneObjectGroup> retvals = new List<SceneObjectGroup>();
438
439 DataTable prims = ds.Tables["prims"];
440 DataTable shapes = ds.Tables["primshapes"];
441
442 string byRegion = "RegionUUID = '" + regionUUID + "'";
443
444 lock (ds)
445 {
446 DataRow[] primsForRegion = prims.Select(byRegion);
447// m_log.Info("[SQLITE REGION DB]: Loaded " + primsForRegion.Length + " prims for region: " + regionUUID);
448
449 // First, create all groups
450 foreach (DataRow primRow in primsForRegion)
451 {
452 try
453 {
454 SceneObjectPart prim = null;
455
456 string uuid = (string) primRow["UUID"];
457 string objID = (string) primRow["SceneGroupID"];
458
459 if (uuid == objID) //is new SceneObjectGroup ?
460 {
461 prim = buildPrim(primRow);
462 DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
463 if (shapeRow != null)
464 {
465 prim.Shape = buildShape(shapeRow);
466 }
467 else
468 {
469 m_log.Warn(
470 "[SQLITE REGION DB]: No shape found for prim in storage, so setting default box shape");
471 prim.Shape = PrimitiveBaseShape.Default;
472 }
473
474 SceneObjectGroup group = new SceneObjectGroup(prim);
475 createdObjects.Add(group.UUID, group);
476 retvals.Add(group);
477 LoadItems(prim);
478 }
479 }
480 catch (Exception e)
481 {
482 m_log.Error("[SQLITE REGION DB]: Failed create prim object in new group, exception and data follows");
483 m_log.Error("[SQLITE REGION DB]: ", e);
484 foreach (DataColumn col in prims.Columns)
485 {
486 m_log.Error("[SQLITE REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]);
487 }
488 }
489 }
490
491 // Now fill the groups with part data
492 foreach (DataRow primRow in primsForRegion)
493 {
494 try
495 {
496 SceneObjectPart prim = null;
497
498 string uuid = (string) primRow["UUID"];
499 string objID = (string) primRow["SceneGroupID"];
500 if (uuid != objID) //is new SceneObjectGroup ?
501 {
502 prim = buildPrim(primRow);
503 DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
504 if (shapeRow != null)
505 {
506 prim.Shape = buildShape(shapeRow);
507 }
508 else
509 {
510 m_log.Warn(
511 "[SQLITE REGION DB]: No shape found for prim in storage, so setting default box shape");
512 prim.Shape = PrimitiveBaseShape.Default;
513 }
514
515 createdObjects[new UUID(objID)].AddPart(prim);
516 LoadItems(prim);
517 }
518 }
519 catch (Exception e)
520 {
521 m_log.Error("[SQLITE REGION DB]: Failed create prim object in group, exception and data follows");
522 m_log.Error("[SQLITE REGION DB]: ", e);
523 foreach (DataColumn col in prims.Columns)
524 {
525 m_log.Error("[SQLITE REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]);
526 }
527 }
528 }
529 }
530 return retvals;
531 }
532
533 /// <summary>
534 /// Load in a prim's persisted inventory.
535 /// </summary>
536 /// <param name="prim">the prim</param>
537 private void LoadItems(SceneObjectPart prim)
538 {
539// m_log.DebugFormat("[SQLITE REGION DB]: Loading inventory for {0} {1}", prim.Name, prim.UUID);
540
541 DataTable dbItems = ds.Tables["primitems"];
542 String sql = String.Format("primID = '{0}'", prim.UUID.ToString());
543 DataRow[] dbItemRows = dbItems.Select(sql);
544 IList<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
545
546// m_log.DebugFormat(
547// "[SQLITE REGION DB]: Found {0} items for {1} {2}", dbItemRows.Length, prim.Name, prim.UUID);
548
549 foreach (DataRow row in dbItemRows)
550 {
551 TaskInventoryItem item = buildItem(row);
552 inventory.Add(item);
553
554// m_log.DebugFormat("[SQLITE REGION DB]: Restored item {0} {1}", item.Name, item.ItemID);
555 }
556
557 prim.Inventory.RestoreInventoryItems(inventory);
558 }
559
560 /// <summary>
561 /// Store a terrain revision in region storage
562 /// </summary>
563 /// <param name="ter">terrain heightfield</param>
564 /// <param name="regionID">region UUID</param>
565 public void StoreTerrain(double[,] ter, UUID regionID)
566 {
567 lock (ds)
568 {
569 int revision = Util.UnixTimeSinceEpoch();
570
571 // This is added to get rid of the infinitely growing
572 // terrain databases which negatively impact on SQLite
573 // over time. Before reenabling this feature there
574 // needs to be a limitter put on the number of
575 // revisions in the database, as this old
576 // implementation is a DOS attack waiting to happen.
577
578 using (
579 SqliteCommand cmd =
580 new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID and Revision <= :Revision",
581 m_conn))
582 {
583 cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
584 cmd.Parameters.Add(new SqliteParameter(":Revision", revision));
585 cmd.ExecuteNonQuery();
586 }
587
588 // the following is an work around for .NET. The perf
589 // issues associated with it aren't as bad as you think.
590 m_log.Debug("[SQLITE REGION DB]: Storing terrain revision r" + revision.ToString());
591 String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" +
592 " values(:RegionUUID, :Revision, :Heightfield)";
593
594 using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
595 {
596 cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
597 cmd.Parameters.Add(new SqliteParameter(":Revision", revision));
598 cmd.Parameters.Add(new SqliteParameter(":Heightfield", serializeTerrain(ter)));
599 cmd.ExecuteNonQuery();
600 }
601 }
602 }
603
604 /// <summary>
605 /// Load the latest terrain revision from region storage
606 /// </summary>
607 /// <param name="regionID">the region UUID</param>
608 /// <returns>Heightfield data</returns>
609 public double[,] LoadTerrain(UUID regionID)
610 {
611 lock (ds)
612 {
613 double[,] terret = new double[(int)Constants.RegionSize, (int)Constants.RegionSize];
614 terret.Initialize();
615
616 String sql = "select RegionUUID, Revision, Heightfield from terrain" +
617 " where RegionUUID=:RegionUUID order by Revision desc";
618
619 using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
620 {
621 cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
622
623 using (IDataReader row = cmd.ExecuteReader())
624 {
625 int rev = 0;
626 if (row.Read())
627 {
628 // TODO: put this into a function
629 using (MemoryStream str = new MemoryStream((byte[])row["Heightfield"]))
630 {
631 using (BinaryReader br = new BinaryReader(str))
632 {
633 for (int x = 0; x < (int)Constants.RegionSize; x++)
634 {
635 for (int y = 0; y < (int)Constants.RegionSize; y++)
636 {
637 terret[x, y] = br.ReadDouble();
638 }
639 }
640 }
641 }
642 rev = Convert.ToInt32(row["Revision"]);
643 }
644 else
645 {
646 m_log.Warn("[SQLITE REGION DB]: No terrain found for region");
647 return null;
648 }
649
650 m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString());
651 }
652 }
653 return terret;
654 }
655 }
656
657 /// <summary>
658 ///
659 /// </summary>
660 /// <param name="globalID"></param>
661 public void RemoveLandObject(UUID globalID)
662 {
663 lock (ds)
664 {
665 // Can't use blanket SQL statements when using SqlAdapters unless you re-read the data into the adapter
666 // after you're done.
667 // replaced below code with the SqliteAdapter version.
668 //using (SqliteCommand cmd = new SqliteCommand("delete from land where UUID=:UUID", m_conn))
669 //{
670 // cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString()));
671 // cmd.ExecuteNonQuery();
672 //}
673
674 //using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:UUID", m_conn))
675 //{
676 // cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString()));
677 // cmd.ExecuteNonQuery();
678 //}
679
680 DataTable land = ds.Tables["land"];
681 DataTable landaccesslist = ds.Tables["landaccesslist"];
682 DataRow landRow = land.Rows.Find(globalID.ToString());
683 if (landRow != null)
684 {
685 land.Rows.Remove(landRow);
686 }
687 List<DataRow> rowsToDelete = new List<DataRow>();
688 foreach (DataRow rowToCheck in landaccesslist.Rows)
689 {
690 if (rowToCheck["LandUUID"].ToString() == globalID.ToString())
691 rowsToDelete.Add(rowToCheck);
692 }
693 for (int iter = 0; iter < rowsToDelete.Count; iter++)
694 {
695 landaccesslist.Rows.Remove(rowsToDelete[iter]);
696 }
697
698
699 }
700 Commit();
701 }
702
703 /// <summary>
704 ///
705 /// </summary>
706 /// <param name="parcel"></param>
707 public void StoreLandObject(ILandObject parcel)
708 {
709 lock (ds)
710 {
711 DataTable land = ds.Tables["land"];
712 DataTable landaccesslist = ds.Tables["landaccesslist"];
713
714 DataRow landRow = land.Rows.Find(parcel.LandData.GlobalID.ToString());
715 if (landRow == null)
716 {
717 landRow = land.NewRow();
718 fillLandRow(landRow, parcel.LandData, parcel.RegionUUID);
719 land.Rows.Add(landRow);
720 }
721 else
722 {
723 fillLandRow(landRow, parcel.LandData, parcel.RegionUUID);
724 }
725
726 // I know this caused someone issues before, but OpenSim is unusable if we leave this stuff around
727 //using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:LandUUID", m_conn))
728 //{
729 // cmd.Parameters.Add(new SqliteParameter(":LandUUID", parcel.LandData.GlobalID.ToString()));
730 // cmd.ExecuteNonQuery();
731
732// }
733
734 // This is the slower.. but more appropriate thing to do
735
736 // We can't modify the table with direct queries before calling Commit() and re-filling them.
737 List<DataRow> rowsToDelete = new List<DataRow>();
738 foreach (DataRow rowToCheck in landaccesslist.Rows)
739 {
740 if (rowToCheck["LandUUID"].ToString() == parcel.LandData.GlobalID.ToString())
741 rowsToDelete.Add(rowToCheck);
742 }
743 for (int iter = 0; iter < rowsToDelete.Count; iter++)
744 {
745 landaccesslist.Rows.Remove(rowsToDelete[iter]);
746 }
747 rowsToDelete.Clear();
748 foreach (ParcelManager.ParcelAccessEntry entry in parcel.LandData.ParcelAccessList)
749 {
750 DataRow newAccessRow = landaccesslist.NewRow();
751 fillLandAccessRow(newAccessRow, entry, parcel.LandData.GlobalID);
752 landaccesslist.Rows.Add(newAccessRow);
753 }
754 }
755
756 Commit();
757 }
758
759 /// <summary>
760 ///
761 /// </summary>
762 /// <param name="regionUUID"></param>
763 /// <returns></returns>
764 public List<LandData> LoadLandObjects(UUID regionUUID)
765 {
766 List<LandData> landDataForRegion = new List<LandData>();
767 lock (ds)
768 {
769 DataTable land = ds.Tables["land"];
770 DataTable landaccesslist = ds.Tables["landaccesslist"];
771 string searchExp = "RegionUUID = '" + regionUUID + "'";
772 DataRow[] rawDataForRegion = land.Select(searchExp);
773 foreach (DataRow rawDataLand in rawDataForRegion)
774 {
775 LandData newLand = buildLandData(rawDataLand);
776 string accessListSearchExp = "LandUUID = '" + newLand.GlobalID + "'";
777 DataRow[] rawDataForLandAccessList = landaccesslist.Select(accessListSearchExp);
778 foreach (DataRow rawDataLandAccess in rawDataForLandAccessList)
779 {
780 newLand.ParcelAccessList.Add(buildLandAccessData(rawDataLandAccess));
781 }
782
783 landDataForRegion.Add(newLand);
784 }
785 }
786 return landDataForRegion;
787 }
788
789 /// <summary>
790 ///
791 /// </summary>
792 public void Commit()
793 {
794 //m_log.Debug("[SQLITE]: Starting commit");
795 lock (ds)
796 {
797 primDa.Update(ds, "prims");
798 shapeDa.Update(ds, "primshapes");
799
800 itemsDa.Update(ds, "primitems");
801
802 terrainDa.Update(ds, "terrain");
803 landDa.Update(ds, "land");
804 landAccessListDa.Update(ds, "landaccesslist");
805 try
806 {
807 regionSettingsDa.Update(ds, "regionsettings");
808 }
809 catch (SqliteException SqlEx)
810 {
811 throw new Exception(
812 "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!",
813 SqlEx);
814 }
815 ds.AcceptChanges();
816 }
817 }
818
819 /// <summary>
820 /// See <see cref="Commit"/>
821 /// </summary>
822 public void Shutdown()
823 {
824 Commit();
825 }
826
827 /***********************************************************************
828 *
829 * Database Definition Functions
830 *
831 * This should be db agnostic as we define them in ADO.NET terms
832 *
833 **********************************************************************/
834
835 protected void CreateDataSetMapping(IDataAdapter da, string tableName)
836 {
837 ITableMapping dbMapping = da.TableMappings.Add(tableName, tableName);
838 foreach (DataColumn col in ds.Tables[tableName].Columns)
839 {
840 dbMapping.ColumnMappings.Add(col.ColumnName, col.ColumnName);
841 }
842 }
843
844 /// <summary>
845 ///
846 /// </summary>
847 /// <param name="dt"></param>
848 /// <param name="name"></param>
849 /// <param name="type"></param>
850 private static void createCol(DataTable dt, string name, Type type)
851 {
852 DataColumn col = new DataColumn(name, type);
853 dt.Columns.Add(col);
854 }
855
856 /// <summary>
857 /// Creates the "terrain" table
858 /// </summary>
859 /// <returns>terrain table DataTable</returns>
860 private static DataTable createTerrainTable()
861 {
862 DataTable terrain = new DataTable("terrain");
863
864 createCol(terrain, "RegionUUID", typeof (String));
865 createCol(terrain, "Revision", typeof (Int32));
866 createCol(terrain, "Heightfield", typeof (Byte[]));
867
868 return terrain;
869 }
870
871 /// <summary>
872 /// Creates the "prims" table
873 /// </summary>
874 /// <returns>prim table DataTable</returns>
875 private static DataTable createPrimTable()
876 {
877 DataTable prims = new DataTable("prims");
878
879 createCol(prims, "UUID", typeof (String));
880 createCol(prims, "RegionUUID", typeof (String));
881 createCol(prims, "CreationDate", typeof (Int32));
882 createCol(prims, "Name", typeof (String));
883 createCol(prims, "SceneGroupID", typeof (String));
884 // various text fields
885 createCol(prims, "Text", typeof (String));
886 createCol(prims, "ColorR", typeof (Int32));
887 createCol(prims, "ColorG", typeof (Int32));
888 createCol(prims, "ColorB", typeof (Int32));
889 createCol(prims, "ColorA", typeof (Int32));
890 createCol(prims, "Description", typeof (String));
891 createCol(prims, "SitName", typeof (String));
892 createCol(prims, "TouchName", typeof (String));
893 // permissions
894 createCol(prims, "ObjectFlags", typeof (Int32));
895 createCol(prims, "CreatorID", typeof (String));
896 createCol(prims, "OwnerID", typeof (String));
897 createCol(prims, "GroupID", typeof (String));
898 createCol(prims, "LastOwnerID", typeof (String));
899 createCol(prims, "OwnerMask", typeof (Int32));
900 createCol(prims, "NextOwnerMask", typeof (Int32));
901 createCol(prims, "GroupMask", typeof (Int32));
902 createCol(prims, "EveryoneMask", typeof (Int32));
903 createCol(prims, "BaseMask", typeof (Int32));
904 // vectors
905 createCol(prims, "PositionX", typeof (Double));
906 createCol(prims, "PositionY", typeof (Double));
907 createCol(prims, "PositionZ", typeof (Double));
908 createCol(prims, "GroupPositionX", typeof (Double));
909 createCol(prims, "GroupPositionY", typeof (Double));
910 createCol(prims, "GroupPositionZ", typeof (Double));
911 createCol(prims, "VelocityX", typeof (Double));
912 createCol(prims, "VelocityY", typeof (Double));
913 createCol(prims, "VelocityZ", typeof (Double));
914 createCol(prims, "AngularVelocityX", typeof (Double));
915 createCol(prims, "AngularVelocityY", typeof (Double));
916 createCol(prims, "AngularVelocityZ", typeof (Double));
917 createCol(prims, "AccelerationX", typeof (Double));
918 createCol(prims, "AccelerationY", typeof (Double));
919 createCol(prims, "AccelerationZ", typeof (Double));
920 // quaternions
921 createCol(prims, "RotationX", typeof (Double));
922 createCol(prims, "RotationY", typeof (Double));
923 createCol(prims, "RotationZ", typeof (Double));
924 createCol(prims, "RotationW", typeof (Double));
925
926 // sit target
927 createCol(prims, "SitTargetOffsetX", typeof (Double));
928 createCol(prims, "SitTargetOffsetY", typeof (Double));
929 createCol(prims, "SitTargetOffsetZ", typeof (Double));
930
931 createCol(prims, "SitTargetOrientW", typeof (Double));
932 createCol(prims, "SitTargetOrientX", typeof (Double));
933 createCol(prims, "SitTargetOrientY", typeof (Double));
934 createCol(prims, "SitTargetOrientZ", typeof (Double));
935
936 createCol(prims, "PayPrice", typeof(Int32));
937 createCol(prims, "PayButton1", typeof(Int32));
938 createCol(prims, "PayButton2", typeof(Int32));
939 createCol(prims, "PayButton3", typeof(Int32));
940 createCol(prims, "PayButton4", typeof(Int32));
941
942 createCol(prims, "LoopedSound", typeof(String));
943 createCol(prims, "LoopedSoundGain", typeof(Double));
944 createCol(prims, "TextureAnimation", typeof(String));
945 createCol(prims, "ParticleSystem", typeof(String));
946
947 createCol(prims, "OmegaX", typeof(Double));
948 createCol(prims, "OmegaY", typeof(Double));
949 createCol(prims, "OmegaZ", typeof(Double));
950
951 createCol(prims, "CameraEyeOffsetX", typeof(Double));
952 createCol(prims, "CameraEyeOffsetY", typeof(Double));
953 createCol(prims, "CameraEyeOffsetZ", typeof(Double));
954
955 createCol(prims, "CameraAtOffsetX", typeof(Double));
956 createCol(prims, "CameraAtOffsetY", typeof(Double));
957 createCol(prims, "CameraAtOffsetZ", typeof(Double));
958
959 createCol(prims, "ForceMouselook", typeof(Int16));
960
961 createCol(prims, "ScriptAccessPin", typeof(Int32));
962
963 createCol(prims, "AllowedDrop", typeof(Int16));
964 createCol(prims, "DieAtEdge", typeof(Int16));
965
966 createCol(prims, "SalePrice", typeof(Int32));
967 createCol(prims, "SaleType", typeof(Int16));
968
969 // click action
970 createCol(prims, "ClickAction", typeof (Byte));
971
972 createCol(prims, "Material", typeof(Byte));
973
974 createCol(prims, "CollisionSound", typeof(String));
975 createCol(prims, "CollisionSoundVolume", typeof(Double));
976
977 createCol(prims, "VolumeDetect", typeof(Int16));
978
979 createCol(prims, "MediaURL", typeof(String));
980
981 // Add in contraints
982 prims.PrimaryKey = new DataColumn[] {prims.Columns["UUID"]};
983
984 return prims;
985 }
986
987 /// <summary>
988 /// Creates "primshapes" table
989 /// </summary>
990 /// <returns>shape table DataTable</returns>
991 private static DataTable createShapeTable()
992 {
993 DataTable shapes = new DataTable("primshapes");
994 createCol(shapes, "UUID", typeof (String));
995 // shape is an enum
996 createCol(shapes, "Shape", typeof (Int32));
997 // vectors
998 createCol(shapes, "ScaleX", typeof (Double));
999 createCol(shapes, "ScaleY", typeof (Double));
1000 createCol(shapes, "ScaleZ", typeof (Double));
1001 // paths
1002 createCol(shapes, "PCode", typeof (Int32));
1003 createCol(shapes, "PathBegin", typeof (Int32));
1004 createCol(shapes, "PathEnd", typeof (Int32));
1005 createCol(shapes, "PathScaleX", typeof (Int32));
1006 createCol(shapes, "PathScaleY", typeof (Int32));
1007 createCol(shapes, "PathShearX", typeof (Int32));
1008 createCol(shapes, "PathShearY", typeof (Int32));
1009 createCol(shapes, "PathSkew", typeof (Int32));
1010 createCol(shapes, "PathCurve", typeof (Int32));
1011 createCol(shapes, "PathRadiusOffset", typeof (Int32));
1012 createCol(shapes, "PathRevolutions", typeof (Int32));
1013 createCol(shapes, "PathTaperX", typeof (Int32));
1014 createCol(shapes, "PathTaperY", typeof (Int32));
1015 createCol(shapes, "PathTwist", typeof (Int32));
1016 createCol(shapes, "PathTwistBegin", typeof (Int32));
1017 // profile
1018 createCol(shapes, "ProfileBegin", typeof (Int32));
1019 createCol(shapes, "ProfileEnd", typeof (Int32));
1020 createCol(shapes, "ProfileCurve", typeof (Int32));
1021 createCol(shapes, "ProfileHollow", typeof (Int32));
1022 createCol(shapes, "State", typeof(Int32));
1023 // text TODO: this isn't right, but I'm not sure the right
1024 // way to specify this as a blob atm
1025 createCol(shapes, "Texture", typeof (Byte[]));
1026 createCol(shapes, "ExtraParams", typeof (Byte[]));
1027 createCol(shapes, "Media", typeof(String));
1028
1029 shapes.PrimaryKey = new DataColumn[] {shapes.Columns["UUID"]};
1030
1031 return shapes;
1032 }
1033
1034 /// <summary>
1035 /// creates "primitems" table
1036 /// </summary>
1037 /// <returns>item table DataTable</returns>
1038 private static DataTable createItemsTable()
1039 {
1040 DataTable items = new DataTable("primitems");
1041
1042 createCol(items, "itemID", typeof (String));
1043 createCol(items, "primID", typeof (String));
1044 createCol(items, "assetID", typeof (String));
1045 createCol(items, "parentFolderID", typeof (String));
1046
1047 createCol(items, "invType", typeof (Int32));
1048 createCol(items, "assetType", typeof (Int32));
1049
1050 createCol(items, "name", typeof (String));
1051 createCol(items, "description", typeof (String));
1052
1053 createCol(items, "creationDate", typeof (Int64));
1054 createCol(items, "creatorID", typeof (String));
1055 createCol(items, "ownerID", typeof (String));
1056 createCol(items, "lastOwnerID", typeof (String));
1057 createCol(items, "groupID", typeof (String));
1058
1059 createCol(items, "nextPermissions", typeof (UInt32));
1060 createCol(items, "currentPermissions", typeof (UInt32));
1061 createCol(items, "basePermissions", typeof (UInt32));
1062 createCol(items, "everyonePermissions", typeof (UInt32));
1063 createCol(items, "groupPermissions", typeof (UInt32));
1064 createCol(items, "flags", typeof (UInt32));
1065
1066 items.PrimaryKey = new DataColumn[] { items.Columns["itemID"] };
1067
1068 return items;
1069 }
1070
1071 /// <summary>
1072 /// Creates "land" table
1073 /// </summary>
1074 /// <returns>land table DataTable</returns>
1075 private static DataTable createLandTable()
1076 {
1077 DataTable land = new DataTable("land");
1078 createCol(land, "UUID", typeof (String));
1079 createCol(land, "RegionUUID", typeof (String));
1080 createCol(land, "LocalLandID", typeof (UInt32));
1081
1082 // Bitmap is a byte[512]
1083 createCol(land, "Bitmap", typeof (Byte[]));
1084
1085 createCol(land, "Name", typeof (String));
1086 createCol(land, "Desc", typeof (String));
1087 createCol(land, "OwnerUUID", typeof (String));
1088 createCol(land, "IsGroupOwned", typeof (Boolean));
1089 createCol(land, "Area", typeof (Int32));
1090 createCol(land, "AuctionID", typeof (Int32)); //Unemplemented
1091 createCol(land, "Category", typeof (Int32)); //Enum OpenMetaverse.Parcel.ParcelCategory
1092 createCol(land, "ClaimDate", typeof (Int32));
1093 createCol(land, "ClaimPrice", typeof (Int32));
1094 createCol(land, "GroupUUID", typeof (string));
1095 createCol(land, "SalePrice", typeof (Int32));
1096 createCol(land, "LandStatus", typeof (Int32)); //Enum. OpenMetaverse.Parcel.ParcelStatus
1097 createCol(land, "LandFlags", typeof (UInt32));
1098 createCol(land, "LandingType", typeof (Byte));
1099 createCol(land, "MediaAutoScale", typeof (Byte));
1100 createCol(land, "MediaTextureUUID", typeof (String));
1101 createCol(land, "MediaURL", typeof (String));
1102 createCol(land, "MusicURL", typeof (String));
1103 createCol(land, "PassHours", typeof (Double));
1104 createCol(land, "PassPrice", typeof (UInt32));
1105 createCol(land, "SnapshotUUID", typeof (String));
1106 createCol(land, "UserLocationX", typeof (Double));
1107 createCol(land, "UserLocationY", typeof (Double));
1108 createCol(land, "UserLocationZ", typeof (Double));
1109 createCol(land, "UserLookAtX", typeof (Double));
1110 createCol(land, "UserLookAtY", typeof (Double));
1111 createCol(land, "UserLookAtZ", typeof (Double));
1112 createCol(land, "AuthbuyerID", typeof(String));
1113 createCol(land, "OtherCleanTime", typeof(Int32));
1114
1115 land.PrimaryKey = new DataColumn[] {land.Columns["UUID"]};
1116
1117 return land;
1118 }
1119
1120 /// <summary>
1121 /// create "landaccesslist" table
1122 /// </summary>
1123 /// <returns>Landacceslist DataTable</returns>
1124 private static DataTable createLandAccessListTable()
1125 {
1126 DataTable landaccess = new DataTable("landaccesslist");
1127 createCol(landaccess, "LandUUID", typeof (String));
1128 createCol(landaccess, "AccessUUID", typeof (String));
1129 createCol(landaccess, "Flags", typeof (UInt32));
1130
1131 return landaccess;
1132 }
1133
1134 private static DataTable createRegionSettingsTable()
1135 {
1136 DataTable regionsettings = new DataTable("regionsettings");
1137 createCol(regionsettings, "regionUUID", typeof(String));
1138 createCol(regionsettings, "block_terraform", typeof (Int32));
1139 createCol(regionsettings, "block_fly", typeof (Int32));
1140 createCol(regionsettings, "allow_damage", typeof (Int32));
1141 createCol(regionsettings, "restrict_pushing", typeof (Int32));
1142 createCol(regionsettings, "allow_land_resell", typeof (Int32));
1143 createCol(regionsettings, "allow_land_join_divide", typeof (Int32));
1144 createCol(regionsettings, "block_show_in_search", typeof (Int32));
1145 createCol(regionsettings, "agent_limit", typeof (Int32));
1146 createCol(regionsettings, "object_bonus", typeof (Double));
1147 createCol(regionsettings, "maturity", typeof (Int32));
1148 createCol(regionsettings, "disable_scripts", typeof (Int32));
1149 createCol(regionsettings, "disable_collisions", typeof (Int32));
1150 createCol(regionsettings, "disable_physics", typeof (Int32));
1151 createCol(regionsettings, "terrain_texture_1", typeof(String));
1152 createCol(regionsettings, "terrain_texture_2", typeof(String));
1153 createCol(regionsettings, "terrain_texture_3", typeof(String));
1154 createCol(regionsettings, "terrain_texture_4", typeof(String));
1155 createCol(regionsettings, "elevation_1_nw", typeof (Double));
1156 createCol(regionsettings, "elevation_2_nw", typeof (Double));
1157 createCol(regionsettings, "elevation_1_ne", typeof (Double));
1158 createCol(regionsettings, "elevation_2_ne", typeof (Double));
1159 createCol(regionsettings, "elevation_1_se", typeof (Double));
1160 createCol(regionsettings, "elevation_2_se", typeof (Double));
1161 createCol(regionsettings, "elevation_1_sw", typeof (Double));
1162 createCol(regionsettings, "elevation_2_sw", typeof (Double));
1163 createCol(regionsettings, "water_height", typeof (Double));
1164 createCol(regionsettings, "terrain_raise_limit", typeof (Double));
1165 createCol(regionsettings, "terrain_lower_limit", typeof (Double));
1166 createCol(regionsettings, "use_estate_sun", typeof (Int32));
1167 createCol(regionsettings, "sandbox", typeof (Int32));
1168 createCol(regionsettings, "sunvectorx",typeof (Double));
1169 createCol(regionsettings, "sunvectory",typeof (Double));
1170 createCol(regionsettings, "sunvectorz",typeof (Double));
1171 createCol(regionsettings, "fixed_sun", typeof (Int32));
1172 createCol(regionsettings, "sun_position", typeof (Double));
1173 createCol(regionsettings, "covenant", typeof(String));
1174 createCol(regionsettings, "map_tile_ID", typeof(String));
1175 regionsettings.PrimaryKey = new DataColumn[] { regionsettings.Columns["regionUUID"] };
1176 return regionsettings;
1177 }
1178
1179 /***********************************************************************
1180 *
1181 * Convert between ADO.NET <=> OpenSim Objects
1182 *
1183 * These should be database independant
1184 *
1185 **********************************************************************/
1186
1187 /// <summary>
1188 ///
1189 /// </summary>
1190 /// <param name="row"></param>
1191 /// <returns></returns>
1192 private SceneObjectPart buildPrim(DataRow row)
1193 {
1194 // Code commented. Uncomment to test the unit test inline.
1195
1196 // The unit test mentions this commented code for the purposes
1197 // of debugging a unit test failure
1198
1199 // SceneObjectGroup sog = new SceneObjectGroup();
1200 // SceneObjectPart sop = new SceneObjectPart();
1201 // sop.LocalId = 1;
1202 // sop.Name = "object1";
1203 // sop.Description = "object1";
1204 // sop.Text = "";
1205 // sop.SitName = "";
1206 // sop.TouchName = "";
1207 // sop.UUID = UUID.Random();
1208 // sop.Shape = PrimitiveBaseShape.Default;
1209 // sog.SetRootPart(sop);
1210 // Add breakpoint in above line. Check sop fields.
1211
1212 // TODO: this doesn't work yet because something more
1213 // interesting has to be done to actually get these values
1214 // back out. Not enough time to figure it out yet.
1215
1216 SceneObjectPart prim = new SceneObjectPart();
1217 prim.UUID = new UUID((String) row["UUID"]);
1218 // explicit conversion of integers is required, which sort
1219 // of sucks. No idea if there is a shortcut here or not.
1220 prim.CreationDate = Convert.ToInt32(row["CreationDate"]);
1221 prim.Name = row["Name"] == DBNull.Value ? string.Empty : (string)row["Name"];
1222 // various text fields
1223 prim.Text = (String) row["Text"];
1224 prim.Color = Color.FromArgb(Convert.ToInt32(row["ColorA"]),
1225 Convert.ToInt32(row["ColorR"]),
1226 Convert.ToInt32(row["ColorG"]),
1227 Convert.ToInt32(row["ColorB"]));
1228 prim.Description = (String) row["Description"];
1229 prim.SitName = (String) row["SitName"];
1230 prim.TouchName = (String) row["TouchName"];
1231 // permissions
1232 prim.ObjectFlags = Convert.ToUInt32(row["ObjectFlags"]);
1233 prim.CreatorID = new UUID((String) row["CreatorID"]);
1234 prim.OwnerID = new UUID((String) row["OwnerID"]);
1235 prim.GroupID = new UUID((String) row["GroupID"]);
1236 prim.LastOwnerID = new UUID((String) row["LastOwnerID"]);
1237 prim.OwnerMask = Convert.ToUInt32(row["OwnerMask"]);
1238 prim.NextOwnerMask = Convert.ToUInt32(row["NextOwnerMask"]);
1239 prim.GroupMask = Convert.ToUInt32(row["GroupMask"]);
1240 prim.EveryoneMask = Convert.ToUInt32(row["EveryoneMask"]);
1241 prim.BaseMask = Convert.ToUInt32(row["BaseMask"]);
1242 // vectors
1243 prim.OffsetPosition = new Vector3(
1244 Convert.ToSingle(row["PositionX"]),
1245 Convert.ToSingle(row["PositionY"]),
1246 Convert.ToSingle(row["PositionZ"])
1247 );
1248 prim.GroupPosition = new Vector3(
1249 Convert.ToSingle(row["GroupPositionX"]),
1250 Convert.ToSingle(row["GroupPositionY"]),
1251 Convert.ToSingle(row["GroupPositionZ"])
1252 );
1253 prim.Velocity = new Vector3(
1254 Convert.ToSingle(row["VelocityX"]),
1255 Convert.ToSingle(row["VelocityY"]),
1256 Convert.ToSingle(row["VelocityZ"])
1257 );
1258 prim.AngularVelocity = new Vector3(
1259 Convert.ToSingle(row["AngularVelocityX"]),
1260 Convert.ToSingle(row["AngularVelocityY"]),
1261 Convert.ToSingle(row["AngularVelocityZ"])
1262 );
1263 prim.Acceleration = new Vector3(
1264 Convert.ToSingle(row["AccelerationX"]),
1265 Convert.ToSingle(row["AccelerationY"]),
1266 Convert.ToSingle(row["AccelerationZ"])
1267 );
1268 // quaternions
1269 prim.RotationOffset = new Quaternion(
1270 Convert.ToSingle(row["RotationX"]),
1271 Convert.ToSingle(row["RotationY"]),
1272 Convert.ToSingle(row["RotationZ"]),
1273 Convert.ToSingle(row["RotationW"])
1274 );
1275
1276 prim.SitTargetPositionLL = new Vector3(
1277 Convert.ToSingle(row["SitTargetOffsetX"]),
1278 Convert.ToSingle(row["SitTargetOffsetY"]),
1279 Convert.ToSingle(row["SitTargetOffsetZ"]));
1280 prim.SitTargetOrientationLL = new Quaternion(
1281 Convert.ToSingle(
1282 row["SitTargetOrientX"]),
1283 Convert.ToSingle(
1284 row["SitTargetOrientY"]),
1285 Convert.ToSingle(
1286 row["SitTargetOrientZ"]),
1287 Convert.ToSingle(
1288 row["SitTargetOrientW"]));
1289
1290 prim.ClickAction = Convert.ToByte(row["ClickAction"]);
1291 prim.PayPrice[0] = Convert.ToInt32(row["PayPrice"]);
1292 prim.PayPrice[1] = Convert.ToInt32(row["PayButton1"]);
1293 prim.PayPrice[2] = Convert.ToInt32(row["PayButton2"]);
1294 prim.PayPrice[3] = Convert.ToInt32(row["PayButton3"]);
1295 prim.PayPrice[4] = Convert.ToInt32(row["PayButton4"]);
1296
1297 prim.Sound = new UUID(row["LoopedSound"].ToString());
1298 prim.SoundGain = Convert.ToSingle(row["LoopedSoundGain"]);
1299 prim.SoundFlags = 1; // If it's persisted at all, it's looped
1300
1301 if (!row.IsNull("TextureAnimation"))
1302 prim.TextureAnimation = Convert.FromBase64String(row["TextureAnimation"].ToString());
1303 if (!row.IsNull("ParticleSystem"))
1304 prim.ParticleSystem = Convert.FromBase64String(row["ParticleSystem"].ToString());
1305
1306 prim.AngularVelocity = new Vector3(
1307 Convert.ToSingle(row["OmegaX"]),
1308 Convert.ToSingle(row["OmegaY"]),
1309 Convert.ToSingle(row["OmegaZ"])
1310 );
1311
1312 prim.SetCameraEyeOffset(new Vector3(
1313 Convert.ToSingle(row["CameraEyeOffsetX"]),
1314 Convert.ToSingle(row["CameraEyeOffsetY"]),
1315 Convert.ToSingle(row["CameraEyeOffsetZ"])
1316 ));
1317
1318 prim.SetCameraAtOffset(new Vector3(
1319 Convert.ToSingle(row["CameraAtOffsetX"]),
1320 Convert.ToSingle(row["CameraAtOffsetY"]),
1321 Convert.ToSingle(row["CameraAtOffsetZ"])
1322 ));
1323
1324 if (Convert.ToInt16(row["ForceMouselook"]) != 0)
1325 prim.SetForceMouselook(true);
1326
1327 prim.ScriptAccessPin = Convert.ToInt32(row["ScriptAccessPin"]);
1328
1329 if (Convert.ToInt16(row["AllowedDrop"]) != 0)
1330 prim.AllowedDrop = true;
1331
1332 if (Convert.ToInt16(row["DieAtEdge"]) != 0)
1333 prim.DIE_AT_EDGE = true;
1334
1335 prim.SalePrice = Convert.ToInt32(row["SalePrice"]);
1336 prim.ObjectSaleType = Convert.ToByte(row["SaleType"]);
1337
1338 prim.Material = Convert.ToByte(row["Material"]);
1339
1340 prim.CollisionSound = new UUID(row["CollisionSound"].ToString());
1341 prim.CollisionSoundVolume = Convert.ToSingle(row["CollisionSoundVolume"]);
1342
1343 if (Convert.ToInt16(row["VolumeDetect"]) != 0)
1344 prim.VolumeDetectActive = true;
1345
1346 if (!(row["MediaURL"] is System.DBNull))
1347 {
1348 //m_log.DebugFormat("[SQLITE]: MediaUrl type [{0}]", row["MediaURL"].GetType());
1349 prim.MediaUrl = (string)row["MediaURL"];
1350 }
1351
1352 return prim;
1353 }
1354
1355 /// <summary>
1356 /// Build a prim inventory item from the persisted data.
1357 /// </summary>
1358 /// <param name="row"></param>
1359 /// <returns></returns>
1360 private static TaskInventoryItem buildItem(DataRow row)
1361 {
1362 TaskInventoryItem taskItem = new TaskInventoryItem();
1363
1364 taskItem.ItemID = new UUID((String)row["itemID"]);
1365 taskItem.ParentPartID = new UUID((String)row["primID"]);
1366 taskItem.AssetID = new UUID((String)row["assetID"]);
1367 taskItem.ParentID = new UUID((String)row["parentFolderID"]);
1368
1369 taskItem.InvType = Convert.ToInt32(row["invType"]);
1370 taskItem.Type = Convert.ToInt32(row["assetType"]);
1371
1372 taskItem.Name = (String)row["name"];
1373 taskItem.Description = (String)row["description"];
1374 taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
1375 taskItem.CreatorID = new UUID((String)row["creatorID"]);
1376 taskItem.OwnerID = new UUID((String)row["ownerID"]);
1377 taskItem.LastOwnerID = new UUID((String)row["lastOwnerID"]);
1378 taskItem.GroupID = new UUID((String)row["groupID"]);
1379
1380 taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
1381 taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
1382 taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
1383 taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
1384 taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
1385 taskItem.Flags = Convert.ToUInt32(row["flags"]);
1386
1387 return taskItem;
1388 }
1389
1390 /// <summary>
1391 /// Build a Land Data from the persisted data.
1392 /// </summary>
1393 /// <param name="row"></param>
1394 /// <returns></returns>
1395 private LandData buildLandData(DataRow row)
1396 {
1397 LandData newData = new LandData();
1398
1399 newData.GlobalID = new UUID((String) row["UUID"]);
1400 newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
1401
1402 // Bitmap is a byte[512]
1403 newData.Bitmap = (Byte[]) row["Bitmap"];
1404
1405 newData.Name = (String) row["Name"];
1406 newData.Description = (String) row["Desc"];
1407 newData.OwnerID = (UUID)(String) row["OwnerUUID"];
1408 newData.IsGroupOwned = (Boolean) row["IsGroupOwned"];
1409 newData.Area = Convert.ToInt32(row["Area"]);
1410 newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
1411 newData.Category = (ParcelCategory) Convert.ToInt32(row["Category"]);
1412 //Enum OpenMetaverse.Parcel.ParcelCategory
1413 newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
1414 newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
1415 newData.GroupID = new UUID((String) row["GroupUUID"]);
1416 newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
1417 newData.Status = (ParcelStatus) Convert.ToInt32(row["LandStatus"]);
1418 //Enum. OpenMetaverse.Parcel.ParcelStatus
1419 newData.Flags = Convert.ToUInt32(row["LandFlags"]);
1420 newData.LandingType = (Byte) row["LandingType"];
1421 newData.MediaAutoScale = (Byte) row["MediaAutoScale"];
1422 newData.MediaID = new UUID((String) row["MediaTextureUUID"]);
1423 newData.MediaURL = (String) row["MediaURL"];
1424 newData.MusicURL = (String) row["MusicURL"];
1425 newData.PassHours = Convert.ToSingle(row["PassHours"]);
1426 newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
1427 newData.SnapshotID = (UUID)(String) row["SnapshotUUID"];
1428 try
1429 {
1430
1431 newData.UserLocation =
1432 new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
1433 Convert.ToSingle(row["UserLocationZ"]));
1434 newData.UserLookAt =
1435 new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
1436 Convert.ToSingle(row["UserLookAtZ"]));
1437
1438 }
1439 catch (InvalidCastException)
1440 {
1441 m_log.ErrorFormat("[SQLITE REGION DB]: unable to get parcel telehub settings for {1}", newData.Name);
1442 newData.UserLocation = Vector3.Zero;
1443 newData.UserLookAt = Vector3.Zero;
1444 }
1445 newData.ParcelAccessList = new List<ParcelManager.ParcelAccessEntry>();
1446 UUID authBuyerID = UUID.Zero;
1447
1448 UUID.TryParse((string)row["AuthbuyerID"], out authBuyerID);
1449
1450 newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
1451
1452 return newData;
1453 }
1454
1455 private RegionSettings buildRegionSettings(DataRow row)
1456 {
1457 RegionSettings newSettings = new RegionSettings();
1458
1459 newSettings.RegionUUID = new UUID((string) row["regionUUID"]);
1460 newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
1461 newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
1462 newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
1463 newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
1464 newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
1465 newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
1466 newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
1467 newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
1468 newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
1469 newSettings.Maturity = Convert.ToInt32(row["maturity"]);
1470 newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
1471 newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
1472 newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
1473 newSettings.TerrainTexture1 = new UUID((String) row["terrain_texture_1"]);
1474 newSettings.TerrainTexture2 = new UUID((String) row["terrain_texture_2"]);
1475 newSettings.TerrainTexture3 = new UUID((String) row["terrain_texture_3"]);
1476 newSettings.TerrainTexture4 = new UUID((String) row["terrain_texture_4"]);
1477 newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
1478 newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
1479 newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
1480 newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
1481 newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
1482 newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
1483 newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
1484 newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
1485 newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
1486 newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
1487 newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
1488 newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
1489 newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
1490 newSettings.SunVector = new Vector3 (
1491 Convert.ToSingle(row["sunvectorx"]),
1492 Convert.ToSingle(row["sunvectory"]),
1493 Convert.ToSingle(row["sunvectorz"])
1494 );
1495 newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
1496 newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
1497 newSettings.Covenant = new UUID((String) row["covenant"]);
1498 newSettings.TerrainImageID = new UUID((String)row["map_tile_ID"]);
1499
1500 return newSettings;
1501 }
1502
1503 /// <summary>
1504 /// Build a land access entry from the persisted data.
1505 /// </summary>
1506 /// <param name="row"></param>
1507 /// <returns></returns>
1508 private static ParcelManager.ParcelAccessEntry buildLandAccessData(DataRow row)
1509 {
1510 ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
1511 entry.AgentID = new UUID((string) row["AccessUUID"]);
1512 entry.Flags = (AccessList) row["Flags"];
1513 entry.Time = new DateTime();
1514 return entry;
1515 }
1516
1517 /// <summary>
1518 ///
1519 /// </summary>
1520 /// <param name="val"></param>
1521 /// <returns></returns>
1522 private static Array serializeTerrain(double[,] val)
1523 {
1524 MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) *sizeof (double));
1525 BinaryWriter bw = new BinaryWriter(str);
1526
1527 // TODO: COMPATIBILITY - Add byte-order conversions
1528 for (int x = 0; x < (int)Constants.RegionSize; x++)
1529 for (int y = 0; y < (int)Constants.RegionSize; y++)
1530 bw.Write(val[x, y]);
1531
1532 return str.ToArray();
1533 }
1534
1535// private void fillTerrainRow(DataRow row, UUID regionUUID, int rev, double[,] val)
1536// {
1537// row["RegionUUID"] = regionUUID;
1538// row["Revision"] = rev;
1539
1540 // MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize)*sizeof (double));
1541// BinaryWriter bw = new BinaryWriter(str);
1542
1543// // TODO: COMPATIBILITY - Add byte-order conversions
1544 // for (int x = 0; x < (int)Constants.RegionSize; x++)
1545 // for (int y = 0; y < (int)Constants.RegionSize; y++)
1546// bw.Write(val[x, y]);
1547
1548// row["Heightfield"] = str.ToArray();
1549// }
1550
1551 /// <summary>
1552 ///
1553 /// </summary>
1554 /// <param name="row"></param>
1555 /// <param name="prim"></param>
1556 /// <param name="sceneGroupID"></param>
1557 /// <param name="regionUUID"></param>
1558 private static void fillPrimRow(DataRow row, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
1559 {
1560 row["UUID"] = prim.UUID.ToString();
1561 row["RegionUUID"] = regionUUID.ToString();
1562 row["CreationDate"] = prim.CreationDate;
1563 row["Name"] = prim.Name;
1564 row["SceneGroupID"] = sceneGroupID.ToString();
1565 // the UUID of the root part for this SceneObjectGroup
1566 // various text fields
1567 row["Text"] = prim.Text;
1568 row["Description"] = prim.Description;
1569 row["SitName"] = prim.SitName;
1570 row["TouchName"] = prim.TouchName;
1571 // permissions
1572 row["ObjectFlags"] = prim.ObjectFlags;
1573 row["CreatorID"] = prim.CreatorID.ToString();
1574 row["OwnerID"] = prim.OwnerID.ToString();
1575 row["GroupID"] = prim.GroupID.ToString();
1576 row["LastOwnerID"] = prim.LastOwnerID.ToString();
1577 row["OwnerMask"] = prim.OwnerMask;
1578 row["NextOwnerMask"] = prim.NextOwnerMask;
1579 row["GroupMask"] = prim.GroupMask;
1580 row["EveryoneMask"] = prim.EveryoneMask;
1581 row["BaseMask"] = prim.BaseMask;
1582 // vectors
1583 row["PositionX"] = prim.OffsetPosition.X;
1584 row["PositionY"] = prim.OffsetPosition.Y;
1585 row["PositionZ"] = prim.OffsetPosition.Z;
1586 row["GroupPositionX"] = prim.GroupPosition.X;
1587 row["GroupPositionY"] = prim.GroupPosition.Y;
1588 row["GroupPositionZ"] = prim.GroupPosition.Z;
1589 row["VelocityX"] = prim.Velocity.X;
1590 row["VelocityY"] = prim.Velocity.Y;
1591 row["VelocityZ"] = prim.Velocity.Z;
1592 row["AngularVelocityX"] = prim.AngularVelocity.X;
1593 row["AngularVelocityY"] = prim.AngularVelocity.Y;
1594 row["AngularVelocityZ"] = prim.AngularVelocity.Z;
1595 row["AccelerationX"] = prim.Acceleration.X;
1596 row["AccelerationY"] = prim.Acceleration.Y;
1597 row["AccelerationZ"] = prim.Acceleration.Z;
1598 // quaternions
1599 row["RotationX"] = prim.RotationOffset.X;
1600 row["RotationY"] = prim.RotationOffset.Y;
1601 row["RotationZ"] = prim.RotationOffset.Z;
1602 row["RotationW"] = prim.RotationOffset.W;
1603
1604 // Sit target
1605 Vector3 sitTargetPos = prim.SitTargetPositionLL;
1606 row["SitTargetOffsetX"] = sitTargetPos.X;
1607 row["SitTargetOffsetY"] = sitTargetPos.Y;
1608 row["SitTargetOffsetZ"] = sitTargetPos.Z;
1609
1610 Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
1611 row["SitTargetOrientW"] = sitTargetOrient.W;
1612 row["SitTargetOrientX"] = sitTargetOrient.X;
1613 row["SitTargetOrientY"] = sitTargetOrient.Y;
1614 row["SitTargetOrientZ"] = sitTargetOrient.Z;
1615 row["ColorR"] = Convert.ToInt32(prim.Color.R);
1616 row["ColorG"] = Convert.ToInt32(prim.Color.G);
1617 row["ColorB"] = Convert.ToInt32(prim.Color.B);
1618 row["ColorA"] = Convert.ToInt32(prim.Color.A);
1619 row["PayPrice"] = prim.PayPrice[0];
1620 row["PayButton1"] = prim.PayPrice[1];
1621 row["PayButton2"] = prim.PayPrice[2];
1622 row["PayButton3"] = prim.PayPrice[3];
1623 row["PayButton4"] = prim.PayPrice[4];
1624
1625 row["TextureAnimation"] = Convert.ToBase64String(prim.TextureAnimation);
1626 row["ParticleSystem"] = Convert.ToBase64String(prim.ParticleSystem);
1627
1628 row["OmegaX"] = prim.AngularVelocity.X;
1629 row["OmegaY"] = prim.AngularVelocity.Y;
1630 row["OmegaZ"] = prim.AngularVelocity.Z;
1631
1632 row["CameraEyeOffsetX"] = prim.GetCameraEyeOffset().X;
1633 row["CameraEyeOffsetY"] = prim.GetCameraEyeOffset().Y;
1634 row["CameraEyeOffsetZ"] = prim.GetCameraEyeOffset().Z;
1635
1636 row["CameraAtOffsetX"] = prim.GetCameraAtOffset().X;
1637 row["CameraAtOffsetY"] = prim.GetCameraAtOffset().Y;
1638 row["CameraAtOffsetZ"] = prim.GetCameraAtOffset().Z;
1639
1640
1641 if ((prim.SoundFlags & 1) != 0) // Looped
1642 {
1643 row["LoopedSound"] = prim.Sound.ToString();
1644 row["LoopedSoundGain"] = prim.SoundGain;
1645 }
1646 else
1647 {
1648 row["LoopedSound"] = UUID.Zero.ToString();
1649 row["LoopedSoundGain"] = 0.0f;
1650 }
1651
1652 if (prim.GetForceMouselook())
1653 row["ForceMouselook"] = 1;
1654 else
1655 row["ForceMouselook"] = 0;
1656
1657 row["ScriptAccessPin"] = prim.ScriptAccessPin;
1658
1659 if (prim.AllowedDrop)
1660 row["AllowedDrop"] = 1;
1661 else
1662 row["AllowedDrop"] = 0;
1663
1664 if (prim.DIE_AT_EDGE)
1665 row["DieAtEdge"] = 1;
1666 else
1667 row["DieAtEdge"] = 0;
1668
1669 row["SalePrice"] = prim.SalePrice;
1670 row["SaleType"] = Convert.ToInt16(prim.ObjectSaleType);
1671
1672 // click action
1673 row["ClickAction"] = prim.ClickAction;
1674
1675 row["SalePrice"] = prim.SalePrice;
1676 row["Material"] = prim.Material;
1677
1678 row["CollisionSound"] = prim.CollisionSound.ToString();
1679 row["CollisionSoundVolume"] = prim.CollisionSoundVolume;
1680 if (prim.VolumeDetectActive)
1681 row["VolumeDetect"] = 1;
1682 else
1683 row["VolumeDetect"] = 0;
1684
1685 row["MediaURL"] = prim.MediaUrl;
1686 }
1687
1688 /// <summary>
1689 ///
1690 /// </summary>
1691 /// <param name="row"></param>
1692 /// <param name="taskItem"></param>
1693 private static void fillItemRow(DataRow row, TaskInventoryItem taskItem)
1694 {
1695 row["itemID"] = taskItem.ItemID.ToString();
1696 row["primID"] = taskItem.ParentPartID.ToString();
1697 row["assetID"] = taskItem.AssetID.ToString();
1698 row["parentFolderID"] = taskItem.ParentID.ToString();
1699
1700 row["invType"] = taskItem.InvType;
1701 row["assetType"] = taskItem.Type;
1702
1703 row["name"] = taskItem.Name;
1704 row["description"] = taskItem.Description;
1705 row["creationDate"] = taskItem.CreationDate;
1706 row["creatorID"] = taskItem.CreatorID.ToString();
1707 row["ownerID"] = taskItem.OwnerID.ToString();
1708 row["lastOwnerID"] = taskItem.LastOwnerID.ToString();
1709 row["groupID"] = taskItem.GroupID.ToString();
1710 row["nextPermissions"] = taskItem.NextPermissions;
1711 row["currentPermissions"] = taskItem.CurrentPermissions;
1712 row["basePermissions"] = taskItem.BasePermissions;
1713 row["everyonePermissions"] = taskItem.EveryonePermissions;
1714 row["groupPermissions"] = taskItem.GroupPermissions;
1715 row["flags"] = taskItem.Flags;
1716 }
1717
1718 /// <summary>
1719 ///
1720 /// </summary>
1721 /// <param name="row"></param>
1722 /// <param name="land"></param>
1723 /// <param name="regionUUID"></param>
1724 private static void fillLandRow(DataRow row, LandData land, UUID regionUUID)
1725 {
1726 row["UUID"] = land.GlobalID.ToString();
1727 row["RegionUUID"] = regionUUID.ToString();
1728 row["LocalLandID"] = land.LocalID;
1729
1730 // Bitmap is a byte[512]
1731 row["Bitmap"] = land.Bitmap;
1732
1733 row["Name"] = land.Name;
1734 row["Desc"] = land.Description;
1735 row["OwnerUUID"] = land.OwnerID.ToString();
1736 row["IsGroupOwned"] = land.IsGroupOwned;
1737 row["Area"] = land.Area;
1738 row["AuctionID"] = land.AuctionID; //Unemplemented
1739 row["Category"] = land.Category; //Enum OpenMetaverse.Parcel.ParcelCategory
1740 row["ClaimDate"] = land.ClaimDate;
1741 row["ClaimPrice"] = land.ClaimPrice;
1742 row["GroupUUID"] = land.GroupID.ToString();
1743 row["SalePrice"] = land.SalePrice;
1744 row["LandStatus"] = land.Status; //Enum. OpenMetaverse.Parcel.ParcelStatus
1745 row["LandFlags"] = land.Flags;
1746 row["LandingType"] = land.LandingType;
1747 row["MediaAutoScale"] = land.MediaAutoScale;
1748 row["MediaTextureUUID"] = land.MediaID.ToString();
1749 row["MediaURL"] = land.MediaURL;
1750 row["MusicURL"] = land.MusicURL;
1751 row["PassHours"] = land.PassHours;
1752 row["PassPrice"] = land.PassPrice;
1753 row["SnapshotUUID"] = land.SnapshotID.ToString();
1754 row["UserLocationX"] = land.UserLocation.X;
1755 row["UserLocationY"] = land.UserLocation.Y;
1756 row["UserLocationZ"] = land.UserLocation.Z;
1757 row["UserLookAtX"] = land.UserLookAt.X;
1758 row["UserLookAtY"] = land.UserLookAt.Y;
1759 row["UserLookAtZ"] = land.UserLookAt.Z;
1760 row["AuthbuyerID"] = land.AuthBuyerID.ToString();
1761 row["OtherCleanTime"] = land.OtherCleanTime;
1762 row["MediaType"] = land.MediaType;
1763 row["MediaDescription"] = land.MediaDescription;
1764 row["MediaSize"] = land.MediaWidth.ToString() + "," + land.MediaHeight.ToString();
1765 row["MediaLoop"] = land.MediaLoop.ToString();
1766 row["ObscureMusic"] = land.ObscureMusic.ToString();
1767 row["ObscureMedia"] = land.ObscureMedia.ToString();
1768 }
1769
1770 /// <summary>
1771 ///
1772 /// </summary>
1773 /// <param name="row"></param>
1774 /// <param name="entry"></param>
1775 /// <param name="parcelID"></param>
1776 private static void fillLandAccessRow(DataRow row, ParcelManager.ParcelAccessEntry entry, UUID parcelID)
1777 {
1778 row["LandUUID"] = parcelID.ToString();
1779 row["AccessUUID"] = entry.AgentID.ToString();
1780 row["Flags"] = entry.Flags;
1781 }
1782
1783 private static void fillRegionSettingsRow(DataRow row, RegionSettings settings)
1784 {
1785 row["regionUUID"] = settings.RegionUUID.ToString();
1786 row["block_terraform"] = settings.BlockTerraform;
1787 row["block_fly"] = settings.BlockFly;
1788 row["allow_damage"] = settings.AllowDamage;
1789 row["restrict_pushing"] = settings.RestrictPushing;
1790 row["allow_land_resell"] = settings.AllowLandResell;
1791 row["allow_land_join_divide"] = settings.AllowLandJoinDivide;
1792 row["block_show_in_search"] = settings.BlockShowInSearch;
1793 row["agent_limit"] = settings.AgentLimit;
1794 row["object_bonus"] = settings.ObjectBonus;
1795 row["maturity"] = settings.Maturity;
1796 row["disable_scripts"] = settings.DisableScripts;
1797 row["disable_collisions"] = settings.DisableCollisions;
1798 row["disable_physics"] = settings.DisablePhysics;
1799 row["terrain_texture_1"] = settings.TerrainTexture1.ToString();
1800 row["terrain_texture_2"] = settings.TerrainTexture2.ToString();
1801 row["terrain_texture_3"] = settings.TerrainTexture3.ToString();
1802 row["terrain_texture_4"] = settings.TerrainTexture4.ToString();
1803 row["elevation_1_nw"] = settings.Elevation1NW;
1804 row["elevation_2_nw"] = settings.Elevation2NW;
1805 row["elevation_1_ne"] = settings.Elevation1NE;
1806 row["elevation_2_ne"] = settings.Elevation2NE;
1807 row["elevation_1_se"] = settings.Elevation1SE;
1808 row["elevation_2_se"] = settings.Elevation2SE;
1809 row["elevation_1_sw"] = settings.Elevation1SW;
1810 row["elevation_2_sw"] = settings.Elevation2SW;
1811 row["water_height"] = settings.WaterHeight;
1812 row["terrain_raise_limit"] = settings.TerrainRaiseLimit;
1813 row["terrain_lower_limit"] = settings.TerrainLowerLimit;
1814 row["use_estate_sun"] = settings.UseEstateSun;
1815 row["Sandbox"] = settings.Sandbox; // database uses upper case S for sandbox
1816 row["sunvectorx"] = settings.SunVector.X;
1817 row["sunvectory"] = settings.SunVector.Y;
1818 row["sunvectorz"] = settings.SunVector.Z;
1819 row["fixed_sun"] = settings.FixedSun;
1820 row["sun_position"] = settings.SunPosition;
1821 row["covenant"] = settings.Covenant.ToString();
1822 row["map_tile_ID"] = settings.TerrainImageID.ToString();
1823 }
1824
1825 /// <summary>
1826 ///
1827 /// </summary>
1828 /// <param name="row"></param>
1829 /// <returns></returns>
1830 private PrimitiveBaseShape buildShape(DataRow row)
1831 {
1832 PrimitiveBaseShape s = new PrimitiveBaseShape();
1833 s.Scale = new Vector3(
1834 Convert.ToSingle(row["ScaleX"]),
1835 Convert.ToSingle(row["ScaleY"]),
1836 Convert.ToSingle(row["ScaleZ"])
1837 );
1838 // paths
1839 s.PCode = Convert.ToByte(row["PCode"]);
1840 s.PathBegin = Convert.ToUInt16(row["PathBegin"]);
1841 s.PathEnd = Convert.ToUInt16(row["PathEnd"]);
1842 s.PathScaleX = Convert.ToByte(row["PathScaleX"]);
1843 s.PathScaleY = Convert.ToByte(row["PathScaleY"]);
1844 s.PathShearX = Convert.ToByte(row["PathShearX"]);
1845 s.PathShearY = Convert.ToByte(row["PathShearY"]);
1846 s.PathSkew = Convert.ToSByte(row["PathSkew"]);
1847 s.PathCurve = Convert.ToByte(row["PathCurve"]);
1848 s.PathRadiusOffset = Convert.ToSByte(row["PathRadiusOffset"]);
1849 s.PathRevolutions = Convert.ToByte(row["PathRevolutions"]);
1850 s.PathTaperX = Convert.ToSByte(row["PathTaperX"]);
1851 s.PathTaperY = Convert.ToSByte(row["PathTaperY"]);
1852 s.PathTwist = Convert.ToSByte(row["PathTwist"]);
1853 s.PathTwistBegin = Convert.ToSByte(row["PathTwistBegin"]);
1854 // profile
1855 s.ProfileBegin = Convert.ToUInt16(row["ProfileBegin"]);
1856 s.ProfileEnd = Convert.ToUInt16(row["ProfileEnd"]);
1857 s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]);
1858 s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]);
1859 s.State = Convert.ToByte(row["State"]);
1860
1861 byte[] textureEntry = (byte[])row["Texture"];
1862 s.TextureEntry = textureEntry;
1863
1864 s.ExtraParams = (byte[]) row["ExtraParams"];
1865
1866 if (!(row["Media"] is System.DBNull))
1867 s.Media = PrimitiveBaseShape.MediaList.FromXml((string)row["Media"]);
1868
1869 return s;
1870 }
1871
1872 /// <summary>
1873 ///
1874 /// </summary>
1875 /// <param name="row"></param>
1876 /// <param name="prim"></param>
1877 private static void fillShapeRow(DataRow row, SceneObjectPart prim)
1878 {
1879 PrimitiveBaseShape s = prim.Shape;
1880 row["UUID"] = prim.UUID.ToString();
1881 // shape is an enum
1882 row["Shape"] = 0;
1883 // vectors
1884 row["ScaleX"] = s.Scale.X;
1885 row["ScaleY"] = s.Scale.Y;
1886 row["ScaleZ"] = s.Scale.Z;
1887 // paths
1888 row["PCode"] = s.PCode;
1889 row["PathBegin"] = s.PathBegin;
1890 row["PathEnd"] = s.PathEnd;
1891 row["PathScaleX"] = s.PathScaleX;
1892 row["PathScaleY"] = s.PathScaleY;
1893 row["PathShearX"] = s.PathShearX;
1894 row["PathShearY"] = s.PathShearY;
1895 row["PathSkew"] = s.PathSkew;
1896 row["PathCurve"] = s.PathCurve;
1897 row["PathRadiusOffset"] = s.PathRadiusOffset;
1898 row["PathRevolutions"] = s.PathRevolutions;
1899 row["PathTaperX"] = s.PathTaperX;
1900 row["PathTaperY"] = s.PathTaperY;
1901 row["PathTwist"] = s.PathTwist;
1902 row["PathTwistBegin"] = s.PathTwistBegin;
1903 // profile
1904 row["ProfileBegin"] = s.ProfileBegin;
1905 row["ProfileEnd"] = s.ProfileEnd;
1906 row["ProfileCurve"] = s.ProfileCurve;
1907 row["ProfileHollow"] = s.ProfileHollow;
1908 row["State"] = s.State;
1909
1910 row["Texture"] = s.TextureEntry;
1911 row["ExtraParams"] = s.ExtraParams;
1912
1913 if (s.Media != null)
1914 row["Media"] = s.Media.ToXml();
1915 }
1916
1917 /// <summary>
1918 /// Persistently store a prim.
1919 /// </summary>
1920 /// <param name="prim"></param>
1921 /// <param name="sceneGroupID"></param>
1922 /// <param name="regionUUID"></param>
1923 private void addPrim(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
1924 {
1925 DataTable prims = ds.Tables["prims"];
1926 DataTable shapes = ds.Tables["primshapes"];
1927
1928 DataRow primRow = prims.Rows.Find(prim.UUID.ToString());
1929 if (primRow == null)
1930 {
1931 primRow = prims.NewRow();
1932 fillPrimRow(primRow, prim, sceneGroupID, regionUUID);
1933 prims.Rows.Add(primRow);
1934 }
1935 else
1936 {
1937 fillPrimRow(primRow, prim, sceneGroupID, regionUUID);
1938 }
1939
1940 DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
1941 if (shapeRow == null)
1942 {
1943 shapeRow = shapes.NewRow();
1944 fillShapeRow(shapeRow, prim);
1945 shapes.Rows.Add(shapeRow);
1946 }
1947 else
1948 {
1949 fillShapeRow(shapeRow, prim);
1950 }
1951 }
1952
1953 /// <summary>
1954 /// see IRegionDatastore
1955 /// </summary>
1956 /// <param name="primID"></param>
1957 /// <param name="items"></param>
1958 public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
1959 {
1960// m_log.DebugFormat("[SQLITE REGION DB]: Entered StorePrimInventory with prim ID {0}", primID);
1961
1962 DataTable dbItems = ds.Tables["primitems"];
1963
1964 // For now, we're just going to crudely remove all the previous inventory items
1965 // no matter whether they have changed or not, and replace them with the current set.
1966 lock (ds)
1967 {
1968 RemoveItems(primID);
1969
1970 // repalce with current inventory details
1971 foreach (TaskInventoryItem newItem in items)
1972 {
1973// m_log.InfoFormat(
1974// "[DATASTORE]: ",
1975// "Adding item {0}, {1} to prim ID {2}",
1976// newItem.Name, newItem.ItemID, newItem.ParentPartID);
1977
1978 DataRow newItemRow = dbItems.NewRow();
1979 fillItemRow(newItemRow, newItem);
1980 dbItems.Rows.Add(newItemRow);
1981 }
1982 }
1983
1984 Commit();
1985 }
1986
1987 /***********************************************************************
1988 *
1989 * SQL Statement Creation Functions
1990 *
1991 * These functions create SQL statements for update, insert, and create.
1992 * They can probably be factored later to have a db independant
1993 * portion and a db specific portion
1994 *
1995 **********************************************************************/
1996
1997 /// <summary>
1998 /// Create an insert command
1999 /// </summary>
2000 /// <param name="table">table name</param>
2001 /// <param name="dt">data table</param>
2002 /// <returns>the created command</returns>
2003 /// <remarks>
2004 /// This is subtle enough to deserve some commentary.
2005 /// Instead of doing *lots* and *lots of hardcoded strings
2006 /// for database definitions we'll use the fact that
2007 /// realistically all insert statements look like "insert
2008 /// into A(b, c) values(:b, :c) on the parameterized query
2009 /// front. If we just have a list of b, c, etc... we can
2010 /// generate these strings instead of typing them out.
2011 /// </remarks>
2012 private static SqliteCommand createInsertCommand(string table, DataTable dt)
2013 {
2014 string[] cols = new string[dt.Columns.Count];
2015 for (int i = 0; i < dt.Columns.Count; i++)
2016 {
2017 DataColumn col = dt.Columns[i];
2018 cols[i] = col.ColumnName;
2019 }
2020
2021 string sql = "insert into " + table + "(";
2022 sql += String.Join(", ", cols);
2023 // important, the first ':' needs to be here, the rest get added in the join
2024 sql += ") values (:";
2025 sql += String.Join(", :", cols);
2026 sql += ")";
2027 //m_log.DebugFormat("[SQLITE]: Created insert command {0}", sql);
2028 SqliteCommand cmd = new SqliteCommand(sql);
2029
2030 // this provides the binding for all our parameters, so
2031 // much less code than it used to be
2032 foreach (DataColumn col in dt.Columns)
2033 {
2034 cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
2035 }
2036 return cmd;
2037 }
2038
2039
2040 /// <summary>
2041 /// create an update command
2042 /// </summary>
2043 /// <param name="table">table name</param>
2044 /// <param name="pk"></param>
2045 /// <param name="dt"></param>
2046 /// <returns>the created command</returns>
2047 private static SqliteCommand createUpdateCommand(string table, string pk, DataTable dt)
2048 {
2049 string sql = "update " + table + " set ";
2050 string subsql = String.Empty;
2051 foreach (DataColumn col in dt.Columns)
2052 {
2053 if (subsql.Length > 0)
2054 {
2055 // a map function would rock so much here
2056 subsql += ", ";
2057 }
2058 subsql += col.ColumnName + "= :" + col.ColumnName;
2059 }
2060 sql += subsql;
2061 sql += " where " + pk;
2062 SqliteCommand cmd = new SqliteCommand(sql);
2063
2064 // this provides the binding for all our parameters, so
2065 // much less code than it used to be
2066
2067 foreach (DataColumn col in dt.Columns)
2068 {
2069 cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
2070 }
2071 return cmd;
2072 }
2073
2074 /// <summary>
2075 /// create an update command
2076 /// </summary>
2077 /// <param name="table">table name</param>
2078 /// <param name="pk"></param>
2079 /// <param name="dt"></param>
2080 /// <returns>the created command</returns>
2081 private static SqliteCommand createUpdateCommand(string table, string pk1, string pk2, DataTable dt)
2082 {
2083 string sql = "update " + table + " set ";
2084 string subsql = String.Empty;
2085 foreach (DataColumn col in dt.Columns)
2086 {
2087 if (subsql.Length > 0)
2088 {
2089 // a map function would rock so much here
2090 subsql += ", ";
2091 }
2092 subsql += col.ColumnName + "= :" + col.ColumnName;
2093 }
2094 sql += subsql;
2095 sql += " where " + pk1 + " and " + pk2;
2096 SqliteCommand cmd = new SqliteCommand(sql);
2097
2098 // this provides the binding for all our parameters, so
2099 // much less code than it used to be
2100
2101 foreach (DataColumn col in dt.Columns)
2102 {
2103 cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
2104 }
2105 return cmd;
2106 }
2107
2108 /// <summary>
2109 ///
2110 /// </summary>
2111 /// <param name="dt">Data Table</param>
2112 /// <returns></returns>
2113 // private static string defineTable(DataTable dt)
2114 // {
2115 // string sql = "create table " + dt.TableName + "(";
2116 // string subsql = String.Empty;
2117 // foreach (DataColumn col in dt.Columns)
2118 // {
2119 // if (subsql.Length > 0)
2120 // {
2121 // // a map function would rock so much here
2122 // subsql += ",\n";
2123 // }
2124 // subsql += col.ColumnName + " " + sqliteType(col.DataType);
2125 // if (dt.PrimaryKey.Length > 0 && col == dt.PrimaryKey[0])
2126 // {
2127 // subsql += " primary key";
2128 // }
2129 // }
2130 // sql += subsql;
2131 // sql += ")";
2132 // return sql;
2133 // }
2134
2135 /***********************************************************************
2136 *
2137 * Database Binding functions
2138 *
2139 * These will be db specific due to typing, and minor differences
2140 * in databases.
2141 *
2142 **********************************************************************/
2143
2144 ///<summary>
2145 /// This is a convenience function that collapses 5 repetitive
2146 /// lines for defining SqliteParameters to 2 parameters:
2147 /// column name and database type.
2148 ///
2149 /// It assumes certain conventions like :param as the param
2150 /// name to replace in parametrized queries, and that source
2151 /// version is always current version, both of which are fine
2152 /// for us.
2153 ///</summary>
2154 ///<returns>a built sqlite parameter</returns>
2155 private static SqliteParameter createSqliteParameter(string name, Type type)
2156 {
2157 SqliteParameter param = new SqliteParameter();
2158 param.ParameterName = ":" + name;
2159 param.DbType = dbtypeFromType(type);
2160 param.SourceColumn = name;
2161 param.SourceVersion = DataRowVersion.Current;
2162 return param;
2163 }
2164
2165 /// <summary>
2166 ///
2167 /// </summary>
2168 /// <param name="da"></param>
2169 /// <param name="conn"></param>
2170 private void setupPrimCommands(SqliteDataAdapter da, SqliteConnection conn)
2171 {
2172 da.InsertCommand = createInsertCommand("prims", ds.Tables["prims"]);
2173 da.InsertCommand.Connection = conn;
2174
2175 da.UpdateCommand = createUpdateCommand("prims", "UUID=:UUID", ds.Tables["prims"]);
2176 da.UpdateCommand.Connection = conn;
2177
2178 SqliteCommand delete = new SqliteCommand("delete from prims where UUID = :UUID");
2179 delete.Parameters.Add(createSqliteParameter("UUID", typeof (String)));
2180 delete.Connection = conn;
2181 da.DeleteCommand = delete;
2182 }
2183
2184 /// <summary>
2185 ///
2186 /// </summary>
2187 /// <param name="da"></param>
2188 /// <param name="conn"></param>
2189 private void setupItemsCommands(SqliteDataAdapter da, SqliteConnection conn)
2190 {
2191 da.InsertCommand = createInsertCommand("primitems", ds.Tables["primitems"]);
2192 da.InsertCommand.Connection = conn;
2193
2194 da.UpdateCommand = createUpdateCommand("primitems", "itemID = :itemID", ds.Tables["primitems"]);
2195 da.UpdateCommand.Connection = conn;
2196
2197 SqliteCommand delete = new SqliteCommand("delete from primitems where itemID = :itemID");
2198 delete.Parameters.Add(createSqliteParameter("itemID", typeof (String)));
2199 delete.Connection = conn;
2200 da.DeleteCommand = delete;
2201 }
2202
2203 /// <summary>
2204 ///
2205 /// </summary>
2206 /// <param name="da"></param>
2207 /// <param name="conn"></param>
2208 private void setupTerrainCommands(SqliteDataAdapter da, SqliteConnection conn)
2209 {
2210 da.InsertCommand = createInsertCommand("terrain", ds.Tables["terrain"]);
2211 da.InsertCommand.Connection = conn;
2212 }
2213
2214 /// <summary>
2215 ///
2216 /// </summary>
2217 /// <param name="da"></param>
2218 /// <param name="conn"></param>
2219 private void setupLandCommands(SqliteDataAdapter da, SqliteConnection conn)
2220 {
2221 da.InsertCommand = createInsertCommand("land", ds.Tables["land"]);
2222 da.InsertCommand.Connection = conn;
2223
2224 da.UpdateCommand = createUpdateCommand("land", "UUID=:UUID", ds.Tables["land"]);
2225 da.UpdateCommand.Connection = conn;
2226
2227 SqliteCommand delete = new SqliteCommand("delete from land where UUID=:UUID");
2228 delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
2229 da.DeleteCommand = delete;
2230 da.DeleteCommand.Connection = conn;
2231 }
2232
2233 /// <summary>
2234 ///
2235 /// </summary>
2236 /// <param name="da"></param>
2237 /// <param name="conn"></param>
2238 private void setupLandAccessCommands(SqliteDataAdapter da, SqliteConnection conn)
2239 {
2240 da.InsertCommand = createInsertCommand("landaccesslist", ds.Tables["landaccesslist"]);
2241 da.InsertCommand.Connection = conn;
2242
2243 da.UpdateCommand = createUpdateCommand("landaccesslist", "LandUUID=:landUUID", "AccessUUID=:AccessUUID", ds.Tables["landaccesslist"]);
2244 da.UpdateCommand.Connection = conn;
2245
2246 SqliteCommand delete = new SqliteCommand("delete from landaccesslist where LandUUID= :LandUUID and AccessUUID= :AccessUUID");
2247 delete.Parameters.Add(createSqliteParameter("LandUUID", typeof(String)));
2248 delete.Parameters.Add(createSqliteParameter("AccessUUID", typeof(String)));
2249 da.DeleteCommand = delete;
2250 da.DeleteCommand.Connection = conn;
2251
2252 }
2253
2254 private void setupRegionSettingsCommands(SqliteDataAdapter da, SqliteConnection conn)
2255 {
2256 da.InsertCommand = createInsertCommand("regionsettings", ds.Tables["regionsettings"]);
2257 da.InsertCommand.Connection = conn;
2258 da.UpdateCommand = createUpdateCommand("regionsettings", "regionUUID=:regionUUID", ds.Tables["regionsettings"]);
2259 da.UpdateCommand.Connection = conn;
2260 }
2261
2262 /// <summary>
2263 ///
2264 /// </summary>
2265 /// <param name="da"></param>
2266 /// <param name="conn"></param>
2267 private void setupShapeCommands(SqliteDataAdapter da, SqliteConnection conn)
2268 {
2269 da.InsertCommand = createInsertCommand("primshapes", ds.Tables["primshapes"]);
2270 da.InsertCommand.Connection = conn;
2271
2272 da.UpdateCommand = createUpdateCommand("primshapes", "UUID=:UUID", ds.Tables["primshapes"]);
2273 da.UpdateCommand.Connection = conn;
2274
2275 SqliteCommand delete = new SqliteCommand("delete from primshapes where UUID = :UUID");
2276 delete.Parameters.Add(createSqliteParameter("UUID", typeof (String)));
2277 delete.Connection = conn;
2278 da.DeleteCommand = delete;
2279 }
2280
2281 /***********************************************************************
2282 *
2283 * Type conversion functions
2284 *
2285 **********************************************************************/
2286
2287 /// <summary>
2288 /// Type conversion function
2289 /// </summary>
2290 /// <param name="type"></param>
2291 /// <returns></returns>
2292 private static DbType dbtypeFromType(Type type)
2293 {
2294 if (type == typeof (String))
2295 {
2296 return DbType.String;
2297 }
2298 else if (type == typeof (Int32))
2299 {
2300 return DbType.Int32;
2301 }
2302 else if (type == typeof (Double))
2303 {
2304 return DbType.Double;
2305 }
2306 else if (type == typeof (Byte))
2307 {
2308 return DbType.Byte;
2309 }
2310 else if (type == typeof (Double))
2311 {
2312 return DbType.Double;
2313 }
2314 else if (type == typeof (Byte[]))
2315 {
2316 return DbType.Binary;
2317 }
2318 else
2319 {
2320 return DbType.String;
2321 }
2322 }
2323
2324 static void PrintDataSet(DataSet ds)
2325 {
2326 // Print out any name and extended properties.
2327 Console.WriteLine("DataSet is named: {0}", ds.DataSetName);
2328 foreach (System.Collections.DictionaryEntry de in ds.ExtendedProperties)
2329 {
2330 Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
2331 }
2332 Console.WriteLine();
2333 foreach (DataTable dt in ds.Tables)
2334 {
2335 Console.WriteLine("=> {0} Table:", dt.TableName);
2336 // Print out the column names.
2337 for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
2338 {
2339 Console.Write(dt.Columns[curCol].ColumnName + "\t");
2340 }
2341 Console.WriteLine("\n----------------------------------");
2342 // Print the DataTable.
2343 for (int curRow = 0; curRow < dt.Rows.Count; curRow++)
2344 {
2345 for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
2346 {
2347 Console.Write(dt.Rows[curRow][curCol].ToString() + "\t");
2348 }
2349 Console.WriteLine();
2350 }
2351 }
2352 }
2353
2354 }
2355}