SQLiteRegionData.cs 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Data;
  30. using System.Drawing;
  31. using System.IO;
  32. using System.Reflection;
  33. using log4net;
  34. using Mono.Data.SqliteClient;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Region.Framework.Interfaces;
  38. using OpenSim.Region.Framework.Scenes;
  39. namespace OpenSim.Data.SQLite
  40. {
  41. /// <summary>
  42. /// A RegionData Interface to the SQLite database
  43. /// </summary>
  44. public class SQLiteRegionData : IRegionDataStore
  45. {
  46. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  47. private const string primSelect = "select * from prims";
  48. private const string shapeSelect = "select * from primshapes";
  49. private const string itemsSelect = "select * from primitems";
  50. private const string terrainSelect = "select * from terrain limit 1";
  51. private const string landSelect = "select * from land";
  52. private const string landAccessListSelect = "select distinct * from landaccesslist";
  53. private const string regionbanListSelect = "select * from regionban";
  54. private const string regionSettingsSelect = "select * from regionsettings";
  55. private DataSet ds;
  56. private SqliteDataAdapter primDa;
  57. private SqliteDataAdapter shapeDa;
  58. private SqliteDataAdapter itemsDa;
  59. private SqliteDataAdapter terrainDa;
  60. private SqliteDataAdapter landDa;
  61. private SqliteDataAdapter landAccessListDa;
  62. private SqliteDataAdapter regionSettingsDa;
  63. private SqliteConnection m_conn;
  64. private String m_connectionString;
  65. // Temporary attribute while this is experimental
  66. /***********************************************************************
  67. *
  68. * Public Interface Functions
  69. *
  70. **********************************************************************/
  71. /// <summary>
  72. /// See IRegionDataStore
  73. /// <list type="bullet">
  74. /// <item>Initialises RegionData Interface</item>
  75. /// <item>Loads and initialises a new SQLite connection and maintains it.</item>
  76. /// </list>
  77. /// </summary>
  78. /// <param name="connectionString">the connection string</param>
  79. public void Initialise(string connectionString)
  80. {
  81. m_connectionString = connectionString;
  82. ds = new DataSet();
  83. m_log.Info("[REGION DB]: Sqlite - connecting: " + connectionString);
  84. m_conn = new SqliteConnection(m_connectionString);
  85. m_conn.Open();
  86. SqliteCommand primSelectCmd = new SqliteCommand(primSelect, m_conn);
  87. primDa = new SqliteDataAdapter(primSelectCmd);
  88. // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa);
  89. SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, m_conn);
  90. shapeDa = new SqliteDataAdapter(shapeSelectCmd);
  91. // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa);
  92. SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, m_conn);
  93. itemsDa = new SqliteDataAdapter(itemsSelectCmd);
  94. SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, m_conn);
  95. terrainDa = new SqliteDataAdapter(terrainSelectCmd);
  96. SqliteCommand landSelectCmd = new SqliteCommand(landSelect, m_conn);
  97. landDa = new SqliteDataAdapter(landSelectCmd);
  98. SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn);
  99. landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd);
  100. SqliteCommand regionSettingsSelectCmd = new SqliteCommand(regionSettingsSelect, m_conn);
  101. regionSettingsDa = new SqliteDataAdapter(regionSettingsSelectCmd);
  102. // This actually does the roll forward assembly stuff
  103. Assembly assem = GetType().Assembly;
  104. Migration m = new Migration(m_conn, assem, "RegionStore");
  105. m.Update();
  106. lock (ds)
  107. {
  108. ds.Tables.Add(createPrimTable());
  109. setupPrimCommands(primDa, m_conn);
  110. primDa.Fill(ds.Tables["prims"]);
  111. ds.Tables.Add(createShapeTable());
  112. setupShapeCommands(shapeDa, m_conn);
  113. ds.Tables.Add(createItemsTable());
  114. setupItemsCommands(itemsDa, m_conn);
  115. itemsDa.Fill(ds.Tables["primitems"]);
  116. ds.Tables.Add(createTerrainTable());
  117. setupTerrainCommands(terrainDa, m_conn);
  118. ds.Tables.Add(createLandTable());
  119. setupLandCommands(landDa, m_conn);
  120. ds.Tables.Add(createLandAccessListTable());
  121. setupLandAccessCommands(landAccessListDa, m_conn);
  122. ds.Tables.Add(createRegionSettingsTable());
  123. setupRegionSettingsCommands(regionSettingsDa, m_conn);
  124. // WORKAROUND: This is a work around for sqlite on
  125. // windows, which gets really unhappy with blob columns
  126. // that have no sample data in them. At some point we
  127. // need to actually find a proper way to handle this.
  128. try
  129. {
  130. shapeDa.Fill(ds.Tables["primshapes"]);
  131. }
  132. catch (Exception)
  133. {
  134. m_log.Info("[REGION DB]: Caught fill error on primshapes table");
  135. }
  136. try
  137. {
  138. terrainDa.Fill(ds.Tables["terrain"]);
  139. }
  140. catch (Exception)
  141. {
  142. m_log.Info("[REGION DB]: Caught fill error on terrain table");
  143. }
  144. try
  145. {
  146. landDa.Fill(ds.Tables["land"]);
  147. }
  148. catch (Exception)
  149. {
  150. m_log.Info("[REGION DB]: Caught fill error on land table");
  151. }
  152. try
  153. {
  154. landAccessListDa.Fill(ds.Tables["landaccesslist"]);
  155. }
  156. catch (Exception)
  157. {
  158. m_log.Info("[REGION DB]: Caught fill error on landaccesslist table");
  159. }
  160. try
  161. {
  162. regionSettingsDa.Fill(ds.Tables["regionsettings"]);
  163. }
  164. catch (Exception)
  165. {
  166. m_log.Info("[REGION DB]: Caught fill error on regionsettings table");
  167. }
  168. return;
  169. }
  170. }
  171. public void Dispose()
  172. {
  173. if (m_conn != null)
  174. {
  175. m_conn.Close();
  176. m_conn = null;
  177. }
  178. if (ds != null)
  179. {
  180. ds.Dispose();
  181. ds = null;
  182. }
  183. if (primDa != null)
  184. {
  185. primDa.Dispose();
  186. primDa = null;
  187. }
  188. if (shapeDa != null)
  189. {
  190. shapeDa.Dispose();
  191. shapeDa = null;
  192. }
  193. if (itemsDa != null)
  194. {
  195. itemsDa.Dispose();
  196. itemsDa = null;
  197. }
  198. if (terrainDa != null)
  199. {
  200. terrainDa.Dispose();
  201. terrainDa = null;
  202. }
  203. if (landDa != null)
  204. {
  205. landDa.Dispose();
  206. landDa = null;
  207. }
  208. if (landAccessListDa != null)
  209. {
  210. landAccessListDa.Dispose();
  211. landAccessListDa = null;
  212. }
  213. if (regionSettingsDa != null)
  214. {
  215. regionSettingsDa.Dispose();
  216. regionSettingsDa = null;
  217. }
  218. }
  219. public void StoreRegionSettings(RegionSettings rs)
  220. {
  221. lock (ds)
  222. {
  223. DataTable regionsettings = ds.Tables["regionsettings"];
  224. DataRow settingsRow = regionsettings.Rows.Find(rs.RegionUUID.ToString());
  225. if (settingsRow == null)
  226. {
  227. settingsRow = regionsettings.NewRow();
  228. fillRegionSettingsRow(settingsRow, rs);
  229. regionsettings.Rows.Add(settingsRow);
  230. }
  231. else
  232. {
  233. fillRegionSettingsRow(settingsRow, rs);
  234. }
  235. Commit();
  236. }
  237. }
  238. public RegionSettings LoadRegionSettings(UUID regionUUID)
  239. {
  240. lock (ds)
  241. {
  242. DataTable regionsettings = ds.Tables["regionsettings"];
  243. string searchExp = "regionUUID = '" + regionUUID.ToString() + "'";
  244. DataRow[] rawsettings = regionsettings.Select(searchExp);
  245. if (rawsettings.Length == 0)
  246. {
  247. RegionSettings rs = new RegionSettings();
  248. rs.RegionUUID = regionUUID;
  249. rs.OnSave += StoreRegionSettings;
  250. StoreRegionSettings(rs);
  251. return rs;
  252. }
  253. DataRow row = rawsettings[0];
  254. RegionSettings newSettings = buildRegionSettings(row);
  255. newSettings.OnSave += StoreRegionSettings;
  256. return newSettings;
  257. }
  258. }
  259. /// <summary>
  260. /// Adds an object into region storage
  261. /// </summary>
  262. /// <param name="obj">the object</param>
  263. /// <param name="regionUUID">the region UUID</param>
  264. public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
  265. {
  266. uint flags = obj.RootPart.GetEffectiveObjectFlags();
  267. // Eligibility check
  268. //
  269. if ((flags & (uint)PrimFlags.Temporary) != 0)
  270. return;
  271. if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
  272. return;
  273. lock (ds)
  274. {
  275. foreach (SceneObjectPart prim in obj.Children.Values)
  276. {
  277. m_log.Info("[REGION DB]: Adding obj: " + obj.UUID + " to region: " + regionUUID);
  278. addPrim(prim, obj.UUID, regionUUID);
  279. }
  280. }
  281. Commit();
  282. // m_log.Info("[Dump of prims]: " + ds.GetXml());
  283. }
  284. /// <summary>
  285. /// Removes an object from region storage
  286. /// </summary>
  287. /// <param name="obj">the object</param>
  288. /// <param name="regionUUID">the region UUID</param>
  289. public void RemoveObject(UUID obj, UUID regionUUID)
  290. {
  291. m_log.InfoFormat("[REGION DB]: Removing obj: {0} from region: {1}", obj.Guid, regionUUID);
  292. DataTable prims = ds.Tables["prims"];
  293. DataTable shapes = ds.Tables["primshapes"];
  294. string selectExp = "SceneGroupID = '" + obj + "' and RegionUUID = '" + regionUUID + "'";
  295. lock (ds)
  296. {
  297. DataRow[] primRows = prims.Select(selectExp);
  298. foreach (DataRow row in primRows)
  299. {
  300. // Remove shape rows
  301. UUID uuid = new UUID((string) row["UUID"]);
  302. DataRow shapeRow = shapes.Rows.Find(uuid.ToString());
  303. if (shapeRow != null)
  304. {
  305. shapeRow.Delete();
  306. }
  307. RemoveItems(uuid);
  308. // Remove prim row
  309. row.Delete();
  310. }
  311. }
  312. Commit();
  313. }
  314. /// <summary>
  315. /// Remove all persisted items of the given prim.
  316. /// The caller must acquire the necessrary synchronization locks and commit or rollback changes.
  317. /// </summary>
  318. /// <param name="uuid">The item UUID</param>
  319. private void RemoveItems(UUID uuid)
  320. {
  321. DataTable items = ds.Tables["primitems"];
  322. String sql = String.Format("primID = '{0}'", uuid);
  323. DataRow[] itemRows = items.Select(sql);
  324. foreach (DataRow itemRow in itemRows)
  325. {
  326. itemRow.Delete();
  327. }
  328. }
  329. /// <summary>
  330. /// Load persisted objects from region storage.
  331. /// </summary>
  332. /// <param name="regionUUID">The region UUID</param>
  333. /// <returns>List of loaded groups</returns>
  334. public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
  335. {
  336. Dictionary<UUID, SceneObjectGroup> createdObjects = new Dictionary<UUID, SceneObjectGroup>();
  337. List<SceneObjectGroup> retvals = new List<SceneObjectGroup>();
  338. DataTable prims = ds.Tables["prims"];
  339. DataTable shapes = ds.Tables["primshapes"];
  340. string byRegion = "RegionUUID = '" + regionUUID + "'";
  341. lock (ds)
  342. {
  343. DataRow[] primsForRegion = prims.Select(byRegion);
  344. m_log.Info("[REGION DB]: Loaded " + primsForRegion.Length + " prims for region: " + regionUUID);
  345. // First, create all groups
  346. foreach (DataRow primRow in primsForRegion)
  347. {
  348. try
  349. {
  350. SceneObjectPart prim = null;
  351. string uuid = (string) primRow["UUID"];
  352. string objID = (string) primRow["SceneGroupID"];
  353. if (uuid == objID) //is new SceneObjectGroup ?
  354. {
  355. SceneObjectGroup group = new SceneObjectGroup();
  356. prim = buildPrim(primRow);
  357. DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
  358. if (shapeRow != null)
  359. {
  360. prim.Shape = buildShape(shapeRow);
  361. }
  362. else
  363. {
  364. m_log.Info(
  365. "[REGION DB]: No shape found for prim in storage, so setting default box shape");
  366. prim.Shape = PrimitiveBaseShape.Default;
  367. }
  368. group.SetRootPart(prim);
  369. createdObjects.Add(group.UUID, group);
  370. retvals.Add(group);
  371. LoadItems(prim);
  372. }
  373. }
  374. catch (Exception e)
  375. {
  376. m_log.Error("[REGION DB]: Failed create prim object in new group, exception and data follows");
  377. m_log.Info("[REGION DB]: " + e.ToString());
  378. foreach (DataColumn col in prims.Columns)
  379. {
  380. m_log.Info("[REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]);
  381. }
  382. }
  383. }
  384. // Now fill the groups with part data
  385. foreach (DataRow primRow in primsForRegion)
  386. {
  387. try
  388. {
  389. SceneObjectPart prim = null;
  390. string uuid = (string) primRow["UUID"];
  391. string objID = (string) primRow["SceneGroupID"];
  392. if (uuid != objID) //is new SceneObjectGroup ?
  393. {
  394. prim = buildPrim(primRow);
  395. DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
  396. if (shapeRow != null)
  397. {
  398. prim.Shape = buildShape(shapeRow);
  399. }
  400. else
  401. {
  402. m_log.Warn(
  403. "[REGION DB]: No shape found for prim in storage, so setting default box shape");
  404. prim.Shape = PrimitiveBaseShape.Default;
  405. }
  406. createdObjects[new UUID(objID)].AddPart(prim);
  407. LoadItems(prim);
  408. }
  409. }
  410. catch (Exception e)
  411. {
  412. m_log.Error("[REGION DB]: Failed create prim object in group, exception and data follows");
  413. m_log.Info("[REGION DB]: " + e.ToString());
  414. foreach (DataColumn col in prims.Columns)
  415. {
  416. m_log.Info("[REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]);
  417. }
  418. }
  419. }
  420. }
  421. return retvals;
  422. }
  423. /// <summary>
  424. /// Load in a prim's persisted inventory.
  425. /// </summary>
  426. /// <param name="prim">the prim</param>
  427. private void LoadItems(SceneObjectPart prim)
  428. {
  429. //m_log.DebugFormat("[DATASTORE]: Loading inventory for {0}, {1}", prim.Name, prim.UUID);
  430. DataTable dbItems = ds.Tables["primitems"];
  431. String sql = String.Format("primID = '{0}'", prim.UUID.ToString());
  432. DataRow[] dbItemRows = dbItems.Select(sql);
  433. IList<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
  434. foreach (DataRow row in dbItemRows)
  435. {
  436. TaskInventoryItem item = buildItem(row);
  437. inventory.Add(item);
  438. //m_log.DebugFormat("[DATASTORE]: Restored item {0}, {1}", item.Name, item.ItemID);
  439. }
  440. prim.Inventory.RestoreInventoryItems(inventory);
  441. }
  442. /// <summary>
  443. /// Store a terrain revision in region storage
  444. /// </summary>
  445. /// <param name="ter">terrain heightfield</param>
  446. /// <param name="regionID">region UUID</param>
  447. public void StoreTerrain(double[,] ter, UUID regionID)
  448. {
  449. lock (ds)
  450. {
  451. int revision = Util.UnixTimeSinceEpoch();
  452. // This is added to get rid of the infinitely growing
  453. // terrain databases which negatively impact on SQLite
  454. // over time. Before reenabling this feature there
  455. // needs to be a limitter put on the number of
  456. // revisions in the database, as this old
  457. // implementation is a DOS attack waiting to happen.
  458. using (
  459. SqliteCommand cmd =
  460. new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID and Revision <= :Revision",
  461. m_conn))
  462. {
  463. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  464. cmd.Parameters.Add(new SqliteParameter(":Revision", revision));
  465. cmd.ExecuteNonQuery();
  466. }
  467. // the following is an work around for .NET. The perf
  468. // issues associated with it aren't as bad as you think.
  469. m_log.Info("[REGION DB]: Storing terrain revision r" + revision.ToString());
  470. String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" +
  471. " values(:RegionUUID, :Revision, :Heightfield)";
  472. using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
  473. {
  474. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  475. cmd.Parameters.Add(new SqliteParameter(":Revision", revision));
  476. cmd.Parameters.Add(new SqliteParameter(":Heightfield", serializeTerrain(ter)));
  477. cmd.ExecuteNonQuery();
  478. }
  479. }
  480. }
  481. /// <summary>
  482. /// Load the latest terrain revision from region storage
  483. /// </summary>
  484. /// <param name="regionID">the region UUID</param>
  485. /// <returns>Heightfield data</returns>
  486. public double[,] LoadTerrain(UUID regionID)
  487. {
  488. lock (ds)
  489. {
  490. double[,] terret = new double[(int)Constants.RegionSize, (int)Constants.RegionSize];
  491. terret.Initialize();
  492. String sql = "select RegionUUID, Revision, Heightfield from terrain" +
  493. " where RegionUUID=:RegionUUID order by Revision desc";
  494. using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
  495. {
  496. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  497. using (IDataReader row = cmd.ExecuteReader())
  498. {
  499. int rev = 0;
  500. if (row.Read())
  501. {
  502. // TODO: put this into a function
  503. MemoryStream str = new MemoryStream((byte[]) row["Heightfield"]);
  504. BinaryReader br = new BinaryReader(str);
  505. for (int x = 0; x < (int)Constants.RegionSize; x++)
  506. {
  507. for (int y = 0; y < (int)Constants.RegionSize; y++)
  508. {
  509. terret[x, y] = br.ReadDouble();
  510. }
  511. }
  512. rev = (int) row["Revision"];
  513. }
  514. else
  515. {
  516. m_log.Info("[REGION DB]: No terrain found for region");
  517. return null;
  518. }
  519. m_log.Info("[REGION DB]: Loaded terrain revision r" + rev.ToString());
  520. }
  521. }
  522. return terret;
  523. }
  524. }
  525. /// <summary>
  526. ///
  527. /// </summary>
  528. /// <param name="globalID"></param>
  529. public void RemoveLandObject(UUID globalID)
  530. {
  531. lock (ds)
  532. {
  533. using (SqliteCommand cmd = new SqliteCommand("delete from land where UUID=:UUID", m_conn))
  534. {
  535. cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString()));
  536. cmd.ExecuteNonQuery();
  537. }
  538. using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:UUID", m_conn))
  539. {
  540. cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString()));
  541. cmd.ExecuteNonQuery();
  542. }
  543. }
  544. }
  545. /// <summary>
  546. ///
  547. /// </summary>
  548. /// <param name="parcel"></param>
  549. public void StoreLandObject(ILandObject parcel)
  550. {
  551. lock (ds)
  552. {
  553. DataTable land = ds.Tables["land"];
  554. DataTable landaccesslist = ds.Tables["landaccesslist"];
  555. DataRow landRow = land.Rows.Find(parcel.landData.GlobalID.ToString());
  556. if (landRow == null)
  557. {
  558. landRow = land.NewRow();
  559. fillLandRow(landRow, parcel.landData, parcel.regionUUID);
  560. land.Rows.Add(landRow);
  561. }
  562. else
  563. {
  564. fillLandRow(landRow, parcel.landData, parcel.regionUUID);
  565. }
  566. // I know this caused someone issues before, but OpenSim is unusable if we leave this stuff around
  567. using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:LandUUID", m_conn))
  568. {
  569. cmd.Parameters.Add(new SqliteParameter(":LandUUID", parcel.landData.GlobalID.ToString()));
  570. cmd.ExecuteNonQuery();
  571. }
  572. foreach (ParcelManager.ParcelAccessEntry entry in parcel.landData.ParcelAccessList)
  573. {
  574. DataRow newAccessRow = landaccesslist.NewRow();
  575. fillLandAccessRow(newAccessRow, entry, parcel.landData.GlobalID);
  576. landaccesslist.Rows.Add(newAccessRow);
  577. }
  578. }
  579. Commit();
  580. }
  581. /// <summary>
  582. ///
  583. /// </summary>
  584. /// <param name="regionUUID"></param>
  585. /// <returns></returns>
  586. public List<LandData> LoadLandObjects(UUID regionUUID)
  587. {
  588. List<LandData> landDataForRegion = new List<LandData>();
  589. lock (ds)
  590. {
  591. DataTable land = ds.Tables["land"];
  592. DataTable landaccesslist = ds.Tables["landaccesslist"];
  593. string searchExp = "RegionUUID = '" + regionUUID + "'";
  594. DataRow[] rawDataForRegion = land.Select(searchExp);
  595. foreach (DataRow rawDataLand in rawDataForRegion)
  596. {
  597. LandData newLand = buildLandData(rawDataLand);
  598. string accessListSearchExp = "LandUUID = '" + newLand.GlobalID + "'";
  599. DataRow[] rawDataForLandAccessList = landaccesslist.Select(accessListSearchExp);
  600. foreach (DataRow rawDataLandAccess in rawDataForLandAccessList)
  601. {
  602. newLand.ParcelAccessList.Add(buildLandAccessData(rawDataLandAccess));
  603. }
  604. landDataForRegion.Add(newLand);
  605. }
  606. }
  607. return landDataForRegion;
  608. }
  609. /// <summary>
  610. ///
  611. /// </summary>
  612. public void Commit()
  613. {
  614. lock (ds)
  615. {
  616. primDa.Update(ds, "prims");
  617. shapeDa.Update(ds, "primshapes");
  618. itemsDa.Update(ds, "primitems");
  619. terrainDa.Update(ds, "terrain");
  620. landDa.Update(ds, "land");
  621. landAccessListDa.Update(ds, "landaccesslist");
  622. try
  623. {
  624. regionSettingsDa.Update(ds, "regionsettings");
  625. }
  626. catch (SqliteExecutionException SqlEx)
  627. {
  628. if (SqlEx.Message.Contains("logic error"))
  629. {
  630. throw new Exception(
  631. "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!",
  632. SqlEx);
  633. }
  634. else
  635. {
  636. throw SqlEx;
  637. }
  638. }
  639. ds.AcceptChanges();
  640. }
  641. }
  642. /// <summary>
  643. /// See <see cref="Commit"/>
  644. /// </summary>
  645. public void Shutdown()
  646. {
  647. Commit();
  648. }
  649. /***********************************************************************
  650. *
  651. * Database Definition Functions
  652. *
  653. * This should be db agnostic as we define them in ADO.NET terms
  654. *
  655. **********************************************************************/
  656. /// <summary>
  657. ///
  658. /// </summary>
  659. /// <param name="dt"></param>
  660. /// <param name="name"></param>
  661. /// <param name="type"></param>
  662. private static void createCol(DataTable dt, string name, Type type)
  663. {
  664. DataColumn col = new DataColumn(name, type);
  665. dt.Columns.Add(col);
  666. }
  667. /// <summary>
  668. /// Creates the "terrain" table
  669. /// </summary>
  670. /// <returns>terrain table DataTable</returns>
  671. private static DataTable createTerrainTable()
  672. {
  673. DataTable terrain = new DataTable("terrain");
  674. createCol(terrain, "RegionUUID", typeof (String));
  675. createCol(terrain, "Revision", typeof (Int32));
  676. createCol(terrain, "Heightfield", typeof (Byte[]));
  677. return terrain;
  678. }
  679. /// <summary>
  680. /// Creates the "prims" table
  681. /// </summary>
  682. /// <returns>prim table DataTable</returns>
  683. private static DataTable createPrimTable()
  684. {
  685. DataTable prims = new DataTable("prims");
  686. createCol(prims, "UUID", typeof (String));
  687. createCol(prims, "RegionUUID", typeof (String));
  688. createCol(prims, "CreationDate", typeof (Int32));
  689. createCol(prims, "Name", typeof (String));
  690. createCol(prims, "SceneGroupID", typeof (String));
  691. // various text fields
  692. createCol(prims, "Text", typeof (String));
  693. createCol(prims, "ColorR", typeof (Int32));
  694. createCol(prims, "ColorG", typeof (Int32));
  695. createCol(prims, "ColorB", typeof (Int32));
  696. createCol(prims, "ColorA", typeof (Int32));
  697. createCol(prims, "Description", typeof (String));
  698. createCol(prims, "SitName", typeof (String));
  699. createCol(prims, "TouchName", typeof (String));
  700. // permissions
  701. createCol(prims, "ObjectFlags", typeof (Int32));
  702. createCol(prims, "CreatorID", typeof (String));
  703. createCol(prims, "OwnerID", typeof (String));
  704. createCol(prims, "GroupID", typeof (String));
  705. createCol(prims, "LastOwnerID", typeof (String));
  706. createCol(prims, "OwnerMask", typeof (Int32));
  707. createCol(prims, "NextOwnerMask", typeof (Int32));
  708. createCol(prims, "GroupMask", typeof (Int32));
  709. createCol(prims, "EveryoneMask", typeof (Int32));
  710. createCol(prims, "BaseMask", typeof (Int32));
  711. // vectors
  712. createCol(prims, "PositionX", typeof (Double));
  713. createCol(prims, "PositionY", typeof (Double));
  714. createCol(prims, "PositionZ", typeof (Double));
  715. createCol(prims, "GroupPositionX", typeof (Double));
  716. createCol(prims, "GroupPositionY", typeof (Double));
  717. createCol(prims, "GroupPositionZ", typeof (Double));
  718. createCol(prims, "VelocityX", typeof (Double));
  719. createCol(prims, "VelocityY", typeof (Double));
  720. createCol(prims, "VelocityZ", typeof (Double));
  721. createCol(prims, "AngularVelocityX", typeof (Double));
  722. createCol(prims, "AngularVelocityY", typeof (Double));
  723. createCol(prims, "AngularVelocityZ", typeof (Double));
  724. createCol(prims, "AccelerationX", typeof (Double));
  725. createCol(prims, "AccelerationY", typeof (Double));
  726. createCol(prims, "AccelerationZ", typeof (Double));
  727. // quaternions
  728. createCol(prims, "RotationX", typeof (Double));
  729. createCol(prims, "RotationY", typeof (Double));
  730. createCol(prims, "RotationZ", typeof (Double));
  731. createCol(prims, "RotationW", typeof (Double));
  732. // sit target
  733. createCol(prims, "SitTargetOffsetX", typeof (Double));
  734. createCol(prims, "SitTargetOffsetY", typeof (Double));
  735. createCol(prims, "SitTargetOffsetZ", typeof (Double));
  736. createCol(prims, "SitTargetOrientW", typeof (Double));
  737. createCol(prims, "SitTargetOrientX", typeof (Double));
  738. createCol(prims, "SitTargetOrientY", typeof (Double));
  739. createCol(prims, "SitTargetOrientZ", typeof (Double));
  740. createCol(prims, "PayPrice", typeof(Int32));
  741. createCol(prims, "PayButton1", typeof(Int32));
  742. createCol(prims, "PayButton2", typeof(Int32));
  743. createCol(prims, "PayButton3", typeof(Int32));
  744. createCol(prims, "PayButton4", typeof(Int32));
  745. createCol(prims, "LoopedSound", typeof(String));
  746. createCol(prims, "LoopedSoundGain", typeof(Double));
  747. createCol(prims, "TextureAnimation", typeof(String));
  748. createCol(prims, "ParticleSystem", typeof(String));
  749. createCol(prims, "OmegaX", typeof(Double));
  750. createCol(prims, "OmegaY", typeof(Double));
  751. createCol(prims, "OmegaZ", typeof(Double));
  752. createCol(prims, "CameraEyeOffsetX", typeof(Double));
  753. createCol(prims, "CameraEyeOffsetY", typeof(Double));
  754. createCol(prims, "CameraEyeOffsetZ", typeof(Double));
  755. createCol(prims, "CameraAtOffsetX", typeof(Double));
  756. createCol(prims, "CameraAtOffsetY", typeof(Double));
  757. createCol(prims, "CameraAtOffsetZ", typeof(Double));
  758. createCol(prims, "ForceMouselook", typeof(Int16));
  759. createCol(prims, "ScriptAccessPin", typeof(Int32));
  760. createCol(prims, "AllowedDrop", typeof(Int16));
  761. createCol(prims, "DieAtEdge", typeof(Int16));
  762. createCol(prims, "SalePrice", typeof(Int32));
  763. createCol(prims, "SaleType", typeof(Int16));
  764. // click action
  765. createCol(prims, "ClickAction", typeof (Byte));
  766. createCol(prims, "Material", typeof(Byte));
  767. createCol(prims, "CollisionSound", typeof(String));
  768. createCol(prims, "CollisionSoundVolume", typeof(Double));
  769. createCol(prims, "VolumeDetect", typeof(Int16));
  770. // Add in contraints
  771. prims.PrimaryKey = new DataColumn[] {prims.Columns["UUID"]};
  772. return prims;
  773. }
  774. /// <summary>
  775. /// Creates "primshapes" table
  776. /// </summary>
  777. /// <returns>shape table DataTable</returns>
  778. private static DataTable createShapeTable()
  779. {
  780. DataTable shapes = new DataTable("primshapes");
  781. createCol(shapes, "UUID", typeof (String));
  782. // shape is an enum
  783. createCol(shapes, "Shape", typeof (Int32));
  784. // vectors
  785. createCol(shapes, "ScaleX", typeof (Double));
  786. createCol(shapes, "ScaleY", typeof (Double));
  787. createCol(shapes, "ScaleZ", typeof (Double));
  788. // paths
  789. createCol(shapes, "PCode", typeof (Int32));
  790. createCol(shapes, "PathBegin", typeof (Int32));
  791. createCol(shapes, "PathEnd", typeof (Int32));
  792. createCol(shapes, "PathScaleX", typeof (Int32));
  793. createCol(shapes, "PathScaleY", typeof (Int32));
  794. createCol(shapes, "PathShearX", typeof (Int32));
  795. createCol(shapes, "PathShearY", typeof (Int32));
  796. createCol(shapes, "PathSkew", typeof (Int32));
  797. createCol(shapes, "PathCurve", typeof (Int32));
  798. createCol(shapes, "PathRadiusOffset", typeof (Int32));
  799. createCol(shapes, "PathRevolutions", typeof (Int32));
  800. createCol(shapes, "PathTaperX", typeof (Int32));
  801. createCol(shapes, "PathTaperY", typeof (Int32));
  802. createCol(shapes, "PathTwist", typeof (Int32));
  803. createCol(shapes, "PathTwistBegin", typeof (Int32));
  804. // profile
  805. createCol(shapes, "ProfileBegin", typeof (Int32));
  806. createCol(shapes, "ProfileEnd", typeof (Int32));
  807. createCol(shapes, "ProfileCurve", typeof (Int32));
  808. createCol(shapes, "ProfileHollow", typeof (Int32));
  809. createCol(shapes, "State", typeof(Int32));
  810. // text TODO: this isn't right, but I'm not sure the right
  811. // way to specify this as a blob atm
  812. createCol(shapes, "Texture", typeof (Byte[]));
  813. createCol(shapes, "ExtraParams", typeof (Byte[]));
  814. shapes.PrimaryKey = new DataColumn[] {shapes.Columns["UUID"]};
  815. return shapes;
  816. }
  817. /// <summary>
  818. /// creates "primitems" table
  819. /// </summary>
  820. /// <returns>item table DataTable</returns>
  821. private static DataTable createItemsTable()
  822. {
  823. DataTable items = new DataTable("primitems");
  824. createCol(items, "itemID", typeof (String));
  825. createCol(items, "primID", typeof (String));
  826. createCol(items, "assetID", typeof (String));
  827. createCol(items, "parentFolderID", typeof (String));
  828. createCol(items, "invType", typeof (Int32));
  829. createCol(items, "assetType", typeof (Int32));
  830. createCol(items, "name", typeof (String));
  831. createCol(items, "description", typeof (String));
  832. createCol(items, "creationDate", typeof (Int64));
  833. createCol(items, "creatorID", typeof (String));
  834. createCol(items, "ownerID", typeof (String));
  835. createCol(items, "lastOwnerID", typeof (String));
  836. createCol(items, "groupID", typeof (String));
  837. createCol(items, "nextPermissions", typeof (UInt32));
  838. createCol(items, "currentPermissions", typeof (UInt32));
  839. createCol(items, "basePermissions", typeof (UInt32));
  840. createCol(items, "everyonePermissions", typeof (UInt32));
  841. createCol(items, "groupPermissions", typeof (UInt32));
  842. createCol(items, "flags", typeof (UInt32));
  843. items.PrimaryKey = new DataColumn[] { items.Columns["itemID"] };
  844. return items;
  845. }
  846. /// <summary>
  847. /// Creates "land" table
  848. /// </summary>
  849. /// <returns>land table DataTable</returns>
  850. private static DataTable createLandTable()
  851. {
  852. DataTable land = new DataTable("land");
  853. createCol(land, "UUID", typeof (String));
  854. createCol(land, "RegionUUID", typeof (String));
  855. createCol(land, "LocalLandID", typeof (UInt32));
  856. // Bitmap is a byte[512]
  857. createCol(land, "Bitmap", typeof (Byte[]));
  858. createCol(land, "Name", typeof (String));
  859. createCol(land, "Desc", typeof (String));
  860. createCol(land, "OwnerUUID", typeof (String));
  861. createCol(land, "IsGroupOwned", typeof (Boolean));
  862. createCol(land, "Area", typeof (Int32));
  863. createCol(land, "AuctionID", typeof (Int32)); //Unemplemented
  864. createCol(land, "Category", typeof (Int32)); //Enum OpenMetaverse.Parcel.ParcelCategory
  865. createCol(land, "ClaimDate", typeof (Int32));
  866. createCol(land, "ClaimPrice", typeof (Int32));
  867. createCol(land, "GroupUUID", typeof (string));
  868. createCol(land, "SalePrice", typeof (Int32));
  869. createCol(land, "LandStatus", typeof (Int32)); //Enum. OpenMetaverse.Parcel.ParcelStatus
  870. createCol(land, "LandFlags", typeof (UInt32));
  871. createCol(land, "LandingType", typeof (Byte));
  872. createCol(land, "MediaAutoScale", typeof (Byte));
  873. createCol(land, "MediaTextureUUID", typeof (String));
  874. createCol(land, "MediaURL", typeof (String));
  875. createCol(land, "MusicURL", typeof (String));
  876. createCol(land, "PassHours", typeof (Double));
  877. createCol(land, "PassPrice", typeof (UInt32));
  878. createCol(land, "SnapshotUUID", typeof (String));
  879. createCol(land, "UserLocationX", typeof (Double));
  880. createCol(land, "UserLocationY", typeof (Double));
  881. createCol(land, "UserLocationZ", typeof (Double));
  882. createCol(land, "UserLookAtX", typeof (Double));
  883. createCol(land, "UserLookAtY", typeof (Double));
  884. createCol(land, "UserLookAtZ", typeof (Double));
  885. createCol(land, "AuthbuyerID", typeof(String));
  886. createCol(land, "OtherCleanTime", typeof(Int32));
  887. createCol(land, "Dwell", typeof(Int32));
  888. land.PrimaryKey = new DataColumn[] {land.Columns["UUID"]};
  889. return land;
  890. }
  891. /// <summary>
  892. /// create "landaccesslist" table
  893. /// </summary>
  894. /// <returns>Landacceslist DataTable</returns>
  895. private static DataTable createLandAccessListTable()
  896. {
  897. DataTable landaccess = new DataTable("landaccesslist");
  898. createCol(landaccess, "LandUUID", typeof (String));
  899. createCol(landaccess, "AccessUUID", typeof (String));
  900. createCol(landaccess, "Flags", typeof (UInt32));
  901. return landaccess;
  902. }
  903. private static DataTable createRegionSettingsTable()
  904. {
  905. DataTable regionsettings = new DataTable("regionsettings");
  906. createCol(regionsettings, "regionUUID", typeof(String));
  907. createCol(regionsettings, "block_terraform", typeof (Int32));
  908. createCol(regionsettings, "block_fly", typeof (Int32));
  909. createCol(regionsettings, "allow_damage", typeof (Int32));
  910. createCol(regionsettings, "restrict_pushing", typeof (Int32));
  911. createCol(regionsettings, "allow_land_resell", typeof (Int32));
  912. createCol(regionsettings, "allow_land_join_divide", typeof (Int32));
  913. createCol(regionsettings, "block_show_in_search", typeof (Int32));
  914. createCol(regionsettings, "agent_limit", typeof (Int32));
  915. createCol(regionsettings, "object_bonus", typeof (Double));
  916. createCol(regionsettings, "maturity", typeof (Int32));
  917. createCol(regionsettings, "disable_scripts", typeof (Int32));
  918. createCol(regionsettings, "disable_collisions", typeof (Int32));
  919. createCol(regionsettings, "disable_physics", typeof (Int32));
  920. createCol(regionsettings, "terrain_texture_1", typeof(String));
  921. createCol(regionsettings, "terrain_texture_2", typeof(String));
  922. createCol(regionsettings, "terrain_texture_3", typeof(String));
  923. createCol(regionsettings, "terrain_texture_4", typeof(String));
  924. createCol(regionsettings, "elevation_1_nw", typeof (Double));
  925. createCol(regionsettings, "elevation_2_nw", typeof (Double));
  926. createCol(regionsettings, "elevation_1_ne", typeof (Double));
  927. createCol(regionsettings, "elevation_2_ne", typeof (Double));
  928. createCol(regionsettings, "elevation_1_se", typeof (Double));
  929. createCol(regionsettings, "elevation_2_se", typeof (Double));
  930. createCol(regionsettings, "elevation_1_sw", typeof (Double));
  931. createCol(regionsettings, "elevation_2_sw", typeof (Double));
  932. createCol(regionsettings, "water_height", typeof (Double));
  933. createCol(regionsettings, "terrain_raise_limit", typeof (Double));
  934. createCol(regionsettings, "terrain_lower_limit", typeof (Double));
  935. createCol(regionsettings, "use_estate_sun", typeof (Int32));
  936. createCol(regionsettings, "sandbox", typeof (Int32));
  937. createCol(regionsettings, "sunvectorx",typeof (Double));
  938. createCol(regionsettings, "sunvectory",typeof (Double));
  939. createCol(regionsettings, "sunvectorz",typeof (Double));
  940. createCol(regionsettings, "fixed_sun", typeof (Int32));
  941. createCol(regionsettings, "sun_position", typeof (Double));
  942. createCol(regionsettings, "covenant", typeof(String));
  943. regionsettings.PrimaryKey = new DataColumn[] { regionsettings.Columns["regionUUID"] };
  944. return regionsettings;
  945. }
  946. /***********************************************************************
  947. *
  948. * Convert between ADO.NET <=> OpenSim Objects
  949. *
  950. * These should be database independant
  951. *
  952. **********************************************************************/
  953. /// <summary>
  954. ///
  955. /// </summary>
  956. /// <param name="row"></param>
  957. /// <returns></returns>
  958. private SceneObjectPart buildPrim(DataRow row)
  959. {
  960. // Code commented. Uncomment to test the unit test inline.
  961. // The unit test mentions this commented code for the purposes
  962. // of debugging a unit test failure
  963. // SceneObjectGroup sog = new SceneObjectGroup();
  964. // SceneObjectPart sop = new SceneObjectPart();
  965. // sop.LocalId = 1;
  966. // sop.Name = "object1";
  967. // sop.Description = "object1";
  968. // sop.Text = "";
  969. // sop.SitName = "";
  970. // sop.TouchName = "";
  971. // sop.UUID = UUID.Random();
  972. // sop.Shape = PrimitiveBaseShape.Default;
  973. // sog.SetRootPart(sop);
  974. // Add breakpoint in above line. Check sop fields.
  975. // TODO: this doesn't work yet because something more
  976. // interesting has to be done to actually get these values
  977. // back out. Not enough time to figure it out yet.
  978. SceneObjectPart prim = new SceneObjectPart();
  979. prim.UUID = new UUID((String) row["UUID"]);
  980. // explicit conversion of integers is required, which sort
  981. // of sucks. No idea if there is a shortcut here or not.
  982. prim.CreationDate = Convert.ToInt32(row["CreationDate"]);
  983. prim.Name = row["Name"] == DBNull.Value ? string.Empty : (string)row["Name"];
  984. // various text fields
  985. prim.Text = (String) row["Text"];
  986. prim.Color = Color.FromArgb(Convert.ToInt32(row["ColorA"]),
  987. Convert.ToInt32(row["ColorR"]),
  988. Convert.ToInt32(row["ColorG"]),
  989. Convert.ToInt32(row["ColorB"]));
  990. prim.Description = (String) row["Description"];
  991. prim.SitName = (String) row["SitName"];
  992. prim.TouchName = (String) row["TouchName"];
  993. // permissions
  994. prim.ObjectFlags = Convert.ToUInt32(row["ObjectFlags"]);
  995. prim.CreatorID = new UUID((String) row["CreatorID"]);
  996. prim.OwnerID = new UUID((String) row["OwnerID"]);
  997. prim.GroupID = new UUID((String) row["GroupID"]);
  998. prim.LastOwnerID = new UUID((String) row["LastOwnerID"]);
  999. prim.OwnerMask = Convert.ToUInt32(row["OwnerMask"]);
  1000. prim.NextOwnerMask = Convert.ToUInt32(row["NextOwnerMask"]);
  1001. prim.GroupMask = Convert.ToUInt32(row["GroupMask"]);
  1002. prim.EveryoneMask = Convert.ToUInt32(row["EveryoneMask"]);
  1003. prim.BaseMask = Convert.ToUInt32(row["BaseMask"]);
  1004. // vectors
  1005. prim.OffsetPosition = new Vector3(
  1006. Convert.ToSingle(row["PositionX"]),
  1007. Convert.ToSingle(row["PositionY"]),
  1008. Convert.ToSingle(row["PositionZ"])
  1009. );
  1010. prim.GroupPosition = new Vector3(
  1011. Convert.ToSingle(row["GroupPositionX"]),
  1012. Convert.ToSingle(row["GroupPositionY"]),
  1013. Convert.ToSingle(row["GroupPositionZ"])
  1014. );
  1015. prim.Velocity = new Vector3(
  1016. Convert.ToSingle(row["VelocityX"]),
  1017. Convert.ToSingle(row["VelocityY"]),
  1018. Convert.ToSingle(row["VelocityZ"])
  1019. );
  1020. prim.AngularVelocity = new Vector3(
  1021. Convert.ToSingle(row["AngularVelocityX"]),
  1022. Convert.ToSingle(row["AngularVelocityY"]),
  1023. Convert.ToSingle(row["AngularVelocityZ"])
  1024. );
  1025. prim.Acceleration = new Vector3(
  1026. Convert.ToSingle(row["AccelerationX"]),
  1027. Convert.ToSingle(row["AccelerationY"]),
  1028. Convert.ToSingle(row["AccelerationZ"])
  1029. );
  1030. // quaternions
  1031. prim.RotationOffset = new Quaternion(
  1032. Convert.ToSingle(row["RotationX"]),
  1033. Convert.ToSingle(row["RotationY"]),
  1034. Convert.ToSingle(row["RotationZ"]),
  1035. Convert.ToSingle(row["RotationW"])
  1036. );
  1037. prim.SitTargetPositionLL = new Vector3(
  1038. Convert.ToSingle(row["SitTargetOffsetX"]),
  1039. Convert.ToSingle(row["SitTargetOffsetY"]),
  1040. Convert.ToSingle(row["SitTargetOffsetZ"]));
  1041. prim.SitTargetOrientationLL = new Quaternion(
  1042. Convert.ToSingle(
  1043. row["SitTargetOrientX"]),
  1044. Convert.ToSingle(
  1045. row["SitTargetOrientY"]),
  1046. Convert.ToSingle(
  1047. row["SitTargetOrientZ"]),
  1048. Convert.ToSingle(
  1049. row["SitTargetOrientW"]));
  1050. prim.ClickAction = Convert.ToByte(row["ClickAction"]);
  1051. prim.PayPrice[0] = Convert.ToInt32(row["PayPrice"]);
  1052. prim.PayPrice[1] = Convert.ToInt32(row["PayButton1"]);
  1053. prim.PayPrice[2] = Convert.ToInt32(row["PayButton2"]);
  1054. prim.PayPrice[3] = Convert.ToInt32(row["PayButton3"]);
  1055. prim.PayPrice[4] = Convert.ToInt32(row["PayButton4"]);
  1056. prim.Sound = new UUID(row["LoopedSound"].ToString());
  1057. prim.SoundGain = Convert.ToSingle(row["LoopedSoundGain"]);
  1058. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  1059. if (!row.IsNull("TextureAnimation"))
  1060. prim.TextureAnimation = Convert.FromBase64String(row["TextureAnimation"].ToString());
  1061. if (!row.IsNull("ParticleSystem"))
  1062. prim.ParticleSystem = Convert.FromBase64String(row["ParticleSystem"].ToString());
  1063. prim.RotationalVelocity = new Vector3(
  1064. Convert.ToSingle(row["OmegaX"]),
  1065. Convert.ToSingle(row["OmegaY"]),
  1066. Convert.ToSingle(row["OmegaZ"])
  1067. );
  1068. prim.SetCameraEyeOffset(new Vector3(
  1069. Convert.ToSingle(row["CameraEyeOffsetX"]),
  1070. Convert.ToSingle(row["CameraEyeOffsetY"]),
  1071. Convert.ToSingle(row["CameraEyeOffsetZ"])
  1072. ));
  1073. prim.SetCameraAtOffset(new Vector3(
  1074. Convert.ToSingle(row["CameraAtOffsetX"]),
  1075. Convert.ToSingle(row["CameraAtOffsetY"]),
  1076. Convert.ToSingle(row["CameraAtOffsetZ"])
  1077. ));
  1078. if (Convert.ToInt16(row["ForceMouselook"]) != 0)
  1079. prim.SetForceMouselook(true);
  1080. prim.ScriptAccessPin = Convert.ToInt32(row["ScriptAccessPin"]);
  1081. if (Convert.ToInt16(row["AllowedDrop"]) != 0)
  1082. prim.AllowedDrop = true;
  1083. if (Convert.ToInt16(row["DieAtEdge"]) != 0)
  1084. prim.DIE_AT_EDGE = true;
  1085. prim.SalePrice = Convert.ToInt32(row["SalePrice"]);
  1086. prim.ObjectSaleType = Convert.ToByte(row["SaleType"]);
  1087. prim.Material = Convert.ToByte(row["Material"]);
  1088. prim.CollisionSound = new UUID(row["CollisionSound"].ToString());
  1089. prim.CollisionSoundVolume = Convert.ToSingle(row["CollisionSoundVolume"]);
  1090. if (Convert.ToInt16(row["VolumeDetect"]) != 0)
  1091. prim.VolumeDetectActive = true;
  1092. return prim;
  1093. }
  1094. /// <summary>
  1095. /// Build a prim inventory item from the persisted data.
  1096. /// </summary>
  1097. /// <param name="row"></param>
  1098. /// <returns></returns>
  1099. private static TaskInventoryItem buildItem(DataRow row)
  1100. {
  1101. TaskInventoryItem taskItem = new TaskInventoryItem();
  1102. taskItem.ItemID = new UUID((String)row["itemID"]);
  1103. taskItem.ParentPartID = new UUID((String)row["primID"]);
  1104. taskItem.AssetID = new UUID((String)row["assetID"]);
  1105. taskItem.ParentID = new UUID((String)row["parentFolderID"]);
  1106. taskItem.InvType = Convert.ToInt32(row["invType"]);
  1107. taskItem.Type = Convert.ToInt32(row["assetType"]);
  1108. taskItem.Name = (String)row["name"];
  1109. taskItem.Description = (String)row["description"];
  1110. taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
  1111. taskItem.CreatorID = new UUID((String)row["creatorID"]);
  1112. taskItem.OwnerID = new UUID((String)row["ownerID"]);
  1113. taskItem.LastOwnerID = new UUID((String)row["lastOwnerID"]);
  1114. taskItem.GroupID = new UUID((String)row["groupID"]);
  1115. taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
  1116. taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
  1117. taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
  1118. taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
  1119. taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
  1120. taskItem.Flags = Convert.ToUInt32(row["flags"]);
  1121. return taskItem;
  1122. }
  1123. /// <summary>
  1124. /// Build a Land Data from the persisted data.
  1125. /// </summary>
  1126. /// <param name="row"></param>
  1127. /// <returns></returns>
  1128. private LandData buildLandData(DataRow row)
  1129. {
  1130. LandData newData = new LandData();
  1131. newData.GlobalID = new UUID((String) row["UUID"]);
  1132. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  1133. // Bitmap is a byte[512]
  1134. newData.Bitmap = (Byte[]) row["Bitmap"];
  1135. newData.Name = (String) row["Name"];
  1136. newData.Description = (String) row["Desc"];
  1137. newData.OwnerID = (UUID)(String) row["OwnerUUID"];
  1138. newData.IsGroupOwned = (Boolean) row["IsGroupOwned"];
  1139. newData.Area = Convert.ToInt32(row["Area"]);
  1140. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
  1141. newData.Category = (ParcelCategory) Convert.ToInt32(row["Category"]);
  1142. //Enum OpenMetaverse.Parcel.ParcelCategory
  1143. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  1144. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  1145. newData.GroupID = new UUID((String) row["GroupUUID"]);
  1146. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  1147. newData.Status = (ParcelStatus) Convert.ToInt32(row["LandStatus"]);
  1148. //Enum. OpenMetaverse.Parcel.ParcelStatus
  1149. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  1150. newData.LandingType = (Byte) row["LandingType"];
  1151. newData.MediaAutoScale = (Byte) row["MediaAutoScale"];
  1152. newData.MediaID = new UUID((String) row["MediaTextureUUID"]);
  1153. newData.MediaURL = (String) row["MediaURL"];
  1154. newData.MusicURL = (String) row["MusicURL"];
  1155. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  1156. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  1157. newData.SnapshotID = (UUID)(String) row["SnapshotUUID"];
  1158. try
  1159. {
  1160. newData.UserLocation =
  1161. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  1162. Convert.ToSingle(row["UserLocationZ"]));
  1163. newData.UserLookAt =
  1164. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  1165. Convert.ToSingle(row["UserLookAtZ"]));
  1166. }
  1167. catch (InvalidCastException)
  1168. {
  1169. m_log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
  1170. newData.UserLocation = Vector3.Zero;
  1171. newData.UserLookAt = Vector3.Zero;
  1172. }
  1173. newData.ParcelAccessList = new List<ParcelManager.ParcelAccessEntry>();
  1174. UUID authBuyerID = UUID.Zero;
  1175. UUID.TryParse((string)row["AuthbuyerID"], out authBuyerID);
  1176. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  1177. newData.Dwell = Convert.ToInt32(row["Dwell"]);
  1178. return newData;
  1179. }
  1180. private RegionSettings buildRegionSettings(DataRow row)
  1181. {
  1182. RegionSettings newSettings = new RegionSettings();
  1183. newSettings.RegionUUID = new UUID((string) row["regionUUID"]);
  1184. newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
  1185. newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
  1186. newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
  1187. newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
  1188. newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
  1189. newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
  1190. newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
  1191. newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
  1192. newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
  1193. newSettings.Maturity = Convert.ToInt32(row["maturity"]);
  1194. newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
  1195. newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
  1196. newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
  1197. newSettings.TerrainTexture1 = new UUID((String) row["terrain_texture_1"]);
  1198. newSettings.TerrainTexture2 = new UUID((String) row["terrain_texture_2"]);
  1199. newSettings.TerrainTexture3 = new UUID((String) row["terrain_texture_3"]);
  1200. newSettings.TerrainTexture4 = new UUID((String) row["terrain_texture_4"]);
  1201. newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
  1202. newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
  1203. newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
  1204. newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
  1205. newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
  1206. newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
  1207. newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
  1208. newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
  1209. newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
  1210. newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
  1211. newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
  1212. newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
  1213. newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
  1214. newSettings.SunVector = new Vector3 (
  1215. Convert.ToSingle(row["sunvectorx"]),
  1216. Convert.ToSingle(row["sunvectory"]),
  1217. Convert.ToSingle(row["sunvectorz"])
  1218. );
  1219. newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
  1220. newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
  1221. newSettings.Covenant = new UUID((String) row["covenant"]);
  1222. return newSettings;
  1223. }
  1224. /// <summary>
  1225. /// Build a land access entry from the persisted data.
  1226. /// </summary>
  1227. /// <param name="row"></param>
  1228. /// <returns></returns>
  1229. private static ParcelManager.ParcelAccessEntry buildLandAccessData(DataRow row)
  1230. {
  1231. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  1232. entry.AgentID = new UUID((string) row["AccessUUID"]);
  1233. entry.Flags = (AccessList) row["Flags"];
  1234. entry.Time = new DateTime();
  1235. return entry;
  1236. }
  1237. /// <summary>
  1238. ///
  1239. /// </summary>
  1240. /// <param name="val"></param>
  1241. /// <returns></returns>
  1242. private static Array serializeTerrain(double[,] val)
  1243. {
  1244. MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) *sizeof (double));
  1245. BinaryWriter bw = new BinaryWriter(str);
  1246. // TODO: COMPATIBILITY - Add byte-order conversions
  1247. for (int x = 0; x < (int)Constants.RegionSize; x++)
  1248. for (int y = 0; y < (int)Constants.RegionSize; y++)
  1249. bw.Write(val[x, y]);
  1250. return str.ToArray();
  1251. }
  1252. // private void fillTerrainRow(DataRow row, UUID regionUUID, int rev, double[,] val)
  1253. // {
  1254. // row["RegionUUID"] = regionUUID;
  1255. // row["Revision"] = rev;
  1256. // MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize)*sizeof (double));
  1257. // BinaryWriter bw = new BinaryWriter(str);
  1258. // // TODO: COMPATIBILITY - Add byte-order conversions
  1259. // for (int x = 0; x < (int)Constants.RegionSize; x++)
  1260. // for (int y = 0; y < (int)Constants.RegionSize; y++)
  1261. // bw.Write(val[x, y]);
  1262. // row["Heightfield"] = str.ToArray();
  1263. // }
  1264. /// <summary>
  1265. ///
  1266. /// </summary>
  1267. /// <param name="row"></param>
  1268. /// <param name="prim"></param>
  1269. /// <param name="sceneGroupID"></param>
  1270. /// <param name="regionUUID"></param>
  1271. private static void fillPrimRow(DataRow row, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1272. {
  1273. row["UUID"] = prim.UUID.ToString();
  1274. row["RegionUUID"] = regionUUID.ToString();
  1275. row["CreationDate"] = prim.CreationDate;
  1276. row["Name"] = prim.Name;
  1277. row["SceneGroupID"] = sceneGroupID.ToString();
  1278. // the UUID of the root part for this SceneObjectGroup
  1279. // various text fields
  1280. row["Text"] = prim.Text;
  1281. row["Description"] = prim.Description;
  1282. row["SitName"] = prim.SitName;
  1283. row["TouchName"] = prim.TouchName;
  1284. // permissions
  1285. row["ObjectFlags"] = prim.ObjectFlags;
  1286. row["CreatorID"] = prim.CreatorID.ToString();
  1287. row["OwnerID"] = prim.OwnerID.ToString();
  1288. row["GroupID"] = prim.GroupID.ToString();
  1289. row["LastOwnerID"] = prim.LastOwnerID.ToString();
  1290. row["OwnerMask"] = prim.OwnerMask;
  1291. row["NextOwnerMask"] = prim.NextOwnerMask;
  1292. row["GroupMask"] = prim.GroupMask;
  1293. row["EveryoneMask"] = prim.EveryoneMask;
  1294. row["BaseMask"] = prim.BaseMask;
  1295. // vectors
  1296. row["PositionX"] = prim.OffsetPosition.X;
  1297. row["PositionY"] = prim.OffsetPosition.Y;
  1298. row["PositionZ"] = prim.OffsetPosition.Z;
  1299. row["GroupPositionX"] = prim.GroupPosition.X;
  1300. row["GroupPositionY"] = prim.GroupPosition.Y;
  1301. row["GroupPositionZ"] = prim.GroupPosition.Z;
  1302. row["VelocityX"] = prim.Velocity.X;
  1303. row["VelocityY"] = prim.Velocity.Y;
  1304. row["VelocityZ"] = prim.Velocity.Z;
  1305. row["AngularVelocityX"] = prim.AngularVelocity.X;
  1306. row["AngularVelocityY"] = prim.AngularVelocity.Y;
  1307. row["AngularVelocityZ"] = prim.AngularVelocity.Z;
  1308. row["AccelerationX"] = prim.Acceleration.X;
  1309. row["AccelerationY"] = prim.Acceleration.Y;
  1310. row["AccelerationZ"] = prim.Acceleration.Z;
  1311. // quaternions
  1312. row["RotationX"] = prim.RotationOffset.X;
  1313. row["RotationY"] = prim.RotationOffset.Y;
  1314. row["RotationZ"] = prim.RotationOffset.Z;
  1315. row["RotationW"] = prim.RotationOffset.W;
  1316. // Sit target
  1317. Vector3 sitTargetPos = prim.SitTargetPositionLL;
  1318. row["SitTargetOffsetX"] = sitTargetPos.X;
  1319. row["SitTargetOffsetY"] = sitTargetPos.Y;
  1320. row["SitTargetOffsetZ"] = sitTargetPos.Z;
  1321. Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
  1322. row["SitTargetOrientW"] = sitTargetOrient.W;
  1323. row["SitTargetOrientX"] = sitTargetOrient.X;
  1324. row["SitTargetOrientY"] = sitTargetOrient.Y;
  1325. row["SitTargetOrientZ"] = sitTargetOrient.Z;
  1326. row["ColorR"] = Convert.ToInt32(prim.Color.R);
  1327. row["ColorG"] = Convert.ToInt32(prim.Color.G);
  1328. row["ColorB"] = Convert.ToInt32(prim.Color.B);
  1329. row["ColorA"] = Convert.ToInt32(prim.Color.A);
  1330. row["PayPrice"] = prim.PayPrice[0];
  1331. row["PayButton1"] = prim.PayPrice[1];
  1332. row["PayButton2"] = prim.PayPrice[2];
  1333. row["PayButton3"] = prim.PayPrice[3];
  1334. row["PayButton4"] = prim.PayPrice[4];
  1335. row["TextureAnimation"] = Convert.ToBase64String(prim.TextureAnimation);
  1336. row["ParticleSystem"] = Convert.ToBase64String(prim.ParticleSystem);
  1337. row["OmegaX"] = prim.RotationalVelocity.X;
  1338. row["OmegaY"] = prim.RotationalVelocity.Y;
  1339. row["OmegaZ"] = prim.RotationalVelocity.Z;
  1340. row["CameraEyeOffsetX"] = prim.GetCameraEyeOffset().X;
  1341. row["CameraEyeOffsetY"] = prim.GetCameraEyeOffset().Y;
  1342. row["CameraEyeOffsetZ"] = prim.GetCameraEyeOffset().Z;
  1343. row["CameraAtOffsetX"] = prim.GetCameraAtOffset().X;
  1344. row["CameraAtOffsetY"] = prim.GetCameraAtOffset().Y;
  1345. row["CameraAtOffsetZ"] = prim.GetCameraAtOffset().Z;
  1346. if ((prim.SoundFlags & 1) != 0) // Looped
  1347. {
  1348. row["LoopedSound"] = prim.Sound.ToString();
  1349. row["LoopedSoundGain"] = prim.SoundGain;
  1350. }
  1351. else
  1352. {
  1353. row["LoopedSound"] = UUID.Zero.ToString();
  1354. row["LoopedSoundGain"] = 0.0f;
  1355. }
  1356. if (prim.GetForceMouselook())
  1357. row["ForceMouselook"] = 1;
  1358. else
  1359. row["ForceMouselook"] = 0;
  1360. row["ScriptAccessPin"] = prim.ScriptAccessPin;
  1361. if (prim.AllowedDrop)
  1362. row["AllowedDrop"] = 1;
  1363. else
  1364. row["AllowedDrop"] = 0;
  1365. if (prim.DIE_AT_EDGE)
  1366. row["DieAtEdge"] = 1;
  1367. else
  1368. row["DieAtEdge"] = 0;
  1369. row["SalePrice"] = prim.SalePrice;
  1370. row["SaleType"] = Convert.ToInt16(prim.ObjectSaleType);
  1371. // click action
  1372. row["ClickAction"] = prim.ClickAction;
  1373. row["SalePrice"] = prim.SalePrice;
  1374. row["Material"] = prim.Material;
  1375. row["CollisionSound"] = prim.CollisionSound.ToString();
  1376. row["CollisionSoundVolume"] = prim.CollisionSoundVolume;
  1377. if (prim.VolumeDetectActive)
  1378. row["VolumeDetect"] = 1;
  1379. else
  1380. row["VolumeDetect"] = 0;
  1381. }
  1382. /// <summary>
  1383. ///
  1384. /// </summary>
  1385. /// <param name="row"></param>
  1386. /// <param name="taskItem"></param>
  1387. private static void fillItemRow(DataRow row, TaskInventoryItem taskItem)
  1388. {
  1389. row["itemID"] = taskItem.ItemID.ToString();
  1390. row["primID"] = taskItem.ParentPartID.ToString();
  1391. row["assetID"] = taskItem.AssetID.ToString();
  1392. row["parentFolderID"] = taskItem.ParentID.ToString();
  1393. row["invType"] = taskItem.InvType;
  1394. row["assetType"] = taskItem.Type;
  1395. row["name"] = taskItem.Name;
  1396. row["description"] = taskItem.Description;
  1397. row["creationDate"] = taskItem.CreationDate;
  1398. row["creatorID"] = taskItem.CreatorID.ToString();
  1399. row["ownerID"] = taskItem.OwnerID.ToString();
  1400. row["lastOwnerID"] = taskItem.LastOwnerID.ToString();
  1401. row["groupID"] = taskItem.GroupID.ToString();
  1402. row["nextPermissions"] = taskItem.NextPermissions;
  1403. row["currentPermissions"] = taskItem.CurrentPermissions;
  1404. row["basePermissions"] = taskItem.BasePermissions;
  1405. row["everyonePermissions"] = taskItem.EveryonePermissions;
  1406. row["groupPermissions"] = taskItem.GroupPermissions;
  1407. row["flags"] = taskItem.Flags;
  1408. }
  1409. /// <summary>
  1410. ///
  1411. /// </summary>
  1412. /// <param name="row"></param>
  1413. /// <param name="land"></param>
  1414. /// <param name="regionUUID"></param>
  1415. private static void fillLandRow(DataRow row, LandData land, UUID regionUUID)
  1416. {
  1417. row["UUID"] = land.GlobalID.ToString();
  1418. row["RegionUUID"] = regionUUID.ToString();
  1419. row["LocalLandID"] = land.LocalID;
  1420. // Bitmap is a byte[512]
  1421. row["Bitmap"] = land.Bitmap;
  1422. row["Name"] = land.Name;
  1423. row["Desc"] = land.Description;
  1424. row["OwnerUUID"] = land.OwnerID.ToString();
  1425. row["IsGroupOwned"] = land.IsGroupOwned;
  1426. row["Area"] = land.Area;
  1427. row["AuctionID"] = land.AuctionID; //Unemplemented
  1428. row["Category"] = land.Category; //Enum OpenMetaverse.Parcel.ParcelCategory
  1429. row["ClaimDate"] = land.ClaimDate;
  1430. row["ClaimPrice"] = land.ClaimPrice;
  1431. row["GroupUUID"] = land.GroupID.ToString();
  1432. row["SalePrice"] = land.SalePrice;
  1433. row["LandStatus"] = land.Status; //Enum. OpenMetaverse.Parcel.ParcelStatus
  1434. row["LandFlags"] = land.Flags;
  1435. row["LandingType"] = land.LandingType;
  1436. row["MediaAutoScale"] = land.MediaAutoScale;
  1437. row["MediaTextureUUID"] = land.MediaID.ToString();
  1438. row["MediaURL"] = land.MediaURL;
  1439. row["MusicURL"] = land.MusicURL;
  1440. row["PassHours"] = land.PassHours;
  1441. row["PassPrice"] = land.PassPrice;
  1442. row["SnapshotUUID"] = land.SnapshotID.ToString();
  1443. row["UserLocationX"] = land.UserLocation.X;
  1444. row["UserLocationY"] = land.UserLocation.Y;
  1445. row["UserLocationZ"] = land.UserLocation.Z;
  1446. row["UserLookAtX"] = land.UserLookAt.X;
  1447. row["UserLookAtY"] = land.UserLookAt.Y;
  1448. row["UserLookAtZ"] = land.UserLookAt.Z;
  1449. row["AuthbuyerID"] = land.AuthBuyerID.ToString();
  1450. row["OtherCleanTime"] = land.OtherCleanTime;
  1451. row["Dwell"] = land.Dwell;
  1452. }
  1453. /// <summary>
  1454. ///
  1455. /// </summary>
  1456. /// <param name="row"></param>
  1457. /// <param name="entry"></param>
  1458. /// <param name="parcelID"></param>
  1459. private static void fillLandAccessRow(DataRow row, ParcelManager.ParcelAccessEntry entry, UUID parcelID)
  1460. {
  1461. row["LandUUID"] = parcelID.ToString();
  1462. row["AccessUUID"] = entry.AgentID.ToString();
  1463. row["Flags"] = entry.Flags;
  1464. }
  1465. private static void fillRegionSettingsRow(DataRow row, RegionSettings settings)
  1466. {
  1467. row["regionUUID"] = settings.RegionUUID.ToString();
  1468. row["block_terraform"] = settings.BlockTerraform;
  1469. row["block_fly"] = settings.BlockFly;
  1470. row["allow_damage"] = settings.AllowDamage;
  1471. row["restrict_pushing"] = settings.RestrictPushing;
  1472. row["allow_land_resell"] = settings.AllowLandResell;
  1473. row["allow_land_join_divide"] = settings.AllowLandJoinDivide;
  1474. row["block_show_in_search"] = settings.BlockShowInSearch;
  1475. row["agent_limit"] = settings.AgentLimit;
  1476. row["object_bonus"] = settings.ObjectBonus;
  1477. row["maturity"] = settings.Maturity;
  1478. row["disable_scripts"] = settings.DisableScripts;
  1479. row["disable_collisions"] = settings.DisableCollisions;
  1480. row["disable_physics"] = settings.DisablePhysics;
  1481. row["terrain_texture_1"] = settings.TerrainTexture1.ToString();
  1482. row["terrain_texture_2"] = settings.TerrainTexture2.ToString();
  1483. row["terrain_texture_3"] = settings.TerrainTexture3.ToString();
  1484. row["terrain_texture_4"] = settings.TerrainTexture4.ToString();
  1485. row["elevation_1_nw"] = settings.Elevation1NW;
  1486. row["elevation_2_nw"] = settings.Elevation2NW;
  1487. row["elevation_1_ne"] = settings.Elevation1NE;
  1488. row["elevation_2_ne"] = settings.Elevation2NE;
  1489. row["elevation_1_se"] = settings.Elevation1SE;
  1490. row["elevation_2_se"] = settings.Elevation2SE;
  1491. row["elevation_1_sw"] = settings.Elevation1SW;
  1492. row["elevation_2_sw"] = settings.Elevation2SW;
  1493. row["water_height"] = settings.WaterHeight;
  1494. row["terrain_raise_limit"] = settings.TerrainRaiseLimit;
  1495. row["terrain_lower_limit"] = settings.TerrainLowerLimit;
  1496. row["use_estate_sun"] = settings.UseEstateSun;
  1497. row["sandbox"] = settings.Sandbox;
  1498. row["sunvectorx"] = settings.SunVector.X;
  1499. row["sunvectory"] = settings.SunVector.Y;
  1500. row["sunvectorz"] = settings.SunVector.Z;
  1501. row["fixed_sun"] = settings.FixedSun;
  1502. row["sun_position"] = settings.SunPosition;
  1503. row["covenant"] = settings.Covenant.ToString();
  1504. }
  1505. /// <summary>
  1506. ///
  1507. /// </summary>
  1508. /// <param name="row"></param>
  1509. /// <returns></returns>
  1510. private PrimitiveBaseShape buildShape(DataRow row)
  1511. {
  1512. PrimitiveBaseShape s = new PrimitiveBaseShape();
  1513. s.Scale = new Vector3(
  1514. Convert.ToSingle(row["ScaleX"]),
  1515. Convert.ToSingle(row["ScaleY"]),
  1516. Convert.ToSingle(row["ScaleZ"])
  1517. );
  1518. // paths
  1519. s.PCode = Convert.ToByte(row["PCode"]);
  1520. s.PathBegin = Convert.ToUInt16(row["PathBegin"]);
  1521. s.PathEnd = Convert.ToUInt16(row["PathEnd"]);
  1522. s.PathScaleX = Convert.ToByte(row["PathScaleX"]);
  1523. s.PathScaleY = Convert.ToByte(row["PathScaleY"]);
  1524. s.PathShearX = Convert.ToByte(row["PathShearX"]);
  1525. s.PathShearY = Convert.ToByte(row["PathShearY"]);
  1526. s.PathSkew = Convert.ToSByte(row["PathSkew"]);
  1527. s.PathCurve = Convert.ToByte(row["PathCurve"]);
  1528. s.PathRadiusOffset = Convert.ToSByte(row["PathRadiusOffset"]);
  1529. s.PathRevolutions = Convert.ToByte(row["PathRevolutions"]);
  1530. s.PathTaperX = Convert.ToSByte(row["PathTaperX"]);
  1531. s.PathTaperY = Convert.ToSByte(row["PathTaperY"]);
  1532. s.PathTwist = Convert.ToSByte(row["PathTwist"]);
  1533. s.PathTwistBegin = Convert.ToSByte(row["PathTwistBegin"]);
  1534. // profile
  1535. s.ProfileBegin = Convert.ToUInt16(row["ProfileBegin"]);
  1536. s.ProfileEnd = Convert.ToUInt16(row["ProfileEnd"]);
  1537. s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]);
  1538. s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]);
  1539. s.State = Convert.ToByte(row["State"]);
  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"] = prim.UUID.ToString();
  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(prim.UUID.ToString());
  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(prim.UUID.ToString());
  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. }