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