Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Modularize various aspects of the virtual table handling in the example SQLiteVirtualTableCursorEnumerable class. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | virtualTables |
Files: | files | file ages | folders |
SHA1: |
5033bacee1d04e58b47a5d307fc54e33 |
User & Date: | mistachkin 2013-06-21 06:06:27.219 |
Context
2013-06-21
| ||
06:27 | Fix disposal semantics for classes derived from the SQLiteModuleBase class. Use the String.Format method consistently. Enable virtual table related native memory allocation tracking on the .NET Compact Framework. check-in: f9041807b3 user: mistachkin tags: virtualTables | |
06:06 | Modularize various aspects of the virtual table handling in the example SQLiteVirtualTableCursorEnumerable class. check-in: 5033bacee1 user: mistachkin tags: virtualTables | |
05:39 | Move the native memory allocation wrapper methods into the new SQLiteMemory class. check-in: c16bb56cfd user: mistachkin tags: virtualTables | |
Changes
Changes to System.Data.SQLite/SQLiteModuleBase.cs.
︙ | ︙ | |||
2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 | SQLiteMemory.Free(pError); pError = IntPtr.Zero; } } return success; } /////////////////////////////////////////////////////////////////////// protected virtual bool SetCursorError( SQLiteVirtualTableCursor cursor, string error ) | > > > > > > > > > > > > > > > > > > | 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 | SQLiteMemory.Free(pError); pError = IntPtr.Zero; } } return success; } /////////////////////////////////////////////////////////////////////// protected virtual bool SetTableError( SQLiteVirtualTable table, string error ) { if (table == null) return false; IntPtr pVtab = table.NativeHandle; if (pVtab == IntPtr.Zero) return false; return SetTableError(pVtab, error); } /////////////////////////////////////////////////////////////////////// protected virtual bool SetCursorError( SQLiteVirtualTableCursor cursor, string error ) |
︙ | ︙ |
Changes to System.Data.SQLite/SQLiteModuleEnumerable.cs.
︙ | ︙ | |||
99 100 101 102 103 104 105 | /////////////////////////////////////////////////////////////////////// #region Private Data /// <summary> /// The <see cref="IEnumerable" /> instance containing the backing data /// for the virtual table. /// </summary> | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | /////////////////////////////////////////////////////////////////////// #region Private Data /// <summary> /// The <see cref="IEnumerable" /> instance containing the backing data /// for the virtual table. /// </summary> private IEnumerable enumerable; #endregion /////////////////////////////////////////////////////////////////////// #region Public Constructors public SQLiteModuleEnumerable( string name, IEnumerable enumerable ) : base(name) { if (enumerable == null) throw new ArgumentNullException("enumerable"); this.enumerable = enumerable; } #endregion /////////////////////////////////////////////////////////////////////// #region Protected Methods protected virtual SQLiteErrorCode CursorTypeMismatchError( SQLiteVirtualTableCursor cursor ) { SetCursorError(cursor, "not an \"enumerable\" cursor"); return SQLiteErrorCode.Error; } /////////////////////////////////////////////////////////////////////// protected virtual SQLiteErrorCode CursorEndOfEnumeratorError( SQLiteVirtualTableCursor cursor ) { SetCursorError(cursor, "already hit end of enumerator"); return SQLiteErrorCode.Error; } /////////////////////////////////////////////////////////////////////// protected virtual string GetStringFromObject( object value ) { if (value == null) return null; return value.ToString(); } /////////////////////////////////////////////////////////////////////// protected virtual long GetRowIdFromObject( object value ) { if (value == null) return 0; return value.GetHashCode(); } /////////////////////////////////////////////////////////////////////// protected virtual bool CodeToEofResult( SQLiteErrorCode returnCode ) { return (returnCode == SQLiteErrorCode.Ok) ? false : true; } #endregion /////////////////////////////////////////////////////////////////////// #region ISQLiteManagedModule Members public override SQLiteErrorCode Create( SQLiteConnection connection, |
︙ | ︙ | |||
188 189 190 191 192 193 194 | SQLiteIndex index ) { CheckDisposed(); if (!SetDefaultEstimatedCost(index)) { | < | < | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | SQLiteIndex index ) { CheckDisposed(); if (!SetDefaultEstimatedCost(index)) { SetTableError(table, "failed to set default estimated cost"); return SQLiteErrorCode.Error; } return SQLiteErrorCode.Ok; } /////////////////////////////////////////////////////////////////////// |
︙ | ︙ | |||
231 232 233 234 235 236 237 | SQLiteVirtualTable table, ref SQLiteVirtualTableCursor cursor ) { CheckDisposed(); cursor = new SQLiteVirtualTableCursorEnumerable( | | | 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | SQLiteVirtualTable table, ref SQLiteVirtualTableCursor cursor ) { CheckDisposed(); cursor = new SQLiteVirtualTableCursorEnumerable( table, enumerable.GetEnumerator()); return SQLiteErrorCode.Ok; } /////////////////////////////////////////////////////////////////////// public override SQLiteErrorCode Close( |
︙ | ︙ | |||
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | SQLiteVirtualTableCursorEnumerable enumerableCursor = cursor as SQLiteVirtualTableCursorEnumerable; if (enumerableCursor == null) return CursorTypeMismatchError(cursor); enumerableCursor.MoveNext(); /* IGNORED */ return SQLiteErrorCode.Ok; } /////////////////////////////////////////////////////////////////////// public override bool Eof( SQLiteVirtualTableCursor cursor ) { CheckDisposed(); SQLiteVirtualTableCursorEnumerable enumerableCursor = cursor as SQLiteVirtualTableCursorEnumerable; if (enumerableCursor == null) | > > > < | < < | 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | SQLiteVirtualTableCursorEnumerable enumerableCursor = cursor as SQLiteVirtualTableCursorEnumerable; if (enumerableCursor == null) return CursorTypeMismatchError(cursor); if (enumerableCursor.EndOfEnumerator) return CursorEndOfEnumeratorError(cursor); enumerableCursor.MoveNext(); /* IGNORED */ return SQLiteErrorCode.Ok; } /////////////////////////////////////////////////////////////////////// public override bool Eof( SQLiteVirtualTableCursor cursor ) { CheckDisposed(); SQLiteVirtualTableCursorEnumerable enumerableCursor = cursor as SQLiteVirtualTableCursorEnumerable; if (enumerableCursor == null) return CodeToEofResult(CursorTypeMismatchError(cursor)); return enumerableCursor.EndOfEnumerator; } /////////////////////////////////////////////////////////////////////// public override SQLiteErrorCode Column( |
︙ | ︙ | |||
333 334 335 336 337 338 339 | SQLiteVirtualTableCursorEnumerable enumerableCursor = cursor as SQLiteVirtualTableCursorEnumerable; if (enumerableCursor == null) return CursorTypeMismatchError(cursor); if (enumerableCursor.EndOfEnumerator) | < < | < | > > > < < | < < | | | | | 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | SQLiteVirtualTableCursorEnumerable enumerableCursor = cursor as SQLiteVirtualTableCursorEnumerable; if (enumerableCursor == null) return CursorTypeMismatchError(cursor); if (enumerableCursor.EndOfEnumerator) return CursorEndOfEnumeratorError(cursor); object current = enumerableCursor.Current; if (current != null) context.SetString(GetStringFromObject(current)); else context.SetNull(); return SQLiteErrorCode.Ok; } /////////////////////////////////////////////////////////////////////// public override SQLiteErrorCode RowId( SQLiteVirtualTableCursor cursor, ref long rowId ) { CheckDisposed(); SQLiteVirtualTableCursorEnumerable enumerableCursor = cursor as SQLiteVirtualTableCursorEnumerable; if (enumerableCursor == null) return CursorTypeMismatchError(cursor); if (enumerableCursor.EndOfEnumerator) return CursorEndOfEnumeratorError(cursor); object current = enumerableCursor.Current; rowId = GetRowIdFromObject(current); return SQLiteErrorCode.Ok; } /////////////////////////////////////////////////////////////////////// public override SQLiteErrorCode Update( SQLiteVirtualTable table, SQLiteValue[] values, ref long rowId ) { CheckDisposed(); SetTableError(table, String.Format( "virtual table \"{0}\" is read-only", table.TableName)); return SQLiteErrorCode.Error; } /////////////////////////////////////////////////////////////////////// public override SQLiteErrorCode Rename( SQLiteVirtualTable table, string newName ) { CheckDisposed(); if (!table.Rename(newName)) { SetTableError(table, String.Format( "failed to rename virtual table from \"{0}\" to \"{1}\"", table.TableName, newName)); return SQLiteErrorCode.Error; } return SQLiteErrorCode.Ok; } |
︙ | ︙ |