* Split out MSSQLManager Test/Init into each provider.

* Made regions table name configurable (MSSQL only)
* Added a note in ini.example pointing out that the sql resources have to change if you change table names
* Removed duplicate picker method from GridData interface
[Provided by openlifegrid.com]
ThreadPoolClientBranch
lbsa71 2008-02-13 13:39:51 +00:00
parent 680b80044c
commit 4880bd121e
9 changed files with 142 additions and 256 deletions

View File

@ -47,21 +47,48 @@ namespace OpenSim.Framework.Data.MSSQL
/// </summary> /// </summary>
private MSSQLManager database; private MSSQLManager database;
private string m_regionsTableName;
/// <summary> /// <summary>
/// Initialises the Grid Interface /// Initialises the Grid Interface
/// </summary> /// </summary>
public void Initialise() public void Initialise()
{ {
IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini"); IniFile iniFile = new IniFile("mssql_connection.ini");
string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source");
string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog"); string settingDataSource = iniFile.ParseFileReadValue("data_source");
string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info"); string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog");
string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id"); string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info");
string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); string settingUserId = iniFile.ParseFileReadValue("user_id");
string settingPassword = iniFile.ParseFileReadValue("password");
m_regionsTableName = iniFile.ParseFileReadValue("regionstablename");
if (m_regionsTableName == null)
{
m_regionsTableName = "regions";
}
database = database =
new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
settingPassword); settingPassword);
TestTables();
}
private void TestTables()
{
IDbCommand cmd = database.Query("SELECT * FROM "+m_regionsTableName, new Dictionary<string, string>());
try
{
cmd.ExecuteNonQuery();
cmd.Dispose();
}
catch (Exception)
{
m_log.Info("[DATASTORE]: MSSQL Database doesn't exist... creating");
database.ExecuteResourceSql("Mssql-regions.sql");
}
} }
/// <summary> /// <summary>
@ -115,7 +142,7 @@ namespace OpenSim.Framework.Data.MSSQL
{ {
Dictionary<string, string> param = new Dictionary<string, string>(); Dictionary<string, string> param = new Dictionary<string, string>();
param["handle"] = handle.ToString(); param["handle"] = handle.ToString();
IDbCommand result = database.Query("SELECT * FROM regions WHERE regionHandle = @handle", param); IDbCommand result = database.Query("SELECT * FROM " + m_regionsTableName + " WHERE regionHandle = @handle", param);
reader = result.ExecuteReader(); reader = result.ExecuteReader();
RegionProfileData row = database.getRegionRow(reader); RegionProfileData row = database.getRegionRow(reader);
@ -134,88 +161,6 @@ namespace OpenSim.Framework.Data.MSSQL
return null; return null;
} }
/// <summary>
/// // Returns a list of avatar and UUIDs that match the query
/// </summary>
public List<AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query)
{
List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>();
string[] querysplit;
querysplit = query.Split(' ');
if (querysplit.Length == 2)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["first"] = querysplit[0];
param["second"] = querysplit[1];
IDbCommand result =
database.Query(
"SELECT UUID,username,surname FROM users WHERE username = @first AND lastname = @second",
param);
IDataReader reader = result.ExecuteReader();
while (reader.Read())
{
AvatarPickerAvatar user = new AvatarPickerAvatar();
user.AvatarID = new LLUUID((string) reader["UUID"]);
user.firstName = (string) reader["username"];
user.lastName = (string) reader["surname"];
returnlist.Add(user);
}
reader.Close();
result.Dispose();
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.ToString());
return returnlist;
}
}
else if (querysplit.Length == 1)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["first"] = querysplit[0];
param["second"] = querysplit[1];
IDbCommand result =
database.Query(
"SELECT UUID,username,surname FROM users WHERE username = @first OR lastname = @second",
param);
IDataReader reader = result.ExecuteReader();
while (reader.Read())
{
AvatarPickerAvatar user = new AvatarPickerAvatar();
user.AvatarID = new LLUUID((string) reader["UUID"]);
user.firstName = (string) reader["username"];
user.lastName = (string) reader["surname"];
returnlist.Add(user);
}
reader.Close();
result.Dispose();
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.ToString());
return returnlist;
}
}
return returnlist;
}
/// <summary> /// <summary>
/// Returns a sim profile from it's UUID /// Returns a sim profile from it's UUID
@ -226,7 +171,7 @@ namespace OpenSim.Framework.Data.MSSQL
{ {
Dictionary<string, string> param = new Dictionary<string, string>(); Dictionary<string, string> param = new Dictionary<string, string>();
param["uuid"] = uuid.ToString(); param["uuid"] = uuid.ToString();
IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param); IDbCommand result = database.Query("SELECT * FROM " + m_regionsTableName + " WHERE uuid = @uuid", param);
IDataReader reader = result.ExecuteReader(); IDataReader reader = result.ExecuteReader();
RegionProfileData row = database.getRegionRow(reader); RegionProfileData row = database.getRegionRow(reader);

View File

@ -25,6 +25,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
using System.Collections.Generic;
using System.Data;
namespace OpenSim.Framework.Data.MSSQL namespace OpenSim.Framework.Data.MSSQL
{ {
/// <summary> /// <summary>
@ -52,6 +55,18 @@ namespace OpenSim.Framework.Data.MSSQL
database = database =
new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
settingPassword); settingPassword);
IDbCommand cmd = database.Query("select top 1 * from logs", new Dictionary<string, string>());
try
{
cmd.ExecuteNonQuery();
cmd.Dispose();
}
catch
{
database.ExecuteResourceSql("Mssql-logs.sql");
}
} }
/// <summary> /// <summary>

View File

@ -52,16 +52,8 @@ namespace OpenSim.Framework.Data.MSSQL
/// <summary> /// <summary>
/// Connection string for ADO.net /// Connection string for ADO.net
/// </summary> /// </summary>
private string connectionString; private readonly string connectionString;
/// <summary>
/// Initialises and creates a new Sql connection and maintains it.
/// </summary>
/// <param name="hostname">The Sql server being connected to</param>
/// <param name="database">The name of the Sql database being used</param>
/// <param name="username">The username logging into the database</param>
/// <param name="password">The password for the user logging in</param>
/// <param name="cpooling">Whether to use connection pooling or not, can be one of the following: 'yes', 'true', 'no' or 'false', if unsure use 'false'.</param>
public MSSQLManager(string dataSource, string initialCatalog, string persistSecurityInfo, string userId, public MSSQLManager(string dataSource, string initialCatalog, string persistSecurityInfo, string userId,
string password) string password)
{ {
@ -71,7 +63,6 @@ namespace OpenSim.Framework.Data.MSSQL
";Persist Security Info=" + persistSecurityInfo + ";User ID=" + userId + ";Password=" + ";Persist Security Info=" + persistSecurityInfo + ";User ID=" + userId + ";Password=" +
password + ";"; password + ";";
dbcon = new SqlConnection(connectionString); dbcon = new SqlConnection(connectionString);
TestTables(dbcon);
dbcon.Open(); dbcon.Open();
} }
catch (Exception e) catch (Exception e)
@ -80,61 +71,6 @@ namespace OpenSim.Framework.Data.MSSQL
} }
} }
private bool TestTables(IDbConnection conn)
{
IDbCommand cmd = Query("SELECT * FROM regions", new Dictionary<string, string>());
//SqlCommand cmd = (SqlCommand)dbcon.CreateCommand();
//cmd.CommandText = "SELECT * FROM regions";
try
{
conn.Open();
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
}
catch (Exception)
{
m_log.Info("[DATASTORE]: MSSQL Database doesn't exist... creating");
InitDB(conn);
}
cmd = Query("select top 1 webLoginKey from users", new Dictionary<string, string>());
try
{
conn.Open();
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
}
catch (Exception)
{
conn.Open();
cmd = Query("alter table users add column [webLoginKey] varchar(36) default NULL", new Dictionary<string, string>());
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
}
return true;
}
private void InitDB(IDbConnection conn)
{
string createRegions = defineTable(createRegionsTable());
Dictionary<string, string> param = new Dictionary<string, string>();
IDbCommand pcmd = Query(createRegions, param);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
pcmd.ExecuteNonQuery();
pcmd.Dispose();
ExecuteResourceSql("Mssql-users.sql");
ExecuteResourceSql("Mssql-agents.sql");
ExecuteResourceSql("Mssql-logs.sql");
conn.Close();
}
private DataTable createRegionsTable() private DataTable createRegionsTable()
{ {
DataTable regions = new DataTable("regions"); DataTable regions = new DataTable("regions");
@ -253,7 +189,6 @@ namespace OpenSim.Framework.Data.MSSQL
{ {
try try
{ {
//string connectionString = "Data Source=WRK-OU-738\\SQLEXPRESS;Initial Catalog=rex;Persist Security Info=True;User ID=sa;Password=rex";
// Close the DB connection // Close the DB connection
dbcon.Close(); dbcon.Close();
// Try reopen it // Try reopen it

View File

@ -85,8 +85,42 @@ namespace OpenSim.Framework.Data.MSSQL
database = database =
new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
settingPassword); settingPassword);
if (!TestTables())
{
database.ExecuteResourceSql("Mssql-agents.sql");
database.ExecuteResourceSql("Mssql-users.sql");
database.ExecuteResourceSql("Mssql-userfriends.sql");
}
} }
private bool TestTables()
{
IDbCommand cmd = database.Query("select top 1 webLoginKey from "+m_usersTableName, new Dictionary<string, string>());
try
{
cmd.ExecuteNonQuery();
cmd.Dispose();
}
catch
{
database.Query("alter table "+m_usersTableName+" add column [webLoginKey] varchar(36) default NULL", new Dictionary<string, string>());
cmd.ExecuteNonQuery();
cmd.Dispose();
}
cmd = database.Query("select top 1 * from "+m_usersTableName, new Dictionary<string, string>());
try
{
cmd.ExecuteNonQuery();
}
catch
{
return false;
}
return true;
}
/// <summary> /// <summary>
/// Searches the database for a specified user profile by name components /// Searches the database for a specified user profile by name components
/// </summary> /// </summary>

View File

@ -0,0 +1,41 @@
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [db_owner].[regions](
[regionHandle] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[regionName] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[uuid] [varchar](255) COLLATE Latin1_General_CI_AS NOT NULL,
[regionRecvKey] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[regionSecret] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[regionSendKey] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[regionDataURI] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[serverIP] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[serverPort] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[serverURI] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[locX] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[locY] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[locZ] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[eastOverrideHandle] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[westOverrideHandle] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[southOverrideHandle] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[northOverrideHandle] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[regionAssetURI] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[regionAssetRecvKey] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[regionAssetSendKey] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[regionUserURI] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[regionUserRecvKey] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[regionUserSendKey] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[regionMapTexture] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[serverHttpPort] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[serverRemotingPort] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
PRIMARY KEY CLUSTERED
(
[uuid] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF

View File

@ -207,90 +207,6 @@ namespace OpenSim.Framework.Data.MySQL
} }
} }
/// <summary>
/// // Returns a list of avatar and UUIDs that match the query
/// </summary>
public List<AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query)
{
List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>();
Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9]");
string[] querysplit;
querysplit = query.Split(' ');
if (querysplit.Length == 2)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["?first"] = objAlphaNumericPattern.Replace(querysplit[0], String.Empty) + "%";
param["?second"] = objAlphaNumericPattern.Replace(querysplit[1], String.Empty) + "%";
try
{
lock (database)
{
IDbCommand result =
database.Query(
"SELECT UUID,username,surname FROM users WHERE username like ?first AND lastname like ?second LIMIT 100",
param);
IDataReader reader = result.ExecuteReader();
while (reader.Read())
{
AvatarPickerAvatar user = new AvatarPickerAvatar();
user.AvatarID = new LLUUID((string) reader["UUID"]);
user.firstName = (string) reader["username"];
user.lastName = (string) reader["surname"];
returnlist.Add(user);
}
reader.Close();
result.Dispose();
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.ToString());
return returnlist;
}
}
else if (querysplit.Length == 1)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["?first"] = objAlphaNumericPattern.Replace(querysplit[0], System.String.Empty) + "%";
IDbCommand result =
database.Query(
"SELECT UUID,username,surname FROM users WHERE username like ?first OR lastname like ?second",
param);
IDataReader reader = result.ExecuteReader();
while (reader.Read())
{
AvatarPickerAvatar user = new AvatarPickerAvatar();
user.AvatarID = new LLUUID((string) reader["UUID"]);
user.firstName = (string) reader["username"];
user.lastName = (string) reader["surname"];
returnlist.Add(user);
}
reader.Close();
result.Dispose();
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.ToString());
return returnlist;
}
}
return returnlist;
}
/// <summary> /// <summary>
/// Returns a sim profile from it's UUID /// Returns a sim profile from it's UUID
/// </summary> /// </summary>

View File

@ -78,9 +78,6 @@ namespace OpenSim.Framework.Data
/// <returns>An array containing all the sim profiles in the specified range</returns> /// <returns>An array containing all the sim profiles in the specified range</returns>
RegionProfileData[] GetProfilesInRange(uint Xmin, uint Ymin, uint Xmax, uint Ymax); RegionProfileData[] GetProfilesInRange(uint Xmin, uint Ymin, uint Xmax, uint Ymax);
List<AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query);
/// <summary> /// <summary>
/// Authenticates a sim by use of its recv key. /// Authenticates a sim by use of its recv key.
/// WARNING: Insecure /// WARNING: Insecure

View File

@ -9,8 +9,10 @@ user_id=username
password=password password=password
; These entries are only for if you, for some reason, wish to customize your user server table names. ; These entries are only for if you, for some reason, wish to customize your user server table names.
; Do note that if you change the table names, you might have to change the sql resources too manually
; If ommitted, default values will be used. ; If ommitted, default values will be used.
userstablename=users userstablename=users
userfriendstablename=userfriends userfriendstablename=userfriends
agentstablename=agents agentstablename=agents
regionstablename=regions

View File

@ -10,6 +10,7 @@ pooling=false
port=3306 port=3306
; These entries are only for if you, for some reason, wish to customize your user server table names. ; These entries are only for if you, for some reason, wish to customize your user server table names.
; Do note that if you change the table names, you might have to change the sql resources too manually
; If ommitted, default values will be used. ; If ommitted, default values will be used.
userstablename=users userstablename=users