SQLiteRegionData.cs 90 KB

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