diff options
author | Jeff Ames | 2007-11-17 08:39:59 +0000 |
---|---|---|
committer | Jeff Ames | 2007-11-17 08:39:59 +0000 |
commit | 6ad471abc025a951e8db66a356cbd15b4fabe0c8 (patch) | |
tree | 76e88cfc7405f05ff7502b37f11b0e4e76d6b207 /OpenSim | |
parent | minor cleanup of some dodgy bits (diff) | |
download | opensim-SC-6ad471abc025a951e8db66a356cbd15b4fabe0c8.zip opensim-SC-6ad471abc025a951e8db66a356cbd15b4fabe0c8.tar.gz opensim-SC-6ad471abc025a951e8db66a356cbd15b4fabe0c8.tar.bz2 opensim-SC-6ad471abc025a951e8db66a356cbd15b4fabe0c8.tar.xz |
set svn:eol-style
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Framework/Data.MySQL/MySQLDataStore.cs | 2030 |
1 files changed, 1015 insertions, 1015 deletions
diff --git a/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs b/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs index 343970e..60ffaa3 100644 --- a/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs +++ b/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs | |||
@@ -1,1015 +1,1015 @@ | |||
1 | using System; | 1 | using System; |
2 | using System.Collections.Generic; | 2 | using System.Collections.Generic; |
3 | using System.Data; | 3 | using System.Data; |
4 | using System.Diagnostics; | 4 | using System.Diagnostics; |
5 | using System.IO; | 5 | using System.IO; |
6 | using System.Text; | 6 | using System.Text; |
7 | using libsecondlife; | 7 | using libsecondlife; |
8 | using MySql.Data.MySqlClient; | 8 | using MySql.Data.MySqlClient; |
9 | using OpenSim.Framework.Console; | 9 | using OpenSim.Framework.Console; |
10 | using OpenSim.Region.Environment.Interfaces; | 10 | using OpenSim.Region.Environment.Interfaces; |
11 | using OpenSim.Region.Environment.LandManagement; | 11 | using OpenSim.Region.Environment.LandManagement; |
12 | using OpenSim.Region.Environment.Scenes; | 12 | using OpenSim.Region.Environment.Scenes; |
13 | using System.Data.SqlClient; | 13 | using System.Data.SqlClient; |
14 | using System.Data.Common; | 14 | using System.Data.Common; |
15 | 15 | ||
16 | namespace OpenSim.Framework.Data.MySQL | 16 | namespace OpenSim.Framework.Data.MySQL |
17 | { | 17 | { |
18 | public class MySQLDataStore : IRegionDataStore | 18 | public class MySQLDataStore : IRegionDataStore |
19 | { | 19 | { |
20 | private const string m_primSelect = "select * from prims"; | 20 | private const string m_primSelect = "select * from prims"; |
21 | private const string m_shapeSelect = "select * from primshapes"; | 21 | private const string m_shapeSelect = "select * from primshapes"; |
22 | private const string m_terrainSelect = "select * from terrain limit 1"; | 22 | private const string m_terrainSelect = "select * from terrain limit 1"; |
23 | 23 | ||
24 | private DataSet m_dataSet; | 24 | private DataSet m_dataSet; |
25 | private MySqlDataAdapter m_primDataAdapter; | 25 | private MySqlDataAdapter m_primDataAdapter; |
26 | private MySqlDataAdapter m_shapeDataAdapter; | 26 | private MySqlDataAdapter m_shapeDataAdapter; |
27 | private MySqlConnection m_connection; | 27 | private MySqlConnection m_connection; |
28 | private MySqlDataAdapter m_terrainDataAdapter; | 28 | private MySqlDataAdapter m_terrainDataAdapter; |
29 | private DataTable m_primTable; | 29 | private DataTable m_primTable; |
30 | private DataTable m_shapeTable; | 30 | private DataTable m_shapeTable; |
31 | private DataTable m_terrainTable; | 31 | private DataTable m_terrainTable; |
32 | 32 | ||
33 | /*********************************************************************** | 33 | /*********************************************************************** |
34 | * | 34 | * |
35 | * Public Interface Functions | 35 | * Public Interface Functions |
36 | * | 36 | * |
37 | **********************************************************************/ | 37 | **********************************************************************/ |
38 | 38 | ||
39 | public void Initialise(string connectionstring) | 39 | public void Initialise(string connectionstring) |
40 | { | 40 | { |
41 | m_dataSet = new DataSet(); | 41 | m_dataSet = new DataSet(); |
42 | 42 | ||
43 | MainLog.Instance.Verbose("DATASTORE", "MySql - connecting: " + connectionstring); | 43 | MainLog.Instance.Verbose("DATASTORE", "MySql - connecting: " + connectionstring); |
44 | m_connection = new MySqlConnection(connectionstring); | 44 | m_connection = new MySqlConnection(connectionstring); |
45 | 45 | ||
46 | MySqlCommand primSelectCmd = new MySqlCommand(m_primSelect, m_connection); | 46 | MySqlCommand primSelectCmd = new MySqlCommand(m_primSelect, m_connection); |
47 | m_primDataAdapter = new MySqlDataAdapter(primSelectCmd); | 47 | m_primDataAdapter = new MySqlDataAdapter(primSelectCmd); |
48 | 48 | ||
49 | MySqlCommand shapeSelectCmd = new MySqlCommand(m_shapeSelect, m_connection); | 49 | MySqlCommand shapeSelectCmd = new MySqlCommand(m_shapeSelect, m_connection); |
50 | m_shapeDataAdapter = new MySqlDataAdapter(shapeSelectCmd); | 50 | m_shapeDataAdapter = new MySqlDataAdapter(shapeSelectCmd); |
51 | 51 | ||
52 | MySqlCommand terrainSelectCmd = new MySqlCommand(m_terrainSelect, m_connection); | 52 | MySqlCommand terrainSelectCmd = new MySqlCommand(m_terrainSelect, m_connection); |
53 | m_terrainDataAdapter = new MySqlDataAdapter(terrainSelectCmd); | 53 | m_terrainDataAdapter = new MySqlDataAdapter(terrainSelectCmd); |
54 | 54 | ||
55 | TestTables(m_connection); | 55 | TestTables(m_connection); |
56 | 56 | ||
57 | lock (m_dataSet) | 57 | lock (m_dataSet) |
58 | { | 58 | { |
59 | m_primTable = createPrimTable(); | 59 | m_primTable = createPrimTable(); |
60 | m_dataSet.Tables.Add(m_primTable); | 60 | m_dataSet.Tables.Add(m_primTable); |
61 | SetupPrimCommands(m_primDataAdapter, m_connection); | 61 | SetupPrimCommands(m_primDataAdapter, m_connection); |
62 | m_primDataAdapter.Fill(m_primTable); | 62 | m_primDataAdapter.Fill(m_primTable); |
63 | 63 | ||
64 | m_shapeTable = createShapeTable(); | 64 | m_shapeTable = createShapeTable(); |
65 | m_dataSet.Tables.Add(m_shapeTable); | 65 | m_dataSet.Tables.Add(m_shapeTable); |
66 | SetupShapeCommands(m_shapeDataAdapter, m_connection); | 66 | SetupShapeCommands(m_shapeDataAdapter, m_connection); |
67 | m_shapeDataAdapter.Fill(m_shapeTable); | 67 | m_shapeDataAdapter.Fill(m_shapeTable); |
68 | 68 | ||
69 | m_terrainTable = createTerrainTable(); | 69 | m_terrainTable = createTerrainTable(); |
70 | m_dataSet.Tables.Add(m_terrainTable); | 70 | m_dataSet.Tables.Add(m_terrainTable); |
71 | SetupTerrainCommands(m_terrainDataAdapter, m_connection); | 71 | SetupTerrainCommands(m_terrainDataAdapter, m_connection); |
72 | m_terrainDataAdapter.Fill(m_terrainTable); | 72 | m_terrainDataAdapter.Fill(m_terrainTable); |
73 | } | 73 | } |
74 | } | 74 | } |
75 | 75 | ||
76 | public void StoreObject(SceneObjectGroup obj, LLUUID regionUUID) | 76 | public void StoreObject(SceneObjectGroup obj, LLUUID regionUUID) |
77 | { | 77 | { |
78 | lock (m_dataSet) | 78 | lock (m_dataSet) |
79 | { | 79 | { |
80 | foreach (SceneObjectPart prim in obj.Children.Values) | 80 | foreach (SceneObjectPart prim in obj.Children.Values) |
81 | { | 81 | { |
82 | if ((prim.ObjectFlags & (uint)LLObject.ObjectFlags.Physics) == 0) | 82 | if ((prim.ObjectFlags & (uint)LLObject.ObjectFlags.Physics) == 0) |
83 | { | 83 | { |
84 | MainLog.Instance.Verbose("DATASTORE", "Adding obj: " + obj.UUID + " to region: " + regionUUID); | 84 | MainLog.Instance.Verbose("DATASTORE", "Adding obj: " + obj.UUID + " to region: " + regionUUID); |
85 | addPrim(prim, obj.UUID, regionUUID); | 85 | addPrim(prim, obj.UUID, regionUUID); |
86 | } | 86 | } |
87 | else | 87 | else |
88 | { | 88 | { |
89 | // MainLog.Instance.Verbose("DATASTORE", "Ignoring Physical obj: " + obj.UUID + " in region: " + regionUUID); | 89 | // MainLog.Instance.Verbose("DATASTORE", "Ignoring Physical obj: " + obj.UUID + " in region: " + regionUUID); |
90 | } | 90 | } |
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | Commit(); | 94 | Commit(); |
95 | } | 95 | } |
96 | 96 | ||
97 | public void RemoveObject(LLUUID obj, LLUUID regionUUID) | 97 | public void RemoveObject(LLUUID obj, LLUUID regionUUID) |
98 | { | 98 | { |
99 | DataTable prims = m_primTable; | 99 | DataTable prims = m_primTable; |
100 | DataTable shapes = m_shapeTable; | 100 | DataTable shapes = m_shapeTable; |
101 | 101 | ||
102 | string selectExp = "SceneGroupID = '" + obj.ToString() + "'"; | 102 | string selectExp = "SceneGroupID = '" + obj.ToString() + "'"; |
103 | lock (m_dataSet) | 103 | lock (m_dataSet) |
104 | { | 104 | { |
105 | DataRow[] primRows = prims.Select(selectExp); | 105 | DataRow[] primRows = prims.Select(selectExp); |
106 | foreach (DataRow row in primRows) | 106 | foreach (DataRow row in primRows) |
107 | { | 107 | { |
108 | LLUUID uuid = new LLUUID((string)row["UUID"]); | 108 | LLUUID uuid = new LLUUID((string)row["UUID"]); |
109 | DataRow shapeRow = shapes.Rows.Find(uuid); | 109 | DataRow shapeRow = shapes.Rows.Find(uuid); |
110 | if (shapeRow != null) | 110 | if (shapeRow != null) |
111 | { | 111 | { |
112 | shapeRow.Delete(); | 112 | shapeRow.Delete(); |
113 | } | 113 | } |
114 | row.Delete(); | 114 | row.Delete(); |
115 | } | 115 | } |
116 | } | 116 | } |
117 | 117 | ||
118 | Commit(); | 118 | Commit(); |
119 | } | 119 | } |
120 | 120 | ||
121 | public List<SceneObjectGroup> LoadObjects(LLUUID regionUUID) | 121 | public List<SceneObjectGroup> LoadObjects(LLUUID regionUUID) |
122 | { | 122 | { |
123 | Dictionary<LLUUID, SceneObjectGroup> createdObjects = new Dictionary<LLUUID, SceneObjectGroup>(); | 123 | Dictionary<LLUUID, SceneObjectGroup> createdObjects = new Dictionary<LLUUID, SceneObjectGroup>(); |
124 | 124 | ||
125 | List<SceneObjectGroup> retvals = new List<SceneObjectGroup>(); | 125 | List<SceneObjectGroup> retvals = new List<SceneObjectGroup>(); |
126 | 126 | ||
127 | DataTable prims = m_primTable; | 127 | DataTable prims = m_primTable; |
128 | DataTable shapes = m_shapeTable; | 128 | DataTable shapes = m_shapeTable; |
129 | 129 | ||
130 | string byRegion = "RegionUUID = '" + regionUUID.ToString() + "'"; | 130 | string byRegion = "RegionUUID = '" + regionUUID.ToString() + "'"; |
131 | string orderByParent = "ParentID ASC"; | 131 | string orderByParent = "ParentID ASC"; |
132 | 132 | ||
133 | lock (m_dataSet) | 133 | lock (m_dataSet) |
134 | { | 134 | { |
135 | DataRow[] primsForRegion = prims.Select(byRegion, orderByParent); | 135 | DataRow[] primsForRegion = prims.Select(byRegion, orderByParent); |
136 | MainLog.Instance.Verbose("DATASTORE", | 136 | MainLog.Instance.Verbose("DATASTORE", |
137 | "Loaded " + primsForRegion.Length + " prims for region: " + regionUUID); | 137 | "Loaded " + primsForRegion.Length + " prims for region: " + regionUUID); |
138 | 138 | ||
139 | foreach (DataRow primRow in primsForRegion) | 139 | foreach (DataRow primRow in primsForRegion) |
140 | { | 140 | { |
141 | try | 141 | try |
142 | { | 142 | { |
143 | string uuid = (string)primRow["UUID"]; | 143 | string uuid = (string)primRow["UUID"]; |
144 | string objID = (string)primRow["SceneGroupID"]; | 144 | string objID = (string)primRow["SceneGroupID"]; |
145 | if (uuid == objID) //is new SceneObjectGroup ? | 145 | if (uuid == objID) //is new SceneObjectGroup ? |
146 | { | 146 | { |
147 | SceneObjectGroup group = new SceneObjectGroup(); | 147 | SceneObjectGroup group = new SceneObjectGroup(); |
148 | SceneObjectPart prim = buildPrim(primRow); | 148 | SceneObjectPart prim = buildPrim(primRow); |
149 | DataRow shapeRow = shapes.Rows.Find(prim.UUID); | 149 | DataRow shapeRow = shapes.Rows.Find(prim.UUID); |
150 | if (shapeRow != null) | 150 | if (shapeRow != null) |
151 | { | 151 | { |
152 | prim.Shape = buildShape(shapeRow); | 152 | prim.Shape = buildShape(shapeRow); |
153 | } | 153 | } |
154 | else | 154 | else |
155 | { | 155 | { |
156 | MainLog.Instance.Notice( | 156 | MainLog.Instance.Notice( |
157 | "No shape found for prim in storage, so setting default box shape"); | 157 | "No shape found for prim in storage, so setting default box shape"); |
158 | prim.Shape = BoxShape.Default; | 158 | prim.Shape = BoxShape.Default; |
159 | } | 159 | } |
160 | group.AddPart(prim); | 160 | group.AddPart(prim); |
161 | group.RootPart = prim; | 161 | group.RootPart = prim; |
162 | 162 | ||
163 | createdObjects.Add(group.UUID, group); | 163 | createdObjects.Add(group.UUID, group); |
164 | retvals.Add(group); | 164 | retvals.Add(group); |
165 | } | 165 | } |
166 | else | 166 | else |
167 | { | 167 | { |
168 | SceneObjectPart prim = buildPrim(primRow); | 168 | SceneObjectPart prim = buildPrim(primRow); |
169 | DataRow shapeRow = shapes.Rows.Find(prim.UUID); | 169 | DataRow shapeRow = shapes.Rows.Find(prim.UUID); |
170 | if (shapeRow != null) | 170 | if (shapeRow != null) |
171 | { | 171 | { |
172 | prim.Shape = buildShape(shapeRow); | 172 | prim.Shape = buildShape(shapeRow); |
173 | } | 173 | } |
174 | else | 174 | else |
175 | { | 175 | { |
176 | MainLog.Instance.Notice( | 176 | MainLog.Instance.Notice( |
177 | "No shape found for prim in storage, so setting default box shape"); | 177 | "No shape found for prim in storage, so setting default box shape"); |
178 | prim.Shape = BoxShape.Default; | 178 | prim.Shape = BoxShape.Default; |
179 | } | 179 | } |
180 | createdObjects[new LLUUID(objID)].AddPart(prim); | 180 | createdObjects[new LLUUID(objID)].AddPart(prim); |
181 | } | 181 | } |
182 | } | 182 | } |
183 | catch (Exception e) | 183 | catch (Exception e) |
184 | { | 184 | { |
185 | MainLog.Instance.Error("DATASTORE", "Failed create prim object, exception and data follows"); | 185 | MainLog.Instance.Error("DATASTORE", "Failed create prim object, exception and data follows"); |
186 | MainLog.Instance.Verbose(e.ToString()); | 186 | MainLog.Instance.Verbose(e.ToString()); |
187 | foreach (DataColumn col in prims.Columns) | 187 | foreach (DataColumn col in prims.Columns) |
188 | { | 188 | { |
189 | MainLog.Instance.Verbose("Col: " + col.ColumnName + " => " + primRow[col]); | 189 | MainLog.Instance.Verbose("Col: " + col.ColumnName + " => " + primRow[col]); |
190 | } | 190 | } |
191 | } | 191 | } |
192 | } | 192 | } |
193 | } | 193 | } |
194 | return retvals; | 194 | return retvals; |
195 | } | 195 | } |
196 | 196 | ||
197 | 197 | ||
198 | public void StoreTerrain(double[,] ter, LLUUID regionID) | 198 | public void StoreTerrain(double[,] ter, LLUUID regionID) |
199 | { | 199 | { |
200 | int revision = Util.UnixTimeSinceEpoch(); | 200 | int revision = Util.UnixTimeSinceEpoch(); |
201 | MainLog.Instance.Verbose("DATASTORE", "Storing terrain revision r" + revision.ToString()); | 201 | MainLog.Instance.Verbose("DATASTORE", "Storing terrain revision r" + revision.ToString()); |
202 | 202 | ||
203 | DataTable terrain = m_dataSet.Tables["terrain"]; | 203 | DataTable terrain = m_dataSet.Tables["terrain"]; |
204 | lock (m_dataSet) | 204 | lock (m_dataSet) |
205 | { | 205 | { |
206 | MySqlCommand cmd = new MySqlCommand("insert into terrain(RegionUUID, Revision, Heightfield)" + | 206 | MySqlCommand cmd = new MySqlCommand("insert into terrain(RegionUUID, Revision, Heightfield)" + |
207 | " values(?RegionUUID, ?Revision, ?Heightfield)", m_connection); | 207 | " values(?RegionUUID, ?Revision, ?Heightfield)", m_connection); |
208 | using (cmd) | 208 | using (cmd) |
209 | { | 209 | { |
210 | 210 | ||
211 | cmd.Parameters.Add(new MySqlParameter("?RegionUUID", regionID.ToString())); | 211 | cmd.Parameters.Add(new MySqlParameter("?RegionUUID", regionID.ToString())); |
212 | cmd.Parameters.Add(new MySqlParameter("?Revision", revision)); | 212 | cmd.Parameters.Add(new MySqlParameter("?Revision", revision)); |
213 | cmd.Parameters.Add(new MySqlParameter("?Heightfield", serializeTerrain(ter))); | 213 | cmd.Parameters.Add(new MySqlParameter("?Heightfield", serializeTerrain(ter))); |
214 | cmd.ExecuteNonQuery(); | 214 | cmd.ExecuteNonQuery(); |
215 | } | 215 | } |
216 | } | 216 | } |
217 | } | 217 | } |
218 | 218 | ||
219 | public double[,] LoadTerrain(LLUUID regionID) | 219 | public double[,] LoadTerrain(LLUUID regionID) |
220 | { | 220 | { |
221 | double[,] terret = new double[256, 256]; | 221 | double[,] terret = new double[256, 256]; |
222 | terret.Initialize(); | 222 | terret.Initialize(); |
223 | 223 | ||
224 | MySqlCommand cmd = new MySqlCommand( | 224 | MySqlCommand cmd = new MySqlCommand( |
225 | @"select RegionUUID, Revision, Heightfield from terrain | 225 | @"select RegionUUID, Revision, Heightfield from terrain |
226 | where RegionUUID=?RegionUUID order by Revision desc limit 1" | 226 | where RegionUUID=?RegionUUID order by Revision desc limit 1" |
227 | , m_connection); | 227 | , m_connection); |
228 | 228 | ||
229 | MySqlParameter param = new MySqlParameter(); | 229 | MySqlParameter param = new MySqlParameter(); |
230 | cmd.Parameters.Add(new MySqlParameter("?RegionUUID", regionID.ToString())); | 230 | cmd.Parameters.Add(new MySqlParameter("?RegionUUID", regionID.ToString())); |
231 | 231 | ||
232 | if (m_connection.State != ConnectionState.Open) | 232 | if (m_connection.State != ConnectionState.Open) |
233 | { | 233 | { |
234 | m_connection.Open(); | 234 | m_connection.Open(); |
235 | } | 235 | } |
236 | 236 | ||
237 | using (MySqlDataReader row = cmd.ExecuteReader()) | 237 | using (MySqlDataReader row = cmd.ExecuteReader()) |
238 | { | 238 | { |
239 | int rev = 0; | 239 | int rev = 0; |
240 | if (row.Read()) | 240 | if (row.Read()) |
241 | { | 241 | { |
242 | byte[] heightmap = (byte[])row["Heightfield"]; | 242 | byte[] heightmap = (byte[])row["Heightfield"]; |
243 | for (int x = 0; x < 256; x++) | 243 | for (int x = 0; x < 256; x++) |
244 | { | 244 | { |
245 | for (int y = 0; y < 256; y++) | 245 | for (int y = 0; y < 256; y++) |
246 | { | 246 | { |
247 | terret[x, y] = BitConverter.ToDouble(heightmap, ((x * 256) + y) * 8); | 247 | terret[x, y] = BitConverter.ToDouble(heightmap, ((x * 256) + y) * 8); |
248 | } | 248 | } |
249 | } | 249 | } |
250 | rev = (int)row["Revision"]; | 250 | rev = (int)row["Revision"]; |
251 | } | 251 | } |
252 | else | 252 | else |
253 | { | 253 | { |
254 | MainLog.Instance.Verbose("DATASTORE", "No terrain found for region"); | 254 | MainLog.Instance.Verbose("DATASTORE", "No terrain found for region"); |
255 | return null; | 255 | return null; |
256 | } | 256 | } |
257 | 257 | ||
258 | MainLog.Instance.Verbose("DATASTORE", "Loaded terrain revision r" + rev.ToString()); | 258 | MainLog.Instance.Verbose("DATASTORE", "Loaded terrain revision r" + rev.ToString()); |
259 | } | 259 | } |
260 | 260 | ||
261 | return terret; | 261 | return terret; |
262 | } | 262 | } |
263 | 263 | ||
264 | public void RemoveLandObject(uint id) | 264 | public void RemoveLandObject(uint id) |
265 | { | 265 | { |
266 | } | 266 | } |
267 | 267 | ||
268 | public void StoreParcel(Land parcel) | 268 | public void StoreParcel(Land parcel) |
269 | { | 269 | { |
270 | } | 270 | } |
271 | 271 | ||
272 | public List<Land> LoadLandObjects() | 272 | public List<Land> LoadLandObjects() |
273 | { | 273 | { |
274 | return new List<Land>(); | 274 | return new List<Land>(); |
275 | } | 275 | } |
276 | 276 | ||
277 | private void DisplayDataSet(DataSet ds, string title) | 277 | private void DisplayDataSet(DataSet ds, string title) |
278 | { | 278 | { |
279 | Debug.WriteLine(title); | 279 | Debug.WriteLine(title); |
280 | //--- Loop through the DataTables | 280 | //--- Loop through the DataTables |
281 | foreach (DataTable table in ds.Tables) | 281 | foreach (DataTable table in ds.Tables) |
282 | { | 282 | { |
283 | Debug.WriteLine("*** DataTable: " + table.TableName + "***"); | 283 | Debug.WriteLine("*** DataTable: " + table.TableName + "***"); |
284 | //--- Loop through each DataTable's DataRows | 284 | //--- Loop through each DataTable's DataRows |
285 | foreach (DataRow row in table.Rows) | 285 | foreach (DataRow row in table.Rows) |
286 | { | 286 | { |
287 | //--- Display the original values, if there are any. | 287 | //--- Display the original values, if there are any. |
288 | if (row.HasVersion(System.Data.DataRowVersion.Original)) | 288 | if (row.HasVersion(System.Data.DataRowVersion.Original)) |
289 | { | 289 | { |
290 | Debug.Write("Original Row Values ===> "); | 290 | Debug.Write("Original Row Values ===> "); |
291 | foreach (DataColumn column in table.Columns) | 291 | foreach (DataColumn column in table.Columns) |
292 | Debug.Write(column.ColumnName + " = " + | 292 | Debug.Write(column.ColumnName + " = " + |
293 | row[column, DataRowVersion.Original] + ", "); | 293 | row[column, DataRowVersion.Original] + ", "); |
294 | Debug.WriteLine(""); | 294 | Debug.WriteLine(""); |
295 | } | 295 | } |
296 | //--- Display the current values, if there are any. | 296 | //--- Display the current values, if there are any. |
297 | if (row.HasVersion(System.Data.DataRowVersion.Current)) | 297 | if (row.HasVersion(System.Data.DataRowVersion.Current)) |
298 | { | 298 | { |
299 | Debug.Write("Current Row Values ====> "); | 299 | Debug.Write("Current Row Values ====> "); |
300 | foreach (DataColumn column in table.Columns) | 300 | foreach (DataColumn column in table.Columns) |
301 | Debug.Write(column.ColumnName + " = " + | 301 | Debug.Write(column.ColumnName + " = " + |
302 | row[column, DataRowVersion.Current] + ", "); | 302 | row[column, DataRowVersion.Current] + ", "); |
303 | Debug.WriteLine(""); | 303 | Debug.WriteLine(""); |
304 | } | 304 | } |
305 | Debug.WriteLine(""); | 305 | Debug.WriteLine(""); |
306 | } | 306 | } |
307 | } | 307 | } |
308 | } | 308 | } |
309 | 309 | ||
310 | public void Commit() | 310 | public void Commit() |
311 | { | 311 | { |
312 | if (m_connection.State != ConnectionState.Open) | 312 | if (m_connection.State != ConnectionState.Open) |
313 | { | 313 | { |
314 | m_connection.Open(); | 314 | m_connection.Open(); |
315 | } | 315 | } |
316 | 316 | ||
317 | lock (m_dataSet) | 317 | lock (m_dataSet) |
318 | { | 318 | { |
319 | // DisplayDataSet(m_dataSet, "Region DataSet"); | 319 | // DisplayDataSet(m_dataSet, "Region DataSet"); |
320 | 320 | ||
321 | m_primDataAdapter.Update(m_primTable); | 321 | m_primDataAdapter.Update(m_primTable); |
322 | m_shapeDataAdapter.Update(m_shapeTable); | 322 | m_shapeDataAdapter.Update(m_shapeTable); |
323 | m_terrainDataAdapter.Update(m_terrainTable); | 323 | m_terrainDataAdapter.Update(m_terrainTable); |
324 | 324 | ||
325 | m_dataSet.AcceptChanges(); | 325 | m_dataSet.AcceptChanges(); |
326 | } | 326 | } |
327 | } | 327 | } |
328 | 328 | ||
329 | public void Shutdown() | 329 | public void Shutdown() |
330 | { | 330 | { |
331 | Commit(); | 331 | Commit(); |
332 | } | 332 | } |
333 | 333 | ||
334 | /*********************************************************************** | 334 | /*********************************************************************** |
335 | * | 335 | * |
336 | * Database Definition Functions | 336 | * Database Definition Functions |
337 | * | 337 | * |
338 | * This should be db agnostic as we define them in ADO.NET terms | 338 | * This should be db agnostic as we define them in ADO.NET terms |
339 | * | 339 | * |
340 | **********************************************************************/ | 340 | **********************************************************************/ |
341 | 341 | ||
342 | private DataColumn createCol(DataTable dt, string name, Type type) | 342 | private DataColumn createCol(DataTable dt, string name, Type type) |
343 | { | 343 | { |
344 | DataColumn col = new DataColumn(name, type); | 344 | DataColumn col = new DataColumn(name, type); |
345 | dt.Columns.Add(col); | 345 | dt.Columns.Add(col); |
346 | return col; | 346 | return col; |
347 | } | 347 | } |
348 | 348 | ||
349 | private DataTable createTerrainTable() | 349 | private DataTable createTerrainTable() |
350 | { | 350 | { |
351 | DataTable terrain = new DataTable("terrain"); | 351 | DataTable terrain = new DataTable("terrain"); |
352 | 352 | ||
353 | createCol(terrain, "RegionUUID", typeof(String)); | 353 | createCol(terrain, "RegionUUID", typeof(String)); |
354 | createCol(terrain, "Revision", typeof(Int32)); | 354 | createCol(terrain, "Revision", typeof(Int32)); |
355 | DataColumn heightField = createCol(terrain, "Heightfield", typeof(Byte[])); | 355 | DataColumn heightField = createCol(terrain, "Heightfield", typeof(Byte[])); |
356 | return terrain; | 356 | return terrain; |
357 | } | 357 | } |
358 | 358 | ||
359 | private DataTable createPrimTable() | 359 | private DataTable createPrimTable() |
360 | { | 360 | { |
361 | DataTable prims = new DataTable("prims"); | 361 | DataTable prims = new DataTable("prims"); |
362 | 362 | ||
363 | createCol(prims, "UUID", typeof(String)); | 363 | createCol(prims, "UUID", typeof(String)); |
364 | createCol(prims, "RegionUUID", typeof(String)); | 364 | createCol(prims, "RegionUUID", typeof(String)); |
365 | createCol(prims, "ParentID", typeof(Int32)); | 365 | createCol(prims, "ParentID", typeof(Int32)); |
366 | createCol(prims, "CreationDate", typeof(Int32)); | 366 | createCol(prims, "CreationDate", typeof(Int32)); |
367 | createCol(prims, "Name", typeof(String)); | 367 | createCol(prims, "Name", typeof(String)); |
368 | createCol(prims, "SceneGroupID", typeof(String)); | 368 | createCol(prims, "SceneGroupID", typeof(String)); |
369 | // various text fields | 369 | // various text fields |
370 | createCol(prims, "Text", typeof(String)); | 370 | createCol(prims, "Text", typeof(String)); |
371 | createCol(prims, "Description", typeof(String)); | 371 | createCol(prims, "Description", typeof(String)); |
372 | createCol(prims, "SitName", typeof(String)); | 372 | createCol(prims, "SitName", typeof(String)); |
373 | createCol(prims, "TouchName", typeof(String)); | 373 | createCol(prims, "TouchName", typeof(String)); |
374 | // permissions | 374 | // permissions |
375 | createCol(prims, "ObjectFlags", typeof(Int32)); | 375 | createCol(prims, "ObjectFlags", typeof(Int32)); |
376 | createCol(prims, "CreatorID", typeof(String)); | 376 | createCol(prims, "CreatorID", typeof(String)); |
377 | createCol(prims, "OwnerID", typeof(String)); | 377 | createCol(prims, "OwnerID", typeof(String)); |
378 | createCol(prims, "GroupID", typeof(String)); | 378 | createCol(prims, "GroupID", typeof(String)); |
379 | createCol(prims, "LastOwnerID", typeof(String)); | 379 | createCol(prims, "LastOwnerID", typeof(String)); |
380 | createCol(prims, "OwnerMask", typeof(Int32)); | 380 | createCol(prims, "OwnerMask", typeof(Int32)); |
381 | createCol(prims, "NextOwnerMask", typeof(Int32)); | 381 | createCol(prims, "NextOwnerMask", typeof(Int32)); |
382 | createCol(prims, "GroupMask", typeof(Int32)); | 382 | createCol(prims, "GroupMask", typeof(Int32)); |
383 | createCol(prims, "EveryoneMask", typeof(Int32)); | 383 | createCol(prims, "EveryoneMask", typeof(Int32)); |
384 | createCol(prims, "BaseMask", typeof(Int32)); | 384 | createCol(prims, "BaseMask", typeof(Int32)); |
385 | // vectors | 385 | // vectors |
386 | createCol(prims, "PositionX", typeof(Double)); | 386 | createCol(prims, "PositionX", typeof(Double)); |
387 | createCol(prims, "PositionY", typeof(Double)); | 387 | createCol(prims, "PositionY", typeof(Double)); |
388 | createCol(prims, "PositionZ", typeof(Double)); | 388 | createCol(prims, "PositionZ", typeof(Double)); |
389 | createCol(prims, "GroupPositionX", typeof(Double)); | 389 | createCol(prims, "GroupPositionX", typeof(Double)); |
390 | createCol(prims, "GroupPositionY", typeof(Double)); | 390 | createCol(prims, "GroupPositionY", typeof(Double)); |
391 | createCol(prims, "GroupPositionZ", typeof(Double)); | 391 | createCol(prims, "GroupPositionZ", typeof(Double)); |
392 | createCol(prims, "VelocityX", typeof(Double)); | 392 | createCol(prims, "VelocityX", typeof(Double)); |
393 | createCol(prims, "VelocityY", typeof(Double)); | 393 | createCol(prims, "VelocityY", typeof(Double)); |
394 | createCol(prims, "VelocityZ", typeof(Double)); | 394 | createCol(prims, "VelocityZ", typeof(Double)); |
395 | createCol(prims, "AngularVelocityX", typeof(Double)); | 395 | createCol(prims, "AngularVelocityX", typeof(Double)); |
396 | createCol(prims, "AngularVelocityY", typeof(Double)); | 396 | createCol(prims, "AngularVelocityY", typeof(Double)); |
397 | createCol(prims, "AngularVelocityZ", typeof(Double)); | 397 | createCol(prims, "AngularVelocityZ", typeof(Double)); |
398 | createCol(prims, "AccelerationX", typeof(Double)); | 398 | createCol(prims, "AccelerationX", typeof(Double)); |
399 | createCol(prims, "AccelerationY", typeof(Double)); | 399 | createCol(prims, "AccelerationY", typeof(Double)); |
400 | createCol(prims, "AccelerationZ", typeof(Double)); | 400 | createCol(prims, "AccelerationZ", typeof(Double)); |
401 | // quaternions | 401 | // quaternions |
402 | createCol(prims, "RotationX", typeof(Double)); | 402 | createCol(prims, "RotationX", typeof(Double)); |
403 | createCol(prims, "RotationY", typeof(Double)); | 403 | createCol(prims, "RotationY", typeof(Double)); |
404 | createCol(prims, "RotationZ", typeof(Double)); | 404 | createCol(prims, "RotationZ", typeof(Double)); |
405 | createCol(prims, "RotationW", typeof(Double)); | 405 | createCol(prims, "RotationW", typeof(Double)); |
406 | 406 | ||
407 | // Add in contraints | 407 | // Add in contraints |
408 | prims.PrimaryKey = new DataColumn[] { prims.Columns["UUID"] }; | 408 | prims.PrimaryKey = new DataColumn[] { prims.Columns["UUID"] }; |
409 | 409 | ||
410 | return prims; | 410 | return prims; |
411 | } | 411 | } |
412 | 412 | ||
413 | private DataTable createShapeTable() | 413 | private DataTable createShapeTable() |
414 | { | 414 | { |
415 | DataTable shapes = new DataTable("primshapes"); | 415 | DataTable shapes = new DataTable("primshapes"); |
416 | createCol(shapes, "UUID", typeof(String)); | 416 | createCol(shapes, "UUID", typeof(String)); |
417 | // shape is an enum | 417 | // shape is an enum |
418 | createCol(shapes, "Shape", typeof(Int32)); | 418 | createCol(shapes, "Shape", typeof(Int32)); |
419 | // vectors | 419 | // vectors |
420 | createCol(shapes, "ScaleX", typeof(Double)); | 420 | createCol(shapes, "ScaleX", typeof(Double)); |
421 | createCol(shapes, "ScaleY", typeof(Double)); | 421 | createCol(shapes, "ScaleY", typeof(Double)); |
422 | createCol(shapes, "ScaleZ", typeof(Double)); | 422 | createCol(shapes, "ScaleZ", typeof(Double)); |
423 | // paths | 423 | // paths |
424 | createCol(shapes, "PCode", typeof(Int32)); | 424 | createCol(shapes, "PCode", typeof(Int32)); |
425 | createCol(shapes, "PathBegin", typeof(Int32)); | 425 | createCol(shapes, "PathBegin", typeof(Int32)); |
426 | createCol(shapes, "PathEnd", typeof(Int32)); | 426 | createCol(shapes, "PathEnd", typeof(Int32)); |
427 | createCol(shapes, "PathScaleX", typeof(Int32)); | 427 | createCol(shapes, "PathScaleX", typeof(Int32)); |
428 | createCol(shapes, "PathScaleY", typeof(Int32)); | 428 | createCol(shapes, "PathScaleY", typeof(Int32)); |
429 | createCol(shapes, "PathShearX", typeof(Int32)); | 429 | createCol(shapes, "PathShearX", typeof(Int32)); |
430 | createCol(shapes, "PathShearY", typeof(Int32)); | 430 | createCol(shapes, "PathShearY", typeof(Int32)); |
431 | createCol(shapes, "PathSkew", typeof(Int32)); | 431 | createCol(shapes, "PathSkew", typeof(Int32)); |
432 | createCol(shapes, "PathCurve", typeof(Int32)); | 432 | createCol(shapes, "PathCurve", typeof(Int32)); |
433 | createCol(shapes, "PathRadiusOffset", typeof(Int32)); | 433 | createCol(shapes, "PathRadiusOffset", typeof(Int32)); |
434 | createCol(shapes, "PathRevolutions", typeof(Int32)); | 434 | createCol(shapes, "PathRevolutions", typeof(Int32)); |
435 | createCol(shapes, "PathTaperX", typeof(Int32)); | 435 | createCol(shapes, "PathTaperX", typeof(Int32)); |
436 | createCol(shapes, "PathTaperY", typeof(Int32)); | 436 | createCol(shapes, "PathTaperY", typeof(Int32)); |
437 | createCol(shapes, "PathTwist", typeof(Int32)); | 437 | createCol(shapes, "PathTwist", typeof(Int32)); |
438 | createCol(shapes, "PathTwistBegin", typeof(Int32)); | 438 | createCol(shapes, "PathTwistBegin", typeof(Int32)); |
439 | // profile | 439 | // profile |
440 | createCol(shapes, "ProfileBegin", typeof(Int32)); | 440 | createCol(shapes, "ProfileBegin", typeof(Int32)); |
441 | createCol(shapes, "ProfileEnd", typeof(Int32)); | 441 | createCol(shapes, "ProfileEnd", typeof(Int32)); |
442 | createCol(shapes, "ProfileCurve", typeof(Int32)); | 442 | createCol(shapes, "ProfileCurve", typeof(Int32)); |
443 | createCol(shapes, "ProfileHollow", typeof(Int32)); | 443 | createCol(shapes, "ProfileHollow", typeof(Int32)); |
444 | createCol(shapes, "Texture", typeof(Byte[])); | 444 | createCol(shapes, "Texture", typeof(Byte[])); |
445 | createCol(shapes, "ExtraParams", typeof(Byte[])); | 445 | createCol(shapes, "ExtraParams", typeof(Byte[])); |
446 | 446 | ||
447 | shapes.PrimaryKey = new DataColumn[] { shapes.Columns["UUID"] }; | 447 | shapes.PrimaryKey = new DataColumn[] { shapes.Columns["UUID"] }; |
448 | 448 | ||
449 | return shapes; | 449 | return shapes; |
450 | } | 450 | } |
451 | 451 | ||
452 | /*********************************************************************** | 452 | /*********************************************************************** |
453 | * | 453 | * |
454 | * Convert between ADO.NET <=> OpenSim Objects | 454 | * Convert between ADO.NET <=> OpenSim Objects |
455 | * | 455 | * |
456 | * These should be database independant | 456 | * These should be database independant |
457 | * | 457 | * |
458 | **********************************************************************/ | 458 | **********************************************************************/ |
459 | 459 | ||
460 | private SceneObjectPart buildPrim(DataRow row) | 460 | private SceneObjectPart buildPrim(DataRow row) |
461 | { | 461 | { |
462 | // TODO: this doesn't work yet because something more | 462 | // TODO: this doesn't work yet because something more |
463 | // interesting has to be done to actually get these values | 463 | // interesting has to be done to actually get these values |
464 | // back out. Not enough time to figure it out yet. | 464 | // back out. Not enough time to figure it out yet. |
465 | SceneObjectPart prim = new SceneObjectPart(); | 465 | SceneObjectPart prim = new SceneObjectPart(); |
466 | prim.UUID = new LLUUID((String)row["UUID"]); | 466 | prim.UUID = new LLUUID((String)row["UUID"]); |
467 | // explicit conversion of integers is required, which sort | 467 | // explicit conversion of integers is required, which sort |
468 | // of sucks. No idea if there is a shortcut here or not. | 468 | // of sucks. No idea if there is a shortcut here or not. |
469 | prim.ParentID = Convert.ToUInt32(row["ParentID"]); | 469 | prim.ParentID = Convert.ToUInt32(row["ParentID"]); |
470 | prim.CreationDate = Convert.ToInt32(row["CreationDate"]); | 470 | prim.CreationDate = Convert.ToInt32(row["CreationDate"]); |
471 | prim.Name = (String)row["Name"]; | 471 | prim.Name = (String)row["Name"]; |
472 | // various text fields | 472 | // various text fields |
473 | prim.Text = (String)row["Text"]; | 473 | prim.Text = (String)row["Text"]; |
474 | prim.Description = (String)row["Description"]; | 474 | prim.Description = (String)row["Description"]; |
475 | prim.SitName = (String)row["SitName"]; | 475 | prim.SitName = (String)row["SitName"]; |
476 | prim.TouchName = (String)row["TouchName"]; | 476 | prim.TouchName = (String)row["TouchName"]; |
477 | // permissions | 477 | // permissions |
478 | prim.ObjectFlags = Convert.ToUInt32(row["ObjectFlags"]); | 478 | prim.ObjectFlags = Convert.ToUInt32(row["ObjectFlags"]); |
479 | prim.CreatorID = new LLUUID((String)row["CreatorID"]); | 479 | prim.CreatorID = new LLUUID((String)row["CreatorID"]); |
480 | prim.OwnerID = new LLUUID((String)row["OwnerID"]); | 480 | prim.OwnerID = new LLUUID((String)row["OwnerID"]); |
481 | prim.GroupID = new LLUUID((String)row["GroupID"]); | 481 | prim.GroupID = new LLUUID((String)row["GroupID"]); |
482 | prim.LastOwnerID = new LLUUID((String)row["LastOwnerID"]); | 482 | prim.LastOwnerID = new LLUUID((String)row["LastOwnerID"]); |
483 | prim.OwnerMask = Convert.ToUInt32(row["OwnerMask"]); | 483 | prim.OwnerMask = Convert.ToUInt32(row["OwnerMask"]); |
484 | prim.NextOwnerMask = Convert.ToUInt32(row["NextOwnerMask"]); | 484 | prim.NextOwnerMask = Convert.ToUInt32(row["NextOwnerMask"]); |
485 | prim.GroupMask = Convert.ToUInt32(row["GroupMask"]); | 485 | prim.GroupMask = Convert.ToUInt32(row["GroupMask"]); |
486 | prim.EveryoneMask = Convert.ToUInt32(row["EveryoneMask"]); | 486 | prim.EveryoneMask = Convert.ToUInt32(row["EveryoneMask"]); |
487 | prim.BaseMask = Convert.ToUInt32(row["BaseMask"]); | 487 | prim.BaseMask = Convert.ToUInt32(row["BaseMask"]); |
488 | // vectors | 488 | // vectors |
489 | prim.OffsetPosition = new LLVector3( | 489 | prim.OffsetPosition = new LLVector3( |
490 | Convert.ToSingle(row["PositionX"]), | 490 | Convert.ToSingle(row["PositionX"]), |
491 | Convert.ToSingle(row["PositionY"]), | 491 | Convert.ToSingle(row["PositionY"]), |
492 | Convert.ToSingle(row["PositionZ"]) | 492 | Convert.ToSingle(row["PositionZ"]) |
493 | ); | 493 | ); |
494 | prim.GroupPosition = new LLVector3( | 494 | prim.GroupPosition = new LLVector3( |
495 | Convert.ToSingle(row["GroupPositionX"]), | 495 | Convert.ToSingle(row["GroupPositionX"]), |
496 | Convert.ToSingle(row["GroupPositionY"]), | 496 | Convert.ToSingle(row["GroupPositionY"]), |
497 | Convert.ToSingle(row["GroupPositionZ"]) | 497 | Convert.ToSingle(row["GroupPositionZ"]) |
498 | ); | 498 | ); |
499 | prim.Velocity = new LLVector3( | 499 | prim.Velocity = new LLVector3( |
500 | Convert.ToSingle(row["VelocityX"]), | 500 | Convert.ToSingle(row["VelocityX"]), |
501 | Convert.ToSingle(row["VelocityY"]), | 501 | Convert.ToSingle(row["VelocityY"]), |
502 | Convert.ToSingle(row["VelocityZ"]) | 502 | Convert.ToSingle(row["VelocityZ"]) |
503 | ); | 503 | ); |
504 | prim.AngularVelocity = new LLVector3( | 504 | prim.AngularVelocity = new LLVector3( |
505 | Convert.ToSingle(row["AngularVelocityX"]), | 505 | Convert.ToSingle(row["AngularVelocityX"]), |
506 | Convert.ToSingle(row["AngularVelocityY"]), | 506 | Convert.ToSingle(row["AngularVelocityY"]), |
507 | Convert.ToSingle(row["AngularVelocityZ"]) | 507 | Convert.ToSingle(row["AngularVelocityZ"]) |
508 | ); | 508 | ); |
509 | prim.Acceleration = new LLVector3( | 509 | prim.Acceleration = new LLVector3( |
510 | Convert.ToSingle(row["AccelerationX"]), | 510 | Convert.ToSingle(row["AccelerationX"]), |
511 | Convert.ToSingle(row["AccelerationY"]), | 511 | Convert.ToSingle(row["AccelerationY"]), |
512 | Convert.ToSingle(row["AccelerationZ"]) | 512 | Convert.ToSingle(row["AccelerationZ"]) |
513 | ); | 513 | ); |
514 | // quaternions | 514 | // quaternions |
515 | prim.RotationOffset = new LLQuaternion( | 515 | prim.RotationOffset = new LLQuaternion( |
516 | Convert.ToSingle(row["RotationX"]), | 516 | Convert.ToSingle(row["RotationX"]), |
517 | Convert.ToSingle(row["RotationY"]), | 517 | Convert.ToSingle(row["RotationY"]), |
518 | Convert.ToSingle(row["RotationZ"]), | 518 | Convert.ToSingle(row["RotationZ"]), |
519 | Convert.ToSingle(row["RotationW"]) | 519 | Convert.ToSingle(row["RotationW"]) |
520 | ); | 520 | ); |
521 | 521 | ||
522 | return prim; | 522 | return prim; |
523 | } | 523 | } |
524 | 524 | ||
525 | private Array serializeTerrain(double[,] val) | 525 | private Array serializeTerrain(double[,] val) |
526 | { | 526 | { |
527 | MemoryStream str = new MemoryStream(65536 * sizeof(double)); | 527 | MemoryStream str = new MemoryStream(65536 * sizeof(double)); |
528 | BinaryWriter bw = new BinaryWriter(str); | 528 | BinaryWriter bw = new BinaryWriter(str); |
529 | 529 | ||
530 | // TODO: COMPATIBILITY - Add byte-order conversions | 530 | // TODO: COMPATIBILITY - Add byte-order conversions |
531 | for (int x = 0; x < 256; x++) | 531 | for (int x = 0; x < 256; x++) |
532 | for (int y = 0; y < 256; y++) | 532 | for (int y = 0; y < 256; y++) |
533 | bw.Write(val[x, y]); | 533 | bw.Write(val[x, y]); |
534 | 534 | ||
535 | return str.ToArray(); | 535 | return str.ToArray(); |
536 | } | 536 | } |
537 | 537 | ||
538 | private void fillPrimRow(DataRow row, SceneObjectPart prim, LLUUID sceneGroupID, LLUUID regionUUID) | 538 | private void fillPrimRow(DataRow row, SceneObjectPart prim, LLUUID sceneGroupID, LLUUID regionUUID) |
539 | { | 539 | { |
540 | row["UUID"] = prim.UUID; | 540 | row["UUID"] = prim.UUID; |
541 | row["RegionUUID"] = regionUUID; | 541 | row["RegionUUID"] = regionUUID; |
542 | row["ParentID"] = prim.ParentID; | 542 | row["ParentID"] = prim.ParentID; |
543 | row["CreationDate"] = prim.CreationDate; | 543 | row["CreationDate"] = prim.CreationDate; |
544 | row["Name"] = prim.Name; | 544 | row["Name"] = prim.Name; |
545 | row["SceneGroupID"] = sceneGroupID; // the UUID of the root part for this SceneObjectGroup | 545 | row["SceneGroupID"] = sceneGroupID; // the UUID of the root part for this SceneObjectGroup |
546 | // various text fields | 546 | // various text fields |
547 | row["Text"] = prim.Text; | 547 | row["Text"] = prim.Text; |
548 | row["Description"] = prim.Description; | 548 | row["Description"] = prim.Description; |
549 | row["SitName"] = prim.SitName; | 549 | row["SitName"] = prim.SitName; |
550 | row["TouchName"] = prim.TouchName; | 550 | row["TouchName"] = prim.TouchName; |
551 | // permissions | 551 | // permissions |
552 | row["ObjectFlags"] = prim.ObjectFlags; | 552 | row["ObjectFlags"] = prim.ObjectFlags; |
553 | row["CreatorID"] = prim.CreatorID; | 553 | row["CreatorID"] = prim.CreatorID; |
554 | row["OwnerID"] = prim.OwnerID; | 554 | row["OwnerID"] = prim.OwnerID; |
555 | row["GroupID"] = prim.GroupID; | 555 | row["GroupID"] = prim.GroupID; |
556 | row["LastOwnerID"] = prim.LastOwnerID; | 556 | row["LastOwnerID"] = prim.LastOwnerID; |
557 | row["OwnerMask"] = prim.OwnerMask; | 557 | row["OwnerMask"] = prim.OwnerMask; |
558 | row["NextOwnerMask"] = prim.NextOwnerMask; | 558 | row["NextOwnerMask"] = prim.NextOwnerMask; |
559 | row["GroupMask"] = prim.GroupMask; | 559 | row["GroupMask"] = prim.GroupMask; |
560 | row["EveryoneMask"] = prim.EveryoneMask; | 560 | row["EveryoneMask"] = prim.EveryoneMask; |
561 | row["BaseMask"] = prim.BaseMask; | 561 | row["BaseMask"] = prim.BaseMask; |
562 | // vectors | 562 | // vectors |
563 | row["PositionX"] = prim.OffsetPosition.X; | 563 | row["PositionX"] = prim.OffsetPosition.X; |
564 | row["PositionY"] = prim.OffsetPosition.Y; | 564 | row["PositionY"] = prim.OffsetPosition.Y; |
565 | row["PositionZ"] = prim.OffsetPosition.Z; | 565 | row["PositionZ"] = prim.OffsetPosition.Z; |
566 | row["GroupPositionX"] = prim.GroupPosition.X; | 566 | row["GroupPositionX"] = prim.GroupPosition.X; |
567 | row["GroupPositionY"] = prim.GroupPosition.Y; | 567 | row["GroupPositionY"] = prim.GroupPosition.Y; |
568 | row["GroupPositionZ"] = prim.GroupPosition.Z; | 568 | row["GroupPositionZ"] = prim.GroupPosition.Z; |
569 | row["VelocityX"] = prim.Velocity.X; | 569 | row["VelocityX"] = prim.Velocity.X; |
570 | row["VelocityY"] = prim.Velocity.Y; | 570 | row["VelocityY"] = prim.Velocity.Y; |
571 | row["VelocityZ"] = prim.Velocity.Z; | 571 | row["VelocityZ"] = prim.Velocity.Z; |
572 | row["AngularVelocityX"] = prim.AngularVelocity.X; | 572 | row["AngularVelocityX"] = prim.AngularVelocity.X; |
573 | row["AngularVelocityY"] = prim.AngularVelocity.Y; | 573 | row["AngularVelocityY"] = prim.AngularVelocity.Y; |
574 | row["AngularVelocityZ"] = prim.AngularVelocity.Z; | 574 | row["AngularVelocityZ"] = prim.AngularVelocity.Z; |
575 | row["AccelerationX"] = prim.Acceleration.X; | 575 | row["AccelerationX"] = prim.Acceleration.X; |
576 | row["AccelerationY"] = prim.Acceleration.Y; | 576 | row["AccelerationY"] = prim.Acceleration.Y; |
577 | row["AccelerationZ"] = prim.Acceleration.Z; | 577 | row["AccelerationZ"] = prim.Acceleration.Z; |
578 | // quaternions | 578 | // quaternions |
579 | row["RotationX"] = prim.RotationOffset.X; | 579 | row["RotationX"] = prim.RotationOffset.X; |
580 | row["RotationY"] = prim.RotationOffset.Y; | 580 | row["RotationY"] = prim.RotationOffset.Y; |
581 | row["RotationZ"] = prim.RotationOffset.Z; | 581 | row["RotationZ"] = prim.RotationOffset.Z; |
582 | row["RotationW"] = prim.RotationOffset.W; | 582 | row["RotationW"] = prim.RotationOffset.W; |
583 | } | 583 | } |
584 | 584 | ||
585 | private PrimitiveBaseShape buildShape(DataRow row) | 585 | private PrimitiveBaseShape buildShape(DataRow row) |
586 | { | 586 | { |
587 | PrimitiveBaseShape s = new PrimitiveBaseShape(); | 587 | PrimitiveBaseShape s = new PrimitiveBaseShape(); |
588 | s.Scale = new LLVector3( | 588 | s.Scale = new LLVector3( |
589 | Convert.ToSingle(row["ScaleX"]), | 589 | Convert.ToSingle(row["ScaleX"]), |
590 | Convert.ToSingle(row["ScaleY"]), | 590 | Convert.ToSingle(row["ScaleY"]), |
591 | Convert.ToSingle(row["ScaleZ"]) | 591 | Convert.ToSingle(row["ScaleZ"]) |
592 | ); | 592 | ); |
593 | // paths | 593 | // paths |
594 | s.PCode = Convert.ToByte(row["PCode"]); | 594 | s.PCode = Convert.ToByte(row["PCode"]); |
595 | s.PathBegin = Convert.ToUInt16(row["PathBegin"]); | 595 | s.PathBegin = Convert.ToUInt16(row["PathBegin"]); |
596 | s.PathEnd = Convert.ToUInt16(row["PathEnd"]); | 596 | s.PathEnd = Convert.ToUInt16(row["PathEnd"]); |
597 | s.PathScaleX = Convert.ToByte(row["PathScaleX"]); | 597 | s.PathScaleX = Convert.ToByte(row["PathScaleX"]); |
598 | s.PathScaleY = Convert.ToByte(row["PathScaleY"]); | 598 | s.PathScaleY = Convert.ToByte(row["PathScaleY"]); |
599 | s.PathShearX = Convert.ToByte(row["PathShearX"]); | 599 | s.PathShearX = Convert.ToByte(row["PathShearX"]); |
600 | s.PathShearY = Convert.ToByte(row["PathShearY"]); | 600 | s.PathShearY = Convert.ToByte(row["PathShearY"]); |
601 | s.PathSkew = Convert.ToSByte(row["PathSkew"]); | 601 | s.PathSkew = Convert.ToSByte(row["PathSkew"]); |
602 | s.PathCurve = Convert.ToByte(row["PathCurve"]); | 602 | s.PathCurve = Convert.ToByte(row["PathCurve"]); |
603 | s.PathRadiusOffset = Convert.ToSByte(row["PathRadiusOffset"]); | 603 | s.PathRadiusOffset = Convert.ToSByte(row["PathRadiusOffset"]); |
604 | s.PathRevolutions = Convert.ToByte(row["PathRevolutions"]); | 604 | s.PathRevolutions = Convert.ToByte(row["PathRevolutions"]); |
605 | s.PathTaperX = Convert.ToSByte(row["PathTaperX"]); | 605 | s.PathTaperX = Convert.ToSByte(row["PathTaperX"]); |
606 | s.PathTaperY = Convert.ToSByte(row["PathTaperY"]); | 606 | s.PathTaperY = Convert.ToSByte(row["PathTaperY"]); |
607 | s.PathTwist = Convert.ToSByte(row["PathTwist"]); | 607 | s.PathTwist = Convert.ToSByte(row["PathTwist"]); |
608 | s.PathTwistBegin = Convert.ToSByte(row["PathTwistBegin"]); | 608 | s.PathTwistBegin = Convert.ToSByte(row["PathTwistBegin"]); |
609 | // profile | 609 | // profile |
610 | s.ProfileBegin = Convert.ToUInt16(row["ProfileBegin"]); | 610 | s.ProfileBegin = Convert.ToUInt16(row["ProfileBegin"]); |
611 | s.ProfileEnd = Convert.ToUInt16(row["ProfileEnd"]); | 611 | s.ProfileEnd = Convert.ToUInt16(row["ProfileEnd"]); |
612 | s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]); | 612 | s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]); |
613 | s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]); | 613 | s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]); |
614 | s.TextureEntry = (byte[])row["Texture"]; | 614 | s.TextureEntry = (byte[])row["Texture"]; |
615 | s.ExtraParams = (byte[])row["ExtraParams"]; | 615 | s.ExtraParams = (byte[])row["ExtraParams"]; |
616 | 616 | ||
617 | return s; | 617 | return s; |
618 | } | 618 | } |
619 | 619 | ||
620 | private void fillShapeRow(DataRow row, SceneObjectPart prim) | 620 | private void fillShapeRow(DataRow row, SceneObjectPart prim) |
621 | { | 621 | { |
622 | PrimitiveBaseShape s = prim.Shape; | 622 | PrimitiveBaseShape s = prim.Shape; |
623 | row["UUID"] = prim.UUID; | 623 | row["UUID"] = prim.UUID; |
624 | // shape is an enum | 624 | // shape is an enum |
625 | row["Shape"] = 0; | 625 | row["Shape"] = 0; |
626 | // vectors | 626 | // vectors |
627 | row["ScaleX"] = s.Scale.X; | 627 | row["ScaleX"] = s.Scale.X; |
628 | row["ScaleY"] = s.Scale.Y; | 628 | row["ScaleY"] = s.Scale.Y; |
629 | row["ScaleZ"] = s.Scale.Z; | 629 | row["ScaleZ"] = s.Scale.Z; |
630 | // paths | 630 | // paths |
631 | row["PCode"] = s.PCode; | 631 | row["PCode"] = s.PCode; |
632 | row["PathBegin"] = s.PathBegin; | 632 | row["PathBegin"] = s.PathBegin; |
633 | row["PathEnd"] = s.PathEnd; | 633 | row["PathEnd"] = s.PathEnd; |
634 | row["PathScaleX"] = s.PathScaleX; | 634 | row["PathScaleX"] = s.PathScaleX; |
635 | row["PathScaleY"] = s.PathScaleY; | 635 | row["PathScaleY"] = s.PathScaleY; |
636 | row["PathShearX"] = s.PathShearX; | 636 | row["PathShearX"] = s.PathShearX; |
637 | row["PathShearY"] = s.PathShearY; | 637 | row["PathShearY"] = s.PathShearY; |
638 | row["PathSkew"] = s.PathSkew; | 638 | row["PathSkew"] = s.PathSkew; |
639 | row["PathCurve"] = s.PathCurve; | 639 | row["PathCurve"] = s.PathCurve; |
640 | row["PathRadiusOffset"] = s.PathRadiusOffset; | 640 | row["PathRadiusOffset"] = s.PathRadiusOffset; |
641 | row["PathRevolutions"] = s.PathRevolutions; | 641 | row["PathRevolutions"] = s.PathRevolutions; |
642 | row["PathTaperX"] = s.PathTaperX; | 642 | row["PathTaperX"] = s.PathTaperX; |
643 | row["PathTaperY"] = s.PathTaperY; | 643 | row["PathTaperY"] = s.PathTaperY; |
644 | row["PathTwist"] = s.PathTwist; | 644 | row["PathTwist"] = s.PathTwist; |
645 | row["PathTwistBegin"] = s.PathTwistBegin; | 645 | row["PathTwistBegin"] = s.PathTwistBegin; |
646 | // profile | 646 | // profile |
647 | row["ProfileBegin"] = s.ProfileBegin; | 647 | row["ProfileBegin"] = s.ProfileBegin; |
648 | row["ProfileEnd"] = s.ProfileEnd; | 648 | row["ProfileEnd"] = s.ProfileEnd; |
649 | row["ProfileCurve"] = s.ProfileCurve; | 649 | row["ProfileCurve"] = s.ProfileCurve; |
650 | row["ProfileHollow"] = s.ProfileHollow; | 650 | row["ProfileHollow"] = s.ProfileHollow; |
651 | row["Texture"] = s.TextureEntry; | 651 | row["Texture"] = s.TextureEntry; |
652 | row["ExtraParams"] = s.ExtraParams; | 652 | row["ExtraParams"] = s.ExtraParams; |
653 | } | 653 | } |
654 | 654 | ||
655 | private void addPrim(SceneObjectPart prim, LLUUID sceneGroupID, LLUUID regionUUID) | 655 | private void addPrim(SceneObjectPart prim, LLUUID sceneGroupID, LLUUID regionUUID) |
656 | { | 656 | { |
657 | DataTable prims = m_dataSet.Tables["prims"]; | 657 | DataTable prims = m_dataSet.Tables["prims"]; |
658 | DataTable shapes = m_dataSet.Tables["primshapes"]; | 658 | DataTable shapes = m_dataSet.Tables["primshapes"]; |
659 | 659 | ||
660 | DataRow primRow = prims.Rows.Find(prim.UUID); | 660 | DataRow primRow = prims.Rows.Find(prim.UUID); |
661 | if (primRow == null) | 661 | if (primRow == null) |
662 | { | 662 | { |
663 | primRow = prims.NewRow(); | 663 | primRow = prims.NewRow(); |
664 | fillPrimRow(primRow, prim, sceneGroupID, regionUUID); | 664 | fillPrimRow(primRow, prim, sceneGroupID, regionUUID); |
665 | prims.Rows.Add(primRow); | 665 | prims.Rows.Add(primRow); |
666 | } | 666 | } |
667 | else | 667 | else |
668 | { | 668 | { |
669 | fillPrimRow(primRow, prim, sceneGroupID, regionUUID); | 669 | fillPrimRow(primRow, prim, sceneGroupID, regionUUID); |
670 | } | 670 | } |
671 | 671 | ||
672 | DataRow shapeRow = shapes.Rows.Find(prim.UUID); | 672 | DataRow shapeRow = shapes.Rows.Find(prim.UUID); |
673 | if (shapeRow == null) | 673 | if (shapeRow == null) |
674 | { | 674 | { |
675 | shapeRow = shapes.NewRow(); | 675 | shapeRow = shapes.NewRow(); |
676 | fillShapeRow(shapeRow, prim); | 676 | fillShapeRow(shapeRow, prim); |
677 | shapes.Rows.Add(shapeRow); | 677 | shapes.Rows.Add(shapeRow); |
678 | } | 678 | } |
679 | else | 679 | else |
680 | { | 680 | { |
681 | fillShapeRow(shapeRow, prim); | 681 | fillShapeRow(shapeRow, prim); |
682 | } | 682 | } |
683 | } | 683 | } |
684 | 684 | ||
685 | /*********************************************************************** | 685 | /*********************************************************************** |
686 | * | 686 | * |
687 | * SQL Statement Creation Functions | 687 | * SQL Statement Creation Functions |
688 | * | 688 | * |
689 | * These functions create SQL statements for update, insert, and create. | 689 | * These functions create SQL statements for update, insert, and create. |
690 | * They can probably be factored later to have a db independant | 690 | * They can probably be factored later to have a db independant |
691 | * portion and a db specific portion | 691 | * portion and a db specific portion |
692 | * | 692 | * |
693 | **********************************************************************/ | 693 | **********************************************************************/ |
694 | 694 | ||
695 | private MySqlCommand createInsertCommand(string table, DataTable dt) | 695 | private MySqlCommand createInsertCommand(string table, DataTable dt) |
696 | { | 696 | { |
697 | /** | 697 | /** |
698 | * This is subtle enough to deserve some commentary. | 698 | * This is subtle enough to deserve some commentary. |
699 | * Instead of doing *lots* and *lots of hardcoded strings | 699 | * Instead of doing *lots* and *lots of hardcoded strings |
700 | * for database definitions we'll use the fact that | 700 | * for database definitions we'll use the fact that |
701 | * realistically all insert statements look like "insert | 701 | * realistically all insert statements look like "insert |
702 | * into A(b, c) values(:b, :c) on the parameterized query | 702 | * into A(b, c) values(:b, :c) on the parameterized query |
703 | * front. If we just have a list of b, c, etc... we can | 703 | * front. If we just have a list of b, c, etc... we can |
704 | * generate these strings instead of typing them out. | 704 | * generate these strings instead of typing them out. |
705 | */ | 705 | */ |
706 | string[] cols = new string[dt.Columns.Count]; | 706 | string[] cols = new string[dt.Columns.Count]; |
707 | for (int i = 0; i < dt.Columns.Count; i++) | 707 | for (int i = 0; i < dt.Columns.Count; i++) |
708 | { | 708 | { |
709 | DataColumn col = dt.Columns[i]; | 709 | DataColumn col = dt.Columns[i]; |
710 | cols[i] = col.ColumnName; | 710 | cols[i] = col.ColumnName; |
711 | } | 711 | } |
712 | 712 | ||
713 | string sql = "insert into " + table + "("; | 713 | string sql = "insert into " + table + "("; |
714 | sql += String.Join(", ", cols); | 714 | sql += String.Join(", ", cols); |
715 | // important, the first ':' needs to be here, the rest get added in the join | 715 | // important, the first ':' needs to be here, the rest get added in the join |
716 | sql += ") values (?"; | 716 | sql += ") values (?"; |
717 | sql += String.Join(", ?", cols); | 717 | sql += String.Join(", ?", cols); |
718 | sql += ")"; | 718 | sql += ")"; |
719 | MySqlCommand cmd = new MySqlCommand(sql); | 719 | MySqlCommand cmd = new MySqlCommand(sql); |
720 | 720 | ||
721 | // this provides the binding for all our parameters, so | 721 | // this provides the binding for all our parameters, so |
722 | // much less code than it used to be | 722 | // much less code than it used to be |
723 | foreach (DataColumn col in dt.Columns) | 723 | foreach (DataColumn col in dt.Columns) |
724 | { | 724 | { |
725 | cmd.Parameters.Add(createMySqlParameter(col.ColumnName, col.DataType)); | 725 | cmd.Parameters.Add(createMySqlParameter(col.ColumnName, col.DataType)); |
726 | } | 726 | } |
727 | return cmd; | 727 | return cmd; |
728 | } | 728 | } |
729 | 729 | ||
730 | private MySqlCommand createUpdateCommand(string table, string pk, DataTable dt) | 730 | private MySqlCommand createUpdateCommand(string table, string pk, DataTable dt) |
731 | { | 731 | { |
732 | string sql = "update " + table + " set "; | 732 | string sql = "update " + table + " set "; |
733 | string subsql = ""; | 733 | string subsql = ""; |
734 | foreach (DataColumn col in dt.Columns) | 734 | foreach (DataColumn col in dt.Columns) |
735 | { | 735 | { |
736 | if (subsql.Length > 0) | 736 | if (subsql.Length > 0) |
737 | { | 737 | { |
738 | // a map function would rock so much here | 738 | // a map function would rock so much here |
739 | subsql += ", "; | 739 | subsql += ", "; |
740 | } | 740 | } |
741 | subsql += col.ColumnName + "=?" + col.ColumnName; | 741 | subsql += col.ColumnName + "=?" + col.ColumnName; |
742 | } | 742 | } |
743 | sql += subsql; | 743 | sql += subsql; |
744 | sql += " where " + pk; | 744 | sql += " where " + pk; |
745 | MySqlCommand cmd = new MySqlCommand(sql); | 745 | MySqlCommand cmd = new MySqlCommand(sql); |
746 | 746 | ||
747 | // this provides the binding for all our parameters, so | 747 | // this provides the binding for all our parameters, so |
748 | // much less code than it used to be | 748 | // much less code than it used to be |
749 | 749 | ||
750 | foreach (DataColumn col in dt.Columns) | 750 | foreach (DataColumn col in dt.Columns) |
751 | { | 751 | { |
752 | cmd.Parameters.Add(createMySqlParameter(col.ColumnName, col.DataType)); | 752 | cmd.Parameters.Add(createMySqlParameter(col.ColumnName, col.DataType)); |
753 | } | 753 | } |
754 | return cmd; | 754 | return cmd; |
755 | } | 755 | } |
756 | 756 | ||
757 | 757 | ||
758 | private string defineTable(DataTable dt) | 758 | private string defineTable(DataTable dt) |
759 | { | 759 | { |
760 | string sql = "create table " + dt.TableName + "("; | 760 | string sql = "create table " + dt.TableName + "("; |
761 | string subsql = ""; | 761 | string subsql = ""; |
762 | foreach (DataColumn col in dt.Columns) | 762 | foreach (DataColumn col in dt.Columns) |
763 | { | 763 | { |
764 | if (subsql.Length > 0) | 764 | if (subsql.Length > 0) |
765 | { | 765 | { |
766 | // a map function would rock so much here | 766 | // a map function would rock so much here |
767 | subsql += ",\n"; | 767 | subsql += ",\n"; |
768 | } | 768 | } |
769 | subsql += col.ColumnName + " " + MySqlType(col.DataType); | 769 | subsql += col.ColumnName + " " + MySqlType(col.DataType); |
770 | if (dt.PrimaryKey.Length > 0 && col == dt.PrimaryKey[0]) | 770 | if (dt.PrimaryKey.Length > 0 && col == dt.PrimaryKey[0]) |
771 | { | 771 | { |
772 | subsql += " primary key"; | 772 | subsql += " primary key"; |
773 | } | 773 | } |
774 | } | 774 | } |
775 | sql += subsql; | 775 | sql += subsql; |
776 | sql += ")"; | 776 | sql += ")"; |
777 | return sql; | 777 | return sql; |
778 | } | 778 | } |
779 | 779 | ||
780 | /*********************************************************************** | 780 | /*********************************************************************** |
781 | * | 781 | * |
782 | * Database Binding functions | 782 | * Database Binding functions |
783 | * | 783 | * |
784 | * These will be db specific due to typing, and minor differences | 784 | * These will be db specific due to typing, and minor differences |
785 | * in databases. | 785 | * in databases. |
786 | * | 786 | * |
787 | **********************************************************************/ | 787 | **********************************************************************/ |
788 | 788 | ||
789 | ///<summary> | 789 | ///<summary> |
790 | /// This is a convenience function that collapses 5 repetitive | 790 | /// This is a convenience function that collapses 5 repetitive |
791 | /// lines for defining MySqlParameters to 2 parameters: | 791 | /// lines for defining MySqlParameters to 2 parameters: |
792 | /// column name and database type. | 792 | /// column name and database type. |
793 | /// | 793 | /// |
794 | /// It assumes certain conventions like ?param as the param | 794 | /// It assumes certain conventions like ?param as the param |
795 | /// name to replace in parametrized queries, and that source | 795 | /// name to replace in parametrized queries, and that source |
796 | /// version is always current version, both of which are fine | 796 | /// version is always current version, both of which are fine |
797 | /// for us. | 797 | /// for us. |
798 | ///</summary> | 798 | ///</summary> |
799 | ///<returns>a built MySql parameter</returns> | 799 | ///<returns>a built MySql parameter</returns> |
800 | private MySqlParameter createMySqlParameter(string name, Type type) | 800 | private MySqlParameter createMySqlParameter(string name, Type type) |
801 | { | 801 | { |
802 | MySqlParameter param = new MySqlParameter(); | 802 | MySqlParameter param = new MySqlParameter(); |
803 | param.ParameterName = "?" + name; | 803 | param.ParameterName = "?" + name; |
804 | param.DbType = dbtypeFromType(type); | 804 | param.DbType = dbtypeFromType(type); |
805 | param.SourceColumn = name; | 805 | param.SourceColumn = name; |
806 | param.SourceVersion = DataRowVersion.Current; | 806 | param.SourceVersion = DataRowVersion.Current; |
807 | return param; | 807 | return param; |
808 | } | 808 | } |
809 | 809 | ||
810 | private MySqlParameter createParamWithValue(string name, Type type, Object o) | 810 | private MySqlParameter createParamWithValue(string name, Type type, Object o) |
811 | { | 811 | { |
812 | MySqlParameter param = createMySqlParameter(name, type); | 812 | MySqlParameter param = createMySqlParameter(name, type); |
813 | param.Value = o; | 813 | param.Value = o; |
814 | return param; | 814 | return param; |
815 | } | 815 | } |
816 | 816 | ||
817 | private void SetupPrimCommands(MySqlDataAdapter da, MySqlConnection conn) | 817 | private void SetupPrimCommands(MySqlDataAdapter da, MySqlConnection conn) |
818 | { | 818 | { |
819 | MySqlCommand insertCommand = createInsertCommand("prims", m_primTable); | 819 | MySqlCommand insertCommand = createInsertCommand("prims", m_primTable); |
820 | insertCommand.Connection = conn; | 820 | insertCommand.Connection = conn; |
821 | da.InsertCommand = insertCommand; | 821 | da.InsertCommand = insertCommand; |
822 | 822 | ||
823 | MySqlCommand updateCommand = createUpdateCommand("prims", "UUID=?UUID", m_primTable); | 823 | MySqlCommand updateCommand = createUpdateCommand("prims", "UUID=?UUID", m_primTable); |
824 | updateCommand.Connection = conn; | 824 | updateCommand.Connection = conn; |
825 | da.UpdateCommand = updateCommand; | 825 | da.UpdateCommand = updateCommand; |
826 | 826 | ||
827 | MySqlCommand delete = new MySqlCommand("delete from prims where UUID=?UUID"); | 827 | MySqlCommand delete = new MySqlCommand("delete from prims where UUID=?UUID"); |
828 | delete.Parameters.Add(createMySqlParameter("UUID", typeof(String))); | 828 | delete.Parameters.Add(createMySqlParameter("UUID", typeof(String))); |
829 | delete.Connection = conn; | 829 | delete.Connection = conn; |
830 | da.DeleteCommand = delete; | 830 | da.DeleteCommand = delete; |
831 | } | 831 | } |
832 | 832 | ||
833 | private void SetupTerrainCommands(MySqlDataAdapter da, MySqlConnection conn) | 833 | private void SetupTerrainCommands(MySqlDataAdapter da, MySqlConnection conn) |
834 | { | 834 | { |
835 | da.InsertCommand = createInsertCommand("terrain", m_dataSet.Tables["terrain"]); | 835 | da.InsertCommand = createInsertCommand("terrain", m_dataSet.Tables["terrain"]); |
836 | da.InsertCommand.Connection = conn; | 836 | da.InsertCommand.Connection = conn; |
837 | } | 837 | } |
838 | 838 | ||
839 | private void SetupShapeCommands(MySqlDataAdapter da, MySqlConnection conn) | 839 | private void SetupShapeCommands(MySqlDataAdapter da, MySqlConnection conn) |
840 | { | 840 | { |
841 | da.InsertCommand = createInsertCommand("primshapes", m_dataSet.Tables["primshapes"]); | 841 | da.InsertCommand = createInsertCommand("primshapes", m_dataSet.Tables["primshapes"]); |
842 | da.InsertCommand.Connection = conn; | 842 | da.InsertCommand.Connection = conn; |
843 | 843 | ||
844 | da.UpdateCommand = createUpdateCommand("primshapes", "UUID=?UUID", m_dataSet.Tables["primshapes"]); | 844 | da.UpdateCommand = createUpdateCommand("primshapes", "UUID=?UUID", m_dataSet.Tables["primshapes"]); |
845 | da.UpdateCommand.Connection = conn; | 845 | da.UpdateCommand.Connection = conn; |
846 | 846 | ||
847 | MySqlCommand delete = new MySqlCommand("delete from primshapes where UUID = ?UUID"); | 847 | MySqlCommand delete = new MySqlCommand("delete from primshapes where UUID = ?UUID"); |
848 | delete.Parameters.Add(createMySqlParameter("UUID", typeof(String))); | 848 | delete.Parameters.Add(createMySqlParameter("UUID", typeof(String))); |
849 | delete.Connection = conn; | 849 | delete.Connection = conn; |
850 | da.DeleteCommand = delete; | 850 | da.DeleteCommand = delete; |
851 | } | 851 | } |
852 | 852 | ||
853 | private void InitDB(MySqlConnection conn) | 853 | private void InitDB(MySqlConnection conn) |
854 | { | 854 | { |
855 | string createPrims = defineTable(createPrimTable()); | 855 | string createPrims = defineTable(createPrimTable()); |
856 | string createShapes = defineTable(createShapeTable()); | 856 | string createShapes = defineTable(createShapeTable()); |
857 | string createTerrain = defineTable(createTerrainTable()); | 857 | string createTerrain = defineTable(createTerrainTable()); |
858 | 858 | ||
859 | MySqlCommand pcmd = new MySqlCommand(createPrims, conn); | 859 | MySqlCommand pcmd = new MySqlCommand(createPrims, conn); |
860 | MySqlCommand scmd = new MySqlCommand(createShapes, conn); | 860 | MySqlCommand scmd = new MySqlCommand(createShapes, conn); |
861 | MySqlCommand tcmd = new MySqlCommand(createTerrain, conn); | 861 | MySqlCommand tcmd = new MySqlCommand(createTerrain, conn); |
862 | 862 | ||
863 | if (conn.State != ConnectionState.Open) | 863 | if (conn.State != ConnectionState.Open) |
864 | { | 864 | { |
865 | conn.Open(); | 865 | conn.Open(); |
866 | } | 866 | } |
867 | 867 | ||
868 | try | 868 | try |
869 | { | 869 | { |
870 | pcmd.ExecuteNonQuery(); | 870 | pcmd.ExecuteNonQuery(); |
871 | } | 871 | } |
872 | catch (MySqlException) | 872 | catch (MySqlException) |
873 | { | 873 | { |
874 | MainLog.Instance.Warn("MySql", "Primitives Table Already Exists"); | 874 | MainLog.Instance.Warn("MySql", "Primitives Table Already Exists"); |
875 | } | 875 | } |
876 | 876 | ||
877 | try | 877 | try |
878 | { | 878 | { |
879 | scmd.ExecuteNonQuery(); | 879 | scmd.ExecuteNonQuery(); |
880 | } | 880 | } |
881 | catch (MySqlException) | 881 | catch (MySqlException) |
882 | { | 882 | { |
883 | MainLog.Instance.Warn("MySql", "Shapes Table Already Exists"); | 883 | MainLog.Instance.Warn("MySql", "Shapes Table Already Exists"); |
884 | } | 884 | } |
885 | 885 | ||
886 | try | 886 | try |
887 | { | 887 | { |
888 | tcmd.ExecuteNonQuery(); | 888 | tcmd.ExecuteNonQuery(); |
889 | } | 889 | } |
890 | catch (MySqlException) | 890 | catch (MySqlException) |
891 | { | 891 | { |
892 | MainLog.Instance.Warn("MySql", "Terrain Table Already Exists"); | 892 | MainLog.Instance.Warn("MySql", "Terrain Table Already Exists"); |
893 | } | 893 | } |
894 | 894 | ||
895 | conn.Close(); | 895 | conn.Close(); |
896 | } | 896 | } |
897 | 897 | ||
898 | private bool TestTables(MySqlConnection conn) | 898 | private bool TestTables(MySqlConnection conn) |
899 | { | 899 | { |
900 | MySqlCommand primSelectCmd = new MySqlCommand(m_primSelect, conn); | 900 | MySqlCommand primSelectCmd = new MySqlCommand(m_primSelect, conn); |
901 | MySqlDataAdapter pDa = new MySqlDataAdapter(primSelectCmd); | 901 | MySqlDataAdapter pDa = new MySqlDataAdapter(primSelectCmd); |
902 | MySqlCommand shapeSelectCmd = new MySqlCommand(m_shapeSelect, conn); | 902 | MySqlCommand shapeSelectCmd = new MySqlCommand(m_shapeSelect, conn); |
903 | MySqlDataAdapter sDa = new MySqlDataAdapter(shapeSelectCmd); | 903 | MySqlDataAdapter sDa = new MySqlDataAdapter(shapeSelectCmd); |
904 | MySqlCommand terrainSelectCmd = new MySqlCommand(m_terrainSelect, conn); | 904 | MySqlCommand terrainSelectCmd = new MySqlCommand(m_terrainSelect, conn); |
905 | MySqlDataAdapter tDa = new MySqlDataAdapter(terrainSelectCmd); | 905 | MySqlDataAdapter tDa = new MySqlDataAdapter(terrainSelectCmd); |
906 | 906 | ||
907 | DataSet tmpDS = new DataSet(); | 907 | DataSet tmpDS = new DataSet(); |
908 | try | 908 | try |
909 | { | 909 | { |
910 | pDa.Fill(tmpDS, "prims"); | 910 | pDa.Fill(tmpDS, "prims"); |
911 | sDa.Fill(tmpDS, "primshapes"); | 911 | sDa.Fill(tmpDS, "primshapes"); |
912 | tDa.Fill(tmpDS, "terrain"); | 912 | tDa.Fill(tmpDS, "terrain"); |
913 | } | 913 | } |
914 | catch (MySqlException) | 914 | catch (MySqlException) |
915 | { | 915 | { |
916 | MainLog.Instance.Verbose("DATASTORE", "MySql Database doesn't exist... creating"); | 916 | MainLog.Instance.Verbose("DATASTORE", "MySql Database doesn't exist... creating"); |
917 | InitDB(conn); | 917 | InitDB(conn); |
918 | } | 918 | } |
919 | 919 | ||
920 | pDa.Fill(tmpDS, "prims"); | 920 | pDa.Fill(tmpDS, "prims"); |
921 | sDa.Fill(tmpDS, "primshapes"); | 921 | sDa.Fill(tmpDS, "primshapes"); |
922 | tDa.Fill(tmpDS, "terrain"); | 922 | tDa.Fill(tmpDS, "terrain"); |
923 | 923 | ||
924 | foreach (DataColumn col in createPrimTable().Columns) | 924 | foreach (DataColumn col in createPrimTable().Columns) |
925 | { | 925 | { |
926 | if (!tmpDS.Tables["prims"].Columns.Contains(col.ColumnName)) | 926 | if (!tmpDS.Tables["prims"].Columns.Contains(col.ColumnName)) |
927 | { | 927 | { |
928 | MainLog.Instance.Verbose("DATASTORE", "Missing required column:" + col.ColumnName); | 928 | MainLog.Instance.Verbose("DATASTORE", "Missing required column:" + col.ColumnName); |
929 | return false; | 929 | return false; |
930 | } | 930 | } |
931 | } | 931 | } |
932 | foreach (DataColumn col in createShapeTable().Columns) | 932 | foreach (DataColumn col in createShapeTable().Columns) |
933 | { | 933 | { |
934 | if (!tmpDS.Tables["primshapes"].Columns.Contains(col.ColumnName)) | 934 | if (!tmpDS.Tables["primshapes"].Columns.Contains(col.ColumnName)) |
935 | { | 935 | { |
936 | MainLog.Instance.Verbose("DATASTORE", "Missing required column:" + col.ColumnName); | 936 | MainLog.Instance.Verbose("DATASTORE", "Missing required column:" + col.ColumnName); |
937 | return false; | 937 | return false; |
938 | } | 938 | } |
939 | } | 939 | } |
940 | foreach (DataColumn col in createTerrainTable().Columns) | 940 | foreach (DataColumn col in createTerrainTable().Columns) |
941 | { | 941 | { |
942 | if (!tmpDS.Tables["terrain"].Columns.Contains(col.ColumnName)) | 942 | if (!tmpDS.Tables["terrain"].Columns.Contains(col.ColumnName)) |
943 | { | 943 | { |
944 | MainLog.Instance.Verbose("DATASTORE", "Missing require column:" + col.ColumnName); | 944 | MainLog.Instance.Verbose("DATASTORE", "Missing require column:" + col.ColumnName); |
945 | return false; | 945 | return false; |
946 | } | 946 | } |
947 | } | 947 | } |
948 | return true; | 948 | return true; |
949 | } | 949 | } |
950 | 950 | ||
951 | /*********************************************************************** | 951 | /*********************************************************************** |
952 | * | 952 | * |
953 | * Type conversion functions | 953 | * Type conversion functions |
954 | * | 954 | * |
955 | **********************************************************************/ | 955 | **********************************************************************/ |
956 | 956 | ||
957 | private DbType dbtypeFromType(Type type) | 957 | private DbType dbtypeFromType(Type type) |
958 | { | 958 | { |
959 | if (type == typeof(String)) | 959 | if (type == typeof(String)) |
960 | { | 960 | { |
961 | return DbType.String; | 961 | return DbType.String; |
962 | } | 962 | } |
963 | else if (type == typeof(Int32)) | 963 | else if (type == typeof(Int32)) |
964 | { | 964 | { |
965 | return DbType.Int32; | 965 | return DbType.Int32; |
966 | } | 966 | } |
967 | else if (type == typeof(Double)) | 967 | else if (type == typeof(Double)) |
968 | { | 968 | { |
969 | return DbType.Double; | 969 | return DbType.Double; |
970 | } | 970 | } |
971 | else if (type == typeof(Byte)) | 971 | else if (type == typeof(Byte)) |
972 | { | 972 | { |
973 | return DbType.Byte; | 973 | return DbType.Byte; |
974 | } | 974 | } |
975 | else if (type == typeof(Double)) | 975 | else if (type == typeof(Double)) |
976 | { | 976 | { |
977 | return DbType.Double; | 977 | return DbType.Double; |
978 | } | 978 | } |
979 | else if (type == typeof(Byte[])) | 979 | else if (type == typeof(Byte[])) |
980 | { | 980 | { |
981 | return DbType.Binary; | 981 | return DbType.Binary; |
982 | } | 982 | } |
983 | else | 983 | else |
984 | { | 984 | { |
985 | return DbType.String; | 985 | return DbType.String; |
986 | } | 986 | } |
987 | } | 987 | } |
988 | 988 | ||
989 | // this is something we'll need to implement for each db | 989 | // this is something we'll need to implement for each db |
990 | // slightly differently. | 990 | // slightly differently. |
991 | private string MySqlType(Type type) | 991 | private string MySqlType(Type type) |
992 | { | 992 | { |
993 | if (type == typeof(String)) | 993 | if (type == typeof(String)) |
994 | { | 994 | { |
995 | return "varchar(255)"; | 995 | return "varchar(255)"; |
996 | } | 996 | } |
997 | else if (type == typeof(Int32)) | 997 | else if (type == typeof(Int32)) |
998 | { | 998 | { |
999 | return "integer"; | 999 | return "integer"; |
1000 | } | 1000 | } |
1001 | else if (type == typeof(Double)) | 1001 | else if (type == typeof(Double)) |
1002 | { | 1002 | { |
1003 | return "float"; | 1003 | return "float"; |
1004 | } | 1004 | } |
1005 | else if (type == typeof(Byte[])) | 1005 | else if (type == typeof(Byte[])) |
1006 | { | 1006 | { |
1007 | return "longblob"; | 1007 | return "longblob"; |
1008 | } | 1008 | } |
1009 | else | 1009 | else |
1010 | { | 1010 | { |
1011 | return "string"; | 1011 | return "string"; |
1012 | } | 1012 | } |
1013 | } | 1013 | } |
1014 | } | 1014 | } |
1015 | } | 1015 | } |