From 1232eb1c587ffdc06c26a1c5b1b4fa5f22848754 Mon Sep 17 00:00:00 2001
From: Tleiades Hax
Date: Sat, 13 Oct 2007 07:26:21 +0000
Subject: Asset server implementation. Again one of these "plumbing" releases,
where no real functionality has been introduced, but ground work has been
made, enabling the asset server, and preparing the sim server to query the
asset server.
Introduced an "IPlugin" interface, which plugins can inherit from.
---
OpenSim/Framework/Data.MySQL/MySQLManager.cs | 92 +++++++++++++++++++++++++++-
1 file changed, 89 insertions(+), 3 deletions(-)
(limited to 'OpenSim/Framework/Data.MySQL/MySQLManager.cs')
diff --git a/OpenSim/Framework/Data.MySQL/MySQLManager.cs b/OpenSim/Framework/Data.MySQL/MySQLManager.cs
index ea174b2..d3f6976 100644
--- a/OpenSim/Framework/Data.MySQL/MySQLManager.cs
+++ b/OpenSim/Framework/Data.MySQL/MySQLManager.cs
@@ -26,10 +26,14 @@
*
*/
using System;
-using System.Collections.Generic;
+using System.IO;
using System.Data;
+using System.Reflection;
+using System.Collections.Generic;
using libsecondlife;
+
using MySql.Data.MySqlClient;
+
using OpenSim.Framework.Types;
using OpenSim.Framework.Console;
@@ -114,6 +118,88 @@ namespace OpenSim.Framework.Data.MySQL
}
///
+ /// Returns the version of this DB provider
+ ///
+ /// A string containing the DB provider
+ public string getVersion()
+ {
+ System.Reflection.Module module = this.GetType().Module;
+ string dllName = module.Assembly.ManifestModule.Name;
+ Version dllVersion = module.Assembly.GetName().Version;
+
+
+ return string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision);
+ }
+
+
+ ///
+ /// Extract a named string resource from the embedded resources
+ ///
+ /// name of embedded resource
+ /// string contained within the embedded resource
+ private string getResourceString(string name)
+ {
+ Assembly assem = this.GetType().Assembly;
+ string[] names = assem.GetManifestResourceNames();
+
+ foreach (string s in names)
+ if (s.EndsWith(name))
+ using (Stream resource = assem.GetManifestResourceStream(s))
+ {
+ using (StreamReader resourceReader = new StreamReader(resource))
+ {
+ string resourceString = resourceReader.ReadToEnd();
+ return resourceString;
+ }
+ }
+ throw new Exception(string.Format("Resource '{0}' was not found", name));
+ }
+
+ ///
+ /// Execute a SQL statement stored in a resource, as a string
+ ///
+ ///
+ public void ExecuteResourceSql(string name)
+ {
+ MySqlCommand cmd = new MySqlCommand(getResourceString(name), dbcon);
+ cmd.ExecuteNonQuery();
+ }
+
+ ///
+ /// Given a list of tables, return the version of the tables, as seen in the database
+ ///
+ ///
+ public void GetTableVersion(Dictionary tableList)
+ {
+ lock (dbcon)
+ {
+ MySqlCommand tablesCmd = new MySqlCommand("SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname", dbcon);
+ tablesCmd.Parameters.AddWithValue("?dbname", dbcon.Database);
+ using (MySqlDataReader tables = tablesCmd.ExecuteReader())
+ {
+ while (tables.Read())
+ {
+ try
+ {
+ string tableName = (string)tables["TABLE_NAME"];
+ string comment = (string)tables["TABLE_COMMENT"];
+ if(tableList.ContainsKey(tableName))
+ tableList[tableName] = comment;
+ }
+ catch (Exception e)
+ {
+ MainLog.Instance.Error(e.ToString());
+ }
+ }
+ tables.Close();
+ }
+ }
+ }
+
+
+ // at some time this code should be cleaned up
+
+ ///
/// Runs a query with protection against SQL Injection by using parameterised input.
///
/// The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y
@@ -127,7 +213,7 @@ namespace OpenSim.Framework.Data.MySQL
dbcommand.CommandText = sql;
foreach (KeyValuePair param in parameters)
{
- dbcommand.Parameters.Add(param.Key, param.Value);
+ dbcommand.Parameters.AddWithValue(param.Key, param.Value);
}
return (IDbCommand)dbcommand;
@@ -161,7 +247,7 @@ namespace OpenSim.Framework.Data.MySQL
dbcommand.CommandText = sql;
foreach (KeyValuePair param in parameters)
{
- dbcommand.Parameters.Add(param.Key, param.Value);
+ dbcommand.Parameters.AddWithValue(param.Key, param.Value);
}
return (IDbCommand)dbcommand;
--
cgit v1.1