diff options
author | Melanie | 2011-10-12 00:10:15 +0200 |
---|---|---|
committer | Melanie | 2011-10-12 00:10:15 +0200 |
commit | 1c2b5d99c9601a3d301f4bc0f53389cca831ee04 (patch) | |
tree | 97fa9c758f429d5dee64234e442f2c83cd1b9994 /OpenSim/Data/MSSQL | |
parent | Merge branch 'careminster-presence-refactor' into bigmerge (diff) | |
parent | Merge commit '92c88121c72386f85472c6cf4891eca8b62b9867' into bigmerge (diff) | |
download | opensim-SC-1c2b5d99c9601a3d301f4bc0f53389cca831ee04.zip opensim-SC-1c2b5d99c9601a3d301f4bc0f53389cca831ee04.tar.gz opensim-SC-1c2b5d99c9601a3d301f4bc0f53389cca831ee04.tar.bz2 opensim-SC-1c2b5d99c9601a3d301f4bc0f53389cca831ee04.tar.xz |
Merge branch 'bigmerge' of ssh://3dhosting.de/var/git/careminster into bigmerge
Diffstat (limited to 'OpenSim/Data/MSSQL')
-rw-r--r-- | OpenSim/Data/MSSQL/MSSQLEstateData.cs | 117 | ||||
-rw-r--r-- | OpenSim/Data/MSSQL/MSSQLUserAccountData.cs | 18 | ||||
-rw-r--r-- | OpenSim/Data/MSSQL/Resources/FriendsStore.migrations | 28 | ||||
-rw-r--r-- | OpenSim/Data/MSSQL/Resources/InventoryStore.migrations | 32 | ||||
-rw-r--r-- | OpenSim/Data/MSSQL/Resources/OpenSim.Data.MSSQL.addin.xml | 23 |
5 files changed, 140 insertions, 78 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLEstateData.cs b/OpenSim/Data/MSSQL/MSSQLEstateData.cs index 9c54e77..1faa249 100644 --- a/OpenSim/Data/MSSQL/MSSQLEstateData.cs +++ b/OpenSim/Data/MSSQL/MSSQLEstateData.cs | |||
@@ -148,56 +148,29 @@ namespace OpenSim.Data.MSSQL | |||
148 | } | 148 | } |
149 | } | 149 | } |
150 | 150 | ||
151 | |||
152 | if (insertEstate && create) | 151 | if (insertEstate && create) |
153 | { | 152 | { |
154 | List<string> names = new List<string>(FieldList); | 153 | DoCreate(es); |
155 | 154 | LinkRegion(regionID, (int)es.EstateID); | |
156 | names.Remove("EstateID"); | 155 | } |
157 | |||
158 | sql = string.Format("insert into estate_settings ({0}) values ( @{1})", String.Join(",", names.ToArray()), String.Join(", @", names.ToArray())); | ||
159 | |||
160 | //_Log.Debug("[DB ESTATE]: SQL: " + sql); | ||
161 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | ||
162 | using (SqlCommand insertCommand = new SqlCommand(sql, conn)) | ||
163 | { | ||
164 | insertCommand.CommandText = sql + " SET @ID = SCOPE_IDENTITY()"; | ||
165 | 156 | ||
166 | foreach (string name in names) | 157 | LoadBanList(es); |
167 | { | ||
168 | insertCommand.Parameters.Add(_Database.CreateParameter("@" + name, _FieldMap[name].GetValue(es))); | ||
169 | } | ||
170 | SqlParameter idParameter = new SqlParameter("@ID", SqlDbType.Int); | ||
171 | idParameter.Direction = ParameterDirection.Output; | ||
172 | insertCommand.Parameters.Add(idParameter); | ||
173 | conn.Open(); | ||
174 | insertCommand.ExecuteNonQuery(); | ||
175 | 158 | ||
176 | es.EstateID = Convert.ToUInt32(idParameter.Value); | 159 | es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers"); |
177 | } | 160 | es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users"); |
161 | es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups"); | ||
178 | 162 | ||
179 | sql = "INSERT INTO [estate_map] ([RegionID] ,[EstateID]) VALUES (@RegionID, @EstateID)"; | 163 | //Set event |
180 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | 164 | es.OnSave += StoreEstateSettings; |
181 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | 165 | return es; |
182 | { | 166 | } |
183 | 167 | ||
184 | cmd.Parameters.Add(_Database.CreateParameter("@RegionID", regionID)); | 168 | public EstateSettings CreateNewEstate() |
185 | cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID)); | 169 | { |
186 | // This will throw on dupe key | 170 | EstateSettings es = new EstateSettings(); |
187 | try | 171 | es.OnSave += StoreEstateSettings; |
188 | { | ||
189 | conn.Open(); | ||
190 | cmd.ExecuteNonQuery(); | ||
191 | } | ||
192 | catch (Exception e) | ||
193 | { | ||
194 | m_log.DebugFormat("[ESTATE DB]: Error inserting regionID and EstateID in estate_map: {0}", e); | ||
195 | } | ||
196 | } | ||
197 | 172 | ||
198 | //TODO check if this is needed?? | 173 | DoCreate(es); |
199 | es.Save(); | ||
200 | } | ||
201 | 174 | ||
202 | LoadBanList(es); | 175 | LoadBanList(es); |
203 | 176 | ||
@@ -205,11 +178,40 @@ namespace OpenSim.Data.MSSQL | |||
205 | es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users"); | 178 | es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users"); |
206 | es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups"); | 179 | es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups"); |
207 | 180 | ||
208 | //Set event | ||
209 | es.OnSave += StoreEstateSettings; | ||
210 | return es; | 181 | return es; |
211 | } | 182 | } |
212 | 183 | ||
184 | private void DoCreate(EstateSettings es) | ||
185 | { | ||
186 | List<string> names = new List<string>(FieldList); | ||
187 | |||
188 | names.Remove("EstateID"); | ||
189 | |||
190 | string sql = string.Format("insert into estate_settings ({0}) values ( @{1})", String.Join(",", names.ToArray()), String.Join(", @", names.ToArray())); | ||
191 | |||
192 | //_Log.Debug("[DB ESTATE]: SQL: " + sql); | ||
193 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | ||
194 | using (SqlCommand insertCommand = new SqlCommand(sql, conn)) | ||
195 | { | ||
196 | insertCommand.CommandText = sql + " SET @ID = SCOPE_IDENTITY()"; | ||
197 | |||
198 | foreach (string name in names) | ||
199 | { | ||
200 | insertCommand.Parameters.Add(_Database.CreateParameter("@" + name, _FieldMap[name].GetValue(es))); | ||
201 | } | ||
202 | SqlParameter idParameter = new SqlParameter("@ID", SqlDbType.Int); | ||
203 | idParameter.Direction = ParameterDirection.Output; | ||
204 | insertCommand.Parameters.Add(idParameter); | ||
205 | conn.Open(); | ||
206 | insertCommand.ExecuteNonQuery(); | ||
207 | |||
208 | es.EstateID = Convert.ToUInt32(idParameter.Value); | ||
209 | } | ||
210 | |||
211 | //TODO check if this is needed?? | ||
212 | es.Save(); | ||
213 | } | ||
214 | |||
213 | /// <summary> | 215 | /// <summary> |
214 | /// Stores the estate settings. | 216 | /// Stores the estate settings. |
215 | /// </summary> | 217 | /// </summary> |
@@ -498,24 +500,43 @@ namespace OpenSim.Data.MSSQL | |||
498 | 500 | ||
499 | public bool LinkRegion(UUID regionID, int estateID) | 501 | public bool LinkRegion(UUID regionID, int estateID) |
500 | { | 502 | { |
501 | string sql = "insert into estate_map values (@RegionID, @EstateID)"; | 503 | string deleteSQL = "delete from estate_map where RegionID = @RegionID"; |
504 | string insertSQL = "insert into estate_map values (@RegionID, @EstateID)"; | ||
502 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | 505 | using (SqlConnection conn = new SqlConnection(m_connectionString)) |
503 | { | 506 | { |
504 | conn.Open(); | 507 | conn.Open(); |
508 | SqlTransaction transaction = conn.BeginTransaction(); | ||
509 | |||
505 | try | 510 | try |
506 | { | 511 | { |
507 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | 512 | using (SqlCommand cmd = new SqlCommand(deleteSQL, conn)) |
508 | { | 513 | { |
509 | cmd.Parameters.AddWithValue("@RegionID", regionID); | 514 | cmd.Transaction = transaction; |
515 | cmd.Parameters.AddWithValue("@RegionID", regionID.Guid); | ||
516 | |||
517 | cmd.ExecuteNonQuery(); | ||
518 | } | ||
519 | |||
520 | using (SqlCommand cmd = new SqlCommand(insertSQL, conn)) | ||
521 | { | ||
522 | cmd.Transaction = transaction; | ||
523 | cmd.Parameters.AddWithValue("@RegionID", regionID.Guid); | ||
510 | cmd.Parameters.AddWithValue("@EstateID", estateID); | 524 | cmd.Parameters.AddWithValue("@EstateID", estateID); |
511 | 525 | ||
512 | int ret = cmd.ExecuteNonQuery(); | 526 | int ret = cmd.ExecuteNonQuery(); |
527 | |||
528 | if (ret != 0) | ||
529 | transaction.Commit(); | ||
530 | else | ||
531 | transaction.Rollback(); | ||
532 | |||
513 | return (ret != 0); | 533 | return (ret != 0); |
514 | } | 534 | } |
515 | } | 535 | } |
516 | catch (Exception ex) | 536 | catch (Exception ex) |
517 | { | 537 | { |
518 | m_log.Error("[REGION DB]: LinkRegion failed: " + ex.Message); | 538 | m_log.Error("[REGION DB]: LinkRegion failed: " + ex.Message); |
539 | transaction.Rollback(); | ||
519 | } | 540 | } |
520 | } | 541 | } |
521 | return false; | 542 | return false; |
diff --git a/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs b/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs index f24b441..dd0689c 100644 --- a/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs +++ b/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs | |||
@@ -218,23 +218,27 @@ namespace OpenSim.Data.MSSQL | |||
218 | if (words.Length > 2) | 218 | if (words.Length > 2) |
219 | return new UserAccountData[0]; | 219 | return new UserAccountData[0]; |
220 | 220 | ||
221 | string sql = ""; | ||
222 | |||
221 | using (SqlConnection conn = new SqlConnection(m_ConnectionString)) | 223 | using (SqlConnection conn = new SqlConnection(m_ConnectionString)) |
222 | using (SqlCommand cmd = new SqlCommand()) | 224 | using (SqlCommand cmd = new SqlCommand()) |
223 | { | 225 | { |
224 | if (words.Length == 1) | 226 | if (words.Length == 1) |
225 | { | 227 | { |
226 | cmd.CommandText = String.Format("select * from {0} where ([ScopeID]=@ScopeID or [ScopeID]='00000000-0000-0000-0000-000000000000') and ([FirstName] like @search or [LastName] like @search)", m_Realm); | 228 | sql = String.Format("select * from {0} where ([ScopeID]=@ScopeID or [ScopeID]='00000000-0000-0000-0000-000000000000') and ([FirstName] like @search or [LastName] like @search)", m_Realm); |
227 | cmd.Parameters.Add(m_database.CreateParameter("@scopeID", scopeID)); | 229 | cmd.Parameters.Add(m_database.CreateParameter("@scopeID", scopeID)); |
228 | cmd.Parameters.Add(m_database.CreateParameter("@search", "%" + words[0] + "%")); | 230 | cmd.Parameters.Add(m_database.CreateParameter("@search", "%" + words[0] + "%")); |
229 | } | 231 | } |
230 | else | 232 | else |
231 | { | 233 | { |
232 | cmd.CommandText = String.Format("select * from {0} where ([ScopeID]=@ScopeID or [ScopeID]='00000000-0000-0000-0000-000000000000') and ([FirstName] like @searchFirst or [LastName] like @searchLast)", m_Realm); | 234 | sql = String.Format("select * from {0} where ([ScopeID]=@ScopeID or [ScopeID]='00000000-0000-0000-0000-000000000000') and ([FirstName] like @searchFirst or [LastName] like @searchLast)", m_Realm); |
233 | cmd.Parameters.Add(m_database.CreateParameter("@searchFirst", "%" + words[0] + "%")); | 235 | cmd.Parameters.Add(m_database.CreateParameter("@searchFirst", "%" + words[0] + "%")); |
234 | cmd.Parameters.Add(m_database.CreateParameter("@searchLast", "%" + words[1] + "%")); | 236 | cmd.Parameters.Add(m_database.CreateParameter("@searchLast", "%" + words[1] + "%")); |
235 | cmd.Parameters.Add(m_database.CreateParameter("@ScopeID", scopeID.ToString())); | 237 | cmd.Parameters.Add(m_database.CreateParameter("@ScopeID", scopeID.ToString())); |
236 | } | 238 | } |
237 | 239 | cmd.Connection = conn; | |
240 | cmd.CommandText = sql; | ||
241 | conn.Open(); | ||
238 | return DoQuery(cmd); | 242 | return DoQuery(cmd); |
239 | } | 243 | } |
240 | } | 244 | } |
diff --git a/OpenSim/Data/MSSQL/Resources/FriendsStore.migrations b/OpenSim/Data/MSSQL/Resources/FriendsStore.migrations index 4d8ab0f..cc94c4e 100644 --- a/OpenSim/Data/MSSQL/Resources/FriendsStore.migrations +++ b/OpenSim/Data/MSSQL/Resources/FriendsStore.migrations | |||
@@ -19,4 +19,32 @@ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[userf | |||
19 | INSERT INTO Friends (PrincipalID, Friend, Flags, Offered) | 19 | INSERT INTO Friends (PrincipalID, Friend, Flags, Offered) |
20 | SELECT [ownerID], [friendID], [friendPerms], 0 FROM userfriends; | 20 | SELECT [ownerID], [friendID], [friendPerms], 0 FROM userfriends; |
21 | 21 | ||
22 | COMMIT | ||
23 | |||
24 | :VERSION 3 | ||
25 | |||
26 | BEGIN TRANSACTION | ||
27 | |||
28 | CREATE TABLE [Tmp_Friends] | ||
29 | ([PrincipalID] varchar(255) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', | ||
30 | [Friend] varchar(255) NOT NULL, | ||
31 | [Flags] char(16) NOT NULL DEFAULT '0', | ||
32 | [Offered] varchar(32) NOT NULL DEFAULT 0) | ||
33 | ON [PRIMARY] | ||
34 | |||
35 | |||
36 | IF EXISTS(SELECT * FROM dbo.Friends) | ||
37 | EXEC('INSERT INTO dbo.Tmp_Friends (PrincipalID, Friend, Flags, Offered) | ||
38 | SELECT CONVERT(varchar(255),PrincipalID), Friend, Flags, Offered FROM dbo.Friends WITH (HOLDLOCK TABLOCKX)') | ||
39 | |||
40 | DROP TABLE dbo.Friends | ||
41 | |||
42 | EXECUTE sp_rename N'dbo.Tmp_Friends', N'Friends', 'OBJECT' | ||
43 | |||
44 | ALTER TABLE dbo.Friends ADD | ||
45 | PRIMARY KEY CLUSTERED | ||
46 | ( | ||
47 | [PrincipalID] ASC, [Friend] ASC | ||
48 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] | ||
49 | |||
22 | COMMIT \ No newline at end of file | 50 | COMMIT \ No newline at end of file |
diff --git a/OpenSim/Data/MSSQL/Resources/InventoryStore.migrations b/OpenSim/Data/MSSQL/Resources/InventoryStore.migrations index 4a3cb27..4e43653 100644 --- a/OpenSim/Data/MSSQL/Resources/InventoryStore.migrations +++ b/OpenSim/Data/MSSQL/Resources/InventoryStore.migrations | |||
@@ -244,4 +244,36 @@ ALTER TABLE inventoryitems | |||
244 | ADD CONSTRAINT DF_inventoryitems_creatorID | 244 | ADD CONSTRAINT DF_inventoryitems_creatorID |
245 | DEFAULT '00000000-0000-0000-0000-000000000000' FOR creatorID | 245 | DEFAULT '00000000-0000-0000-0000-000000000000' FOR creatorID |
246 | 246 | ||
247 | :GO | ||
248 | |||
249 | :VERSION 9 | ||
250 | |||
251 | BEGIN TRANSACTION | ||
252 | |||
253 | # CreatorID goes up to VARCHAR(255) | ||
254 | |||
255 | exec sp_rename 'inventoryitems.CreatorID', 'cr_old', 'COLUMN' | ||
256 | |||
257 | :GO | ||
258 | |||
259 | alter table inventoryitems | ||
260 | add creatorID varchar(255) NULL | ||
261 | |||
262 | :GO | ||
263 | |||
264 | update inventoryitems set creatorID = cr_old | ||
265 | |||
266 | alter table inventoryitems | ||
267 | drop CONSTRAINT DF_inventoryitems_creatorID | ||
268 | :GO | ||
269 | |||
270 | alter table inventoryitems | ||
271 | drop column cr_old | ||
272 | :GO | ||
273 | COMMIT | ||
274 | |||
275 | ALTER TABLE inventoryitems | ||
276 | ADD CONSTRAINT DF_inventoryitems_creatorID | ||
277 | DEFAULT '00000000-0000-0000-0000-000000000000' FOR creatorID | ||
278 | |||
247 | :GO \ No newline at end of file | 279 | :GO \ No newline at end of file |
diff --git a/OpenSim/Data/MSSQL/Resources/OpenSim.Data.MSSQL.addin.xml b/OpenSim/Data/MSSQL/Resources/OpenSim.Data.MSSQL.addin.xml deleted file mode 100644 index 15fd29e..0000000 --- a/OpenSim/Data/MSSQL/Resources/OpenSim.Data.MSSQL.addin.xml +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | <Addin id="OpenSim.Data.MSSQL" version="0.1"> | ||
2 | <Runtime> | ||
3 | <Import assembly="OpenSim.Data.MSSQL.dll"/> | ||
4 | </Runtime> | ||
5 | <Dependencies> | ||
6 | <Addin id="OpenSim.Data" version="0.5" /> | ||
7 | </Dependencies> | ||
8 | <Extension path = "/OpenSim/GridData"> | ||
9 | <Plugin id="MSSQLGridData" provider="OpenSim.Data.MSSQL.dll" type="OpenSim.Data.MSSQL.MSSQLGridData" /> | ||
10 | </Extension> | ||
11 | <Extension path = "/OpenSim/LogData"> | ||
12 | <Plugin id="MSSQLLogData" provider="OpenSim.Data.MSSQL.dll" type="OpenSim.Data.MSSQL.MSSQLLogData" /> | ||
13 | </Extension> | ||
14 | <Extension path = "/OpenSim/AssetData"> | ||
15 | <Plugin id="MSSQLAssetData" provider="OpenSim.Data.MSSQL.dll" type="OpenSim.Data.MSSQL.MSSQLAssetData" /> | ||
16 | </Extension> | ||
17 | <Extension path = "/OpenSim/InventoryData"> | ||
18 | <Plugin id="MSSQLInventoryData" provider="OpenSim.Data.MSSQL.dll" type="OpenSim.Data.MSSQL.MSSQLInventoryData" /> | ||
19 | </Extension> | ||
20 | <Extension path = "/OpenSim/UserData"> | ||
21 | <Plugin id="MSSQLUserData" provider="OpenSim.Data.MSSQL.dll" type="OpenSim.Data.MSSQL.MSSQLUserData" /> | ||
22 | </Extension> | ||
23 | </Addin> | ||