SQLiteSimulationData.cs 134 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082
  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. #if CSharpSqlite
  35. using Community.CsharpSqlite.Sqlite;
  36. #else
  37. using Mono.Data.Sqlite;
  38. #endif
  39. using OpenMetaverse;
  40. using OpenMetaverse.StructuredData;
  41. using OpenSim.Framework;
  42. using OpenSim.Region.Framework.Interfaces;
  43. using OpenSim.Region.Framework.Scenes;
  44. namespace OpenSim.Data.SQLite
  45. {
  46. /// <summary>
  47. /// A RegionData Interface to the SQLite database
  48. /// </summary>
  49. public class SQLiteSimulationData : ISimulationDataStore
  50. {
  51. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  52. private static readonly string LogHeader = "[REGION DB SQLITE]";
  53. private const string primSelect = "select * from prims";
  54. private const string shapeSelect = "select * from primshapes";
  55. private const string itemsSelect = "select * from primitems";
  56. private const string terrainSelect = "select * from terrain limit 1";
  57. private const string landSelect = "select * from land";
  58. private const string landAccessListSelect = "select distinct * from landaccesslist";
  59. private const string regionbanListSelect = "select * from regionban";
  60. private const string regionSettingsSelect = "select * from regionsettings";
  61. private const string regionWindlightSelect = "select * from regionwindlight";
  62. private const string regionEnvironmentSelect = "select * from regionenvironment";
  63. private const string regionSpawnPointsSelect = "select * from spawn_points";
  64. private DataSet ds;
  65. private SqliteDataAdapter primDa;
  66. private SqliteDataAdapter shapeDa;
  67. private SqliteDataAdapter itemsDa;
  68. private SqliteDataAdapter terrainDa;
  69. private SqliteDataAdapter landDa;
  70. private SqliteDataAdapter landAccessListDa;
  71. private SqliteDataAdapter regionSettingsDa;
  72. private SqliteDataAdapter regionWindlightDa;
  73. private SqliteDataAdapter regionEnvironmentDa;
  74. private SqliteDataAdapter regionSpawnPointsDa;
  75. private SqliteConnection m_conn;
  76. private String m_connectionString;
  77. protected virtual Assembly Assembly
  78. {
  79. get { return GetType().Assembly; }
  80. }
  81. public SQLiteSimulationData()
  82. {
  83. }
  84. public SQLiteSimulationData(string connectionString)
  85. {
  86. Initialise(connectionString);
  87. }
  88. // Temporary attribute while this is experimental
  89. /***********************************************************************
  90. *
  91. * Public Interface Functions
  92. *
  93. **********************************************************************/
  94. /// <summary>
  95. /// <list type="bullet">
  96. /// <item>Initialises RegionData Interface</item>
  97. /// <item>Loads and initialises a new SQLite connection and maintains it.</item>
  98. /// </list>
  99. /// </summary>
  100. /// <param name="connectionString">the connection string</param>
  101. public void Initialise(string connectionString)
  102. {
  103. try
  104. {
  105. if (Util.IsWindows())
  106. Util.LoadArchSpecificWindowsDll("sqlite3.dll");
  107. m_connectionString = connectionString;
  108. ds = new DataSet("Region");
  109. m_log.Info("[SQLITE REGION DB]: Sqlite - connecting: " + connectionString);
  110. m_conn = new SqliteConnection(m_connectionString);
  111. m_conn.Open();
  112. SqliteCommand primSelectCmd = new SqliteCommand(primSelect, m_conn);
  113. primDa = new SqliteDataAdapter(primSelectCmd);
  114. SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, m_conn);
  115. shapeDa = new SqliteDataAdapter(shapeSelectCmd);
  116. // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa);
  117. SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, m_conn);
  118. itemsDa = new SqliteDataAdapter(itemsSelectCmd);
  119. SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, m_conn);
  120. terrainDa = new SqliteDataAdapter(terrainSelectCmd);
  121. SqliteCommand landSelectCmd = new SqliteCommand(landSelect, m_conn);
  122. landDa = new SqliteDataAdapter(landSelectCmd);
  123. SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn);
  124. landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd);
  125. SqliteCommand regionSettingsSelectCmd = new SqliteCommand(regionSettingsSelect, m_conn);
  126. regionSettingsDa = new SqliteDataAdapter(regionSettingsSelectCmd);
  127. SqliteCommand regionWindlightSelectCmd = new SqliteCommand(regionWindlightSelect, m_conn);
  128. regionWindlightDa = new SqliteDataAdapter(regionWindlightSelectCmd);
  129. SqliteCommand regionEnvironmentSelectCmd = new SqliteCommand(regionEnvironmentSelect, m_conn);
  130. regionEnvironmentDa = new SqliteDataAdapter(regionEnvironmentSelectCmd);
  131. SqliteCommand regionSpawnPointsSelectCmd = new SqliteCommand(regionSpawnPointsSelect, m_conn);
  132. regionSpawnPointsDa = new SqliteDataAdapter(regionSpawnPointsSelectCmd);
  133. // This actually does the roll forward assembly stuff
  134. Migration m = new Migration(m_conn, Assembly, "RegionStore");
  135. m.Update();
  136. lock (ds)
  137. {
  138. ds.Tables.Add(createPrimTable());
  139. setupPrimCommands(primDa, m_conn);
  140. ds.Tables.Add(createShapeTable());
  141. setupShapeCommands(shapeDa, m_conn);
  142. ds.Tables.Add(createItemsTable());
  143. setupItemsCommands(itemsDa, m_conn);
  144. ds.Tables.Add(createTerrainTable());
  145. setupTerrainCommands(terrainDa, m_conn);
  146. ds.Tables.Add(createLandTable());
  147. setupLandCommands(landDa, m_conn);
  148. ds.Tables.Add(createLandAccessListTable());
  149. setupLandAccessCommands(landAccessListDa, m_conn);
  150. ds.Tables.Add(createRegionSettingsTable());
  151. setupRegionSettingsCommands(regionSettingsDa, m_conn);
  152. ds.Tables.Add(createRegionWindlightTable());
  153. setupRegionWindlightCommands(regionWindlightDa, m_conn);
  154. ds.Tables.Add(createRegionEnvironmentTable());
  155. setupRegionEnvironmentCommands(regionEnvironmentDa, m_conn);
  156. ds.Tables.Add(createRegionSpawnPointsTable());
  157. setupRegionSpawnPointsCommands(regionSpawnPointsDa, m_conn);
  158. // WORKAROUND: This is a work around for sqlite on
  159. // windows, which gets really unhappy with blob columns
  160. // that have no sample data in them. At some point we
  161. // need to actually find a proper way to handle this.
  162. try
  163. {
  164. primDa.Fill(ds.Tables["prims"]);
  165. }
  166. catch (Exception e)
  167. {
  168. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on prims table :{0}", e.Message);
  169. }
  170. try
  171. {
  172. shapeDa.Fill(ds.Tables["primshapes"]);
  173. }
  174. catch (Exception e)
  175. {
  176. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on primshapes table :{0}", e.Message);
  177. }
  178. try
  179. {
  180. itemsDa.Fill(ds.Tables["primitems"]);
  181. }
  182. catch (Exception e)
  183. {
  184. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on primitems table :{0}", e.Message);
  185. }
  186. try
  187. {
  188. terrainDa.Fill(ds.Tables["terrain"]);
  189. }
  190. catch (Exception e)
  191. {
  192. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on terrain table :{0}", e.Message);
  193. }
  194. try
  195. {
  196. landDa.Fill(ds.Tables["land"]);
  197. }
  198. catch (Exception e)
  199. {
  200. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on land table :{0}", e.Message);
  201. }
  202. try
  203. {
  204. landAccessListDa.Fill(ds.Tables["landaccesslist"]);
  205. }
  206. catch (Exception e)
  207. {
  208. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on landaccesslist table :{0}", e.Message);
  209. }
  210. try
  211. {
  212. regionSettingsDa.Fill(ds.Tables["regionsettings"]);
  213. }
  214. catch (Exception e)
  215. {
  216. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on regionsettings table :{0}", e.Message);
  217. }
  218. try
  219. {
  220. regionWindlightDa.Fill(ds.Tables["regionwindlight"]);
  221. }
  222. catch (Exception e)
  223. {
  224. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on regionwindlight table :{0}", e.Message);
  225. }
  226. try
  227. {
  228. regionEnvironmentDa.Fill(ds.Tables["regionenvironment"]);
  229. }
  230. catch (Exception e)
  231. {
  232. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on regionenvironment table :{0}", e.Message);
  233. }
  234. try
  235. {
  236. regionSpawnPointsDa.Fill(ds.Tables["spawn_points"]);
  237. }
  238. catch (Exception e)
  239. {
  240. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on spawn_points table :{0}", e.Message);
  241. }
  242. // We have to create a data set mapping for every table, otherwise the IDataAdaptor.Update() will not populate rows with values!
  243. // Not sure exactly why this is - this kind of thing was not necessary before - justincc 20100409
  244. // Possibly because we manually set up our own DataTables before connecting to the database
  245. CreateDataSetMapping(primDa, "prims");
  246. CreateDataSetMapping(shapeDa, "primshapes");
  247. CreateDataSetMapping(itemsDa, "primitems");
  248. CreateDataSetMapping(terrainDa, "terrain");
  249. CreateDataSetMapping(landDa, "land");
  250. CreateDataSetMapping(landAccessListDa, "landaccesslist");
  251. CreateDataSetMapping(regionSettingsDa, "regionsettings");
  252. CreateDataSetMapping(regionWindlightDa, "regionwindlight");
  253. CreateDataSetMapping(regionEnvironmentDa, "regionenvironment");
  254. CreateDataSetMapping(regionSpawnPointsDa, "spawn_points");
  255. }
  256. }
  257. catch (Exception e)
  258. {
  259. m_log.ErrorFormat("[SQLITE REGION DB]: {0} - {1}", e.Message, e.StackTrace);
  260. Environment.Exit(23);
  261. }
  262. return;
  263. }
  264. public void Dispose()
  265. {
  266. if (m_conn != null)
  267. {
  268. m_conn.Close();
  269. m_conn = null;
  270. }
  271. if (ds != null)
  272. {
  273. ds.Dispose();
  274. ds = null;
  275. }
  276. if (primDa != null)
  277. {
  278. primDa.Dispose();
  279. primDa = null;
  280. }
  281. if (shapeDa != null)
  282. {
  283. shapeDa.Dispose();
  284. shapeDa = null;
  285. }
  286. if (itemsDa != null)
  287. {
  288. itemsDa.Dispose();
  289. itemsDa = null;
  290. }
  291. if (terrainDa != null)
  292. {
  293. terrainDa.Dispose();
  294. terrainDa = null;
  295. }
  296. if (landDa != null)
  297. {
  298. landDa.Dispose();
  299. landDa = null;
  300. }
  301. if (landAccessListDa != null)
  302. {
  303. landAccessListDa.Dispose();
  304. landAccessListDa = null;
  305. }
  306. if (regionSettingsDa != null)
  307. {
  308. regionSettingsDa.Dispose();
  309. regionSettingsDa = null;
  310. }
  311. if (regionWindlightDa != null)
  312. {
  313. regionWindlightDa.Dispose();
  314. regionWindlightDa = null;
  315. }
  316. if (regionEnvironmentDa != null)
  317. {
  318. regionEnvironmentDa.Dispose();
  319. regionEnvironmentDa = null;
  320. }
  321. if (regionSpawnPointsDa != null)
  322. {
  323. regionSpawnPointsDa.Dispose();
  324. regionWindlightDa = null;
  325. }
  326. }
  327. public void StoreRegionSettings(RegionSettings rs)
  328. {
  329. lock (ds)
  330. {
  331. DataTable regionsettings = ds.Tables["regionsettings"];
  332. DataRow settingsRow = regionsettings.Rows.Find(rs.RegionUUID.ToString());
  333. if (settingsRow == null)
  334. {
  335. settingsRow = regionsettings.NewRow();
  336. fillRegionSettingsRow(settingsRow, rs);
  337. regionsettings.Rows.Add(settingsRow);
  338. }
  339. else
  340. {
  341. fillRegionSettingsRow(settingsRow, rs);
  342. }
  343. StoreSpawnPoints(rs);
  344. Commit();
  345. }
  346. }
  347. public void StoreSpawnPoints(RegionSettings rs)
  348. {
  349. lock (ds)
  350. {
  351. // DataTable spawnpoints = ds.Tables["spawn_points"];
  352. // remove region's spawnpoints
  353. using (
  354. SqliteCommand cmd =
  355. new SqliteCommand("delete from spawn_points where RegionID=:RegionID",
  356. m_conn))
  357. {
  358. cmd.Parameters.Add(new SqliteParameter(":RegionID", rs.RegionUUID.ToString()));
  359. cmd.ExecuteNonQuery();
  360. }
  361. }
  362. foreach (SpawnPoint sp in rs.SpawnPoints())
  363. {
  364. using (SqliteCommand cmd = new SqliteCommand("insert into spawn_points(RegionID, Yaw, Pitch, Distance)" +
  365. "values ( :RegionID, :Yaw, :Pitch, :Distance)", m_conn))
  366. {
  367. cmd.Parameters.Add(new SqliteParameter(":RegionID", rs.RegionUUID.ToString()));
  368. cmd.Parameters.Add(new SqliteParameter(":Yaw", sp.Yaw));
  369. cmd.Parameters.Add(new SqliteParameter(":Pitch", sp.Pitch));
  370. cmd.Parameters.Add(new SqliteParameter(":Distance", sp.Distance));
  371. cmd.ExecuteNonQuery();
  372. }
  373. }
  374. }
  375. /// <summary>
  376. /// Load windlight settings from region storage
  377. /// </summary>
  378. /// <param name="regionUUID">RegionID</param>
  379. public RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID)
  380. {
  381. RegionLightShareData wl = null;
  382. lock (ds)
  383. {
  384. DataTable windlightTable = ds.Tables["regionwindlight"];
  385. DataRow windlightRow = windlightTable.Rows.Find(regionUUID.ToString());
  386. if (windlightRow == null)
  387. {
  388. wl = new RegionLightShareData();
  389. wl.regionID = regionUUID;
  390. StoreRegionWindlightSettings(wl);
  391. return wl;
  392. }
  393. wl = buildRegionWindlight(windlightRow);
  394. return wl;
  395. }
  396. }
  397. /// <summary>
  398. /// Remove windlight settings from region storage
  399. /// </summary>
  400. /// <param name="regionID">RegionID</param>
  401. public void RemoveRegionWindlightSettings(UUID regionID)
  402. {
  403. lock (ds)
  404. {
  405. DataTable windlightTable = ds.Tables["regionwindlight"];
  406. DataRow windlightRow = windlightTable.Rows.Find(regionID.ToString());
  407. if (windlightRow != null)
  408. {
  409. windlightRow.Delete();
  410. }
  411. }
  412. Commit();
  413. }
  414. /// <summary>
  415. /// Adds an windlight into region storage
  416. /// </summary>
  417. /// <param name="wl">RegionLightShareData</param>
  418. public void StoreRegionWindlightSettings(RegionLightShareData wl)
  419. {
  420. lock (ds)
  421. {
  422. DataTable windlightTable = ds.Tables["regionwindlight"];
  423. DataRow windlightRow = windlightTable.Rows.Find(wl.regionID.ToString());
  424. if (windlightRow == null)
  425. {
  426. windlightRow = windlightTable.NewRow();
  427. fillRegionWindlightRow(windlightRow, wl);
  428. windlightTable.Rows.Add(windlightRow);
  429. }
  430. else
  431. {
  432. fillRegionWindlightRow(windlightRow, wl);
  433. }
  434. Commit();
  435. }
  436. }
  437. #region Region Environment Settings
  438. public string LoadRegionEnvironmentSettings(UUID regionUUID)
  439. {
  440. lock (ds)
  441. {
  442. DataTable environmentTable = ds.Tables["regionenvironment"];
  443. DataRow row = environmentTable.Rows.Find(regionUUID.ToString());
  444. if (row == null)
  445. {
  446. return String.Empty;
  447. }
  448. return (String)row["llsd_settings"];
  449. }
  450. }
  451. public void StoreRegionEnvironmentSettings(UUID regionUUID, string settings)
  452. {
  453. lock (ds)
  454. {
  455. DataTable environmentTable = ds.Tables["regionenvironment"];
  456. DataRow row = environmentTable.Rows.Find(regionUUID.ToString());
  457. if (row == null)
  458. {
  459. row = environmentTable.NewRow();
  460. row["region_id"] = regionUUID.ToString();
  461. row["llsd_settings"] = settings;
  462. environmentTable.Rows.Add(row);
  463. }
  464. else
  465. {
  466. row["llsd_settings"] = settings;
  467. }
  468. regionEnvironmentDa.Update(ds, "regionenvironment");
  469. }
  470. }
  471. public void RemoveRegionEnvironmentSettings(UUID regionUUID)
  472. {
  473. lock (ds)
  474. {
  475. DataTable environmentTable = ds.Tables["regionenvironment"];
  476. DataRow row = environmentTable.Rows.Find(regionUUID.ToString());
  477. if (row != null)
  478. {
  479. row.Delete();
  480. }
  481. regionEnvironmentDa.Update(ds, "regionenvironment");
  482. }
  483. }
  484. #endregion
  485. public RegionSettings LoadRegionSettings(UUID regionUUID)
  486. {
  487. lock (ds)
  488. {
  489. DataTable regionsettings = ds.Tables["regionsettings"];
  490. string searchExp = "regionUUID = '" + regionUUID.ToString() + "'";
  491. DataRow[] rawsettings = regionsettings.Select(searchExp);
  492. if (rawsettings.Length == 0)
  493. {
  494. RegionSettings rs = new RegionSettings();
  495. rs.RegionUUID = regionUUID;
  496. rs.OnSave += StoreRegionSettings;
  497. StoreRegionSettings(rs);
  498. return rs;
  499. }
  500. DataRow row = rawsettings[0];
  501. RegionSettings newSettings = buildRegionSettings(row);
  502. newSettings.OnSave += StoreRegionSettings;
  503. LoadSpawnPoints(newSettings);
  504. return newSettings;
  505. }
  506. }
  507. private void LoadSpawnPoints(RegionSettings rs)
  508. {
  509. rs.ClearSpawnPoints();
  510. DataTable spawnpoints = ds.Tables["spawn_points"];
  511. string byRegion = "RegionID = '" + rs.RegionUUID + "'";
  512. DataRow[] spForRegion = spawnpoints.Select(byRegion);
  513. foreach (DataRow spRow in spForRegion)
  514. {
  515. SpawnPoint sp = new SpawnPoint();
  516. sp.Pitch = (float)spRow["Pitch"];
  517. sp.Yaw = (float)spRow["Yaw"];
  518. sp.Distance = (float)spRow["Distance"];
  519. rs.AddSpawnPoint(sp);
  520. }
  521. }
  522. /// <summary>
  523. /// Adds an object into region storage
  524. /// </summary>
  525. /// <param name="obj">the object</param>
  526. /// <param name="regionUUID">the region UUID</param>
  527. public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
  528. {
  529. uint flags = obj.RootPart.GetEffectiveObjectFlags();
  530. // Eligibility check
  531. //
  532. if ((flags & (uint)PrimFlags.Temporary) != 0)
  533. return;
  534. if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
  535. return;
  536. lock (ds)
  537. {
  538. foreach (SceneObjectPart prim in obj.Parts)
  539. {
  540. // m_log.Info("[REGION DB]: Adding obj: " + obj.UUID + " to region: " + regionUUID);
  541. addPrim(prim, obj.UUID, regionUUID);
  542. }
  543. }
  544. Commit();
  545. // m_log.Info("[Dump of prims]: " + ds.GetXml());
  546. }
  547. /// <summary>
  548. /// Removes an object from region storage
  549. /// </summary>
  550. /// <param name="obj">the object</param>
  551. /// <param name="regionUUID">the region UUID</param>
  552. public void RemoveObject(UUID obj, UUID regionUUID)
  553. {
  554. // m_log.InfoFormat("[REGION DB]: Removing obj: {0} from region: {1}", obj.Guid, regionUUID);
  555. DataTable prims = ds.Tables["prims"];
  556. DataTable shapes = ds.Tables["primshapes"];
  557. string selectExp = "SceneGroupID = '" + obj + "' and RegionUUID = '" + regionUUID + "'";
  558. lock (ds)
  559. {
  560. DataRow[] primRows = prims.Select(selectExp);
  561. foreach (DataRow row in primRows)
  562. {
  563. // Remove shape rows
  564. UUID uuid = new UUID((string)row["UUID"]);
  565. DataRow shapeRow = shapes.Rows.Find(uuid.ToString());
  566. if (shapeRow != null)
  567. {
  568. shapeRow.Delete();
  569. }
  570. RemoveItems(uuid);
  571. // Remove prim row
  572. row.Delete();
  573. }
  574. }
  575. Commit();
  576. }
  577. /// <summary>
  578. /// Remove all persisted items of the given prim.
  579. /// The caller must acquire the necessrary synchronization locks and commit or rollback changes.
  580. /// </summary>
  581. /// <param name="uuid">The item UUID</param>
  582. private void RemoveItems(UUID uuid)
  583. {
  584. DataTable items = ds.Tables["primitems"];
  585. String sql = String.Format("primID = '{0}'", uuid);
  586. DataRow[] itemRows = items.Select(sql);
  587. foreach (DataRow itemRow in itemRows)
  588. {
  589. itemRow.Delete();
  590. }
  591. }
  592. /// <summary>
  593. /// Load persisted objects from region storage.
  594. /// </summary>
  595. /// <param name="regionUUID">The region UUID</param>
  596. /// <returns>List of loaded groups</returns>
  597. public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
  598. {
  599. Dictionary<UUID, SceneObjectGroup> createdObjects = new Dictionary<UUID, SceneObjectGroup>();
  600. List<SceneObjectGroup> retvals = new List<SceneObjectGroup>();
  601. DataTable prims = ds.Tables["prims"];
  602. DataTable shapes = ds.Tables["primshapes"];
  603. string byRegion = "RegionUUID = '" + regionUUID + "'";
  604. lock (ds)
  605. {
  606. DataRow[] primsForRegion = prims.Select(byRegion);
  607. // m_log.Info("[SQLITE REGION DB]: Loaded " + primsForRegion.Length + " prims for region: " + regionUUID);
  608. // First, create all groups
  609. foreach (DataRow primRow in primsForRegion)
  610. {
  611. try
  612. {
  613. SceneObjectPart prim = null;
  614. string uuid = (string)primRow["UUID"];
  615. string objID = (string)primRow["SceneGroupID"];
  616. if (uuid == objID) //is new SceneObjectGroup ?
  617. {
  618. prim = buildPrim(primRow);
  619. DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
  620. if (shapeRow != null)
  621. {
  622. prim.Shape = buildShape(shapeRow);
  623. }
  624. else
  625. {
  626. m_log.Warn(
  627. "[SQLITE REGION DB]: No shape found for prim in storage, so setting default box shape");
  628. prim.Shape = PrimitiveBaseShape.Default;
  629. }
  630. SceneObjectGroup group = new SceneObjectGroup(prim);
  631. createdObjects.Add(group.UUID, group);
  632. retvals.Add(group);
  633. LoadItems(prim);
  634. }
  635. }
  636. catch (Exception e)
  637. {
  638. m_log.Error("[SQLITE REGION DB]: Failed create prim object in new group, exception and data follows");
  639. m_log.Error("[SQLITE REGION DB]: ", e);
  640. foreach (DataColumn col in prims.Columns)
  641. {
  642. m_log.Error("[SQLITE REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]);
  643. }
  644. }
  645. }
  646. // Now fill the groups with part data
  647. foreach (DataRow primRow in primsForRegion)
  648. {
  649. try
  650. {
  651. SceneObjectPart prim = null;
  652. string uuid = (string)primRow["UUID"];
  653. string objID = (string)primRow["SceneGroupID"];
  654. if (uuid != objID) //is new SceneObjectGroup ?
  655. {
  656. prim = buildPrim(primRow);
  657. DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
  658. if (shapeRow != null)
  659. {
  660. prim.Shape = buildShape(shapeRow);
  661. }
  662. else
  663. {
  664. m_log.Warn(
  665. "[SQLITE REGION DB]: No shape found for prim in storage, so setting default box shape");
  666. prim.Shape = PrimitiveBaseShape.Default;
  667. }
  668. createdObjects[new UUID(objID)].AddPart(prim);
  669. LoadItems(prim);
  670. }
  671. }
  672. catch (Exception e)
  673. {
  674. m_log.Error("[SQLITE REGION DB]: Failed create prim object in group, exception and data follows");
  675. m_log.Error("[SQLITE REGION DB]: ", e);
  676. foreach (DataColumn col in prims.Columns)
  677. {
  678. m_log.Error("[SQLITE REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]);
  679. }
  680. }
  681. }
  682. }
  683. return retvals;
  684. }
  685. /// <summary>
  686. /// Load in a prim's persisted inventory.
  687. /// </summary>
  688. /// <param name="prim">the prim</param>
  689. private void LoadItems(SceneObjectPart prim)
  690. {
  691. // m_log.DebugFormat("[SQLITE REGION DB]: Loading inventory for {0} {1}", prim.Name, prim.UUID);
  692. DataTable dbItems = ds.Tables["primitems"];
  693. String sql = String.Format("primID = '{0}'", prim.UUID.ToString());
  694. DataRow[] dbItemRows = dbItems.Select(sql);
  695. IList<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
  696. // m_log.DebugFormat("[SQLITE REGION DB]: Found {0} items for {1} {2}", dbItemRows.Length, prim.Name, prim.UUID);
  697. foreach (DataRow row in dbItemRows)
  698. {
  699. TaskInventoryItem item = buildItem(row);
  700. inventory.Add(item);
  701. // m_log.DebugFormat("[SQLITE REGION DB]: Restored item {0} {1}", item.Name, item.ItemID);
  702. }
  703. prim.Inventory.RestoreInventoryItems(inventory);
  704. }
  705. // Legacy entry point for when terrain was always a 256x256 hieghtmap
  706. public void StoreTerrain(double[,] ter, UUID regionID)
  707. {
  708. StoreTerrain(new HeightmapTerrainData(ter), regionID);
  709. }
  710. /// <summary>
  711. /// Store a terrain in region storage
  712. /// </summary>
  713. /// <param name="ter">terrain heightfield</param>
  714. /// <param name="regionID">region UUID</param>
  715. public void StoreTerrain(TerrainData terrData, UUID regionID)
  716. {
  717. lock (ds)
  718. {
  719. using (
  720. SqliteCommand cmd = new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID", m_conn))
  721. {
  722. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  723. cmd.ExecuteNonQuery();
  724. }
  725. // the following is an work around for .NET. The perf
  726. // issues associated with it aren't as bad as you think.
  727. String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" +
  728. " values(:RegionUUID, :Revision, :Heightfield)";
  729. int terrainDBRevision;
  730. Array terrainDBblob;
  731. terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
  732. m_log.DebugFormat("{0} Storing terrain format {1}", LogHeader, terrainDBRevision);
  733. using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
  734. {
  735. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  736. cmd.Parameters.Add(new SqliteParameter(":Revision", terrainDBRevision));
  737. cmd.Parameters.Add(new SqliteParameter(":Heightfield", terrainDBblob));
  738. cmd.ExecuteNonQuery();
  739. }
  740. }
  741. }
  742. /// <summary>
  743. /// Store baked terrain in region storage
  744. /// </summary>
  745. /// <param name="ter">terrain heightfield</param>
  746. /// <param name="regionID">region UUID</param>
  747. public void StoreBakedTerrain(TerrainData terrData, UUID regionID)
  748. {
  749. lock (ds)
  750. {
  751. using (
  752. SqliteCommand cmd = new SqliteCommand("delete from bakedterrain where RegionUUID=:RegionUUID", m_conn))
  753. {
  754. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  755. cmd.ExecuteNonQuery();
  756. }
  757. // the following is an work around for .NET. The perf
  758. // issues associated with it aren't as bad as you think.
  759. String sql = "insert into bakedterrain(RegionUUID, Revision, Heightfield)" +
  760. " values(:RegionUUID, :Revision, :Heightfield)";
  761. int terrainDBRevision;
  762. Array terrainDBblob;
  763. terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
  764. m_log.DebugFormat("{0} Storing bakedterrain format {1}", LogHeader, terrainDBRevision);
  765. using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
  766. {
  767. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  768. cmd.Parameters.Add(new SqliteParameter(":Revision", terrainDBRevision));
  769. cmd.Parameters.Add(new SqliteParameter(":Heightfield", terrainDBblob));
  770. cmd.ExecuteNonQuery();
  771. }
  772. }
  773. }
  774. /// <summary>
  775. /// Load the latest terrain revision from region storage
  776. /// </summary>
  777. /// <param name="regionID">the region UUID</param>
  778. /// <returns>Heightfield data</returns>
  779. public double[,] LoadTerrain(UUID regionID)
  780. {
  781. double[,] ret = null;
  782. TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
  783. if (terrData != null)
  784. ret = terrData.GetDoubles();
  785. return ret;
  786. }
  787. // Returns 'null' if region not found
  788. public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
  789. {
  790. TerrainData terrData = null;
  791. lock (ds)
  792. {
  793. String sql = "select RegionUUID, Revision, Heightfield from terrain" +
  794. " where RegionUUID=:RegionUUID order by Revision desc";
  795. using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
  796. {
  797. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  798. using (IDataReader row = cmd.ExecuteReader())
  799. {
  800. int rev = 0;
  801. if (row.Read())
  802. {
  803. rev = Convert.ToInt32(row["Revision"]);
  804. byte[] blob = (byte[])row["Heightfield"];
  805. terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
  806. }
  807. else
  808. {
  809. m_log.Warn("[SQLITE REGION DB]: No terrain found for region");
  810. return null;
  811. }
  812. m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString());
  813. }
  814. }
  815. }
  816. return terrData;
  817. }
  818. public TerrainData LoadBakedTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
  819. {
  820. TerrainData terrData = null;
  821. lock (ds)
  822. {
  823. String sql = "select RegionUUID, Revision, Heightfield from bakedterrain" +
  824. " where RegionUUID=:RegionUUID";
  825. using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
  826. {
  827. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  828. using (IDataReader row = cmd.ExecuteReader())
  829. {
  830. int rev = 0;
  831. if (row.Read())
  832. {
  833. rev = Convert.ToInt32(row["Revision"]);
  834. byte[] blob = (byte[])row["Heightfield"];
  835. terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
  836. }
  837. }
  838. }
  839. }
  840. return terrData;
  841. }
  842. public void RemoveLandObject(UUID globalID)
  843. {
  844. lock (ds)
  845. {
  846. // Can't use blanket SQL statements when using SqlAdapters unless you re-read the data into the adapter
  847. // after you're done.
  848. // replaced below code with the SqliteAdapter version.
  849. //using (SqliteCommand cmd = new SqliteCommand("delete from land where UUID=:UUID", m_conn))
  850. //{
  851. // cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString()));
  852. // cmd.ExecuteNonQuery();
  853. //}
  854. //using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:UUID", m_conn))
  855. //{
  856. // cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString()));
  857. // cmd.ExecuteNonQuery();
  858. //}
  859. DataTable land = ds.Tables["land"];
  860. DataTable landaccesslist = ds.Tables["landaccesslist"];
  861. DataRow landRow = land.Rows.Find(globalID.ToString());
  862. if (landRow != null)
  863. {
  864. landRow.Delete();
  865. }
  866. List<DataRow> rowsToDelete = new List<DataRow>();
  867. foreach (DataRow rowToCheck in landaccesslist.Rows)
  868. {
  869. if (rowToCheck["LandUUID"].ToString() == globalID.ToString())
  870. rowsToDelete.Add(rowToCheck);
  871. }
  872. for (int iter = 0; iter < rowsToDelete.Count; iter++)
  873. {
  874. rowsToDelete[iter].Delete();
  875. }
  876. }
  877. Commit();
  878. }
  879. /// <summary>
  880. ///
  881. /// </summary>
  882. /// <param name="parcel"></param>
  883. public void StoreLandObject(ILandObject parcel)
  884. {
  885. lock (ds)
  886. {
  887. DataTable land = ds.Tables["land"];
  888. DataTable landaccesslist = ds.Tables["landaccesslist"];
  889. DataRow landRow = land.Rows.Find(parcel.LandData.GlobalID.ToString());
  890. if (landRow == null)
  891. {
  892. landRow = land.NewRow();
  893. fillLandRow(landRow, parcel.LandData, parcel.RegionUUID);
  894. land.Rows.Add(landRow);
  895. }
  896. else
  897. {
  898. fillLandRow(landRow, parcel.LandData, parcel.RegionUUID);
  899. }
  900. // I know this caused someone issues before, but OpenSim is unusable if we leave this stuff around
  901. //using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:LandUUID", m_conn))
  902. //{
  903. // cmd.Parameters.Add(new SqliteParameter(":LandUUID", parcel.LandData.GlobalID.ToString()));
  904. // cmd.ExecuteNonQuery();
  905. // }
  906. // This is the slower.. but more appropriate thing to do
  907. // We can't modify the table with direct queries before calling Commit() and re-filling them.
  908. List<DataRow> rowsToDelete = new List<DataRow>();
  909. foreach (DataRow rowToCheck in landaccesslist.Rows)
  910. {
  911. if (rowToCheck["LandUUID"].ToString() == parcel.LandData.GlobalID.ToString())
  912. rowsToDelete.Add(rowToCheck);
  913. }
  914. for (int iter = 0; iter < rowsToDelete.Count; iter++)
  915. {
  916. rowsToDelete[iter].Delete();
  917. landaccesslist.Rows.Remove(rowsToDelete[iter]);
  918. }
  919. rowsToDelete.Clear();
  920. foreach (LandAccessEntry entry in parcel.LandData.ParcelAccessList)
  921. {
  922. DataRow newAccessRow = landaccesslist.NewRow();
  923. fillLandAccessRow(newAccessRow, entry, parcel.LandData.GlobalID);
  924. landaccesslist.Rows.Add(newAccessRow);
  925. }
  926. }
  927. Commit();
  928. }
  929. /// <summary>
  930. ///
  931. /// </summary>
  932. /// <param name="regionUUID"></param>
  933. /// <returns></returns>
  934. public List<LandData> LoadLandObjects(UUID regionUUID)
  935. {
  936. List<LandData> landDataForRegion = new List<LandData>();
  937. lock (ds)
  938. {
  939. DataTable land = ds.Tables["land"];
  940. DataTable landaccesslist = ds.Tables["landaccesslist"];
  941. string searchExp = "RegionUUID = '" + regionUUID + "'";
  942. DataRow[] rawDataForRegion = land.Select(searchExp);
  943. foreach (DataRow rawDataLand in rawDataForRegion)
  944. {
  945. LandData newLand = buildLandData(rawDataLand);
  946. string accessListSearchExp = "LandUUID = '" + newLand.GlobalID + "'";
  947. DataRow[] rawDataForLandAccessList = landaccesslist.Select(accessListSearchExp);
  948. foreach (DataRow rawDataLandAccess in rawDataForLandAccessList)
  949. {
  950. newLand.ParcelAccessList.Add(buildLandAccessData(rawDataLandAccess));
  951. }
  952. landDataForRegion.Add(newLand);
  953. }
  954. }
  955. return landDataForRegion;
  956. }
  957. /// <summary>
  958. ///
  959. /// </summary>
  960. public void Commit()
  961. {
  962. // m_log.Debug("[SQLITE]: Starting commit");
  963. lock (ds)
  964. {
  965. primDa.Update(ds, "prims");
  966. shapeDa.Update(ds, "primshapes");
  967. itemsDa.Update(ds, "primitems");
  968. terrainDa.Update(ds, "terrain");
  969. landDa.Update(ds, "land");
  970. landAccessListDa.Update(ds, "landaccesslist");
  971. try
  972. {
  973. regionSettingsDa.Update(ds, "regionsettings");
  974. regionWindlightDa.Update(ds, "regionwindlight");
  975. }
  976. catch (SqliteException SqlEx)
  977. {
  978. throw new Exception(
  979. "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!",
  980. SqlEx);
  981. }
  982. ds.AcceptChanges();
  983. }
  984. }
  985. /// <summary>
  986. /// See <see cref="Commit"/>
  987. /// </summary>
  988. public void Shutdown()
  989. {
  990. Commit();
  991. }
  992. /***********************************************************************
  993. *
  994. * Database Definition Functions
  995. *
  996. * This should be db agnostic as we define them in ADO.NET terms
  997. *
  998. **********************************************************************/
  999. protected void CreateDataSetMapping(IDataAdapter da, string tableName)
  1000. {
  1001. ITableMapping dbMapping = da.TableMappings.Add(tableName, tableName);
  1002. foreach (DataColumn col in ds.Tables[tableName].Columns)
  1003. {
  1004. dbMapping.ColumnMappings.Add(col.ColumnName, col.ColumnName);
  1005. }
  1006. }
  1007. /// <summary>
  1008. ///
  1009. /// </summary>
  1010. /// <param name="dt"></param>
  1011. /// <param name="name"></param>
  1012. /// <param name="type"></param>
  1013. private static void createCol(DataTable dt, string name, Type type)
  1014. {
  1015. DataColumn col = new DataColumn(name, type);
  1016. dt.Columns.Add(col);
  1017. }
  1018. /// <summary>
  1019. /// Creates the "terrain" table
  1020. /// </summary>
  1021. /// <returns>terrain table DataTable</returns>
  1022. private static DataTable createTerrainTable()
  1023. {
  1024. DataTable terrain = new DataTable("terrain");
  1025. createCol(terrain, "RegionUUID", typeof(String));
  1026. createCol(terrain, "Revision", typeof(Int32));
  1027. createCol(terrain, "Heightfield", typeof(Byte[]));
  1028. return terrain;
  1029. }
  1030. /// <summary>
  1031. /// Creates the "prims" table
  1032. /// </summary>
  1033. /// <returns>prim table DataTable</returns>
  1034. private static DataTable createPrimTable()
  1035. {
  1036. DataTable prims = new DataTable("prims");
  1037. createCol(prims, "UUID", typeof(String));
  1038. createCol(prims, "RegionUUID", typeof(String));
  1039. createCol(prims, "CreationDate", typeof(Int32));
  1040. createCol(prims, "Name", typeof(String));
  1041. createCol(prims, "SceneGroupID", typeof(String));
  1042. // various text fields
  1043. createCol(prims, "Text", typeof(String));
  1044. createCol(prims, "ColorR", typeof(Int32));
  1045. createCol(prims, "ColorG", typeof(Int32));
  1046. createCol(prims, "ColorB", typeof(Int32));
  1047. createCol(prims, "ColorA", typeof(Int32));
  1048. createCol(prims, "Description", typeof(String));
  1049. createCol(prims, "SitName", typeof(String));
  1050. createCol(prims, "TouchName", typeof(String));
  1051. // permissions
  1052. createCol(prims, "ObjectFlags", typeof(Int32));
  1053. createCol(prims, "CreatorID", typeof(String));
  1054. createCol(prims, "OwnerID", typeof(String));
  1055. createCol(prims, "GroupID", typeof(String));
  1056. createCol(prims, "LastOwnerID", typeof(String));
  1057. createCol(prims, "RezzerID", typeof(String));
  1058. createCol(prims, "OwnerMask", typeof(Int32));
  1059. createCol(prims, "NextOwnerMask", typeof(Int32));
  1060. createCol(prims, "GroupMask", typeof(Int32));
  1061. createCol(prims, "EveryoneMask", typeof(Int32));
  1062. createCol(prims, "BaseMask", typeof(Int32));
  1063. // vectors
  1064. createCol(prims, "PositionX", typeof(Double));
  1065. createCol(prims, "PositionY", typeof(Double));
  1066. createCol(prims, "PositionZ", typeof(Double));
  1067. createCol(prims, "GroupPositionX", typeof(Double));
  1068. createCol(prims, "GroupPositionY", typeof(Double));
  1069. createCol(prims, "GroupPositionZ", typeof(Double));
  1070. createCol(prims, "VelocityX", typeof(Double));
  1071. createCol(prims, "VelocityY", typeof(Double));
  1072. createCol(prims, "VelocityZ", typeof(Double));
  1073. createCol(prims, "AngularVelocityX", typeof(Double));
  1074. createCol(prims, "AngularVelocityY", typeof(Double));
  1075. createCol(prims, "AngularVelocityZ", typeof(Double));
  1076. createCol(prims, "AccelerationX", typeof(Double));
  1077. createCol(prims, "AccelerationY", typeof(Double));
  1078. createCol(prims, "AccelerationZ", typeof(Double));
  1079. // quaternions
  1080. createCol(prims, "RotationX", typeof(Double));
  1081. createCol(prims, "RotationY", typeof(Double));
  1082. createCol(prims, "RotationZ", typeof(Double));
  1083. createCol(prims, "RotationW", typeof(Double));
  1084. // sit target
  1085. createCol(prims, "SitTargetOffsetX", typeof(Double));
  1086. createCol(prims, "SitTargetOffsetY", typeof(Double));
  1087. createCol(prims, "SitTargetOffsetZ", typeof(Double));
  1088. createCol(prims, "SitTargetOrientW", typeof(Double));
  1089. createCol(prims, "SitTargetOrientX", typeof(Double));
  1090. createCol(prims, "SitTargetOrientY", typeof(Double));
  1091. createCol(prims, "SitTargetOrientZ", typeof(Double));
  1092. createCol(prims, "PayPrice", typeof(Int32));
  1093. createCol(prims, "PayButton1", typeof(Int32));
  1094. createCol(prims, "PayButton2", typeof(Int32));
  1095. createCol(prims, "PayButton3", typeof(Int32));
  1096. createCol(prims, "PayButton4", typeof(Int32));
  1097. createCol(prims, "LoopedSound", typeof(String));
  1098. createCol(prims, "LoopedSoundGain", typeof(Double));
  1099. createCol(prims, "TextureAnimation", typeof(String));
  1100. createCol(prims, "ParticleSystem", typeof(String));
  1101. createCol(prims, "OmegaX", typeof(Double));
  1102. createCol(prims, "OmegaY", typeof(Double));
  1103. createCol(prims, "OmegaZ", typeof(Double));
  1104. createCol(prims, "CameraEyeOffsetX", typeof(Double));
  1105. createCol(prims, "CameraEyeOffsetY", typeof(Double));
  1106. createCol(prims, "CameraEyeOffsetZ", typeof(Double));
  1107. createCol(prims, "CameraAtOffsetX", typeof(Double));
  1108. createCol(prims, "CameraAtOffsetY", typeof(Double));
  1109. createCol(prims, "CameraAtOffsetZ", typeof(Double));
  1110. createCol(prims, "ForceMouselook", typeof(Int16));
  1111. createCol(prims, "ScriptAccessPin", typeof(Int32));
  1112. createCol(prims, "AllowedDrop", typeof(Int16));
  1113. createCol(prims, "DieAtEdge", typeof(Int16));
  1114. createCol(prims, "SalePrice", typeof(Int32));
  1115. createCol(prims, "SaleType", typeof(Int16));
  1116. // click action
  1117. createCol(prims, "ClickAction", typeof(Byte));
  1118. createCol(prims, "Material", typeof(Byte));
  1119. createCol(prims, "CollisionSound", typeof(String));
  1120. createCol(prims, "CollisionSoundVolume", typeof(Double));
  1121. createCol(prims, "VolumeDetect", typeof(Int16));
  1122. createCol(prims, "MediaURL", typeof(String));
  1123. createCol(prims, "AttachedPosX", typeof(Double));
  1124. createCol(prims, "AttachedPosY", typeof(Double));
  1125. createCol(prims, "AttachedPosZ", typeof(Double));
  1126. createCol(prims, "DynAttrs", typeof(String));
  1127. createCol(prims, "PhysicsShapeType", typeof(Byte));
  1128. createCol(prims, "Density", typeof(Double));
  1129. createCol(prims, "GravityModifier", typeof(Double));
  1130. createCol(prims, "Friction", typeof(Double));
  1131. createCol(prims, "Restitution", typeof(Double));
  1132. createCol(prims, "KeyframeMotion", typeof(Byte[]));
  1133. // Add in contraints
  1134. prims.PrimaryKey = new DataColumn[] { prims.Columns["UUID"] };
  1135. return prims;
  1136. }
  1137. /// <summary>
  1138. /// Creates "primshapes" table
  1139. /// </summary>
  1140. /// <returns>shape table DataTable</returns>
  1141. private static DataTable createShapeTable()
  1142. {
  1143. DataTable shapes = new DataTable("primshapes");
  1144. createCol(shapes, "UUID", typeof(String));
  1145. // shape is an enum
  1146. createCol(shapes, "Shape", typeof(Int32));
  1147. // vectors
  1148. createCol(shapes, "ScaleX", typeof(Double));
  1149. createCol(shapes, "ScaleY", typeof(Double));
  1150. createCol(shapes, "ScaleZ", typeof(Double));
  1151. // paths
  1152. createCol(shapes, "PCode", typeof(Int32));
  1153. createCol(shapes, "PathBegin", typeof(Int32));
  1154. createCol(shapes, "PathEnd", typeof(Int32));
  1155. createCol(shapes, "PathScaleX", typeof(Int32));
  1156. createCol(shapes, "PathScaleY", typeof(Int32));
  1157. createCol(shapes, "PathShearX", typeof(Int32));
  1158. createCol(shapes, "PathShearY", typeof(Int32));
  1159. createCol(shapes, "PathSkew", typeof(Int32));
  1160. createCol(shapes, "PathCurve", typeof(Int32));
  1161. createCol(shapes, "PathRadiusOffset", typeof(Int32));
  1162. createCol(shapes, "PathRevolutions", typeof(Int32));
  1163. createCol(shapes, "PathTaperX", typeof(Int32));
  1164. createCol(shapes, "PathTaperY", typeof(Int32));
  1165. createCol(shapes, "PathTwist", typeof(Int32));
  1166. createCol(shapes, "PathTwistBegin", typeof(Int32));
  1167. // profile
  1168. createCol(shapes, "ProfileBegin", typeof(Int32));
  1169. createCol(shapes, "ProfileEnd", typeof(Int32));
  1170. createCol(shapes, "ProfileCurve", typeof(Int32));
  1171. createCol(shapes, "ProfileHollow", typeof(Int32));
  1172. createCol(shapes, "State", typeof(Int32));
  1173. // text TODO: this isn't right, but I'm not sure the right
  1174. // way to specify this as a blob atm
  1175. createCol(shapes, "Texture", typeof(Byte[]));
  1176. createCol(shapes, "ExtraParams", typeof(Byte[]));
  1177. createCol(shapes, "Media", typeof(String));
  1178. shapes.PrimaryKey = new DataColumn[] { shapes.Columns["UUID"] };
  1179. return shapes;
  1180. }
  1181. /// <summary>
  1182. /// creates "primitems" table
  1183. /// </summary>
  1184. /// <returns>item table DataTable</returns>
  1185. private static DataTable createItemsTable()
  1186. {
  1187. DataTable items = new DataTable("primitems");
  1188. createCol(items, "itemID", typeof(String));
  1189. createCol(items, "primID", typeof(String));
  1190. createCol(items, "assetID", typeof(String));
  1191. createCol(items, "parentFolderID", typeof(String));
  1192. createCol(items, "invType", typeof(Int32));
  1193. createCol(items, "assetType", typeof(Int32));
  1194. createCol(items, "name", typeof(String));
  1195. createCol(items, "description", typeof(String));
  1196. createCol(items, "creationDate", typeof(Int64));
  1197. createCol(items, "creatorID", typeof(String));
  1198. createCol(items, "ownerID", typeof(String));
  1199. createCol(items, "lastOwnerID", typeof(String));
  1200. createCol(items, "groupID", typeof(String));
  1201. createCol(items, "nextPermissions", typeof(UInt32));
  1202. createCol(items, "currentPermissions", typeof(UInt32));
  1203. createCol(items, "basePermissions", typeof(UInt32));
  1204. createCol(items, "everyonePermissions", typeof(UInt32));
  1205. createCol(items, "groupPermissions", typeof(UInt32));
  1206. createCol(items, "flags", typeof(UInt32));
  1207. items.PrimaryKey = new DataColumn[] { items.Columns["itemID"] };
  1208. return items;
  1209. }
  1210. /// <summary>
  1211. /// Creates "land" table
  1212. /// </summary>
  1213. /// <returns>land table DataTable</returns>
  1214. private static DataTable createLandTable()
  1215. {
  1216. DataTable land = new DataTable("land");
  1217. createCol(land, "UUID", typeof(String));
  1218. createCol(land, "RegionUUID", typeof(String));
  1219. createCol(land, "LocalLandID", typeof(UInt32));
  1220. // Bitmap is a byte[512]
  1221. createCol(land, "Bitmap", typeof(Byte[]));
  1222. createCol(land, "Name", typeof(String));
  1223. createCol(land, "Desc", typeof(String));
  1224. createCol(land, "OwnerUUID", typeof(String));
  1225. createCol(land, "IsGroupOwned", typeof(string));
  1226. createCol(land, "Area", typeof(Int32));
  1227. createCol(land, "AuctionID", typeof(Int32)); //Unemplemented
  1228. createCol(land, "Category", typeof(Int32)); //Enum OpenMetaverse.Parcel.ParcelCategory
  1229. createCol(land, "ClaimDate", typeof(Int32));
  1230. createCol(land, "ClaimPrice", typeof(Int32));
  1231. createCol(land, "GroupUUID", typeof(string));
  1232. createCol(land, "SalePrice", typeof(Int32));
  1233. createCol(land, "LandStatus", typeof(Int32)); //Enum. OpenMetaverse.Parcel.ParcelStatus
  1234. createCol(land, "LandFlags", typeof(UInt32));
  1235. createCol(land, "LandingType", typeof(Byte));
  1236. createCol(land, "MediaAutoScale", typeof(Byte));
  1237. createCol(land, "MediaTextureUUID", typeof(String));
  1238. createCol(land, "MediaURL", typeof(String));
  1239. createCol(land, "MusicURL", typeof(String));
  1240. createCol(land, "PassHours", typeof(Double));
  1241. createCol(land, "PassPrice", typeof(UInt32));
  1242. createCol(land, "SnapshotUUID", typeof(String));
  1243. createCol(land, "UserLocationX", typeof(Double));
  1244. createCol(land, "UserLocationY", typeof(Double));
  1245. createCol(land, "UserLocationZ", typeof(Double));
  1246. createCol(land, "UserLookAtX", typeof(Double));
  1247. createCol(land, "UserLookAtY", typeof(Double));
  1248. createCol(land, "UserLookAtZ", typeof(Double));
  1249. createCol(land, "AuthbuyerID", typeof(String));
  1250. createCol(land, "OtherCleanTime", typeof(Int32));
  1251. createCol(land, "Dwell", typeof(Int32));
  1252. createCol(land, "MediaType", typeof(String));
  1253. createCol(land, "MediaDescription", typeof(String));
  1254. createCol(land, "MediaSize", typeof(String));
  1255. createCol(land, "MediaLoop", typeof(Boolean));
  1256. createCol(land, "ObscureMedia", typeof(Boolean));
  1257. createCol(land, "ObscureMusic", typeof(Boolean));
  1258. createCol(land, "SeeAVs", typeof(Boolean));
  1259. createCol(land, "AnyAVSounds", typeof(Boolean));
  1260. createCol(land, "GroupAVSounds", typeof(Boolean));
  1261. land.PrimaryKey = new DataColumn[] { land.Columns["UUID"] };
  1262. return land;
  1263. }
  1264. /// <summary>
  1265. /// create "landaccesslist" table
  1266. /// </summary>
  1267. /// <returns>Landacceslist DataTable</returns>
  1268. private static DataTable createLandAccessListTable()
  1269. {
  1270. DataTable landaccess = new DataTable("landaccesslist");
  1271. createCol(landaccess, "LandUUID", typeof(String));
  1272. createCol(landaccess, "AccessUUID", typeof(String));
  1273. createCol(landaccess, "Flags", typeof(UInt32));
  1274. return landaccess;
  1275. }
  1276. private static DataTable createRegionSettingsTable()
  1277. {
  1278. DataTable regionsettings = new DataTable("regionsettings");
  1279. createCol(regionsettings, "regionUUID", typeof(String));
  1280. createCol(regionsettings, "block_terraform", typeof(Int32));
  1281. createCol(regionsettings, "block_fly", typeof(Int32));
  1282. createCol(regionsettings, "allow_damage", typeof(Int32));
  1283. createCol(regionsettings, "restrict_pushing", typeof(Int32));
  1284. createCol(regionsettings, "allow_land_resell", typeof(Int32));
  1285. createCol(regionsettings, "allow_land_join_divide", typeof(Int32));
  1286. createCol(regionsettings, "block_show_in_search", typeof(Int32));
  1287. createCol(regionsettings, "agent_limit", typeof(Int32));
  1288. createCol(regionsettings, "object_bonus", typeof(Double));
  1289. createCol(regionsettings, "maturity", typeof(Int32));
  1290. createCol(regionsettings, "disable_scripts", typeof(Int32));
  1291. createCol(regionsettings, "disable_collisions", typeof(Int32));
  1292. createCol(regionsettings, "disable_physics", typeof(Int32));
  1293. createCol(regionsettings, "terrain_texture_1", typeof(String));
  1294. createCol(regionsettings, "terrain_texture_2", typeof(String));
  1295. createCol(regionsettings, "terrain_texture_3", typeof(String));
  1296. createCol(regionsettings, "terrain_texture_4", typeof(String));
  1297. createCol(regionsettings, "elevation_1_nw", typeof(Double));
  1298. createCol(regionsettings, "elevation_2_nw", typeof(Double));
  1299. createCol(regionsettings, "elevation_1_ne", typeof(Double));
  1300. createCol(regionsettings, "elevation_2_ne", typeof(Double));
  1301. createCol(regionsettings, "elevation_1_se", typeof(Double));
  1302. createCol(regionsettings, "elevation_2_se", typeof(Double));
  1303. createCol(regionsettings, "elevation_1_sw", typeof(Double));
  1304. createCol(regionsettings, "elevation_2_sw", typeof(Double));
  1305. createCol(regionsettings, "water_height", typeof(Double));
  1306. createCol(regionsettings, "terrain_raise_limit", typeof(Double));
  1307. createCol(regionsettings, "terrain_lower_limit", typeof(Double));
  1308. createCol(regionsettings, "use_estate_sun", typeof(Int32));
  1309. createCol(regionsettings, "sandbox", typeof(Int32));
  1310. createCol(regionsettings, "sunvectorx", typeof(Double));
  1311. createCol(regionsettings, "sunvectory", typeof(Double));
  1312. createCol(regionsettings, "sunvectorz", typeof(Double));
  1313. createCol(regionsettings, "fixed_sun", typeof(Int32));
  1314. createCol(regionsettings, "sun_position", typeof(Double));
  1315. createCol(regionsettings, "covenant", typeof(String));
  1316. createCol(regionsettings, "covenant_datetime", typeof(Int32));
  1317. createCol(regionsettings, "map_tile_ID", typeof(String));
  1318. createCol(regionsettings, "TelehubObject", typeof(String));
  1319. createCol(regionsettings, "parcel_tile_ID", typeof(String));
  1320. regionsettings.PrimaryKey = new DataColumn[] { regionsettings.Columns["regionUUID"] };
  1321. return regionsettings;
  1322. }
  1323. /// <summary>
  1324. /// create "regionwindlight" table
  1325. /// </summary>
  1326. /// <returns>RegionWindlight DataTable</returns>
  1327. private static DataTable createRegionWindlightTable()
  1328. {
  1329. DataTable regionwindlight = new DataTable("regionwindlight");
  1330. createCol(regionwindlight, "region_id", typeof(String));
  1331. createCol(regionwindlight, "water_color_r", typeof(Double));
  1332. createCol(regionwindlight, "water_color_g", typeof(Double));
  1333. createCol(regionwindlight, "water_color_b", typeof(Double));
  1334. createCol(regionwindlight, "water_color_i", typeof(Double));
  1335. createCol(regionwindlight, "water_fog_density_exponent", typeof(Double));
  1336. createCol(regionwindlight, "underwater_fog_modifier", typeof(Double));
  1337. createCol(regionwindlight, "reflection_wavelet_scale_1", typeof(Double));
  1338. createCol(regionwindlight, "reflection_wavelet_scale_2", typeof(Double));
  1339. createCol(regionwindlight, "reflection_wavelet_scale_3", typeof(Double));
  1340. createCol(regionwindlight, "fresnel_scale", typeof(Double));
  1341. createCol(regionwindlight, "fresnel_offset", typeof(Double));
  1342. createCol(regionwindlight, "refract_scale_above", typeof(Double));
  1343. createCol(regionwindlight, "refract_scale_below", typeof(Double));
  1344. createCol(regionwindlight, "blur_multiplier", typeof(Double));
  1345. createCol(regionwindlight, "big_wave_direction_x", typeof(Double));
  1346. createCol(regionwindlight, "big_wave_direction_y", typeof(Double));
  1347. createCol(regionwindlight, "little_wave_direction_x", typeof(Double));
  1348. createCol(regionwindlight, "little_wave_direction_y", typeof(Double));
  1349. createCol(regionwindlight, "normal_map_texture", typeof(String));
  1350. createCol(regionwindlight, "horizon_r", typeof(Double));
  1351. createCol(regionwindlight, "horizon_g", typeof(Double));
  1352. createCol(regionwindlight, "horizon_b", typeof(Double));
  1353. createCol(regionwindlight, "horizon_i", typeof(Double));
  1354. createCol(regionwindlight, "haze_horizon", typeof(Double));
  1355. createCol(regionwindlight, "blue_density_r", typeof(Double));
  1356. createCol(regionwindlight, "blue_density_g", typeof(Double));
  1357. createCol(regionwindlight, "blue_density_b", typeof(Double));
  1358. createCol(regionwindlight, "blue_density_i", typeof(Double));
  1359. createCol(regionwindlight, "haze_density", typeof(Double));
  1360. createCol(regionwindlight, "density_multiplier", typeof(Double));
  1361. createCol(regionwindlight, "distance_multiplier", typeof(Double));
  1362. createCol(regionwindlight, "max_altitude", typeof(Int32));
  1363. createCol(regionwindlight, "sun_moon_color_r", typeof(Double));
  1364. createCol(regionwindlight, "sun_moon_color_g", typeof(Double));
  1365. createCol(regionwindlight, "sun_moon_color_b", typeof(Double));
  1366. createCol(regionwindlight, "sun_moon_color_i", typeof(Double));
  1367. createCol(regionwindlight, "sun_moon_position", typeof(Double));
  1368. createCol(regionwindlight, "ambient_r", typeof(Double));
  1369. createCol(regionwindlight, "ambient_g", typeof(Double));
  1370. createCol(regionwindlight, "ambient_b", typeof(Double));
  1371. createCol(regionwindlight, "ambient_i", typeof(Double));
  1372. createCol(regionwindlight, "east_angle", typeof(Double));
  1373. createCol(regionwindlight, "sun_glow_focus", typeof(Double));
  1374. createCol(regionwindlight, "sun_glow_size", typeof(Double));
  1375. createCol(regionwindlight, "scene_gamma", typeof(Double));
  1376. createCol(regionwindlight, "star_brightness", typeof(Double));
  1377. createCol(regionwindlight, "cloud_color_r", typeof(Double));
  1378. createCol(regionwindlight, "cloud_color_g", typeof(Double));
  1379. createCol(regionwindlight, "cloud_color_b", typeof(Double));
  1380. createCol(regionwindlight, "cloud_color_i", typeof(Double));
  1381. createCol(regionwindlight, "cloud_x", typeof(Double));
  1382. createCol(regionwindlight, "cloud_y", typeof(Double));
  1383. createCol(regionwindlight, "cloud_density", typeof(Double));
  1384. createCol(regionwindlight, "cloud_coverage", typeof(Double));
  1385. createCol(regionwindlight, "cloud_scale", typeof(Double));
  1386. createCol(regionwindlight, "cloud_detail_x", typeof(Double));
  1387. createCol(regionwindlight, "cloud_detail_y", typeof(Double));
  1388. createCol(regionwindlight, "cloud_detail_density", typeof(Double));
  1389. createCol(regionwindlight, "cloud_scroll_x", typeof(Double));
  1390. createCol(regionwindlight, "cloud_scroll_x_lock", typeof(Int32));
  1391. createCol(regionwindlight, "cloud_scroll_y", typeof(Double));
  1392. createCol(regionwindlight, "cloud_scroll_y_lock", typeof(Int32));
  1393. createCol(regionwindlight, "draw_classic_clouds", typeof(Int32));
  1394. regionwindlight.PrimaryKey = new DataColumn[] { regionwindlight.Columns["region_id"] };
  1395. return regionwindlight;
  1396. }
  1397. private static DataTable createRegionEnvironmentTable()
  1398. {
  1399. DataTable regionEnvironment = new DataTable("regionenvironment");
  1400. createCol(regionEnvironment, "region_id", typeof(String));
  1401. createCol(regionEnvironment, "llsd_settings", typeof(String));
  1402. regionEnvironment.PrimaryKey = new DataColumn[] { regionEnvironment.Columns["region_id"] };
  1403. return regionEnvironment;
  1404. }
  1405. private static DataTable createRegionSpawnPointsTable()
  1406. {
  1407. DataTable spawn_points = new DataTable("spawn_points");
  1408. createCol(spawn_points, "regionID", typeof(String));
  1409. createCol(spawn_points, "Yaw", typeof(float));
  1410. createCol(spawn_points, "Pitch", typeof(float));
  1411. createCol(spawn_points, "Distance", typeof(float));
  1412. return spawn_points;
  1413. }
  1414. /***********************************************************************
  1415. *
  1416. * Convert between ADO.NET <=> OpenSim Objects
  1417. *
  1418. * These should be database independant
  1419. *
  1420. **********************************************************************/
  1421. /// <summary>
  1422. ///
  1423. /// </summary>
  1424. /// <param name="row"></param>
  1425. /// <returns></returns>
  1426. private SceneObjectPart buildPrim(DataRow row)
  1427. {
  1428. // Code commented. Uncomment to test the unit test inline.
  1429. // The unit test mentions this commented code for the purposes
  1430. // of debugging a unit test failure
  1431. // SceneObjectGroup sog = new SceneObjectGroup();
  1432. // SceneObjectPart sop = new SceneObjectPart();
  1433. // sop.LocalId = 1;
  1434. // sop.Name = "object1";
  1435. // sop.Description = "object1";
  1436. // sop.Text = "";
  1437. // sop.SitName = "";
  1438. // sop.TouchName = "";
  1439. // sop.UUID = UUID.Random();
  1440. // sop.Shape = PrimitiveBaseShape.Default;
  1441. // sog.SetRootPart(sop);
  1442. // Add breakpoint in above line. Check sop fields.
  1443. // TODO: this doesn't work yet because something more
  1444. // interesting has to be done to actually get these values
  1445. // back out. Not enough time to figure it out yet.
  1446. SceneObjectPart prim = new SceneObjectPart();
  1447. prim.UUID = new UUID((String)row["UUID"]);
  1448. // explicit conversion of integers is required, which sort
  1449. // of sucks. No idea if there is a shortcut here or not.
  1450. prim.CreationDate = Convert.ToInt32(row["CreationDate"]);
  1451. prim.Name = row["Name"] == DBNull.Value ? string.Empty : (string)row["Name"];
  1452. // various text fields
  1453. prim.Text = (String)row["Text"];
  1454. prim.Color = Color.FromArgb(Convert.ToInt32(row["ColorA"]),
  1455. Convert.ToInt32(row["ColorR"]),
  1456. Convert.ToInt32(row["ColorG"]),
  1457. Convert.ToInt32(row["ColorB"]));
  1458. prim.Description = (String)row["Description"];
  1459. prim.SitName = (String)row["SitName"];
  1460. prim.TouchName = (String)row["TouchName"];
  1461. // permissions
  1462. prim.Flags = (PrimFlags)Convert.ToUInt32(row["ObjectFlags"]);
  1463. prim.CreatorIdentification = (String)row["CreatorID"];
  1464. prim.OwnerID = new UUID((String)row["OwnerID"]);
  1465. prim.GroupID = new UUID((String)row["GroupID"]);
  1466. prim.LastOwnerID = new UUID((String)row["LastOwnerID"]);
  1467. prim.RezzerID = row["RezzerID"] == DBNull.Value ? UUID.Zero : new UUID((String)row["RezzerID"]);
  1468. prim.OwnerMask = Convert.ToUInt32(row["OwnerMask"]);
  1469. prim.NextOwnerMask = Convert.ToUInt32(row["NextOwnerMask"]);
  1470. prim.GroupMask = Convert.ToUInt32(row["GroupMask"]);
  1471. prim.EveryoneMask = Convert.ToUInt32(row["EveryoneMask"]);
  1472. prim.BaseMask = Convert.ToUInt32(row["BaseMask"]);
  1473. // vectors
  1474. prim.OffsetPosition = new Vector3(
  1475. Convert.ToSingle(row["PositionX"]),
  1476. Convert.ToSingle(row["PositionY"]),
  1477. Convert.ToSingle(row["PositionZ"])
  1478. );
  1479. prim.GroupPosition = new Vector3(
  1480. Convert.ToSingle(row["GroupPositionX"]),
  1481. Convert.ToSingle(row["GroupPositionY"]),
  1482. Convert.ToSingle(row["GroupPositionZ"])
  1483. );
  1484. prim.Velocity = new Vector3(
  1485. Convert.ToSingle(row["VelocityX"]),
  1486. Convert.ToSingle(row["VelocityY"]),
  1487. Convert.ToSingle(row["VelocityZ"])
  1488. );
  1489. prim.AngularVelocity = new Vector3(
  1490. Convert.ToSingle(row["AngularVelocityX"]),
  1491. Convert.ToSingle(row["AngularVelocityY"]),
  1492. Convert.ToSingle(row["AngularVelocityZ"])
  1493. );
  1494. prim.Acceleration = new Vector3(
  1495. Convert.ToSingle(row["AccelerationX"]),
  1496. Convert.ToSingle(row["AccelerationY"]),
  1497. Convert.ToSingle(row["AccelerationZ"])
  1498. );
  1499. // quaternions
  1500. prim.RotationOffset = new Quaternion(
  1501. Convert.ToSingle(row["RotationX"]),
  1502. Convert.ToSingle(row["RotationY"]),
  1503. Convert.ToSingle(row["RotationZ"]),
  1504. Convert.ToSingle(row["RotationW"])
  1505. );
  1506. prim.SitTargetPositionLL = new Vector3(
  1507. Convert.ToSingle(row["SitTargetOffsetX"]),
  1508. Convert.ToSingle(row["SitTargetOffsetY"]),
  1509. Convert.ToSingle(row["SitTargetOffsetZ"]));
  1510. prim.SitTargetOrientationLL = new Quaternion(
  1511. Convert.ToSingle(
  1512. row["SitTargetOrientX"]),
  1513. Convert.ToSingle(
  1514. row["SitTargetOrientY"]),
  1515. Convert.ToSingle(
  1516. row["SitTargetOrientZ"]),
  1517. Convert.ToSingle(
  1518. row["SitTargetOrientW"]));
  1519. prim.ClickAction = Convert.ToByte(row["ClickAction"]);
  1520. prim.PayPrice[0] = Convert.ToInt32(row["PayPrice"]);
  1521. prim.PayPrice[1] = Convert.ToInt32(row["PayButton1"]);
  1522. prim.PayPrice[2] = Convert.ToInt32(row["PayButton2"]);
  1523. prim.PayPrice[3] = Convert.ToInt32(row["PayButton3"]);
  1524. prim.PayPrice[4] = Convert.ToInt32(row["PayButton4"]);
  1525. prim.Sound = new UUID(row["LoopedSound"].ToString());
  1526. prim.SoundGain = Convert.ToSingle(row["LoopedSoundGain"]);
  1527. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  1528. if (!row.IsNull("TextureAnimation"))
  1529. prim.TextureAnimation = Convert.FromBase64String(row["TextureAnimation"].ToString());
  1530. if (!row.IsNull("ParticleSystem"))
  1531. prim.ParticleSystem = Convert.FromBase64String(row["ParticleSystem"].ToString());
  1532. prim.AngularVelocity = new Vector3(
  1533. Convert.ToSingle(row["OmegaX"]),
  1534. Convert.ToSingle(row["OmegaY"]),
  1535. Convert.ToSingle(row["OmegaZ"])
  1536. );
  1537. prim.SetCameraEyeOffset(new Vector3(
  1538. Convert.ToSingle(row["CameraEyeOffsetX"]),
  1539. Convert.ToSingle(row["CameraEyeOffsetY"]),
  1540. Convert.ToSingle(row["CameraEyeOffsetZ"])
  1541. ));
  1542. prim.SetCameraAtOffset(new Vector3(
  1543. Convert.ToSingle(row["CameraAtOffsetX"]),
  1544. Convert.ToSingle(row["CameraAtOffsetY"]),
  1545. Convert.ToSingle(row["CameraAtOffsetZ"])
  1546. ));
  1547. if (Convert.ToInt16(row["ForceMouselook"]) != 0)
  1548. prim.SetForceMouselook(true);
  1549. prim.ScriptAccessPin = Convert.ToInt32(row["ScriptAccessPin"]);
  1550. if (Convert.ToInt16(row["AllowedDrop"]) != 0)
  1551. prim.AllowedDrop = true;
  1552. if (Convert.ToInt16(row["DieAtEdge"]) != 0)
  1553. prim.DIE_AT_EDGE = true;
  1554. prim.SalePrice = Convert.ToInt32(row["SalePrice"]);
  1555. prim.ObjectSaleType = Convert.ToByte(row["SaleType"]);
  1556. prim.Material = Convert.ToByte(row["Material"]);
  1557. prim.CollisionSound = new UUID(row["CollisionSound"].ToString());
  1558. prim.CollisionSoundVolume = Convert.ToSingle(row["CollisionSoundVolume"]);
  1559. if (Convert.ToInt16(row["VolumeDetect"]) != 0)
  1560. prim.VolumeDetectActive = true;
  1561. if (!(row["MediaURL"] is System.DBNull))
  1562. {
  1563. // m_log.DebugFormat("[SQLITE]: MediaUrl type [{0}]", row["MediaURL"].GetType());
  1564. prim.MediaUrl = (string)row["MediaURL"];
  1565. }
  1566. prim.AttachedPos = new Vector3(
  1567. Convert.ToSingle(row["AttachedPosX"]),
  1568. Convert.ToSingle(row["AttachedPosY"]),
  1569. Convert.ToSingle(row["AttachedPosZ"])
  1570. );
  1571. if (!(row["DynAttrs"] is System.DBNull))
  1572. {
  1573. //m_log.DebugFormat("[SQLITE]: DynAttrs type [{0}]", row["DynAttrs"].GetType());
  1574. prim.DynAttrs = DAMap.FromXml((string)row["DynAttrs"]);
  1575. }
  1576. else
  1577. {
  1578. prim.DynAttrs = new DAMap();
  1579. }
  1580. prim.PhysicsShapeType = Convert.ToByte(row["PhysicsShapeType"]);
  1581. prim.Density = Convert.ToSingle(row["Density"]);
  1582. prim.GravityModifier = Convert.ToSingle(row["GravityModifier"]);
  1583. prim.Friction = Convert.ToSingle(row["Friction"]);
  1584. prim.Restitution = Convert.ToSingle(row["Restitution"]);
  1585. if (!(row["KeyframeMotion"] is DBNull))
  1586. {
  1587. Byte[] data = (byte[])row["KeyframeMotion"];
  1588. if (data.Length > 0)
  1589. prim.KeyframeMotion = KeyframeMotion.FromData(null, data);
  1590. else
  1591. prim.KeyframeMotion = null;
  1592. }
  1593. else
  1594. {
  1595. prim.KeyframeMotion = null;
  1596. }
  1597. prim.PassCollisions = Convert.ToBoolean(row["PassCollisions"]);
  1598. prim.PassTouches = Convert.ToBoolean(row["PassTouches"]);
  1599. prim.RotationAxisLocks = Convert.ToByte(row["RotationAxisLocks"]);
  1600. SOPVehicle vehicle = null;
  1601. if (!(row["Vehicle"] is DBNull) && row["Vehicle"].ToString() != String.Empty)
  1602. {
  1603. vehicle = SOPVehicle.FromXml2(row["Vehicle"].ToString());
  1604. if (vehicle != null)
  1605. prim.VehicleParams = vehicle;
  1606. }
  1607. PhysicsInertiaData pdata = null;
  1608. if (!(row["PhysInertia"] is DBNull) && row["PhysInertia"].ToString() != String.Empty)
  1609. pdata = PhysicsInertiaData.FromXml2(row["PhysInertia"].ToString());
  1610. prim.PhysicsInertia = pdata;
  1611. return prim;
  1612. }
  1613. /// <summary>
  1614. /// Build a prim inventory item from the persisted data.
  1615. /// </summary>
  1616. /// <param name="row"></param>
  1617. /// <returns></returns>
  1618. private static TaskInventoryItem buildItem(DataRow row)
  1619. {
  1620. TaskInventoryItem taskItem = new TaskInventoryItem();
  1621. taskItem.ItemID = new UUID((String)row["itemID"]);
  1622. taskItem.ParentPartID = new UUID((String)row["primID"]);
  1623. taskItem.AssetID = new UUID((String)row["assetID"]);
  1624. taskItem.ParentID = new UUID((String)row["parentFolderID"]);
  1625. taskItem.InvType = Convert.ToInt32(row["invType"]);
  1626. taskItem.Type = Convert.ToInt32(row["assetType"]);
  1627. taskItem.Name = (String)row["name"];
  1628. taskItem.Description = (String)row["description"];
  1629. taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
  1630. taskItem.CreatorIdentification = (String)row["creatorID"];
  1631. taskItem.OwnerID = new UUID((String)row["ownerID"]);
  1632. taskItem.LastOwnerID = new UUID((String)row["lastOwnerID"]);
  1633. taskItem.GroupID = new UUID((String)row["groupID"]);
  1634. taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
  1635. taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
  1636. taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
  1637. taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
  1638. taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
  1639. taskItem.Flags = Convert.ToUInt32(row["flags"]);
  1640. return taskItem;
  1641. }
  1642. /// <summary>
  1643. /// Build a Land Data from the persisted data.
  1644. /// </summary>
  1645. /// <param name="row"></param>
  1646. /// <returns></returns>
  1647. private LandData buildLandData(DataRow row)
  1648. {
  1649. LandData newData = new LandData();
  1650. newData.GlobalID = new UUID((String)row["UUID"]);
  1651. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  1652. // Bitmap is a byte[512]
  1653. newData.Bitmap = (Byte[])row["Bitmap"];
  1654. newData.Name = (String)row["Name"];
  1655. newData.Description = (String)row["Desc"];
  1656. newData.OwnerID = (UUID)(String)row["OwnerUUID"];
  1657. newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
  1658. newData.Area = Convert.ToInt32(row["Area"]);
  1659. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
  1660. newData.Category = (ParcelCategory)Convert.ToInt32(row["Category"]);
  1661. //Enum OpenMetaverse.Parcel.ParcelCategory
  1662. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  1663. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  1664. newData.GroupID = new UUID((String)row["GroupUUID"]);
  1665. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  1666. newData.Status = (ParcelStatus)Convert.ToInt32(row["LandStatus"]);
  1667. //Enum. OpenMetaverse.Parcel.ParcelStatus
  1668. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  1669. newData.LandingType = (Byte)row["LandingType"];
  1670. newData.MediaAutoScale = (Byte)row["MediaAutoScale"];
  1671. newData.MediaID = new UUID((String)row["MediaTextureUUID"]);
  1672. newData.MediaURL = (String)row["MediaURL"];
  1673. newData.MusicURL = (String)row["MusicURL"];
  1674. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  1675. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  1676. newData.SnapshotID = (UUID)(String)row["SnapshotUUID"];
  1677. newData.Dwell = Convert.ToInt32(row["Dwell"]);
  1678. newData.MediaType = (String)row["MediaType"];
  1679. newData.MediaDescription = (String)row["MediaDescription"];
  1680. newData.MediaWidth = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[0]);
  1681. newData.MediaHeight = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[1]);
  1682. newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]);
  1683. newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]);
  1684. newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]);
  1685. newData.SeeAVs = Convert.ToBoolean(row["SeeAVs"]);
  1686. newData.AnyAVSounds = Convert.ToBoolean(row["AnyAVSounds"]);
  1687. newData.GroupAVSounds = Convert.ToBoolean(row["GroupAVSounds"]);
  1688. try
  1689. {
  1690. newData.UserLocation =
  1691. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  1692. Convert.ToSingle(row["UserLocationZ"]));
  1693. newData.UserLookAt =
  1694. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  1695. Convert.ToSingle(row["UserLookAtZ"]));
  1696. }
  1697. catch (InvalidCastException)
  1698. {
  1699. m_log.ErrorFormat("[SQLITE REGION DB]: unable to get parcel telehub settings for {1}", newData.Name);
  1700. newData.UserLocation = Vector3.Zero;
  1701. newData.UserLookAt = Vector3.Zero;
  1702. }
  1703. newData.ParcelAccessList = new List<LandAccessEntry>();
  1704. UUID authBuyerID = UUID.Zero;
  1705. UUID.TryParse((string)row["AuthbuyerID"], out authBuyerID);
  1706. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  1707. return newData;
  1708. }
  1709. private RegionSettings buildRegionSettings(DataRow row)
  1710. {
  1711. RegionSettings newSettings = new RegionSettings();
  1712. newSettings.RegionUUID = new UUID((string)row["regionUUID"]);
  1713. newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
  1714. newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
  1715. newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
  1716. newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
  1717. newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
  1718. newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
  1719. newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
  1720. newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
  1721. newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
  1722. newSettings.Maturity = Convert.ToInt32(row["maturity"]);
  1723. newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
  1724. newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
  1725. newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
  1726. newSettings.TerrainTexture1 = new UUID((String)row["terrain_texture_1"]);
  1727. newSettings.TerrainTexture2 = new UUID((String)row["terrain_texture_2"]);
  1728. newSettings.TerrainTexture3 = new UUID((String)row["terrain_texture_3"]);
  1729. newSettings.TerrainTexture4 = new UUID((String)row["terrain_texture_4"]);
  1730. newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
  1731. newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
  1732. newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
  1733. newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
  1734. newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
  1735. newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
  1736. newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
  1737. newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
  1738. newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
  1739. newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
  1740. newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
  1741. newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
  1742. newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
  1743. newSettings.SunVector = new Vector3(
  1744. Convert.ToSingle(row["sunvectorx"]),
  1745. Convert.ToSingle(row["sunvectory"]),
  1746. Convert.ToSingle(row["sunvectorz"])
  1747. );
  1748. newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
  1749. newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
  1750. newSettings.Covenant = new UUID((String)row["covenant"]);
  1751. newSettings.CovenantChangedDateTime = Convert.ToInt32(row["covenant_datetime"]);
  1752. newSettings.TerrainImageID = new UUID((String)row["map_tile_ID"]);
  1753. newSettings.TelehubObject = new UUID((String)row["TelehubObject"]);
  1754. newSettings.ParcelImageID = new UUID((String)row["parcel_tile_ID"]);
  1755. newSettings.GodBlockSearch = Convert.ToBoolean(row["block_search"]);
  1756. newSettings.Casino = Convert.ToBoolean(row["casino"]);
  1757. return newSettings;
  1758. }
  1759. /// <summary>
  1760. /// Build a windlight entry from the persisted data.
  1761. /// </summary>
  1762. /// <param name="row"></param>
  1763. /// <returns>RegionLightShareData</returns>
  1764. private RegionLightShareData buildRegionWindlight(DataRow row)
  1765. {
  1766. RegionLightShareData windlight = new RegionLightShareData();
  1767. windlight.regionID = new UUID((string)row["region_id"]);
  1768. windlight.waterColor.X = Convert.ToSingle(row["water_color_r"]);
  1769. windlight.waterColor.Y = Convert.ToSingle(row["water_color_g"]);
  1770. windlight.waterColor.Z = Convert.ToSingle(row["water_color_b"]);
  1771. //windlight.waterColor.W = Convert.ToSingle(row["water_color_i"]); //not implemented
  1772. windlight.waterFogDensityExponent = Convert.ToSingle(row["water_fog_density_exponent"]);
  1773. windlight.underwaterFogModifier = Convert.ToSingle(row["underwater_fog_modifier"]);
  1774. windlight.reflectionWaveletScale.X = Convert.ToSingle(row["reflection_wavelet_scale_1"]);
  1775. windlight.reflectionWaveletScale.Y = Convert.ToSingle(row["reflection_wavelet_scale_2"]);
  1776. windlight.reflectionWaveletScale.Z = Convert.ToSingle(row["reflection_wavelet_scale_3"]);
  1777. windlight.fresnelScale = Convert.ToSingle(row["fresnel_scale"]);
  1778. windlight.fresnelOffset = Convert.ToSingle(row["fresnel_offset"]);
  1779. windlight.refractScaleAbove = Convert.ToSingle(row["refract_scale_above"]);
  1780. windlight.refractScaleBelow = Convert.ToSingle(row["refract_scale_below"]);
  1781. windlight.blurMultiplier = Convert.ToSingle(row["blur_multiplier"]);
  1782. windlight.bigWaveDirection.X = Convert.ToSingle(row["big_wave_direction_x"]);
  1783. windlight.bigWaveDirection.Y = Convert.ToSingle(row["big_wave_direction_y"]);
  1784. windlight.littleWaveDirection.X = Convert.ToSingle(row["little_wave_direction_x"]);
  1785. windlight.littleWaveDirection.Y = Convert.ToSingle(row["little_wave_direction_y"]);
  1786. windlight.normalMapTexture = new UUID((string)row["normal_map_texture"]);
  1787. windlight.horizon.X = Convert.ToSingle(row["horizon_r"]);
  1788. windlight.horizon.Y = Convert.ToSingle(row["horizon_g"]);
  1789. windlight.horizon.Z = Convert.ToSingle(row["horizon_b"]);
  1790. windlight.horizon.W = Convert.ToSingle(row["horizon_i"]);
  1791. windlight.hazeHorizon = Convert.ToSingle(row["haze_horizon"]);
  1792. windlight.blueDensity.X = Convert.ToSingle(row["blue_density_r"]);
  1793. windlight.blueDensity.Y = Convert.ToSingle(row["blue_density_g"]);
  1794. windlight.blueDensity.Z = Convert.ToSingle(row["blue_density_b"]);
  1795. windlight.blueDensity.W = Convert.ToSingle(row["blue_density_i"]);
  1796. windlight.hazeDensity = Convert.ToSingle(row["haze_density"]);
  1797. windlight.densityMultiplier = Convert.ToSingle(row["density_multiplier"]);
  1798. windlight.distanceMultiplier = Convert.ToSingle(row["distance_multiplier"]);
  1799. windlight.maxAltitude = Convert.ToUInt16(row["max_altitude"]);
  1800. windlight.sunMoonColor.X = Convert.ToSingle(row["sun_moon_color_r"]);
  1801. windlight.sunMoonColor.Y = Convert.ToSingle(row["sun_moon_color_g"]);
  1802. windlight.sunMoonColor.Z = Convert.ToSingle(row["sun_moon_color_b"]);
  1803. windlight.sunMoonColor.W = Convert.ToSingle(row["sun_moon_color_i"]);
  1804. windlight.sunMoonPosition = Convert.ToSingle(row["sun_moon_position"]);
  1805. windlight.ambient.X = Convert.ToSingle(row["ambient_r"]);
  1806. windlight.ambient.Y = Convert.ToSingle(row["ambient_g"]);
  1807. windlight.ambient.Z = Convert.ToSingle(row["ambient_b"]);
  1808. windlight.ambient.W = Convert.ToSingle(row["ambient_i"]);
  1809. windlight.eastAngle = Convert.ToSingle(row["east_angle"]);
  1810. windlight.sunGlowFocus = Convert.ToSingle(row["sun_glow_focus"]);
  1811. windlight.sunGlowSize = Convert.ToSingle(row["sun_glow_size"]);
  1812. windlight.sceneGamma = Convert.ToSingle(row["scene_gamma"]);
  1813. windlight.starBrightness = Convert.ToSingle(row["star_brightness"]);
  1814. windlight.cloudColor.X = Convert.ToSingle(row["cloud_color_r"]);
  1815. windlight.cloudColor.Y = Convert.ToSingle(row["cloud_color_g"]);
  1816. windlight.cloudColor.Z = Convert.ToSingle(row["cloud_color_b"]);
  1817. windlight.cloudColor.W = Convert.ToSingle(row["cloud_color_i"]);
  1818. windlight.cloudXYDensity.X = Convert.ToSingle(row["cloud_x"]);
  1819. windlight.cloudXYDensity.Y = Convert.ToSingle(row["cloud_y"]);
  1820. windlight.cloudXYDensity.Z = Convert.ToSingle(row["cloud_density"]);
  1821. windlight.cloudCoverage = Convert.ToSingle(row["cloud_coverage"]);
  1822. windlight.cloudScale = Convert.ToSingle(row["cloud_scale"]);
  1823. windlight.cloudDetailXYDensity.X = Convert.ToSingle(row["cloud_detail_x"]);
  1824. windlight.cloudDetailXYDensity.Y = Convert.ToSingle(row["cloud_detail_y"]);
  1825. windlight.cloudDetailXYDensity.Z = Convert.ToSingle(row["cloud_detail_density"]);
  1826. windlight.cloudScrollX = Convert.ToSingle(row["cloud_scroll_x"]);
  1827. windlight.cloudScrollXLock = Convert.ToBoolean(row["cloud_scroll_x_lock"]);
  1828. windlight.cloudScrollY = Convert.ToSingle(row["cloud_scroll_y"]);
  1829. windlight.cloudScrollYLock = Convert.ToBoolean(row["cloud_scroll_y_lock"]);
  1830. windlight.drawClassicClouds = Convert.ToBoolean(row["draw_classic_clouds"]);
  1831. return windlight;
  1832. }
  1833. /// <summary>
  1834. /// Build a land access entry from the persisted data.
  1835. /// </summary>
  1836. /// <param name="row"></param>
  1837. /// <returns></returns>
  1838. private static LandAccessEntry buildLandAccessData(DataRow row)
  1839. {
  1840. LandAccessEntry entry = new LandAccessEntry();
  1841. entry.AgentID = new UUID((string)row["AccessUUID"]);
  1842. entry.Flags = (AccessList)row["Flags"];
  1843. entry.Expires = 0;
  1844. return entry;
  1845. }
  1846. /// <summary>
  1847. ///
  1848. /// </summary>
  1849. /// <param name="row"></param>
  1850. /// <param name="prim"></param>
  1851. /// <param name="sceneGroupID"></param>
  1852. /// <param name="regionUUID"></param>
  1853. private static void fillPrimRow(DataRow row, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1854. {
  1855. row["UUID"] = prim.UUID.ToString();
  1856. row["RegionUUID"] = regionUUID.ToString();
  1857. row["CreationDate"] = prim.CreationDate;
  1858. row["Name"] = prim.Name;
  1859. row["SceneGroupID"] = sceneGroupID.ToString();
  1860. // the UUID of the root part for this SceneObjectGroup
  1861. // various text fields
  1862. row["Text"] = prim.Text;
  1863. row["Description"] = prim.Description;
  1864. row["SitName"] = prim.SitName;
  1865. row["TouchName"] = prim.TouchName;
  1866. // permissions
  1867. row["ObjectFlags"] = (uint)prim.Flags;
  1868. row["CreatorID"] = prim.CreatorIdentification.ToString();
  1869. row["OwnerID"] = prim.OwnerID.ToString();
  1870. row["GroupID"] = prim.GroupID.ToString();
  1871. row["LastOwnerID"] = prim.LastOwnerID.ToString();
  1872. row["RezzerID"] = prim.RezzerID.ToString();
  1873. row["OwnerMask"] = prim.OwnerMask;
  1874. row["NextOwnerMask"] = prim.NextOwnerMask;
  1875. row["GroupMask"] = prim.GroupMask;
  1876. row["EveryoneMask"] = prim.EveryoneMask;
  1877. row["BaseMask"] = prim.BaseMask;
  1878. // vectors
  1879. row["PositionX"] = prim.OffsetPosition.X;
  1880. row["PositionY"] = prim.OffsetPosition.Y;
  1881. row["PositionZ"] = prim.OffsetPosition.Z;
  1882. row["GroupPositionX"] = prim.GroupPosition.X;
  1883. row["GroupPositionY"] = prim.GroupPosition.Y;
  1884. row["GroupPositionZ"] = prim.GroupPosition.Z;
  1885. row["VelocityX"] = prim.Velocity.X;
  1886. row["VelocityY"] = prim.Velocity.Y;
  1887. row["VelocityZ"] = prim.Velocity.Z;
  1888. row["AngularVelocityX"] = prim.AngularVelocity.X;
  1889. row["AngularVelocityY"] = prim.AngularVelocity.Y;
  1890. row["AngularVelocityZ"] = prim.AngularVelocity.Z;
  1891. row["AccelerationX"] = prim.Acceleration.X;
  1892. row["AccelerationY"] = prim.Acceleration.Y;
  1893. row["AccelerationZ"] = prim.Acceleration.Z;
  1894. // quaternions
  1895. row["RotationX"] = prim.RotationOffset.X;
  1896. row["RotationY"] = prim.RotationOffset.Y;
  1897. row["RotationZ"] = prim.RotationOffset.Z;
  1898. row["RotationW"] = prim.RotationOffset.W;
  1899. // Sit target
  1900. Vector3 sitTargetPos = prim.SitTargetPositionLL;
  1901. row["SitTargetOffsetX"] = sitTargetPos.X;
  1902. row["SitTargetOffsetY"] = sitTargetPos.Y;
  1903. row["SitTargetOffsetZ"] = sitTargetPos.Z;
  1904. Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
  1905. row["SitTargetOrientW"] = sitTargetOrient.W;
  1906. row["SitTargetOrientX"] = sitTargetOrient.X;
  1907. row["SitTargetOrientY"] = sitTargetOrient.Y;
  1908. row["SitTargetOrientZ"] = sitTargetOrient.Z;
  1909. row["ColorR"] = Convert.ToInt32(prim.Color.R);
  1910. row["ColorG"] = Convert.ToInt32(prim.Color.G);
  1911. row["ColorB"] = Convert.ToInt32(prim.Color.B);
  1912. row["ColorA"] = Convert.ToInt32(prim.Color.A);
  1913. row["PayPrice"] = prim.PayPrice[0];
  1914. row["PayButton1"] = prim.PayPrice[1];
  1915. row["PayButton2"] = prim.PayPrice[2];
  1916. row["PayButton3"] = prim.PayPrice[3];
  1917. row["PayButton4"] = prim.PayPrice[4];
  1918. row["TextureAnimation"] = Convert.ToBase64String(prim.TextureAnimation);
  1919. row["ParticleSystem"] = Convert.ToBase64String(prim.ParticleSystem);
  1920. row["OmegaX"] = prim.AngularVelocity.X;
  1921. row["OmegaY"] = prim.AngularVelocity.Y;
  1922. row["OmegaZ"] = prim.AngularVelocity.Z;
  1923. row["CameraEyeOffsetX"] = prim.GetCameraEyeOffset().X;
  1924. row["CameraEyeOffsetY"] = prim.GetCameraEyeOffset().Y;
  1925. row["CameraEyeOffsetZ"] = prim.GetCameraEyeOffset().Z;
  1926. row["CameraAtOffsetX"] = prim.GetCameraAtOffset().X;
  1927. row["CameraAtOffsetY"] = prim.GetCameraAtOffset().Y;
  1928. row["CameraAtOffsetZ"] = prim.GetCameraAtOffset().Z;
  1929. if ((prim.SoundFlags & 1) != 0) // Looped
  1930. {
  1931. row["LoopedSound"] = prim.Sound.ToString();
  1932. row["LoopedSoundGain"] = prim.SoundGain;
  1933. }
  1934. else
  1935. {
  1936. row["LoopedSound"] = UUID.Zero.ToString();
  1937. row["LoopedSoundGain"] = 0.0f;
  1938. }
  1939. if (prim.GetForceMouselook())
  1940. row["ForceMouselook"] = 1;
  1941. else
  1942. row["ForceMouselook"] = 0;
  1943. row["ScriptAccessPin"] = prim.ScriptAccessPin;
  1944. if (prim.AllowedDrop)
  1945. row["AllowedDrop"] = 1;
  1946. else
  1947. row["AllowedDrop"] = 0;
  1948. if (prim.DIE_AT_EDGE)
  1949. row["DieAtEdge"] = 1;
  1950. else
  1951. row["DieAtEdge"] = 0;
  1952. row["SalePrice"] = prim.SalePrice;
  1953. row["SaleType"] = Convert.ToInt16(prim.ObjectSaleType);
  1954. // click action
  1955. row["ClickAction"] = prim.ClickAction;
  1956. row["Material"] = prim.Material;
  1957. row["CollisionSound"] = prim.CollisionSound.ToString();
  1958. row["CollisionSoundVolume"] = prim.CollisionSoundVolume;
  1959. if (prim.VolumeDetectActive)
  1960. row["VolumeDetect"] = 1;
  1961. else
  1962. row["VolumeDetect"] = 0;
  1963. row["MediaURL"] = prim.MediaUrl;
  1964. row["AttachedPosX"] = prim.AttachedPos.X;
  1965. row["AttachedPosY"] = prim.AttachedPos.Y;
  1966. row["AttachedPosZ"] = prim.AttachedPos.Z;
  1967. if (prim.DynAttrs.CountNamespaces > 0)
  1968. row["DynAttrs"] = prim.DynAttrs.ToXml();
  1969. else
  1970. row["DynAttrs"] = null;
  1971. row["PhysicsShapeType"] = prim.PhysicsShapeType;
  1972. row["Density"] = (double)prim.Density;
  1973. row["GravityModifier"] = (double)prim.GravityModifier;
  1974. row["Friction"] = (double)prim.Friction;
  1975. row["Restitution"] = (double)prim.Restitution;
  1976. if (prim.KeyframeMotion != null)
  1977. row["KeyframeMotion"] = prim.KeyframeMotion.Serialize();
  1978. else
  1979. row["KeyframeMotion"] = new Byte[0];
  1980. row["PassTouches"] = prim.PassTouches;
  1981. row["PassCollisions"] = prim.PassCollisions;
  1982. row["RotationAxisLocks"] = prim.RotationAxisLocks;
  1983. if (prim.VehicleParams != null)
  1984. row["Vehicle"] = prim.VehicleParams.ToXml2();
  1985. else
  1986. row["Vehicle"] = String.Empty;
  1987. if (prim.PhysicsInertia != null)
  1988. row["PhysInertia"] = prim.PhysicsInertia.ToXml2();
  1989. else
  1990. row["PhysInertia"] = String.Empty;
  1991. }
  1992. /// <summary>
  1993. ///
  1994. /// </summary>
  1995. /// <param name="row"></param>
  1996. /// <param name="taskItem"></param>
  1997. private static void fillItemRow(DataRow row, TaskInventoryItem taskItem)
  1998. {
  1999. row["itemID"] = taskItem.ItemID.ToString();
  2000. row["primID"] = taskItem.ParentPartID.ToString();
  2001. row["assetID"] = taskItem.AssetID.ToString();
  2002. row["parentFolderID"] = taskItem.ParentID.ToString();
  2003. row["invType"] = taskItem.InvType;
  2004. row["assetType"] = taskItem.Type;
  2005. row["name"] = taskItem.Name;
  2006. row["description"] = taskItem.Description;
  2007. row["creationDate"] = taskItem.CreationDate;
  2008. row["creatorID"] = taskItem.CreatorIdentification.ToString();
  2009. row["ownerID"] = taskItem.OwnerID.ToString();
  2010. row["lastOwnerID"] = taskItem.LastOwnerID.ToString();
  2011. row["groupID"] = taskItem.GroupID.ToString();
  2012. row["nextPermissions"] = taskItem.NextPermissions;
  2013. row["currentPermissions"] = taskItem.CurrentPermissions;
  2014. row["basePermissions"] = taskItem.BasePermissions;
  2015. row["everyonePermissions"] = taskItem.EveryonePermissions;
  2016. row["groupPermissions"] = taskItem.GroupPermissions;
  2017. row["flags"] = taskItem.Flags;
  2018. }
  2019. /// <summary>
  2020. ///
  2021. /// </summary>
  2022. /// <param name="row"></param>
  2023. /// <param name="land"></param>
  2024. /// <param name="regionUUID"></param>
  2025. private static void fillLandRow(DataRow row, LandData land, UUID regionUUID)
  2026. {
  2027. row["UUID"] = land.GlobalID.ToString();
  2028. row["RegionUUID"] = regionUUID.ToString();
  2029. row["LocalLandID"] = land.LocalID;
  2030. // Bitmap is a byte[512]
  2031. row["Bitmap"] = land.Bitmap;
  2032. row["Name"] = land.Name;
  2033. row["Desc"] = land.Description;
  2034. row["OwnerUUID"] = land.OwnerID.ToString();
  2035. row["IsGroupOwned"] = land.IsGroupOwned.ToString();
  2036. row["Area"] = land.Area;
  2037. row["AuctionID"] = land.AuctionID; //Unemplemented
  2038. row["Category"] = land.Category; //Enum OpenMetaverse.Parcel.ParcelCategory
  2039. row["ClaimDate"] = land.ClaimDate;
  2040. row["ClaimPrice"] = land.ClaimPrice;
  2041. row["GroupUUID"] = land.GroupID.ToString();
  2042. row["SalePrice"] = land.SalePrice;
  2043. row["LandStatus"] = land.Status; //Enum. OpenMetaverse.Parcel.ParcelStatus
  2044. row["LandFlags"] = land.Flags;
  2045. row["LandingType"] = land.LandingType;
  2046. row["MediaAutoScale"] = land.MediaAutoScale;
  2047. row["MediaTextureUUID"] = land.MediaID.ToString();
  2048. row["MediaURL"] = land.MediaURL;
  2049. row["MusicURL"] = land.MusicURL;
  2050. row["PassHours"] = land.PassHours;
  2051. row["PassPrice"] = land.PassPrice;
  2052. row["SnapshotUUID"] = land.SnapshotID.ToString();
  2053. row["UserLocationX"] = land.UserLocation.X;
  2054. row["UserLocationY"] = land.UserLocation.Y;
  2055. row["UserLocationZ"] = land.UserLocation.Z;
  2056. row["UserLookAtX"] = land.UserLookAt.X;
  2057. row["UserLookAtY"] = land.UserLookAt.Y;
  2058. row["UserLookAtZ"] = land.UserLookAt.Z;
  2059. row["AuthbuyerID"] = land.AuthBuyerID.ToString();
  2060. row["OtherCleanTime"] = land.OtherCleanTime;
  2061. row["Dwell"] = land.Dwell;
  2062. row["MediaType"] = land.MediaType;
  2063. row["MediaDescription"] = land.MediaDescription;
  2064. row["MediaSize"] = String.Format("{0},{1}", land.MediaWidth, land.MediaHeight);
  2065. row["MediaLoop"] = land.MediaLoop;
  2066. row["ObscureMusic"] = land.ObscureMusic;
  2067. row["ObscureMedia"] = land.ObscureMedia;
  2068. row["SeeAVs"] = land.SeeAVs;
  2069. row["AnyAVSounds"] = land.AnyAVSounds;
  2070. row["GroupAVSounds"] = land.GroupAVSounds;
  2071. }
  2072. /// <summary>
  2073. ///
  2074. /// </summary>
  2075. /// <param name="row"></param>
  2076. /// <param name="entry"></param>
  2077. /// <param name="parcelID"></param>
  2078. private static void fillLandAccessRow(DataRow row, LandAccessEntry entry, UUID parcelID)
  2079. {
  2080. row["LandUUID"] = parcelID.ToString();
  2081. row["AccessUUID"] = entry.AgentID.ToString();
  2082. row["Flags"] = entry.Flags;
  2083. }
  2084. private static void fillRegionSettingsRow(DataRow row, RegionSettings settings)
  2085. {
  2086. row["regionUUID"] = settings.RegionUUID.ToString();
  2087. row["block_terraform"] = settings.BlockTerraform;
  2088. row["block_fly"] = settings.BlockFly;
  2089. row["allow_damage"] = settings.AllowDamage;
  2090. row["restrict_pushing"] = settings.RestrictPushing;
  2091. row["allow_land_resell"] = settings.AllowLandResell;
  2092. row["allow_land_join_divide"] = settings.AllowLandJoinDivide;
  2093. row["block_show_in_search"] = settings.BlockShowInSearch;
  2094. row["agent_limit"] = settings.AgentLimit;
  2095. row["object_bonus"] = settings.ObjectBonus;
  2096. row["maturity"] = settings.Maturity;
  2097. row["disable_scripts"] = settings.DisableScripts;
  2098. row["disable_collisions"] = settings.DisableCollisions;
  2099. row["disable_physics"] = settings.DisablePhysics;
  2100. row["terrain_texture_1"] = settings.TerrainTexture1.ToString();
  2101. row["terrain_texture_2"] = settings.TerrainTexture2.ToString();
  2102. row["terrain_texture_3"] = settings.TerrainTexture3.ToString();
  2103. row["terrain_texture_4"] = settings.TerrainTexture4.ToString();
  2104. row["elevation_1_nw"] = settings.Elevation1NW;
  2105. row["elevation_2_nw"] = settings.Elevation2NW;
  2106. row["elevation_1_ne"] = settings.Elevation1NE;
  2107. row["elevation_2_ne"] = settings.Elevation2NE;
  2108. row["elevation_1_se"] = settings.Elevation1SE;
  2109. row["elevation_2_se"] = settings.Elevation2SE;
  2110. row["elevation_1_sw"] = settings.Elevation1SW;
  2111. row["elevation_2_sw"] = settings.Elevation2SW;
  2112. row["water_height"] = settings.WaterHeight;
  2113. row["terrain_raise_limit"] = settings.TerrainRaiseLimit;
  2114. row["terrain_lower_limit"] = settings.TerrainLowerLimit;
  2115. row["use_estate_sun"] = settings.UseEstateSun;
  2116. row["sandbox"] = settings.Sandbox; // unlike other database modules, sqlite uses a lower case s for sandbox!
  2117. row["sunvectorx"] = settings.SunVector.X;
  2118. row["sunvectory"] = settings.SunVector.Y;
  2119. row["sunvectorz"] = settings.SunVector.Z;
  2120. row["fixed_sun"] = settings.FixedSun;
  2121. row["sun_position"] = settings.SunPosition;
  2122. row["covenant"] = settings.Covenant.ToString();
  2123. row["covenant_datetime"] = settings.CovenantChangedDateTime;
  2124. row["map_tile_ID"] = settings.TerrainImageID.ToString();
  2125. row["TelehubObject"] = settings.TelehubObject.ToString();
  2126. row["parcel_tile_ID"] = settings.ParcelImageID.ToString();
  2127. row["block_search"] = settings.GodBlockSearch;
  2128. row["casino"] = settings.Casino;
  2129. }
  2130. /// <summary>
  2131. ///
  2132. /// </summary>
  2133. /// <param name="row"></param>
  2134. /// <param name="windlight"></param>
  2135. private static void fillRegionWindlightRow(DataRow row, RegionLightShareData windlight)
  2136. {
  2137. row["region_id"] = windlight.regionID.ToString();
  2138. row["water_color_r"] = windlight.waterColor.X;
  2139. row["water_color_g"] = windlight.waterColor.Y;
  2140. row["water_color_b"] = windlight.waterColor.Z;
  2141. row["water_color_i"] = 1; //windlight.waterColor.W; //not implemented
  2142. row["water_fog_density_exponent"] = windlight.waterFogDensityExponent;
  2143. row["underwater_fog_modifier"] = windlight.underwaterFogModifier;
  2144. row["reflection_wavelet_scale_1"] = windlight.reflectionWaveletScale.X;
  2145. row["reflection_wavelet_scale_2"] = windlight.reflectionWaveletScale.Y;
  2146. row["reflection_wavelet_scale_3"] = windlight.reflectionWaveletScale.Z;
  2147. row["fresnel_scale"] = windlight.fresnelScale;
  2148. row["fresnel_offset"] = windlight.fresnelOffset;
  2149. row["refract_scale_above"] = windlight.refractScaleAbove;
  2150. row["refract_scale_below"] = windlight.refractScaleBelow;
  2151. row["blur_multiplier"] = windlight.blurMultiplier;
  2152. row["big_wave_direction_x"] = windlight.bigWaveDirection.X;
  2153. row["big_wave_direction_y"] = windlight.bigWaveDirection.Y;
  2154. row["little_wave_direction_x"] = windlight.littleWaveDirection.X;
  2155. row["little_wave_direction_y"] = windlight.littleWaveDirection.Y;
  2156. row["normal_map_texture"] = windlight.normalMapTexture.ToString();
  2157. row["horizon_r"] = windlight.horizon.X;
  2158. row["horizon_g"] = windlight.horizon.Y;
  2159. row["horizon_b"] = windlight.horizon.Z;
  2160. row["horizon_i"] = windlight.horizon.W;
  2161. row["haze_horizon"] = windlight.hazeHorizon;
  2162. row["blue_density_r"] = windlight.blueDensity.X;
  2163. row["blue_density_g"] = windlight.blueDensity.Y;
  2164. row["blue_density_b"] = windlight.blueDensity.Z;
  2165. row["blue_density_i"] = windlight.blueDensity.W;
  2166. row["haze_density"] = windlight.hazeDensity;
  2167. row["density_multiplier"] = windlight.densityMultiplier;
  2168. row["distance_multiplier"] = windlight.distanceMultiplier;
  2169. row["max_altitude"] = windlight.maxAltitude;
  2170. row["sun_moon_color_r"] = windlight.sunMoonColor.X;
  2171. row["sun_moon_color_g"] = windlight.sunMoonColor.Y;
  2172. row["sun_moon_color_b"] = windlight.sunMoonColor.Z;
  2173. row["sun_moon_color_i"] = windlight.sunMoonColor.W;
  2174. row["sun_moon_position"] = windlight.sunMoonPosition;
  2175. row["ambient_r"] = windlight.ambient.X;
  2176. row["ambient_g"] = windlight.ambient.Y;
  2177. row["ambient_b"] = windlight.ambient.Z;
  2178. row["ambient_i"] = windlight.ambient.W;
  2179. row["east_angle"] = windlight.eastAngle;
  2180. row["sun_glow_focus"] = windlight.sunGlowFocus;
  2181. row["sun_glow_size"] = windlight.sunGlowSize;
  2182. row["scene_gamma"] = windlight.sceneGamma;
  2183. row["star_brightness"] = windlight.starBrightness;
  2184. row["cloud_color_r"] = windlight.cloudColor.X;
  2185. row["cloud_color_g"] = windlight.cloudColor.Y;
  2186. row["cloud_color_b"] = windlight.cloudColor.Z;
  2187. row["cloud_color_i"] = windlight.cloudColor.W;
  2188. row["cloud_x"] = windlight.cloudXYDensity.X;
  2189. row["cloud_y"] = windlight.cloudXYDensity.Y;
  2190. row["cloud_density"] = windlight.cloudXYDensity.Z;
  2191. row["cloud_coverage"] = windlight.cloudCoverage;
  2192. row["cloud_scale"] = windlight.cloudScale;
  2193. row["cloud_detail_x"] = windlight.cloudDetailXYDensity.X;
  2194. row["cloud_detail_y"] = windlight.cloudDetailXYDensity.Y;
  2195. row["cloud_detail_density"] = windlight.cloudDetailXYDensity.Z;
  2196. row["cloud_scroll_x"] = windlight.cloudScrollX;
  2197. row["cloud_scroll_x_lock"] = windlight.cloudScrollXLock;
  2198. row["cloud_scroll_y"] = windlight.cloudScrollY;
  2199. row["cloud_scroll_y_lock"] = windlight.cloudScrollYLock;
  2200. row["draw_classic_clouds"] = windlight.drawClassicClouds;
  2201. }
  2202. /// <summary>
  2203. ///
  2204. /// </summary>
  2205. /// <param name="row"></param>
  2206. /// <returns></returns>
  2207. private PrimitiveBaseShape buildShape(DataRow row)
  2208. {
  2209. PrimitiveBaseShape s = new PrimitiveBaseShape();
  2210. s.Scale = new Vector3(
  2211. Convert.ToSingle(row["ScaleX"]),
  2212. Convert.ToSingle(row["ScaleY"]),
  2213. Convert.ToSingle(row["ScaleZ"])
  2214. );
  2215. // paths
  2216. s.PCode = Convert.ToByte(row["PCode"]);
  2217. s.PathBegin = Convert.ToUInt16(row["PathBegin"]);
  2218. s.PathEnd = Convert.ToUInt16(row["PathEnd"]);
  2219. s.PathScaleX = Convert.ToByte(row["PathScaleX"]);
  2220. s.PathScaleY = Convert.ToByte(row["PathScaleY"]);
  2221. s.PathShearX = Convert.ToByte(row["PathShearX"]);
  2222. s.PathShearY = Convert.ToByte(row["PathShearY"]);
  2223. s.PathSkew = Convert.ToSByte(row["PathSkew"]);
  2224. s.PathCurve = Convert.ToByte(row["PathCurve"]);
  2225. s.PathRadiusOffset = Convert.ToSByte(row["PathRadiusOffset"]);
  2226. s.PathRevolutions = Convert.ToByte(row["PathRevolutions"]);
  2227. s.PathTaperX = Convert.ToSByte(row["PathTaperX"]);
  2228. s.PathTaperY = Convert.ToSByte(row["PathTaperY"]);
  2229. s.PathTwist = Convert.ToSByte(row["PathTwist"]);
  2230. s.PathTwistBegin = Convert.ToSByte(row["PathTwistBegin"]);
  2231. // profile
  2232. s.ProfileBegin = Convert.ToUInt16(row["ProfileBegin"]);
  2233. s.ProfileEnd = Convert.ToUInt16(row["ProfileEnd"]);
  2234. s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]);
  2235. s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]);
  2236. s.State = Convert.ToByte(row["State"]);
  2237. s.LastAttachPoint = Convert.ToByte(row["LastAttachPoint"]);
  2238. byte[] textureEntry = (byte[])row["Texture"];
  2239. s.TextureEntry = textureEntry;
  2240. s.ExtraParams = (byte[])row["ExtraParams"];
  2241. if (!(row["Media"] is System.DBNull))
  2242. s.Media = PrimitiveBaseShape.MediaList.FromXml((string)row["Media"]);
  2243. return s;
  2244. }
  2245. /// <summary>
  2246. ///
  2247. /// </summary>
  2248. /// <param name="row"></param>
  2249. /// <param name="prim"></param>
  2250. private static void fillShapeRow(DataRow row, SceneObjectPart prim)
  2251. {
  2252. PrimitiveBaseShape s = prim.Shape;
  2253. row["UUID"] = prim.UUID.ToString();
  2254. // shape is an enum
  2255. row["Shape"] = 0;
  2256. // vectors
  2257. row["ScaleX"] = s.Scale.X;
  2258. row["ScaleY"] = s.Scale.Y;
  2259. row["ScaleZ"] = s.Scale.Z;
  2260. // paths
  2261. row["PCode"] = s.PCode;
  2262. row["PathBegin"] = s.PathBegin;
  2263. row["PathEnd"] = s.PathEnd;
  2264. row["PathScaleX"] = s.PathScaleX;
  2265. row["PathScaleY"] = s.PathScaleY;
  2266. row["PathShearX"] = s.PathShearX;
  2267. row["PathShearY"] = s.PathShearY;
  2268. row["PathSkew"] = s.PathSkew;
  2269. row["PathCurve"] = s.PathCurve;
  2270. row["PathRadiusOffset"] = s.PathRadiusOffset;
  2271. row["PathRevolutions"] = s.PathRevolutions;
  2272. row["PathTaperX"] = s.PathTaperX;
  2273. row["PathTaperY"] = s.PathTaperY;
  2274. row["PathTwist"] = s.PathTwist;
  2275. row["PathTwistBegin"] = s.PathTwistBegin;
  2276. // profile
  2277. row["ProfileBegin"] = s.ProfileBegin;
  2278. row["ProfileEnd"] = s.ProfileEnd;
  2279. row["ProfileCurve"] = s.ProfileCurve;
  2280. row["ProfileHollow"] = s.ProfileHollow;
  2281. row["State"] = s.State;
  2282. row["LastAttachPoint"] = s.LastAttachPoint;
  2283. row["Texture"] = s.TextureEntry;
  2284. row["ExtraParams"] = s.ExtraParams;
  2285. if (s.Media != null)
  2286. row["Media"] = s.Media.ToXml();
  2287. }
  2288. /// <summary>
  2289. /// Persistently store a prim.
  2290. /// </summary>
  2291. /// <param name="prim"></param>
  2292. /// <param name="sceneGroupID"></param>
  2293. /// <param name="regionUUID"></param>
  2294. private void addPrim(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  2295. {
  2296. DataTable prims = ds.Tables["prims"];
  2297. DataTable shapes = ds.Tables["primshapes"];
  2298. DataRow primRow = prims.Rows.Find(prim.UUID.ToString());
  2299. if (primRow == null)
  2300. {
  2301. primRow = prims.NewRow();
  2302. fillPrimRow(primRow, prim, sceneGroupID, regionUUID);
  2303. prims.Rows.Add(primRow);
  2304. }
  2305. else
  2306. {
  2307. fillPrimRow(primRow, prim, sceneGroupID, regionUUID);
  2308. }
  2309. DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
  2310. if (shapeRow == null)
  2311. {
  2312. shapeRow = shapes.NewRow();
  2313. fillShapeRow(shapeRow, prim);
  2314. shapes.Rows.Add(shapeRow);
  2315. }
  2316. else
  2317. {
  2318. fillShapeRow(shapeRow, prim);
  2319. }
  2320. }
  2321. /// <summary>
  2322. /// </summary>
  2323. /// <param name="primID"></param>
  2324. /// <param name="items"></param>
  2325. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  2326. {
  2327. // m_log.DebugFormat("[SQLITE REGION DB]: Entered StorePrimInventory with prim ID {0}", primID);
  2328. DataTable dbItems = ds.Tables["primitems"];
  2329. // For now, we're just going to crudely remove all the previous inventory items
  2330. // no matter whether they have changed or not, and replace them with the current set.
  2331. lock (ds)
  2332. {
  2333. RemoveItems(primID);
  2334. // repalce with current inventory details
  2335. foreach (TaskInventoryItem newItem in items)
  2336. {
  2337. // m_log.InfoFormat(
  2338. // "[DATASTORE]: ",
  2339. // "Adding item {0}, {1} to prim ID {2}",
  2340. // newItem.Name, newItem.ItemID, newItem.ParentPartID);
  2341. DataRow newItemRow = dbItems.NewRow();
  2342. fillItemRow(newItemRow, newItem);
  2343. dbItems.Rows.Add(newItemRow);
  2344. }
  2345. }
  2346. Commit();
  2347. }
  2348. /***********************************************************************
  2349. *
  2350. * SQL Statement Creation Functions
  2351. *
  2352. * These functions create SQL statements for update, insert, and create.
  2353. * They can probably be factored later to have a db independant
  2354. * portion and a db specific portion
  2355. *
  2356. **********************************************************************/
  2357. /// <summary>
  2358. /// Create an insert command
  2359. /// </summary>
  2360. /// <param name="table">table name</param>
  2361. /// <param name="dt">data table</param>
  2362. /// <returns>the created command</returns>
  2363. /// <remarks>
  2364. /// This is subtle enough to deserve some commentary.
  2365. /// Instead of doing *lots* and *lots of hardcoded strings
  2366. /// for database definitions we'll use the fact that
  2367. /// realistically all insert statements look like "insert
  2368. /// into A(b, c) values(:b, :c) on the parameterized query
  2369. /// front. If we just have a list of b, c, etc... we can
  2370. /// generate these strings instead of typing them out.
  2371. /// </remarks>
  2372. private static SqliteCommand createInsertCommand(string table, DataTable dt)
  2373. {
  2374. string[] cols = new string[dt.Columns.Count];
  2375. for (int i = 0; i < dt.Columns.Count; i++)
  2376. {
  2377. DataColumn col = dt.Columns[i];
  2378. cols[i] = col.ColumnName;
  2379. }
  2380. string sql = "insert into " + table + "(";
  2381. sql += String.Join(", ", cols);
  2382. // important, the first ':' needs to be here, the rest get added in the join
  2383. sql += ") values (:";
  2384. sql += String.Join(", :", cols);
  2385. sql += ")";
  2386. // m_log.DebugFormat("[SQLITE]: Created insert command {0}", sql);
  2387. SqliteCommand cmd = new SqliteCommand(sql);
  2388. // this provides the binding for all our parameters, so
  2389. // much less code than it used to be
  2390. foreach (DataColumn col in dt.Columns)
  2391. {
  2392. cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
  2393. }
  2394. return cmd;
  2395. }
  2396. /// <summary>
  2397. /// create an update command
  2398. /// </summary>
  2399. /// <param name="table">table name</param>
  2400. /// <param name="pk"></param>
  2401. /// <param name="dt"></param>
  2402. /// <returns>the created command</returns>
  2403. private static SqliteCommand createUpdateCommand(string table, string pk, DataTable dt)
  2404. {
  2405. string sql = "update " + table + " set ";
  2406. string subsql = String.Empty;
  2407. foreach (DataColumn col in dt.Columns)
  2408. {
  2409. if (subsql.Length > 0)
  2410. {
  2411. // a map function would rock so much here
  2412. subsql += ", ";
  2413. }
  2414. subsql += col.ColumnName + "= :" + col.ColumnName;
  2415. }
  2416. sql += subsql;
  2417. sql += " where " + pk;
  2418. SqliteCommand cmd = new SqliteCommand(sql);
  2419. // this provides the binding for all our parameters, so
  2420. // much less code than it used to be
  2421. foreach (DataColumn col in dt.Columns)
  2422. {
  2423. cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
  2424. }
  2425. return cmd;
  2426. }
  2427. /// <summary>
  2428. /// create an update command
  2429. /// </summary>
  2430. /// <param name="table">table name</param>
  2431. /// <param name="pk"></param>
  2432. /// <param name="dt"></param>
  2433. /// <returns>the created command</returns>
  2434. private static SqliteCommand createUpdateCommand(string table, string pk1, string pk2, DataTable dt)
  2435. {
  2436. string sql = "update " + table + " set ";
  2437. string subsql = String.Empty;
  2438. foreach (DataColumn col in dt.Columns)
  2439. {
  2440. if (subsql.Length > 0)
  2441. {
  2442. // a map function would rock so much here
  2443. subsql += ", ";
  2444. }
  2445. subsql += col.ColumnName + "= :" + col.ColumnName;
  2446. }
  2447. sql += subsql;
  2448. sql += " where " + pk1 + " and " + pk2;
  2449. SqliteCommand cmd = new SqliteCommand(sql);
  2450. // this provides the binding for all our parameters, so
  2451. // much less code than it used to be
  2452. foreach (DataColumn col in dt.Columns)
  2453. {
  2454. cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
  2455. }
  2456. return cmd;
  2457. }
  2458. /// <summary>
  2459. ///
  2460. /// </summary>
  2461. /// <param name="dt">Data Table</param>
  2462. /// <returns></returns>
  2463. // private static string defineTable(DataTable dt)
  2464. // {
  2465. // string sql = "create table " + dt.TableName + "(";
  2466. // string subsql = String.Empty;
  2467. // foreach (DataColumn col in dt.Columns)
  2468. // {
  2469. // if (subsql.Length > 0)
  2470. // {
  2471. // // a map function would rock so much here
  2472. // subsql += ",\n";
  2473. // }
  2474. // subsql += col.ColumnName + " " + sqliteType(col.DataType);
  2475. // if (dt.PrimaryKey.Length > 0 && col == dt.PrimaryKey[0])
  2476. // {
  2477. // subsql += " primary key";
  2478. // }
  2479. // }
  2480. // sql += subsql;
  2481. // sql += ")";
  2482. // return sql;
  2483. // }
  2484. /***********************************************************************
  2485. *
  2486. * Database Binding functions
  2487. *
  2488. * These will be db specific due to typing, and minor differences
  2489. * in databases.
  2490. *
  2491. **********************************************************************/
  2492. ///<summary>
  2493. /// This is a convenience function that collapses 5 repetitive
  2494. /// lines for defining SqliteParameters to 2 parameters:
  2495. /// column name and database type.
  2496. ///
  2497. /// It assumes certain conventions like :param as the param
  2498. /// name to replace in parametrized queries, and that source
  2499. /// version is always current version, both of which are fine
  2500. /// for us.
  2501. ///</summary>
  2502. ///<returns>a built sqlite parameter</returns>
  2503. private static SqliteParameter createSqliteParameter(string name, Type type)
  2504. {
  2505. SqliteParameter param = new SqliteParameter();
  2506. param.ParameterName = ":" + name;
  2507. param.DbType = dbtypeFromType(type);
  2508. param.SourceColumn = name;
  2509. param.SourceVersion = DataRowVersion.Current;
  2510. return param;
  2511. }
  2512. /// <summary>
  2513. ///
  2514. /// </summary>
  2515. /// <param name="da"></param>
  2516. /// <param name="conn"></param>
  2517. private void setupPrimCommands(SqliteDataAdapter da, SqliteConnection conn)
  2518. {
  2519. da.InsertCommand = createInsertCommand("prims", ds.Tables["prims"]);
  2520. da.InsertCommand.Connection = conn;
  2521. da.UpdateCommand = createUpdateCommand("prims", "UUID=:UUID", ds.Tables["prims"]);
  2522. da.UpdateCommand.Connection = conn;
  2523. SqliteCommand delete = new SqliteCommand("delete from prims where UUID = :UUID");
  2524. delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
  2525. delete.Connection = conn;
  2526. da.DeleteCommand = delete;
  2527. }
  2528. /// <summary>
  2529. ///
  2530. /// </summary>
  2531. /// <param name="da"></param>
  2532. /// <param name="conn"></param>
  2533. private void setupItemsCommands(SqliteDataAdapter da, SqliteConnection conn)
  2534. {
  2535. da.InsertCommand = createInsertCommand("primitems", ds.Tables["primitems"]);
  2536. da.InsertCommand.Connection = conn;
  2537. da.UpdateCommand = createUpdateCommand("primitems", "itemID = :itemID", ds.Tables["primitems"]);
  2538. da.UpdateCommand.Connection = conn;
  2539. SqliteCommand delete = new SqliteCommand("delete from primitems where itemID = :itemID");
  2540. delete.Parameters.Add(createSqliteParameter("itemID", typeof(String)));
  2541. delete.Connection = conn;
  2542. da.DeleteCommand = delete;
  2543. }
  2544. /// <summary>
  2545. ///
  2546. /// </summary>
  2547. /// <param name="da"></param>
  2548. /// <param name="conn"></param>
  2549. private void setupTerrainCommands(SqliteDataAdapter da, SqliteConnection conn)
  2550. {
  2551. da.InsertCommand = createInsertCommand("terrain", ds.Tables["terrain"]);
  2552. da.InsertCommand.Connection = conn;
  2553. }
  2554. /// <summary>
  2555. ///
  2556. /// </summary>
  2557. /// <param name="da"></param>
  2558. /// <param name="conn"></param>
  2559. private void setupLandCommands(SqliteDataAdapter da, SqliteConnection conn)
  2560. {
  2561. da.InsertCommand = createInsertCommand("land", ds.Tables["land"]);
  2562. da.InsertCommand.Connection = conn;
  2563. da.UpdateCommand = createUpdateCommand("land", "UUID=:UUID", ds.Tables["land"]);
  2564. da.UpdateCommand.Connection = conn;
  2565. SqliteCommand delete = new SqliteCommand("delete from land where UUID=:UUID");
  2566. delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
  2567. da.DeleteCommand = delete;
  2568. da.DeleteCommand.Connection = conn;
  2569. }
  2570. /// <summary>
  2571. ///
  2572. /// </summary>
  2573. /// <param name="da"></param>
  2574. /// <param name="conn"></param>
  2575. private void setupLandAccessCommands(SqliteDataAdapter da, SqliteConnection conn)
  2576. {
  2577. da.InsertCommand = createInsertCommand("landaccesslist", ds.Tables["landaccesslist"]);
  2578. da.InsertCommand.Connection = conn;
  2579. da.UpdateCommand = createUpdateCommand("landaccesslist", "LandUUID=:landUUID", "AccessUUID=:AccessUUID", ds.Tables["landaccesslist"]);
  2580. da.UpdateCommand.Connection = conn;
  2581. SqliteCommand delete = new SqliteCommand("delete from landaccesslist where LandUUID= :LandUUID and AccessUUID= :AccessUUID");
  2582. delete.Parameters.Add(createSqliteParameter("LandUUID", typeof(String)));
  2583. delete.Parameters.Add(createSqliteParameter("AccessUUID", typeof(String)));
  2584. da.DeleteCommand = delete;
  2585. da.DeleteCommand.Connection = conn;
  2586. }
  2587. private void setupRegionSettingsCommands(SqliteDataAdapter da, SqliteConnection conn)
  2588. {
  2589. da.InsertCommand = createInsertCommand("regionsettings", ds.Tables["regionsettings"]);
  2590. da.InsertCommand.Connection = conn;
  2591. da.UpdateCommand = createUpdateCommand("regionsettings", "regionUUID=:regionUUID", ds.Tables["regionsettings"]);
  2592. da.UpdateCommand.Connection = conn;
  2593. }
  2594. /// <summary>
  2595. ///
  2596. /// </summary>
  2597. /// <param name="da"></param>
  2598. /// <param name="conn"></param>
  2599. private void setupRegionWindlightCommands(SqliteDataAdapter da, SqliteConnection conn)
  2600. {
  2601. da.InsertCommand = createInsertCommand("regionwindlight", ds.Tables["regionwindlight"]);
  2602. da.InsertCommand.Connection = conn;
  2603. da.UpdateCommand = createUpdateCommand("regionwindlight", "region_id=:region_id", ds.Tables["regionwindlight"]);
  2604. da.UpdateCommand.Connection = conn;
  2605. }
  2606. private void setupRegionEnvironmentCommands(SqliteDataAdapter da, SqliteConnection conn)
  2607. {
  2608. da.InsertCommand = createInsertCommand("regionenvironment", ds.Tables["regionenvironment"]);
  2609. da.InsertCommand.Connection = conn;
  2610. da.UpdateCommand = createUpdateCommand("regionenvironment", "region_id=:region_id", ds.Tables["regionenvironment"]);
  2611. da.UpdateCommand.Connection = conn;
  2612. }
  2613. private void setupRegionSpawnPointsCommands(SqliteDataAdapter da, SqliteConnection conn)
  2614. {
  2615. da.InsertCommand = createInsertCommand("spawn_points", ds.Tables["spawn_points"]);
  2616. da.InsertCommand.Connection = conn;
  2617. da.UpdateCommand = createUpdateCommand("spawn_points", "RegionID=:RegionID", ds.Tables["spawn_points"]);
  2618. da.UpdateCommand.Connection = conn;
  2619. }
  2620. /// <summary>
  2621. ///
  2622. /// </summary>
  2623. /// <param name="da"></param>
  2624. /// <param name="conn"></param>
  2625. private void setupShapeCommands(SqliteDataAdapter da, SqliteConnection conn)
  2626. {
  2627. da.InsertCommand = createInsertCommand("primshapes", ds.Tables["primshapes"]);
  2628. da.InsertCommand.Connection = conn;
  2629. da.UpdateCommand = createUpdateCommand("primshapes", "UUID=:UUID", ds.Tables["primshapes"]);
  2630. da.UpdateCommand.Connection = conn;
  2631. SqliteCommand delete = new SqliteCommand("delete from primshapes where UUID = :UUID");
  2632. delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
  2633. delete.Connection = conn;
  2634. da.DeleteCommand = delete;
  2635. }
  2636. /***********************************************************************
  2637. *
  2638. * Type conversion functions
  2639. *
  2640. **********************************************************************/
  2641. /// <summary>
  2642. /// Type conversion function
  2643. /// </summary>
  2644. /// <param name="type"></param>
  2645. /// <returns></returns>
  2646. private static DbType dbtypeFromType(Type type)
  2647. {
  2648. if (type == typeof(String))
  2649. {
  2650. return DbType.String;
  2651. }
  2652. else if (type == typeof(Int32))
  2653. {
  2654. return DbType.Int32;
  2655. }
  2656. else if (type == typeof(Double))
  2657. {
  2658. return DbType.Double;
  2659. }
  2660. else if (type == typeof(Byte))
  2661. {
  2662. return DbType.Byte;
  2663. }
  2664. else if (type == typeof(Double))
  2665. {
  2666. return DbType.Double;
  2667. }
  2668. else if (type == typeof(Byte[]))
  2669. {
  2670. return DbType.Binary;
  2671. }
  2672. else if (type == typeof(Boolean))
  2673. {
  2674. return DbType.Boolean;
  2675. }
  2676. else
  2677. {
  2678. return DbType.String;
  2679. }
  2680. }
  2681. static void PrintDataSet(DataSet ds)
  2682. {
  2683. // Print out any name and extended properties.
  2684. Console.WriteLine("DataSet is named: {0}", ds.DataSetName);
  2685. foreach (System.Collections.DictionaryEntry de in ds.ExtendedProperties)
  2686. {
  2687. Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
  2688. }
  2689. Console.WriteLine();
  2690. foreach (DataTable dt in ds.Tables)
  2691. {
  2692. Console.WriteLine("=> {0} Table:", dt.TableName);
  2693. // Print out the column names.
  2694. for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
  2695. {
  2696. Console.Write(dt.Columns[curCol].ColumnName + "\t");
  2697. }
  2698. Console.WriteLine("\n----------------------------------");
  2699. // Print the DataTable.
  2700. for (int curRow = 0; curRow < dt.Rows.Count; curRow++)
  2701. {
  2702. for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
  2703. {
  2704. Console.Write(dt.Rows[curRow][curCol].ToString() + "\t");
  2705. }
  2706. Console.WriteLine();
  2707. }
  2708. }
  2709. }
  2710. public UUID[] GetObjectIDs(UUID regionID)
  2711. {
  2712. return new UUID[0];
  2713. }
  2714. public void SaveExtra(UUID regionID, string name, string value)
  2715. {
  2716. }
  2717. public void RemoveExtra(UUID regionID, string name)
  2718. {
  2719. }
  2720. public Dictionary<string, string> GetExtra(UUID regionID)
  2721. {
  2722. return null;
  2723. }
  2724. }
  2725. }