aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MSSQL/MSSQLManager.cs
diff options
context:
space:
mode:
authorMelanie Thielker2008-09-01 17:10:01 +0000
committerMelanie Thielker2008-09-01 17:10:01 +0000
commitb6bb5f944f19b330656105ff79cd5ca3f2d5c242 (patch)
tree433ee8a24136ac10ed63dc3cf715b16ba786b8a8 /OpenSim/Data/MSSQL/MSSQLManager.cs
parentMantis #2072 (diff)
downloadopensim-SC_OLD-b6bb5f944f19b330656105ff79cd5ca3f2d5c242.zip
opensim-SC_OLD-b6bb5f944f19b330656105ff79cd5ca3f2d5c242.tar.gz
opensim-SC_OLD-b6bb5f944f19b330656105ff79cd5ca3f2d5c242.tar.bz2
opensim-SC_OLD-b6bb5f944f19b330656105ff79cd5ca3f2d5c242.tar.xz
Mantis #2095
Thank you, RuudL, for a complete adaptation of migration and estate data to MSSQL, and the updating of the RegionData handling in MSSQL.
Diffstat (limited to 'OpenSim/Data/MSSQL/MSSQLManager.cs')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLManager.cs116
1 files changed, 112 insertions, 4 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLManager.cs b/OpenSim/Data/MSSQL/MSSQLManager.cs
index 1a053d5..535cf33 100644
--- a/OpenSim/Data/MSSQL/MSSQLManager.cs
+++ b/OpenSim/Data/MSSQL/MSSQLManager.cs
@@ -64,9 +64,20 @@ namespace OpenSim.Data.MSSQL
64 connectionString = builder.ToString(); 64 connectionString = builder.ToString();
65 } 65 }
66 66
67 private SqlConnection createConnection() 67 /// <summary>
68 /// Initialize the manager and set the connectionstring
69 /// </summary>
70 /// <param name="connection"></param>
71 public MSSQLManager(string connection)
72 {
73 connectionString = connection;
74 }
75
76 public SqlConnection DatabaseConnection()
68 { 77 {
69 SqlConnection conn = new SqlConnection(connectionString); 78 SqlConnection conn = new SqlConnection(connectionString);
79
80 //TODO is this good??? Opening connection here
70 conn.Open(); 81 conn.Open();
71 82
72 return conn; 83 return conn;
@@ -186,6 +197,105 @@ namespace OpenSim.Data.MSSQL
186 } 197 }
187 } 198 }
188 199
200 /// <summary>
201 /// Type conversion to a SQLDbType functions
202 /// </summary>
203 /// <param name="type"></param>
204 /// <returns></returns>
205 internal SqlDbType DbtypeFromType(Type type)
206 {
207 if (type == typeof(string))
208 {
209 return SqlDbType.VarChar;
210 }
211 if (type == typeof(double))
212 {
213 return SqlDbType.Float;
214 }
215 if (type == typeof(int))
216 {
217 return SqlDbType.Int;
218 }
219 if (type == typeof(bool))
220 {
221 return SqlDbType.Bit;
222 }
223 if (type == typeof(LLUUID))
224 {
225 return SqlDbType.VarChar;
226 }
227 if (type == typeof(Byte[]))
228 {
229 return SqlDbType.Image;
230 }
231 if (type == typeof(uint))
232 {
233 return SqlDbType.Int;
234 }
235 return SqlDbType.VarChar;
236 }
237
238 /// <summary>
239 /// Creates value for parameter.
240 /// </summary>
241 /// <param name="value">The value.</param>
242 /// <returns></returns>
243 private static object CreateParameterValue(object value)
244 {
245 Type valueType = value.GetType();
246
247 if (valueType == typeof(LLUUID))
248 {
249 return value.ToString();
250 }
251 if (valueType == typeof(bool))
252 {
253 return (bool)value ? 1 : 0;
254 }
255 if (valueType == typeof(Byte[]))
256 {
257 return value;
258 }
259 return value;
260 }
261
262 /// <summary>
263 /// Create a parameter for a command
264 /// </summary>
265 /// <param name="parameterName">Name of the parameter.</param>
266 /// <param name="parameterObject">parameter object.</param>
267 /// <returns></returns>
268 internal SqlParameter CreateParameter(string parameterName, object parameterObject)
269 {
270 return CreateParameter(parameterName, parameterObject, false);
271 }
272
273 /// <summary>
274 /// Creates the parameter for a command.
275 /// </summary>
276 /// <param name="parameterName">Name of the parameter.</param>
277 /// <param name="parameterObject">parameter object.</param>
278 /// <param name="parameterOut">if set to <c>true</c> parameter is a output parameter</param>
279 /// <returns></returns>
280 internal SqlParameter CreateParameter(string parameterName, object parameterObject, bool parameterOut)
281 {
282 //Tweak so we dont always have to add @ sign
283 if (!parameterName.StartsWith("@")) parameterName = "@" + parameterName;
284
285 SqlParameter parameter = new SqlParameter(parameterName, DbtypeFromType(parameterObject.GetType()));
286
287 if (parameterOut)
288 {
289 parameter.Direction = ParameterDirection.Output;
290 }
291 else
292 {
293 parameter.Direction = ParameterDirection.Input;
294 parameter.Value = CreateParameterValue(parameterObject);
295 }
296
297 return parameter;
298 }
189 299
190 private static readonly Dictionary<string, string> emptyDictionary = new Dictionary<string, string>(); 300 private static readonly Dictionary<string, string> emptyDictionary = new Dictionary<string, string>();
191 internal AutoClosingSqlCommand Query(string sql) 301 internal AutoClosingSqlCommand Query(string sql)
@@ -201,7 +311,7 @@ namespace OpenSim.Data.MSSQL
201 /// <returns>A Sql DB Command</returns> 311 /// <returns>A Sql DB Command</returns>
202 internal AutoClosingSqlCommand Query(string sql, Dictionary<string, string> parameters) 312 internal AutoClosingSqlCommand Query(string sql, Dictionary<string, string> parameters)
203 { 313 {
204 SqlCommand dbcommand = createConnection().CreateCommand(); 314 SqlCommand dbcommand = DatabaseConnection().CreateCommand();
205 dbcommand.CommandText = sql; 315 dbcommand.CommandText = sql;
206 foreach (KeyValuePair<string, string> param in parameters) 316 foreach (KeyValuePair<string, string> param in parameters)
207 { 317 {
@@ -211,8 +321,6 @@ namespace OpenSim.Data.MSSQL
211 return new AutoClosingSqlCommand(dbcommand); 321 return new AutoClosingSqlCommand(dbcommand);
212 } 322 }
213 323
214
215
216 /// <summary> 324 /// <summary>
217 /// Runs a database reader object and returns a region row 325 /// Runs a database reader object and returns a region row
218 /// </summary> 326 /// </summary>