From d82ed9a8c5aff8c95ce1c9aa092d68a4f649fa07 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Thu, 27 Dec 2007 18:49:16 +0000 Subject: [PATCH] * Fixed MonoSQLite Update Table routine * Charles, this will fix the red issue. * Same situation, the first run updates the tables (and gives you a ton of red errors), the second run and everything works as expected. --- .../Framework/Data.MySQL/MySQLDataStore.cs | 39 ++++++++++++------- .../Environment/Scenes/SceneObjectPart.cs | 4 +- .../OpenSim.DataStore.MSSQL/MSSQLDataStore.cs | 6 +-- .../MonoSqliteDataStore.cs | 28 +++++++++---- 4 files changed, 52 insertions(+), 25 deletions(-) diff --git a/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs b/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs index 06a5814405..c48c88f24e 100644 --- a/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs +++ b/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs @@ -702,12 +702,12 @@ namespace OpenSim.Framework.Data.MySQL { prim.SetSitTargetLL(new LLVector3( Convert.ToSingle(row["SitTargetOffsetX"]), - Convert.ToSingle(row["SitTargetOffsetX"]), + Convert.ToSingle(row["SitTargetOffsetY"]), Convert.ToSingle(row["SitTargetOffsetZ"])), new LLQuaternion( - Convert.ToSingle(row["SitTargetOrientW"]), Convert.ToSingle(row["SitTargetOrientX"]), Convert.ToSingle(row["SitTargetOrientY"]), - Convert.ToSingle(row["SitTargetOrientX"]))); + Convert.ToSingle(row["SitTargetOrientZ"]), + Convert.ToSingle(row["SitTargetOrientW"]))); } catch (System.InvalidCastException) { @@ -828,17 +828,30 @@ namespace OpenSim.Framework.Data.MySQL row["RotationZ"] = prim.RotationOffset.Z; row["RotationW"] = prim.RotationOffset.W; - // Sit target - LLVector3 sitTargetPos = prim.GetSitTargetPositionLL(); - row["SitTargetOffsetX"] = sitTargetPos.X; - row["SitTargetOffsetY"] = sitTargetPos.Y; - row["SitTargetOffsetZ"] = sitTargetPos.Z; + try + { + // Sit target + LLVector3 sitTargetPos = prim.GetSitTargetPositionLL(); + row["SitTargetOffsetX"] = sitTargetPos.X; + row["SitTargetOffsetY"] = sitTargetPos.Y; + row["SitTargetOffsetZ"] = sitTargetPos.Z; + + LLQuaternion sitTargetOrient = prim.GetSitTargetOrientationLL(); + row["SitTargetOrientW"] = sitTargetOrient.W; + row["SitTargetOrientX"] = sitTargetOrient.X; + row["SitTargetOrientY"] = sitTargetOrient.Y; + row["SitTargetOrientZ"] = sitTargetOrient.Z; + } + catch (MySql.Data.MySqlClient.MySqlException) + { + // Database table was created before we got here and needs to be created! :P + + using (MySqlCommand cmd = new MySqlCommand("ALTER TABLE `prims` ADD COLUMN `SitTargetOffsetX` float NOT NULL default 0, ADD COLUMN `SitTargetOffsetY` float NOT NULL default 0, ADD COLUMN `SitTargetOffsetZ` float NOT NULL default 0, ADD COLUMN `SitTargetOrientW` float NOT NULL default 0, ADD COLUMN `SitTargetOrientX` float NOT NULL default 0, ADD COLUMN `SitTargetOrientY` float NOT NULL default 0, ADD COLUMN `SitTargetOrientZ` float NOT NULL default 0;", m_connection)) + { + cmd.ExecuteNonQuery(); + } + } - LLQuaternion sitTargetOrient = prim.GetSitTargetOrientationLL(); - row["SitTargetOrientW"] = sitTargetOrient.W; - row["SitTargetOrientX"] = sitTargetOrient.X; - row["SitTargetOrientY"] = sitTargetOrient.Y; - row["SitTargetOrientZ"] = sitTargetOrient.Z; } diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index 29a163be40..f226150764 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs @@ -804,13 +804,13 @@ namespace OpenSim.Region.Environment.Scenes public LLQuaternion GetSitTargetOrientationLL() { - return new LLQuaternion(m_sitTargetOrientation.w, m_sitTargetOrientation.x, m_sitTargetOrientation.y, m_sitTargetOrientation.z); + return new LLQuaternion( m_sitTargetOrientation.x, m_sitTargetOrientation.y, m_sitTargetOrientation.z,m_sitTargetOrientation.w); } // Utility function so the databases don't have to reference axiom.math public void SetSitTargetLL(LLVector3 offset, LLQuaternion orientation) { - if (!(offset.X == 0 && offset.Y == 0 && offset.Z == 0 && (orientation.W == 0 || orientation.W == 1) && orientation.X == 0 && orientation.Y == 0 && (orientation.Z == 0 || orientation.Z == 0))) + if (!(offset.X == 0 && offset.Y == 0 && offset.Z == 0 && (orientation.W == 0 || orientation.W == 1) && orientation.X == 0 && orientation.Y == 0 && orientation.Z == 0)) { m_sitTargetPosition = new Vector3(offset.X, offset.Y, offset.Z); m_sitTargetOrientation = new Quaternion(orientation.W, orientation.X, orientation.Y, orientation.Z); diff --git a/OpenSim/Region/Storage/OpenSim.DataStore.MSSQL/MSSQLDataStore.cs b/OpenSim/Region/Storage/OpenSim.DataStore.MSSQL/MSSQLDataStore.cs index 0a48126f41..60aeb83069 100644 --- a/OpenSim/Region/Storage/OpenSim.DataStore.MSSQL/MSSQLDataStore.cs +++ b/OpenSim/Region/Storage/OpenSim.DataStore.MSSQL/MSSQLDataStore.cs @@ -522,12 +522,12 @@ namespace OpenSim.DataStore.MSSQL { prim.SetSitTargetLL(new LLVector3( Convert.ToSingle(row["SitTargetOffsetX"]), - Convert.ToSingle(row["SitTargetOffsetX"]), + Convert.ToSingle(row["SitTargetOffsetY"]), Convert.ToSingle(row["SitTargetOffsetZ"])), new LLQuaternion( - Convert.ToSingle(row["SitTargetOrientW"]), Convert.ToSingle(row["SitTargetOrientX"]), Convert.ToSingle(row["SitTargetOrientY"]), - Convert.ToSingle(row["SitTargetOrientX"]))); + Convert.ToSingle(row["SitTargetOrientZ"]), + Convert.ToSingle(row["SitTargetOrientW"]))); } catch (System.InvalidCastException) { diff --git a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs index 9118082b7c..c885310567 100644 --- a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs +++ b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs @@ -783,20 +783,34 @@ namespace OpenSim.DataStore.MonoSqlite { prim.SetSitTargetLL(new LLVector3( Convert.ToSingle(row["SitTargetOffsetX"]), - Convert.ToSingle(row["SitTargetOffsetX"]), + Convert.ToSingle(row["SitTargetOffsetY"]), Convert.ToSingle(row["SitTargetOffsetZ"])), new LLQuaternion( - Convert.ToSingle(row["SitTargetOrientW"]), Convert.ToSingle(row["SitTargetOrientX"]), Convert.ToSingle(row["SitTargetOrientY"]), - Convert.ToSingle(row["SitTargetOrientX"]))); + Convert.ToSingle(row["SitTargetOrientZ"]), + Convert.ToSingle(row["SitTargetOrientW"]))); } catch (System.InvalidCastException) { // Database table was created before we got here and now has null values :P - using (SqliteCommand cmd = new SqliteCommand("ALTER TABLE `prims` ADD COLUMN `SitTargetOffsetX` float NOT NULL default 0, ADD COLUMN `SitTargetOffsetY` float NOT NULL default 0, ADD COLUMN `SitTargetOffsetZ` float NOT NULL default 0, ADD COLUMN `SitTargetOrientW` float NOT NULL default 0, ADD COLUMN `SitTargetOrientX` float NOT NULL default 0, ADD COLUMN `SitTargetOrientY` float NOT NULL default 0, ADD COLUMN `SitTargetOrientZ` float NOT NULL default 0;", m_conn)) - { - cmd.ExecuteNonQuery(); - } + m_conn.Open(); + SqliteCommand cmd = new SqliteCommand("ALTER TABLE prims ADD COLUMN SitTargetOffsetX float NOT NULL default 0;", m_conn); + cmd.ExecuteNonQuery(); + cmd = new SqliteCommand("ALTER TABLE prims ADD COLUMN SitTargetOffsetY float NOT NULL default 0;", m_conn); + cmd.ExecuteNonQuery(); + cmd = new SqliteCommand("ALTER TABLE prims ADD COLUMN SitTargetOffsetZ float NOT NULL default 0;", m_conn); + cmd.ExecuteNonQuery(); + cmd = new SqliteCommand("ALTER TABLE prims ADD COLUMN SitTargetOrientW float NOT NULL default 0;", m_conn); + cmd.ExecuteNonQuery(); + cmd = new SqliteCommand("ALTER TABLE prims ADD COLUMN SitTargetOrientX float NOT NULL default 0;", m_conn); + cmd.ExecuteNonQuery(); + cmd = new SqliteCommand("ALTER TABLE prims ADD COLUMN SitTargetOrientY float NOT NULL default 0;", m_conn); + cmd.ExecuteNonQuery(); + cmd = new SqliteCommand("ALTER TABLE prims ADD COLUMN SitTargetOrientZ float NOT NULL default 0;", m_conn); + cmd.ExecuteNonQuery(); + + + } return prim;