Thank you kindly, StrawberryFride, for a patch that:

Adds maturity & access logic for MSSQL platform to 
mirror that of MySQL as committed in 9502.
0.6.6-post-fixes
Charles Krinke 2009-05-17 18:18:48 +00:00
parent 74f1c16c49
commit 7a8a481f88
5 changed files with 168 additions and 155 deletions

View File

@ -27,6 +27,7 @@
using System; using System;
using System.Data; using System.Data;
using System.Data.SqlClient;
using System.Reflection; using System.Reflection;
using System.Collections.Generic; using System.Collections.Generic;
using OpenMetaverse; using OpenMetaverse;
@ -124,10 +125,11 @@ namespace OpenSim.Data.MSSQL
/// <returns></returns> /// <returns></returns>
override protected AssetBase FetchStoredAsset(UUID assetID) override protected AssetBase FetchStoredAsset(UUID assetID)
{ {
using (AutoClosingSqlCommand command = m_database.Query("SELECT * FROM assets WHERE id = @id")) string sql = "SELECT * FROM assets WHERE id = @id";
using (AutoClosingSqlCommand command = m_database.Query(sql))
{ {
command.Parameters.Add(m_database.CreateParameter("id", assetID)); command.Parameters.Add(m_database.CreateParameter("id", assetID));
using (IDataReader reader = command.ExecuteReader()) using (SqlDataReader reader = command.ExecuteReader())
{ {
if (reader.Read()) if (reader.Read())
{ {
@ -157,11 +159,13 @@ namespace OpenSim.Data.MSSQL
{ {
return; return;
} }
string sql = @"INSERT INTO assets
using (AutoClosingSqlCommand command = m_database.Query( ([id], [name], [description], [assetType], [local],
"INSERT INTO assets ([id], [name], [description], [assetType], [local], [temporary], [create_time], [access_time], [data])" + [temporary], [create_time], [access_time], [data])
" VALUES " + VALUES
"(@id, @name, @description, @assetType, @local, @temporary, @create_time, @access_time, @data)")) (@id, @name, @description, @assetType, @local,
@temporary, @create_time, @access_time, @data)";
using (AutoClosingSqlCommand command = m_database.Query(sql))
{ {
int now = (int)((System.DateTime.Now.Ticks - m_ticksToEpoch) / 10000000); int now = (int)((System.DateTime.Now.Ticks - m_ticksToEpoch) / 10000000);
command.Parameters.Add(m_database.CreateParameter("id", asset.FullID)); command.Parameters.Add(m_database.CreateParameter("id", asset.FullID));
@ -184,14 +188,10 @@ namespace OpenSim.Data.MSSQL
/// <param name="asset">the asset</param> /// <param name="asset">the asset</param>
override public void UpdateAsset(AssetBase asset) override public void UpdateAsset(AssetBase asset)
{ {
using (AutoClosingSqlCommand command = m_database.Query("UPDATE assets set id = @id, " + string sql = @"UPDATE assets set id = @id, name = @name, description = @description, assetType = @assetType,
"name = @name, " + local = @local, temporary = @temporary, data = @data
"description = @description," + WHERE id = @keyId;";
"assetType = @assetType," + using (AutoClosingSqlCommand command = m_database.Query(sql))
"local = @local," +
"temporary = @temporary," +
"data = @data where " +
"id = @keyId;"))
{ {
command.Parameters.Add(m_database.CreateParameter("id", asset.FullID)); command.Parameters.Add(m_database.CreateParameter("id", asset.FullID));
command.Parameters.Add(m_database.CreateParameter("name", asset.Name)); command.Parameters.Add(m_database.CreateParameter("name", asset.Name));
@ -257,18 +257,19 @@ namespace OpenSim.Data.MSSQL
public override List<AssetMetadata> FetchAssetMetadataSet(int start, int count) public override List<AssetMetadata> FetchAssetMetadataSet(int start, int count)
{ {
List<AssetMetadata> retList = new List<AssetMetadata>(count); List<AssetMetadata> retList = new List<AssetMetadata>(count);
string sql = @"SELECT (name,description,assetType,temporary,id), Row = ROW_NUMBER()
using (AutoClosingSqlCommand command = m_database.Query("SELECT (name,description,assetType,temporary,id), Row = ROW_NUMBER() OVER (ORDER BY (some column to order by)) WHERE Row >= @Start AND Row < @Start + @Count")) OVER (ORDER BY (some column to order by))
WHERE Row >= @Start AND Row < @Start + @Count";
using (AutoClosingSqlCommand command = m_database.Query(sql))
{ {
command.Parameters.Add(m_database.CreateParameter("start", start)); command.Parameters.Add(m_database.CreateParameter("start", start));
command.Parameters.Add(m_database.CreateParameter("count", count)); command.Parameters.Add(m_database.CreateParameter("count", count));
using (IDataReader reader = command.ExecuteReader()) using (SqlDataReader reader = command.ExecuteReader())
{ {
while (reader.Read()) while (reader.Read())
{ {
AssetMetadata metadata = new AssetMetadata(); AssetMetadata metadata = new AssetMetadata();
// Region Main
metadata.FullID = new UUID((Guid)reader["id"]); metadata.FullID = new UUID((Guid)reader["id"]);
metadata.Name = (string)reader["name"]; metadata.Name = (string)reader["name"];
metadata.Description = (string)reader["description"]; metadata.Description = (string)reader["description"];

View File

@ -108,7 +108,7 @@ namespace OpenSim.Data.MSSQL
{ {
cmd.Parameters.Add(_Database.CreateParameter("@RegionID", regionID)); cmd.Parameters.Add(_Database.CreateParameter("@RegionID", regionID));
using (IDataReader reader = cmd.ExecuteReader()) using (SqlDataReader reader = cmd.ExecuteReader())
{ {
if (reader.Read()) if (reader.Read())
{ {
@ -323,7 +323,7 @@ namespace OpenSim.Data.MSSQL
idParameter.Value = es.EstateID; idParameter.Value = es.EstateID;
cmd.Parameters.Add(idParameter); cmd.Parameters.Add(idParameter);
using (IDataReader reader = cmd.ExecuteReader()) using (SqlDataReader reader = cmd.ExecuteReader())
{ {
while (reader.Read()) while (reader.Read())
{ {
@ -351,7 +351,7 @@ namespace OpenSim.Data.MSSQL
{ {
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID)); cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID));
using (IDataReader reader = cmd.ExecuteReader()) using (SqlDataReader reader = cmd.ExecuteReader())
{ {
while (reader.Read()) while (reader.Read())
{ {
@ -385,11 +385,8 @@ namespace OpenSim.Data.MSSQL
foreach (EstateBan b in es.EstateBans) foreach (EstateBan b in es.EstateBans)
{ {
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID)); cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID));
cmd.Parameters.Add(_Database.CreateParameter("@bannedUUID", b.BannedUserID)); cmd.Parameters.Add(_Database.CreateParameter("@bannedUUID", b.BannedUserID));
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
cmd.Parameters.Clear(); cmd.Parameters.Clear();
} }
} }

View File

@ -445,9 +445,7 @@ namespace OpenSim.Data.MSSQL
// World Map Addition // World Map Addition
retval.regionMapTextureID = new UUID((Guid)reader["regionMapTexture"]); retval.regionMapTextureID = new UUID((Guid)reader["regionMapTexture"]);
retval.owner_uuid = new UUID((Guid)reader["owner_uuid"]); retval.owner_uuid = new UUID((Guid)reader["owner_uuid"]);
// UUID.TryParse((string)reader["regionMapTexture"], out retval.regionMapTextureID); retval.maturity = Convert.ToUInt32(reader["access"]);
// UUID.TryParse((string)reader["owner_uuid"], out retval.owner_uuid);
return retval; return retval;
} }
@ -535,11 +533,11 @@ namespace OpenSim.Data.MSSQL
[serverIP], [serverPort], [serverURI], [locX], [locY], [locZ], [eastOverrideHandle], [westOverrideHandle], [serverIP], [serverPort], [serverURI], [locX], [locY], [locZ], [eastOverrideHandle], [westOverrideHandle],
[southOverrideHandle], [northOverrideHandle], [regionAssetURI], [regionAssetRecvKey], [regionAssetSendKey], [southOverrideHandle], [northOverrideHandle], [regionAssetURI], [regionAssetRecvKey], [regionAssetSendKey],
[regionUserURI], [regionUserRecvKey], [regionUserSendKey], [regionMapTexture], [serverHttpPort], [regionUserURI], [regionUserRecvKey], [regionUserSendKey], [regionMapTexture], [serverHttpPort],
[serverRemotingPort], [owner_uuid], [originUUID]) [serverRemotingPort], [owner_uuid], [originUUID], [access])
VALUES (@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, VALUES (@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI,
@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle,
@southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, @regionAssetSendKey, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, @regionAssetSendKey,
@regionUserURI, @regionUserRecvKey, @regionUserSendKey, @regionMapTexture, @serverHttpPort, @serverRemotingPort, @owner_uuid, @originUUID);"; @regionUserURI, @regionUserRecvKey, @regionUserSendKey, @regionMapTexture, @serverHttpPort, @serverRemotingPort, @owner_uuid, @originUUID, @access);";
using (AutoClosingSqlCommand command = database.Query(sql)) using (AutoClosingSqlCommand command = database.Query(sql))
{ {
@ -571,6 +569,7 @@ namespace OpenSim.Data.MSSQL
command.Parameters.Add(database.CreateParameter("serverRemotingPort", profile.remotingPort)); command.Parameters.Add(database.CreateParameter("serverRemotingPort", profile.remotingPort));
command.Parameters.Add(database.CreateParameter("owner_uuid", profile.owner_uuid)); command.Parameters.Add(database.CreateParameter("owner_uuid", profile.owner_uuid));
command.Parameters.Add(database.CreateParameter("originUUID", profile.originUUID)); command.Parameters.Add(database.CreateParameter("originUUID", profile.originUUID));
command.Parameters.Add(database.CreateParameter("access", profile.maturity));
try try
{ {

View File

@ -69,7 +69,6 @@ namespace OpenSim.Data.MSSQL
/// <remarks>use mssql_connection.ini</remarks> /// <remarks>use mssql_connection.ini</remarks>
override public void Initialise(string connect) override public void Initialise(string connect)
{ {
if (!string.IsNullOrEmpty(connect)) if (!string.IsNullOrEmpty(connect))
{ {
database = new MSSQLManager(connect); database = new MSSQLManager(connect);
@ -106,11 +105,12 @@ namespace OpenSim.Data.MSSQL
/// <returns>A user profile</returns> /// <returns>A user profile</returns>
override public UserProfileData GetUserByName(string user, string last) override public UserProfileData GetUserByName(string user, string last)
{ {
using (AutoClosingSqlCommand command = database.Query("SELECT * FROM " + m_usersTableName + " WHERE username = @first AND lastname = @second")) string sql = string.Format(@"SELECT * FROM {0}
WHERE username = @first AND lastname = @second", m_usersTableName);
using (AutoClosingSqlCommand command = database.Query(sql))
{ {
command.Parameters.Add(database.CreateParameter("first", user)); command.Parameters.Add(database.CreateParameter("first", user));
command.Parameters.Add(database.CreateParameter("second", last)); command.Parameters.Add(database.CreateParameter("second", last));
try try
{ {
using (SqlDataReader reader = command.ExecuteReader()) using (SqlDataReader reader = command.ExecuteReader())
@ -120,7 +120,7 @@ namespace OpenSim.Data.MSSQL
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Error("[USER DB] Error getting user profile, error: " + e.Message); m_log.ErrorFormat("[USER DB] Error getting user profile for {0} {1}: {2}", user, last, e.Message);
return null; return null;
} }
} }
@ -133,20 +133,20 @@ namespace OpenSim.Data.MSSQL
/// <returns></returns> /// <returns></returns>
override public UserProfileData GetUserByUUID(UUID uuid) override public UserProfileData GetUserByUUID(UUID uuid)
{ {
using (AutoClosingSqlCommand command = database.Query("SELECT * FROM " + m_usersTableName + " WHERE UUID = @uuid")) string sql = string.Format("SELECT * FROM {0} WHERE UUID = @uuid", m_usersTableName);
using (AutoClosingSqlCommand command = database.Query(sql))
{ {
command.Parameters.Add(database.CreateParameter("uuid", uuid)); command.Parameters.Add(database.CreateParameter("uuid", uuid));
try try
{ {
using (IDataReader reader = command.ExecuteReader()) using (SqlDataReader reader = command.ExecuteReader())
{ {
return ReadUserRow(reader); return ReadUserRow(reader);
} }
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Error("[USER DB] Error getting user profile by UUID, error: " + e.Message); m_log.ErrorFormat("[USER DB] Error getting user profile by UUID {0}, error: {1}", uuid, e.Message);
return null; return null;
} }
} }
@ -173,7 +173,7 @@ namespace OpenSim.Data.MSSQL
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Error("[USER DB] Error adding new profile, error: " + e.Message); m_log.ErrorFormat("[USER DB] Error adding new profile, error: {0}", e.Message);
} }
} }
@ -184,36 +184,37 @@ namespace OpenSim.Data.MSSQL
/// <returns></returns> /// <returns></returns>
override public bool UpdateUserProfile(UserProfileData user) override public bool UpdateUserProfile(UserProfileData user)
{ {
using (AutoClosingSqlCommand command = database.Query("UPDATE " + m_usersTableName + " set UUID = @uuid, " + string sql = string.Format(@"UPDATE {0}
"username = @username, " + SET UUID = @uuid,
"lastname = @lastname," + username = @username,
"email = @email," + lastname = @lastname,
"passwordHash = @passwordHash," + email = @email,
"passwordSalt = @passwordSalt," + passwordHash = @passwordHash,
"homeRegion = @homeRegion," + passwordSalt = @passwordSalt,
"homeLocationX = @homeLocationX," + homeRegion = @homeRegion,
"homeLocationY = @homeLocationY," + homeLocationX = @homeLocationX,
"homeLocationZ = @homeLocationZ," + homeLocationY = @homeLocationY,
"homeLookAtX = @homeLookAtX," + homeLocationZ = @homeLocationZ,
"homeLookAtY = @homeLookAtY," + homeLookAtX = @homeLookAtX,
"homeLookAtZ = @homeLookAtZ," + homeLookAtY = @homeLookAtY,
"created = @created," + homeLookAtZ = @homeLookAtZ,
"lastLogin = @lastLogin," + created = @created,
"userInventoryURI = @userInventoryURI," + lastLogin = @lastLogin,
"userAssetURI = @userAssetURI," + userInventoryURI = @userInventoryURI,
"profileCanDoMask = @profileCanDoMask," + userAssetURI = @userAssetURI,
"profileWantDoMask = @profileWantDoMask," + profileCanDoMask = @profileCanDoMask,
"profileAboutText = @profileAboutText," + profileWantDoMask = @profileWantDoMask,
"profileFirstText = @profileFirstText," + profileAboutText = @profileAboutText,
"profileImage = @profileImage," + profileFirstText = @profileFirstText,
"profileFirstImage = @profileFirstImage, " + profileImage = @profileImage,
"webLoginKey = @webLoginKey, " + profileFirstImage = @profileFirstImage,
"homeRegionID = @homeRegionID, " + webLoginKey = @webLoginKey,
"userFlags = @userFlags, " + homeRegionID = @homeRegionID,
"godLevel = @godLevel, " + userFlags = @userFlags,
"customType = @customType, " + godLevel = @godLevel,
"partner = @partner where " + customType = @customType,
"UUID = @keyUUUID;")) partner = @partner WHERE UUID = @keyUUUID;",m_usersTableName);
using (AutoClosingSqlCommand command = database.Query(sql))
{ {
command.Parameters.Add(database.CreateParameter("uuid", user.ID)); command.Parameters.Add(database.CreateParameter("uuid", user.ID));
command.Parameters.Add(database.CreateParameter("username", user.FirstName)); command.Parameters.Add(database.CreateParameter("username", user.FirstName));
@ -239,7 +240,6 @@ namespace OpenSim.Data.MSSQL
command.Parameters.Add(database.CreateParameter("profileImage", user.Image)); command.Parameters.Add(database.CreateParameter("profileImage", user.Image));
command.Parameters.Add(database.CreateParameter("profileFirstImage", user.FirstLifeImage)); command.Parameters.Add(database.CreateParameter("profileFirstImage", user.FirstLifeImage));
command.Parameters.Add(database.CreateParameter("webLoginKey", user.WebLoginKey)); command.Parameters.Add(database.CreateParameter("webLoginKey", user.WebLoginKey));
//
command.Parameters.Add(database.CreateParameter("homeRegionID", user.HomeRegionID)); command.Parameters.Add(database.CreateParameter("homeRegionID", user.HomeRegionID));
command.Parameters.Add(database.CreateParameter("userFlags", user.UserFlags)); command.Parameters.Add(database.CreateParameter("userFlags", user.UserFlags));
command.Parameters.Add(database.CreateParameter("godLevel", user.GodLevel)); command.Parameters.Add(database.CreateParameter("godLevel", user.GodLevel));
@ -254,7 +254,7 @@ namespace OpenSim.Data.MSSQL
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Error("[USER DB] Error updating profile, error: " + e.Message); m_log.ErrorFormat("[USER DB] Error updating profile, error: {0}", e.Message);
} }
} }
return false; return false;
@ -293,7 +293,8 @@ namespace OpenSim.Data.MSSQL
/// <returns>The users session</returns> /// <returns>The users session</returns>
override public UserAgentData GetAgentByUUID(UUID uuid) override public UserAgentData GetAgentByUUID(UUID uuid)
{ {
using (AutoClosingSqlCommand command = database.Query("SELECT * FROM " + m_agentsTableName + " WHERE UUID = @uuid")) string sql = string.Format("SELECT * FROM {0} WHERE UUID = @uuid", m_agentsTableName);
using (AutoClosingSqlCommand command = database.Query(sql))
{ {
command.Parameters.Add(database.CreateParameter("uuid", uuid)); command.Parameters.Add(database.CreateParameter("uuid", uuid));
try try
@ -305,7 +306,7 @@ namespace OpenSim.Data.MSSQL
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Error("[USER DB] Error updating agentdata by UUID, error: " + e.Message); m_log.ErrorFormat("[USER DB] Error updating agentdata by UUID, error: {0}", e.Message);
return null; return null;
} }
} }
@ -323,7 +324,7 @@ namespace OpenSim.Data.MSSQL
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Error("[USER DB] Error adding new agentdata, error: " + e.Message); m_log.ErrorFormat("[USER DB] Error adding new agentdata, error: {0}", e.Message);
} }
} }
@ -340,12 +341,11 @@ namespace OpenSim.Data.MSSQL
override public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms) override public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
{ {
int dtvalue = Util.UnixTimeSinceEpoch(); int dtvalue = Util.UnixTimeSinceEpoch();
string sql = string.Format(@"INSERT INTO {0}
using (AutoClosingSqlCommand command = database.Query( (ownerID,friendID,friendPerms,datetimestamp)
"INSERT INTO " + m_userFriendsTableName + " " + VALUES
"(ownerID,friendID,friendPerms,datetimestamp) " + (@ownerID,@friendID,@friendPerms,@datetimestamp)", m_userFriendsTableName);
"VALUES " + using (AutoClosingSqlCommand command = database.Query(sql))
"(@ownerID,@friendID,@friendPerms,@datetimestamp)"))
{ {
command.Parameters.Add(database.CreateParameter("ownerID", friendlistowner)); command.Parameters.Add(database.CreateParameter("ownerID", friendlistowner));
command.Parameters.Add(database.CreateParameter("friendID", friend)); command.Parameters.Add(database.CreateParameter("friendID", friend));
@ -355,14 +355,16 @@ namespace OpenSim.Data.MSSQL
try try
{ {
command.CommandText = string.Format("INSERT INTO {0} (ownerID,friendID,friendPerms,datetimestamp) VALUES (@friendID,@ownerID,@friendPerms,@datetimestamp)", sql = string.Format(@"INSERT INTO {0}
m_userFriendsTableName); (ownerID,friendID,friendPerms,datetimestamp)
VALUES
(@friendID,@ownerID,@friendPerms,@datetimestamp)", m_userFriendsTableName);
command.CommandText = sql;
command.ExecuteNonQuery(); command.ExecuteNonQuery();
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Error("[USER DB] Error adding new userfriend, error: " + e.Message); m_log.ErrorFormat("[USER DB] Error adding new userfriend, error: {0}", e.Message);
return; return;
} }
} }
@ -375,21 +377,25 @@ namespace OpenSim.Data.MSSQL
/// <param name="friend">UUID of the not-so-friendly user to remove from the list</param> /// <param name="friend">UUID of the not-so-friendly user to remove from the list</param>
override public void RemoveUserFriend(UUID friendlistowner, UUID friend) override public void RemoveUserFriend(UUID friendlistowner, UUID friend)
{ {
using (AutoClosingSqlCommand command = database.Query("delete from " + m_userFriendsTableName + " where ownerID = @ownerID and friendID = @friendID")) string sql = string.Format(@"DELETE from {0}
WHERE ownerID = @ownerID
AND friendID = @friendID", m_userFriendsTableName);
using (AutoClosingSqlCommand command = database.Query(sql))
{ {
command.Parameters.Add(database.CreateParameter("@ownerID", friendlistowner)); command.Parameters.Add(database.CreateParameter("@ownerID", friendlistowner));
command.Parameters.Add(database.CreateParameter("@friendID", friend)); command.Parameters.Add(database.CreateParameter("@friendID", friend));
command.ExecuteNonQuery(); command.ExecuteNonQuery();
sql = string.Format(@"DELETE from {0}
command.CommandText = "delete from " + m_userFriendsTableName + WHERE ownerID = @friendID
" where ownerID = @friendID and friendID = @ownerID"; AND friendID = @ownerID", m_userFriendsTableName);
command.CommandText = sql;
try try
{ {
command.ExecuteNonQuery(); command.ExecuteNonQuery();
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Error("[USER DB] Error removing userfriend, error: " + e.Message); m_log.ErrorFormat("[USER DB] Error removing userfriend, error: {0}", e.Message);
} }
} }
} }
@ -402,10 +408,10 @@ namespace OpenSim.Data.MSSQL
/// <param name="perms">new permission flag</param> /// <param name="perms">new permission flag</param>
override public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms) override public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
{ {
using (AutoClosingSqlCommand command = database.Query( string sql = string.Format(@"UPDATE {0} SET friendPerms = @friendPerms
"update " + m_userFriendsTableName + WHERE ownerID = @ownerID
" SET friendPerms = @friendPerms " + AND friendID = @friendID", m_userFriendsTableName);
"where ownerID = @ownerID and friendID = @friendID")) using (AutoClosingSqlCommand command = database.Query(sql))
{ {
command.Parameters.Add(database.CreateParameter("@ownerID", friendlistowner)); command.Parameters.Add(database.CreateParameter("@ownerID", friendlistowner));
command.Parameters.Add(database.CreateParameter("@friendID", friend)); command.Parameters.Add(database.CreateParameter("@friendID", friend));
@ -417,7 +423,7 @@ namespace OpenSim.Data.MSSQL
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Error("[USER DB] Error updating userfriend, error: " + e.Message); m_log.ErrorFormat("[USER DB] Error updating userfriend, error: {0}", e.Message);
} }
} }
} }
@ -432,15 +438,17 @@ namespace OpenSim.Data.MSSQL
List<FriendListItem> friendList = new List<FriendListItem>(); List<FriendListItem> friendList = new List<FriendListItem>();
//Left Join userfriends to itself //Left Join userfriends to itself
using (AutoClosingSqlCommand command = database.Query( string sql = string.Format(@"SELECT a.ownerID, a.friendID, a.friendPerms, b.friendPerms AS ownerperms
"select a.ownerID,a.friendID,a.friendPerms,b.friendPerms as ownerperms from " + m_userFriendsTableName + " as a, " + m_userFriendsTableName + " as b" + FROM {0} as a, {0} as b
" where a.ownerID = @ownerID and b.ownerID = a.friendID and b.friendID = a.ownerID")) WHERE a.ownerID = @ownerID
AND b.ownerID = a.friendID
AND b.friendID = a.ownerID", m_userFriendsTableName);
using (AutoClosingSqlCommand command = database.Query(sql))
{ {
command.Parameters.Add(database.CreateParameter("@ownerID", friendlistowner)); command.Parameters.Add(database.CreateParameter("@ownerID", friendlistowner));
try try
{ {
using (IDataReader reader = command.ExecuteReader()) using (SqlDataReader reader = command.ExecuteReader())
{ {
while (reader.Read()) while (reader.Read())
{ {
@ -451,17 +459,15 @@ namespace OpenSim.Data.MSSQL
// This is not a real column in the database table, it's a joined column from the opposite record // This is not a real column in the database table, it's a joined column from the opposite record
fli.FriendListOwnerPerms = (uint)Convert.ToInt32(reader["ownerperms"]); fli.FriendListOwnerPerms = (uint)Convert.ToInt32(reader["ownerperms"]);
friendList.Add(fli); friendList.Add(fli);
} }
} }
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Error("[USER DB] Error updating userfriend, error: " + e.Message); m_log.ErrorFormat("[USER DB] Error updating userfriend, error: {0}", e.Message);
} }
} }
return friendList; return friendList;
} }
@ -472,12 +478,12 @@ namespace OpenSim.Data.MSSQL
{ {
foreach (UUID uuid in uuids) foreach (UUID uuid in uuids)
{ {
using (AutoClosingSqlCommand command = database.Query( string sql = string.Format(@"SELECT agentOnline,currentHandle
"select agentOnline,currentHandle from " + m_agentsTableName + " where UUID = @uuid")) FROM {0} WHERE UUID = @uuid", m_agentsTableName);
using (AutoClosingSqlCommand command = database.Query(sql))
{ {
command.Parameters.Add(database.CreateParameter("@uuid", uuid)); command.Parameters.Add(database.CreateParameter("@uuid", uuid));
using (SqlDataReader reader = command.ExecuteReader())
using (IDataReader reader = command.ExecuteReader())
{ {
while (reader.Read()) while (reader.Read())
{ {
@ -541,11 +547,11 @@ namespace OpenSim.Data.MSSQL
try try
{ {
AvatarAppearance appearance = new AvatarAppearance(); AvatarAppearance appearance = new AvatarAppearance();
string sql = "SELECT * FROM avatarappearance WHERE owner = @UUID";
using (AutoClosingSqlCommand command = database.Query("SELECT * FROM avatarappearance WHERE owner = @UUID")) using (AutoClosingSqlCommand command = database.Query(sql))
{ {
command.Parameters.Add(database.CreateParameter("@UUID", user)); command.Parameters.Add(database.CreateParameter("@UUID", user));
using (IDataReader reader = command.ExecuteReader()) using (SqlDataReader reader = command.ExecuteReader())
{ {
if (reader.Read()) if (reader.Read())
appearance = readUserAppearance(reader); appearance = readUserAppearance(reader);
@ -564,12 +570,11 @@ namespace OpenSim.Data.MSSQL
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Error("[USER DB] Error updating userfriend, error: " + e.Message); m_log.ErrorFormat("[USER DB] Error updating userfriend, error: {0}", e.Message);
} }
return null; return null;
} }
/// <summary> /// <summary>
/// Update a user appearence into database /// Update a user appearence into database
/// </summary> /// </summary>
@ -577,20 +582,23 @@ namespace OpenSim.Data.MSSQL
/// <param name="appearance">the appearence</param> /// <param name="appearance">the appearence</param>
override public void UpdateUserAppearance(UUID user, AvatarAppearance appearance) override public void UpdateUserAppearance(UUID user, AvatarAppearance appearance)
{ {
m_log.Error("[USER DB] updating user appearance for user ID " + user.Guid); string sql = @"DELETE FROM avatarappearance WHERE owner=@owner;
string sql = String.Empty; INSERT INTO avatarappearance
sql += "DELETE FROM avatarappearance WHERE owner=@owner "; (owner, serial, visual_params, texture, avatar_height,
sql += "INSERT INTO avatarappearance "; body_item, body_asset, skin_item, skin_asset, hair_item,
sql += "(owner, serial, visual_params, texture, avatar_height, "; hair_asset, eyes_item, eyes_asset, shirt_item, shirt_asset,
sql += "body_item, body_asset, skin_item, skin_asset, hair_item, hair_asset, eyes_item, eyes_asset, "; pants_item, pants_asset, shoes_item, shoes_asset, socks_item,
sql += "shirt_item, shirt_asset, pants_item, pants_asset, shoes_item, shoes_asset, socks_item, socks_asset, "; socks_asset, jacket_item, jacket_asset, gloves_item, gloves_asset,
sql += "jacket_item, jacket_asset, gloves_item, gloves_asset, undershirt_item, undershirt_asset, underpants_item, underpants_asset, "; undershirt_item, undershirt_asset, underpants_item, underpants_asset,
sql += "skirt_item, skirt_asset) values ("; skirt_item, skirt_asset)
sql += "@owner, @serial, @visual_params, @texture, @avatar_height, "; VALUES
sql += "@body_item, @body_asset, @skin_item, @skin_asset, @hair_item, @hair_asset, @eyes_item, @eyes_asset, "; (@owner, @serial, @visual_params, @texture, @avatar_height,
sql += "@shirt_item, @shirt_asset, @pants_item, @pants_asset, @shoes_item, @shoes_asset, @socks_item, @socks_asset, "; @body_item, @body_asset, @skin_item, @skin_asset, @hair_item,
sql += "@jacket_item, @jacket_asset, @gloves_item, @gloves_asset, @undershirt_item, @undershirt_asset, @underpants_item, @underpants_asset, "; @hair_asset, @eyes_item, @eyes_asset, @shirt_item, @shirt_asset,
sql += "@skirt_item, @skirt_asset)"; @pants_item, @pants_asset, @shoes_item, @shoes_asset, @socks_item,
@socks_asset, @jacket_item, @jacket_asset, @gloves_item, @gloves_asset,
@undershirt_item, @undershirt_asset, @underpants_item, @underpants_asset,
@skirt_item, @skirt_asset)";
using (AutoClosingSqlCommand cmd = database.Query(sql)) using (AutoClosingSqlCommand cmd = database.Query(sql))
{ {
@ -632,10 +640,9 @@ namespace OpenSim.Data.MSSQL
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Error("[USER DB] Error updating user appearance, error: " + e.Message); m_log.ErrorFormat("[USER DB] Error updating user appearance, error: {0}", e.Message);
} }
} }
UpdateUserAttachments(user, appearance.GetAttachments()); UpdateUserAttachments(user, appearance.GetAttachments());
} }
@ -651,7 +658,8 @@ namespace OpenSim.Data.MSSQL
public Hashtable GetUserAttachments(UUID agentID) public Hashtable GetUserAttachments(UUID agentID)
{ {
Hashtable returnTable = new Hashtable(); Hashtable returnTable = new Hashtable();
using (AutoClosingSqlCommand command = database.Query("select attachpoint, item, asset from avatarattachments where UUID = @uuid", database.CreateParameter("@uuid", agentID))) string sql = "select attachpoint, item, asset from avatarattachments where UUID = @uuid";
using (AutoClosingSqlCommand command = database.Query(sql, database.CreateParameter("@uuid", agentID)))
{ {
using (SqlDataReader reader = command.ExecuteReader()) using (SqlDataReader reader = command.ExecuteReader())
{ {
@ -678,7 +686,7 @@ namespace OpenSim.Data.MSSQL
/// <param name="data">data with all items on attachmentpoints</param> /// <param name="data">data with all items on attachmentpoints</param>
public void UpdateUserAttachments(UUID agentID, Hashtable data) public void UpdateUserAttachments(UUID agentID, Hashtable data)
{ {
string sql = "delete from avatarattachments where UUID = @uuid"; string sql = "DELETE FROM avatarattachments WHERE UUID = @uuid";
using (AutoClosingSqlCommand command = database.Query(sql)) using (AutoClosingSqlCommand command = database.Query(sql))
{ {
@ -688,7 +696,8 @@ namespace OpenSim.Data.MSSQL
if (data == null) if (data == null)
return; return;
sql = "insert into avatarattachments (UUID, attachpoint, item, asset) values (@uuid, @attachpoint, @item, @asset)"; sql = @"INSERT INTO avatarattachments (UUID, attachpoint, item, asset)
VALUES (@uuid, @attachpoint, @item, @asset)";
using (AutoClosingSqlCommand command = database.Query(sql)) using (AutoClosingSqlCommand command = database.Query(sql))
{ {
@ -730,7 +739,8 @@ namespace OpenSim.Data.MSSQL
/// <param name="agentID">agentID.</param> /// <param name="agentID">agentID.</param>
override public void ResetAttachments(UUID agentID) override public void ResetAttachments(UUID agentID)
{ {
using (AutoClosingSqlCommand command = database.Query("update avatarattachments set asset = '00000000-0000-0000-0000-000000000000' where UUID = @uuid")) string sql = "UPDATE avatarattachments SET asset = '00000000-0000-0000-0000-000000000000' WHERE UUID = @uuid";
using (AutoClosingSqlCommand command = database.Query(sql))
{ {
command.Parameters.Add(database.CreateParameter("uuid", agentID)); command.Parameters.Add(database.CreateParameter("uuid", agentID));
command.ExecuteNonQuery(); command.ExecuteNonQuery();
@ -759,12 +769,14 @@ namespace OpenSim.Data.MSSQL
{ {
try try
{ {
using (AutoClosingSqlCommand command = database.Query("SELECT UUID,username,lastname FROM " + m_usersTableName + " WHERE username LIKE @first AND lastname LIKE @second")) string sql = string.Format(@"SELECT UUID,username,lastname FROM {0}
WHERE username LIKE @first AND lastname LIKE @second", m_usersTableName);
using (AutoClosingSqlCommand command = database.Query(sql))
{ {
//Add wildcard to the search //Add wildcard to the search
command.Parameters.Add(database.CreateParameter("first", querysplit[0] + "%")); command.Parameters.Add(database.CreateParameter("first", querysplit[0] + "%"));
command.Parameters.Add(database.CreateParameter("second", querysplit[1] + "%")); command.Parameters.Add(database.CreateParameter("second", querysplit[1] + "%"));
using (IDataReader reader = command.ExecuteReader()) using (SqlDataReader reader = command.ExecuteReader())
{ {
while (reader.Read()) while (reader.Read())
{ {
@ -786,11 +798,13 @@ namespace OpenSim.Data.MSSQL
{ {
try try
{ {
using (AutoClosingSqlCommand command = database.Query("SELECT UUID,username,lastname FROM " + m_usersTableName + " WHERE username LIKE @first OR lastname LIKE @first")) string sql = string.Format(@"SELECT UUID,username,lastname FROM {0}
WHERE username LIKE @first OR lastname LIKE @first", m_usersTableName);
using (AutoClosingSqlCommand command = database.Query(sql))
{ {
command.Parameters.Add(database.CreateParameter("first", querysplit[0] + "%")); command.Parameters.Add(database.CreateParameter("first", querysplit[0] + "%"));
using (IDataReader reader = command.ExecuteReader()) using (SqlDataReader reader = command.ExecuteReader())
{ {
while (reader.Read()) while (reader.Read())
{ {
@ -822,7 +836,6 @@ namespace OpenSim.Data.MSSQL
UserProfileData user = GetUserByUUID(AgentID); UserProfileData user = GetUserByUUID(AgentID);
user.WebLoginKey = WebLoginKey; user.WebLoginKey = WebLoginKey;
UpdateUserProfile(user); UpdateUserProfile(user);
} }
/// <summary> /// <summary>
@ -852,7 +865,7 @@ namespace OpenSim.Data.MSSQL
/// </summary> /// </summary>
/// <param name="reader">The SQL Result</param> /// <param name="reader">The SQL Result</param>
/// <returns>the item read</returns> /// <returns>the item read</returns>
private static AvatarAppearance readUserAppearance(IDataReader reader) private static AvatarAppearance readUserAppearance(SqlDataReader reader)
{ {
try try
{ {
@ -962,7 +975,7 @@ ELSE
/// </summary> /// </summary>
/// <param name="reader">An active database reader</param> /// <param name="reader">An active database reader</param>
/// <returns>A user session agent</returns> /// <returns>A user session agent</returns>
private UserAgentData readAgentRow(IDataReader reader) private UserAgentData readAgentRow(SqlDataReader reader)
{ {
UserAgentData retval = new UserAgentData(); UserAgentData retval = new UserAgentData();
@ -1038,18 +1051,20 @@ ELSE
UUID profileImage, UUID firstImage, UUID webLoginKey, UUID homeRegionID, UUID profileImage, UUID firstImage, UUID webLoginKey, UUID homeRegionID,
int godLevel, int userFlags, string customType, UUID partnerID) int godLevel, int userFlags, string customType, UUID partnerID)
{ {
string sql = "INSERT INTO " + m_usersTableName; string sql = string.Format(@"INSERT INTO {0}
sql += " ([UUID], [username], [lastname], [email], [passwordHash], [passwordSalt], [homeRegion], "; ([UUID], [username], [lastname], [email], [passwordHash], [passwordSalt],
sql += "[homeLocationX], [homeLocationY], [homeLocationZ], [homeLookAtX], [homeLookAtY], [homeLookAtZ], [created], "; [homeRegion], [homeLocationX], [homeLocationY], [homeLocationZ], [homeLookAtX],
sql += "[lastLogin], [userInventoryURI], [userAssetURI], [profileCanDoMask], [profileWantDoMask], [profileAboutText], "; [homeLookAtY], [homeLookAtZ], [created], [lastLogin], [userInventoryURI],
sql += "[profileFirstText], [profileImage], [profileFirstImage], [webLoginKey], "; [userAssetURI], [profileCanDoMask], [profileWantDoMask], [profileAboutText],
sql += "[homeRegionID], [userFlags], [godLevel], [customType], [partner]) VALUES "; [profileFirstText], [profileImage], [profileFirstImage], [webLoginKey],
[homeRegionID], [userFlags], [godLevel], [customType], [partner])
sql += "(@UUID, @username, @lastname, @email, @passwordHash, @passwordSalt, @homeRegion, "; VALUES
sql += "@homeLocationX, @homeLocationY, @homeLocationZ, @homeLookAtX, @homeLookAtY, @homeLookAtZ, @created, "; (@UUID, @username, @lastname, @email, @passwordHash, @passwordSalt,
sql += "@lastLogin, @userInventoryURI, @userAssetURI, @profileCanDoMask, @profileWantDoMask, @profileAboutText, "; @homeRegion, @homeLocationX, @homeLocationY, @homeLocationZ, @homeLookAtX,
sql += "@profileFirstText, @profileImage, @profileFirstImage, @webLoginKey, "; @homeLookAtY, @homeLookAtZ, @created, @lastLogin, @userInventoryURI,
sql += "@homeRegionID, @userFlags, @godLevel, @customType, @partner)"; @userAssetURI, @profileCanDoMask, @profileWantDoMask, @profileAboutText,
@profileFirstText, @profileImage, @profileFirstImage, @webLoginKey,
@homeRegionID, @userFlags, @godLevel, @customType, @partner)", m_usersTableName);
try try
{ {
@ -1079,14 +1094,12 @@ ELSE
command.Parameters.Add(database.CreateParameter("profileImage", profileImage)); command.Parameters.Add(database.CreateParameter("profileImage", profileImage));
command.Parameters.Add(database.CreateParameter("profileFirstImage", firstImage)); command.Parameters.Add(database.CreateParameter("profileFirstImage", firstImage));
command.Parameters.Add(database.CreateParameter("webLoginKey", webLoginKey)); command.Parameters.Add(database.CreateParameter("webLoginKey", webLoginKey));
//
command.Parameters.Add(database.CreateParameter("homeRegionID", homeRegionID)); command.Parameters.Add(database.CreateParameter("homeRegionID", homeRegionID));
command.Parameters.Add(database.CreateParameter("userFlags", userFlags)); command.Parameters.Add(database.CreateParameter("userFlags", userFlags));
command.Parameters.Add(database.CreateParameter("godLevel", godLevel)); command.Parameters.Add(database.CreateParameter("godLevel", godLevel));
command.Parameters.Add(database.CreateParameter("customType", customType)); command.Parameters.Add(database.CreateParameter("customType", customType));
command.Parameters.Add(database.CreateParameter("partner", partnerID)); command.Parameters.Add(database.CreateParameter("partner", partnerID));
command.ExecuteNonQuery(); command.ExecuteNonQuery();
return; return;
} }
@ -1096,7 +1109,6 @@ ELSE
m_log.Error(e.ToString()); m_log.Error(e.ToString());
return; return;
} }
} }
/// <summary> /// <summary>
@ -1104,7 +1116,7 @@ ELSE
/// </summary> /// </summary>
/// <param name="reader">An active database reader</param> /// <param name="reader">An active database reader</param>
/// <returns>A user profile</returns> /// <returns>A user profile</returns>
private static UserProfileData ReadUserRow(IDataReader reader) private static UserProfileData ReadUserRow(SqlDataReader reader)
{ {
UserProfileData retval = new UserProfileData(); UserProfileData retval = new UserProfileData();
@ -1149,7 +1161,6 @@ ELSE
} }
return retval; return retval;
} }
#endregion #endregion
} }

View File

@ -0,0 +1,5 @@
BEGIN TRANSACTION
ALTER TABLE regions ADD access int default 0;
COMMIT