Fixed the problem of prims not being loaded from the database (that my last commit created).

afrisby
MW 2007-08-29 16:35:22 +00:00
parent 36fba5e7e2
commit 334dce42e7
2 changed files with 113 additions and 77 deletions

View File

@ -363,7 +363,10 @@ namespace OpenSim.Region.Environment.Scenes
/// </summary> /// </summary>
public void ScheduleFullUpdate() public void ScheduleFullUpdate()
{ {
m_parentGroup.HasChanged = true; if (m_parentGroup != null)
{
m_parentGroup.HasChanged = true;
}
m_updateFlag = 2; m_updateFlag = 2;
} }
@ -374,7 +377,10 @@ namespace OpenSim.Region.Environment.Scenes
{ {
if (m_updateFlag < 1) if (m_updateFlag < 1)
{ {
m_parentGroup.HasChanged = true; if (m_parentGroup != null)
{
m_parentGroup.HasChanged = true;
}
m_updateFlag = 1; m_updateFlag = 1;
} }
} }

View File

@ -25,7 +25,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage
{ {
private const string primSelect = "select * from prims"; private const string primSelect = "select * from prims";
private const string shapeSelect = "select * from primshapes"; private const string shapeSelect = "select * from primshapes";
private DataSet ds; private DataSet ds;
private SqliteDataAdapter primDa; private SqliteDataAdapter primDa;
private SqliteDataAdapter shapeDa; private SqliteDataAdapter shapeDa;
@ -38,7 +38,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage
public void Initialise(string dbfile, string dbname) public void Initialise(string dbfile, string dbname)
{ {
string connectionString = "URI=file:" + dbfile + ",version=3"; string connectionString = "URI=file:" + dbfile + ",version=3";
ds = new DataSet(); ds = new DataSet();
MainLog.Instance.Verbose("DATASTORE", "Sqlite - connecting: " + dbfile); MainLog.Instance.Verbose("DATASTORE", "Sqlite - connecting: " + dbfile);
@ -89,14 +89,14 @@ namespace OpenSim.DataStore.MonoSqliteStorage
MainLog.Instance.Verbose("DATASTORE", "Adding obj: " + obj.UUID + " to region: " + regionUUID); MainLog.Instance.Verbose("DATASTORE", "Adding obj: " + obj.UUID + " to region: " + regionUUID);
addPrim(prim, obj.UUID, regionUUID); addPrim(prim, obj.UUID, regionUUID);
} }
// MainLog.Instance.Verbose("Attempting to do database update...."); // MainLog.Instance.Verbose("Attempting to do database update....");
primDa.Update(ds, "prims"); primDa.Update(ds, "prims");
shapeDa.Update(ds, "primshapes"); shapeDa.Update(ds, "primshapes");
ds.AcceptChanges(); ds.AcceptChanges();
// MainLog.Instance.Verbose("Dump of prims:", ds.GetXml()); // MainLog.Instance.Verbose("Dump of prims:", ds.GetXml());
} }
public void RemoveObject(LLUUID obj, LLUUID regionUUID) public void RemoveObject(LLUUID obj, LLUUID regionUUID)
{ {
DataTable prims = ds.Tables["prims"]; DataTable prims = ds.Tables["prims"];
@ -122,20 +122,21 @@ namespace OpenSim.DataStore.MonoSqliteStorage
public List<SceneObjectGroup> LoadObjects(LLUUID regionUUID) public List<SceneObjectGroup> LoadObjects(LLUUID regionUUID)
{ {
Dictionary<LLUUID, SceneObjectGroup> createdObjects = new Dictionary<LLUUID, SceneObjectGroup>(); Dictionary<LLUUID, SceneObjectGroup> createdObjects = new Dictionary<LLUUID, SceneObjectGroup>();
List<SceneObjectGroup> retvals = new List<SceneObjectGroup>(); List<SceneObjectGroup> retvals = new List<SceneObjectGroup>();
DataTable prims = ds.Tables["prims"]; DataTable prims = ds.Tables["prims"];
DataTable shapes = ds.Tables["primshapes"]; DataTable shapes = ds.Tables["primshapes"];
string byRegion = "RegionUUID = '" + regionUUID.ToString() + "'"; string byRegion = "RegionUUID = '" + regionUUID.ToString() + "'";
string orderByParent = "ParentID ASC"; string orderByParent = "ParentID ASC";
DataRow[] primsForRegion = prims.Select(byRegion, orderByParent); DataRow[] primsForRegion = prims.Select(byRegion, orderByParent);
MainLog.Instance.Verbose("DATASTORE", "Loaded " + primsForRegion.Length + " prims for region: " + regionUUID); MainLog.Instance.Verbose("DATASTORE", "Loaded " + primsForRegion.Length + " prims for region: " + regionUUID);
foreach (DataRow primRow in primsForRegion) foreach (DataRow primRow in primsForRegion)
{ {
try { try
{
string uuid = (string)primRow["UUID"]; string uuid = (string)primRow["UUID"];
string objID = (string)primRow["SceneGroupID"]; string objID = (string)primRow["SceneGroupID"];
if (uuid == objID) //is new SceneObjectGroup ? if (uuid == objID) //is new SceneObjectGroup ?
@ -154,7 +155,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage
} }
group.AddPart(prim); group.AddPart(prim);
group.RootPart = prim; group.RootPart = prim;
createdObjects.Add(group.UUID, group); createdObjects.Add(group.UUID, group);
retvals.Add(group); retvals.Add(group);
} }
@ -173,14 +174,17 @@ namespace OpenSim.DataStore.MonoSqliteStorage
} }
createdObjects[new LLUUID(objID)].AddPart(prim); createdObjects[new LLUUID(objID)].AddPart(prim);
} }
} catch(Exception) { }
foreach (DataColumn col in prims.Columns) { catch (Exception)
{
foreach (DataColumn col in prims.Columns)
{
MainLog.Instance.Verbose("Col: " + col.ColumnName + " => " + primRow[col]); MainLog.Instance.Verbose("Col: " + col.ColumnName + " => " + primRow[col]);
} }
} }
} }
MainLog.Instance.Verbose("DATASTORE", "Sqlite - LoadObjects found " + prims.Rows.Count + " primitives"); MainLog.Instance.Verbose("DATASTORE", "Sqlite - LoadObjects found " + prims.Rows.Count + " primitives");
MainLog.Instance.Verbose("DATASTORE", "Sqlite - Number of sceneObjects" + retvals.Count);
return retvals; return retvals;
} }
@ -214,42 +218,42 @@ namespace OpenSim.DataStore.MonoSqliteStorage
// TODO: DataSet commit // TODO: DataSet commit
} }
// public class TextureBlock // public class TextureBlock
// { // {
// public byte[] TextureData; // public byte[] TextureData;
// public byte[] ExtraParams = new byte[1]; // public byte[] ExtraParams = new byte[1];
// public TextureBlock(byte[] data) // public TextureBlock(byte[] data)
// { // {
// TextureData = data; // TextureData = data;
// } // }
// public TextureBlock() // public TextureBlock()
// { // {
// } // }
// public string ToXMLString() // public string ToXMLString()
// { // {
// StringWriter sw = new StringWriter(); // StringWriter sw = new StringWriter();
// XmlTextWriter writer = new XmlTextWriter(sw); // XmlTextWriter writer = new XmlTextWriter(sw);
// XmlSerializer serializer = new XmlSerializer(typeof(TextureBlock)); // XmlSerializer serializer = new XmlSerializer(typeof(TextureBlock));
// serializer.Serialize(writer, this); // serializer.Serialize(writer, this);
// return sw.ToString(); // return sw.ToString();
// } // }
// public static TextureBlock FromXmlString(string xmlData) // public static TextureBlock FromXmlString(string xmlData)
// { // {
// TextureBlock textureEntry = null; // TextureBlock textureEntry = null;
// StringReader sr = new StringReader(xmlData); // StringReader sr = new StringReader(xmlData);
// XmlTextReader reader = new XmlTextReader(sr); // XmlTextReader reader = new XmlTextReader(sr);
// XmlSerializer serializer = new XmlSerializer(typeof(TextureBlock)); // XmlSerializer serializer = new XmlSerializer(typeof(TextureBlock));
// textureEntry = (TextureBlock)serializer.Deserialize(reader); // textureEntry = (TextureBlock)serializer.Deserialize(reader);
// reader.Close(); // reader.Close();
// sr.Close(); // sr.Close();
// return textureEntry; // return textureEntry;
// } // }
// } // }
/*********************************************************************** /***********************************************************************
* *
@ -258,7 +262,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage
* This should be db agnostic as we define them in ADO.NET terms * This should be db agnostic as we define them in ADO.NET terms
* *
**********************************************************************/ **********************************************************************/
private void createCol(DataTable dt, string name, System.Type type) private void createCol(DataTable dt, string name, System.Type type)
{ {
DataColumn col = new DataColumn(name, type); DataColumn col = new DataColumn(name, type);
@ -312,7 +316,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage
createCol(prims, "RotationY", typeof(System.Double)); createCol(prims, "RotationY", typeof(System.Double));
createCol(prims, "RotationZ", typeof(System.Double)); createCol(prims, "RotationZ", typeof(System.Double));
createCol(prims, "RotationW", typeof(System.Double)); createCol(prims, "RotationW", typeof(System.Double));
// Add in contraints // Add in contraints
prims.PrimaryKey = new DataColumn[] { prims.Columns["UUID"] }; prims.PrimaryKey = new DataColumn[] { prims.Columns["UUID"] };
@ -359,7 +363,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage
return shapes; return shapes;
} }
/*********************************************************************** /***********************************************************************
* *
* Convert between ADO.NET <=> OpenSim Objects * Convert between ADO.NET <=> OpenSim Objects
@ -528,10 +532,10 @@ namespace OpenSim.DataStore.MonoSqliteStorage
// s.TextureEntry = textureEntry.TextureData; // s.TextureEntry = textureEntry.TextureData;
// s.ExtraParams = textureEntry.ExtraParams; // s.ExtraParams = textureEntry.ExtraParams;
// } // }
return s; return s;
} }
private void fillShapeRow(DataRow row, SceneObjectPart prim) private void fillShapeRow(DataRow row, SceneObjectPart prim)
{ {
PrimitiveBaseShape s = prim.Shape; PrimitiveBaseShape s = prim.Shape;
@ -585,7 +589,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage
{ {
DataTable prims = ds.Tables["prims"]; DataTable prims = ds.Tables["prims"];
DataTable shapes = ds.Tables["primshapes"]; DataTable shapes = ds.Tables["primshapes"];
DataRow primRow = prims.Rows.Find(prim.UUID); DataRow primRow = prims.Rows.Find(prim.UUID);
if (primRow == null) if (primRow == null)
{ {
@ -610,7 +614,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage
fillShapeRow(shapeRow, prim); fillShapeRow(shapeRow, prim);
} }
} }
/*********************************************************************** /***********************************************************************
* *
* SQL Statement Creation Functions * SQL Statement Creation Functions
@ -633,7 +637,8 @@ namespace OpenSim.DataStore.MonoSqliteStorage
* generate these strings instead of typing them out. * generate these strings instead of typing them out.
*/ */
string[] cols = new string[dt.Columns.Count]; string[] cols = new string[dt.Columns.Count];
for (int i = 0; i < dt.Columns.Count; i++) { for (int i = 0; i < dt.Columns.Count; i++)
{
DataColumn col = dt.Columns[i]; DataColumn col = dt.Columns[i];
cols[i] = col.ColumnName; cols[i] = col.ColumnName;
} }
@ -648,7 +653,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage
// this provides the binding for all our parameters, so // this provides the binding for all our parameters, so
// much less code than it used to be // much less code than it used to be
foreach (DataColumn col in dt.Columns) foreach (DataColumn col in dt.Columns)
{ {
cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType)); cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
} }
@ -674,7 +679,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage
// this provides the binding for all our parameters, so // this provides the binding for all our parameters, so
// much less code than it used to be // much less code than it used to be
foreach (DataColumn col in dt.Columns) foreach (DataColumn col in dt.Columns)
{ {
cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType)); cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
} }
@ -693,7 +698,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage
subsql += ",\n"; subsql += ",\n";
} }
subsql += col.ColumnName + " " + sqliteType(col.DataType); subsql += col.ColumnName + " " + sqliteType(col.DataType);
if(col == dt.PrimaryKey[0]) if (col == dt.PrimaryKey[0])
{ {
subsql += " primary key"; subsql += " primary key";
} }
@ -746,7 +751,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage
delete.Connection = conn; delete.Connection = conn;
da.DeleteCommand = delete; da.DeleteCommand = delete;
} }
private void setupShapeCommands(SqliteDataAdapter da, SqliteConnection conn) private void setupShapeCommands(SqliteDataAdapter da, SqliteConnection conn)
{ {
da.InsertCommand = createInsertCommand("primshapes", ds.Tables["primshapes"]); da.InsertCommand = createInsertCommand("primshapes", ds.Tables["primshapes"]);
@ -765,13 +770,13 @@ namespace OpenSim.DataStore.MonoSqliteStorage
{ {
string createPrims = defineTable(createPrimTable()); string createPrims = defineTable(createPrimTable());
string createShapes = defineTable(createShapeTable()); string createShapes = defineTable(createShapeTable());
SqliteCommand pcmd = new SqliteCommand(createPrims, conn); SqliteCommand pcmd = new SqliteCommand(createPrims, conn);
SqliteCommand scmd = new SqliteCommand(createShapes, conn); SqliteCommand scmd = new SqliteCommand(createShapes, conn);
conn.Open(); conn.Open();
pcmd.ExecuteNonQuery(); pcmd.ExecuteNonQuery();
scmd.ExecuteNonQuery(); scmd.ExecuteNonQuery();
conn.Close(); conn.Close();
} }
private bool TestTables(SqliteConnection conn) private bool TestTables(SqliteConnection conn)
@ -782,10 +787,13 @@ namespace OpenSim.DataStore.MonoSqliteStorage
SqliteDataAdapter sDa = new SqliteDataAdapter(shapeSelectCmd); SqliteDataAdapter sDa = new SqliteDataAdapter(shapeSelectCmd);
DataSet tmpDS = new DataSet(); DataSet tmpDS = new DataSet();
try { try
{
pDa.Fill(tmpDS, "prims"); pDa.Fill(tmpDS, "prims");
sDa.Fill(tmpDS, "primshapes"); sDa.Fill(tmpDS, "primshapes");
} catch (Mono.Data.SqliteClient.SqliteSyntaxException) { }
catch (Mono.Data.SqliteClient.SqliteSyntaxException)
{
MainLog.Instance.Verbose("DATASTORE", "SQLite Database doesn't exist... creating"); MainLog.Instance.Verbose("DATASTORE", "SQLite Database doesn't exist... creating");
InitDB(conn); InitDB(conn);
} }
@ -793,14 +801,18 @@ namespace OpenSim.DataStore.MonoSqliteStorage
pDa.Fill(tmpDS, "prims"); pDa.Fill(tmpDS, "prims");
sDa.Fill(tmpDS, "primshapes"); sDa.Fill(tmpDS, "primshapes");
foreach (DataColumn col in createPrimTable().Columns) { foreach (DataColumn col in createPrimTable().Columns)
if (! tmpDS.Tables["prims"].Columns.Contains(col.ColumnName) ) { {
if (!tmpDS.Tables["prims"].Columns.Contains(col.ColumnName))
{
MainLog.Instance.Verbose("DATASTORE", "Missing required column:" + col.ColumnName); MainLog.Instance.Verbose("DATASTORE", "Missing required column:" + col.ColumnName);
return false; return false;
} }
} }
foreach (DataColumn col in createShapeTable().Columns) { foreach (DataColumn col in createShapeTable().Columns)
if (! tmpDS.Tables["primshapes"].Columns.Contains(col.ColumnName) ) { {
if (!tmpDS.Tables["primshapes"].Columns.Contains(col.ColumnName))
{
MainLog.Instance.Verbose("DATASTORE", "Missing required column:" + col.ColumnName); MainLog.Instance.Verbose("DATASTORE", "Missing required column:" + col.ColumnName);
return false; return false;
} }
@ -813,35 +825,53 @@ namespace OpenSim.DataStore.MonoSqliteStorage
* Type conversion functions * Type conversion functions
* *
**********************************************************************/ **********************************************************************/
private DbType dbtypeFromType(Type type) private DbType dbtypeFromType(Type type)
{ {
if (type == typeof(System.String)) { if (type == typeof(System.String))
{
return DbType.String; return DbType.String;
} else if (type == typeof(System.Int32)) { }
else if (type == typeof(System.Int32))
{
return DbType.Int32; return DbType.Int32;
} else if (type == typeof(System.Double)) { }
else if (type == typeof(System.Double))
{
return DbType.Double; return DbType.Double;
} else if (type == typeof(System.Byte[])) { }
else if (type == typeof(System.Byte[]))
{
return DbType.Binary; return DbType.Binary;
} else { }
else
{
return DbType.String; return DbType.String;
} }
} }
// this is something we'll need to implement for each db // this is something we'll need to implement for each db
// slightly differently. // slightly differently.
private string sqliteType(Type type) private string sqliteType(Type type)
{ {
if (type == typeof(System.String)) { if (type == typeof(System.String))
{
return "varchar(255)"; return "varchar(255)";
} else if (type == typeof(System.Int32)) { }
else if (type == typeof(System.Int32))
{
return "integer"; return "integer";
} else if (type == typeof(System.Double)) { }
else if (type == typeof(System.Double))
{
return "float"; return "float";
} else if (type == typeof(System.Byte[])) { }
else if (type == typeof(System.Byte[]))
{
return "blob"; return "blob";
} else { }
else
{
return "string"; return "string";
} }
} }