diff options
author | Teravus Ovares | 2007-12-05 15:53:58 +0000 |
---|---|---|
committer | Teravus Ovares | 2007-12-05 15:53:58 +0000 |
commit | 71fd737a66c58faa6854ad1c1d8c58f64491fdb0 (patch) | |
tree | c9c876c361afbf76d416b7f2c413ff56a1f9beef /OpenSim/Framework/Data.MSSQL/MSSQLAssetData.cs | |
parent | made one or two more methods in Scene virtual to allow overriding in sub clas... (diff) | |
download | opensim-SC_OLD-71fd737a66c58faa6854ad1c1d8c58f64491fdb0.zip opensim-SC_OLD-71fd737a66c58faa6854ad1c1d8c58f64491fdb0.tar.gz opensim-SC_OLD-71fd737a66c58faa6854ad1c1d8c58f64491fdb0.tar.bz2 opensim-SC_OLD-71fd737a66c58faa6854ad1c1d8c58f64491fdb0.tar.xz |
* Applied MSSQL Patch from akokko, Thanks! akokko
* This hasn't been tested in MSSQL mode, however it's been checked to make sure it doesn't cause any issues with mySQL/SQLlite
Diffstat (limited to 'OpenSim/Framework/Data.MSSQL/MSSQLAssetData.cs')
-rw-r--r-- | OpenSim/Framework/Data.MSSQL/MSSQLAssetData.cs | 227 |
1 files changed, 227 insertions, 0 deletions
diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLAssetData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLAssetData.cs new file mode 100644 index 0000000..e933a5b --- /dev/null +++ b/OpenSim/Framework/Data.MSSQL/MSSQLAssetData.cs | |||
@@ -0,0 +1,227 @@ | |||
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 OpenSim 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 | |||
29 | using System; | ||
30 | using System.Data; | ||
31 | using System.Collections.Generic; | ||
32 | using System.Data.SqlClient; | ||
33 | |||
34 | using libsecondlife; | ||
35 | using OpenSim.Framework.Console; | ||
36 | |||
37 | namespace OpenSim.Framework.Data.MSSQL | ||
38 | { | ||
39 | class MSSQLAssetData : IAssetProvider | ||
40 | { | ||
41 | MSSQLManager database; | ||
42 | #region IAssetProvider Members | ||
43 | |||
44 | private void UpgradeAssetsTable(string tableName) | ||
45 | { | ||
46 | // null as the version, indicates that the table didn't exist | ||
47 | if (tableName == null) | ||
48 | { | ||
49 | MainLog.Instance.Notice("ASSETS", "Creating new database tables"); | ||
50 | database.ExecuteResourceSql("CreateAssetsTable.sql"); | ||
51 | return; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | /// <summary> | ||
56 | /// Ensure that the assets related tables exists and are at the latest version | ||
57 | /// </summary> | ||
58 | private void TestTables() | ||
59 | { | ||
60 | |||
61 | Dictionary<string, string> tableList = new Dictionary<string, string>(); | ||
62 | |||
63 | tableList["assets"] = null; | ||
64 | database.GetTableVersion(tableList); | ||
65 | |||
66 | UpgradeAssetsTable(tableList["assets"]); | ||
67 | |||
68 | } | ||
69 | |||
70 | public AssetBase FetchAsset(LLUUID assetID) | ||
71 | { | ||
72 | AssetBase asset = null; | ||
73 | |||
74 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
75 | param["id"] = assetID.ToStringHyphenated(); | ||
76 | |||
77 | IDbCommand result = database.Query("SELECT * FROM assets WHERE id = @id", param); | ||
78 | IDataReader reader = result.ExecuteReader(); | ||
79 | |||
80 | asset = database.getAssetRow(reader); | ||
81 | reader.Close(); | ||
82 | result.Dispose(); | ||
83 | |||
84 | return asset; | ||
85 | } | ||
86 | |||
87 | public void CreateAsset(AssetBase asset) | ||
88 | { | ||
89 | |||
90 | if (ExistsAsset((LLUUID)asset.FullID)) | ||
91 | { | ||
92 | return; | ||
93 | } | ||
94 | |||
95 | |||
96 | |||
97 | SqlCommand cmd = | ||
98 | new SqlCommand( | ||
99 | "INSERT INTO assets ([id], [name], [description], [assetType], [invType], [local], [temporary], [data])"+ | ||
100 | " VALUES "+ | ||
101 | "(@id, @name, @description, @assetType, @invType, @local, @temporary, @data)", | ||
102 | database.getConnection()); | ||
103 | |||
104 | using (cmd) | ||
105 | { | ||
106 | |||
107 | //SqlParameter p = cmd.Parameters.Add("id", SqlDbType.NVarChar); | ||
108 | //p.Value = asset.FullID.ToStringHyphenated(); | ||
109 | cmd.Parameters.AddWithValue("id", asset.FullID.ToStringHyphenated()); | ||
110 | cmd.Parameters.AddWithValue("name", asset.Name); | ||
111 | cmd.Parameters.AddWithValue("description", asset.Description); | ||
112 | SqlParameter e = cmd.Parameters.Add("assetType", SqlDbType.TinyInt); | ||
113 | e.Value = asset.Type; | ||
114 | SqlParameter f = cmd.Parameters.Add("invType", SqlDbType.TinyInt); | ||
115 | f.Value = asset.InvType; | ||
116 | SqlParameter g = cmd.Parameters.Add("local", SqlDbType.TinyInt); | ||
117 | g.Value = asset.Local; | ||
118 | SqlParameter h = cmd.Parameters.Add("temporary", SqlDbType.TinyInt); | ||
119 | h.Value = asset.Temporary; | ||
120 | SqlParameter i = cmd.Parameters.Add("data", SqlDbType.Image); | ||
121 | i.Value = asset.Data; | ||
122 | try | ||
123 | { | ||
124 | cmd.ExecuteNonQuery(); | ||
125 | } | ||
126 | catch (Exception) | ||
127 | { | ||
128 | throw; | ||
129 | } | ||
130 | |||
131 | cmd.Dispose(); | ||
132 | } | ||
133 | |||
134 | } | ||
135 | |||
136 | |||
137 | public void UpdateAsset(AssetBase asset) | ||
138 | { | ||
139 | SqlCommand command = new SqlCommand("UPDATE assets set id = @id, " + | ||
140 | "name = @name, " + | ||
141 | "description = @description," + | ||
142 | "assetType = @assetType," + | ||
143 | "invType = @invType," + | ||
144 | "local = @local,"+ | ||
145 | "temporary = @temporary," + | ||
146 | "data = @data where " + | ||
147 | "id = @keyId;", database.getConnection()); | ||
148 | SqlParameter param1 = new SqlParameter("@id", asset.FullID.ToStringHyphenated()); | ||
149 | SqlParameter param2 = new SqlParameter("@name", asset.Name); | ||
150 | SqlParameter param3 = new SqlParameter("@description", asset.Description); | ||
151 | SqlParameter param4 = new SqlParameter("@assetType", asset.Type); | ||
152 | SqlParameter param5 = new SqlParameter("@invType", asset.InvType); | ||
153 | SqlParameter param6 = new SqlParameter("@local", asset.Local); | ||
154 | SqlParameter param7 = new SqlParameter("@temporary", asset.Temporary); | ||
155 | SqlParameter param8 = new SqlParameter("@data", asset.Data); | ||
156 | SqlParameter param9 = new SqlParameter("@keyId", asset.FullID.ToStringHyphenated()); | ||
157 | command.Parameters.Add(param1); | ||
158 | command.Parameters.Add(param2); | ||
159 | command.Parameters.Add(param3); | ||
160 | command.Parameters.Add(param4); | ||
161 | command.Parameters.Add(param5); | ||
162 | command.Parameters.Add(param6); | ||
163 | command.Parameters.Add(param7); | ||
164 | command.Parameters.Add(param8); | ||
165 | command.Parameters.Add(param9); | ||
166 | |||
167 | try | ||
168 | { | ||
169 | command.ExecuteNonQuery(); | ||
170 | } | ||
171 | catch (Exception e) | ||
172 | { | ||
173 | MainLog.Instance.Error(e.ToString()); | ||
174 | } | ||
175 | |||
176 | } | ||
177 | |||
178 | public bool ExistsAsset(LLUUID uuid) | ||
179 | { | ||
180 | if (FetchAsset(uuid) != null) { | ||
181 | return true; | ||
182 | } | ||
183 | return false; | ||
184 | } | ||
185 | |||
186 | /// <summary> | ||
187 | /// All writes are immediately commited to the database, so this is a no-op | ||
188 | /// </summary> | ||
189 | public void CommitAssets() | ||
190 | { | ||
191 | } | ||
192 | |||
193 | #endregion | ||
194 | |||
195 | #region IPlugin Members | ||
196 | |||
197 | |||
198 | |||
199 | public void Initialise() | ||
200 | { | ||
201 | |||
202 | IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini"); | ||
203 | string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source"); | ||
204 | string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog"); | ||
205 | string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info"); | ||
206 | string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id"); | ||
207 | string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); | ||
208 | |||
209 | this.database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword); | ||
210 | |||
211 | TestTables(); | ||
212 | } | ||
213 | |||
214 | public string Version | ||
215 | { | ||
216 | // get { return database.getVersion(); } | ||
217 | get { return database.getVersion(); } | ||
218 | } | ||
219 | |||
220 | public string Name | ||
221 | { | ||
222 | get { return "MSSQL Asset storage engine"; } | ||
223 | } | ||
224 | |||
225 | #endregion | ||
226 | } | ||
227 | } \ No newline at end of file | ||