SQLiteRegionData.cs 91 KB

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