Thank you, RuudL, for a complete adaptation of migration and estate
data to MSSQL, and the updating of the RegionData handling in MSSQL.
0.6.0-stable
Melanie Thielker 2008-09-01 17:10:01 +00:00
parent ddd68a0537
commit b6bb5f944f
11 changed files with 2090 additions and 1490 deletions

View File

@ -0,0 +1,434 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;
using libsecondlife;
using log4net;
using OpenSim.Framework;
using OpenSim.Region.Environment.Interfaces;
namespace OpenSim.Data.MSSQL
{
public class MSSQLEstateData : IEstateDataStore
{
private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private MSSQLManager _Database;
private FieldInfo[] _Fields;
private Dictionary<string, FieldInfo> _FieldMap = new Dictionary<string, FieldInfo>();
#region Public methods
/// <summary>
/// Initialises the estatedata class.
/// </summary>
/// <param name="connectionString">connectionString.</param>
public void Initialise(string connectionString)
{
if (string.IsNullOrEmpty(connectionString))
{
_Database = new MSSQLManager(connectionString);
}
else
{
//TODO when can this be deleted
IniFile iniFile = new IniFile("mssql_connection.ini");
string settingDataSource = iniFile.ParseFileReadValue("data_source");
string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog");
string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info");
string settingUserId = iniFile.ParseFileReadValue("user_id");
string settingPassword = iniFile.ParseFileReadValue("password");
_Database =
new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
settingPassword);
}
//Migration settings
using (SqlConnection connection = _Database.DatabaseConnection())
{
Assembly assem = GetType().Assembly;
MSSQLMigration migration = new MSSQLMigration(connection, assem, "EstateStore");
migration.Update();
connection.Close();
}
//Interesting way to get parameters! Maybe implement that also with other types
Type t = typeof(EstateSettings);
_Fields = t.GetFields(BindingFlags.NonPublic |
BindingFlags.Instance |
BindingFlags.DeclaredOnly);
foreach (FieldInfo f in _Fields)
{
if (f.Name.Substring(0, 2) == "m_")
_FieldMap[f.Name.Substring(2)] = f;
}
}
/// <summary>
/// Loads the estate settings.
/// </summary>
/// <param name="regionID">region ID.</param>
/// <returns></returns>
public EstateSettings LoadEstateSettings(LLUUID regionID)
{
EstateSettings es = new EstateSettings();
string sql = "select estate_settings." + String.Join(",estate_settings.", FieldList) + " from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = @RegionID";
bool insertEstate = false;
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
{
cmd.Parameters.AddWithValue("@RegionID", regionID.ToString());
using (IDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
foreach (string name in FieldList)
{
if (_FieldMap[name].GetValue(es) is bool)
{
int v = Convert.ToInt32(reader[name]);
if (v != 0)
_FieldMap[name].SetValue(es, true);
else
_FieldMap[name].SetValue(es, false);
}
else if (_FieldMap[name].GetValue(es) is LLUUID)
{
LLUUID uuid;
LLUUID.TryParse(reader[name].ToString(), out uuid);
_FieldMap[name].SetValue(es, uuid);
}
else
{
_FieldMap[name].SetValue(es, reader[name]);
}
}
}
else
{
insertEstate = true;
}
}
}
if (insertEstate)
{
List<string> names = new List<string>(FieldList);
names.Remove("EstateID");
sql = string.Format("insert into estate_settings ({0}) values ( @{1})", String.Join(",", names.ToArray()), String.Join(", @", names.ToArray()));
//_Log.Debug("[DB ESTATE]: SQL: " + sql);
using (SqlConnection connection = _Database.DatabaseConnection())
{
using (SqlCommand insertCommand = connection.CreateCommand())
{
insertCommand.CommandText = sql + " SET @ID = SCOPE_IDENTITY()";
foreach (string name in names)
{
if (_FieldMap[name].GetValue(es) is bool)
{
SqlParameter tempBool = new SqlParameter("@" + name, SqlDbType.Bit);
if ((bool) _FieldMap[name].GetValue(es))
tempBool.Value = 1;
else
tempBool.Value = 0;
insertCommand.Parameters.Add(tempBool);
}
else
{
//cmd.Parameters.AddWithValue("@" + name, _FieldMap[name].GetValue(es));
SqlParameter tempPar = new SqlParameter("@" + name,
_Database.DbtypeFromType(_FieldMap[name].FieldType));
tempPar.Value = _FieldMap[name].GetValue(es).ToString();
insertCommand.Parameters.Add(tempPar);
}
}
SqlParameter idParameter = new SqlParameter("@ID", SqlDbType.Int);
idParameter.Direction = ParameterDirection.Output;
insertCommand.Parameters.Add(idParameter);
insertCommand.ExecuteNonQuery();
es.EstateID = Convert.ToUInt32(idParameter.Value);
}
}
using (AutoClosingSqlCommand cmd = _Database.Query("insert into estate_map values (@RegionID, @EstateID)"))
{
cmd.Parameters.AddWithValue("@RegionID", regionID.ToString());
cmd.Parameters.AddWithValue("@EstateID", es.EstateID);
// This will throw on dupe key
try
{
cmd.ExecuteNonQuery();
}
catch (Exception)
{
_Log.Debug("[ESTATE DB]: Error inserting regionID and EstateID in estate_map");
}
}
// Munge and transfer the ban list
//
sql = string.Format("insert into estateban select {0}, bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = @UUID", es.EstateID);
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
{
cmd.Parameters.AddWithValue("@UUID", regionID);
try
{
cmd.ExecuteNonQuery();
}
catch (Exception)
{
_Log.Debug("[ESTATE DB]: Error setting up estateban from regionban");
}
}
//TODO check if this is needed??
es.Save();
}
LoadBanList(es);
es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
//Set event
es.OnSave += StoreEstateSettings;
return es;
}
/// <summary>
/// Stores the estate settings.
/// </summary>
/// <param name="es">estate settings</param>
public void StoreEstateSettings(EstateSettings es)
{
List<string> names = new List<string>(FieldList);
names.Remove("EstateID");
string sql = string.Format("UPDATE estate_settings SET ") ; // ({0}) values ( @{1}) WHERE EstateID = @EstateID", String.Join(",", names.ToArray()), String.Join(", @", names.ToArray()));
foreach (string name in names)
{
sql += name + " = @" + name + ", ";
}
sql = sql.Remove(sql.LastIndexOf(","));
sql += " WHERE EstateID = @EstateID";
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
{
foreach (string name in names)
{
if (_FieldMap[name].GetValue(es) is bool)
{
SqlParameter tempBool = new SqlParameter("@" + name, SqlDbType.Bit);
if ((bool)_FieldMap[name].GetValue(es))
tempBool.Value = 1;
else
tempBool.Value = 0;
cmd.Parameters.Add(tempBool);
}
else
{
//cmd.Parameters.AddWithValue("@" + name, _FieldMap[name].GetValue(es));
SqlParameter tempPar = new SqlParameter("@" + name,
_Database.DbtypeFromType(_FieldMap[name].FieldType));
tempPar.Value = _FieldMap[name].GetValue(es).ToString();
cmd.Parameters.Add(tempPar);
}
}
SqlParameter idParameter = new SqlParameter("@EstateID", SqlDbType.Int);
idParameter.Value = es.EstateID;
cmd.Parameters.Add(idParameter);
cmd.ExecuteNonQuery();
}
SaveBanList(es);
SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers);
SaveUUIDList(es.EstateID, "estate_users", es.EstateAccess);
SaveUUIDList(es.EstateID, "estate_groups", es.EstateGroups);
}
#endregion
#region Private methods
private string[] FieldList
{
get { return new List<string>(_FieldMap.Keys).ToArray(); }
}
private void LoadBanList(EstateSettings es)
{
es.ClearBans();
string sql = "select bannedUUID from estateban where EstateID = @EstateID";
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
{
SqlParameter idParameter = new SqlParameter("@EstateID", SqlDbType.Int);
idParameter.Value = es.EstateID;
cmd.Parameters.Add(idParameter);
using (IDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
EstateBan eb = new EstateBan();
LLUUID uuid;
LLUUID.TryParse(reader["bannedUUID"].ToString(), out uuid);
eb.bannedUUID = uuid;
eb.bannedIP = "0.0.0.0";
eb.bannedIPHostMask = "0.0.0.0";
es.AddBan(eb);
}
}
}
}
private LLUUID[] LoadUUIDList(uint estateID, string table)
{
List<LLUUID> uuids = new List<LLUUID>();
string sql = string.Format("select uuid from {0} where EstateID = @EstateID", table);
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
{
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID));
using (IDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
// EstateBan eb = new EstateBan();
LLUUID uuid;
LLUUID.TryParse(reader["uuid"].ToString(), out uuid);
uuids.Add(uuid);
}
}
}
return uuids.ToArray();
}
private void SaveBanList(EstateSettings es)
{
//Delete first
string sql = "delete from estateban where EstateID = @EstateID";
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
{
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID));
cmd.ExecuteNonQuery();
}
//Insert after
sql = "insert into estateban (EstateID, bannedUUID) values ( @EstateID, @bannedUUID )";
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
{
foreach (EstateBan b in es.EstateBans)
{
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID));
cmd.Parameters.Add(_Database.CreateParameter("@bannedUUID", b.bannedUUID));
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
}
}
private void SaveUUIDList(uint estateID, string table, LLUUID[] data)
{
//Delete first
string sql = string.Format("delete from {0} where EstateID = @EstateID", table);
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
{
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID));
cmd.ExecuteNonQuery();
}
sql = string.Format("insert into {0} (EstateID, uuid) values ( @EstateID, @uuid )", table);
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
{
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID));
bool createParamOnce = true;
foreach (LLUUID uuid in data)
{
if (createParamOnce)
{
cmd.Parameters.Add(_Database.CreateParameter("@uuid", uuid));
createParamOnce = false;
}
else
cmd.Parameters["@uuid"].Value = uuid.ToString();
cmd.ExecuteNonQuery();
}
}
}
#endregion
}
}

View File

@ -64,9 +64,20 @@ namespace OpenSim.Data.MSSQL
connectionString = builder.ToString();
}
private SqlConnection createConnection()
/// <summary>
/// Initialize the manager and set the connectionstring
/// </summary>
/// <param name="connection"></param>
public MSSQLManager(string connection)
{
connectionString = connection;
}
public SqlConnection DatabaseConnection()
{
SqlConnection conn = new SqlConnection(connectionString);
//TODO is this good??? Opening connection here
conn.Open();
return conn;
@ -186,6 +197,105 @@ namespace OpenSim.Data.MSSQL
}
}
/// <summary>
/// Type conversion to a SQLDbType functions
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
internal SqlDbType DbtypeFromType(Type type)
{
if (type == typeof(string))
{
return SqlDbType.VarChar;
}
if (type == typeof(double))
{
return SqlDbType.Float;
}
if (type == typeof(int))
{
return SqlDbType.Int;
}
if (type == typeof(bool))
{
return SqlDbType.Bit;
}
if (type == typeof(LLUUID))
{
return SqlDbType.VarChar;
}
if (type == typeof(Byte[]))
{
return SqlDbType.Image;
}
if (type == typeof(uint))
{
return SqlDbType.Int;
}
return SqlDbType.VarChar;
}
/// <summary>
/// Creates value for parameter.
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
private static object CreateParameterValue(object value)
{
Type valueType = value.GetType();
if (valueType == typeof(LLUUID))
{
return value.ToString();
}
if (valueType == typeof(bool))
{
return (bool)value ? 1 : 0;
}
if (valueType == typeof(Byte[]))
{
return value;
}
return value;
}
/// <summary>
/// Create a parameter for a command
/// </summary>
/// <param name="parameterName">Name of the parameter.</param>
/// <param name="parameterObject">parameter object.</param>
/// <returns></returns>
internal SqlParameter CreateParameter(string parameterName, object parameterObject)
{
return CreateParameter(parameterName, parameterObject, false);
}
/// <summary>
/// Creates the parameter for a command.
/// </summary>
/// <param name="parameterName">Name of the parameter.</param>
/// <param name="parameterObject">parameter object.</param>
/// <param name="parameterOut">if set to <c>true</c> parameter is a output parameter</param>
/// <returns></returns>
internal SqlParameter CreateParameter(string parameterName, object parameterObject, bool parameterOut)
{
//Tweak so we dont always have to add @ sign
if (!parameterName.StartsWith("@")) parameterName = "@" + parameterName;
SqlParameter parameter = new SqlParameter(parameterName, DbtypeFromType(parameterObject.GetType()));
if (parameterOut)
{
parameter.Direction = ParameterDirection.Output;
}
else
{
parameter.Direction = ParameterDirection.Input;
parameter.Value = CreateParameterValue(parameterObject);
}
return parameter;
}
private static readonly Dictionary<string, string> emptyDictionary = new Dictionary<string, string>();
internal AutoClosingSqlCommand Query(string sql)
@ -201,7 +311,7 @@ namespace OpenSim.Data.MSSQL
/// <returns>A Sql DB Command</returns>
internal AutoClosingSqlCommand Query(string sql, Dictionary<string, string> parameters)
{
SqlCommand dbcommand = createConnection().CreateCommand();
SqlCommand dbcommand = DatabaseConnection().CreateCommand();
dbcommand.CommandText = sql;
foreach (KeyValuePair<string, string> param in parameters)
{
@ -211,8 +321,6 @@ namespace OpenSim.Data.MSSQL
return new AutoClosingSqlCommand(dbcommand);
}
/// <summary>
/// Runs a database reader object and returns a region row
/// </summary>

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Reflection;
using System.Text;
namespace OpenSim.Data.MSSQL
{
public class MSSQLMigration : Migration
{
public MSSQLMigration(DbConnection conn, Assembly assem, string type) : base(conn, assem, type)
{
}
public MSSQLMigration(DbConnection conn, Assembly assem, string subtype, string type) : base(conn, assem, subtype, type)
{
}
protected override int FindVersion(DbConnection conn, string type)
{
int version = 0;
using (DbCommand cmd = conn.CreateCommand())
{
try
{
cmd.CommandText = "select top 1 version from migrations where name = '" + type + "' order by version desc"; //Must be
using (IDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
version = Convert.ToInt32(reader["version"]);
}
reader.Close();
}
}
catch
{
// Something went wrong, so we're version 0
}
}
return version;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,85 @@
BEGIN TRANSACTION
CREATE TABLE [dbo].[estate_managers](
[EstateID] [int] NOT NULL,
[uuid] [varchar](36) NOT NULL,
CONSTRAINT [PK_estate_managers] PRIMARY KEY CLUSTERED
(
[EstateID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY];
CREATE TABLE [dbo].[estate_groups](
[EstateID] [int] NOT NULL,
[uuid] [varchar](36) NOT NULL,
CONSTRAINT [PK_estate_groups] PRIMARY KEY CLUSTERED
(
[EstateID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY];
CREATE TABLE [dbo].[estate_users](
[EstateID] [int] NOT NULL,
[uuid] [varchar](36) NOT NULL,
CONSTRAINT [PK_estate_users] PRIMARY KEY CLUSTERED
(
[EstateID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY];
CREATE TABLE [dbo].[estateban](
[EstateID] [int] NOT NULL,
[bannedUUID] [varchar](36) NOT NULL,
[bannedIp] [varchar](16) NOT NULL,
[bannedIpHostMask] [varchar](16) NOT NULL,
[bannedNameMask] [varchar](64) NULL DEFAULT (NULL),
CONSTRAINT [PK_estateban] PRIMARY KEY CLUSTERED
(
[EstateID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY];
CREATE TABLE [dbo].[estate_settings](
[EstateID] [int] IDENTITY(1,100) NOT NULL,
[EstateName] [varchar](64) NULL DEFAULT (NULL),
[AbuseEmailToEstateOwner] [bit] NOT NULL,
[DenyAnonymous] [bit] NOT NULL,
[ResetHomeOnTeleport] [bit] NOT NULL,
[FixedSun] [bit] NOT NULL,
[DenyTransacted] [bit] NOT NULL,
[BlockDwell] [bit] NOT NULL,
[DenyIdentified] [bit] NOT NULL,
[AllowVoice] [bit] NOT NULL,
[UseGlobalTime] [bit] NOT NULL,
[PricePerMeter] [int] NOT NULL,
[TaxFree] [bit] NOT NULL,
[AllowDirectTeleport] [bit] NOT NULL,
[RedirectGridX] [int] NOT NULL,
[RedirectGridY] [int] NOT NULL,
[ParentEstateID] [int] NOT NULL,
[SunPosition] [float] NOT NULL,
[EstateSkipScripts] [bit] NOT NULL,
[BillableFactor] [float] NOT NULL,
[PublicAccess] [bit] NOT NULL,
[AbuseEmail] [varchar](255) NOT NULL,
[EstateOwner] [varchar](36) NOT NULL,
[DenyMinors] [bit] NOT NULL,
CONSTRAINT [PK_estate_settings] PRIMARY KEY CLUSTERED
(
[EstateID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY];
CREATE TABLE [dbo].[estate_map](
[RegionID] [varchar](36) NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000'),
[EstateID] [int] NOT NULL,
CONSTRAINT [PK_estate_map] PRIMARY KEY CLUSTERED
(
[RegionID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY];
COMMIT

View File

@ -0,0 +1,50 @@
BEGIN TRANSACTION
CREATE TABLE regionban (
[regionUUID] VARCHAR(36) NOT NULL,
[bannedUUID] VARCHAR(36) NOT NULL,
[bannedIp] VARCHAR(16) NOT NULL,
[bannedIpHostMask] VARCHAR(16) NOT NULL)
create table [dbo].[regionsettings] (
[regionUUID] [varchar](36) not null,
[block_terraform] [bit] not null,
[block_fly] [bit] not null,
[allow_damage] [bit] not null,
[restrict_pushing] [bit] not null,
[allow_land_resell] [bit] not null,
[allow_land_join_divide] [bit] not null,
[block_show_in_search] [bit] not null,
[agent_limit] [int] not null,
[object_bonus] [float] not null,
[maturity] [int] not null,
[disable_scripts] [bit] not null,
[disable_collisions] [bit] not null,
[disable_physics] [bit] not null,
[terrain_texture_1] [varchar](36) not null,
[terrain_texture_2] [varchar](36) not null,
[terrain_texture_3] [varchar](36) not null,
[terrain_texture_4] [varchar](36) not null,
[elevation_1_nw] [float] not null,
[elevation_2_nw] [float] not null,
[elevation_1_ne] [float] not null,
[elevation_2_ne] [float] not null,
[elevation_1_se] [float] not null,
[elevation_2_se] [float] not null,
[elevation_1_sw] [float] not null,
[elevation_2_sw] [float] not null,
[water_height] [float] not null,
[terrain_raise_limit] [float] not null,
[terrain_lower_limit] [float] not null,
[use_estate_sun] [bit] not null,
[fixed_sun] [bit] not null,
[sun_position] [float] not null,
[covenant] [varchar](36) default NULL,
[Sandbox] [bit] NOT NULL,
PRIMARY KEY CLUSTERED
(
[regionUUID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
COMMIT

View File

@ -0,0 +1,67 @@
BEGIN TRANSACTION
CREATE TABLE dbo.Tmp_prims
(
UUID varchar(36) NOT NULL,
RegionUUID varchar(36) NULL,
ParentID int NULL,
CreationDate int NULL,
Name varchar(255) NULL,
SceneGroupID varchar(36) NULL,
Text varchar(255) NULL,
Description varchar(255) NULL,
SitName varchar(255) NULL,
TouchName varchar(255) NULL,
ObjectFlags int NULL,
CreatorID varchar(36) NULL,
OwnerID varchar(36) NULL,
GroupID varchar(36) NULL,
LastOwnerID varchar(36) NULL,
OwnerMask int NULL,
NextOwnerMask int NULL,
GroupMask int NULL,
EveryoneMask int NULL,
BaseMask int NULL,
PositionX float(53) NULL,
PositionY float(53) NULL,
PositionZ float(53) NULL,
GroupPositionX float(53) NULL,
GroupPositionY float(53) NULL,
GroupPositionZ float(53) NULL,
VelocityX float(53) NULL,
VelocityY float(53) NULL,
VelocityZ float(53) NULL,
AngularVelocityX float(53) NULL,
AngularVelocityY float(53) NULL,
AngularVelocityZ float(53) NULL,
AccelerationX float(53) NULL,
AccelerationY float(53) NULL,
AccelerationZ float(53) NULL,
RotationX float(53) NULL,
RotationY float(53) NULL,
RotationZ float(53) NULL,
RotationW float(53) NULL,
SitTargetOffsetX float(53) NULL,
SitTargetOffsetY float(53) NULL,
SitTargetOffsetZ float(53) NULL,
SitTargetOrientW float(53) NULL,
SitTargetOrientX float(53) NULL,
SitTargetOrientY float(53) NULL,
SitTargetOrientZ float(53) NULL
) ON [PRIMARY]
IF EXISTS(SELECT * FROM dbo.prims)
EXEC('INSERT INTO dbo.Tmp_prims (UUID, RegionUUID, ParentID, CreationDate, Name, SceneGroupID, Text, Description, SitName, TouchName, ObjectFlags, CreatorID, OwnerID, GroupID, LastOwnerID, OwnerMask, NextOwnerMask, GroupMask, EveryoneMask, BaseMask, PositionX, PositionY, PositionZ, GroupPositionX, GroupPositionY, GroupPositionZ, VelocityX, VelocityY, VelocityZ, AngularVelocityX, AngularVelocityY, AngularVelocityZ, AccelerationX, AccelerationY, AccelerationZ, RotationX, RotationY, RotationZ, RotationW, SitTargetOffsetX, SitTargetOffsetY, SitTargetOffsetZ, SitTargetOrientW, SitTargetOrientX, SitTargetOrientY, SitTargetOrientZ)
SELECT CONVERT(varchar(36), UUID), CONVERT(varchar(36), RegionUUID), ParentID, CreationDate, Name, CONVERT(varchar(36), SceneGroupID), Text, Description, SitName, TouchName, ObjectFlags, CONVERT(varchar(36), CreatorID), CONVERT(varchar(36), OwnerID), CONVERT(varchar(36), GroupID), CONVERT(varchar(36), LastOwnerID), OwnerMask, NextOwnerMask, GroupMask, EveryoneMask, BaseMask, PositionX, PositionY, PositionZ, GroupPositionX, GroupPositionY, GroupPositionZ, VelocityX, VelocityY, VelocityZ, AngularVelocityX, AngularVelocityY, AngularVelocityZ, AccelerationX, AccelerationY, AccelerationZ, RotationX, RotationY, RotationZ, RotationW, SitTargetOffsetX, SitTargetOffsetY, SitTargetOffsetZ, SitTargetOrientW, SitTargetOrientX, SitTargetOrientY, SitTargetOrientZ FROM dbo.prims WITH (HOLDLOCK TABLOCKX)')
DROP TABLE dbo.prims
EXECUTE sp_rename N'dbo.Tmp_prims', N'prims', 'OBJECT'
ALTER TABLE dbo.prims ADD CONSTRAINT
PK__prims__10566F31 PRIMARY KEY CLUSTERED
(
UUID
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
COMMIT

View File

@ -0,0 +1,40 @@
BEGIN TRANSACTION
CREATE TABLE dbo.Tmp_primitems
(
itemID varchar(36) NOT NULL,
primID varchar(36) NULL,
assetID varchar(36) NULL,
parentFolderID varchar(36) NULL,
invType int NULL,
assetType int NULL,
name varchar(255) NULL,
description varchar(255) NULL,
creationDate varchar(255) NULL,
creatorID varchar(36) NULL,
ownerID varchar(36) NULL,
lastOwnerID varchar(36) NULL,
groupID varchar(36) NULL,
nextPermissions int NULL,
currentPermissions int NULL,
basePermissions int NULL,
everyonePermissions int NULL,
groupPermissions int NULL
) ON [PRIMARY]
IF EXISTS(SELECT * FROM dbo.primitems)
EXEC('INSERT INTO dbo.Tmp_primitems (itemID, primID, assetID, parentFolderID, invType, assetType, name, description, creationDate, creatorID, ownerID, lastOwnerID, groupID, nextPermissions, currentPermissions, basePermissions, everyonePermissions, groupPermissions)
SELECT CONVERT(varchar(36), itemID), CONVERT(varchar(36), primID), CONVERT(varchar(36), assetID), CONVERT(varchar(36), parentFolderID), invType, assetType, name, description, creationDate, CONVERT(varchar(36), creatorID), CONVERT(varchar(36), ownerID), CONVERT(varchar(36), lastOwnerID), CONVERT(varchar(36), groupID), nextPermissions, currentPermissions, basePermissions, everyonePermissions, groupPermissions')
DROP TABLE dbo.primitems
EXECUTE sp_rename N'dbo.Tmp_primitems', N'primitems', 'OBJECT'
ALTER TABLE dbo.primitems ADD CONSTRAINT
PK__primitems__0A688BB1 PRIMARY KEY CLUSTERED
(
itemID
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
COMMIT

View File

@ -0,0 +1,49 @@
BEGIN TRANSACTION
CREATE TABLE dbo.Tmp_primshapes
(
UUID varchar(36) NOT NULL,
Shape int NULL,
ScaleX float(53) NULL,
ScaleY float(53) NULL,
ScaleZ float(53) NULL,
PCode int NULL,
PathBegin int NULL,
PathEnd int NULL,
PathScaleX int NULL,
PathScaleY int NULL,
PathShearX int NULL,
PathShearY int NULL,
PathSkew int NULL,
PathCurve int NULL,
PathRadiusOffset int NULL,
PathRevolutions int NULL,
PathTaperX int NULL,
PathTaperY int NULL,
PathTwist int NULL,
PathTwistBegin int NULL,
ProfileBegin int NULL,
ProfileEnd int NULL,
ProfileCurve int NULL,
ProfileHollow int NULL,
State int NULL,
Texture image NULL,
ExtraParams image NULL
) ON [PRIMARY]
TEXTIMAGE_ON [PRIMARY]
IF EXISTS(SELECT * FROM dbo.primshapes)
EXEC('INSERT INTO dbo.Tmp_primshapes (UUID, Shape, ScaleX, ScaleY, ScaleZ, PCode, PathBegin, PathEnd, PathScaleX, PathScaleY, PathShearX, PathShearY, PathSkew, PathCurve, PathRadiusOffset, PathRevolutions, PathTaperX, PathTaperY, PathTwist, PathTwistBegin, ProfileBegin, ProfileEnd, ProfileCurve, ProfileHollow, State, Texture, ExtraParams)
SELECT CONVERT(varchar(36), UUID), Shape, ScaleX, ScaleY, ScaleZ, PCode, PathBegin, PathEnd, PathScaleX, PathScaleY, PathShearX, PathShearY, PathSkew, PathCurve, PathRadiusOffset, PathRevolutions, PathTaperX, PathTaperY, PathTwist, PathTwistBegin, ProfileBegin, ProfileEnd, ProfileCurve, ProfileHollow, State, Texture, ExtraParams FROM dbo.primshapes WITH (HOLDLOCK TABLOCKX)')
DROP TABLE dbo.primshapes
EXECUTE sp_rename N'dbo.Tmp_primshapes', N'primshapes', 'OBJECT'
ALTER TABLE dbo.primshapes ADD CONSTRAINT
PK__primshapes__0880433F PRIMARY KEY CLUSTERED
(
UUID
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
COMMIT

View File

@ -0,0 +1,36 @@
BEGIN TRANSACTION
ALTER TABLE prims ADD PayPrice int not null default 0
ALTER TABLE prims ADD PayButton1 int not null default 0
ALTER TABLE prims ADD PayButton2 int not null default 0
ALTER TABLE prims ADD PayButton3 int not null default 0
ALTER TABLE prims ADD PayButton4 int not null default 0
ALTER TABLE prims ADD LoopedSound varchar(36) not null default '00000000-0000-0000-0000-000000000000';
ALTER TABLE prims ADD LoopedSoundGain float not null default 0.0;
ALTER TABLE prims ADD TextureAnimation image
ALTER TABLE prims ADD OmegaX float not null default 0.0
ALTER TABLE prims ADD OmegaY float not null default 0.0
ALTER TABLE prims ADD OmegaZ float not null default 0.0
ALTER TABLE prims ADD CameraEyeOffsetX float not null default 0.0
ALTER TABLE prims ADD CameraEyeOffsetY float not null default 0.0
ALTER TABLE prims ADD CameraEyeOffsetZ float not null default 0.0
ALTER TABLE prims ADD CameraAtOffsetX float not null default 0.0
ALTER TABLE prims ADD CameraAtOffsetY float not null default 0.0
ALTER TABLE prims ADD CameraAtOffsetZ float not null default 0.0
ALTER TABLE prims ADD ForceMouselook tinyint not null default 0
ALTER TABLE prims ADD ScriptAccessPin int not null default 0
ALTER TABLE prims ADD AllowedDrop tinyint not null default 0
ALTER TABLE prims ADD DieAtEdge tinyint not null default 0
ALTER TABLE prims ADD SalePrice int not null default 10
ALTER TABLE prims ADD SaleType tinyint not null default 0
ALTER TABLE primitems add flags integer not null default 0
ALTER TABLE land ADD AuthbuyerID varchar(36) NOT NULL default '00000000-0000-0000-0000-000000000000'
CREATE index prims_regionuuid on prims(RegionUUID)
CREATE index prims_parentid on prims(ParentID)
CREATE index primitems_primid on primitems(primID)
COMMIT

View File

@ -103,7 +103,7 @@ namespace OpenSim.Data
private void Initialize()
{
// clever, eh, we figure out which migrations version we are
int migration_version = FindVersion("migrations");
int migration_version = FindVersion(_conn, "migrations");
if (migration_version > 0)
return;
@ -119,7 +119,7 @@ namespace OpenSim.Data
public void Update()
{
int version = 0;
version = FindVersion(_type);
version = FindVersion(_conn, _type);
SortedList<int, string> migrations = GetMigrationsAfter(version);
if (migrations.Count < 1)
@ -170,7 +170,7 @@ namespace OpenSim.Data
public int Version
{
get { return FindVersion(_type); }
get { return FindVersion(_conn, _type); }
set {
if (Version < 1)
{
@ -183,10 +183,10 @@ namespace OpenSim.Data
}
}
private int FindVersion(string type)
protected virtual int FindVersion(DbConnection conn, string type)
{
int version = 0;
DbCommand cmd = _conn.CreateCommand();
DbCommand cmd = conn.CreateCommand();
try
{
cmd.CommandText = "select version from migrations where name='" + type + "' limit 1";