aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGrid.Framework.Data.MySQL/MySQLManager.cs
diff options
context:
space:
mode:
authorAdam Frisby2007-05-04 03:25:20 +0000
committerAdam Frisby2007-05-04 03:25:20 +0000
commit10f75f936e1322ea1e328799cfba08229d667a78 (patch)
tree87bc3faaeb19595a67ef0b286a93dbdb117c1942 /OpenGrid.Framework.Data.MySQL/MySQLManager.cs
parentfix array size (diff)
downloadopensim-SC-10f75f936e1322ea1e328799cfba08229d667a78.zip
opensim-SC-10f75f936e1322ea1e328799cfba08229d667a78.tar.gz
opensim-SC-10f75f936e1322ea1e328799cfba08229d667a78.tar.bz2
opensim-SC-10f75f936e1322ea1e328799cfba08229d667a78.tar.xz
Committing OpenGrid.Framework.Data and MySql Adaptor - not in functional state yet, posted for reference and future use.
Diffstat (limited to 'OpenGrid.Framework.Data.MySQL/MySQLManager.cs')
-rw-r--r--OpenGrid.Framework.Data.MySQL/MySQLManager.cs84
1 files changed, 84 insertions, 0 deletions
diff --git a/OpenGrid.Framework.Data.MySQL/MySQLManager.cs b/OpenGrid.Framework.Data.MySQL/MySQLManager.cs
new file mode 100644
index 0000000..30ad314
--- /dev/null
+++ b/OpenGrid.Framework.Data.MySQL/MySQLManager.cs
@@ -0,0 +1,84 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Data;
5
6// MySQL Native
7using MySql;
8using MySql.Data;
9using MySql.Data.Types;
10using MySql.Data.MySqlClient;
11
12namespace OpenGrid.Framework.Data.MySQL
13{
14 class MySQLManager
15 {
16 IDbConnection dbcon;
17
18 /// <summary>
19 /// Initialises and creates a new MySQL connection and maintains it.
20 /// </summary>
21 /// <param name="hostname">The MySQL server being connected to</param>
22 /// <param name="database">The name of the MySQL database being used</param>
23 /// <param name="username">The username logging into the database</param>
24 /// <param name="password">The password for the user logging in</param>
25 /// <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>
26 public MySQLManager(string hostname, string database, string username, string password, string cpooling)
27 {
28 try
29 {
30 string connectionString = "Server=" + hostname + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";";
31 dbcon = new MySqlConnection(connectionString);
32
33 dbcon.Open();
34 }
35 catch (Exception e)
36 {
37 throw new Exception("Error initialising MySql Database: " + e.ToString());
38 }
39 }
40
41 /// <summary>
42 /// Shuts down the database connection
43 /// </summary>
44 public void Close()
45 {
46 dbcon.Close();
47 dbcon = null;
48 }
49
50 /// <summary>
51 /// Runs a query with protection against SQL Injection by using parameterised input.
52 /// </summary>
53 /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param>
54 /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param>
55 /// <returns>A MySQL DB Command</returns>
56 public IDbCommand Query(string sql, Dictionary<string, string> parameters)
57 {
58 MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand();
59 dbcommand.CommandText = sql;
60 foreach (KeyValuePair<string, string> param in parameters)
61 {
62 dbcommand.Parameters.Add(param.Key, param.Value);
63 }
64
65 return (IDbCommand)dbcommand;
66 }
67
68 public SimProfileData getRow(IDataReader reader)
69 {
70 SimProfileData retval = new SimProfileData();
71
72 if (reader.Read())
73 {
74 //retval.regionDataURI = reader["regionDataURI"];
75
76 }
77 else
78 {
79 return null;
80 }
81 return retval;
82 }
83 }
84}