1
0

SQLiteSimulationData.cs 134 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084
  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 TerrainData(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 (SqliteCommand cmd = new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID", m_conn))
  720. {
  721. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  722. cmd.ExecuteNonQuery();
  723. }
  724. // the following is an work around for .NET. The perf
  725. // issues associated with it aren't as bad as you think.
  726. String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" +
  727. " values(:RegionUUID, :Revision, :Heightfield)";
  728. int terrainDBRevision;
  729. Array terrainDBblob;
  730. terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
  731. m_log.DebugFormat("{0} Storing terrain format {1}", LogHeader, terrainDBRevision);
  732. using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
  733. {
  734. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  735. cmd.Parameters.Add(new SqliteParameter(":Revision", terrainDBRevision));
  736. cmd.Parameters.Add(new SqliteParameter(":Heightfield", terrainDBblob));
  737. cmd.ExecuteNonQuery();
  738. }
  739. }
  740. }
  741. /// <summary>
  742. /// Store baked terrain in region storage
  743. /// </summary>
  744. /// <param name="ter">terrain heightfield</param>
  745. /// <param name="regionID">region UUID</param>
  746. public void StoreBakedTerrain(TerrainData terrData, UUID regionID)
  747. {
  748. lock (ds)
  749. {
  750. using (
  751. SqliteCommand cmd = new SqliteCommand("delete from bakedterrain where RegionUUID=:RegionUUID", m_conn))
  752. {
  753. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  754. cmd.ExecuteNonQuery();
  755. }
  756. // the following is an work around for .NET. The perf
  757. // issues associated with it aren't as bad as you think.
  758. String sql = "insert into bakedterrain(RegionUUID, Revision, Heightfield)" +
  759. " values(:RegionUUID, :Revision, :Heightfield)";
  760. int terrainDBRevision;
  761. Array terrainDBblob;
  762. terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
  763. m_log.DebugFormat("{0} Storing bakedterrain format {1}", LogHeader, terrainDBRevision);
  764. using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
  765. {
  766. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  767. cmd.Parameters.Add(new SqliteParameter(":Revision", terrainDBRevision));
  768. cmd.Parameters.Add(new SqliteParameter(":Heightfield", terrainDBblob));
  769. cmd.ExecuteNonQuery();
  770. }
  771. }
  772. }
  773. /// <summary>
  774. /// Load the latest terrain revision from region storage
  775. /// </summary>
  776. /// <param name="regionID">the region UUID</param>
  777. /// <returns>Heightfield data</returns>
  778. public double[,] LoadTerrain(UUID regionID)
  779. {
  780. double[,] ret = null;
  781. TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
  782. if (terrData != null)
  783. ret = terrData.GetDoubles();
  784. return ret;
  785. }
  786. // Returns 'null' if region not found
  787. public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
  788. {
  789. TerrainData terrData = null;
  790. lock (ds)
  791. {
  792. String sql = "select RegionUUID, Revision, Heightfield from terrain" +
  793. " where RegionUUID=:RegionUUID order by Revision desc";
  794. using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
  795. {
  796. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  797. using (IDataReader row = cmd.ExecuteReader())
  798. {
  799. int rev = 0;
  800. if (row.Read())
  801. {
  802. rev = Convert.ToInt32(row["Revision"]);
  803. byte[] blob = (byte[])row["Heightfield"];
  804. terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
  805. }
  806. else
  807. {
  808. m_log.Warn("[SQLITE REGION DB]: No terrain found for region");
  809. return null;
  810. }
  811. m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString());
  812. }
  813. }
  814. }
  815. return terrData;
  816. }
  817. public TerrainData LoadBakedTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
  818. {
  819. TerrainData terrData = null;
  820. lock (ds)
  821. {
  822. String sql = "select RegionUUID, Revision, Heightfield from bakedterrain" +
  823. " where RegionUUID=:RegionUUID";
  824. using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
  825. {
  826. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  827. using (IDataReader row = cmd.ExecuteReader())
  828. {
  829. int rev = 0;
  830. if (row.Read())
  831. {
  832. rev = Convert.ToInt32(row["Revision"]);
  833. byte[] blob = (byte[])row["Heightfield"];
  834. terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
  835. }
  836. }
  837. }
  838. }
  839. return terrData;
  840. }
  841. public void RemoveLandObject(UUID globalID)
  842. {
  843. lock (ds)
  844. {
  845. // Can't use blanket SQL statements when using SqlAdapters unless you re-read the data into the adapter
  846. // after you're done.
  847. // replaced below code with the SqliteAdapter version.
  848. //using (SqliteCommand cmd = new SqliteCommand("delete from land where UUID=:UUID", m_conn))
  849. //{
  850. // cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString()));
  851. // cmd.ExecuteNonQuery();
  852. //}
  853. //using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:UUID", m_conn))
  854. //{
  855. // cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString()));
  856. // cmd.ExecuteNonQuery();
  857. //}
  858. DataTable land = ds.Tables["land"];
  859. DataTable landaccesslist = ds.Tables["landaccesslist"];
  860. DataRow landRow = land.Rows.Find(globalID.ToString());
  861. if (landRow != null)
  862. {
  863. landRow.Delete();
  864. }
  865. List<DataRow> rowsToDelete = new List<DataRow>();
  866. foreach (DataRow rowToCheck in landaccesslist.Rows)
  867. {
  868. if (rowToCheck["LandUUID"].ToString() == globalID.ToString())
  869. rowsToDelete.Add(rowToCheck);
  870. }
  871. for (int iter = 0; iter < rowsToDelete.Count; iter++)
  872. {
  873. rowsToDelete[iter].Delete();
  874. }
  875. }
  876. Commit();
  877. }
  878. /// <summary>
  879. ///
  880. /// </summary>
  881. /// <param name="parcel"></param>
  882. public void StoreLandObject(ILandObject parcel)
  883. {
  884. lock (ds)
  885. {
  886. DataTable land = ds.Tables["land"];
  887. DataTable landaccesslist = ds.Tables["landaccesslist"];
  888. DataRow landRow = land.Rows.Find(parcel.LandData.GlobalID.ToString());
  889. if (landRow == null)
  890. {
  891. landRow = land.NewRow();
  892. fillLandRow(landRow, parcel.LandData, parcel.RegionUUID);
  893. land.Rows.Add(landRow);
  894. }
  895. else
  896. {
  897. fillLandRow(landRow, parcel.LandData, parcel.RegionUUID);
  898. }
  899. // I know this caused someone issues before, but OpenSim is unusable if we leave this stuff around
  900. //using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:LandUUID", m_conn))
  901. //{
  902. // cmd.Parameters.Add(new SqliteParameter(":LandUUID", parcel.LandData.GlobalID.ToString()));
  903. // cmd.ExecuteNonQuery();
  904. // }
  905. // This is the slower.. but more appropriate thing to do
  906. // We can't modify the table with direct queries before calling Commit() and re-filling them.
  907. List<DataRow> rowsToDelete = new List<DataRow>();
  908. foreach (DataRow rowToCheck in landaccesslist.Rows)
  909. {
  910. if (rowToCheck["LandUUID"].ToString() == parcel.LandData.GlobalID.ToString())
  911. rowsToDelete.Add(rowToCheck);
  912. }
  913. for (int iter = 0; iter < rowsToDelete.Count; iter++)
  914. {
  915. rowsToDelete[iter].Delete();
  916. landaccesslist.Rows.Remove(rowsToDelete[iter]);
  917. }
  918. rowsToDelete.Clear();
  919. foreach (LandAccessEntry entry in parcel.LandData.ParcelAccessList)
  920. {
  921. DataRow newAccessRow = landaccesslist.NewRow();
  922. fillLandAccessRow(newAccessRow, entry, parcel.LandData.GlobalID);
  923. landaccesslist.Rows.Add(newAccessRow);
  924. }
  925. }
  926. Commit();
  927. }
  928. /// <summary>
  929. ///
  930. /// </summary>
  931. /// <param name="regionUUID"></param>
  932. /// <returns></returns>
  933. public List<LandData> LoadLandObjects(UUID regionUUID)
  934. {
  935. List<LandData> landDataForRegion = new List<LandData>();
  936. lock (ds)
  937. {
  938. DataTable land = ds.Tables["land"];
  939. DataTable landaccesslist = ds.Tables["landaccesslist"];
  940. string searchExp = "RegionUUID = '" + regionUUID + "'";
  941. DataRow[] rawDataForRegion = land.Select(searchExp);
  942. foreach (DataRow rawDataLand in rawDataForRegion)
  943. {
  944. LandData newLand = buildLandData(rawDataLand);
  945. string accessListSearchExp = "LandUUID = '" + newLand.GlobalID + "'";
  946. DataRow[] rawDataForLandAccessList = landaccesslist.Select(accessListSearchExp);
  947. foreach (DataRow rawDataLandAccess in rawDataForLandAccessList)
  948. {
  949. newLand.ParcelAccessList.Add(buildLandAccessData(rawDataLandAccess));
  950. }
  951. landDataForRegion.Add(newLand);
  952. }
  953. }
  954. return landDataForRegion;
  955. }
  956. /// <summary>
  957. ///
  958. /// </summary>
  959. public void Commit()
  960. {
  961. // m_log.Debug("[SQLITE]: Starting commit");
  962. lock (ds)
  963. {
  964. primDa.Update(ds, "prims");
  965. shapeDa.Update(ds, "primshapes");
  966. itemsDa.Update(ds, "primitems");
  967. terrainDa.Update(ds, "terrain");
  968. landDa.Update(ds, "land");
  969. landAccessListDa.Update(ds, "landaccesslist");
  970. try
  971. {
  972. regionSettingsDa.Update(ds, "regionsettings");
  973. regionWindlightDa.Update(ds, "regionwindlight");
  974. }
  975. catch (SqliteException SqlEx)
  976. {
  977. throw new Exception(
  978. "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!",
  979. SqlEx);
  980. }
  981. ds.AcceptChanges();
  982. }
  983. }
  984. /// <summary>
  985. /// See <see cref="Commit"/>
  986. /// </summary>
  987. public void Shutdown()
  988. {
  989. Commit();
  990. }
  991. /***********************************************************************
  992. *
  993. * Database Definition Functions
  994. *
  995. * This should be db agnostic as we define them in ADO.NET terms
  996. *
  997. **********************************************************************/
  998. protected void CreateDataSetMapping(IDataAdapter da, string tableName)
  999. {
  1000. ITableMapping dbMapping = da.TableMappings.Add(tableName, tableName);
  1001. foreach (DataColumn col in ds.Tables[tableName].Columns)
  1002. {
  1003. dbMapping.ColumnMappings.Add(col.ColumnName, col.ColumnName);
  1004. }
  1005. }
  1006. /// <summary>
  1007. ///
  1008. /// </summary>
  1009. /// <param name="dt"></param>
  1010. /// <param name="name"></param>
  1011. /// <param name="type"></param>
  1012. private static void createCol(DataTable dt, string name, Type type)
  1013. {
  1014. DataColumn col = new DataColumn(name, type);
  1015. dt.Columns.Add(col);
  1016. }
  1017. /// <summary>
  1018. /// Creates the "terrain" table
  1019. /// </summary>
  1020. /// <returns>terrain table DataTable</returns>
  1021. private static DataTable createTerrainTable()
  1022. {
  1023. DataTable terrain = new DataTable("terrain");
  1024. createCol(terrain, "RegionUUID", typeof(String));
  1025. createCol(terrain, "Revision", typeof(Int32));
  1026. createCol(terrain, "Heightfield", typeof(Byte[]));
  1027. return terrain;
  1028. }
  1029. /// <summary>
  1030. /// Creates the "prims" table
  1031. /// </summary>
  1032. /// <returns>prim table DataTable</returns>
  1033. private static DataTable createPrimTable()
  1034. {
  1035. DataTable prims = new DataTable("prims");
  1036. createCol(prims, "UUID", typeof(String));
  1037. createCol(prims, "RegionUUID", typeof(String));
  1038. createCol(prims, "CreationDate", typeof(Int32));
  1039. createCol(prims, "Name", typeof(String));
  1040. createCol(prims, "SceneGroupID", typeof(String));
  1041. // various text fields
  1042. createCol(prims, "Text", typeof(String));
  1043. createCol(prims, "ColorR", typeof(Int32));
  1044. createCol(prims, "ColorG", typeof(Int32));
  1045. createCol(prims, "ColorB", typeof(Int32));
  1046. createCol(prims, "ColorA", typeof(Int32));
  1047. createCol(prims, "Description", typeof(String));
  1048. createCol(prims, "SitName", typeof(String));
  1049. createCol(prims, "TouchName", typeof(String));
  1050. // permissions
  1051. createCol(prims, "ObjectFlags", typeof(Int32));
  1052. createCol(prims, "CreatorID", typeof(String));
  1053. createCol(prims, "OwnerID", typeof(String));
  1054. createCol(prims, "GroupID", typeof(String));
  1055. createCol(prims, "LastOwnerID", typeof(String));
  1056. createCol(prims, "RezzerID", typeof(String));
  1057. createCol(prims, "OwnerMask", typeof(Int32));
  1058. createCol(prims, "NextOwnerMask", typeof(Int32));
  1059. createCol(prims, "GroupMask", typeof(Int32));
  1060. createCol(prims, "EveryoneMask", typeof(Int32));
  1061. createCol(prims, "BaseMask", typeof(Int32));
  1062. // vectors
  1063. createCol(prims, "PositionX", typeof(Double));
  1064. createCol(prims, "PositionY", typeof(Double));
  1065. createCol(prims, "PositionZ", typeof(Double));
  1066. createCol(prims, "GroupPositionX", typeof(Double));
  1067. createCol(prims, "GroupPositionY", typeof(Double));
  1068. createCol(prims, "GroupPositionZ", typeof(Double));
  1069. createCol(prims, "VelocityX", typeof(Double));
  1070. createCol(prims, "VelocityY", typeof(Double));
  1071. createCol(prims, "VelocityZ", typeof(Double));
  1072. createCol(prims, "AngularVelocityX", typeof(Double));
  1073. createCol(prims, "AngularVelocityY", typeof(Double));
  1074. createCol(prims, "AngularVelocityZ", typeof(Double));
  1075. createCol(prims, "AccelerationX", typeof(Double));
  1076. createCol(prims, "AccelerationY", typeof(Double));
  1077. createCol(prims, "AccelerationZ", typeof(Double));
  1078. // quaternions
  1079. createCol(prims, "RotationX", typeof(Double));
  1080. createCol(prims, "RotationY", typeof(Double));
  1081. createCol(prims, "RotationZ", typeof(Double));
  1082. createCol(prims, "RotationW", typeof(Double));
  1083. // sit target
  1084. createCol(prims, "SitTargetOffsetX", typeof(Double));
  1085. createCol(prims, "SitTargetOffsetY", typeof(Double));
  1086. createCol(prims, "SitTargetOffsetZ", typeof(Double));
  1087. createCol(prims, "SitTargetOrientW", typeof(Double));
  1088. createCol(prims, "SitTargetOrientX", typeof(Double));
  1089. createCol(prims, "SitTargetOrientY", typeof(Double));
  1090. createCol(prims, "SitTargetOrientZ", typeof(Double));
  1091. createCol(prims, "PayPrice", typeof(Int32));
  1092. createCol(prims, "PayButton1", typeof(Int32));
  1093. createCol(prims, "PayButton2", typeof(Int32));
  1094. createCol(prims, "PayButton3", typeof(Int32));
  1095. createCol(prims, "PayButton4", typeof(Int32));
  1096. createCol(prims, "LoopedSound", typeof(String));
  1097. createCol(prims, "LoopedSoundGain", typeof(Double));
  1098. createCol(prims, "TextureAnimation", typeof(String));
  1099. createCol(prims, "ParticleSystem", typeof(String));
  1100. createCol(prims, "OmegaX", typeof(Double));
  1101. createCol(prims, "OmegaY", typeof(Double));
  1102. createCol(prims, "OmegaZ", typeof(Double));
  1103. createCol(prims, "CameraEyeOffsetX", typeof(Double));
  1104. createCol(prims, "CameraEyeOffsetY", typeof(Double));
  1105. createCol(prims, "CameraEyeOffsetZ", typeof(Double));
  1106. createCol(prims, "CameraAtOffsetX", typeof(Double));
  1107. createCol(prims, "CameraAtOffsetY", typeof(Double));
  1108. createCol(prims, "CameraAtOffsetZ", typeof(Double));
  1109. createCol(prims, "ForceMouselook", typeof(Int16));
  1110. createCol(prims, "ScriptAccessPin", typeof(Int32));
  1111. createCol(prims, "AllowedDrop", typeof(Int16));
  1112. createCol(prims, "DieAtEdge", typeof(Int16));
  1113. createCol(prims, "SalePrice", typeof(Int32));
  1114. createCol(prims, "SaleType", typeof(Int16));
  1115. // click action
  1116. createCol(prims, "ClickAction", typeof(Byte));
  1117. createCol(prims, "Material", typeof(Byte));
  1118. createCol(prims, "CollisionSound", typeof(String));
  1119. createCol(prims, "CollisionSoundVolume", typeof(Double));
  1120. createCol(prims, "VolumeDetect", typeof(Int16));
  1121. createCol(prims, "MediaURL", typeof(String));
  1122. createCol(prims, "AttachedPosX", typeof(Double));
  1123. createCol(prims, "AttachedPosY", typeof(Double));
  1124. createCol(prims, "AttachedPosZ", typeof(Double));
  1125. createCol(prims, "DynAttrs", typeof(String));
  1126. createCol(prims, "PhysicsShapeType", typeof(Byte));
  1127. createCol(prims, "Density", typeof(Double));
  1128. createCol(prims, "GravityModifier", typeof(Double));
  1129. createCol(prims, "Friction", typeof(Double));
  1130. createCol(prims, "Restitution", typeof(Double));
  1131. createCol(prims, "KeyframeMotion", typeof(Byte[]));
  1132. // Add in contraints
  1133. prims.PrimaryKey = new DataColumn[] { prims.Columns["UUID"] };
  1134. return prims;
  1135. }
  1136. /// <summary>
  1137. /// Creates "primshapes" table
  1138. /// </summary>
  1139. /// <returns>shape table DataTable</returns>
  1140. private static DataTable createShapeTable()
  1141. {
  1142. DataTable shapes = new DataTable("primshapes");
  1143. createCol(shapes, "UUID", typeof(String));
  1144. // shape is an enum
  1145. createCol(shapes, "Shape", typeof(Int32));
  1146. // vectors
  1147. createCol(shapes, "ScaleX", typeof(Double));
  1148. createCol(shapes, "ScaleY", typeof(Double));
  1149. createCol(shapes, "ScaleZ", typeof(Double));
  1150. // paths
  1151. createCol(shapes, "PCode", typeof(Int32));
  1152. createCol(shapes, "PathBegin", typeof(Int32));
  1153. createCol(shapes, "PathEnd", typeof(Int32));
  1154. createCol(shapes, "PathScaleX", typeof(Int32));
  1155. createCol(shapes, "PathScaleY", typeof(Int32));
  1156. createCol(shapes, "PathShearX", typeof(Int32));
  1157. createCol(shapes, "PathShearY", typeof(Int32));
  1158. createCol(shapes, "PathSkew", typeof(Int32));
  1159. createCol(shapes, "PathCurve", typeof(Int32));
  1160. createCol(shapes, "PathRadiusOffset", typeof(Int32));
  1161. createCol(shapes, "PathRevolutions", typeof(Int32));
  1162. createCol(shapes, "PathTaperX", typeof(Int32));
  1163. createCol(shapes, "PathTaperY", typeof(Int32));
  1164. createCol(shapes, "PathTwist", typeof(Int32));
  1165. createCol(shapes, "PathTwistBegin", typeof(Int32));
  1166. // profile
  1167. createCol(shapes, "ProfileBegin", typeof(Int32));
  1168. createCol(shapes, "ProfileEnd", typeof(Int32));
  1169. createCol(shapes, "ProfileCurve", typeof(Int32));
  1170. createCol(shapes, "ProfileHollow", typeof(Int32));
  1171. createCol(shapes, "State", typeof(Int32));
  1172. // text TODO: this isn't right, but I'm not sure the right
  1173. // way to specify this as a blob atm
  1174. createCol(shapes, "Texture", typeof(Byte[]));
  1175. createCol(shapes, "ExtraParams", typeof(Byte[]));
  1176. createCol(shapes, "Media", typeof(String));
  1177. shapes.PrimaryKey = new DataColumn[] { shapes.Columns["UUID"] };
  1178. return shapes;
  1179. }
  1180. /// <summary>
  1181. /// creates "primitems" table
  1182. /// </summary>
  1183. /// <returns>item table DataTable</returns>
  1184. private static DataTable createItemsTable()
  1185. {
  1186. DataTable items = new DataTable("primitems");
  1187. createCol(items, "itemID", typeof(String));
  1188. createCol(items, "primID", typeof(String));
  1189. createCol(items, "assetID", typeof(String));
  1190. createCol(items, "parentFolderID", typeof(String));
  1191. createCol(items, "invType", typeof(Int32));
  1192. createCol(items, "assetType", typeof(Int32));
  1193. createCol(items, "name", typeof(String));
  1194. createCol(items, "description", typeof(String));
  1195. createCol(items, "creationDate", typeof(Int64));
  1196. createCol(items, "creatorID", typeof(String));
  1197. createCol(items, "ownerID", typeof(String));
  1198. createCol(items, "lastOwnerID", typeof(String));
  1199. createCol(items, "groupID", typeof(String));
  1200. createCol(items, "nextPermissions", typeof(UInt32));
  1201. createCol(items, "currentPermissions", typeof(UInt32));
  1202. createCol(items, "basePermissions", typeof(UInt32));
  1203. createCol(items, "everyonePermissions", typeof(UInt32));
  1204. createCol(items, "groupPermissions", typeof(UInt32));
  1205. createCol(items, "flags", typeof(UInt32));
  1206. items.PrimaryKey = new DataColumn[] { items.Columns["itemID"] };
  1207. return items;
  1208. }
  1209. /// <summary>
  1210. /// Creates "land" table
  1211. /// </summary>
  1212. /// <returns>land table DataTable</returns>
  1213. private static DataTable createLandTable()
  1214. {
  1215. DataTable land = new DataTable("land");
  1216. createCol(land, "UUID", typeof(String));
  1217. createCol(land, "RegionUUID", typeof(String));
  1218. createCol(land, "LocalLandID", typeof(UInt32));
  1219. // Bitmap is a byte[512]
  1220. createCol(land, "Bitmap", typeof(Byte[]));
  1221. createCol(land, "Name", typeof(String));
  1222. createCol(land, "Desc", typeof(String));
  1223. createCol(land, "OwnerUUID", typeof(String));
  1224. createCol(land, "IsGroupOwned", typeof(string));
  1225. createCol(land, "Area", typeof(Int32));
  1226. createCol(land, "AuctionID", typeof(Int32)); //Unemplemented
  1227. createCol(land, "Category", typeof(Int32)); //Enum OpenMetaverse.Parcel.ParcelCategory
  1228. createCol(land, "ClaimDate", typeof(Int32));
  1229. createCol(land, "ClaimPrice", typeof(Int32));
  1230. createCol(land, "GroupUUID", typeof(string));
  1231. createCol(land, "SalePrice", typeof(Int32));
  1232. createCol(land, "LandStatus", typeof(Int32)); //Enum. OpenMetaverse.Parcel.ParcelStatus
  1233. createCol(land, "LandFlags", typeof(UInt32));
  1234. createCol(land, "LandingType", typeof(Byte));
  1235. createCol(land, "MediaAutoScale", typeof(Byte));
  1236. createCol(land, "MediaTextureUUID", typeof(String));
  1237. createCol(land, "MediaURL", typeof(String));
  1238. createCol(land, "MusicURL", typeof(String));
  1239. createCol(land, "PassHours", typeof(Double));
  1240. createCol(land, "PassPrice", typeof(UInt32));
  1241. createCol(land, "SnapshotUUID", typeof(String));
  1242. createCol(land, "UserLocationX", typeof(Double));
  1243. createCol(land, "UserLocationY", typeof(Double));
  1244. createCol(land, "UserLocationZ", typeof(Double));
  1245. createCol(land, "UserLookAtX", typeof(Double));
  1246. createCol(land, "UserLookAtY", typeof(Double));
  1247. createCol(land, "UserLookAtZ", typeof(Double));
  1248. createCol(land, "AuthbuyerID", typeof(String));
  1249. createCol(land, "OtherCleanTime", typeof(Int32));
  1250. createCol(land, "Dwell", typeof(Int32));
  1251. createCol(land, "MediaType", typeof(String));
  1252. createCol(land, "MediaDescription", typeof(String));
  1253. createCol(land, "MediaSize", typeof(String));
  1254. createCol(land, "MediaLoop", typeof(Boolean));
  1255. createCol(land, "ObscureMedia", typeof(Boolean));
  1256. createCol(land, "ObscureMusic", typeof(Boolean));
  1257. createCol(land, "SeeAVs", typeof(Boolean));
  1258. createCol(land, "AnyAVSounds", typeof(Boolean));
  1259. createCol(land, "GroupAVSounds", typeof(Boolean));
  1260. land.PrimaryKey = new DataColumn[] { land.Columns["UUID"] };
  1261. return land;
  1262. }
  1263. /// <summary>
  1264. /// create "landaccesslist" table
  1265. /// </summary>
  1266. /// <returns>Landacceslist DataTable</returns>
  1267. private static DataTable createLandAccessListTable()
  1268. {
  1269. DataTable landaccess = new DataTable("landaccesslist");
  1270. createCol(landaccess, "LandUUID", typeof(String));
  1271. createCol(landaccess, "AccessUUID", typeof(String));
  1272. createCol(landaccess, "Flags", typeof(UInt32));
  1273. return landaccess;
  1274. }
  1275. private static DataTable createRegionSettingsTable()
  1276. {
  1277. DataTable regionsettings = new DataTable("regionsettings");
  1278. createCol(regionsettings, "regionUUID", typeof(String));
  1279. createCol(regionsettings, "block_terraform", typeof(Int32));
  1280. createCol(regionsettings, "block_fly", typeof(Int32));
  1281. createCol(regionsettings, "allow_damage", typeof(Int32));
  1282. createCol(regionsettings, "restrict_pushing", typeof(Int32));
  1283. createCol(regionsettings, "allow_land_resell", typeof(Int32));
  1284. createCol(regionsettings, "allow_land_join_divide", typeof(Int32));
  1285. createCol(regionsettings, "block_show_in_search", typeof(Int32));
  1286. createCol(regionsettings, "agent_limit", typeof(Int32));
  1287. createCol(regionsettings, "object_bonus", typeof(Double));
  1288. createCol(regionsettings, "maturity", typeof(Int32));
  1289. createCol(regionsettings, "disable_scripts", typeof(Int32));
  1290. createCol(regionsettings, "disable_collisions", typeof(Int32));
  1291. createCol(regionsettings, "disable_physics", typeof(Int32));
  1292. createCol(regionsettings, "terrain_texture_1", typeof(String));
  1293. createCol(regionsettings, "terrain_texture_2", typeof(String));
  1294. createCol(regionsettings, "terrain_texture_3", typeof(String));
  1295. createCol(regionsettings, "terrain_texture_4", typeof(String));
  1296. createCol(regionsettings, "elevation_1_nw", typeof(Double));
  1297. createCol(regionsettings, "elevation_2_nw", typeof(Double));
  1298. createCol(regionsettings, "elevation_1_ne", typeof(Double));
  1299. createCol(regionsettings, "elevation_2_ne", typeof(Double));
  1300. createCol(regionsettings, "elevation_1_se", typeof(Double));
  1301. createCol(regionsettings, "elevation_2_se", typeof(Double));
  1302. createCol(regionsettings, "elevation_1_sw", typeof(Double));
  1303. createCol(regionsettings, "elevation_2_sw", typeof(Double));
  1304. createCol(regionsettings, "water_height", typeof(Double));
  1305. createCol(regionsettings, "terrain_raise_limit", typeof(Double));
  1306. createCol(regionsettings, "terrain_lower_limit", typeof(Double));
  1307. createCol(regionsettings, "use_estate_sun", typeof(Int32));
  1308. createCol(regionsettings, "sandbox", typeof(Int32));
  1309. createCol(regionsettings, "sunvectorx", typeof(Double));
  1310. createCol(regionsettings, "sunvectory", typeof(Double));
  1311. createCol(regionsettings, "sunvectorz", typeof(Double));
  1312. createCol(regionsettings, "fixed_sun", typeof(Int32));
  1313. createCol(regionsettings, "sun_position", typeof(Double));
  1314. createCol(regionsettings, "covenant", typeof(String));
  1315. createCol(regionsettings, "covenant_datetime", typeof(Int32));
  1316. createCol(regionsettings, "map_tile_ID", typeof(String));
  1317. createCol(regionsettings, "TelehubObject", typeof(String));
  1318. createCol(regionsettings, "parcel_tile_ID", typeof(String));
  1319. regionsettings.PrimaryKey = new DataColumn[] { regionsettings.Columns["regionUUID"] };
  1320. return regionsettings;
  1321. }
  1322. /// <summary>
  1323. /// create "regionwindlight" table
  1324. /// </summary>
  1325. /// <returns>RegionWindlight DataTable</returns>
  1326. private static DataTable createRegionWindlightTable()
  1327. {
  1328. DataTable regionwindlight = new DataTable("regionwindlight");
  1329. createCol(regionwindlight, "region_id", typeof(String));
  1330. createCol(regionwindlight, "water_color_r", typeof(Double));
  1331. createCol(regionwindlight, "water_color_g", typeof(Double));
  1332. createCol(regionwindlight, "water_color_b", typeof(Double));
  1333. createCol(regionwindlight, "water_color_i", typeof(Double));
  1334. createCol(regionwindlight, "water_fog_density_exponent", typeof(Double));
  1335. createCol(regionwindlight, "underwater_fog_modifier", typeof(Double));
  1336. createCol(regionwindlight, "reflection_wavelet_scale_1", typeof(Double));
  1337. createCol(regionwindlight, "reflection_wavelet_scale_2", typeof(Double));
  1338. createCol(regionwindlight, "reflection_wavelet_scale_3", typeof(Double));
  1339. createCol(regionwindlight, "fresnel_scale", typeof(Double));
  1340. createCol(regionwindlight, "fresnel_offset", typeof(Double));
  1341. createCol(regionwindlight, "refract_scale_above", typeof(Double));
  1342. createCol(regionwindlight, "refract_scale_below", typeof(Double));
  1343. createCol(regionwindlight, "blur_multiplier", typeof(Double));
  1344. createCol(regionwindlight, "big_wave_direction_x", typeof(Double));
  1345. createCol(regionwindlight, "big_wave_direction_y", typeof(Double));
  1346. createCol(regionwindlight, "little_wave_direction_x", typeof(Double));
  1347. createCol(regionwindlight, "little_wave_direction_y", typeof(Double));
  1348. createCol(regionwindlight, "normal_map_texture", typeof(String));
  1349. createCol(regionwindlight, "horizon_r", typeof(Double));
  1350. createCol(regionwindlight, "horizon_g", typeof(Double));
  1351. createCol(regionwindlight, "horizon_b", typeof(Double));
  1352. createCol(regionwindlight, "horizon_i", typeof(Double));
  1353. createCol(regionwindlight, "haze_horizon", typeof(Double));
  1354. createCol(regionwindlight, "blue_density_r", typeof(Double));
  1355. createCol(regionwindlight, "blue_density_g", typeof(Double));
  1356. createCol(regionwindlight, "blue_density_b", typeof(Double));
  1357. createCol(regionwindlight, "blue_density_i", typeof(Double));
  1358. createCol(regionwindlight, "haze_density", typeof(Double));
  1359. createCol(regionwindlight, "density_multiplier", typeof(Double));
  1360. createCol(regionwindlight, "distance_multiplier", typeof(Double));
  1361. createCol(regionwindlight, "max_altitude", typeof(Int32));
  1362. createCol(regionwindlight, "sun_moon_color_r", typeof(Double));
  1363. createCol(regionwindlight, "sun_moon_color_g", typeof(Double));
  1364. createCol(regionwindlight, "sun_moon_color_b", typeof(Double));
  1365. createCol(regionwindlight, "sun_moon_color_i", typeof(Double));
  1366. createCol(regionwindlight, "sun_moon_position", typeof(Double));
  1367. createCol(regionwindlight, "ambient_r", typeof(Double));
  1368. createCol(regionwindlight, "ambient_g", typeof(Double));
  1369. createCol(regionwindlight, "ambient_b", typeof(Double));
  1370. createCol(regionwindlight, "ambient_i", typeof(Double));
  1371. createCol(regionwindlight, "east_angle", typeof(Double));
  1372. createCol(regionwindlight, "sun_glow_focus", typeof(Double));
  1373. createCol(regionwindlight, "sun_glow_size", typeof(Double));
  1374. createCol(regionwindlight, "scene_gamma", typeof(Double));
  1375. createCol(regionwindlight, "star_brightness", typeof(Double));
  1376. createCol(regionwindlight, "cloud_color_r", typeof(Double));
  1377. createCol(regionwindlight, "cloud_color_g", typeof(Double));
  1378. createCol(regionwindlight, "cloud_color_b", typeof(Double));
  1379. createCol(regionwindlight, "cloud_color_i", typeof(Double));
  1380. createCol(regionwindlight, "cloud_x", typeof(Double));
  1381. createCol(regionwindlight, "cloud_y", typeof(Double));
  1382. createCol(regionwindlight, "cloud_density", typeof(Double));
  1383. createCol(regionwindlight, "cloud_coverage", typeof(Double));
  1384. createCol(regionwindlight, "cloud_scale", typeof(Double));
  1385. createCol(regionwindlight, "cloud_detail_x", typeof(Double));
  1386. createCol(regionwindlight, "cloud_detail_y", typeof(Double));
  1387. createCol(regionwindlight, "cloud_detail_density", typeof(Double));
  1388. createCol(regionwindlight, "cloud_scroll_x", typeof(Double));
  1389. createCol(regionwindlight, "cloud_scroll_x_lock", typeof(Int32));
  1390. createCol(regionwindlight, "cloud_scroll_y", typeof(Double));
  1391. createCol(regionwindlight, "cloud_scroll_y_lock", typeof(Int32));
  1392. createCol(regionwindlight, "draw_classic_clouds", typeof(Int32));
  1393. regionwindlight.PrimaryKey = new DataColumn[] { regionwindlight.Columns["region_id"] };
  1394. return regionwindlight;
  1395. }
  1396. private static DataTable createRegionEnvironmentTable()
  1397. {
  1398. DataTable regionEnvironment = new DataTable("regionenvironment");
  1399. createCol(regionEnvironment, "region_id", typeof(String));
  1400. createCol(regionEnvironment, "llsd_settings", typeof(String));
  1401. regionEnvironment.PrimaryKey = new DataColumn[] { regionEnvironment.Columns["region_id"] };
  1402. return regionEnvironment;
  1403. }
  1404. private static DataTable createRegionSpawnPointsTable()
  1405. {
  1406. DataTable spawn_points = new DataTable("spawn_points");
  1407. createCol(spawn_points, "regionID", typeof(String));
  1408. createCol(spawn_points, "Yaw", typeof(float));
  1409. createCol(spawn_points, "Pitch", typeof(float));
  1410. createCol(spawn_points, "Distance", typeof(float));
  1411. return spawn_points;
  1412. }
  1413. /***********************************************************************
  1414. *
  1415. * Convert between ADO.NET <=> OpenSim Objects
  1416. *
  1417. * These should be database independant
  1418. *
  1419. **********************************************************************/
  1420. /// <summary>
  1421. ///
  1422. /// </summary>
  1423. /// <param name="row"></param>
  1424. /// <returns></returns>
  1425. private SceneObjectPart buildPrim(DataRow row)
  1426. {
  1427. // Code commented. Uncomment to test the unit test inline.
  1428. // The unit test mentions this commented code for the purposes
  1429. // of debugging a unit test failure
  1430. // SceneObjectGroup sog = new SceneObjectGroup();
  1431. // SceneObjectPart sop = new SceneObjectPart();
  1432. // sop.LocalId = 1;
  1433. // sop.Name = "object1";
  1434. // sop.Description = "object1";
  1435. // sop.Text = "";
  1436. // sop.SitName = "";
  1437. // sop.TouchName = "";
  1438. // sop.UUID = UUID.Random();
  1439. // sop.Shape = PrimitiveBaseShape.Default;
  1440. // sog.SetRootPart(sop);
  1441. // Add breakpoint in above line. Check sop fields.
  1442. // TODO: this doesn't work yet because something more
  1443. // interesting has to be done to actually get these values
  1444. // back out. Not enough time to figure it out yet.
  1445. SceneObjectPart prim = new SceneObjectPart();
  1446. prim.UUID = new UUID((String)row["UUID"]);
  1447. // explicit conversion of integers is required, which sort
  1448. // of sucks. No idea if there is a shortcut here or not.
  1449. prim.CreationDate = Convert.ToInt32(row["CreationDate"]);
  1450. prim.Name = row["Name"] == DBNull.Value ? string.Empty : (string)row["Name"];
  1451. // various text fields
  1452. prim.Text = (String)row["Text"];
  1453. prim.Color = Color.FromArgb(Convert.ToInt32(row["ColorA"]),
  1454. Convert.ToInt32(row["ColorR"]),
  1455. Convert.ToInt32(row["ColorG"]),
  1456. Convert.ToInt32(row["ColorB"]));
  1457. prim.Description = (String)row["Description"];
  1458. prim.SitName = (String)row["SitName"];
  1459. prim.TouchName = (String)row["TouchName"];
  1460. // permissions
  1461. prim.Flags = (PrimFlags)Convert.ToUInt32(row["ObjectFlags"]);
  1462. prim.CreatorIdentification = (String)row["CreatorID"];
  1463. prim.OwnerID = new UUID((String)row["OwnerID"]);
  1464. prim.GroupID = new UUID((String)row["GroupID"]);
  1465. prim.LastOwnerID = new UUID((String)row["LastOwnerID"]);
  1466. prim.RezzerID = row["RezzerID"] == DBNull.Value ? UUID.Zero : new UUID((String)row["RezzerID"]);
  1467. prim.OwnerMask = Convert.ToUInt32(row["OwnerMask"]);
  1468. prim.NextOwnerMask = Convert.ToUInt32(row["NextOwnerMask"]);
  1469. prim.GroupMask = Convert.ToUInt32(row["GroupMask"]);
  1470. prim.EveryoneMask = Convert.ToUInt32(row["EveryoneMask"]);
  1471. prim.BaseMask = Convert.ToUInt32(row["BaseMask"]);
  1472. // vectors
  1473. prim.OffsetPosition = new Vector3(
  1474. Convert.ToSingle(row["PositionX"]),
  1475. Convert.ToSingle(row["PositionY"]),
  1476. Convert.ToSingle(row["PositionZ"])
  1477. );
  1478. prim.GroupPosition = new Vector3(
  1479. Convert.ToSingle(row["GroupPositionX"]),
  1480. Convert.ToSingle(row["GroupPositionY"]),
  1481. Convert.ToSingle(row["GroupPositionZ"])
  1482. );
  1483. prim.Velocity = new Vector3(
  1484. Convert.ToSingle(row["VelocityX"]),
  1485. Convert.ToSingle(row["VelocityY"]),
  1486. Convert.ToSingle(row["VelocityZ"])
  1487. );
  1488. prim.AngularVelocity = new Vector3(
  1489. Convert.ToSingle(row["AngularVelocityX"]),
  1490. Convert.ToSingle(row["AngularVelocityY"]),
  1491. Convert.ToSingle(row["AngularVelocityZ"])
  1492. );
  1493. prim.Acceleration = new Vector3(
  1494. Convert.ToSingle(row["AccelerationX"]),
  1495. Convert.ToSingle(row["AccelerationY"]),
  1496. Convert.ToSingle(row["AccelerationZ"])
  1497. );
  1498. // quaternions
  1499. prim.RotationOffset = new Quaternion(
  1500. Convert.ToSingle(row["RotationX"]),
  1501. Convert.ToSingle(row["RotationY"]),
  1502. Convert.ToSingle(row["RotationZ"]),
  1503. Convert.ToSingle(row["RotationW"])
  1504. );
  1505. prim.SitTargetPositionLL = new Vector3(
  1506. Convert.ToSingle(row["SitTargetOffsetX"]),
  1507. Convert.ToSingle(row["SitTargetOffsetY"]),
  1508. Convert.ToSingle(row["SitTargetOffsetZ"]));
  1509. prim.SitTargetOrientationLL = new Quaternion(
  1510. Convert.ToSingle(
  1511. row["SitTargetOrientX"]),
  1512. Convert.ToSingle(
  1513. row["SitTargetOrientY"]),
  1514. Convert.ToSingle(
  1515. row["SitTargetOrientZ"]),
  1516. Convert.ToSingle(
  1517. row["SitTargetOrientW"]));
  1518. prim.ClickAction = Convert.ToByte(row["ClickAction"]);
  1519. prim.PayPrice[0] = Convert.ToInt32(row["PayPrice"]);
  1520. prim.PayPrice[1] = Convert.ToInt32(row["PayButton1"]);
  1521. prim.PayPrice[2] = Convert.ToInt32(row["PayButton2"]);
  1522. prim.PayPrice[3] = Convert.ToInt32(row["PayButton3"]);
  1523. prim.PayPrice[4] = Convert.ToInt32(row["PayButton4"]);
  1524. prim.Sound = new UUID(row["LoopedSound"].ToString());
  1525. prim.SoundGain = Convert.ToSingle(row["LoopedSoundGain"]);
  1526. if (prim.Sound != UUID.Zero)
  1527. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  1528. else
  1529. prim.SoundFlags = 0;
  1530. if (!row.IsNull("TextureAnimation"))
  1531. prim.TextureAnimation = Convert.FromBase64String(row["TextureAnimation"].ToString());
  1532. if (!row.IsNull("ParticleSystem"))
  1533. prim.ParticleSystem = Convert.FromBase64String(row["ParticleSystem"].ToString());
  1534. prim.AngularVelocity = new Vector3(
  1535. Convert.ToSingle(row["OmegaX"]),
  1536. Convert.ToSingle(row["OmegaY"]),
  1537. Convert.ToSingle(row["OmegaZ"])
  1538. );
  1539. prim.SetCameraEyeOffset(new Vector3(
  1540. Convert.ToSingle(row["CameraEyeOffsetX"]),
  1541. Convert.ToSingle(row["CameraEyeOffsetY"]),
  1542. Convert.ToSingle(row["CameraEyeOffsetZ"])
  1543. ));
  1544. prim.SetCameraAtOffset(new Vector3(
  1545. Convert.ToSingle(row["CameraAtOffsetX"]),
  1546. Convert.ToSingle(row["CameraAtOffsetY"]),
  1547. Convert.ToSingle(row["CameraAtOffsetZ"])
  1548. ));
  1549. if (Convert.ToInt16(row["ForceMouselook"]) != 0)
  1550. prim.SetForceMouselook(true);
  1551. prim.ScriptAccessPin = Convert.ToInt32(row["ScriptAccessPin"]);
  1552. if (Convert.ToInt16(row["AllowedDrop"]) != 0)
  1553. prim.AllowedDrop = true;
  1554. if (Convert.ToInt16(row["DieAtEdge"]) != 0)
  1555. prim.DIE_AT_EDGE = true;
  1556. prim.SalePrice = Convert.ToInt32(row["SalePrice"]);
  1557. prim.ObjectSaleType = Convert.ToByte(row["SaleType"]);
  1558. prim.Material = Convert.ToByte(row["Material"]);
  1559. prim.CollisionSound = new UUID(row["CollisionSound"].ToString());
  1560. prim.CollisionSoundVolume = Convert.ToSingle(row["CollisionSoundVolume"]);
  1561. if (Convert.ToInt16(row["VolumeDetect"]) != 0)
  1562. prim.VolumeDetectActive = true;
  1563. if (!(row["MediaURL"] is System.DBNull))
  1564. {
  1565. // m_log.DebugFormat("[SQLITE]: MediaUrl type [{0}]", row["MediaURL"].GetType());
  1566. prim.MediaUrl = (string)row["MediaURL"];
  1567. }
  1568. prim.AttachedPos = new Vector3(
  1569. Convert.ToSingle(row["AttachedPosX"]),
  1570. Convert.ToSingle(row["AttachedPosY"]),
  1571. Convert.ToSingle(row["AttachedPosZ"])
  1572. );
  1573. if (!(row["DynAttrs"] is System.DBNull))
  1574. {
  1575. //m_log.DebugFormat("[SQLITE]: DynAttrs type [{0}]", row["DynAttrs"].GetType());
  1576. prim.DynAttrs = DAMap.FromXml((string)row["DynAttrs"]);
  1577. }
  1578. else
  1579. {
  1580. prim.DynAttrs = null;
  1581. }
  1582. prim.PhysicsShapeType = Convert.ToByte(row["PhysicsShapeType"]);
  1583. prim.Density = Convert.ToSingle(row["Density"]);
  1584. prim.GravityModifier = Convert.ToSingle(row["GravityModifier"]);
  1585. prim.Friction = Convert.ToSingle(row["Friction"]);
  1586. prim.Restitution = Convert.ToSingle(row["Restitution"]);
  1587. if (!(row["KeyframeMotion"] is DBNull))
  1588. {
  1589. Byte[] data = (byte[])row["KeyframeMotion"];
  1590. if (data.Length > 0)
  1591. prim.KeyframeMotion = KeyframeMotion.FromData(null, data);
  1592. else
  1593. prim.KeyframeMotion = null;
  1594. }
  1595. else
  1596. {
  1597. prim.KeyframeMotion = null;
  1598. }
  1599. prim.PassCollisions = Convert.ToBoolean(row["PassCollisions"]);
  1600. prim.PassTouches = Convert.ToBoolean(row["PassTouches"]);
  1601. prim.RotationAxisLocks = Convert.ToByte(row["RotationAxisLocks"]);
  1602. SOPVehicle vehicle = null;
  1603. if (!(row["Vehicle"] is DBNull) && row["Vehicle"].ToString() != String.Empty)
  1604. {
  1605. vehicle = SOPVehicle.FromXml2(row["Vehicle"].ToString());
  1606. if (vehicle != null)
  1607. prim.VehicleParams = vehicle;
  1608. }
  1609. PhysicsInertiaData pdata = null;
  1610. if (!(row["PhysInertia"] is DBNull) && row["PhysInertia"].ToString() != String.Empty)
  1611. pdata = PhysicsInertiaData.FromXml2(row["PhysInertia"].ToString());
  1612. prim.PhysicsInertia = pdata;
  1613. return prim;
  1614. }
  1615. /// <summary>
  1616. /// Build a prim inventory item from the persisted data.
  1617. /// </summary>
  1618. /// <param name="row"></param>
  1619. /// <returns></returns>
  1620. private static TaskInventoryItem buildItem(DataRow row)
  1621. {
  1622. TaskInventoryItem taskItem = new TaskInventoryItem();
  1623. taskItem.ItemID = new UUID((String)row["itemID"]);
  1624. taskItem.ParentPartID = new UUID((String)row["primID"]);
  1625. taskItem.AssetID = new UUID((String)row["assetID"]);
  1626. taskItem.ParentID = new UUID((String)row["parentFolderID"]);
  1627. taskItem.InvType = Convert.ToInt32(row["invType"]);
  1628. taskItem.Type = Convert.ToInt32(row["assetType"]);
  1629. taskItem.Name = (String)row["name"];
  1630. taskItem.Description = (String)row["description"];
  1631. taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
  1632. taskItem.CreatorIdentification = (String)row["creatorID"];
  1633. taskItem.OwnerID = new UUID((String)row["ownerID"]);
  1634. taskItem.LastOwnerID = new UUID((String)row["lastOwnerID"]);
  1635. taskItem.GroupID = new UUID((String)row["groupID"]);
  1636. taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
  1637. taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
  1638. taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
  1639. taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
  1640. taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
  1641. taskItem.Flags = Convert.ToUInt32(row["flags"]);
  1642. return taskItem;
  1643. }
  1644. /// <summary>
  1645. /// Build a Land Data from the persisted data.
  1646. /// </summary>
  1647. /// <param name="row"></param>
  1648. /// <returns></returns>
  1649. private LandData buildLandData(DataRow row)
  1650. {
  1651. LandData newData = new LandData();
  1652. newData.GlobalID = new UUID((String)row["UUID"]);
  1653. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  1654. // Bitmap is a byte[512]
  1655. newData.Bitmap = (Byte[])row["Bitmap"];
  1656. newData.Name = (String)row["Name"];
  1657. newData.Description = (String)row["Desc"];
  1658. newData.OwnerID = (UUID)(String)row["OwnerUUID"];
  1659. newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
  1660. newData.Area = Convert.ToInt32(row["Area"]);
  1661. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
  1662. newData.Category = (ParcelCategory)Convert.ToInt32(row["Category"]);
  1663. //Enum OpenMetaverse.Parcel.ParcelCategory
  1664. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  1665. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  1666. newData.GroupID = new UUID((String)row["GroupUUID"]);
  1667. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  1668. newData.Status = (ParcelStatus)Convert.ToInt32(row["LandStatus"]);
  1669. //Enum. OpenMetaverse.Parcel.ParcelStatus
  1670. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  1671. newData.LandingType = (Byte)row["LandingType"];
  1672. newData.MediaAutoScale = (Byte)row["MediaAutoScale"];
  1673. newData.MediaID = new UUID((String)row["MediaTextureUUID"]);
  1674. newData.MediaURL = (String)row["MediaURL"];
  1675. newData.MusicURL = (String)row["MusicURL"];
  1676. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  1677. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  1678. newData.SnapshotID = (UUID)(String)row["SnapshotUUID"];
  1679. newData.Dwell = Convert.ToInt32(row["Dwell"]);
  1680. newData.MediaType = (String)row["MediaType"];
  1681. newData.MediaDescription = (String)row["MediaDescription"];
  1682. newData.MediaWidth = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[0]);
  1683. newData.MediaHeight = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[1]);
  1684. newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]);
  1685. newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]);
  1686. newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]);
  1687. newData.SeeAVs = Convert.ToBoolean(row["SeeAVs"]);
  1688. newData.AnyAVSounds = Convert.ToBoolean(row["AnyAVSounds"]);
  1689. newData.GroupAVSounds = Convert.ToBoolean(row["GroupAVSounds"]);
  1690. try
  1691. {
  1692. newData.UserLocation =
  1693. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  1694. Convert.ToSingle(row["UserLocationZ"]));
  1695. newData.UserLookAt =
  1696. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  1697. Convert.ToSingle(row["UserLookAtZ"]));
  1698. }
  1699. catch (InvalidCastException)
  1700. {
  1701. m_log.ErrorFormat("[SQLITE REGION DB]: unable to get parcel telehub settings for {1}", newData.Name);
  1702. newData.UserLocation = Vector3.Zero;
  1703. newData.UserLookAt = Vector3.Zero;
  1704. }
  1705. newData.ParcelAccessList = new List<LandAccessEntry>();
  1706. UUID authBuyerID = UUID.Zero;
  1707. UUID.TryParse((string)row["AuthbuyerID"], out authBuyerID);
  1708. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  1709. return newData;
  1710. }
  1711. private RegionSettings buildRegionSettings(DataRow row)
  1712. {
  1713. RegionSettings newSettings = new RegionSettings();
  1714. newSettings.RegionUUID = new UUID((string)row["regionUUID"]);
  1715. newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
  1716. newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
  1717. newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
  1718. newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
  1719. newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
  1720. newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
  1721. newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
  1722. newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
  1723. newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
  1724. newSettings.Maturity = Convert.ToInt32(row["maturity"]);
  1725. newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
  1726. newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
  1727. newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
  1728. newSettings.TerrainTexture1 = new UUID((String)row["terrain_texture_1"]);
  1729. newSettings.TerrainTexture2 = new UUID((String)row["terrain_texture_2"]);
  1730. newSettings.TerrainTexture3 = new UUID((String)row["terrain_texture_3"]);
  1731. newSettings.TerrainTexture4 = new UUID((String)row["terrain_texture_4"]);
  1732. newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
  1733. newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
  1734. newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
  1735. newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
  1736. newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
  1737. newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
  1738. newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
  1739. newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
  1740. newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
  1741. newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
  1742. newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
  1743. newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
  1744. newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
  1745. newSettings.SunVector = new Vector3(
  1746. Convert.ToSingle(row["sunvectorx"]),
  1747. Convert.ToSingle(row["sunvectory"]),
  1748. Convert.ToSingle(row["sunvectorz"])
  1749. );
  1750. newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
  1751. newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
  1752. newSettings.Covenant = new UUID((String)row["covenant"]);
  1753. newSettings.CovenantChangedDateTime = Convert.ToInt32(row["covenant_datetime"]);
  1754. newSettings.TerrainImageID = new UUID((String)row["map_tile_ID"]);
  1755. newSettings.TelehubObject = new UUID((String)row["TelehubObject"]);
  1756. newSettings.ParcelImageID = new UUID((String)row["parcel_tile_ID"]);
  1757. newSettings.GodBlockSearch = Convert.ToBoolean(row["block_search"]);
  1758. newSettings.Casino = Convert.ToBoolean(row["casino"]);
  1759. return newSettings;
  1760. }
  1761. /// <summary>
  1762. /// Build a windlight entry from the persisted data.
  1763. /// </summary>
  1764. /// <param name="row"></param>
  1765. /// <returns>RegionLightShareData</returns>
  1766. private RegionLightShareData buildRegionWindlight(DataRow row)
  1767. {
  1768. RegionLightShareData windlight = new RegionLightShareData();
  1769. windlight.regionID = new UUID((string)row["region_id"]);
  1770. windlight.waterColor.X = Convert.ToSingle(row["water_color_r"]);
  1771. windlight.waterColor.Y = Convert.ToSingle(row["water_color_g"]);
  1772. windlight.waterColor.Z = Convert.ToSingle(row["water_color_b"]);
  1773. //windlight.waterColor.W = Convert.ToSingle(row["water_color_i"]); //not implemented
  1774. windlight.waterFogDensityExponent = Convert.ToSingle(row["water_fog_density_exponent"]);
  1775. windlight.underwaterFogModifier = Convert.ToSingle(row["underwater_fog_modifier"]);
  1776. windlight.reflectionWaveletScale.X = Convert.ToSingle(row["reflection_wavelet_scale_1"]);
  1777. windlight.reflectionWaveletScale.Y = Convert.ToSingle(row["reflection_wavelet_scale_2"]);
  1778. windlight.reflectionWaveletScale.Z = Convert.ToSingle(row["reflection_wavelet_scale_3"]);
  1779. windlight.fresnelScale = Convert.ToSingle(row["fresnel_scale"]);
  1780. windlight.fresnelOffset = Convert.ToSingle(row["fresnel_offset"]);
  1781. windlight.refractScaleAbove = Convert.ToSingle(row["refract_scale_above"]);
  1782. windlight.refractScaleBelow = Convert.ToSingle(row["refract_scale_below"]);
  1783. windlight.blurMultiplier = Convert.ToSingle(row["blur_multiplier"]);
  1784. windlight.bigWaveDirection.X = Convert.ToSingle(row["big_wave_direction_x"]);
  1785. windlight.bigWaveDirection.Y = Convert.ToSingle(row["big_wave_direction_y"]);
  1786. windlight.littleWaveDirection.X = Convert.ToSingle(row["little_wave_direction_x"]);
  1787. windlight.littleWaveDirection.Y = Convert.ToSingle(row["little_wave_direction_y"]);
  1788. windlight.normalMapTexture = new UUID((string)row["normal_map_texture"]);
  1789. windlight.horizon.X = Convert.ToSingle(row["horizon_r"]);
  1790. windlight.horizon.Y = Convert.ToSingle(row["horizon_g"]);
  1791. windlight.horizon.Z = Convert.ToSingle(row["horizon_b"]);
  1792. windlight.horizon.W = Convert.ToSingle(row["horizon_i"]);
  1793. windlight.hazeHorizon = Convert.ToSingle(row["haze_horizon"]);
  1794. windlight.blueDensity.X = Convert.ToSingle(row["blue_density_r"]);
  1795. windlight.blueDensity.Y = Convert.ToSingle(row["blue_density_g"]);
  1796. windlight.blueDensity.Z = Convert.ToSingle(row["blue_density_b"]);
  1797. windlight.blueDensity.W = Convert.ToSingle(row["blue_density_i"]);
  1798. windlight.hazeDensity = Convert.ToSingle(row["haze_density"]);
  1799. windlight.densityMultiplier = Convert.ToSingle(row["density_multiplier"]);
  1800. windlight.distanceMultiplier = Convert.ToSingle(row["distance_multiplier"]);
  1801. windlight.maxAltitude = Convert.ToUInt16(row["max_altitude"]);
  1802. windlight.sunMoonColor.X = Convert.ToSingle(row["sun_moon_color_r"]);
  1803. windlight.sunMoonColor.Y = Convert.ToSingle(row["sun_moon_color_g"]);
  1804. windlight.sunMoonColor.Z = Convert.ToSingle(row["sun_moon_color_b"]);
  1805. windlight.sunMoonColor.W = Convert.ToSingle(row["sun_moon_color_i"]);
  1806. windlight.sunMoonPosition = Convert.ToSingle(row["sun_moon_position"]);
  1807. windlight.ambient.X = Convert.ToSingle(row["ambient_r"]);
  1808. windlight.ambient.Y = Convert.ToSingle(row["ambient_g"]);
  1809. windlight.ambient.Z = Convert.ToSingle(row["ambient_b"]);
  1810. windlight.ambient.W = Convert.ToSingle(row["ambient_i"]);
  1811. windlight.eastAngle = Convert.ToSingle(row["east_angle"]);
  1812. windlight.sunGlowFocus = Convert.ToSingle(row["sun_glow_focus"]);
  1813. windlight.sunGlowSize = Convert.ToSingle(row["sun_glow_size"]);
  1814. windlight.sceneGamma = Convert.ToSingle(row["scene_gamma"]);
  1815. windlight.starBrightness = Convert.ToSingle(row["star_brightness"]);
  1816. windlight.cloudColor.X = Convert.ToSingle(row["cloud_color_r"]);
  1817. windlight.cloudColor.Y = Convert.ToSingle(row["cloud_color_g"]);
  1818. windlight.cloudColor.Z = Convert.ToSingle(row["cloud_color_b"]);
  1819. windlight.cloudColor.W = Convert.ToSingle(row["cloud_color_i"]);
  1820. windlight.cloudXYDensity.X = Convert.ToSingle(row["cloud_x"]);
  1821. windlight.cloudXYDensity.Y = Convert.ToSingle(row["cloud_y"]);
  1822. windlight.cloudXYDensity.Z = Convert.ToSingle(row["cloud_density"]);
  1823. windlight.cloudCoverage = Convert.ToSingle(row["cloud_coverage"]);
  1824. windlight.cloudScale = Convert.ToSingle(row["cloud_scale"]);
  1825. windlight.cloudDetailXYDensity.X = Convert.ToSingle(row["cloud_detail_x"]);
  1826. windlight.cloudDetailXYDensity.Y = Convert.ToSingle(row["cloud_detail_y"]);
  1827. windlight.cloudDetailXYDensity.Z = Convert.ToSingle(row["cloud_detail_density"]);
  1828. windlight.cloudScrollX = Convert.ToSingle(row["cloud_scroll_x"]);
  1829. windlight.cloudScrollXLock = Convert.ToBoolean(row["cloud_scroll_x_lock"]);
  1830. windlight.cloudScrollY = Convert.ToSingle(row["cloud_scroll_y"]);
  1831. windlight.cloudScrollYLock = Convert.ToBoolean(row["cloud_scroll_y_lock"]);
  1832. windlight.drawClassicClouds = Convert.ToBoolean(row["draw_classic_clouds"]);
  1833. return windlight;
  1834. }
  1835. /// <summary>
  1836. /// Build a land access entry from the persisted data.
  1837. /// </summary>
  1838. /// <param name="row"></param>
  1839. /// <returns></returns>
  1840. private static LandAccessEntry buildLandAccessData(DataRow row)
  1841. {
  1842. LandAccessEntry entry = new LandAccessEntry();
  1843. entry.AgentID = new UUID((string)row["AccessUUID"]);
  1844. entry.Flags = (AccessList)row["Flags"];
  1845. entry.Expires = 0;
  1846. return entry;
  1847. }
  1848. /// <summary>
  1849. ///
  1850. /// </summary>
  1851. /// <param name="row"></param>
  1852. /// <param name="prim"></param>
  1853. /// <param name="sceneGroupID"></param>
  1854. /// <param name="regionUUID"></param>
  1855. private static void fillPrimRow(DataRow row, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1856. {
  1857. row["UUID"] = prim.UUID.ToString();
  1858. row["RegionUUID"] = regionUUID.ToString();
  1859. row["CreationDate"] = prim.CreationDate;
  1860. row["Name"] = prim.Name;
  1861. row["SceneGroupID"] = sceneGroupID.ToString();
  1862. // the UUID of the root part for this SceneObjectGroup
  1863. // various text fields
  1864. row["Text"] = prim.Text;
  1865. row["Description"] = prim.Description;
  1866. row["SitName"] = prim.SitName;
  1867. row["TouchName"] = prim.TouchName;
  1868. // permissions
  1869. row["ObjectFlags"] = (uint)prim.Flags;
  1870. row["CreatorID"] = prim.CreatorIdentification.ToString();
  1871. row["OwnerID"] = prim.OwnerID.ToString();
  1872. row["GroupID"] = prim.GroupID.ToString();
  1873. row["LastOwnerID"] = prim.LastOwnerID.ToString();
  1874. row["RezzerID"] = prim.RezzerID.ToString();
  1875. row["OwnerMask"] = prim.OwnerMask;
  1876. row["NextOwnerMask"] = prim.NextOwnerMask;
  1877. row["GroupMask"] = prim.GroupMask;
  1878. row["EveryoneMask"] = prim.EveryoneMask;
  1879. row["BaseMask"] = prim.BaseMask;
  1880. // vectors
  1881. row["PositionX"] = prim.OffsetPosition.X;
  1882. row["PositionY"] = prim.OffsetPosition.Y;
  1883. row["PositionZ"] = prim.OffsetPosition.Z;
  1884. row["GroupPositionX"] = prim.GroupPosition.X;
  1885. row["GroupPositionY"] = prim.GroupPosition.Y;
  1886. row["GroupPositionZ"] = prim.GroupPosition.Z;
  1887. row["VelocityX"] = prim.Velocity.X;
  1888. row["VelocityY"] = prim.Velocity.Y;
  1889. row["VelocityZ"] = prim.Velocity.Z;
  1890. row["AngularVelocityX"] = prim.AngularVelocity.X;
  1891. row["AngularVelocityY"] = prim.AngularVelocity.Y;
  1892. row["AngularVelocityZ"] = prim.AngularVelocity.Z;
  1893. row["AccelerationX"] = prim.Acceleration.X;
  1894. row["AccelerationY"] = prim.Acceleration.Y;
  1895. row["AccelerationZ"] = prim.Acceleration.Z;
  1896. // quaternions
  1897. row["RotationX"] = prim.RotationOffset.X;
  1898. row["RotationY"] = prim.RotationOffset.Y;
  1899. row["RotationZ"] = prim.RotationOffset.Z;
  1900. row["RotationW"] = prim.RotationOffset.W;
  1901. // Sit target
  1902. Vector3 sitTargetPos = prim.SitTargetPositionLL;
  1903. row["SitTargetOffsetX"] = sitTargetPos.X;
  1904. row["SitTargetOffsetY"] = sitTargetPos.Y;
  1905. row["SitTargetOffsetZ"] = sitTargetPos.Z;
  1906. Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
  1907. row["SitTargetOrientW"] = sitTargetOrient.W;
  1908. row["SitTargetOrientX"] = sitTargetOrient.X;
  1909. row["SitTargetOrientY"] = sitTargetOrient.Y;
  1910. row["SitTargetOrientZ"] = sitTargetOrient.Z;
  1911. row["ColorR"] = Convert.ToInt32(prim.Color.R);
  1912. row["ColorG"] = Convert.ToInt32(prim.Color.G);
  1913. row["ColorB"] = Convert.ToInt32(prim.Color.B);
  1914. row["ColorA"] = Convert.ToInt32(prim.Color.A);
  1915. row["PayPrice"] = prim.PayPrice[0];
  1916. row["PayButton1"] = prim.PayPrice[1];
  1917. row["PayButton2"] = prim.PayPrice[2];
  1918. row["PayButton3"] = prim.PayPrice[3];
  1919. row["PayButton4"] = prim.PayPrice[4];
  1920. row["TextureAnimation"] = Convert.ToBase64String(prim.TextureAnimation);
  1921. row["ParticleSystem"] = Convert.ToBase64String(prim.ParticleSystem);
  1922. row["OmegaX"] = prim.AngularVelocity.X;
  1923. row["OmegaY"] = prim.AngularVelocity.Y;
  1924. row["OmegaZ"] = prim.AngularVelocity.Z;
  1925. row["CameraEyeOffsetX"] = prim.GetCameraEyeOffset().X;
  1926. row["CameraEyeOffsetY"] = prim.GetCameraEyeOffset().Y;
  1927. row["CameraEyeOffsetZ"] = prim.GetCameraEyeOffset().Z;
  1928. row["CameraAtOffsetX"] = prim.GetCameraAtOffset().X;
  1929. row["CameraAtOffsetY"] = prim.GetCameraAtOffset().Y;
  1930. row["CameraAtOffsetZ"] = prim.GetCameraAtOffset().Z;
  1931. if ((prim.SoundFlags & 1) != 0) // Looped
  1932. {
  1933. row["LoopedSound"] = prim.Sound.ToString();
  1934. row["LoopedSoundGain"] = prim.SoundGain;
  1935. }
  1936. else
  1937. {
  1938. row["LoopedSound"] = UUID.Zero.ToString();
  1939. row["LoopedSoundGain"] = 0.0f;
  1940. }
  1941. if (prim.GetForceMouselook())
  1942. row["ForceMouselook"] = 1;
  1943. else
  1944. row["ForceMouselook"] = 0;
  1945. row["ScriptAccessPin"] = prim.ScriptAccessPin;
  1946. if (prim.AllowedDrop)
  1947. row["AllowedDrop"] = 1;
  1948. else
  1949. row["AllowedDrop"] = 0;
  1950. if (prim.DIE_AT_EDGE)
  1951. row["DieAtEdge"] = 1;
  1952. else
  1953. row["DieAtEdge"] = 0;
  1954. row["SalePrice"] = prim.SalePrice;
  1955. row["SaleType"] = Convert.ToInt16(prim.ObjectSaleType);
  1956. // click action
  1957. row["ClickAction"] = prim.ClickAction;
  1958. row["Material"] = prim.Material;
  1959. row["CollisionSound"] = prim.CollisionSound.ToString();
  1960. row["CollisionSoundVolume"] = prim.CollisionSoundVolume;
  1961. if (prim.VolumeDetectActive)
  1962. row["VolumeDetect"] = 1;
  1963. else
  1964. row["VolumeDetect"] = 0;
  1965. row["MediaURL"] = prim.MediaUrl;
  1966. row["AttachedPosX"] = prim.AttachedPos.X;
  1967. row["AttachedPosY"] = prim.AttachedPos.Y;
  1968. row["AttachedPosZ"] = prim.AttachedPos.Z;
  1969. if (prim.DynAttrs!= null && prim.DynAttrs.CountNamespaces > 0)
  1970. row["DynAttrs"] = prim.DynAttrs.ToXml();
  1971. else
  1972. row["DynAttrs"] = null;
  1973. row["PhysicsShapeType"] = prim.PhysicsShapeType;
  1974. row["Density"] = (double)prim.Density;
  1975. row["GravityModifier"] = (double)prim.GravityModifier;
  1976. row["Friction"] = (double)prim.Friction;
  1977. row["Restitution"] = (double)prim.Restitution;
  1978. if (prim.KeyframeMotion != null)
  1979. row["KeyframeMotion"] = prim.KeyframeMotion.Serialize();
  1980. else
  1981. row["KeyframeMotion"] = new Byte[0];
  1982. row["PassTouches"] = prim.PassTouches;
  1983. row["PassCollisions"] = prim.PassCollisions;
  1984. row["RotationAxisLocks"] = prim.RotationAxisLocks;
  1985. if (prim.VehicleParams != null)
  1986. row["Vehicle"] = prim.VehicleParams.ToXml2();
  1987. else
  1988. row["Vehicle"] = String.Empty;
  1989. if (prim.PhysicsInertia != null)
  1990. row["PhysInertia"] = prim.PhysicsInertia.ToXml2();
  1991. else
  1992. row["PhysInertia"] = String.Empty;
  1993. }
  1994. /// <summary>
  1995. ///
  1996. /// </summary>
  1997. /// <param name="row"></param>
  1998. /// <param name="taskItem"></param>
  1999. private static void fillItemRow(DataRow row, TaskInventoryItem taskItem)
  2000. {
  2001. row["itemID"] = taskItem.ItemID.ToString();
  2002. row["primID"] = taskItem.ParentPartID.ToString();
  2003. row["assetID"] = taskItem.AssetID.ToString();
  2004. row["parentFolderID"] = taskItem.ParentID.ToString();
  2005. row["invType"] = taskItem.InvType;
  2006. row["assetType"] = taskItem.Type;
  2007. row["name"] = taskItem.Name;
  2008. row["description"] = taskItem.Description;
  2009. row["creationDate"] = taskItem.CreationDate;
  2010. row["creatorID"] = taskItem.CreatorIdentification.ToString();
  2011. row["ownerID"] = taskItem.OwnerID.ToString();
  2012. row["lastOwnerID"] = taskItem.LastOwnerID.ToString();
  2013. row["groupID"] = taskItem.GroupID.ToString();
  2014. row["nextPermissions"] = taskItem.NextPermissions;
  2015. row["currentPermissions"] = taskItem.CurrentPermissions;
  2016. row["basePermissions"] = taskItem.BasePermissions;
  2017. row["everyonePermissions"] = taskItem.EveryonePermissions;
  2018. row["groupPermissions"] = taskItem.GroupPermissions;
  2019. row["flags"] = taskItem.Flags;
  2020. }
  2021. /// <summary>
  2022. ///
  2023. /// </summary>
  2024. /// <param name="row"></param>
  2025. /// <param name="land"></param>
  2026. /// <param name="regionUUID"></param>
  2027. private static void fillLandRow(DataRow row, LandData land, UUID regionUUID)
  2028. {
  2029. row["UUID"] = land.GlobalID.ToString();
  2030. row["RegionUUID"] = regionUUID.ToString();
  2031. row["LocalLandID"] = land.LocalID;
  2032. // Bitmap is a byte[512]
  2033. row["Bitmap"] = land.Bitmap;
  2034. row["Name"] = land.Name;
  2035. row["Desc"] = land.Description;
  2036. row["OwnerUUID"] = land.OwnerID.ToString();
  2037. row["IsGroupOwned"] = land.IsGroupOwned.ToString();
  2038. row["Area"] = land.Area;
  2039. row["AuctionID"] = land.AuctionID; //Unemplemented
  2040. row["Category"] = land.Category; //Enum OpenMetaverse.Parcel.ParcelCategory
  2041. row["ClaimDate"] = land.ClaimDate;
  2042. row["ClaimPrice"] = land.ClaimPrice;
  2043. row["GroupUUID"] = land.GroupID.ToString();
  2044. row["SalePrice"] = land.SalePrice;
  2045. row["LandStatus"] = land.Status; //Enum. OpenMetaverse.Parcel.ParcelStatus
  2046. row["LandFlags"] = land.Flags;
  2047. row["LandingType"] = land.LandingType;
  2048. row["MediaAutoScale"] = land.MediaAutoScale;
  2049. row["MediaTextureUUID"] = land.MediaID.ToString();
  2050. row["MediaURL"] = land.MediaURL;
  2051. row["MusicURL"] = land.MusicURL;
  2052. row["PassHours"] = land.PassHours;
  2053. row["PassPrice"] = land.PassPrice;
  2054. row["SnapshotUUID"] = land.SnapshotID.ToString();
  2055. row["UserLocationX"] = land.UserLocation.X;
  2056. row["UserLocationY"] = land.UserLocation.Y;
  2057. row["UserLocationZ"] = land.UserLocation.Z;
  2058. row["UserLookAtX"] = land.UserLookAt.X;
  2059. row["UserLookAtY"] = land.UserLookAt.Y;
  2060. row["UserLookAtZ"] = land.UserLookAt.Z;
  2061. row["AuthbuyerID"] = land.AuthBuyerID.ToString();
  2062. row["OtherCleanTime"] = land.OtherCleanTime;
  2063. row["Dwell"] = land.Dwell;
  2064. row["MediaType"] = land.MediaType;
  2065. row["MediaDescription"] = land.MediaDescription;
  2066. row["MediaSize"] = String.Format("{0},{1}", land.MediaWidth, land.MediaHeight);
  2067. row["MediaLoop"] = land.MediaLoop;
  2068. row["ObscureMusic"] = land.ObscureMusic;
  2069. row["ObscureMedia"] = land.ObscureMedia;
  2070. row["SeeAVs"] = land.SeeAVs;
  2071. row["AnyAVSounds"] = land.AnyAVSounds;
  2072. row["GroupAVSounds"] = land.GroupAVSounds;
  2073. }
  2074. /// <summary>
  2075. ///
  2076. /// </summary>
  2077. /// <param name="row"></param>
  2078. /// <param name="entry"></param>
  2079. /// <param name="parcelID"></param>
  2080. private static void fillLandAccessRow(DataRow row, LandAccessEntry entry, UUID parcelID)
  2081. {
  2082. row["LandUUID"] = parcelID.ToString();
  2083. row["AccessUUID"] = entry.AgentID.ToString();
  2084. row["Flags"] = entry.Flags;
  2085. }
  2086. private static void fillRegionSettingsRow(DataRow row, RegionSettings settings)
  2087. {
  2088. row["regionUUID"] = settings.RegionUUID.ToString();
  2089. row["block_terraform"] = settings.BlockTerraform;
  2090. row["block_fly"] = settings.BlockFly;
  2091. row["allow_damage"] = settings.AllowDamage;
  2092. row["restrict_pushing"] = settings.RestrictPushing;
  2093. row["allow_land_resell"] = settings.AllowLandResell;
  2094. row["allow_land_join_divide"] = settings.AllowLandJoinDivide;
  2095. row["block_show_in_search"] = settings.BlockShowInSearch;
  2096. row["agent_limit"] = settings.AgentLimit;
  2097. row["object_bonus"] = settings.ObjectBonus;
  2098. row["maturity"] = settings.Maturity;
  2099. row["disable_scripts"] = settings.DisableScripts;
  2100. row["disable_collisions"] = settings.DisableCollisions;
  2101. row["disable_physics"] = settings.DisablePhysics;
  2102. row["terrain_texture_1"] = settings.TerrainTexture1.ToString();
  2103. row["terrain_texture_2"] = settings.TerrainTexture2.ToString();
  2104. row["terrain_texture_3"] = settings.TerrainTexture3.ToString();
  2105. row["terrain_texture_4"] = settings.TerrainTexture4.ToString();
  2106. row["elevation_1_nw"] = settings.Elevation1NW;
  2107. row["elevation_2_nw"] = settings.Elevation2NW;
  2108. row["elevation_1_ne"] = settings.Elevation1NE;
  2109. row["elevation_2_ne"] = settings.Elevation2NE;
  2110. row["elevation_1_se"] = settings.Elevation1SE;
  2111. row["elevation_2_se"] = settings.Elevation2SE;
  2112. row["elevation_1_sw"] = settings.Elevation1SW;
  2113. row["elevation_2_sw"] = settings.Elevation2SW;
  2114. row["water_height"] = settings.WaterHeight;
  2115. row["terrain_raise_limit"] = settings.TerrainRaiseLimit;
  2116. row["terrain_lower_limit"] = settings.TerrainLowerLimit;
  2117. row["use_estate_sun"] = settings.UseEstateSun;
  2118. row["sandbox"] = settings.Sandbox; // unlike other database modules, sqlite uses a lower case s for sandbox!
  2119. row["sunvectorx"] = settings.SunVector.X;
  2120. row["sunvectory"] = settings.SunVector.Y;
  2121. row["sunvectorz"] = settings.SunVector.Z;
  2122. row["fixed_sun"] = settings.FixedSun;
  2123. row["sun_position"] = settings.SunPosition;
  2124. row["covenant"] = settings.Covenant.ToString();
  2125. row["covenant_datetime"] = settings.CovenantChangedDateTime;
  2126. row["map_tile_ID"] = settings.TerrainImageID.ToString();
  2127. row["TelehubObject"] = settings.TelehubObject.ToString();
  2128. row["parcel_tile_ID"] = settings.ParcelImageID.ToString();
  2129. row["block_search"] = settings.GodBlockSearch;
  2130. row["casino"] = settings.Casino;
  2131. }
  2132. /// <summary>
  2133. ///
  2134. /// </summary>
  2135. /// <param name="row"></param>
  2136. /// <param name="windlight"></param>
  2137. private static void fillRegionWindlightRow(DataRow row, RegionLightShareData windlight)
  2138. {
  2139. row["region_id"] = windlight.regionID.ToString();
  2140. row["water_color_r"] = windlight.waterColor.X;
  2141. row["water_color_g"] = windlight.waterColor.Y;
  2142. row["water_color_b"] = windlight.waterColor.Z;
  2143. row["water_color_i"] = 1; //windlight.waterColor.W; //not implemented
  2144. row["water_fog_density_exponent"] = windlight.waterFogDensityExponent;
  2145. row["underwater_fog_modifier"] = windlight.underwaterFogModifier;
  2146. row["reflection_wavelet_scale_1"] = windlight.reflectionWaveletScale.X;
  2147. row["reflection_wavelet_scale_2"] = windlight.reflectionWaveletScale.Y;
  2148. row["reflection_wavelet_scale_3"] = windlight.reflectionWaveletScale.Z;
  2149. row["fresnel_scale"] = windlight.fresnelScale;
  2150. row["fresnel_offset"] = windlight.fresnelOffset;
  2151. row["refract_scale_above"] = windlight.refractScaleAbove;
  2152. row["refract_scale_below"] = windlight.refractScaleBelow;
  2153. row["blur_multiplier"] = windlight.blurMultiplier;
  2154. row["big_wave_direction_x"] = windlight.bigWaveDirection.X;
  2155. row["big_wave_direction_y"] = windlight.bigWaveDirection.Y;
  2156. row["little_wave_direction_x"] = windlight.littleWaveDirection.X;
  2157. row["little_wave_direction_y"] = windlight.littleWaveDirection.Y;
  2158. row["normal_map_texture"] = windlight.normalMapTexture.ToString();
  2159. row["horizon_r"] = windlight.horizon.X;
  2160. row["horizon_g"] = windlight.horizon.Y;
  2161. row["horizon_b"] = windlight.horizon.Z;
  2162. row["horizon_i"] = windlight.horizon.W;
  2163. row["haze_horizon"] = windlight.hazeHorizon;
  2164. row["blue_density_r"] = windlight.blueDensity.X;
  2165. row["blue_density_g"] = windlight.blueDensity.Y;
  2166. row["blue_density_b"] = windlight.blueDensity.Z;
  2167. row["blue_density_i"] = windlight.blueDensity.W;
  2168. row["haze_density"] = windlight.hazeDensity;
  2169. row["density_multiplier"] = windlight.densityMultiplier;
  2170. row["distance_multiplier"] = windlight.distanceMultiplier;
  2171. row["max_altitude"] = windlight.maxAltitude;
  2172. row["sun_moon_color_r"] = windlight.sunMoonColor.X;
  2173. row["sun_moon_color_g"] = windlight.sunMoonColor.Y;
  2174. row["sun_moon_color_b"] = windlight.sunMoonColor.Z;
  2175. row["sun_moon_color_i"] = windlight.sunMoonColor.W;
  2176. row["sun_moon_position"] = windlight.sunMoonPosition;
  2177. row["ambient_r"] = windlight.ambient.X;
  2178. row["ambient_g"] = windlight.ambient.Y;
  2179. row["ambient_b"] = windlight.ambient.Z;
  2180. row["ambient_i"] = windlight.ambient.W;
  2181. row["east_angle"] = windlight.eastAngle;
  2182. row["sun_glow_focus"] = windlight.sunGlowFocus;
  2183. row["sun_glow_size"] = windlight.sunGlowSize;
  2184. row["scene_gamma"] = windlight.sceneGamma;
  2185. row["star_brightness"] = windlight.starBrightness;
  2186. row["cloud_color_r"] = windlight.cloudColor.X;
  2187. row["cloud_color_g"] = windlight.cloudColor.Y;
  2188. row["cloud_color_b"] = windlight.cloudColor.Z;
  2189. row["cloud_color_i"] = windlight.cloudColor.W;
  2190. row["cloud_x"] = windlight.cloudXYDensity.X;
  2191. row["cloud_y"] = windlight.cloudXYDensity.Y;
  2192. row["cloud_density"] = windlight.cloudXYDensity.Z;
  2193. row["cloud_coverage"] = windlight.cloudCoverage;
  2194. row["cloud_scale"] = windlight.cloudScale;
  2195. row["cloud_detail_x"] = windlight.cloudDetailXYDensity.X;
  2196. row["cloud_detail_y"] = windlight.cloudDetailXYDensity.Y;
  2197. row["cloud_detail_density"] = windlight.cloudDetailXYDensity.Z;
  2198. row["cloud_scroll_x"] = windlight.cloudScrollX;
  2199. row["cloud_scroll_x_lock"] = windlight.cloudScrollXLock;
  2200. row["cloud_scroll_y"] = windlight.cloudScrollY;
  2201. row["cloud_scroll_y_lock"] = windlight.cloudScrollYLock;
  2202. row["draw_classic_clouds"] = windlight.drawClassicClouds;
  2203. }
  2204. /// <summary>
  2205. ///
  2206. /// </summary>
  2207. /// <param name="row"></param>
  2208. /// <returns></returns>
  2209. private PrimitiveBaseShape buildShape(DataRow row)
  2210. {
  2211. PrimitiveBaseShape s = new PrimitiveBaseShape();
  2212. s.Scale = new Vector3(
  2213. Convert.ToSingle(row["ScaleX"]),
  2214. Convert.ToSingle(row["ScaleY"]),
  2215. Convert.ToSingle(row["ScaleZ"])
  2216. );
  2217. // paths
  2218. s.PCode = Convert.ToByte(row["PCode"]);
  2219. s.PathBegin = Convert.ToUInt16(row["PathBegin"]);
  2220. s.PathEnd = Convert.ToUInt16(row["PathEnd"]);
  2221. s.PathScaleX = Convert.ToByte(row["PathScaleX"]);
  2222. s.PathScaleY = Convert.ToByte(row["PathScaleY"]);
  2223. s.PathShearX = Convert.ToByte(row["PathShearX"]);
  2224. s.PathShearY = Convert.ToByte(row["PathShearY"]);
  2225. s.PathSkew = Convert.ToSByte(row["PathSkew"]);
  2226. s.PathCurve = Convert.ToByte(row["PathCurve"]);
  2227. s.PathRadiusOffset = Convert.ToSByte(row["PathRadiusOffset"]);
  2228. s.PathRevolutions = Convert.ToByte(row["PathRevolutions"]);
  2229. s.PathTaperX = Convert.ToSByte(row["PathTaperX"]);
  2230. s.PathTaperY = Convert.ToSByte(row["PathTaperY"]);
  2231. s.PathTwist = Convert.ToSByte(row["PathTwist"]);
  2232. s.PathTwistBegin = Convert.ToSByte(row["PathTwistBegin"]);
  2233. // profile
  2234. s.ProfileBegin = Convert.ToUInt16(row["ProfileBegin"]);
  2235. s.ProfileEnd = Convert.ToUInt16(row["ProfileEnd"]);
  2236. s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]);
  2237. s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]);
  2238. s.State = Convert.ToByte(row["State"]);
  2239. s.LastAttachPoint = Convert.ToByte(row["LastAttachPoint"]);
  2240. byte[] textureEntry = (byte[])row["Texture"];
  2241. s.TextureEntry = textureEntry;
  2242. s.ExtraParams = (byte[])row["ExtraParams"];
  2243. if (!(row["Media"] is System.DBNull))
  2244. s.Media = PrimitiveBaseShape.MediaList.FromXml((string)row["Media"]);
  2245. return s;
  2246. }
  2247. /// <summary>
  2248. ///
  2249. /// </summary>
  2250. /// <param name="row"></param>
  2251. /// <param name="prim"></param>
  2252. private static void fillShapeRow(DataRow row, SceneObjectPart prim)
  2253. {
  2254. PrimitiveBaseShape s = prim.Shape;
  2255. row["UUID"] = prim.UUID.ToString();
  2256. // shape is an enum
  2257. row["Shape"] = 0;
  2258. // vectors
  2259. row["ScaleX"] = s.Scale.X;
  2260. row["ScaleY"] = s.Scale.Y;
  2261. row["ScaleZ"] = s.Scale.Z;
  2262. // paths
  2263. row["PCode"] = s.PCode;
  2264. row["PathBegin"] = s.PathBegin;
  2265. row["PathEnd"] = s.PathEnd;
  2266. row["PathScaleX"] = s.PathScaleX;
  2267. row["PathScaleY"] = s.PathScaleY;
  2268. row["PathShearX"] = s.PathShearX;
  2269. row["PathShearY"] = s.PathShearY;
  2270. row["PathSkew"] = s.PathSkew;
  2271. row["PathCurve"] = s.PathCurve;
  2272. row["PathRadiusOffset"] = s.PathRadiusOffset;
  2273. row["PathRevolutions"] = s.PathRevolutions;
  2274. row["PathTaperX"] = s.PathTaperX;
  2275. row["PathTaperY"] = s.PathTaperY;
  2276. row["PathTwist"] = s.PathTwist;
  2277. row["PathTwistBegin"] = s.PathTwistBegin;
  2278. // profile
  2279. row["ProfileBegin"] = s.ProfileBegin;
  2280. row["ProfileEnd"] = s.ProfileEnd;
  2281. row["ProfileCurve"] = s.ProfileCurve;
  2282. row["ProfileHollow"] = s.ProfileHollow;
  2283. row["State"] = s.State;
  2284. row["LastAttachPoint"] = s.LastAttachPoint;
  2285. row["Texture"] = s.TextureEntry;
  2286. row["ExtraParams"] = s.ExtraParams;
  2287. if (s.Media != null)
  2288. row["Media"] = s.Media.ToXml();
  2289. }
  2290. /// <summary>
  2291. /// Persistently store a prim.
  2292. /// </summary>
  2293. /// <param name="prim"></param>
  2294. /// <param name="sceneGroupID"></param>
  2295. /// <param name="regionUUID"></param>
  2296. private void addPrim(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  2297. {
  2298. DataTable prims = ds.Tables["prims"];
  2299. DataTable shapes = ds.Tables["primshapes"];
  2300. DataRow primRow = prims.Rows.Find(prim.UUID.ToString());
  2301. if (primRow == null)
  2302. {
  2303. primRow = prims.NewRow();
  2304. fillPrimRow(primRow, prim, sceneGroupID, regionUUID);
  2305. prims.Rows.Add(primRow);
  2306. }
  2307. else
  2308. {
  2309. fillPrimRow(primRow, prim, sceneGroupID, regionUUID);
  2310. }
  2311. DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
  2312. if (shapeRow == null)
  2313. {
  2314. shapeRow = shapes.NewRow();
  2315. fillShapeRow(shapeRow, prim);
  2316. shapes.Rows.Add(shapeRow);
  2317. }
  2318. else
  2319. {
  2320. fillShapeRow(shapeRow, prim);
  2321. }
  2322. }
  2323. /// <summary>
  2324. /// </summary>
  2325. /// <param name="primID"></param>
  2326. /// <param name="items"></param>
  2327. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  2328. {
  2329. // m_log.DebugFormat("[SQLITE REGION DB]: Entered StorePrimInventory with prim ID {0}", primID);
  2330. DataTable dbItems = ds.Tables["primitems"];
  2331. // For now, we're just going to crudely remove all the previous inventory items
  2332. // no matter whether they have changed or not, and replace them with the current set.
  2333. lock (ds)
  2334. {
  2335. RemoveItems(primID);
  2336. // repalce with current inventory details
  2337. foreach (TaskInventoryItem newItem in items)
  2338. {
  2339. // m_log.InfoFormat(
  2340. // "[DATASTORE]: ",
  2341. // "Adding item {0}, {1} to prim ID {2}",
  2342. // newItem.Name, newItem.ItemID, newItem.ParentPartID);
  2343. DataRow newItemRow = dbItems.NewRow();
  2344. fillItemRow(newItemRow, newItem);
  2345. dbItems.Rows.Add(newItemRow);
  2346. }
  2347. }
  2348. Commit();
  2349. }
  2350. /***********************************************************************
  2351. *
  2352. * SQL Statement Creation Functions
  2353. *
  2354. * These functions create SQL statements for update, insert, and create.
  2355. * They can probably be factored later to have a db independant
  2356. * portion and a db specific portion
  2357. *
  2358. **********************************************************************/
  2359. /// <summary>
  2360. /// Create an insert command
  2361. /// </summary>
  2362. /// <param name="table">table name</param>
  2363. /// <param name="dt">data table</param>
  2364. /// <returns>the created command</returns>
  2365. /// <remarks>
  2366. /// This is subtle enough to deserve some commentary.
  2367. /// Instead of doing *lots* and *lots of hardcoded strings
  2368. /// for database definitions we'll use the fact that
  2369. /// realistically all insert statements look like "insert
  2370. /// into A(b, c) values(:b, :c) on the parameterized query
  2371. /// front. If we just have a list of b, c, etc... we can
  2372. /// generate these strings instead of typing them out.
  2373. /// </remarks>
  2374. private static SqliteCommand createInsertCommand(string table, DataTable dt)
  2375. {
  2376. string[] cols = new string[dt.Columns.Count];
  2377. for (int i = 0; i < dt.Columns.Count; i++)
  2378. {
  2379. DataColumn col = dt.Columns[i];
  2380. cols[i] = col.ColumnName;
  2381. }
  2382. string sql = "insert into " + table + "(";
  2383. sql += String.Join(", ", cols);
  2384. // important, the first ':' needs to be here, the rest get added in the join
  2385. sql += ") values (:";
  2386. sql += String.Join(", :", cols);
  2387. sql += ")";
  2388. // m_log.DebugFormat("[SQLITE]: Created insert command {0}", sql);
  2389. SqliteCommand cmd = new SqliteCommand(sql);
  2390. // this provides the binding for all our parameters, so
  2391. // much less code than it used to be
  2392. foreach (DataColumn col in dt.Columns)
  2393. {
  2394. cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
  2395. }
  2396. return cmd;
  2397. }
  2398. /// <summary>
  2399. /// create an update command
  2400. /// </summary>
  2401. /// <param name="table">table name</param>
  2402. /// <param name="pk"></param>
  2403. /// <param name="dt"></param>
  2404. /// <returns>the created command</returns>
  2405. private static SqliteCommand createUpdateCommand(string table, string pk, DataTable dt)
  2406. {
  2407. string sql = "update " + table + " set ";
  2408. string subsql = String.Empty;
  2409. foreach (DataColumn col in dt.Columns)
  2410. {
  2411. if (subsql.Length > 0)
  2412. {
  2413. // a map function would rock so much here
  2414. subsql += ", ";
  2415. }
  2416. subsql += col.ColumnName + "= :" + col.ColumnName;
  2417. }
  2418. sql += subsql;
  2419. sql += " where " + pk;
  2420. SqliteCommand cmd = new SqliteCommand(sql);
  2421. // this provides the binding for all our parameters, so
  2422. // much less code than it used to be
  2423. foreach (DataColumn col in dt.Columns)
  2424. {
  2425. cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
  2426. }
  2427. return cmd;
  2428. }
  2429. /// <summary>
  2430. /// create an update command
  2431. /// </summary>
  2432. /// <param name="table">table name</param>
  2433. /// <param name="pk"></param>
  2434. /// <param name="dt"></param>
  2435. /// <returns>the created command</returns>
  2436. private static SqliteCommand createUpdateCommand(string table, string pk1, string pk2, DataTable dt)
  2437. {
  2438. string sql = "update " + table + " set ";
  2439. string subsql = String.Empty;
  2440. foreach (DataColumn col in dt.Columns)
  2441. {
  2442. if (subsql.Length > 0)
  2443. {
  2444. // a map function would rock so much here
  2445. subsql += ", ";
  2446. }
  2447. subsql += col.ColumnName + "= :" + col.ColumnName;
  2448. }
  2449. sql += subsql;
  2450. sql += " where " + pk1 + " and " + pk2;
  2451. SqliteCommand cmd = new SqliteCommand(sql);
  2452. // this provides the binding for all our parameters, so
  2453. // much less code than it used to be
  2454. foreach (DataColumn col in dt.Columns)
  2455. {
  2456. cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
  2457. }
  2458. return cmd;
  2459. }
  2460. /// <summary>
  2461. ///
  2462. /// </summary>
  2463. /// <param name="dt">Data Table</param>
  2464. /// <returns></returns>
  2465. // private static string defineTable(DataTable dt)
  2466. // {
  2467. // string sql = "create table " + dt.TableName + "(";
  2468. // string subsql = String.Empty;
  2469. // foreach (DataColumn col in dt.Columns)
  2470. // {
  2471. // if (subsql.Length > 0)
  2472. // {
  2473. // // a map function would rock so much here
  2474. // subsql += ",\n";
  2475. // }
  2476. // subsql += col.ColumnName + " " + sqliteType(col.DataType);
  2477. // if (dt.PrimaryKey.Length > 0 && col == dt.PrimaryKey[0])
  2478. // {
  2479. // subsql += " primary key";
  2480. // }
  2481. // }
  2482. // sql += subsql;
  2483. // sql += ")";
  2484. // return sql;
  2485. // }
  2486. /***********************************************************************
  2487. *
  2488. * Database Binding functions
  2489. *
  2490. * These will be db specific due to typing, and minor differences
  2491. * in databases.
  2492. *
  2493. **********************************************************************/
  2494. ///<summary>
  2495. /// This is a convenience function that collapses 5 repetitive
  2496. /// lines for defining SqliteParameters to 2 parameters:
  2497. /// column name and database type.
  2498. ///
  2499. /// It assumes certain conventions like :param as the param
  2500. /// name to replace in parametrized queries, and that source
  2501. /// version is always current version, both of which are fine
  2502. /// for us.
  2503. ///</summary>
  2504. ///<returns>a built sqlite parameter</returns>
  2505. private static SqliteParameter createSqliteParameter(string name, Type type)
  2506. {
  2507. SqliteParameter param = new SqliteParameter();
  2508. param.ParameterName = ":" + name;
  2509. param.DbType = dbtypeFromType(type);
  2510. param.SourceColumn = name;
  2511. param.SourceVersion = DataRowVersion.Current;
  2512. return param;
  2513. }
  2514. /// <summary>
  2515. ///
  2516. /// </summary>
  2517. /// <param name="da"></param>
  2518. /// <param name="conn"></param>
  2519. private void setupPrimCommands(SqliteDataAdapter da, SqliteConnection conn)
  2520. {
  2521. da.InsertCommand = createInsertCommand("prims", ds.Tables["prims"]);
  2522. da.InsertCommand.Connection = conn;
  2523. da.UpdateCommand = createUpdateCommand("prims", "UUID=:UUID", ds.Tables["prims"]);
  2524. da.UpdateCommand.Connection = conn;
  2525. SqliteCommand delete = new SqliteCommand("delete from prims where UUID = :UUID");
  2526. delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
  2527. delete.Connection = conn;
  2528. da.DeleteCommand = delete;
  2529. }
  2530. /// <summary>
  2531. ///
  2532. /// </summary>
  2533. /// <param name="da"></param>
  2534. /// <param name="conn"></param>
  2535. private void setupItemsCommands(SqliteDataAdapter da, SqliteConnection conn)
  2536. {
  2537. da.InsertCommand = createInsertCommand("primitems", ds.Tables["primitems"]);
  2538. da.InsertCommand.Connection = conn;
  2539. da.UpdateCommand = createUpdateCommand("primitems", "itemID = :itemID", ds.Tables["primitems"]);
  2540. da.UpdateCommand.Connection = conn;
  2541. SqliteCommand delete = new SqliteCommand("delete from primitems where itemID = :itemID");
  2542. delete.Parameters.Add(createSqliteParameter("itemID", typeof(String)));
  2543. delete.Connection = conn;
  2544. da.DeleteCommand = delete;
  2545. }
  2546. /// <summary>
  2547. ///
  2548. /// </summary>
  2549. /// <param name="da"></param>
  2550. /// <param name="conn"></param>
  2551. private void setupTerrainCommands(SqliteDataAdapter da, SqliteConnection conn)
  2552. {
  2553. da.InsertCommand = createInsertCommand("terrain", ds.Tables["terrain"]);
  2554. da.InsertCommand.Connection = conn;
  2555. }
  2556. /// <summary>
  2557. ///
  2558. /// </summary>
  2559. /// <param name="da"></param>
  2560. /// <param name="conn"></param>
  2561. private void setupLandCommands(SqliteDataAdapter da, SqliteConnection conn)
  2562. {
  2563. da.InsertCommand = createInsertCommand("land", ds.Tables["land"]);
  2564. da.InsertCommand.Connection = conn;
  2565. da.UpdateCommand = createUpdateCommand("land", "UUID=:UUID", ds.Tables["land"]);
  2566. da.UpdateCommand.Connection = conn;
  2567. SqliteCommand delete = new SqliteCommand("delete from land where UUID=:UUID");
  2568. delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
  2569. da.DeleteCommand = delete;
  2570. da.DeleteCommand.Connection = conn;
  2571. }
  2572. /// <summary>
  2573. ///
  2574. /// </summary>
  2575. /// <param name="da"></param>
  2576. /// <param name="conn"></param>
  2577. private void setupLandAccessCommands(SqliteDataAdapter da, SqliteConnection conn)
  2578. {
  2579. da.InsertCommand = createInsertCommand("landaccesslist", ds.Tables["landaccesslist"]);
  2580. da.InsertCommand.Connection = conn;
  2581. da.UpdateCommand = createUpdateCommand("landaccesslist", "LandUUID=:landUUID", "AccessUUID=:AccessUUID", ds.Tables["landaccesslist"]);
  2582. da.UpdateCommand.Connection = conn;
  2583. SqliteCommand delete = new SqliteCommand("delete from landaccesslist where LandUUID= :LandUUID and AccessUUID= :AccessUUID");
  2584. delete.Parameters.Add(createSqliteParameter("LandUUID", typeof(String)));
  2585. delete.Parameters.Add(createSqliteParameter("AccessUUID", typeof(String)));
  2586. da.DeleteCommand = delete;
  2587. da.DeleteCommand.Connection = conn;
  2588. }
  2589. private void setupRegionSettingsCommands(SqliteDataAdapter da, SqliteConnection conn)
  2590. {
  2591. da.InsertCommand = createInsertCommand("regionsettings", ds.Tables["regionsettings"]);
  2592. da.InsertCommand.Connection = conn;
  2593. da.UpdateCommand = createUpdateCommand("regionsettings", "regionUUID=:regionUUID", ds.Tables["regionsettings"]);
  2594. da.UpdateCommand.Connection = conn;
  2595. }
  2596. /// <summary>
  2597. ///
  2598. /// </summary>
  2599. /// <param name="da"></param>
  2600. /// <param name="conn"></param>
  2601. private void setupRegionWindlightCommands(SqliteDataAdapter da, SqliteConnection conn)
  2602. {
  2603. da.InsertCommand = createInsertCommand("regionwindlight", ds.Tables["regionwindlight"]);
  2604. da.InsertCommand.Connection = conn;
  2605. da.UpdateCommand = createUpdateCommand("regionwindlight", "region_id=:region_id", ds.Tables["regionwindlight"]);
  2606. da.UpdateCommand.Connection = conn;
  2607. }
  2608. private void setupRegionEnvironmentCommands(SqliteDataAdapter da, SqliteConnection conn)
  2609. {
  2610. da.InsertCommand = createInsertCommand("regionenvironment", ds.Tables["regionenvironment"]);
  2611. da.InsertCommand.Connection = conn;
  2612. da.UpdateCommand = createUpdateCommand("regionenvironment", "region_id=:region_id", ds.Tables["regionenvironment"]);
  2613. da.UpdateCommand.Connection = conn;
  2614. }
  2615. private void setupRegionSpawnPointsCommands(SqliteDataAdapter da, SqliteConnection conn)
  2616. {
  2617. da.InsertCommand = createInsertCommand("spawn_points", ds.Tables["spawn_points"]);
  2618. da.InsertCommand.Connection = conn;
  2619. da.UpdateCommand = createUpdateCommand("spawn_points", "RegionID=:RegionID", ds.Tables["spawn_points"]);
  2620. da.UpdateCommand.Connection = conn;
  2621. }
  2622. /// <summary>
  2623. ///
  2624. /// </summary>
  2625. /// <param name="da"></param>
  2626. /// <param name="conn"></param>
  2627. private void setupShapeCommands(SqliteDataAdapter da, SqliteConnection conn)
  2628. {
  2629. da.InsertCommand = createInsertCommand("primshapes", ds.Tables["primshapes"]);
  2630. da.InsertCommand.Connection = conn;
  2631. da.UpdateCommand = createUpdateCommand("primshapes", "UUID=:UUID", ds.Tables["primshapes"]);
  2632. da.UpdateCommand.Connection = conn;
  2633. SqliteCommand delete = new SqliteCommand("delete from primshapes where UUID = :UUID");
  2634. delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
  2635. delete.Connection = conn;
  2636. da.DeleteCommand = delete;
  2637. }
  2638. /***********************************************************************
  2639. *
  2640. * Type conversion functions
  2641. *
  2642. **********************************************************************/
  2643. /// <summary>
  2644. /// Type conversion function
  2645. /// </summary>
  2646. /// <param name="type"></param>
  2647. /// <returns></returns>
  2648. private static DbType dbtypeFromType(Type type)
  2649. {
  2650. if (type == typeof(String))
  2651. {
  2652. return DbType.String;
  2653. }
  2654. else if (type == typeof(Int32))
  2655. {
  2656. return DbType.Int32;
  2657. }
  2658. else if (type == typeof(Double))
  2659. {
  2660. return DbType.Double;
  2661. }
  2662. else if (type == typeof(Byte))
  2663. {
  2664. return DbType.Byte;
  2665. }
  2666. else if (type == typeof(Double))
  2667. {
  2668. return DbType.Double;
  2669. }
  2670. else if (type == typeof(Byte[]))
  2671. {
  2672. return DbType.Binary;
  2673. }
  2674. else if (type == typeof(Boolean))
  2675. {
  2676. return DbType.Boolean;
  2677. }
  2678. else
  2679. {
  2680. return DbType.String;
  2681. }
  2682. }
  2683. static void PrintDataSet(DataSet ds)
  2684. {
  2685. // Print out any name and extended properties.
  2686. Console.WriteLine("DataSet is named: {0}", ds.DataSetName);
  2687. foreach (System.Collections.DictionaryEntry de in ds.ExtendedProperties)
  2688. {
  2689. Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
  2690. }
  2691. Console.WriteLine();
  2692. foreach (DataTable dt in ds.Tables)
  2693. {
  2694. Console.WriteLine("=> {0} Table:", dt.TableName);
  2695. // Print out the column names.
  2696. for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
  2697. {
  2698. Console.Write(dt.Columns[curCol].ColumnName + "\t");
  2699. }
  2700. Console.WriteLine("\n----------------------------------");
  2701. // Print the DataTable.
  2702. for (int curRow = 0; curRow < dt.Rows.Count; curRow++)
  2703. {
  2704. for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
  2705. {
  2706. Console.Write(dt.Rows[curRow][curCol].ToString() + "\t");
  2707. }
  2708. Console.WriteLine();
  2709. }
  2710. }
  2711. }
  2712. public UUID[] GetObjectIDs(UUID regionID)
  2713. {
  2714. return new UUID[0];
  2715. }
  2716. public void SaveExtra(UUID regionID, string name, string value)
  2717. {
  2718. }
  2719. public void RemoveExtra(UUID regionID, string name)
  2720. {
  2721. }
  2722. public Dictionary<string, string> GetExtra(UUID regionID)
  2723. {
  2724. return null;
  2725. }
  2726. }
  2727. }