diff options
author | Sean Dague | 2008-01-14 19:47:59 +0000 |
---|---|---|
committer | Sean Dague | 2008-01-14 19:47:59 +0000 |
commit | db40ffb43fc107d94a59930099b63773b1973b47 (patch) | |
tree | fa4c436197f25dc3aa0bdc7e4f0f8f7078e8d7b5 /OpenSim/Framework | |
parent | * First pass at collidable linksets (diff) | |
download | opensim-SC-db40ffb43fc107d94a59930099b63773b1973b47.zip opensim-SC-db40ffb43fc107d94a59930099b63773b1973b47.tar.gz opensim-SC-db40ffb43fc107d94a59930099b63773b1973b47.tar.bz2 opensim-SC-db40ffb43fc107d94a59930099b63773b1973b47.tar.xz |
move db open to initialization, which is where it should have been
all allong
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Data.SQLite/SQLiteRegionData.cs | 62 |
1 files changed, 22 insertions, 40 deletions
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteRegionData.cs b/OpenSim/Framework/Data.SQLite/SQLiteRegionData.cs index dfd4535..33b4111 100644 --- a/OpenSim/Framework/Data.SQLite/SQLiteRegionData.cs +++ b/OpenSim/Framework/Data.SQLite/SQLiteRegionData.cs | |||
@@ -79,60 +79,58 @@ namespace OpenSim.Framework.Data.SQLite | |||
79 | ds = new DataSet(); | 79 | ds = new DataSet(); |
80 | 80 | ||
81 | MainLog.Instance.Verbose("DATASTORE", "Sqlite - connecting: " + connectionString); | 81 | MainLog.Instance.Verbose("DATASTORE", "Sqlite - connecting: " + connectionString); |
82 | SqliteConnection conn = new SqliteConnection(m_connectionString); | 82 | m_conn = new SqliteConnection(m_connectionString); |
83 | m_conn.Open(); | ||
83 | 84 | ||
84 | // Arg! Hate databases.. | 85 | SqliteCommand primSelectCmd = new SqliteCommand(primSelect, m_conn); |
85 | m_conn = conn; | ||
86 | |||
87 | SqliteCommand primSelectCmd = new SqliteCommand(primSelect, conn); | ||
88 | primDa = new SqliteDataAdapter(primSelectCmd); | 86 | primDa = new SqliteDataAdapter(primSelectCmd); |
89 | // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa); | 87 | // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa); |
90 | 88 | ||
91 | SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, conn); | 89 | SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, m_conn); |
92 | shapeDa = new SqliteDataAdapter(shapeSelectCmd); | 90 | shapeDa = new SqliteDataAdapter(shapeSelectCmd); |
93 | // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa); | 91 | // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa); |
94 | 92 | ||
95 | SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, conn); | 93 | SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, m_conn); |
96 | itemsDa = new SqliteDataAdapter(itemsSelectCmd); | 94 | itemsDa = new SqliteDataAdapter(itemsSelectCmd); |
97 | 95 | ||
98 | SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, conn); | 96 | SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, m_conn); |
99 | terrainDa = new SqliteDataAdapter(terrainSelectCmd); | 97 | terrainDa = new SqliteDataAdapter(terrainSelectCmd); |
100 | 98 | ||
101 | SqliteCommand landSelectCmd = new SqliteCommand(landSelect, conn); | 99 | SqliteCommand landSelectCmd = new SqliteCommand(landSelect, m_conn); |
102 | landDa = new SqliteDataAdapter(landSelectCmd); | 100 | landDa = new SqliteDataAdapter(landSelectCmd); |
103 | 101 | ||
104 | SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, conn); | 102 | SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn); |
105 | landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd); | 103 | landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd); |
106 | 104 | ||
107 | // We fill the data set, now we've got copies in memory for the information | 105 | // We fill the data set, now we've got copies in memory for the information |
108 | // TODO: see if the linkage actually holds. | 106 | // TODO: see if the linkage actually holds. |
109 | // primDa.FillSchema(ds, SchemaType.Source, "PrimSchema"); | 107 | // primDa.FillSchema(ds, SchemaType.Source, "PrimSchema"); |
110 | TestTables(conn); | 108 | TestTables(m_conn); |
111 | 109 | ||
112 | lock (ds) | 110 | lock (ds) |
113 | { | 111 | { |
114 | ds.Tables.Add(createPrimTable()); | 112 | ds.Tables.Add(createPrimTable()); |
115 | setupPrimCommands(primDa, conn); | 113 | setupPrimCommands(primDa, m_conn); |
116 | primDa.Fill(ds.Tables["prims"]); | 114 | primDa.Fill(ds.Tables["prims"]); |
117 | 115 | ||
118 | ds.Tables.Add(createShapeTable()); | 116 | ds.Tables.Add(createShapeTable()); |
119 | setupShapeCommands(shapeDa, conn); | 117 | setupShapeCommands(shapeDa, m_conn); |
120 | 118 | ||
121 | if (persistPrimInventories) | 119 | if (persistPrimInventories) |
122 | { | 120 | { |
123 | ds.Tables.Add(createItemsTable()); | 121 | ds.Tables.Add(createItemsTable()); |
124 | setupItemsCommands(itemsDa, conn); | 122 | setupItemsCommands(itemsDa, m_conn); |
125 | itemsDa.Fill(ds.Tables["primitems"]); | 123 | itemsDa.Fill(ds.Tables["primitems"]); |
126 | } | 124 | } |
127 | 125 | ||
128 | ds.Tables.Add(createTerrainTable()); | 126 | ds.Tables.Add(createTerrainTable()); |
129 | setupTerrainCommands(terrainDa, conn); | 127 | setupTerrainCommands(terrainDa, m_conn); |
130 | 128 | ||
131 | ds.Tables.Add(createLandTable()); | 129 | ds.Tables.Add(createLandTable()); |
132 | setupLandCommands(landDa, conn); | 130 | setupLandCommands(landDa, m_conn); |
133 | 131 | ||
134 | ds.Tables.Add(createLandAccessListTable()); | 132 | ds.Tables.Add(createLandAccessListTable()); |
135 | setupLandAccessCommands(landAccessListDa, conn); | 133 | setupLandAccessCommands(landAccessListDa, m_conn); |
136 | 134 | ||
137 | // WORKAROUND: This is a work around for sqlite on | 135 | // WORKAROUND: This is a work around for sqlite on |
138 | // windows, which gets really unhappy with blob columns | 136 | // windows, which gets really unhappy with blob columns |
@@ -374,13 +372,11 @@ namespace OpenSim.Framework.Data.SQLite | |||
374 | 372 | ||
375 | // the following is an work around for .NET. The perf | 373 | // the following is an work around for .NET. The perf |
376 | // issues associated with it aren't as bad as you think. | 374 | // issues associated with it aren't as bad as you think. |
377 | SqliteConnection conn = new SqliteConnection(m_connectionString); | ||
378 | conn.Open(); | ||
379 | MainLog.Instance.Verbose("DATASTORE", "Storing terrain revision r" + revision.ToString()); | 375 | MainLog.Instance.Verbose("DATASTORE", "Storing terrain revision r" + revision.ToString()); |
380 | String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" + | 376 | String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" + |
381 | " values(:RegionUUID, :Revision, :Heightfield)"; | 377 | " values(:RegionUUID, :Revision, :Heightfield)"; |
382 | 378 | ||
383 | using (SqliteCommand cmd = new SqliteCommand(sql, conn)) | 379 | using (SqliteCommand cmd = new SqliteCommand(sql, m_conn)) |
384 | { | 380 | { |
385 | cmd.Parameters.Add(new SqliteParameter(":RegionUUID", Util.ToRawUuidString(regionID))); | 381 | cmd.Parameters.Add(new SqliteParameter(":RegionUUID", Util.ToRawUuidString(regionID))); |
386 | cmd.Parameters.Add(new SqliteParameter(":Revision", revision)); | 382 | cmd.Parameters.Add(new SqliteParameter(":Revision", revision)); |
@@ -398,13 +394,12 @@ namespace OpenSim.Framework.Data.SQLite | |||
398 | using ( | 394 | using ( |
399 | SqliteCommand cmd = | 395 | SqliteCommand cmd = |
400 | new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID and Revision < :Revision", | 396 | new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID and Revision < :Revision", |
401 | conn)) | 397 | m_conn)) |
402 | { | 398 | { |
403 | cmd.Parameters.Add(new SqliteParameter(":RegionUUID", Util.ToRawUuidString(regionID))); | 399 | cmd.Parameters.Add(new SqliteParameter(":RegionUUID", Util.ToRawUuidString(regionID))); |
404 | cmd.Parameters.Add(new SqliteParameter(":Revision", revision)); | 400 | cmd.Parameters.Add(new SqliteParameter(":Revision", revision)); |
405 | cmd.ExecuteNonQuery(); | 401 | cmd.ExecuteNonQuery(); |
406 | } | 402 | } |
407 | conn.Close(); | ||
408 | } | 403 | } |
409 | } | 404 | } |
410 | 405 | ||
@@ -414,15 +409,11 @@ namespace OpenSim.Framework.Data.SQLite | |||
414 | { | 409 | { |
415 | double[,] terret = new double[256,256]; | 410 | double[,] terret = new double[256,256]; |
416 | terret.Initialize(); | 411 | terret.Initialize(); |
417 | // the following is an work around for .NET. The perf | 412 | |
418 | // issues associated with it aren't as bad as you think. | ||
419 | SqliteConnection conn = new SqliteConnection(m_connectionString); | ||
420 | conn.Open(); | ||
421 | String sql = "select RegionUUID, Revision, Heightfield from terrain" + | 413 | String sql = "select RegionUUID, Revision, Heightfield from terrain" + |
422 | " where RegionUUID=:RegionUUID order by Revision desc"; | 414 | " where RegionUUID=:RegionUUID order by Revision desc"; |
423 | 415 | ||
424 | 416 | using (SqliteCommand cmd = new SqliteCommand(sql, m_conn)) | |
425 | using (SqliteCommand cmd = new SqliteCommand(sql, conn)) | ||
426 | { | 417 | { |
427 | cmd.Parameters.Add(new SqliteParameter(":RegionUUID", Util.ToRawUuidString(regionID))); | 418 | cmd.Parameters.Add(new SqliteParameter(":RegionUUID", Util.ToRawUuidString(regionID))); |
428 | 419 | ||
@@ -445,14 +436,12 @@ namespace OpenSim.Framework.Data.SQLite | |||
445 | else | 436 | else |
446 | { | 437 | { |
447 | MainLog.Instance.Verbose("DATASTORE", "No terrain found for region"); | 438 | MainLog.Instance.Verbose("DATASTORE", "No terrain found for region"); |
448 | conn.Close(); | ||
449 | return null; | 439 | return null; |
450 | } | 440 | } |
451 | 441 | ||
452 | MainLog.Instance.Verbose("DATASTORE", "Loaded terrain revision r" + rev.ToString()); | 442 | MainLog.Instance.Verbose("DATASTORE", "Loaded terrain revision r" + rev.ToString()); |
453 | } | 443 | } |
454 | } | 444 | } |
455 | conn.Close(); | ||
456 | return terret; | 445 | return terret; |
457 | } | 446 | } |
458 | } | 447 | } |
@@ -461,21 +450,17 @@ namespace OpenSim.Framework.Data.SQLite | |||
461 | { | 450 | { |
462 | lock (ds) | 451 | lock (ds) |
463 | { | 452 | { |
464 | SqliteConnection conn = new SqliteConnection(m_connectionString); | 453 | using (SqliteCommand cmd = new SqliteCommand("delete from land where UUID=:UUID", m_conn)) |
465 | conn.Open(); | ||
466 | |||
467 | using (SqliteCommand cmd = new SqliteCommand("delete from land where UUID=:UUID", conn)) | ||
468 | { | 454 | { |
469 | cmd.Parameters.Add(new SqliteParameter(":UUID", Util.ToRawUuidString(globalID))); | 455 | cmd.Parameters.Add(new SqliteParameter(":UUID", Util.ToRawUuidString(globalID))); |
470 | cmd.ExecuteNonQuery(); | 456 | cmd.ExecuteNonQuery(); |
471 | } | 457 | } |
472 | 458 | ||
473 | using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:UUID", conn)) | 459 | using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:UUID", m_conn)) |
474 | { | 460 | { |
475 | cmd.Parameters.Add(new SqliteParameter(":UUID", Util.ToRawUuidString(globalID))); | 461 | cmd.Parameters.Add(new SqliteParameter(":UUID", Util.ToRawUuidString(globalID))); |
476 | cmd.ExecuteNonQuery(); | 462 | cmd.ExecuteNonQuery(); |
477 | } | 463 | } |
478 | conn.Close(); | ||
479 | } | 464 | } |
480 | } | 465 | } |
481 | 466 | ||
@@ -483,8 +468,6 @@ namespace OpenSim.Framework.Data.SQLite | |||
483 | { | 468 | { |
484 | lock (ds) | 469 | lock (ds) |
485 | { | 470 | { |
486 | SqliteConnection conn = new SqliteConnection(m_connectionString); | ||
487 | conn.Open(); | ||
488 | DataTable land = ds.Tables["land"]; | 471 | DataTable land = ds.Tables["land"]; |
489 | DataTable landaccesslist = ds.Tables["landaccesslist"]; | 472 | DataTable landaccesslist = ds.Tables["landaccesslist"]; |
490 | 473 | ||
@@ -501,7 +484,7 @@ namespace OpenSim.Framework.Data.SQLite | |||
501 | } | 484 | } |
502 | 485 | ||
503 | using ( | 486 | using ( |
504 | SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:LandUUID", conn)) | 487 | SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:LandUUID", m_conn)) |
505 | { | 488 | { |
506 | cmd.Parameters.Add(new SqliteParameter(":LandUUID", Util.ToRawUuidString(parcel.landData.globalID))); | 489 | cmd.Parameters.Add(new SqliteParameter(":LandUUID", Util.ToRawUuidString(parcel.landData.globalID))); |
507 | cmd.ExecuteNonQuery(); | 490 | cmd.ExecuteNonQuery(); |
@@ -513,7 +496,6 @@ namespace OpenSim.Framework.Data.SQLite | |||
513 | fillLandAccessRow(newAccessRow, entry, parcel.landData.globalID); | 496 | fillLandAccessRow(newAccessRow, entry, parcel.landData.globalID); |
514 | landaccesslist.Rows.Add(newAccessRow); | 497 | landaccesslist.Rows.Add(newAccessRow); |
515 | } | 498 | } |
516 | conn.Close(); | ||
517 | } | 499 | } |
518 | 500 | ||
519 | Commit(); | 501 | Commit(); |