SQLiteRegionData.cs 91 KB

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