aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/SQLiteNG/SQLiteRegionData.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2010-04-23 18:56:50 +0100
committerJustin Clark-Casey (justincc)2010-04-23 18:56:50 +0100
commite84cc2f9db9e03a45f9fa315cf598dd5ef83b7ef (patch)
tree4c07c2f614640afd4dfc3a1bf2594ad369837908 /OpenSim/Data/SQLiteNG/SQLiteRegionData.cs
parentDuplicate OpenSim.Data.SQLite into OpenSim.Data.SQLiteNG. SQLiteNG will shor... (diff)
downloadopensim-SC-e84cc2f9db9e03a45f9fa315cf598dd5ef83b7ef.zip
opensim-SC-e84cc2f9db9e03a45f9fa315cf598dd5ef83b7ef.tar.gz
opensim-SC-e84cc2f9db9e03a45f9fa315cf598dd5ef83b7ef.tar.bz2
opensim-SC-e84cc2f9db9e03a45f9fa315cf598dd5ef83b7ef.tar.xz
Change SQLiteNG to work with mono 2.6 and above using the Mono.Data.Sqlite.dll
Include the library so that Windows builds correctly It appears that Windows is okay with either SQLite or SQLiteNG Incorporate the latest fixes made by Diva to OpenSim.Data.SQLite
Diffstat (limited to 'OpenSim/Data/SQLiteNG/SQLiteRegionData.cs')
-rw-r--r--OpenSim/Data/SQLiteNG/SQLiteRegionData.cs258
1 files changed, 156 insertions, 102 deletions
diff --git a/OpenSim/Data/SQLiteNG/SQLiteRegionData.cs b/OpenSim/Data/SQLiteNG/SQLiteRegionData.cs
index d2ba9ae..bad8adc 100644
--- a/OpenSim/Data/SQLiteNG/SQLiteRegionData.cs
+++ b/OpenSim/Data/SQLiteNG/SQLiteRegionData.cs
@@ -32,7 +32,7 @@ using System.Drawing;
32using System.IO; 32using System.IO;
33using System.Reflection; 33using System.Reflection;
34using log4net; 34using log4net;
35using Mono.Data.SqliteClient; 35using Mono.Data.Sqlite;
36using OpenMetaverse; 36using OpenMetaverse;
37using OpenSim.Framework; 37using OpenSim.Framework;
38using OpenSim.Region.Framework.Interfaces; 38using OpenSim.Region.Framework.Interfaces;
@@ -87,119 +87,139 @@ namespace OpenSim.Data.SQLite
87 /// <param name="connectionString">the connection string</param> 87 /// <param name="connectionString">the connection string</param>
88 public void Initialise(string connectionString) 88 public void Initialise(string connectionString)
89 { 89 {
90 m_connectionString = connectionString; 90 try
91 {
92 m_connectionString = connectionString;
91 93
92 ds = new DataSet(); 94 ds = new DataSet("Region");
93 95
94 m_log.Info("[REGION DB]: Sqlite - connecting: " + connectionString); 96 m_log.Info("[REGION DB]: Sqlite - connecting: " + connectionString);
95 m_conn = new SqliteConnection(m_connectionString); 97 m_conn = new SqliteConnection(m_connectionString);
96 m_conn.Open(); 98 m_conn.Open();
97 99
100 SqliteCommand primSelectCmd = new SqliteCommand(primSelect, m_conn);
101 //SqliteCommand primSelectCmd = new SqliteCommand(primSelect, m_conn);
102 //primDa = new SqliteDataAdapter(primSelectCmd);
103 primDa = new SqliteDataAdapter(primSelect, m_connectionString);
104 // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa);
98 105
106 SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, m_conn);
107 shapeDa = new SqliteDataAdapter(shapeSelectCmd);
108 // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa);
99 109
100 SqliteCommand primSelectCmd = new SqliteCommand(primSelect, m_conn); 110 SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, m_conn);
101 primDa = new SqliteDataAdapter(primSelectCmd); 111 itemsDa = new SqliteDataAdapter(itemsSelectCmd);
102 // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa);
103 112
104 SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, m_conn); 113 SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, m_conn);
105 shapeDa = new SqliteDataAdapter(shapeSelectCmd); 114 terrainDa = new SqliteDataAdapter(terrainSelectCmd);
106 // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa);
107 115
108 SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, m_conn); 116 SqliteCommand landSelectCmd = new SqliteCommand(landSelect, m_conn);
109 itemsDa = new SqliteDataAdapter(itemsSelectCmd); 117 landDa = new SqliteDataAdapter(landSelectCmd);
110 118
111 SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, m_conn); 119 SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn);
112 terrainDa = new SqliteDataAdapter(terrainSelectCmd); 120 landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd);
113 121
114 SqliteCommand landSelectCmd = new SqliteCommand(landSelect, m_conn); 122 SqliteCommand regionSettingsSelectCmd = new SqliteCommand(regionSettingsSelect, m_conn);
115 landDa = new SqliteDataAdapter(landSelectCmd); 123 regionSettingsDa = new SqliteDataAdapter(regionSettingsSelectCmd);
124 // This actually does the roll forward assembly stuff
125 Assembly assem = GetType().Assembly;
126 Migration m = new Migration(m_conn, assem, "RegionStore");
127 m.Update();
116 128
117 SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn); 129 lock (ds)
118 landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd); 130 {
131 //ds.Tables.Add(createPrimTable());
132 //setupPrimCommands(primDa, m_conn);
133 //primDa.Fill(ds.Tables["prims"]);
134 primDa.Fill(ds, "prims");
119 135
120 SqliteCommand regionSettingsSelectCmd = new SqliteCommand(regionSettingsSelect, m_conn); 136 ds.Tables.Add(createShapeTable());
121 regionSettingsDa = new SqliteDataAdapter(regionSettingsSelectCmd); 137 setupShapeCommands(shapeDa, m_conn);
122 // This actually does the roll forward assembly stuff
123 Assembly assem = GetType().Assembly;
124 Migration m = new Migration(m_conn, assem, "RegionStore");
125 m.Update();
126 138
127 lock (ds) 139 ds.Tables.Add(createItemsTable());
128 { 140 setupItemsCommands(itemsDa, m_conn);
129 ds.Tables.Add(createPrimTable()); 141 itemsDa.Fill(ds.Tables["primitems"]);
130 setupPrimCommands(primDa, m_conn);
131 primDa.Fill(ds.Tables["prims"]);
132 142
133 ds.Tables.Add(createShapeTable()); 143 ds.Tables.Add(createTerrainTable());
134 setupShapeCommands(shapeDa, m_conn); 144 setupTerrainCommands(terrainDa, m_conn);
135 145
136 ds.Tables.Add(createItemsTable()); 146 ds.Tables.Add(createLandTable());
137 setupItemsCommands(itemsDa, m_conn); 147 setupLandCommands(landDa, m_conn);
138 itemsDa.Fill(ds.Tables["primitems"]);
139 148
140 ds.Tables.Add(createTerrainTable()); 149 ds.Tables.Add(createLandAccessListTable());
141 setupTerrainCommands(terrainDa, m_conn); 150 setupLandAccessCommands(landAccessListDa, m_conn);
142 151
143 ds.Tables.Add(createLandTable()); 152 ds.Tables.Add(createRegionSettingsTable());
144 setupLandCommands(landDa, m_conn); 153
154 setupRegionSettingsCommands(regionSettingsDa, m_conn);
145 155
146 ds.Tables.Add(createLandAccessListTable()); 156 // WORKAROUND: This is a work around for sqlite on
147 setupLandAccessCommands(landAccessListDa, m_conn); 157 // windows, which gets really unhappy with blob columns
148 158 // that have no sample data in them. At some point we
149 ds.Tables.Add(createRegionSettingsTable()); 159 // need to actually find a proper way to handle this.
150 160 try
151 setupRegionSettingsCommands(regionSettingsDa, m_conn); 161 {
162 shapeDa.Fill(ds.Tables["primshapes"]);
163 }
164 catch (Exception)
165 {
166 m_log.Info("[REGION DB]: Caught fill error on primshapes table");
167 }
152 168
153 // WORKAROUND: This is a work around for sqlite on 169 try
154 // windows, which gets really unhappy with blob columns 170 {
155 // that have no sample data in them. At some point we 171 terrainDa.Fill(ds.Tables["terrain"]);
156 // need to actually find a proper way to handle this. 172 }
157 try 173 catch (Exception)
158 { 174 {
159 shapeDa.Fill(ds.Tables["primshapes"]); 175 m_log.Info("[REGION DB]: Caught fill error on terrain table");
160 } 176 }
161 catch (Exception)
162 {
163 m_log.Info("[REGION DB]: Caught fill error on primshapes table");
164 }
165 177
166 try 178 try
167 { 179 {
168 terrainDa.Fill(ds.Tables["terrain"]); 180 landDa.Fill(ds.Tables["land"]);
169 } 181 }
170 catch (Exception) 182 catch (Exception)
171 { 183 {
172 m_log.Info("[REGION DB]: Caught fill error on terrain table"); 184 m_log.Info("[REGION DB]: Caught fill error on land table");
173 } 185 }
174 186
175 try 187 try
176 { 188 {
177 landDa.Fill(ds.Tables["land"]); 189 landAccessListDa.Fill(ds.Tables["landaccesslist"]);
178 } 190 }
179 catch (Exception) 191 catch (Exception)
180 { 192 {
181 m_log.Info("[REGION DB]: Caught fill error on land table"); 193 m_log.Info("[REGION DB]: Caught fill error on landaccesslist table");
182 } 194 }
183 195
184 try 196 try
185 { 197 {
186 landAccessListDa.Fill(ds.Tables["landaccesslist"]); 198 regionSettingsDa.Fill(ds.Tables["regionsettings"]);
187 } 199 }
188 catch (Exception) 200 catch (Exception)
189 { 201 {
190 m_log.Info("[REGION DB]: Caught fill error on landaccesslist table"); 202 m_log.Info("[REGION DB]: Caught fill error on regionsettings table");
191 } 203 }
192 204
193 try 205 // We have to create a data set mapping for every table, otherwise the IDataAdaptor.Update() will not populate rows with values!
194 { 206 // Not sure exactly why this is - this kind of thing was not necessary before - justincc 20100409
195 regionSettingsDa.Fill(ds.Tables["regionsettings"]); 207 CreateDataSetMapping(primDa, "prims");
208 CreateDataSetMapping(shapeDa, "primshapes");
209 CreateDataSetMapping(itemsDa, "primitems");
210 CreateDataSetMapping(terrainDa, "terrain");
211 CreateDataSetMapping(landDa, "land");
212 CreateDataSetMapping(landAccessListDa, "landaccesslist");
213 CreateDataSetMapping(regionSettingsDa, "regionsettings");
196 } 214 }
197 catch (Exception)
198 {
199 m_log.Info("[REGION DB]: Caught fill error on regionsettings table");
200 }
201 return;
202 } 215 }
216 catch (Exception e)
217 {
218 m_log.Error(e);
219 Environment.Exit(23);
220 }
221
222 return;
203 } 223 }
204 224
205 public void Dispose() 225 public void Dispose()
@@ -603,7 +623,7 @@ namespace OpenSim.Data.SQLite
603 } 623 }
604 } 624 }
605 } 625 }
606 rev = (int) row["Revision"]; 626 rev = Convert.ToInt32(row["Revision"]);
607 } 627 }
608 else 628 else
609 { 629 {
@@ -755,6 +775,7 @@ namespace OpenSim.Data.SQLite
755 /// </summary> 775 /// </summary>
756 public void Commit() 776 public void Commit()
757 { 777 {
778 m_log.Debug("[SQLITE]: Starting commit");
758 lock (ds) 779 lock (ds)
759 { 780 {
760 primDa.Update(ds, "prims"); 781 primDa.Update(ds, "prims");
@@ -769,18 +790,11 @@ namespace OpenSim.Data.SQLite
769 { 790 {
770 regionSettingsDa.Update(ds, "regionsettings"); 791 regionSettingsDa.Update(ds, "regionsettings");
771 } 792 }
772 catch (SqliteExecutionException SqlEx) 793 catch (SqliteException SqlEx)
773 { 794 {
774 if (SqlEx.Message.Contains("logic error")) 795 throw new Exception(
775 { 796 "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!",
776 throw new Exception( 797 SqlEx);
777 "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!",
778 SqlEx);
779 }
780 else
781 {
782 throw SqlEx;
783 }
784 } 798 }
785 ds.AcceptChanges(); 799 ds.AcceptChanges();
786 } 800 }
@@ -802,6 +816,15 @@ namespace OpenSim.Data.SQLite
802 * 816 *
803 **********************************************************************/ 817 **********************************************************************/
804 818
819 protected void CreateDataSetMapping(IDataAdapter da, string tableName)
820 {
821 ITableMapping dbMapping = da.TableMappings.Add(tableName, tableName);
822 foreach (DataColumn col in ds.Tables[tableName].Columns)
823 {
824 dbMapping.ColumnMappings.Add(col.ColumnName, col.ColumnName);
825 }
826 }
827
805 /// <summary> 828 /// <summary>
806 /// 829 ///
807 /// </summary> 830 /// </summary>
@@ -1964,6 +1987,7 @@ namespace OpenSim.Data.SQLite
1964 sql += ") values (:"; 1987 sql += ") values (:";
1965 sql += String.Join(", :", cols); 1988 sql += String.Join(", :", cols);
1966 sql += ")"; 1989 sql += ")";
1990 m_log.DebugFormat("[SQLITE]: Created insert command {0}", sql);
1967 SqliteCommand cmd = new SqliteCommand(sql); 1991 SqliteCommand cmd = new SqliteCommand(sql);
1968 1992
1969 // this provides the binding for all our parameters, so 1993 // this provides the binding for all our parameters, so
@@ -2259,6 +2283,36 @@ namespace OpenSim.Data.SQLite
2259 return DbType.String; 2283 return DbType.String;
2260 } 2284 }
2261 } 2285 }
2286
2287 static void PrintDataSet(DataSet ds)
2288 {
2289 // Print out any name and extended properties.
2290 Console.WriteLine("DataSet is named: {0}", ds.DataSetName);
2291 foreach (System.Collections.DictionaryEntry de in ds.ExtendedProperties)
2292 {
2293 Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
2294 }
2295 Console.WriteLine();
2296 foreach (DataTable dt in ds.Tables)
2297 {
2298 Console.WriteLine("=> {0} Table:", dt.TableName);
2299 // Print out the column names.
2300 for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
2301 {
2302 Console.Write(dt.Columns[curCol].ColumnName + "\t");
2303 }
2304 Console.WriteLine("\n----------------------------------");
2305 // Print the DataTable.
2306 for (int curRow = 0; curRow < dt.Rows.Count; curRow++)
2307 {
2308 for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
2309 {
2310 Console.Write(dt.Rows[curRow][curCol].ToString() + "\t");
2311 }
2312 Console.WriteLine();
2313 }
2314 }
2315 }
2262 2316
2263 } 2317 }
2264} 2318}