aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGrid.Framework.Data.MySQL
diff options
context:
space:
mode:
Diffstat (limited to 'OpenGrid.Framework.Data.MySQL')
-rw-r--r--OpenGrid.Framework.Data.MySQL/MySQLGridData.cs71
-rw-r--r--OpenGrid.Framework.Data.MySQL/MySQLManager.cs109
2 files changed, 110 insertions, 70 deletions
diff --git a/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs b/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs
index 4404a16..3dceff6 100644
--- a/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs
+++ b/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs
@@ -14,7 +14,7 @@ namespace OpenGrid.Framework.Data.MySQL
14 /// </summary> 14 /// </summary>
15 public void Initialise() 15 public void Initialise()
16 { 16 {
17 database = new MySQLManager("localhost", "db", "user", "password", "false"); 17 database = new MySQLManager("server", "database", "username", "password", "false");
18 } 18 }
19 19
20 /// <summary> 20 /// <summary>
@@ -42,17 +42,28 @@ namespace OpenGrid.Framework.Data.MySQL
42 /// <returns>Sim profile</returns> 42 /// <returns>Sim profile</returns>
43 public SimProfileData GetProfileByHandle(ulong handle) 43 public SimProfileData GetProfileByHandle(ulong handle)
44 { 44 {
45 Dictionary<string,string> param = new Dictionary<string,string>(); 45 try
46 param["handle"] = handle.ToString(); 46 {
47 lock (database)
48 {
49 Dictionary<string, string> param = new Dictionary<string, string>();
50 param["?handle"] = handle.ToString();
47 51
48 System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE handle = @handle", param); 52 System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE regionHandle = ?handle", param);
49 System.Data.IDataReader reader = result.ExecuteReader(); 53 System.Data.IDataReader reader = result.ExecuteReader();
50 54
51 SimProfileData row = database.getRow( reader ); 55 SimProfileData row = database.getSimRow(reader);
52 reader.Close(); 56 reader.Close();
53 result.Dispose(); 57 result.Dispose();
54 58
55 return row; 59 return row;
60 }
61 }
62 catch (Exception e)
63 {
64 Console.WriteLine(e.ToString());
65 return null;
66 }
56 } 67 }
57 68
58 /// <summary> 69 /// <summary>
@@ -62,28 +73,42 @@ namespace OpenGrid.Framework.Data.MySQL
62 /// <returns>The sim profile</returns> 73 /// <returns>The sim profile</returns>
63 public SimProfileData GetProfileByLLUUID(libsecondlife.LLUUID uuid) 74 public SimProfileData GetProfileByLLUUID(libsecondlife.LLUUID uuid)
64 { 75 {
65 Dictionary<string, string> param = new Dictionary<string, string>(); 76 try
66 param["uuid"] = uuid.ToStringHyphenated(); 77 {
78 lock (database)
79 {
80 Dictionary<string, string> param = new Dictionary<string, string>();
81 param["?uuid"] = uuid.ToStringHyphenated();
67 82
68 System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param); 83 System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = ?uuid", param);
69 System.Data.IDataReader reader = result.ExecuteReader(); 84 System.Data.IDataReader reader = result.ExecuteReader();
70 85
71 SimProfileData row = database.getRow(reader); 86 SimProfileData row = database.getSimRow(reader);
72 reader.Close(); 87 reader.Close();
73 result.Dispose(); 88 result.Dispose();
74 89
75 return row; 90 return row;
91 }
92 }
93 catch (Exception e)
94 {
95 Console.WriteLine(e.ToString());
96 return null;
97 }
76 } 98 }
77 99
78 public DataResponse AddProfile(SimProfileData profile) 100 public DataResponse AddProfile(SimProfileData profile)
79 { 101 {
80 if (database.insertRow(profile)) 102 lock (database)
81 {
82 return DataResponse.RESPONSE_OK;
83 }
84 else
85 { 103 {
86 return DataResponse.RESPONSE_ERROR; 104 if (database.insertRow(profile))
105 {
106 return DataResponse.RESPONSE_OK;
107 }
108 else
109 {
110 return DataResponse.RESPONSE_ERROR;
111 }
87 } 112 }
88 } 113 }
89 114
diff --git a/OpenGrid.Framework.Data.MySQL/MySQLManager.cs b/OpenGrid.Framework.Data.MySQL/MySQLManager.cs
index d3bfa18..7461b14 100644
--- a/OpenGrid.Framework.Data.MySQL/MySQLManager.cs
+++ b/OpenGrid.Framework.Data.MySQL/MySQLManager.cs
@@ -29,7 +29,7 @@ namespace OpenGrid.Framework.Data.MySQL
29 { 29 {
30 try 30 try
31 { 31 {
32 string connectionString = "Server=" + hostname + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";"; 32 string connectionString = "Server=" + hostname + ";Port=13306;Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";";
33 dbcon = new MySqlConnection(connectionString); 33 dbcon = new MySqlConnection(connectionString);
34 34
35 dbcon.Open(); 35 dbcon.Open();
@@ -57,24 +57,32 @@ namespace OpenGrid.Framework.Data.MySQL
57 /// <returns>A MySQL DB Command</returns> 57 /// <returns>A MySQL DB Command</returns>
58 public IDbCommand Query(string sql, Dictionary<string, string> parameters) 58 public IDbCommand Query(string sql, Dictionary<string, string> parameters)
59 { 59 {
60 MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand(); 60 try
61 dbcommand.CommandText = sql;
62 foreach (KeyValuePair<string, string> param in parameters)
63 { 61 {
64 dbcommand.Parameters.Add(param.Key, param.Value); 62 MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand();
63 dbcommand.CommandText = sql;
64 foreach (KeyValuePair<string, string> param in parameters)
65 {
66 dbcommand.Parameters.Add(param.Key, param.Value);
67 }
68
69 return (IDbCommand)dbcommand;
70 }
71 catch (Exception e)
72 {
73 Console.WriteLine("Failed during Query generation: " + e.ToString());
74 return null;
65 } 75 }
66
67 return (IDbCommand)dbcommand;
68 } 76 }
69 77
70 public SimProfileData getRow(IDataReader reader) 78 public SimProfileData getSimRow(IDataReader reader)
71 { 79 {
72 SimProfileData retval = new SimProfileData(); 80 SimProfileData retval = new SimProfileData();
73 81
74 if (reader.Read()) 82 if (reader.Read())
75 { 83 {
76 // Region Main 84 // Region Main
77 retval.regionHandle = (ulong)reader["regionHandle"]; 85 retval.regionHandle = Convert.ToUInt64(reader["regionHandle"].ToString());
78 retval.regionName = (string)reader["regionName"]; 86 retval.regionName = (string)reader["regionName"];
79 retval.UUID = new libsecondlife.LLUUID((string)reader["uuid"]); 87 retval.UUID = new libsecondlife.LLUUID((string)reader["uuid"]);
80 88
@@ -91,15 +99,15 @@ namespace OpenGrid.Framework.Data.MySQL
91 retval.serverURI = (string)reader["serverURI"]; 99 retval.serverURI = (string)reader["serverURI"];
92 100
93 // Location 101 // Location
94 retval.regionLocX = (uint)((int)reader["locX"]); 102 retval.regionLocX = Convert.ToUInt32(reader["locX"].ToString());
95 retval.regionLocY = (uint)((int)reader["locY"]); 103 retval.regionLocY = Convert.ToUInt32(reader["locY"].ToString());
96 retval.regionLocZ = (uint)((int)reader["locZ"]); 104 retval.regionLocZ = Convert.ToUInt32(reader["locZ"].ToString());
97 105
98 // Neighbours - 0 = No Override 106 // Neighbours - 0 = No Override
99 retval.regionEastOverrideHandle = (ulong)reader["eastOverrideHandle"]; 107 retval.regionEastOverrideHandle = Convert.ToUInt64(reader["eastOverrideHandle"].ToString());
100 retval.regionWestOverrideHandle = (ulong)reader["westOverrideHandle"]; 108 retval.regionWestOverrideHandle = Convert.ToUInt64(reader["westOverrideHandle"].ToString());
101 retval.regionSouthOverrideHandle = (ulong)reader["southOverrideHandle"]; 109 retval.regionSouthOverrideHandle = Convert.ToUInt64(reader["southOverrideHandle"].ToString());
102 retval.regionNorthOverrideHandle = (ulong)reader["northOverrideHandle"]; 110 retval.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"].ToString());
103 111
104 // Assets 112 // Assets
105 retval.regionAssetURI = (string)reader["regionAssetURI"]; 113 retval.regionAssetURI = (string)reader["regionAssetURI"];
@@ -113,51 +121,57 @@ namespace OpenGrid.Framework.Data.MySQL
113 } 121 }
114 else 122 else
115 { 123 {
116 throw new Exception("No rows to return"); 124 throw new Exception("Unable to find region at coordinates");
125 return null;
117 } 126 }
118 return retval; 127 return retval;
119 } 128 }
120 129
121 public bool insertRow(SimProfileData profile) { 130 public bool insertRow(SimProfileData profile)
122 string sql = "REPLACE INTO regions VALUES (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, "; 131 {
132 string sql = "REPLACE INTO regions (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, ";
123 sql += "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, "; 133 sql += "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, ";
124 sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES "; 134 sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES ";
125 135
126 sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, "; 136 sql += "(?regionHandle, ?regionName, ?uuid, ?regionRecvKey, ?regionSecret, ?regionSendKey, ?regionDataURI, ";
127 sql += "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, "; 137 sql += "?serverIP, ?serverPort, ?serverURI, ?locX, ?locY, ?locZ, ?eastOverrideHandle, ?westOverrideHandle, ?southOverrideHandle, ?northOverrideHandle, ?regionAssetURI, ?regionAssetRecvKey, ";
128 sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey);"; 138 sql += "?regionAssetSendKey, ?regionUserURI, ?regionUserRecvKey, ?regionUserSendKey);";
129 139
130 Dictionary<string, string> parameters = new Dictionary<string,string>(); 140 Dictionary<string, string> parameters = new Dictionary<string, string>();
131 141
132 parameters["regionHandle"] = profile.regionHandle.ToString(); 142 parameters["?regionHandle"] = profile.regionHandle.ToString();
133 parameters["regionName"] = profile.regionName; 143 parameters["?regionName"] = profile.regionName.ToString();
134 parameters["uuid"] = profile.UUID.ToString(); 144 parameters["?uuid"] = profile.UUID.ToStringHyphenated();
135 parameters["regionRecvKey"] = profile.regionRecvKey; 145 parameters["?regionRecvKey"] = profile.regionRecvKey.ToString();
136 parameters["regionSendKey"] = profile.regionSendKey; 146 parameters["?regionSecret"] = profile.regionSecret.ToString();
137 parameters["regionDataURI"] = profile.regionDataURI; 147 parameters["?regionSendKey"] = profile.regionSendKey.ToString();
138 parameters["serverIP"] = profile.serverIP; 148 parameters["?regionDataURI"] = profile.regionDataURI.ToString();
139 parameters["serverPort"] = profile.serverPort.ToString(); 149 parameters["?serverIP"] = profile.serverIP.ToString();
140 parameters["serverURI"] = profile.serverURI; 150 parameters["?serverPort"] = profile.serverPort.ToString();
141 parameters["locX"] = profile.regionLocX.ToString(); 151 parameters["?serverURI"] = profile.serverURI.ToString();
142 parameters["locY"] = profile.regionLocY.ToString(); 152 parameters["?locX"] = profile.regionLocX.ToString();
143 parameters["locZ"] = profile.regionLocZ.ToString(); 153 parameters["?locY"] = profile.regionLocY.ToString();
144 parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString(); 154 parameters["?locZ"] = profile.regionLocZ.ToString();
145 parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString(); 155 parameters["?eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString();
146 parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString(); 156 parameters["?westOverrideHandle"] = profile.regionWestOverrideHandle.ToString();
147 parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString(); 157 parameters["?northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString();
148 parameters["regionAssetURI"] = profile.regionAssetURI; 158 parameters["?southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString();
149 parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey; 159 parameters["?regionAssetURI"] = profile.regionAssetURI.ToString();
150 parameters["regionAssetSendKey"] = profile.regionAssetSendKey; 160 parameters["?regionAssetRecvKey"] = profile.regionAssetRecvKey.ToString();
151 parameters["regionUserURI"] = profile.regionUserURI; 161 parameters["?regionAssetSendKey"] = profile.regionAssetSendKey.ToString();
152 parameters["regionUserRecvKey"] = profile.regionUserRecvKey; 162 parameters["?regionUserURI"] = profile.regionUserURI.ToString();
153 parameters["regionUserSendKey"] = profile.regionUserSendKey; 163 parameters["?regionUserRecvKey"] = profile.regionUserRecvKey.ToString();
164 parameters["?regionUserSendKey"] = profile.regionUserSendKey.ToString();
154 165
155 bool returnval = false; 166 bool returnval = false;
156 167
157 try 168 try
158 { 169 {
170
159 IDbCommand result = Query(sql, parameters); 171 IDbCommand result = Query(sql, parameters);
160 172
173 //Console.WriteLine(result.CommandText);
174
161 if (result.ExecuteNonQuery() == 1) 175 if (result.ExecuteNonQuery() == 1)
162 returnval = true; 176 returnval = true;
163 177
@@ -165,6 +179,7 @@ namespace OpenGrid.Framework.Data.MySQL
165 } 179 }
166 catch (Exception e) 180 catch (Exception e)
167 { 181 {
182 Console.WriteLine(e.ToString());
168 return false; 183 return false;
169 } 184 }
170 185