diff options
author | Jeff Ames | 2008-01-26 05:06:19 +0000 |
---|---|---|
committer | Jeff Ames | 2008-01-26 05:06:19 +0000 |
commit | b8820a75ef3bf27d3128cf3787915033aad0a463 (patch) | |
tree | d4950a08ff6d4ddf390c8e853ee5f8b15005e16f /ThirdParty | |
parent | Set svn properties. (diff) | |
download | opensim-SC_OLD-b8820a75ef3bf27d3128cf3787915033aad0a463.zip opensim-SC_OLD-b8820a75ef3bf27d3128cf3787915033aad0a463.tar.gz opensim-SC_OLD-b8820a75ef3bf27d3128cf3787915033aad0a463.tar.bz2 opensim-SC_OLD-b8820a75ef3bf27d3128cf3787915033aad0a463.tar.xz |
Ugly workaround for mono-1.2.6 compile failure in TribalMedia code.
Future versions of mono should not need this.
Please revert if this makes you cry.
Diffstat (limited to 'ThirdParty')
-rw-r--r-- | ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseTableMapper.cs | 115 |
1 files changed, 75 insertions, 40 deletions
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseTableMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseTableMapper.cs index e4ea055..d69fcbb 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseTableMapper.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseTableMapper.cs | |||
@@ -123,50 +123,68 @@ namespace TribalMedia.Framework.Data | |||
123 | { | 123 | { |
124 | } | 124 | } |
125 | 125 | ||
126 | // HACK: This is a temporary function used by TryGetValue(). | ||
127 | // Due to a bug in mono 1.2.6, delegate blocks cannot contain | ||
128 | // a using() block. This has been fixed in SVN, so the next | ||
129 | // mono release should work. | ||
130 | private void TryGetConnectionValue(DbConnection connection, TPrimaryKey primaryKey, ref TRowMapper result, ref bool success) | ||
131 | { | ||
132 | using ( | ||
133 | DbCommand command = | ||
134 | CreateSelectCommand(connection, KeyFieldMapper.FieldName, primaryKey)) | ||
135 | { | ||
136 | using (IDataReader reader = command.ExecuteReader()) | ||
137 | { | ||
138 | if (reader.Read()) | ||
139 | { | ||
140 | result = FromReader( CreateReader(reader)); | ||
141 | success = true; | ||
142 | } | ||
143 | else | ||
144 | { | ||
145 | success = false; | ||
146 | } | ||
147 | } | ||
148 | } | ||
149 | } | ||
150 | |||
126 | public bool TryGetValue(TPrimaryKey primaryKey, out TRowMapper value) | 151 | public bool TryGetValue(TPrimaryKey primaryKey, out TRowMapper value) |
127 | { | 152 | { |
128 | TRowMapper result = default(TRowMapper); | 153 | TRowMapper result = default(TRowMapper); |
129 | bool success = false; | 154 | bool success = false; |
130 | 155 | ||
131 | WithConnection(delegate(DbConnection connection) | 156 | WithConnection(delegate(DbConnection connection) |
132 | { | 157 | { |
133 | using ( | 158 | TryGetConnectionValue(connection, primaryKey, ref result, ref success); |
134 | DbCommand command = | 159 | }); |
135 | CreateSelectCommand(connection, KeyFieldMapper.FieldName, primaryKey)) | ||
136 | { | ||
137 | using (IDataReader reader = command.ExecuteReader()) | ||
138 | { | ||
139 | if (reader.Read()) | ||
140 | { | ||
141 | result = FromReader( CreateReader(reader)); | ||
142 | success = true; | ||
143 | } | ||
144 | else | ||
145 | { | ||
146 | success = false; | ||
147 | } | ||
148 | } | ||
149 | } | ||
150 | }); | ||
151 | 160 | ||
152 | value = result; | 161 | value = result; |
153 | 162 | ||
154 | return success; | 163 | return success; |
155 | } | 164 | } |
156 | 165 | ||
166 | // HACK: This is a temporary function used by Remove(). | ||
167 | // Due to a bug in mono 1.2.6, delegate blocks cannot contain | ||
168 | // a using() block. This has been fixed in SVN, so the next | ||
169 | // mono release should work. | ||
170 | protected virtual void TryDelete(DbConnection connection, TPrimaryKey id, ref int deleted) | ||
171 | { | ||
172 | using ( | ||
173 | DbCommand command = | ||
174 | CreateDeleteCommand(connection, KeyFieldMapper.FieldName, id)) | ||
175 | { | ||
176 | deleted = command.ExecuteNonQuery(); | ||
177 | } | ||
178 | } | ||
179 | |||
157 | public virtual bool Remove(TPrimaryKey id) | 180 | public virtual bool Remove(TPrimaryKey id) |
158 | { | 181 | { |
159 | int deleted = 0; | 182 | int deleted = 0; |
160 | 183 | ||
161 | WithConnection(delegate(DbConnection connection) | 184 | WithConnection(delegate(DbConnection connection) |
162 | { | 185 | { |
163 | using ( | 186 | TryDelete(connection, id, ref deleted); |
164 | DbCommand command = | 187 | }); |
165 | CreateDeleteCommand(connection, KeyFieldMapper.FieldName, id)) | ||
166 | { | ||
167 | deleted = command.ExecuteNonQuery(); | ||
168 | } | ||
169 | }); | ||
170 | 188 | ||
171 | if (deleted == 1) | 189 | if (deleted == 1) |
172 | { | 190 | { |
@@ -178,7 +196,6 @@ namespace TribalMedia.Framework.Data | |||
178 | } | 196 | } |
179 | } | 197 | } |
180 | 198 | ||
181 | |||
182 | public DbCommand CreateDeleteCommand(DbConnection connection, string fieldName, TPrimaryKey primaryKey) | 199 | public DbCommand CreateDeleteCommand(DbConnection connection, string fieldName, TPrimaryKey primaryKey) |
183 | { | 200 | { |
184 | string table = TableName; | 201 | string table = TableName; |
@@ -196,17 +213,26 @@ namespace TribalMedia.Framework.Data | |||
196 | return command; | 213 | return command; |
197 | } | 214 | } |
198 | 215 | ||
216 | // HACK: This is a temporary function used by Update(). | ||
217 | // Due to a bug in mono 1.2.6, delegate blocks cannot contain | ||
218 | // a using() block. This has been fixed in SVN, so the next | ||
219 | // mono release should work. | ||
220 | protected void TryUpdate(DbConnection connection, TPrimaryKey primaryKey, TRowMapper value, ref int updated) | ||
221 | { | ||
222 | using (DbCommand command = CreateUpdateCommand(connection, value, primaryKey)) | ||
223 | { | ||
224 | updated = command.ExecuteNonQuery(); | ||
225 | } | ||
226 | } | ||
227 | |||
199 | public virtual bool Update(TPrimaryKey primaryKey, TRowMapper value) | 228 | public virtual bool Update(TPrimaryKey primaryKey, TRowMapper value) |
200 | { | 229 | { |
201 | int updated = 0; | 230 | int updated = 0; |
202 | 231 | ||
203 | WithConnection(delegate(DbConnection connection) | 232 | WithConnection(delegate(DbConnection connection) |
204 | { | 233 | { |
205 | using (DbCommand command = CreateUpdateCommand(connection, value, primaryKey)) | 234 | TryUpdate(connection, primaryKey, value, ref updated); |
206 | { | 235 | }); |
207 | updated = command.ExecuteNonQuery(); | ||
208 | } | ||
209 | }); | ||
210 | 236 | ||
211 | if (updated == 1) | 237 | if (updated == 1) |
212 | { | 238 | { |
@@ -218,17 +244,26 @@ namespace TribalMedia.Framework.Data | |||
218 | } | 244 | } |
219 | } | 245 | } |
220 | 246 | ||
247 | // HACK: This is a temporary function used by Add(). | ||
248 | // Due to a bug in mono 1.2.6, delegate blocks cannot contain | ||
249 | // a using() block. This has been fixed in SVN, so the next | ||
250 | // mono release should work. | ||
251 | protected void TryAdd(DbConnection connection, TRowMapper value, ref int added) | ||
252 | { | ||
253 | using (DbCommand command = CreateInsertCommand(connection, value)) | ||
254 | { | ||
255 | added = command.ExecuteNonQuery(); | ||
256 | } | ||
257 | } | ||
258 | |||
221 | public virtual bool Add(TRowMapper value) | 259 | public virtual bool Add(TRowMapper value) |
222 | { | 260 | { |
223 | int added = 0; | 261 | int added = 0; |
224 | 262 | ||
225 | WithConnection(delegate(DbConnection connection) | 263 | WithConnection(delegate(DbConnection connection) |
226 | { | 264 | { |
227 | using (DbCommand command = CreateInsertCommand(connection, value)) | 265 | TryAdd(connection, value, ref added); |
228 | { | 266 | }); |
229 | added = command.ExecuteNonQuery(); | ||
230 | } | ||
231 | }); | ||
232 | 267 | ||
233 | if (added == 1) | 268 | if (added == 1) |
234 | { | 269 | { |