diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/MSSQL/MSSQLUserAccountData.cs | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs b/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs index 38be9f4..7b6e7c8 100644 --- a/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs +++ b/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs | |||
@@ -40,19 +40,21 @@ namespace OpenSim.Data.MSSQL | |||
40 | { | 40 | { |
41 | private string m_Realm; | 41 | private string m_Realm; |
42 | private List<string> m_ColumnNames = null; | 42 | private List<string> m_ColumnNames = null; |
43 | private int m_LastExpire = 0; | ||
44 | private string m_ConnectionString; | 43 | private string m_ConnectionString; |
44 | private MSSQLManager m_database; | ||
45 | 45 | ||
46 | public MSSQLUserAccountData(string connectionString, string realm) | 46 | public MSSQLUserAccountData(string connectionString, string realm) |
47 | { | 47 | { |
48 | m_Realm = realm; | 48 | m_Realm = realm; |
49 | m_ConnectionString = connectionString; | 49 | m_ConnectionString = connectionString; |
50 | m_database = new MSSQLManager(connectionString); | ||
51 | |||
50 | using (SqlConnection conn = new SqlConnection(m_ConnectionString)) | 52 | using (SqlConnection conn = new SqlConnection(m_ConnectionString)) |
51 | { | 53 | { |
52 | conn.Open(); | 54 | conn.Open(); |
53 | Migration m = new Migration(conn, GetType().Assembly, "UserStore"); | 55 | Migration m = new Migration(conn, GetType().Assembly, "UserStore"); |
54 | m.Update(); | 56 | m.Update(); |
55 | } | 57 | } |
56 | } | 58 | } |
57 | 59 | ||
58 | public List<UserAccountData> Query(UUID principalID, UUID scopeID, string query) | 60 | public List<UserAccountData> Query(UUID principalID, UUID scopeID, string query) |
@@ -65,16 +67,16 @@ namespace OpenSim.Data.MSSQL | |||
65 | UserAccountData ret = new UserAccountData(); | 67 | UserAccountData ret = new UserAccountData(); |
66 | ret.Data = new Dictionary<string, object>(); | 68 | ret.Data = new Dictionary<string, object>(); |
67 | 69 | ||
68 | string sql = string.Format("select * from '{0}' where UUID = @principalID", m_Realm); | 70 | string sql = string.Format("select * from {0} where UUID = @principalID", m_Realm); |
69 | if (scopeID != UUID.Zero) | 71 | if (scopeID != UUID.Zero) |
70 | sql += " and ScopeID = @scopeID"; | 72 | sql += " and ScopeID = @scopeID"; |
71 | 73 | ||
72 | using (SqlConnection conn = new SqlConnection(m_ConnectionString)) | 74 | using (SqlConnection conn = new SqlConnection(m_ConnectionString)) |
73 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | 75 | using (SqlCommand cmd = new SqlCommand(sql, conn)) |
74 | { | 76 | { |
75 | 77 | cmd.Parameters.Add(m_database.CreateParameter("@principalID", principalID)); | |
76 | cmd.Parameters.AddWithValue("@principalID", principalID); | 78 | cmd.Parameters.Add(m_database.CreateParameter("@scopeID", scopeID)); |
77 | cmd.Parameters.AddWithValue("@scopeID", scopeID); | 79 | |
78 | conn.Open(); | 80 | conn.Open(); |
79 | using (SqlDataReader result = cmd.ExecuteReader()) | 81 | using (SqlDataReader result = cmd.ExecuteReader()) |
80 | { | 82 | { |
@@ -123,17 +125,16 @@ namespace OpenSim.Data.MSSQL | |||
123 | using (SqlCommand cmd = new SqlCommand()) | 125 | using (SqlCommand cmd = new SqlCommand()) |
124 | { | 126 | { |
125 | StringBuilder updateBuilder = new StringBuilder(); | 127 | StringBuilder updateBuilder = new StringBuilder(); |
126 | updateBuilder.AppendFormat("update '{0}' set ", m_Realm); | 128 | updateBuilder.AppendFormat("update {0} set ", m_Realm); |
127 | bool first = true; | 129 | bool first = true; |
128 | foreach (string field in fields) | 130 | foreach (string field in fields) |
129 | { | 131 | { |
130 | if (!first) | 132 | if (!first) |
131 | updateBuilder.Append(", "); | 133 | updateBuilder.Append(", "); |
132 | updateBuilder.AppendFormat("'{0}' = @{0}", field); | 134 | updateBuilder.AppendFormat("{0} = @{0}", field); |
133 | 135 | ||
134 | first = false; | 136 | first = false; |
135 | 137 | cmd.Parameters.Add(m_database.CreateParameter("@" + field, data.Data[field])); | |
136 | cmd.Parameters.AddWithValue("@" + field, data.Data[field]); | ||
137 | } | 138 | } |
138 | 139 | ||
139 | updateBuilder.Append(" where UUID = @principalID"); | 140 | updateBuilder.Append(" where UUID = @principalID"); |
@@ -143,16 +144,16 @@ namespace OpenSim.Data.MSSQL | |||
143 | 144 | ||
144 | cmd.CommandText = updateBuilder.ToString(); | 145 | cmd.CommandText = updateBuilder.ToString(); |
145 | cmd.Connection = conn; | 146 | cmd.Connection = conn; |
146 | cmd.Parameters.AddWithValue("@principalID", data.PrincipalID); | 147 | cmd.Parameters.Add(m_database.CreateParameter("@principalID", data.PrincipalID)); |
147 | cmd.Parameters.AddWithValue("@scopeID", data.ScopeID); | 148 | cmd.Parameters.Add(m_database.CreateParameter("@scopeID", data.ScopeID)); |
148 | conn.Open(); | 149 | conn.Open(); |
149 | 150 | ||
150 | if (cmd.ExecuteNonQuery() < 1) | 151 | if (cmd.ExecuteNonQuery() < 1) |
151 | { | 152 | { |
152 | StringBuilder insertBuilder = new StringBuilder(); | 153 | StringBuilder insertBuilder = new StringBuilder(); |
153 | insertBuilder.AppendFormat("insert into '{0}' ('UUID', 'ScopeID', '", m_Realm); | 154 | insertBuilder.AppendFormat("insert into {0} (UUID, ScopeID, ", m_Realm); |
154 | insertBuilder.Append(String.Join("', '", fields)); | 155 | insertBuilder.Append(String.Join(", ", fields)); |
155 | insertBuilder.Append("') values (@principalID, @scopeID, @"); | 156 | insertBuilder.Append(") values ( @principalID, @scopeID, @"); |
156 | insertBuilder.Append(String.Join(", @", fields)); | 157 | insertBuilder.Append(String.Join(", @", fields)); |
157 | insertBuilder.Append(")"); | 158 | insertBuilder.Append(")"); |
158 | 159 | ||
@@ -169,12 +170,13 @@ namespace OpenSim.Data.MSSQL | |||
169 | 170 | ||
170 | public bool SetDataItem(UUID principalID, string item, string value) | 171 | public bool SetDataItem(UUID principalID, string item, string value) |
171 | { | 172 | { |
172 | string sql = string.Format("update '{0}' set '{1}' = @{1} where UUID = @UUID", m_Realm, item); | 173 | string sql = string.Format("update {0} set {1} = @{1} where UUID = @UUID", m_Realm, item); |
173 | using (SqlConnection conn = new SqlConnection(m_ConnectionString)) | 174 | using (SqlConnection conn = new SqlConnection(m_ConnectionString)) |
174 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | 175 | using (SqlCommand cmd = new SqlCommand(sql, conn)) |
175 | { | 176 | { |
176 | cmd.Parameters.AddWithValue("@" + item, value); | 177 | cmd.Parameters.Add(m_database.CreateParameter("@" + item, value)); |
177 | cmd.Parameters.AddWithValue("@UUID", principalID); | 178 | cmd.Parameters.Add(m_database.CreateParameter("@UUID", principalID)); |
179 | |||
178 | conn.Open(); | 180 | conn.Open(); |
179 | 181 | ||
180 | if (cmd.ExecuteNonQuery() > 0) | 182 | if (cmd.ExecuteNonQuery() > 0) |