diff options
author | Dan Lake | 2012-03-27 12:51:58 -0700 |
---|---|---|
committer | Dan Lake | 2012-03-27 12:51:58 -0700 |
commit | 971d32fda3cf8384987a6709cd2242afecce13ab (patch) | |
tree | 2607c27fad429ff0036fe7b7d275ddf717397282 /OpenSim/Data | |
parent | When loading objects from DB, first add to scene, then call TriggerOnSceneObj... (diff) | |
parent | HG: beginning of a more restrictive inventory access procedure (optional). Ex... (diff) | |
download | opensim-SC-971d32fda3cf8384987a6709cd2242afecce13ab.zip opensim-SC-971d32fda3cf8384987a6709cd2242afecce13ab.tar.gz opensim-SC-971d32fda3cf8384987a6709cd2242afecce13ab.tar.bz2 opensim-SC-971d32fda3cf8384987a6709cd2242afecce13ab.tar.xz |
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Data')
-rw-r--r-- | OpenSim/Data/IXAssetDataPlugin.cs | 47 | ||||
-rw-r--r-- | OpenSim/Data/MSSQL/MSSQLFriendsData.cs | 6 | ||||
-rw-r--r-- | OpenSim/Data/MSSQL/MSSQLInventoryData.cs | 2 | ||||
-rw-r--r-- | OpenSim/Data/MSSQL/MSSQLSimulationData.cs | 83 | ||||
-rw-r--r-- | OpenSim/Data/MSSQL/Resources/RegionStore.migrations | 85 | ||||
-rw-r--r-- | OpenSim/Data/MySQL/MySQLXAssetData.cs | 500 | ||||
-rw-r--r-- | OpenSim/Data/MySQL/Resources/XAssetStore.migrations | 27 |
7 files changed, 743 insertions, 7 deletions
diff --git a/OpenSim/Data/IXAssetDataPlugin.cs b/OpenSim/Data/IXAssetDataPlugin.cs new file mode 100644 index 0000000..74ad6f4 --- /dev/null +++ b/OpenSim/Data/IXAssetDataPlugin.cs | |||
@@ -0,0 +1,47 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using OpenMetaverse; | ||
30 | using OpenSim.Framework; | ||
31 | |||
32 | namespace OpenSim.Data | ||
33 | { | ||
34 | /// <summary> | ||
35 | /// This interface exists to distinguish between the normal IAssetDataPlugin and the one used by XAssetService | ||
36 | /// for now. | ||
37 | /// </summary> | ||
38 | public interface IXAssetDataPlugin : IPlugin | ||
39 | { | ||
40 | AssetBase GetAsset(UUID uuid); | ||
41 | void StoreAsset(AssetBase asset); | ||
42 | bool ExistsAsset(UUID uuid); | ||
43 | List<AssetMetadata> FetchAssetMetadataSet(int start, int count); | ||
44 | void Initialise(string connect); | ||
45 | bool Delete(string id); | ||
46 | } | ||
47 | } \ No newline at end of file | ||
diff --git a/OpenSim/Data/MSSQL/MSSQLFriendsData.cs b/OpenSim/Data/MSSQL/MSSQLFriendsData.cs index 09dde5e..fef6978 100644 --- a/OpenSim/Data/MSSQL/MSSQLFriendsData.cs +++ b/OpenSim/Data/MSSQL/MSSQLFriendsData.cs | |||
@@ -89,5 +89,11 @@ namespace OpenSim.Data.MSSQL | |||
89 | return DoQuery(cmd); | 89 | return DoQuery(cmd); |
90 | } | 90 | } |
91 | } | 91 | } |
92 | |||
93 | public FriendsData[] GetFriends(Guid principalID) | ||
94 | { | ||
95 | return GetFriends(principalID.ToString()); | ||
96 | } | ||
97 | |||
92 | } | 98 | } |
93 | } | 99 | } |
diff --git a/OpenSim/Data/MSSQL/MSSQLInventoryData.cs b/OpenSim/Data/MSSQL/MSSQLInventoryData.cs index 4d06377..961593f 100644 --- a/OpenSim/Data/MSSQL/MSSQLInventoryData.cs +++ b/OpenSim/Data/MSSQL/MSSQLInventoryData.cs | |||
@@ -813,7 +813,7 @@ namespace OpenSim.Data.MSSQL | |||
813 | { | 813 | { |
814 | try | 814 | try |
815 | { | 815 | { |
816 | using (SqlCommand command = new SqlCommand("DELETE FROM inventoryfolders WHERE folderID=@folderID", connection)) | 816 | using (SqlCommand command = new SqlCommand("DELETE FROM inventoryfolders WHERE folderID=@folderID and type=-1", connection)) |
817 | { | 817 | { |
818 | command.Parameters.Add(database.CreateParameter("folderID", folderID)); | 818 | command.Parameters.Add(database.CreateParameter("folderID", folderID)); |
819 | 819 | ||
diff --git a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs index d6b1561..d9dfe86 100644 --- a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs +++ b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs | |||
@@ -675,7 +675,7 @@ VALUES | |||
675 | cmd.ExecuteNonQuery(); | 675 | cmd.ExecuteNonQuery(); |
676 | } | 676 | } |
677 | 677 | ||
678 | sql = "INSERT INTO [landaccesslist] ([LandUUID],[AccessUUID],[Flags]) VALUES (@LandUUID,@AccessUUID,@Flags)"; | 678 | sql = "INSERT INTO [landaccesslist] ([LandUUID],[AccessUUID],[Flags],[Expires]) VALUES (@LandUUID,@AccessUUID,@Flags,@Expires)"; |
679 | 679 | ||
680 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | 680 | using (SqlConnection conn = new SqlConnection(m_connectionString)) |
681 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | 681 | using (SqlCommand cmd = new SqlCommand(sql, conn)) |
@@ -1215,6 +1215,8 @@ VALUES | |||
1215 | //Store new values | 1215 | //Store new values |
1216 | StoreNewRegionSettings(regionSettings); | 1216 | StoreNewRegionSettings(regionSettings); |
1217 | 1217 | ||
1218 | LoadSpawnPoints(regionSettings); | ||
1219 | |||
1218 | return regionSettings; | 1220 | return regionSettings; |
1219 | } | 1221 | } |
1220 | 1222 | ||
@@ -1252,7 +1254,7 @@ VALUES | |||
1252 | ,[elevation_1_ne] = @elevation_1_ne ,[elevation_2_ne] = @elevation_2_ne ,[elevation_1_se] = @elevation_1_se ,[elevation_2_se] = @elevation_2_se | 1254 | ,[elevation_1_ne] = @elevation_1_ne ,[elevation_2_ne] = @elevation_2_ne ,[elevation_1_se] = @elevation_1_se ,[elevation_2_se] = @elevation_2_se |
1253 | ,[elevation_1_sw] = @elevation_1_sw ,[elevation_2_sw] = @elevation_2_sw ,[water_height] = @water_height ,[terrain_raise_limit] = @terrain_raise_limit | 1255 | ,[elevation_1_sw] = @elevation_1_sw ,[elevation_2_sw] = @elevation_2_sw ,[water_height] = @water_height ,[terrain_raise_limit] = @terrain_raise_limit |
1254 | ,[terrain_lower_limit] = @terrain_lower_limit ,[use_estate_sun] = @use_estate_sun ,[fixed_sun] = @fixed_sun ,[sun_position] = @sun_position | 1256 | ,[terrain_lower_limit] = @terrain_lower_limit ,[use_estate_sun] = @use_estate_sun ,[fixed_sun] = @fixed_sun ,[sun_position] = @sun_position |
1255 | ,[covenant] = @covenant ,[covenant_datetime] = @covenant_datetime, [sunvectorx] = @sunvectorx, [sunvectory] = @sunvectory, [sunvectorz] = @sunvectorz, [Sandbox] = @Sandbox, [loaded_creation_datetime] = @loaded_creation_datetime, [loaded_creation_id] = @loaded_creation_id | 1257 | ,[covenant] = @covenant ,[covenant_datetime] = @covenant_datetime, [sunvectorx] = @sunvectorx, [sunvectory] = @sunvectory, [sunvectorz] = @sunvectorz, [Sandbox] = @Sandbox, [loaded_creation_datetime] = @loaded_creation_datetime, [loaded_creation_id] = @loaded_creation_id, [map_tile_id] = @TerrainImageID, [telehubobject] = @telehubobject, [parcel_tile_id] = @ParcelImageID |
1256 | WHERE [regionUUID] = @regionUUID"; | 1258 | WHERE [regionUUID] = @regionUUID"; |
1257 | 1259 | ||
1258 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | 1260 | using (SqlConnection conn = new SqlConnection(m_connectionString)) |
@@ -1263,6 +1265,7 @@ VALUES | |||
1263 | cmd.ExecuteNonQuery(); | 1265 | cmd.ExecuteNonQuery(); |
1264 | } | 1266 | } |
1265 | } | 1267 | } |
1268 | SaveSpawnPoints(regionSettings); | ||
1266 | } | 1269 | } |
1267 | 1270 | ||
1268 | public void Shutdown() | 1271 | public void Shutdown() |
@@ -1383,6 +1386,11 @@ VALUES | |||
1383 | newSettings.LoadedCreationID = ""; | 1386 | newSettings.LoadedCreationID = ""; |
1384 | else | 1387 | else |
1385 | newSettings.LoadedCreationID = (String)row["loaded_creation_id"]; | 1388 | newSettings.LoadedCreationID = (String)row["loaded_creation_id"]; |
1389 | |||
1390 | newSettings.TerrainImageID = new UUID((string)row["map_tile_ID"]); | ||
1391 | newSettings.ParcelImageID = new UUID((Guid)row["parcel_tile_ID"]); | ||
1392 | newSettings.TelehubObject = new UUID((Guid)row["TelehubObject"]); | ||
1393 | |||
1386 | return newSettings; | 1394 | return newSettings; |
1387 | } | 1395 | } |
1388 | 1396 | ||
@@ -1454,6 +1462,13 @@ VALUES | |||
1454 | } | 1462 | } |
1455 | 1463 | ||
1456 | newData.ParcelAccessList = new List<LandAccessEntry>(); | 1464 | newData.ParcelAccessList = new List<LandAccessEntry>(); |
1465 | newData.MediaDescription = (string)row["MediaDescription"]; | ||
1466 | newData.MediaType = (string)row["MediaType"]; | ||
1467 | newData.MediaWidth = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[0]); | ||
1468 | newData.MediaHeight = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[1]); | ||
1469 | newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]); | ||
1470 | newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]); | ||
1471 | newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]); | ||
1457 | 1472 | ||
1458 | return newData; | 1473 | return newData; |
1459 | } | 1474 | } |
@@ -1468,7 +1483,7 @@ VALUES | |||
1468 | LandAccessEntry entry = new LandAccessEntry(); | 1483 | LandAccessEntry entry = new LandAccessEntry(); |
1469 | entry.AgentID = new UUID((Guid)row["AccessUUID"]); | 1484 | entry.AgentID = new UUID((Guid)row["AccessUUID"]); |
1470 | entry.Flags = (AccessList)Convert.ToInt32(row["Flags"]); | 1485 | entry.Flags = (AccessList)Convert.ToInt32(row["Flags"]); |
1471 | entry.Expires = 0; | 1486 | entry.Expires = Convert.ToInt32(row["Expires"]); |
1472 | return entry; | 1487 | return entry; |
1473 | } | 1488 | } |
1474 | 1489 | ||
@@ -1497,7 +1512,8 @@ VALUES | |||
1497 | prim.TouchName = (string)primRow["TouchName"]; | 1512 | prim.TouchName = (string)primRow["TouchName"]; |
1498 | // permissions | 1513 | // permissions |
1499 | prim.Flags = (PrimFlags)Convert.ToUInt32(primRow["ObjectFlags"]); | 1514 | prim.Flags = (PrimFlags)Convert.ToUInt32(primRow["ObjectFlags"]); |
1500 | prim.CreatorID = new UUID((Guid)primRow["CreatorID"]); | 1515 | //prim.CreatorID = new UUID((Guid)primRow["CreatorID"]); |
1516 | prim.CreatorIdentification = (string)primRow["CreatorID"]; | ||
1501 | prim.OwnerID = new UUID((Guid)primRow["OwnerID"]); | 1517 | prim.OwnerID = new UUID((Guid)primRow["OwnerID"]); |
1502 | prim.GroupID = new UUID((Guid)primRow["GroupID"]); | 1518 | prim.GroupID = new UUID((Guid)primRow["GroupID"]); |
1503 | prim.LastOwnerID = new UUID((Guid)primRow["LastOwnerID"]); | 1519 | prim.LastOwnerID = new UUID((Guid)primRow["LastOwnerID"]); |
@@ -1691,7 +1707,8 @@ VALUES | |||
1691 | taskItem.Name = (string)inventoryRow["name"]; | 1707 | taskItem.Name = (string)inventoryRow["name"]; |
1692 | taskItem.Description = (string)inventoryRow["description"]; | 1708 | taskItem.Description = (string)inventoryRow["description"]; |
1693 | taskItem.CreationDate = Convert.ToUInt32(inventoryRow["creationDate"]); | 1709 | taskItem.CreationDate = Convert.ToUInt32(inventoryRow["creationDate"]); |
1694 | taskItem.CreatorID = new UUID((Guid)inventoryRow["creatorID"]); | 1710 | //taskItem.CreatorID = new UUID((Guid)inventoryRow["creatorID"]); |
1711 | taskItem.CreatorIdentification = (string)inventoryRow["creatorID"]; | ||
1695 | taskItem.OwnerID = new UUID((Guid)inventoryRow["ownerID"]); | 1712 | taskItem.OwnerID = new UUID((Guid)inventoryRow["ownerID"]); |
1696 | taskItem.LastOwnerID = new UUID((Guid)inventoryRow["lastOwnerID"]); | 1713 | taskItem.LastOwnerID = new UUID((Guid)inventoryRow["lastOwnerID"]); |
1697 | taskItem.GroupID = new UUID((Guid)inventoryRow["groupID"]); | 1714 | taskItem.GroupID = new UUID((Guid)inventoryRow["groupID"]); |
@@ -1792,6 +1809,9 @@ VALUES | |||
1792 | parameters.Add(_Database.CreateParameter("covenant_datetime", settings.CovenantChangedDateTime)); | 1809 | parameters.Add(_Database.CreateParameter("covenant_datetime", settings.CovenantChangedDateTime)); |
1793 | parameters.Add(_Database.CreateParameter("Loaded_Creation_DateTime", settings.LoadedCreationDateTime)); | 1810 | parameters.Add(_Database.CreateParameter("Loaded_Creation_DateTime", settings.LoadedCreationDateTime)); |
1794 | parameters.Add(_Database.CreateParameter("Loaded_Creation_ID", settings.LoadedCreationID)); | 1811 | parameters.Add(_Database.CreateParameter("Loaded_Creation_ID", settings.LoadedCreationID)); |
1812 | parameters.Add(_Database.CreateParameter("TerrainImageID", settings.TerrainImageID)); | ||
1813 | parameters.Add(_Database.CreateParameter("ParcelImageID", settings.ParcelImageID)); | ||
1814 | parameters.Add(_Database.CreateParameter("TelehubObject", settings.TelehubObject)); | ||
1795 | 1815 | ||
1796 | return parameters.ToArray(); | 1816 | return parameters.ToArray(); |
1797 | } | 1817 | } |
@@ -1859,6 +1879,7 @@ VALUES | |||
1859 | parameters.Add(_Database.CreateParameter("LandUUID", parcelID)); | 1879 | parameters.Add(_Database.CreateParameter("LandUUID", parcelID)); |
1860 | parameters.Add(_Database.CreateParameter("AccessUUID", parcelAccessEntry.AgentID)); | 1880 | parameters.Add(_Database.CreateParameter("AccessUUID", parcelAccessEntry.AgentID)); |
1861 | parameters.Add(_Database.CreateParameter("Flags", parcelAccessEntry.Flags)); | 1881 | parameters.Add(_Database.CreateParameter("Flags", parcelAccessEntry.Flags)); |
1882 | parameters.Add(_Database.CreateParameter("Expires", parcelAccessEntry.Expires)); | ||
1862 | 1883 | ||
1863 | return parameters.ToArray(); | 1884 | return parameters.ToArray(); |
1864 | } | 1885 | } |
@@ -2063,5 +2084,57 @@ VALUES | |||
2063 | #endregion | 2084 | #endregion |
2064 | 2085 | ||
2065 | #endregion | 2086 | #endregion |
2087 | |||
2088 | private void LoadSpawnPoints(RegionSettings rs) | ||
2089 | { | ||
2090 | rs.ClearSpawnPoints(); | ||
2091 | |||
2092 | string sql = "SELECT Yaw, Pitch, Distance FROM spawn_points WHERE RegionUUID = @RegionUUID"; | ||
2093 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | ||
2094 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | ||
2095 | { | ||
2096 | cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", rs.RegionUUID.ToString())); | ||
2097 | conn.Open(); | ||
2098 | using (SqlDataReader reader = cmd.ExecuteReader()) | ||
2099 | { | ||
2100 | if (reader.Read()) | ||
2101 | { | ||
2102 | SpawnPoint sp = new SpawnPoint(); | ||
2103 | |||
2104 | sp.Yaw = (float)reader["Yaw"]; | ||
2105 | sp.Pitch = (float)reader["Pitch"]; | ||
2106 | sp.Distance = (float)reader["Distance"]; | ||
2107 | |||
2108 | rs.AddSpawnPoint(sp); | ||
2109 | } | ||
2110 | } | ||
2111 | } | ||
2112 | } | ||
2113 | |||
2114 | private void SaveSpawnPoints(RegionSettings rs) | ||
2115 | { | ||
2116 | string sql = "DELETE FROM spawn_points WHERE RegionUUID = @RegionUUID"; | ||
2117 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | ||
2118 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | ||
2119 | { | ||
2120 | cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", rs.RegionUUID)); | ||
2121 | conn.Open(); | ||
2122 | cmd.ExecuteNonQuery(); | ||
2123 | } | ||
2124 | foreach (SpawnPoint p in rs.SpawnPoints()) | ||
2125 | { | ||
2126 | sql = "INSERT INTO spawn_points (RegionUUID, Yaw, Pitch, Distance) VALUES (@RegionUUID, @Yaw, @Pitch, @Distance)"; | ||
2127 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | ||
2128 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | ||
2129 | { | ||
2130 | cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", rs.RegionUUID)); | ||
2131 | cmd.Parameters.Add(_Database.CreateParameter("@Yaw", p.Yaw)); | ||
2132 | cmd.Parameters.Add(_Database.CreateParameter("@Pitch", p.Pitch)); | ||
2133 | cmd.Parameters.Add(_Database.CreateParameter("@Distance", p.Distance)); | ||
2134 | conn.Open(); | ||
2135 | cmd.ExecuteNonQuery(); | ||
2136 | } | ||
2137 | } | ||
2138 | } | ||
2066 | } | 2139 | } |
2067 | } | 2140 | } |
diff --git a/OpenSim/Data/MSSQL/Resources/RegionStore.migrations b/OpenSim/Data/MSSQL/Resources/RegionStore.migrations index a98690a..d6a3be9 100644 --- a/OpenSim/Data/MSSQL/Resources/RegionStore.migrations +++ b/OpenSim/Data/MSSQL/Resources/RegionStore.migrations | |||
@@ -1044,10 +1044,93 @@ ALTER TABLE primitems ALTER COLUMN CreatorID uniqueidentifier NOT NULL | |||
1044 | 1044 | ||
1045 | COMMIT | 1045 | COMMIT |
1046 | 1046 | ||
1047 | :VERSION 29 #--------------------- | 1047 | :VERSION 29 #----------------- Region Covenant changed time |
1048 | 1048 | ||
1049 | BEGIN TRANSACTION | 1049 | BEGIN TRANSACTION |
1050 | 1050 | ||
1051 | ALTER TABLE regionsettings ADD covenant_datetime int NOT NULL default 0 | 1051 | ALTER TABLE regionsettings ADD covenant_datetime int NOT NULL default 0 |
1052 | 1052 | ||
1053 | COMMIT | 1053 | COMMIT |
1054 | |||
1055 | :VERSION 30 #------------------Migrate creatorID storage to varchars instead of UUIDs for HG support | ||
1056 | |||
1057 | BEGIN TRANSACTION | ||
1058 | |||
1059 | EXECUTE sp_rename N'dbo.prims.creatorid', N'creatoridold', 'COLUMN' | ||
1060 | EXECUTE sp_rename N'dbo.primitems.creatorid', N'creatoridold', 'COLUMN' | ||
1061 | |||
1062 | COMMIT | ||
1063 | |||
1064 | :VERSION 31 #--------------------- | ||
1065 | |||
1066 | BEGIN TRANSACTION | ||
1067 | |||
1068 | ALTER TABLE prims ADD CreatorID varchar(255) | ||
1069 | ALTER TABLE primitems ADD CreatorID varchar(255) | ||
1070 | |||
1071 | COMMIT | ||
1072 | |||
1073 | :VERSION 32 #--------------------- | ||
1074 | |||
1075 | BEGIN TRANSACTION | ||
1076 | |||
1077 | UPDATE prims SET prims.CreatorID = CONVERT(varchar(255), creatoridold) | ||
1078 | UPDATE primitems SET primitems.CreatorID = CONVERT(varchar(255), creatoridold) | ||
1079 | |||
1080 | COMMIT | ||
1081 | |||
1082 | :VERSION 33 #--------------------- | ||
1083 | |||
1084 | BEGIN TRANSACTION | ||
1085 | |||
1086 | ALTER TABLE prims | ||
1087 | ADD CONSTRAINT DF_prims_CreatorIDNew | ||
1088 | DEFAULT '00000000-0000-0000-0000-000000000000' | ||
1089 | FOR CreatorID | ||
1090 | |||
1091 | ALTER TABLE prims ALTER COLUMN CreatorID varchar(255) NOT NULL | ||
1092 | |||
1093 | ALTER TABLE primitems | ||
1094 | ADD CONSTRAINT DF_primitems_CreatorIDNew | ||
1095 | DEFAULT '00000000-0000-0000-0000-000000000000' | ||
1096 | FOR CreatorID | ||
1097 | |||
1098 | ALTER TABLE primitems ALTER COLUMN CreatorID varchar(255) NOT NULL | ||
1099 | |||
1100 | COMMIT | ||
1101 | |||
1102 | :VERSION 34 #--------------- Telehub support | ||
1103 | |||
1104 | BEGIN TRANSACTION | ||
1105 | |||
1106 | CREATE TABLE [dbo].[Spawn_Points]( | ||
1107 | [RegionUUID] [uniqueidentifier] NOT NULL, | ||
1108 | [Yaw] [float] NOT NULL, | ||
1109 | [Pitch] [float] NOT NULL, | ||
1110 | [Distance] [float] NOT NULL, | ||
1111 | PRIMARY KEY CLUSTERED | ||
1112 | ( | ||
1113 | [RegionUUID] ASC | ||
1114 | )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY] | ||
1115 | ) ON [PRIMARY] | ||
1116 | |||
1117 | ALTER TABLE regionsettings ADD TelehubObject uniqueidentifier NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'; | ||
1118 | |||
1119 | COMMIT | ||
1120 | |||
1121 | :VERSION 35 #---------------- Parcels for sale | ||
1122 | |||
1123 | BEGIN TRANSACTION | ||
1124 | |||
1125 | ALTER TABLE regionsettings ADD parcel_tile_ID uniqueidentifier NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'; | ||
1126 | |||
1127 | COMMIT | ||
1128 | |||
1129 | :VERSION 36 #---------------- Timed bans/access | ||
1130 | |||
1131 | BEGIN TRANSACTION | ||
1132 | |||
1133 | ALTER TABLE landaccesslist ADD Expires integer NOT NULL DEFAULT 0; | ||
1134 | |||
1135 | COMMIT | ||
1136 | |||
diff --git a/OpenSim/Data/MySQL/MySQLXAssetData.cs b/OpenSim/Data/MySQL/MySQLXAssetData.cs new file mode 100644 index 0000000..e6ac22e --- /dev/null +++ b/OpenSim/Data/MySQL/MySQLXAssetData.cs | |||
@@ -0,0 +1,500 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.IO; | ||
32 | using System.IO.Compression; | ||
33 | using System.Reflection; | ||
34 | using System.Security.Cryptography; | ||
35 | using System.Text; | ||
36 | using log4net; | ||
37 | using MySql.Data.MySqlClient; | ||
38 | using OpenMetaverse; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Data; | ||
41 | |||
42 | namespace OpenSim.Data.MySQL | ||
43 | { | ||
44 | public class MySQLXAssetData : IXAssetDataPlugin | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | protected virtual Assembly Assembly | ||
49 | { | ||
50 | get { return GetType().Assembly; } | ||
51 | } | ||
52 | |||
53 | private bool m_enableCompression = false; | ||
54 | private string m_connectionString; | ||
55 | private object m_dbLock = new object(); | ||
56 | |||
57 | /// <summary> | ||
58 | /// We can reuse this for all hashing since all methods are single-threaded through m_dbBLock | ||
59 | /// </summary> | ||
60 | private HashAlgorithm hasher = new SHA256CryptoServiceProvider(); | ||
61 | |||
62 | #region IPlugin Members | ||
63 | |||
64 | public string Version { get { return "1.0.0.0"; } } | ||
65 | |||
66 | /// <summary> | ||
67 | /// <para>Initialises Asset interface</para> | ||
68 | /// <para> | ||
69 | /// <list type="bullet"> | ||
70 | /// <item>Loads and initialises the MySQL storage plugin.</item> | ||
71 | /// <item>Warns and uses the obsolete mysql_connection.ini if connect string is empty.</item> | ||
72 | /// <item>Check for migration</item> | ||
73 | /// </list> | ||
74 | /// </para> | ||
75 | /// </summary> | ||
76 | /// <param name="connect">connect string</param> | ||
77 | public void Initialise(string connect) | ||
78 | { | ||
79 | m_log.ErrorFormat("[MYSQL XASSETDATA]: ***********************************************************"); | ||
80 | m_log.ErrorFormat("[MYSQL XASSETDATA]: ***********************************************************"); | ||
81 | m_log.ErrorFormat("[MYSQL XASSETDATA]: ***********************************************************"); | ||
82 | m_log.ErrorFormat("[MYSQL XASSETDATA]: THIS PLUGIN IS STRICTLY EXPERIMENTAL."); | ||
83 | m_log.ErrorFormat("[MYSQL XASSETDATA]: DO NOT USE FOR ANY DATA THAT YOU DO NOT MIND LOSING."); | ||
84 | m_log.ErrorFormat("[MYSQL XASSETDATA]: DATABASE TABLES CAN CHANGE AT ANY TIME, CAUSING EXISTING DATA TO BE LOST."); | ||
85 | m_log.ErrorFormat("[MYSQL XASSETDATA]: ***********************************************************"); | ||
86 | m_log.ErrorFormat("[MYSQL XASSETDATA]: ***********************************************************"); | ||
87 | m_log.ErrorFormat("[MYSQL XASSETDATA]: ***********************************************************"); | ||
88 | |||
89 | m_connectionString = connect; | ||
90 | |||
91 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
92 | { | ||
93 | dbcon.Open(); | ||
94 | Migration m = new Migration(dbcon, Assembly, "XAssetStore"); | ||
95 | m.Update(); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | public void Initialise() | ||
100 | { | ||
101 | throw new NotImplementedException(); | ||
102 | } | ||
103 | |||
104 | public void Dispose() { } | ||
105 | |||
106 | /// <summary> | ||
107 | /// The name of this DB provider | ||
108 | /// </summary> | ||
109 | public string Name | ||
110 | { | ||
111 | get { return "MySQL XAsset storage engine"; } | ||
112 | } | ||
113 | |||
114 | #endregion | ||
115 | |||
116 | #region IAssetDataPlugin Members | ||
117 | |||
118 | /// <summary> | ||
119 | /// Fetch Asset <paramref name="assetID"/> from database | ||
120 | /// </summary> | ||
121 | /// <param name="assetID">Asset UUID to fetch</param> | ||
122 | /// <returns>Return the asset</returns> | ||
123 | /// <remarks>On failure : throw an exception and attempt to reconnect to database</remarks> | ||
124 | public AssetBase GetAsset(UUID assetID) | ||
125 | { | ||
126 | // m_log.DebugFormat("[MYSQL XASSET DATA]: Looking for asset {0}", assetID); | ||
127 | |||
128 | AssetBase asset = null; | ||
129 | lock (m_dbLock) | ||
130 | { | ||
131 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
132 | { | ||
133 | dbcon.Open(); | ||
134 | |||
135 | using (MySqlCommand cmd = new MySqlCommand( | ||
136 | "SELECT name, description, asset_type, local, temporary, asset_flags, creator_id, data FROM xassetsmeta JOIN xassetsdata ON xassetsmeta.hash = xassetsdata.hash WHERE id=?id", | ||
137 | dbcon)) | ||
138 | { | ||
139 | cmd.Parameters.AddWithValue("?id", assetID.ToString()); | ||
140 | |||
141 | try | ||
142 | { | ||
143 | using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) | ||
144 | { | ||
145 | if (dbReader.Read()) | ||
146 | { | ||
147 | asset = new AssetBase(assetID, (string)dbReader["name"], (sbyte)dbReader["asset_type"], dbReader["creator_id"].ToString()); | ||
148 | asset.Data = (byte[])dbReader["data"]; | ||
149 | asset.Description = (string)dbReader["description"]; | ||
150 | |||
151 | string local = dbReader["local"].ToString(); | ||
152 | if (local.Equals("1") || local.Equals("true", StringComparison.InvariantCultureIgnoreCase)) | ||
153 | asset.Local = true; | ||
154 | else | ||
155 | asset.Local = false; | ||
156 | |||
157 | asset.Temporary = Convert.ToBoolean(dbReader["temporary"]); | ||
158 | asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]); | ||
159 | |||
160 | if (m_enableCompression) | ||
161 | { | ||
162 | using (GZipStream decompressionStream = new GZipStream(new MemoryStream(asset.Data), CompressionMode.Decompress)) | ||
163 | { | ||
164 | MemoryStream outputStream = new MemoryStream(); | ||
165 | WebUtil.CopyStream(decompressionStream, outputStream, int.MaxValue); | ||
166 | // int compressedLength = asset.Data.Length; | ||
167 | asset.Data = outputStream.ToArray(); | ||
168 | |||
169 | // m_log.DebugFormat( | ||
170 | // "[XASSET DB]: Decompressed {0} {1} to {2} bytes from {3}", | ||
171 | // asset.ID, asset.Name, asset.Data.Length, compressedLength); | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | } | ||
176 | } | ||
177 | catch (Exception e) | ||
178 | { | ||
179 | m_log.Error("[MYSQL XASSET DATA]: MySql failure fetching asset " + assetID + ": " + e.Message); | ||
180 | } | ||
181 | } | ||
182 | } | ||
183 | } | ||
184 | |||
185 | return asset; | ||
186 | } | ||
187 | |||
188 | /// <summary> | ||
189 | /// Create an asset in database, or update it if existing. | ||
190 | /// </summary> | ||
191 | /// <param name="asset">Asset UUID to create</param> | ||
192 | /// <remarks>On failure : Throw an exception and attempt to reconnect to database</remarks> | ||
193 | public void StoreAsset(AssetBase asset) | ||
194 | { | ||
195 | lock (m_dbLock) | ||
196 | { | ||
197 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
198 | { | ||
199 | dbcon.Open(); | ||
200 | |||
201 | using (MySqlTransaction transaction = dbcon.BeginTransaction()) | ||
202 | { | ||
203 | string assetName = asset.Name; | ||
204 | if (asset.Name.Length > 64) | ||
205 | { | ||
206 | assetName = asset.Name.Substring(0, 64); | ||
207 | m_log.Warn("[XASSET DB]: Name field truncated from " + asset.Name.Length + " to " + assetName.Length + " characters on add"); | ||
208 | } | ||
209 | |||
210 | string assetDescription = asset.Description; | ||
211 | if (asset.Description.Length > 64) | ||
212 | { | ||
213 | assetDescription = asset.Description.Substring(0, 64); | ||
214 | m_log.Warn("[XASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on add"); | ||
215 | } | ||
216 | |||
217 | if (m_enableCompression) | ||
218 | { | ||
219 | MemoryStream outputStream = new MemoryStream(); | ||
220 | |||
221 | using (GZipStream compressionStream = new GZipStream(outputStream, CompressionMode.Compress, false)) | ||
222 | { | ||
223 | // Console.WriteLine(WebUtil.CopyTo(new MemoryStream(asset.Data), compressionStream, int.MaxValue)); | ||
224 | // We have to close the compression stream in order to make sure it writes everything out to the underlying memory output stream. | ||
225 | compressionStream.Close(); | ||
226 | byte[] compressedData = outputStream.ToArray(); | ||
227 | asset.Data = compressedData; | ||
228 | } | ||
229 | } | ||
230 | |||
231 | byte[] hash = hasher.ComputeHash(asset.Data); | ||
232 | |||
233 | // m_log.DebugFormat( | ||
234 | // "[XASSET DB]: Compressed data size for {0} {1}, hash {2} is {3}", | ||
235 | // asset.ID, asset.Name, hash, compressedData.Length); | ||
236 | |||
237 | try | ||
238 | { | ||
239 | using (MySqlCommand cmd = | ||
240 | new MySqlCommand( | ||
241 | "replace INTO xassetsmeta(id, hash, name, description, asset_type, local, temporary, create_time, access_time, asset_flags, creator_id)" + | ||
242 | "VALUES(?id, ?hash, ?name, ?description, ?asset_type, ?local, ?temporary, ?create_time, ?access_time, ?asset_flags, ?creator_id)", | ||
243 | dbcon)) | ||
244 | { | ||
245 | // create unix epoch time | ||
246 | int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow); | ||
247 | cmd.Parameters.AddWithValue("?id", asset.ID); | ||
248 | cmd.Parameters.AddWithValue("?hash", hash); | ||
249 | cmd.Parameters.AddWithValue("?name", assetName); | ||
250 | cmd.Parameters.AddWithValue("?description", assetDescription); | ||
251 | cmd.Parameters.AddWithValue("?asset_type", asset.Type); | ||
252 | cmd.Parameters.AddWithValue("?local", asset.Local); | ||
253 | cmd.Parameters.AddWithValue("?temporary", asset.Temporary); | ||
254 | cmd.Parameters.AddWithValue("?create_time", now); | ||
255 | cmd.Parameters.AddWithValue("?access_time", now); | ||
256 | cmd.Parameters.AddWithValue("?creator_id", asset.Metadata.CreatorID); | ||
257 | cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags); | ||
258 | cmd.ExecuteNonQuery(); | ||
259 | } | ||
260 | } | ||
261 | catch (Exception e) | ||
262 | { | ||
263 | m_log.ErrorFormat("[ASSET DB]: MySQL failure creating asset metadata {0} with name \"{1}\". Error: {2}", | ||
264 | asset.FullID, asset.Name, e.Message); | ||
265 | |||
266 | transaction.Rollback(); | ||
267 | |||
268 | return; | ||
269 | } | ||
270 | |||
271 | if (!ExistsData(dbcon, transaction, hash)) | ||
272 | { | ||
273 | try | ||
274 | { | ||
275 | using (MySqlCommand cmd = | ||
276 | new MySqlCommand( | ||
277 | "INSERT INTO xassetsdata(hash, data) VALUES(?hash, ?data)", | ||
278 | dbcon)) | ||
279 | { | ||
280 | cmd.Parameters.AddWithValue("?hash", hash); | ||
281 | cmd.Parameters.AddWithValue("?data", asset.Data); | ||
282 | cmd.ExecuteNonQuery(); | ||
283 | } | ||
284 | } | ||
285 | catch (Exception e) | ||
286 | { | ||
287 | m_log.ErrorFormat("[XASSET DB]: MySQL failure creating asset data {0} with name \"{1}\". Error: {2}", | ||
288 | asset.FullID, asset.Name, e.Message); | ||
289 | |||
290 | transaction.Rollback(); | ||
291 | |||
292 | return; | ||
293 | } | ||
294 | } | ||
295 | |||
296 | transaction.Commit(); | ||
297 | } | ||
298 | } | ||
299 | } | ||
300 | } | ||
301 | |||
302 | // private void UpdateAccessTime(AssetBase asset) | ||
303 | // { | ||
304 | // lock (m_dbLock) | ||
305 | // { | ||
306 | // using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
307 | // { | ||
308 | // dbcon.Open(); | ||
309 | // MySqlCommand cmd = | ||
310 | // new MySqlCommand("update assets set access_time=?access_time where id=?id", | ||
311 | // dbcon); | ||
312 | // | ||
313 | // // need to ensure we dispose | ||
314 | // try | ||
315 | // { | ||
316 | // using (cmd) | ||
317 | // { | ||
318 | // // create unix epoch time | ||
319 | // int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow); | ||
320 | // cmd.Parameters.AddWithValue("?id", asset.ID); | ||
321 | // cmd.Parameters.AddWithValue("?access_time", now); | ||
322 | // cmd.ExecuteNonQuery(); | ||
323 | // cmd.Dispose(); | ||
324 | // } | ||
325 | // } | ||
326 | // catch (Exception e) | ||
327 | // { | ||
328 | // m_log.ErrorFormat( | ||
329 | // "[ASSETS DB]: " + | ||
330 | // "MySql failure updating access_time for asset {0} with name {1}" + Environment.NewLine + e.ToString() | ||
331 | // + Environment.NewLine + "Attempting reconnection", asset.FullID, asset.Name); | ||
332 | // } | ||
333 | // } | ||
334 | // } | ||
335 | // | ||
336 | // } | ||
337 | |||
338 | /// <summary> | ||
339 | /// We assume we already have the m_dbLock. | ||
340 | /// </summary> | ||
341 | /// TODO: need to actually use the transaction. | ||
342 | /// <param name="dbcon"></param> | ||
343 | /// <param name="transaction"></param> | ||
344 | /// <param name="hash"></param> | ||
345 | /// <returns></returns> | ||
346 | private bool ExistsData(MySqlConnection dbcon, MySqlTransaction transaction, byte[] hash) | ||
347 | { | ||
348 | // m_log.DebugFormat("[ASSETS DB]: Checking for asset {0}", uuid); | ||
349 | |||
350 | bool exists = false; | ||
351 | |||
352 | using (MySqlCommand cmd = new MySqlCommand("SELECT hash FROM xassetsdata WHERE hash=?hash", dbcon)) | ||
353 | { | ||
354 | cmd.Parameters.AddWithValue("?hash", hash); | ||
355 | |||
356 | try | ||
357 | { | ||
358 | using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) | ||
359 | { | ||
360 | if (dbReader.Read()) | ||
361 | { | ||
362 | // m_log.DebugFormat("[ASSETS DB]: Found asset {0}", uuid); | ||
363 | exists = true; | ||
364 | } | ||
365 | } | ||
366 | } | ||
367 | catch (Exception e) | ||
368 | { | ||
369 | m_log.ErrorFormat( | ||
370 | "[XASSETS DB]: MySql failure in ExistsData fetching hash {0}. Exception {1}{2}", | ||
371 | hash, e.Message, e.StackTrace); | ||
372 | } | ||
373 | } | ||
374 | |||
375 | return exists; | ||
376 | } | ||
377 | |||
378 | /// <summary> | ||
379 | /// Check if the asset exists in the database | ||
380 | /// </summary> | ||
381 | /// <param name="uuid">The asset UUID</param> | ||
382 | /// <returns>true if it exists, false otherwise.</returns> | ||
383 | public bool ExistsAsset(UUID uuid) | ||
384 | { | ||
385 | // m_log.DebugFormat("[ASSETS DB]: Checking for asset {0}", uuid); | ||
386 | |||
387 | bool assetExists = false; | ||
388 | |||
389 | lock (m_dbLock) | ||
390 | { | ||
391 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
392 | { | ||
393 | dbcon.Open(); | ||
394 | using (MySqlCommand cmd = new MySqlCommand("SELECT id FROM xassetsmeta WHERE id=?id", dbcon)) | ||
395 | { | ||
396 | cmd.Parameters.AddWithValue("?id", uuid.ToString()); | ||
397 | |||
398 | try | ||
399 | { | ||
400 | using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) | ||
401 | { | ||
402 | if (dbReader.Read()) | ||
403 | { | ||
404 | // m_log.DebugFormat("[ASSETS DB]: Found asset {0}", uuid); | ||
405 | assetExists = true; | ||
406 | } | ||
407 | } | ||
408 | } | ||
409 | catch (Exception e) | ||
410 | { | ||
411 | m_log.ErrorFormat( | ||
412 | "[XASSETS DB]: MySql failure fetching asset {0}" + Environment.NewLine + e.ToString(), uuid); | ||
413 | } | ||
414 | } | ||
415 | } | ||
416 | } | ||
417 | |||
418 | return assetExists; | ||
419 | } | ||
420 | |||
421 | /// <summary> | ||
422 | /// Returns a list of AssetMetadata objects. The list is a subset of | ||
423 | /// the entire data set offset by <paramref name="start" /> containing | ||
424 | /// <paramref name="count" /> elements. | ||
425 | /// </summary> | ||
426 | /// <param name="start">The number of results to discard from the total data set.</param> | ||
427 | /// <param name="count">The number of rows the returned list should contain.</param> | ||
428 | /// <returns>A list of AssetMetadata objects.</returns> | ||
429 | public List<AssetMetadata> FetchAssetMetadataSet(int start, int count) | ||
430 | { | ||
431 | List<AssetMetadata> retList = new List<AssetMetadata>(count); | ||
432 | |||
433 | lock (m_dbLock) | ||
434 | { | ||
435 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
436 | { | ||
437 | dbcon.Open(); | ||
438 | MySqlCommand cmd = new MySqlCommand("SELECT name,description,asset_type,temporary,id,asset_flags,creator_id FROM xassetsmeta LIMIT ?start, ?count", dbcon); | ||
439 | cmd.Parameters.AddWithValue("?start", start); | ||
440 | cmd.Parameters.AddWithValue("?count", count); | ||
441 | |||
442 | try | ||
443 | { | ||
444 | using (MySqlDataReader dbReader = cmd.ExecuteReader()) | ||
445 | { | ||
446 | while (dbReader.Read()) | ||
447 | { | ||
448 | AssetMetadata metadata = new AssetMetadata(); | ||
449 | metadata.Name = (string)dbReader["name"]; | ||
450 | metadata.Description = (string)dbReader["description"]; | ||
451 | metadata.Type = (sbyte)dbReader["asset_type"]; | ||
452 | metadata.Temporary = Convert.ToBoolean(dbReader["temporary"]); // Not sure if this is correct. | ||
453 | metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]); | ||
454 | metadata.FullID = DBGuid.FromDB(dbReader["id"]); | ||
455 | metadata.CreatorID = dbReader["creator_id"].ToString(); | ||
456 | |||
457 | // We'll ignore this for now - it appears unused! | ||
458 | // metadata.SHA1 = dbReader["hash"]); | ||
459 | |||
460 | retList.Add(metadata); | ||
461 | } | ||
462 | } | ||
463 | } | ||
464 | catch (Exception e) | ||
465 | { | ||
466 | m_log.Error("[XASSETS DB]: MySql failure fetching asset set" + Environment.NewLine + e.ToString()); | ||
467 | } | ||
468 | } | ||
469 | } | ||
470 | |||
471 | return retList; | ||
472 | } | ||
473 | |||
474 | public bool Delete(string id) | ||
475 | { | ||
476 | // m_log.DebugFormat("[XASSETS DB]: Deleting asset {0}", id); | ||
477 | |||
478 | lock (m_dbLock) | ||
479 | { | ||
480 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
481 | { | ||
482 | dbcon.Open(); | ||
483 | |||
484 | using (MySqlCommand cmd = new MySqlCommand("delete from xassetsmeta where id=?id", dbcon)) | ||
485 | { | ||
486 | cmd.Parameters.AddWithValue("?id", id); | ||
487 | cmd.ExecuteNonQuery(); | ||
488 | } | ||
489 | |||
490 | // TODO: How do we deal with data from deleted assets? Probably not easily reapable unless we | ||
491 | // keep a reference count (?) | ||
492 | } | ||
493 | } | ||
494 | |||
495 | return true; | ||
496 | } | ||
497 | |||
498 | #endregion | ||
499 | } | ||
500 | } \ No newline at end of file | ||
diff --git a/OpenSim/Data/MySQL/Resources/XAssetStore.migrations b/OpenSim/Data/MySQL/Resources/XAssetStore.migrations new file mode 100644 index 0000000..d3cca5e --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/XAssetStore.migrations | |||
@@ -0,0 +1,27 @@ | |||
1 | # ----------------- | ||
2 | :VERSION 1 | ||
3 | |||
4 | BEGIN; | ||
5 | |||
6 | CREATE TABLE `xassetsmeta` ( | ||
7 | `id` char(36) NOT NULL, | ||
8 | `hash` binary(32) NOT NULL, | ||
9 | `name` varchar(64) NOT NULL, | ||
10 | `description` varchar(64) NOT NULL, | ||
11 | `asset_type` tinyint(4) NOT NULL, | ||
12 | `local` tinyint(1) NOT NULL, | ||
13 | `temporary` tinyint(1) NOT NULL, | ||
14 | `create_time` int(11) NOT NULL, | ||
15 | `access_time` int(11) NOT NULL, | ||
16 | `asset_flags` int(11) NOT NULL, | ||
17 | `creator_id` varchar(128) NOT NULL, | ||
18 | PRIMARY KEY (`id`) | ||
19 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Version 1'; | ||
20 | |||
21 | CREATE TABLE `xassetsdata` ( | ||
22 | `hash` binary(32) NOT NULL, | ||
23 | `data` longblob NOT NULL, | ||
24 | PRIMARY KEY (`hash`) | ||
25 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Version 1'; | ||
26 | |||
27 | COMMIT; \ No newline at end of file | ||