aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.MySQL/MySQLManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Data.MySQL/MySQLManager.cs')
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLManager.cs92
1 files changed, 89 insertions, 3 deletions
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 @@
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.Collections.Generic; 29using System.IO;
30using System.Data; 30using System.Data;
31using System.Reflection;
32using System.Collections.Generic;
31using libsecondlife; 33using libsecondlife;
34
32using MySql.Data.MySqlClient; 35using MySql.Data.MySqlClient;
36
33using OpenSim.Framework.Types; 37using OpenSim.Framework.Types;
34using OpenSim.Framework.Console; 38using OpenSim.Framework.Console;
35 39
@@ -114,6 +118,88 @@ namespace OpenSim.Framework.Data.MySQL
114 } 118 }
115 119
116 /// <summary> 120 /// <summary>
121 /// Returns the version of this DB provider
122 /// </summary>
123 /// <returns>A string containing the DB provider</returns>
124 public string getVersion()
125 {
126 System.Reflection.Module module = this.GetType().Module;
127 string dllName = module.Assembly.ManifestModule.Name;
128 Version dllVersion = module.Assembly.GetName().Version;
129
130
131 return string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision);
132 }
133
134
135 /// <summary>
136 /// Extract a named string resource from the embedded resources
137 /// </summary>
138 /// <param name="name">name of embedded resource</param>
139 /// <returns>string contained within the embedded resource</returns>
140 private string getResourceString(string name)
141 {
142 Assembly assem = this.GetType().Assembly;
143 string[] names = assem.GetManifestResourceNames();
144
145 foreach (string s in names)
146 if (s.EndsWith(name))
147 using (Stream resource = assem.GetManifestResourceStream(s))
148 {
149 using (StreamReader resourceReader = new StreamReader(resource))
150 {
151 string resourceString = resourceReader.ReadToEnd();
152 return resourceString;
153 }
154 }
155 throw new Exception(string.Format("Resource '{0}' was not found", name));
156 }
157
158 /// <summary>
159 /// Execute a SQL statement stored in a resource, as a string
160 /// </summary>
161 /// <param name="name"></param>
162 public void ExecuteResourceSql(string name)
163 {
164 MySqlCommand cmd = new MySqlCommand(getResourceString(name), dbcon);
165 cmd.ExecuteNonQuery();
166 }
167
168 /// <summary>
169 /// Given a list of tables, return the version of the tables, as seen in the database
170 /// </summary>
171 /// <param name="tableList"></param>
172 public void GetTableVersion(Dictionary<string, string> tableList)
173 {
174 lock (dbcon)
175 {
176 MySqlCommand tablesCmd = new MySqlCommand("SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname", dbcon);
177 tablesCmd.Parameters.AddWithValue("?dbname", dbcon.Database);
178 using (MySqlDataReader tables = tablesCmd.ExecuteReader())
179 {
180 while (tables.Read())
181 {
182 try
183 {
184 string tableName = (string)tables["TABLE_NAME"];
185 string comment = (string)tables["TABLE_COMMENT"];
186 if(tableList.ContainsKey(tableName))
187 tableList[tableName] = comment;
188 }
189 catch (Exception e)
190 {
191 MainLog.Instance.Error(e.ToString());
192 }
193 }
194 tables.Close();
195 }
196 }
197 }
198
199
200 // at some time this code should be cleaned up
201
202 /// <summary>
117 /// Runs a query with protection against SQL Injection by using parameterised input. 203 /// Runs a query with protection against SQL Injection by using parameterised input.
118 /// </summary> 204 /// </summary>
119 /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> 205 /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param>
@@ -127,7 +213,7 @@ namespace OpenSim.Framework.Data.MySQL
127 dbcommand.CommandText = sql; 213 dbcommand.CommandText = sql;
128 foreach (KeyValuePair<string, string> param in parameters) 214 foreach (KeyValuePair<string, string> param in parameters)
129 { 215 {
130 dbcommand.Parameters.Add(param.Key, param.Value); 216 dbcommand.Parameters.AddWithValue(param.Key, param.Value);
131 } 217 }
132 218
133 return (IDbCommand)dbcommand; 219 return (IDbCommand)dbcommand;
@@ -161,7 +247,7 @@ namespace OpenSim.Framework.Data.MySQL
161 dbcommand.CommandText = sql; 247 dbcommand.CommandText = sql;
162 foreach (KeyValuePair<string, string> param in parameters) 248 foreach (KeyValuePair<string, string> param in parameters)
163 { 249 {
164 dbcommand.Parameters.Add(param.Key, param.Value); 250 dbcommand.Parameters.AddWithValue(param.Key, param.Value);
165 } 251 }
166 252
167 return (IDbCommand)dbcommand; 253 return (IDbCommand)dbcommand;