SQLiteRegionData.cs 95 KB

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