SQLiteRegionData.cs 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264
  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. createCol(land, "Dwell", typeof(Int32));
  935. land.PrimaryKey = new DataColumn[] {land.Columns["UUID"]};
  936. return land;
  937. }
  938. /// <summary>
  939. /// create "landaccesslist" table
  940. /// </summary>
  941. /// <returns>Landacceslist DataTable</returns>
  942. private static DataTable createLandAccessListTable()
  943. {
  944. DataTable landaccess = new DataTable("landaccesslist");
  945. createCol(landaccess, "LandUUID", typeof (String));
  946. createCol(landaccess, "AccessUUID", typeof (String));
  947. createCol(landaccess, "Flags", typeof (UInt32));
  948. return landaccess;
  949. }
  950. private static DataTable createRegionSettingsTable()
  951. {
  952. DataTable regionsettings = new DataTable("regionsettings");
  953. createCol(regionsettings, "regionUUID", typeof(String));
  954. createCol(regionsettings, "block_terraform", typeof (Int32));
  955. createCol(regionsettings, "block_fly", typeof (Int32));
  956. createCol(regionsettings, "allow_damage", typeof (Int32));
  957. createCol(regionsettings, "restrict_pushing", typeof (Int32));
  958. createCol(regionsettings, "allow_land_resell", typeof (Int32));
  959. createCol(regionsettings, "allow_land_join_divide", typeof (Int32));
  960. createCol(regionsettings, "block_show_in_search", typeof (Int32));
  961. createCol(regionsettings, "agent_limit", typeof (Int32));
  962. createCol(regionsettings, "object_bonus", typeof (Double));
  963. createCol(regionsettings, "maturity", typeof (Int32));
  964. createCol(regionsettings, "disable_scripts", typeof (Int32));
  965. createCol(regionsettings, "disable_collisions", typeof (Int32));
  966. createCol(regionsettings, "disable_physics", typeof (Int32));
  967. createCol(regionsettings, "terrain_texture_1", typeof(String));
  968. createCol(regionsettings, "terrain_texture_2", typeof(String));
  969. createCol(regionsettings, "terrain_texture_3", typeof(String));
  970. createCol(regionsettings, "terrain_texture_4", typeof(String));
  971. createCol(regionsettings, "elevation_1_nw", typeof (Double));
  972. createCol(regionsettings, "elevation_2_nw", typeof (Double));
  973. createCol(regionsettings, "elevation_1_ne", typeof (Double));
  974. createCol(regionsettings, "elevation_2_ne", typeof (Double));
  975. createCol(regionsettings, "elevation_1_se", typeof (Double));
  976. createCol(regionsettings, "elevation_2_se", typeof (Double));
  977. createCol(regionsettings, "elevation_1_sw", typeof (Double));
  978. createCol(regionsettings, "elevation_2_sw", typeof (Double));
  979. createCol(regionsettings, "water_height", typeof (Double));
  980. createCol(regionsettings, "terrain_raise_limit", typeof (Double));
  981. createCol(regionsettings, "terrain_lower_limit", typeof (Double));
  982. createCol(regionsettings, "use_estate_sun", typeof (Int32));
  983. createCol(regionsettings, "sandbox", typeof (Int32));
  984. createCol(regionsettings, "sunvectorx",typeof (Double));
  985. createCol(regionsettings, "sunvectory",typeof (Double));
  986. createCol(regionsettings, "sunvectorz",typeof (Double));
  987. createCol(regionsettings, "fixed_sun", typeof (Int32));
  988. createCol(regionsettings, "sun_position", typeof (Double));
  989. createCol(regionsettings, "covenant", typeof(String));
  990. regionsettings.PrimaryKey = new DataColumn[] { regionsettings.Columns["regionUUID"] };
  991. return regionsettings;
  992. }
  993. /***********************************************************************
  994. *
  995. * Convert between ADO.NET <=> OpenSim Objects
  996. *
  997. * These should be database independant
  998. *
  999. **********************************************************************/
  1000. /// <summary>
  1001. ///
  1002. /// </summary>
  1003. /// <param name="row"></param>
  1004. /// <returns></returns>
  1005. private SceneObjectPart buildPrim(DataRow row)
  1006. {
  1007. // Code commented. Uncomment to test the unit test inline.
  1008. // The unit test mentions this commented code for the purposes
  1009. // of debugging a unit test failure
  1010. // SceneObjectGroup sog = new SceneObjectGroup();
  1011. // SceneObjectPart sop = new SceneObjectPart();
  1012. // sop.LocalId = 1;
  1013. // sop.Name = "object1";
  1014. // sop.Description = "object1";
  1015. // sop.Text = "";
  1016. // sop.SitName = "";
  1017. // sop.TouchName = "";
  1018. // sop.UUID = UUID.Random();
  1019. // sop.Shape = PrimitiveBaseShape.Default;
  1020. // sog.SetRootPart(sop);
  1021. // Add breakpoint in above line. Check sop fields.
  1022. // TODO: this doesn't work yet because something more
  1023. // interesting has to be done to actually get these values
  1024. // back out. Not enough time to figure it out yet.
  1025. SceneObjectPart prim = new SceneObjectPart();
  1026. prim.UUID = new UUID((String) row["UUID"]);
  1027. // explicit conversion of integers is required, which sort
  1028. // of sucks. No idea if there is a shortcut here or not.
  1029. prim.CreationDate = Convert.ToInt32(row["CreationDate"]);
  1030. prim.Name = row["Name"] == DBNull.Value ? string.Empty : (string)row["Name"];
  1031. // various text fields
  1032. prim.Text = (String) row["Text"];
  1033. prim.Color = Color.FromArgb(Convert.ToInt32(row["ColorA"]),
  1034. Convert.ToInt32(row["ColorR"]),
  1035. Convert.ToInt32(row["ColorG"]),
  1036. Convert.ToInt32(row["ColorB"]));
  1037. prim.Description = (String) row["Description"];
  1038. prim.SitName = (String) row["SitName"];
  1039. prim.TouchName = (String) row["TouchName"];
  1040. // permissions
  1041. prim.Flags = (PrimFlags)Convert.ToUInt32(row["ObjectFlags"]);
  1042. prim.CreatorID = new UUID((String) row["CreatorID"]);
  1043. prim.OwnerID = new UUID((String) row["OwnerID"]);
  1044. prim.GroupID = new UUID((String) row["GroupID"]);
  1045. prim.LastOwnerID = new UUID((String) row["LastOwnerID"]);
  1046. prim.OwnerMask = Convert.ToUInt32(row["OwnerMask"]);
  1047. prim.NextOwnerMask = Convert.ToUInt32(row["NextOwnerMask"]);
  1048. prim.GroupMask = Convert.ToUInt32(row["GroupMask"]);
  1049. prim.EveryoneMask = Convert.ToUInt32(row["EveryoneMask"]);
  1050. prim.BaseMask = Convert.ToUInt32(row["BaseMask"]);
  1051. // vectors
  1052. prim.OffsetPosition = new Vector3(
  1053. Convert.ToSingle(row["PositionX"]),
  1054. Convert.ToSingle(row["PositionY"]),
  1055. Convert.ToSingle(row["PositionZ"])
  1056. );
  1057. prim.GroupPosition = new Vector3(
  1058. Convert.ToSingle(row["GroupPositionX"]),
  1059. Convert.ToSingle(row["GroupPositionY"]),
  1060. Convert.ToSingle(row["GroupPositionZ"])
  1061. );
  1062. prim.Velocity = new Vector3(
  1063. Convert.ToSingle(row["VelocityX"]),
  1064. Convert.ToSingle(row["VelocityY"]),
  1065. Convert.ToSingle(row["VelocityZ"])
  1066. );
  1067. prim.AngularVelocity = new Vector3(
  1068. Convert.ToSingle(row["AngularVelocityX"]),
  1069. Convert.ToSingle(row["AngularVelocityY"]),
  1070. Convert.ToSingle(row["AngularVelocityZ"])
  1071. );
  1072. prim.Acceleration = new Vector3(
  1073. Convert.ToSingle(row["AccelerationX"]),
  1074. Convert.ToSingle(row["AccelerationY"]),
  1075. Convert.ToSingle(row["AccelerationZ"])
  1076. );
  1077. // quaternions
  1078. prim.RotationOffset = new Quaternion(
  1079. Convert.ToSingle(row["RotationX"]),
  1080. Convert.ToSingle(row["RotationY"]),
  1081. Convert.ToSingle(row["RotationZ"]),
  1082. Convert.ToSingle(row["RotationW"])
  1083. );
  1084. prim.SitTargetPositionLL = new Vector3(
  1085. Convert.ToSingle(row["SitTargetOffsetX"]),
  1086. Convert.ToSingle(row["SitTargetOffsetY"]),
  1087. Convert.ToSingle(row["SitTargetOffsetZ"]));
  1088. prim.SitTargetOrientationLL = new Quaternion(
  1089. Convert.ToSingle(
  1090. row["SitTargetOrientX"]),
  1091. Convert.ToSingle(
  1092. row["SitTargetOrientY"]),
  1093. Convert.ToSingle(
  1094. row["SitTargetOrientZ"]),
  1095. Convert.ToSingle(
  1096. row["SitTargetOrientW"]));
  1097. prim.ClickAction = Convert.ToByte(row["ClickAction"]);
  1098. prim.PayPrice[0] = Convert.ToInt32(row["PayPrice"]);
  1099. prim.PayPrice[1] = Convert.ToInt32(row["PayButton1"]);
  1100. prim.PayPrice[2] = Convert.ToInt32(row["PayButton2"]);
  1101. prim.PayPrice[3] = Convert.ToInt32(row["PayButton3"]);
  1102. prim.PayPrice[4] = Convert.ToInt32(row["PayButton4"]);
  1103. prim.Sound = new UUID(row["LoopedSound"].ToString());
  1104. prim.SoundGain = Convert.ToSingle(row["LoopedSoundGain"]);
  1105. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  1106. if (!row.IsNull("TextureAnimation"))
  1107. prim.TextureAnimation = Convert.FromBase64String(row["TextureAnimation"].ToString());
  1108. if (!row.IsNull("ParticleSystem"))
  1109. prim.ParticleSystem = Convert.FromBase64String(row["ParticleSystem"].ToString());
  1110. prim.AngularVelocity = new Vector3(
  1111. Convert.ToSingle(row["OmegaX"]),
  1112. Convert.ToSingle(row["OmegaY"]),
  1113. Convert.ToSingle(row["OmegaZ"])
  1114. );
  1115. prim.SetCameraEyeOffset(new Vector3(
  1116. Convert.ToSingle(row["CameraEyeOffsetX"]),
  1117. Convert.ToSingle(row["CameraEyeOffsetY"]),
  1118. Convert.ToSingle(row["CameraEyeOffsetZ"])
  1119. ));
  1120. prim.SetCameraAtOffset(new Vector3(
  1121. Convert.ToSingle(row["CameraAtOffsetX"]),
  1122. Convert.ToSingle(row["CameraAtOffsetY"]),
  1123. Convert.ToSingle(row["CameraAtOffsetZ"])
  1124. ));
  1125. if (Convert.ToInt16(row["ForceMouselook"]) != 0)
  1126. prim.SetForceMouselook(true);
  1127. prim.ScriptAccessPin = Convert.ToInt32(row["ScriptAccessPin"]);
  1128. if (Convert.ToInt16(row["AllowedDrop"]) != 0)
  1129. prim.AllowedDrop = true;
  1130. if (Convert.ToInt16(row["DieAtEdge"]) != 0)
  1131. prim.DIE_AT_EDGE = true;
  1132. prim.SalePrice = Convert.ToInt32(row["SalePrice"]);
  1133. prim.ObjectSaleType = Convert.ToByte(row["SaleType"]);
  1134. prim.Material = Convert.ToByte(row["Material"]);
  1135. prim.CollisionSound = new UUID(row["CollisionSound"].ToString());
  1136. prim.CollisionSoundVolume = Convert.ToSingle(row["CollisionSoundVolume"]);
  1137. if (Convert.ToInt16(row["VolumeDetect"]) != 0)
  1138. prim.VolumeDetectActive = true;
  1139. return prim;
  1140. }
  1141. /// <summary>
  1142. /// Build a prim inventory item from the persisted data.
  1143. /// </summary>
  1144. /// <param name="row"></param>
  1145. /// <returns></returns>
  1146. private static TaskInventoryItem buildItem(DataRow row)
  1147. {
  1148. TaskInventoryItem taskItem = new TaskInventoryItem();
  1149. taskItem.ItemID = new UUID((String)row["itemID"]);
  1150. taskItem.ParentPartID = new UUID((String)row["primID"]);
  1151. taskItem.AssetID = new UUID((String)row["assetID"]);
  1152. taskItem.ParentID = new UUID((String)row["parentFolderID"]);
  1153. taskItem.InvType = Convert.ToInt32(row["invType"]);
  1154. taskItem.Type = Convert.ToInt32(row["assetType"]);
  1155. taskItem.Name = (String)row["name"];
  1156. taskItem.Description = (String)row["description"];
  1157. taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
  1158. taskItem.CreatorID = new UUID((String)row["creatorID"]);
  1159. taskItem.OwnerID = new UUID((String)row["ownerID"]);
  1160. taskItem.LastOwnerID = new UUID((String)row["lastOwnerID"]);
  1161. taskItem.GroupID = new UUID((String)row["groupID"]);
  1162. taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
  1163. taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
  1164. taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
  1165. taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
  1166. taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
  1167. taskItem.Flags = Convert.ToUInt32(row["flags"]);
  1168. return taskItem;
  1169. }
  1170. /// <summary>
  1171. /// Build a Land Data from the persisted data.
  1172. /// </summary>
  1173. /// <param name="row"></param>
  1174. /// <returns></returns>
  1175. private LandData buildLandData(DataRow row)
  1176. {
  1177. LandData newData = new LandData();
  1178. newData.GlobalID = new UUID((String) row["UUID"]);
  1179. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  1180. // Bitmap is a byte[512]
  1181. newData.Bitmap = (Byte[]) row["Bitmap"];
  1182. newData.Name = (String) row["Name"];
  1183. newData.Description = (String) row["Desc"];
  1184. newData.OwnerID = (UUID)(String) row["OwnerUUID"];
  1185. newData.IsGroupOwned = (Boolean) row["IsGroupOwned"];
  1186. newData.Area = Convert.ToInt32(row["Area"]);
  1187. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
  1188. newData.Category = (ParcelCategory) Convert.ToInt32(row["Category"]);
  1189. //Enum OpenMetaverse.Parcel.ParcelCategory
  1190. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  1191. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  1192. newData.GroupID = new UUID((String) row["GroupUUID"]);
  1193. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  1194. newData.Status = (ParcelStatus) Convert.ToInt32(row["LandStatus"]);
  1195. //Enum. OpenMetaverse.Parcel.ParcelStatus
  1196. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  1197. newData.LandingType = (Byte) row["LandingType"];
  1198. newData.MediaAutoScale = (Byte) row["MediaAutoScale"];
  1199. newData.MediaID = new UUID((String) row["MediaTextureUUID"]);
  1200. newData.MediaURL = (String) row["MediaURL"];
  1201. newData.MusicURL = (String) row["MusicURL"];
  1202. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  1203. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  1204. newData.SnapshotID = (UUID)(String) row["SnapshotUUID"];
  1205. try
  1206. {
  1207. newData.UserLocation =
  1208. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  1209. Convert.ToSingle(row["UserLocationZ"]));
  1210. newData.UserLookAt =
  1211. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  1212. Convert.ToSingle(row["UserLookAtZ"]));
  1213. }
  1214. catch (InvalidCastException)
  1215. {
  1216. m_log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
  1217. newData.UserLocation = Vector3.Zero;
  1218. newData.UserLookAt = Vector3.Zero;
  1219. }
  1220. newData.ParcelAccessList = new List<ParcelManager.ParcelAccessEntry>();
  1221. UUID authBuyerID = UUID.Zero;
  1222. UUID.TryParse((string)row["AuthbuyerID"], out authBuyerID);
  1223. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  1224. newData.Dwell = Convert.ToInt32(row["Dwell"]);
  1225. return newData;
  1226. }
  1227. private RegionSettings buildRegionSettings(DataRow row)
  1228. {
  1229. RegionSettings newSettings = new RegionSettings();
  1230. newSettings.RegionUUID = new UUID((string) row["regionUUID"]);
  1231. newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
  1232. newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
  1233. newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
  1234. newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
  1235. newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
  1236. newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
  1237. newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
  1238. newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
  1239. newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
  1240. newSettings.Maturity = Convert.ToInt32(row["maturity"]);
  1241. newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
  1242. newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
  1243. newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
  1244. newSettings.TerrainTexture1 = new UUID((String) row["terrain_texture_1"]);
  1245. newSettings.TerrainTexture2 = new UUID((String) row["terrain_texture_2"]);
  1246. newSettings.TerrainTexture3 = new UUID((String) row["terrain_texture_3"]);
  1247. newSettings.TerrainTexture4 = new UUID((String) row["terrain_texture_4"]);
  1248. newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
  1249. newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
  1250. newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
  1251. newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
  1252. newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
  1253. newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
  1254. newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
  1255. newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
  1256. newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
  1257. newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
  1258. newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
  1259. newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
  1260. newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
  1261. newSettings.SunVector = new Vector3 (
  1262. Convert.ToSingle(row["sunvectorx"]),
  1263. Convert.ToSingle(row["sunvectory"]),
  1264. Convert.ToSingle(row["sunvectorz"])
  1265. );
  1266. newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
  1267. newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
  1268. newSettings.Covenant = new UUID((String) row["covenant"]);
  1269. return newSettings;
  1270. }
  1271. /// <summary>
  1272. /// Build a land access entry from the persisted data.
  1273. /// </summary>
  1274. /// <param name="row"></param>
  1275. /// <returns></returns>
  1276. private static ParcelManager.ParcelAccessEntry buildLandAccessData(DataRow row)
  1277. {
  1278. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  1279. entry.AgentID = new UUID((string) row["AccessUUID"]);
  1280. entry.Flags = (AccessList) row["Flags"];
  1281. entry.Time = new DateTime();
  1282. return entry;
  1283. }
  1284. /// <summary>
  1285. ///
  1286. /// </summary>
  1287. /// <param name="val"></param>
  1288. /// <returns></returns>
  1289. private static Array serializeTerrain(double[,] val)
  1290. {
  1291. MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) *sizeof (double));
  1292. BinaryWriter bw = new BinaryWriter(str);
  1293. // TODO: COMPATIBILITY - Add byte-order conversions
  1294. for (int x = 0; x < (int)Constants.RegionSize; x++)
  1295. for (int y = 0; y < (int)Constants.RegionSize; y++)
  1296. bw.Write(val[x, y]);
  1297. return str.ToArray();
  1298. }
  1299. // private void fillTerrainRow(DataRow row, UUID regionUUID, int rev, double[,] val)
  1300. // {
  1301. // row["RegionUUID"] = regionUUID;
  1302. // row["Revision"] = rev;
  1303. // MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize)*sizeof (double));
  1304. // BinaryWriter bw = new BinaryWriter(str);
  1305. // // TODO: COMPATIBILITY - Add byte-order conversions
  1306. // for (int x = 0; x < (int)Constants.RegionSize; x++)
  1307. // for (int y = 0; y < (int)Constants.RegionSize; y++)
  1308. // bw.Write(val[x, y]);
  1309. // row["Heightfield"] = str.ToArray();
  1310. // }
  1311. /// <summary>
  1312. ///
  1313. /// </summary>
  1314. /// <param name="row"></param>
  1315. /// <param name="prim"></param>
  1316. /// <param name="sceneGroupID"></param>
  1317. /// <param name="regionUUID"></param>
  1318. private static void fillPrimRow(DataRow row, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1319. {
  1320. row["UUID"] = prim.UUID.ToString();
  1321. row["RegionUUID"] = regionUUID.ToString();
  1322. row["CreationDate"] = prim.CreationDate;
  1323. row["Name"] = prim.Name;
  1324. row["SceneGroupID"] = sceneGroupID.ToString();
  1325. // the UUID of the root part for this SceneObjectGroup
  1326. // various text fields
  1327. row["Text"] = prim.Text;
  1328. row["Description"] = prim.Description;
  1329. row["SitName"] = prim.SitName;
  1330. row["TouchName"] = prim.TouchName;
  1331. // permissions
  1332. row["ObjectFlags"] = (uint)prim.Flags;
  1333. row["CreatorID"] = prim.CreatorID.ToString();
  1334. row["OwnerID"] = prim.OwnerID.ToString();
  1335. row["GroupID"] = prim.GroupID.ToString();
  1336. row["LastOwnerID"] = prim.LastOwnerID.ToString();
  1337. row["OwnerMask"] = prim.OwnerMask;
  1338. row["NextOwnerMask"] = prim.NextOwnerMask;
  1339. row["GroupMask"] = prim.GroupMask;
  1340. row["EveryoneMask"] = prim.EveryoneMask;
  1341. row["BaseMask"] = prim.BaseMask;
  1342. // vectors
  1343. row["PositionX"] = prim.OffsetPosition.X;
  1344. row["PositionY"] = prim.OffsetPosition.Y;
  1345. row["PositionZ"] = prim.OffsetPosition.Z;
  1346. row["GroupPositionX"] = prim.GroupPosition.X;
  1347. row["GroupPositionY"] = prim.GroupPosition.Y;
  1348. row["GroupPositionZ"] = prim.GroupPosition.Z;
  1349. row["VelocityX"] = prim.Velocity.X;
  1350. row["VelocityY"] = prim.Velocity.Y;
  1351. row["VelocityZ"] = prim.Velocity.Z;
  1352. row["AngularVelocityX"] = prim.AngularVelocity.X;
  1353. row["AngularVelocityY"] = prim.AngularVelocity.Y;
  1354. row["AngularVelocityZ"] = prim.AngularVelocity.Z;
  1355. row["AccelerationX"] = prim.Acceleration.X;
  1356. row["AccelerationY"] = prim.Acceleration.Y;
  1357. row["AccelerationZ"] = prim.Acceleration.Z;
  1358. // quaternions
  1359. row["RotationX"] = prim.RotationOffset.X;
  1360. row["RotationY"] = prim.RotationOffset.Y;
  1361. row["RotationZ"] = prim.RotationOffset.Z;
  1362. row["RotationW"] = prim.RotationOffset.W;
  1363. // Sit target
  1364. Vector3 sitTargetPos = prim.SitTargetPositionLL;
  1365. row["SitTargetOffsetX"] = sitTargetPos.X;
  1366. row["SitTargetOffsetY"] = sitTargetPos.Y;
  1367. row["SitTargetOffsetZ"] = sitTargetPos.Z;
  1368. Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
  1369. row["SitTargetOrientW"] = sitTargetOrient.W;
  1370. row["SitTargetOrientX"] = sitTargetOrient.X;
  1371. row["SitTargetOrientY"] = sitTargetOrient.Y;
  1372. row["SitTargetOrientZ"] = sitTargetOrient.Z;
  1373. row["ColorR"] = Convert.ToInt32(prim.Color.R);
  1374. row["ColorG"] = Convert.ToInt32(prim.Color.G);
  1375. row["ColorB"] = Convert.ToInt32(prim.Color.B);
  1376. row["ColorA"] = Convert.ToInt32(prim.Color.A);
  1377. row["PayPrice"] = prim.PayPrice[0];
  1378. row["PayButton1"] = prim.PayPrice[1];
  1379. row["PayButton2"] = prim.PayPrice[2];
  1380. row["PayButton3"] = prim.PayPrice[3];
  1381. row["PayButton4"] = prim.PayPrice[4];
  1382. row["TextureAnimation"] = Convert.ToBase64String(prim.TextureAnimation);
  1383. row["ParticleSystem"] = Convert.ToBase64String(prim.ParticleSystem);
  1384. row["OmegaX"] = prim.AngularVelocity.X;
  1385. row["OmegaY"] = prim.AngularVelocity.Y;
  1386. row["OmegaZ"] = prim.AngularVelocity.Z;
  1387. row["CameraEyeOffsetX"] = prim.GetCameraEyeOffset().X;
  1388. row["CameraEyeOffsetY"] = prim.GetCameraEyeOffset().Y;
  1389. row["CameraEyeOffsetZ"] = prim.GetCameraEyeOffset().Z;
  1390. row["CameraAtOffsetX"] = prim.GetCameraAtOffset().X;
  1391. row["CameraAtOffsetY"] = prim.GetCameraAtOffset().Y;
  1392. row["CameraAtOffsetZ"] = prim.GetCameraAtOffset().Z;
  1393. if ((prim.SoundFlags & 1) != 0) // Looped
  1394. {
  1395. row["LoopedSound"] = prim.Sound.ToString();
  1396. row["LoopedSoundGain"] = prim.SoundGain;
  1397. }
  1398. else
  1399. {
  1400. row["LoopedSound"] = UUID.Zero.ToString();
  1401. row["LoopedSoundGain"] = 0.0f;
  1402. }
  1403. if (prim.GetForceMouselook())
  1404. row["ForceMouselook"] = 1;
  1405. else
  1406. row["ForceMouselook"] = 0;
  1407. row["ScriptAccessPin"] = prim.ScriptAccessPin;
  1408. if (prim.AllowedDrop)
  1409. row["AllowedDrop"] = 1;
  1410. else
  1411. row["AllowedDrop"] = 0;
  1412. if (prim.DIE_AT_EDGE)
  1413. row["DieAtEdge"] = 1;
  1414. else
  1415. row["DieAtEdge"] = 0;
  1416. row["SalePrice"] = prim.SalePrice;
  1417. row["SaleType"] = Convert.ToInt16(prim.ObjectSaleType);
  1418. // click action
  1419. row["ClickAction"] = prim.ClickAction;
  1420. row["SalePrice"] = prim.SalePrice;
  1421. row["Material"] = prim.Material;
  1422. row["CollisionSound"] = prim.CollisionSound.ToString();
  1423. row["CollisionSoundVolume"] = prim.CollisionSoundVolume;
  1424. if (prim.VolumeDetectActive)
  1425. row["VolumeDetect"] = 1;
  1426. else
  1427. row["VolumeDetect"] = 0;
  1428. }
  1429. /// <summary>
  1430. ///
  1431. /// </summary>
  1432. /// <param name="row"></param>
  1433. /// <param name="taskItem"></param>
  1434. private static void fillItemRow(DataRow row, TaskInventoryItem taskItem)
  1435. {
  1436. row["itemID"] = taskItem.ItemID.ToString();
  1437. row["primID"] = taskItem.ParentPartID.ToString();
  1438. row["assetID"] = taskItem.AssetID.ToString();
  1439. row["parentFolderID"] = taskItem.ParentID.ToString();
  1440. row["invType"] = taskItem.InvType;
  1441. row["assetType"] = taskItem.Type;
  1442. row["name"] = taskItem.Name;
  1443. row["description"] = taskItem.Description;
  1444. row["creationDate"] = taskItem.CreationDate;
  1445. row["creatorID"] = taskItem.CreatorID.ToString();
  1446. row["ownerID"] = taskItem.OwnerID.ToString();
  1447. row["lastOwnerID"] = taskItem.LastOwnerID.ToString();
  1448. row["groupID"] = taskItem.GroupID.ToString();
  1449. row["nextPermissions"] = taskItem.NextPermissions;
  1450. row["currentPermissions"] = taskItem.CurrentPermissions;
  1451. row["basePermissions"] = taskItem.BasePermissions;
  1452. row["everyonePermissions"] = taskItem.EveryonePermissions;
  1453. row["groupPermissions"] = taskItem.GroupPermissions;
  1454. row["flags"] = taskItem.Flags;
  1455. }
  1456. /// <summary>
  1457. ///
  1458. /// </summary>
  1459. /// <param name="row"></param>
  1460. /// <param name="land"></param>
  1461. /// <param name="regionUUID"></param>
  1462. private static void fillLandRow(DataRow row, LandData land, UUID regionUUID)
  1463. {
  1464. row["UUID"] = land.GlobalID.ToString();
  1465. row["RegionUUID"] = regionUUID.ToString();
  1466. row["LocalLandID"] = land.LocalID;
  1467. // Bitmap is a byte[512]
  1468. row["Bitmap"] = land.Bitmap;
  1469. row["Name"] = land.Name;
  1470. row["Desc"] = land.Description;
  1471. row["OwnerUUID"] = land.OwnerID.ToString();
  1472. row["IsGroupOwned"] = land.IsGroupOwned;
  1473. row["Area"] = land.Area;
  1474. row["AuctionID"] = land.AuctionID; //Unemplemented
  1475. row["Category"] = land.Category; //Enum OpenMetaverse.Parcel.ParcelCategory
  1476. row["ClaimDate"] = land.ClaimDate;
  1477. row["ClaimPrice"] = land.ClaimPrice;
  1478. row["GroupUUID"] = land.GroupID.ToString();
  1479. row["SalePrice"] = land.SalePrice;
  1480. row["LandStatus"] = land.Status; //Enum. OpenMetaverse.Parcel.ParcelStatus
  1481. row["LandFlags"] = land.Flags;
  1482. row["LandingType"] = land.LandingType;
  1483. row["MediaAutoScale"] = land.MediaAutoScale;
  1484. row["MediaTextureUUID"] = land.MediaID.ToString();
  1485. row["MediaURL"] = land.MediaURL;
  1486. row["MusicURL"] = land.MusicURL;
  1487. row["PassHours"] = land.PassHours;
  1488. row["PassPrice"] = land.PassPrice;
  1489. row["SnapshotUUID"] = land.SnapshotID.ToString();
  1490. row["UserLocationX"] = land.UserLocation.X;
  1491. row["UserLocationY"] = land.UserLocation.Y;
  1492. row["UserLocationZ"] = land.UserLocation.Z;
  1493. row["UserLookAtX"] = land.UserLookAt.X;
  1494. row["UserLookAtY"] = land.UserLookAt.Y;
  1495. row["UserLookAtZ"] = land.UserLookAt.Z;
  1496. row["AuthbuyerID"] = land.AuthBuyerID.ToString();
  1497. row["OtherCleanTime"] = land.OtherCleanTime;
  1498. row["Dwell"] = land.Dwell;
  1499. }
  1500. /// <summary>
  1501. ///
  1502. /// </summary>
  1503. /// <param name="row"></param>
  1504. /// <param name="entry"></param>
  1505. /// <param name="parcelID"></param>
  1506. private static void fillLandAccessRow(DataRow row, ParcelManager.ParcelAccessEntry entry, UUID parcelID)
  1507. {
  1508. row["LandUUID"] = parcelID.ToString();
  1509. row["AccessUUID"] = entry.AgentID.ToString();
  1510. row["Flags"] = entry.Flags;
  1511. }
  1512. private static void fillRegionSettingsRow(DataRow row, RegionSettings settings)
  1513. {
  1514. row["regionUUID"] = settings.RegionUUID.ToString();
  1515. row["block_terraform"] = settings.BlockTerraform;
  1516. row["block_fly"] = settings.BlockFly;
  1517. row["allow_damage"] = settings.AllowDamage;
  1518. row["restrict_pushing"] = settings.RestrictPushing;
  1519. row["allow_land_resell"] = settings.AllowLandResell;
  1520. row["allow_land_join_divide"] = settings.AllowLandJoinDivide;
  1521. row["block_show_in_search"] = settings.BlockShowInSearch;
  1522. row["agent_limit"] = settings.AgentLimit;
  1523. row["object_bonus"] = settings.ObjectBonus;
  1524. row["maturity"] = settings.Maturity;
  1525. row["disable_scripts"] = settings.DisableScripts;
  1526. row["disable_collisions"] = settings.DisableCollisions;
  1527. row["disable_physics"] = settings.DisablePhysics;
  1528. row["terrain_texture_1"] = settings.TerrainTexture1.ToString();
  1529. row["terrain_texture_2"] = settings.TerrainTexture2.ToString();
  1530. row["terrain_texture_3"] = settings.TerrainTexture3.ToString();
  1531. row["terrain_texture_4"] = settings.TerrainTexture4.ToString();
  1532. row["elevation_1_nw"] = settings.Elevation1NW;
  1533. row["elevation_2_nw"] = settings.Elevation2NW;
  1534. row["elevation_1_ne"] = settings.Elevation1NE;
  1535. row["elevation_2_ne"] = settings.Elevation2NE;
  1536. row["elevation_1_se"] = settings.Elevation1SE;
  1537. row["elevation_2_se"] = settings.Elevation2SE;
  1538. row["elevation_1_sw"] = settings.Elevation1SW;
  1539. row["elevation_2_sw"] = settings.Elevation2SW;
  1540. row["water_height"] = settings.WaterHeight;
  1541. row["terrain_raise_limit"] = settings.TerrainRaiseLimit;
  1542. row["terrain_lower_limit"] = settings.TerrainLowerLimit;
  1543. row["use_estate_sun"] = settings.UseEstateSun;
  1544. row["Sandbox"] = settings.Sandbox; // database uses upper case S for sandbox
  1545. row["sunvectorx"] = settings.SunVector.X;
  1546. row["sunvectory"] = settings.SunVector.Y;
  1547. row["sunvectorz"] = settings.SunVector.Z;
  1548. row["fixed_sun"] = settings.FixedSun;
  1549. row["sun_position"] = settings.SunPosition;
  1550. row["covenant"] = settings.Covenant.ToString();
  1551. }
  1552. /// <summary>
  1553. ///
  1554. /// </summary>
  1555. /// <param name="row"></param>
  1556. /// <returns></returns>
  1557. private PrimitiveBaseShape buildShape(DataRow row)
  1558. {
  1559. PrimitiveBaseShape s = new PrimitiveBaseShape();
  1560. s.Scale = new Vector3(
  1561. Convert.ToSingle(row["ScaleX"]),
  1562. Convert.ToSingle(row["ScaleY"]),
  1563. Convert.ToSingle(row["ScaleZ"])
  1564. );
  1565. // paths
  1566. s.PCode = Convert.ToByte(row["PCode"]);
  1567. s.PathBegin = Convert.ToUInt16(row["PathBegin"]);
  1568. s.PathEnd = Convert.ToUInt16(row["PathEnd"]);
  1569. s.PathScaleX = Convert.ToByte(row["PathScaleX"]);
  1570. s.PathScaleY = Convert.ToByte(row["PathScaleY"]);
  1571. s.PathShearX = Convert.ToByte(row["PathShearX"]);
  1572. s.PathShearY = Convert.ToByte(row["PathShearY"]);
  1573. s.PathSkew = Convert.ToSByte(row["PathSkew"]);
  1574. s.PathCurve = Convert.ToByte(row["PathCurve"]);
  1575. s.PathRadiusOffset = Convert.ToSByte(row["PathRadiusOffset"]);
  1576. s.PathRevolutions = Convert.ToByte(row["PathRevolutions"]);
  1577. s.PathTaperX = Convert.ToSByte(row["PathTaperX"]);
  1578. s.PathTaperY = Convert.ToSByte(row["PathTaperY"]);
  1579. s.PathTwist = Convert.ToSByte(row["PathTwist"]);
  1580. s.PathTwistBegin = Convert.ToSByte(row["PathTwistBegin"]);
  1581. // profile
  1582. s.ProfileBegin = Convert.ToUInt16(row["ProfileBegin"]);
  1583. s.ProfileEnd = Convert.ToUInt16(row["ProfileEnd"]);
  1584. s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]);
  1585. s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]);
  1586. s.State = Convert.ToByte(row["State"]);
  1587. byte[] textureEntry = (byte[])row["Texture"];
  1588. s.TextureEntry = textureEntry;
  1589. s.ExtraParams = (byte[]) row["ExtraParams"];
  1590. return s;
  1591. }
  1592. /// <summary>
  1593. ///
  1594. /// </summary>
  1595. /// <param name="row"></param>
  1596. /// <param name="prim"></param>
  1597. private static void fillShapeRow(DataRow row, SceneObjectPart prim)
  1598. {
  1599. PrimitiveBaseShape s = prim.Shape;
  1600. row["UUID"] = prim.UUID.ToString();
  1601. // shape is an enum
  1602. row["Shape"] = 0;
  1603. // vectors
  1604. row["ScaleX"] = s.Scale.X;
  1605. row["ScaleY"] = s.Scale.Y;
  1606. row["ScaleZ"] = s.Scale.Z;
  1607. // paths
  1608. row["PCode"] = s.PCode;
  1609. row["PathBegin"] = s.PathBegin;
  1610. row["PathEnd"] = s.PathEnd;
  1611. row["PathScaleX"] = s.PathScaleX;
  1612. row["PathScaleY"] = s.PathScaleY;
  1613. row["PathShearX"] = s.PathShearX;
  1614. row["PathShearY"] = s.PathShearY;
  1615. row["PathSkew"] = s.PathSkew;
  1616. row["PathCurve"] = s.PathCurve;
  1617. row["PathRadiusOffset"] = s.PathRadiusOffset;
  1618. row["PathRevolutions"] = s.PathRevolutions;
  1619. row["PathTaperX"] = s.PathTaperX;
  1620. row["PathTaperY"] = s.PathTaperY;
  1621. row["PathTwist"] = s.PathTwist;
  1622. row["PathTwistBegin"] = s.PathTwistBegin;
  1623. // profile
  1624. row["ProfileBegin"] = s.ProfileBegin;
  1625. row["ProfileEnd"] = s.ProfileEnd;
  1626. row["ProfileCurve"] = s.ProfileCurve;
  1627. row["ProfileHollow"] = s.ProfileHollow;
  1628. row["State"] = s.State;
  1629. row["Texture"] = s.TextureEntry;
  1630. row["ExtraParams"] = s.ExtraParams;
  1631. }
  1632. /// <summary>
  1633. ///
  1634. /// </summary>
  1635. /// <param name="prim"></param>
  1636. /// <param name="sceneGroupID"></param>
  1637. /// <param name="regionUUID"></param>
  1638. private void addPrim(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1639. {
  1640. DataTable prims = ds.Tables["prims"];
  1641. DataTable shapes = ds.Tables["primshapes"];
  1642. DataRow primRow = prims.Rows.Find(prim.UUID.ToString());
  1643. if (primRow == null)
  1644. {
  1645. primRow = prims.NewRow();
  1646. fillPrimRow(primRow, prim, sceneGroupID, regionUUID);
  1647. prims.Rows.Add(primRow);
  1648. }
  1649. else
  1650. {
  1651. fillPrimRow(primRow, prim, sceneGroupID, regionUUID);
  1652. }
  1653. DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
  1654. if (shapeRow == null)
  1655. {
  1656. shapeRow = shapes.NewRow();
  1657. fillShapeRow(shapeRow, prim);
  1658. shapes.Rows.Add(shapeRow);
  1659. }
  1660. else
  1661. {
  1662. fillShapeRow(shapeRow, prim);
  1663. }
  1664. }
  1665. /// <summary>
  1666. /// see IRegionDatastore
  1667. /// </summary>
  1668. /// <param name="primID"></param>
  1669. /// <param name="items"></param>
  1670. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  1671. {
  1672. m_log.InfoFormat("[REGION DB]: Entered StorePrimInventory with prim ID {0}", primID);
  1673. DataTable dbItems = ds.Tables["primitems"];
  1674. // For now, we're just going to crudely remove all the previous inventory items
  1675. // no matter whether they have changed or not, and replace them with the current set.
  1676. lock (ds)
  1677. {
  1678. RemoveItems(primID);
  1679. // repalce with current inventory details
  1680. foreach (TaskInventoryItem newItem in items)
  1681. {
  1682. // m_log.InfoFormat(
  1683. // "[DATASTORE]: ",
  1684. // "Adding item {0}, {1} to prim ID {2}",
  1685. // newItem.Name, newItem.ItemID, newItem.ParentPartID);
  1686. DataRow newItemRow = dbItems.NewRow();
  1687. fillItemRow(newItemRow, newItem);
  1688. dbItems.Rows.Add(newItemRow);
  1689. }
  1690. }
  1691. Commit();
  1692. }
  1693. /***********************************************************************
  1694. *
  1695. * SQL Statement Creation Functions
  1696. *
  1697. * These functions create SQL statements for update, insert, and create.
  1698. * They can probably be factored later to have a db independant
  1699. * portion and a db specific portion
  1700. *
  1701. **********************************************************************/
  1702. /// <summary>
  1703. /// Create an insert command
  1704. /// </summary>
  1705. /// <param name="table">table name</param>
  1706. /// <param name="dt">data table</param>
  1707. /// <returns>the created command</returns>
  1708. /// <remarks>
  1709. /// This is subtle enough to deserve some commentary.
  1710. /// Instead of doing *lots* and *lots of hardcoded strings
  1711. /// for database definitions we'll use the fact that
  1712. /// realistically all insert statements look like "insert
  1713. /// into A(b, c) values(:b, :c) on the parameterized query
  1714. /// front. If we just have a list of b, c, etc... we can
  1715. /// generate these strings instead of typing them out.
  1716. /// </remarks>
  1717. private static SqliteCommand createInsertCommand(string table, DataTable dt)
  1718. {
  1719. string[] cols = new string[dt.Columns.Count];
  1720. for (int i = 0; i < dt.Columns.Count; i++)
  1721. {
  1722. DataColumn col = dt.Columns[i];
  1723. cols[i] = col.ColumnName;
  1724. }
  1725. string sql = "insert into " + table + "(";
  1726. sql += String.Join(", ", cols);
  1727. // important, the first ':' needs to be here, the rest get added in the join
  1728. sql += ") values (:";
  1729. sql += String.Join(", :", cols);
  1730. sql += ")";
  1731. SqliteCommand cmd = new SqliteCommand(sql);
  1732. // this provides the binding for all our parameters, so
  1733. // much less code than it used to be
  1734. foreach (DataColumn col in dt.Columns)
  1735. {
  1736. cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
  1737. }
  1738. return cmd;
  1739. }
  1740. /// <summary>
  1741. /// create an update command
  1742. /// </summary>
  1743. /// <param name="table">table name</param>
  1744. /// <param name="pk"></param>
  1745. /// <param name="dt"></param>
  1746. /// <returns>the created command</returns>
  1747. private static SqliteCommand createUpdateCommand(string table, string pk, DataTable dt)
  1748. {
  1749. string sql = "update " + table + " set ";
  1750. string subsql = String.Empty;
  1751. foreach (DataColumn col in dt.Columns)
  1752. {
  1753. if (subsql.Length > 0)
  1754. {
  1755. // a map function would rock so much here
  1756. subsql += ", ";
  1757. }
  1758. subsql += col.ColumnName + "= :" + col.ColumnName;
  1759. }
  1760. sql += subsql;
  1761. sql += " where " + pk;
  1762. SqliteCommand cmd = new SqliteCommand(sql);
  1763. // this provides the binding for all our parameters, so
  1764. // much less code than it used to be
  1765. foreach (DataColumn col in dt.Columns)
  1766. {
  1767. cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
  1768. }
  1769. return cmd;
  1770. }
  1771. /// <summary>
  1772. /// create an update command
  1773. /// </summary>
  1774. /// <param name="table">table name</param>
  1775. /// <param name="pk"></param>
  1776. /// <param name="dt"></param>
  1777. /// <returns>the created command</returns>
  1778. private static SqliteCommand createUpdateCommand(string table, string pk1, string pk2, DataTable dt)
  1779. {
  1780. string sql = "update " + table + " set ";
  1781. string subsql = String.Empty;
  1782. foreach (DataColumn col in dt.Columns)
  1783. {
  1784. if (subsql.Length > 0)
  1785. {
  1786. // a map function would rock so much here
  1787. subsql += ", ";
  1788. }
  1789. subsql += col.ColumnName + "= :" + col.ColumnName;
  1790. }
  1791. sql += subsql;
  1792. sql += " where " + pk1 + " and " + pk2;
  1793. SqliteCommand cmd = new SqliteCommand(sql);
  1794. // this provides the binding for all our parameters, so
  1795. // much less code than it used to be
  1796. foreach (DataColumn col in dt.Columns)
  1797. {
  1798. cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
  1799. }
  1800. return cmd;
  1801. }
  1802. /// <summary>
  1803. ///
  1804. /// </summary>
  1805. /// <param name="dt">Data Table</param>
  1806. /// <returns></returns>
  1807. // private static string defineTable(DataTable dt)
  1808. // {
  1809. // string sql = "create table " + dt.TableName + "(";
  1810. // string subsql = String.Empty;
  1811. // foreach (DataColumn col in dt.Columns)
  1812. // {
  1813. // if (subsql.Length > 0)
  1814. // {
  1815. // // a map function would rock so much here
  1816. // subsql += ",\n";
  1817. // }
  1818. // subsql += col.ColumnName + " " + sqliteType(col.DataType);
  1819. // if (dt.PrimaryKey.Length > 0 && col == dt.PrimaryKey[0])
  1820. // {
  1821. // subsql += " primary key";
  1822. // }
  1823. // }
  1824. // sql += subsql;
  1825. // sql += ")";
  1826. // return sql;
  1827. // }
  1828. /***********************************************************************
  1829. *
  1830. * Database Binding functions
  1831. *
  1832. * These will be db specific due to typing, and minor differences
  1833. * in databases.
  1834. *
  1835. **********************************************************************/
  1836. ///<summary>
  1837. /// This is a convenience function that collapses 5 repetitive
  1838. /// lines for defining SqliteParameters to 2 parameters:
  1839. /// column name and database type.
  1840. ///
  1841. /// It assumes certain conventions like :param as the param
  1842. /// name to replace in parametrized queries, and that source
  1843. /// version is always current version, both of which are fine
  1844. /// for us.
  1845. ///</summary>
  1846. ///<returns>a built sqlite parameter</returns>
  1847. private static SqliteParameter createSqliteParameter(string name, Type type)
  1848. {
  1849. SqliteParameter param = new SqliteParameter();
  1850. param.ParameterName = ":" + name;
  1851. param.DbType = dbtypeFromType(type);
  1852. param.SourceColumn = name;
  1853. param.SourceVersion = DataRowVersion.Current;
  1854. return param;
  1855. }
  1856. /// <summary>
  1857. ///
  1858. /// </summary>
  1859. /// <param name="da"></param>
  1860. /// <param name="conn"></param>
  1861. private void setupPrimCommands(SqliteDataAdapter da, SqliteConnection conn)
  1862. {
  1863. da.InsertCommand = createInsertCommand("prims", ds.Tables["prims"]);
  1864. da.InsertCommand.Connection = conn;
  1865. da.UpdateCommand = createUpdateCommand("prims", "UUID=:UUID", ds.Tables["prims"]);
  1866. da.UpdateCommand.Connection = conn;
  1867. SqliteCommand delete = new SqliteCommand("delete from prims where UUID = :UUID");
  1868. delete.Parameters.Add(createSqliteParameter("UUID", typeof (String)));
  1869. delete.Connection = conn;
  1870. da.DeleteCommand = delete;
  1871. }
  1872. /// <summary>
  1873. ///
  1874. /// </summary>
  1875. /// <param name="da"></param>
  1876. /// <param name="conn"></param>
  1877. private void setupItemsCommands(SqliteDataAdapter da, SqliteConnection conn)
  1878. {
  1879. da.InsertCommand = createInsertCommand("primitems", ds.Tables["primitems"]);
  1880. da.InsertCommand.Connection = conn;
  1881. da.UpdateCommand = createUpdateCommand("primitems", "itemID = :itemID", ds.Tables["primitems"]);
  1882. da.UpdateCommand.Connection = conn;
  1883. SqliteCommand delete = new SqliteCommand("delete from primitems where itemID = :itemID");
  1884. delete.Parameters.Add(createSqliteParameter("itemID", typeof (String)));
  1885. delete.Connection = conn;
  1886. da.DeleteCommand = delete;
  1887. }
  1888. /// <summary>
  1889. ///
  1890. /// </summary>
  1891. /// <param name="da"></param>
  1892. /// <param name="conn"></param>
  1893. private void setupTerrainCommands(SqliteDataAdapter da, SqliteConnection conn)
  1894. {
  1895. da.InsertCommand = createInsertCommand("terrain", ds.Tables["terrain"]);
  1896. da.InsertCommand.Connection = conn;
  1897. }
  1898. /// <summary>
  1899. ///
  1900. /// </summary>
  1901. /// <param name="da"></param>
  1902. /// <param name="conn"></param>
  1903. private void setupLandCommands(SqliteDataAdapter da, SqliteConnection conn)
  1904. {
  1905. da.InsertCommand = createInsertCommand("land", ds.Tables["land"]);
  1906. da.InsertCommand.Connection = conn;
  1907. da.UpdateCommand = createUpdateCommand("land", "UUID=:UUID", ds.Tables["land"]);
  1908. da.UpdateCommand.Connection = conn;
  1909. SqliteCommand delete = new SqliteCommand("delete from land where UUID=:UUID");
  1910. delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
  1911. da.DeleteCommand = delete;
  1912. da.DeleteCommand.Connection = conn;
  1913. }
  1914. /// <summary>
  1915. ///
  1916. /// </summary>
  1917. /// <param name="da"></param>
  1918. /// <param name="conn"></param>
  1919. private void setupLandAccessCommands(SqliteDataAdapter da, SqliteConnection conn)
  1920. {
  1921. da.InsertCommand = createInsertCommand("landaccesslist", ds.Tables["landaccesslist"]);
  1922. da.InsertCommand.Connection = conn;
  1923. da.UpdateCommand = createUpdateCommand("landaccesslist", "LandUUID=:landUUID", "AccessUUID=:AccessUUID", ds.Tables["landaccesslist"]);
  1924. da.UpdateCommand.Connection = conn;
  1925. SqliteCommand delete = new SqliteCommand("delete from landaccesslist where LandUUID= :LandUUID and AccessUUID= :AccessUUID");
  1926. delete.Parameters.Add(createSqliteParameter("LandUUID", typeof(String)));
  1927. delete.Parameters.Add(createSqliteParameter("AccessUUID", typeof(String)));
  1928. da.DeleteCommand = delete;
  1929. da.DeleteCommand.Connection = conn;
  1930. }
  1931. private void setupRegionSettingsCommands(SqliteDataAdapter da, SqliteConnection conn)
  1932. {
  1933. da.InsertCommand = createInsertCommand("regionsettings", ds.Tables["regionsettings"]);
  1934. da.InsertCommand.Connection = conn;
  1935. da.UpdateCommand = createUpdateCommand("regionsettings", "regionUUID=:regionUUID", ds.Tables["regionsettings"]);
  1936. da.UpdateCommand.Connection = conn;
  1937. }
  1938. /// <summary>
  1939. ///
  1940. /// </summary>
  1941. /// <param name="da"></param>
  1942. /// <param name="conn"></param>
  1943. private void setupShapeCommands(SqliteDataAdapter da, SqliteConnection conn)
  1944. {
  1945. da.InsertCommand = createInsertCommand("primshapes", ds.Tables["primshapes"]);
  1946. da.InsertCommand.Connection = conn;
  1947. da.UpdateCommand = createUpdateCommand("primshapes", "UUID=:UUID", ds.Tables["primshapes"]);
  1948. da.UpdateCommand.Connection = conn;
  1949. SqliteCommand delete = new SqliteCommand("delete from primshapes where UUID = :UUID");
  1950. delete.Parameters.Add(createSqliteParameter("UUID", typeof (String)));
  1951. delete.Connection = conn;
  1952. da.DeleteCommand = delete;
  1953. }
  1954. /***********************************************************************
  1955. *
  1956. * Type conversion functions
  1957. *
  1958. **********************************************************************/
  1959. /// <summary>
  1960. /// Type conversion function
  1961. /// </summary>
  1962. /// <param name="type"></param>
  1963. /// <returns></returns>
  1964. private static DbType dbtypeFromType(Type type)
  1965. {
  1966. if (type == typeof (String))
  1967. {
  1968. return DbType.String;
  1969. }
  1970. else if (type == typeof (Int32))
  1971. {
  1972. return DbType.Int32;
  1973. }
  1974. else if (type == typeof (Double))
  1975. {
  1976. return DbType.Double;
  1977. }
  1978. else if (type == typeof (Byte))
  1979. {
  1980. return DbType.Byte;
  1981. }
  1982. else if (type == typeof (Double))
  1983. {
  1984. return DbType.Double;
  1985. }
  1986. else if (type == typeof (Byte[]))
  1987. {
  1988. return DbType.Binary;
  1989. }
  1990. else
  1991. {
  1992. return DbType.String;
  1993. }
  1994. }
  1995. }
  1996. }