move db open to initialization, which is where it should have been

all allong
ThreadPoolClientBranch
Sean Dague 2008-01-14 19:47:59 +00:00
parent a522d7844b
commit db40ffb43f
1 changed files with 22 additions and 40 deletions

View File

@ -79,60 +79,58 @@ namespace OpenSim.Framework.Data.SQLite
ds = new DataSet(); ds = new DataSet();
MainLog.Instance.Verbose("DATASTORE", "Sqlite - connecting: " + connectionString); MainLog.Instance.Verbose("DATASTORE", "Sqlite - connecting: " + connectionString);
SqliteConnection conn = new SqliteConnection(m_connectionString); m_conn = new SqliteConnection(m_connectionString);
m_conn.Open();
// Arg! Hate databases.. SqliteCommand primSelectCmd = new SqliteCommand(primSelect, m_conn);
m_conn = conn;
SqliteCommand primSelectCmd = new SqliteCommand(primSelect, conn);
primDa = new SqliteDataAdapter(primSelectCmd); primDa = new SqliteDataAdapter(primSelectCmd);
// SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa); // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa);
SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, conn); SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, m_conn);
shapeDa = new SqliteDataAdapter(shapeSelectCmd); shapeDa = new SqliteDataAdapter(shapeSelectCmd);
// SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa); // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa);
SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, conn); SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, m_conn);
itemsDa = new SqliteDataAdapter(itemsSelectCmd); itemsDa = new SqliteDataAdapter(itemsSelectCmd);
SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, conn); SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, m_conn);
terrainDa = new SqliteDataAdapter(terrainSelectCmd); terrainDa = new SqliteDataAdapter(terrainSelectCmd);
SqliteCommand landSelectCmd = new SqliteCommand(landSelect, conn); SqliteCommand landSelectCmd = new SqliteCommand(landSelect, m_conn);
landDa = new SqliteDataAdapter(landSelectCmd); landDa = new SqliteDataAdapter(landSelectCmd);
SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, conn); SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn);
landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd); landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd);
// We fill the data set, now we've got copies in memory for the information // We fill the data set, now we've got copies in memory for the information
// TODO: see if the linkage actually holds. // TODO: see if the linkage actually holds.
// primDa.FillSchema(ds, SchemaType.Source, "PrimSchema"); // primDa.FillSchema(ds, SchemaType.Source, "PrimSchema");
TestTables(conn); TestTables(m_conn);
lock (ds) lock (ds)
{ {
ds.Tables.Add(createPrimTable()); ds.Tables.Add(createPrimTable());
setupPrimCommands(primDa, conn); setupPrimCommands(primDa, m_conn);
primDa.Fill(ds.Tables["prims"]); primDa.Fill(ds.Tables["prims"]);
ds.Tables.Add(createShapeTable()); ds.Tables.Add(createShapeTable());
setupShapeCommands(shapeDa, conn); setupShapeCommands(shapeDa, m_conn);
if (persistPrimInventories) if (persistPrimInventories)
{ {
ds.Tables.Add(createItemsTable()); ds.Tables.Add(createItemsTable());
setupItemsCommands(itemsDa, conn); setupItemsCommands(itemsDa, m_conn);
itemsDa.Fill(ds.Tables["primitems"]); itemsDa.Fill(ds.Tables["primitems"]);
} }
ds.Tables.Add(createTerrainTable()); ds.Tables.Add(createTerrainTable());
setupTerrainCommands(terrainDa, conn); setupTerrainCommands(terrainDa, m_conn);
ds.Tables.Add(createLandTable()); ds.Tables.Add(createLandTable());
setupLandCommands(landDa, conn); setupLandCommands(landDa, m_conn);
ds.Tables.Add(createLandAccessListTable()); ds.Tables.Add(createLandAccessListTable());
setupLandAccessCommands(landAccessListDa, conn); setupLandAccessCommands(landAccessListDa, m_conn);
// WORKAROUND: This is a work around for sqlite on // WORKAROUND: This is a work around for sqlite on
// windows, which gets really unhappy with blob columns // windows, which gets really unhappy with blob columns
@ -374,13 +372,11 @@ namespace OpenSim.Framework.Data.SQLite
// the following is an work around for .NET. The perf // the following is an work around for .NET. The perf
// issues associated with it aren't as bad as you think. // issues associated with it aren't as bad as you think.
SqliteConnection conn = new SqliteConnection(m_connectionString);
conn.Open();
MainLog.Instance.Verbose("DATASTORE", "Storing terrain revision r" + revision.ToString()); MainLog.Instance.Verbose("DATASTORE", "Storing terrain revision r" + revision.ToString());
String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" + String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" +
" values(:RegionUUID, :Revision, :Heightfield)"; " values(:RegionUUID, :Revision, :Heightfield)";
using (SqliteCommand cmd = new SqliteCommand(sql, conn)) using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
{ {
cmd.Parameters.Add(new SqliteParameter(":RegionUUID", Util.ToRawUuidString(regionID))); cmd.Parameters.Add(new SqliteParameter(":RegionUUID", Util.ToRawUuidString(regionID)));
cmd.Parameters.Add(new SqliteParameter(":Revision", revision)); cmd.Parameters.Add(new SqliteParameter(":Revision", revision));
@ -398,13 +394,12 @@ namespace OpenSim.Framework.Data.SQLite
using ( using (
SqliteCommand cmd = SqliteCommand cmd =
new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID and Revision < :Revision", new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID and Revision < :Revision",
conn)) m_conn))
{ {
cmd.Parameters.Add(new SqliteParameter(":RegionUUID", Util.ToRawUuidString(regionID))); cmd.Parameters.Add(new SqliteParameter(":RegionUUID", Util.ToRawUuidString(regionID)));
cmd.Parameters.Add(new SqliteParameter(":Revision", revision)); cmd.Parameters.Add(new SqliteParameter(":Revision", revision));
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
conn.Close();
} }
} }
@ -414,15 +409,11 @@ namespace OpenSim.Framework.Data.SQLite
{ {
double[,] terret = new double[256,256]; double[,] terret = new double[256,256];
terret.Initialize(); terret.Initialize();
// the following is an work around for .NET. The perf
// issues associated with it aren't as bad as you think.
SqliteConnection conn = new SqliteConnection(m_connectionString);
conn.Open();
String sql = "select RegionUUID, Revision, Heightfield from terrain" + String sql = "select RegionUUID, Revision, Heightfield from terrain" +
" where RegionUUID=:RegionUUID order by Revision desc"; " where RegionUUID=:RegionUUID order by Revision desc";
using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
using (SqliteCommand cmd = new SqliteCommand(sql, conn))
{ {
cmd.Parameters.Add(new SqliteParameter(":RegionUUID", Util.ToRawUuidString(regionID))); cmd.Parameters.Add(new SqliteParameter(":RegionUUID", Util.ToRawUuidString(regionID)));
@ -445,14 +436,12 @@ namespace OpenSim.Framework.Data.SQLite
else else
{ {
MainLog.Instance.Verbose("DATASTORE", "No terrain found for region"); MainLog.Instance.Verbose("DATASTORE", "No terrain found for region");
conn.Close();
return null; return null;
} }
MainLog.Instance.Verbose("DATASTORE", "Loaded terrain revision r" + rev.ToString()); MainLog.Instance.Verbose("DATASTORE", "Loaded terrain revision r" + rev.ToString());
} }
} }
conn.Close();
return terret; return terret;
} }
} }
@ -461,21 +450,17 @@ namespace OpenSim.Framework.Data.SQLite
{ {
lock (ds) lock (ds)
{ {
SqliteConnection conn = new SqliteConnection(m_connectionString); using (SqliteCommand cmd = new SqliteCommand("delete from land where UUID=:UUID", m_conn))
conn.Open();
using (SqliteCommand cmd = new SqliteCommand("delete from land where UUID=:UUID", conn))
{ {
cmd.Parameters.Add(new SqliteParameter(":UUID", Util.ToRawUuidString(globalID))); cmd.Parameters.Add(new SqliteParameter(":UUID", Util.ToRawUuidString(globalID)));
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:UUID", conn)) using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:UUID", m_conn))
{ {
cmd.Parameters.Add(new SqliteParameter(":UUID", Util.ToRawUuidString(globalID))); cmd.Parameters.Add(new SqliteParameter(":UUID", Util.ToRawUuidString(globalID)));
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
conn.Close();
} }
} }
@ -483,8 +468,6 @@ namespace OpenSim.Framework.Data.SQLite
{ {
lock (ds) lock (ds)
{ {
SqliteConnection conn = new SqliteConnection(m_connectionString);
conn.Open();
DataTable land = ds.Tables["land"]; DataTable land = ds.Tables["land"];
DataTable landaccesslist = ds.Tables["landaccesslist"]; DataTable landaccesslist = ds.Tables["landaccesslist"];
@ -501,7 +484,7 @@ namespace OpenSim.Framework.Data.SQLite
} }
using ( using (
SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:LandUUID", conn)) SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:LandUUID", m_conn))
{ {
cmd.Parameters.Add(new SqliteParameter(":LandUUID", Util.ToRawUuidString(parcel.landData.globalID))); cmd.Parameters.Add(new SqliteParameter(":LandUUID", Util.ToRawUuidString(parcel.landData.globalID)));
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
@ -513,7 +496,6 @@ namespace OpenSim.Framework.Data.SQLite
fillLandAccessRow(newAccessRow, entry, parcel.landData.globalID); fillLandAccessRow(newAccessRow, entry, parcel.landData.globalID);
landaccesslist.Rows.Add(newAccessRow); landaccesslist.Rows.Add(newAccessRow);
} }
conn.Close();
} }
Commit(); Commit();