aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MSSQL/MSSQLLogData.cs
diff options
context:
space:
mode:
authorMelanie Thielker2008-09-14 13:23:02 +0000
committerMelanie Thielker2008-09-14 13:23:02 +0000
commit281955949910eb257b5f7e42e54535ba7812418e (patch)
tree8c62c0006f2567983a686e811513c8c009061aac /OpenSim/Data/MSSQL/MSSQLLogData.cs
parent* Converted a number of methods within the login processes from private to pr... (diff)
downloadopensim-SC_OLD-281955949910eb257b5f7e42e54535ba7812418e.zip
opensim-SC_OLD-281955949910eb257b5f7e42e54535ba7812418e.tar.gz
opensim-SC_OLD-281955949910eb257b5f7e42e54535ba7812418e.tar.bz2
opensim-SC_OLD-281955949910eb257b5f7e42e54535ba7812418e.tar.xz
Mantis #2124
Thank you, RuudL, for a patch that brings MSSQL up to the same implementation level as MySQL.
Diffstat (limited to 'OpenSim/Data/MSSQL/MSSQLLogData.cs')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLLogData.cs106
1 files changed, 86 insertions, 20 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLLogData.cs b/OpenSim/Data/MSSQL/MSSQLLogData.cs
index b284c02..a617cea 100644
--- a/OpenSim/Data/MSSQL/MSSQLLogData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLLogData.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Data.SqlClient;
29using System.Reflection; 30using System.Reflection;
30using System.Collections.Generic; 31using System.Collections.Generic;
31using System.Data; 32using System.Data;
@@ -39,6 +40,8 @@ namespace OpenSim.Data.MSSQL
39 /// </summary> 40 /// </summary>
40 internal class MSSQLLogData : ILogDataPlugin 41 internal class MSSQLLogData : ILogDataPlugin
41 { 42 {
43 private const string _migrationStore = "LogStore";
44
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 46
44 /// <summary> 47 /// <summary>
@@ -48,7 +51,7 @@ namespace OpenSim.Data.MSSQL
48 51
49 public void Initialise() 52 public void Initialise()
50 { 53 {
51 m_log.Info("[MSSQLLogData]: " + Name + " cannot be default-initialized!"); 54 m_log.Info("[LOG DB]: " + Name + " cannot be default-initialized!");
52 throw new PluginNotInitialisedException (Name); 55 throw new PluginNotInitialisedException (Name);
53 } 56 }
54 57
@@ -57,18 +60,37 @@ namespace OpenSim.Data.MSSQL
57 /// </summary> 60 /// </summary>
58 public void Initialise(string connect) 61 public void Initialise(string connect)
59 { 62 {
60 // TODO: do something with the connect string 63 if (string.IsNullOrEmpty(connect))
61 IniFile gridDataMSSqlFile = new IniFile("mssql_connection.ini"); 64 {
62 string settingDataSource = gridDataMSSqlFile.ParseFileReadValue("data_source"); 65 database = new MSSQLManager(connect);
63 string settingInitialCatalog = gridDataMSSqlFile.ParseFileReadValue("initial_catalog"); 66 }
64 string settingPersistSecurityInfo = gridDataMSSqlFile.ParseFileReadValue("persist_security_info"); 67 else
65 string settingUserId = gridDataMSSqlFile.ParseFileReadValue("user_id"); 68 {
66 string settingPassword = gridDataMSSqlFile.ParseFileReadValue("password"); 69 // TODO: do something with the connect string
67 70 IniFile gridDataMSSqlFile = new IniFile("mssql_connection.ini");
68 database = 71 string settingDataSource = gridDataMSSqlFile.ParseFileReadValue("data_source");
69 new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, 72 string settingInitialCatalog = gridDataMSSqlFile.ParseFileReadValue("initial_catalog");
70 settingPassword); 73 string settingPersistSecurityInfo = gridDataMSSqlFile.ParseFileReadValue("persist_security_info");
74 string settingUserId = gridDataMSSqlFile.ParseFileReadValue("user_id");
75 string settingPassword = gridDataMSSqlFile.ParseFileReadValue("password");
76
77 database =
78 new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
79 settingPassword);
80 }
81
82 //TODO when can this be removed
83 TestTable();
84
85 //Updating mechanisme
86 database.CheckMigration(_migrationStore);
87 }
71 88
89 /// <summary>
90 /// Can be removed someday!!!
91 /// </summary>
92 private void TestTable()
93 {
72 using (IDbCommand cmd = database.Query("select top 1 * from logs", new Dictionary<string, string>())) 94 using (IDbCommand cmd = database.Query("select top 1 * from logs", new Dictionary<string, string>()))
73 { 95 {
74 try 96 try
@@ -80,9 +102,38 @@ namespace OpenSim.Data.MSSQL
80 database.ExecuteResourceSql("Mssql-logs.sql"); 102 database.ExecuteResourceSql("Mssql-logs.sql");
81 } 103 }
82 } 104 }
105 using (AutoClosingSqlCommand cmd = database.Query("select * from migrations where name = '" + _migrationStore + "'"))
106 {
107 //Special for Migrations to create backword compatible
108 try
109 {
110 bool insert = true;
111 using (SqlDataReader reader = cmd.ExecuteReader())
112 {
113 if (reader.Read()) insert = false;
114 }
115 if (insert)
116 {
117 cmd.CommandText = "insert into migrations(name, version) values('" + _migrationStore + "', 1)";
118 cmd.ExecuteNonQuery();
119 }
120 }
121 catch
122 {
123 //No migrations table
124 //HACK create one and add data
125 cmd.CommandText = "create table migrations(name varchar(100), version int)";
126 cmd.ExecuteNonQuery();
83 127
84 } 128 cmd.CommandText = "insert into migrations(name, version) values('migrations', 1)";
129 cmd.ExecuteNonQuery();
85 130
131 cmd.CommandText = "insert into migrations(name, version) values('" + _migrationStore + "', 1)";
132 cmd.ExecuteNonQuery();
133 }
134 }
135 }
136
86 /// <summary> 137 /// <summary>
87 /// Saves a log item to the database 138 /// Saves a log item to the database
88 /// </summary> 139 /// </summary>
@@ -95,13 +146,28 @@ namespace OpenSim.Data.MSSQL
95 public void saveLog(string serverDaemon, string target, string methodCall, string arguments, int priority, 146 public void saveLog(string serverDaemon, string target, string methodCall, string arguments, int priority,
96 string logMessage) 147 string logMessage)
97 { 148 {
98 try 149 string sql = "INSERT INTO logs ([target], [server], [method], [arguments], [priority], [message]) VALUES ";
99 { 150 sql += "(@target, @server, @method, @arguments, @priority, @message);";
100 database.insertLogRow(serverDaemon, target, methodCall, arguments, priority, logMessage); 151
101 } 152 using (AutoClosingSqlCommand command = database.Query(sql))
102 catch
103 { 153 {
104 // it didn't log, don't worry about it 154 command.Parameters.Add(database.CreateParameter("server", serverDaemon));
155 command.Parameters.Add(database.CreateParameter("target",target));
156 command.Parameters.Add(database.CreateParameter("method", methodCall));
157 command.Parameters.Add(database.CreateParameter("arguments", arguments));
158 command.Parameters.Add(database.CreateParameter("priority", priority.ToString()));
159 command.Parameters.Add(database.CreateParameter("message", logMessage));
160
161 try
162 {
163 command.ExecuteNonQuery();
164 }
165 catch (Exception e)
166 {
167 //Are we not in a loop here
168 //m_log.Error(e.ToString());
169 Console.WriteLine("[LOG DB] Error logging : " + e.Message);
170 }
105 } 171 }
106 } 172 }
107 173
@@ -119,7 +185,7 @@ namespace OpenSim.Data.MSSQL
119 /// </summary> 185 /// </summary>
120 public void Dispose() 186 public void Dispose()
121 { 187 {
122 // Do nothing. 188 database = null;
123 } 189 }
124 190
125 /// <summary> 191 /// <summary>