Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Modify native argument marshalling so that it will work properly on the .NET Compact Framework. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | virtualTables |
Files: | files | file ages | folders |
SHA1: |
9946328e41ba10f22c414137370f909e |
User & Date: | mistachkin 2013-06-25 19:49:13.752 |
Context
2013-06-25
| ||
19:58 | Update version history docs. check-in: 3ea49abb4e user: mistachkin tags: virtualTables | |
19:49 | Modify native argument marshalling so that it will work properly on the .NET Compact Framework. check-in: 9946328e41 user: mistachkin tags: virtualTables | |
11:55 | First attempt at making virtual table support work on the .NET Compact Framework. check-in: 78e8297a83 user: mistachkin tags: virtualTables | |
Changes
Changes to System.Data.SQLite/SQLite3.cs.
︙ | ︙ | |||
1658 1659 1660 1661 1662 1663 1664 | UnsafeNativeMethods.sqlite3_module nativeModule = module.CreateNativeModule(); #if !PLATFORM_COMPACTFRAMEWORK if (UnsafeNativeMethods.sqlite3_create_disposable_module( _sql, pName, ref nativeModule, IntPtr.Zero, null) != IntPtr.Zero) | | > > > > | 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 | UnsafeNativeMethods.sqlite3_module nativeModule = module.CreateNativeModule(); #if !PLATFORM_COMPACTFRAMEWORK if (UnsafeNativeMethods.sqlite3_create_disposable_module( _sql, pName, ref nativeModule, IntPtr.Zero, null) != IntPtr.Zero) #elif !SQLITE_STANDARD if (UnsafeNativeMethods.sqlite3_create_disposable_module_interop( _sql, pName, module.CreateNativeModuleInterop(), nativeModule.iVersion, nativeModule.xCreate, nativeModule.xConnect, nativeModule.xBestIndex, nativeModule.xDisconnect, nativeModule.xDestroy, nativeModule.xOpen, nativeModule.xClose, nativeModule.xFilter, nativeModule.xNext, nativeModule.xEof, nativeModule.xColumn, nativeModule.xRowId, nativeModule.xUpdate, nativeModule.xBegin, nativeModule.xSync, nativeModule.xCommit, nativeModule.xRollback, nativeModule.xFindFunction, nativeModule.xRename, nativeModule.xSavepoint, nativeModule.xRelease, nativeModule.xRollbackTo, IntPtr.Zero, null) != IntPtr.Zero) #else throw new NotImplementedException(); #endif #if !PLATFORM_COMPACTFRAMEWORK || !SQLITE_STANDARD { if (_modules == null) _modules = new Dictionary<string, SQLiteModule>(); _modules.Add(module.Name, module); } else { throw new SQLiteException(GetLastError()); } #endif } finally { if (pName != IntPtr.Zero) { SQLiteMemory.Free(pName); pName = IntPtr.Zero; |
︙ | ︙ |
Changes to System.Data.SQLite/SQLiteModule.cs.
︙ | ︙ | |||
1681 1682 1683 1684 1685 1686 1687 | /// <returns> /// A standard SQLite return code. /// </returns> SQLiteErrorCode xCreate( IntPtr pDb, IntPtr pAux, int argc, | | | 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 | /// <returns> /// A standard SQLite return code. /// </returns> SQLiteErrorCode xCreate( IntPtr pDb, IntPtr pAux, int argc, IntPtr argv, ref IntPtr pVtab, ref IntPtr pError ); /////////////////////////////////////////////////////////////////////// /// <summary> |
︙ | ︙ | |||
1771 1772 1773 1774 1775 1776 1777 | /// <returns> /// A standard SQLite return code. /// </returns> SQLiteErrorCode xConnect( IntPtr pDb, IntPtr pAux, int argc, | | | 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 | /// <returns> /// A standard SQLite return code. /// </returns> SQLiteErrorCode xConnect( IntPtr pDb, IntPtr pAux, int argc, IntPtr argv, ref IntPtr pVtab, ref IntPtr pError ); /////////////////////////////////////////////////////////////////////// /// <summary> |
︙ | ︙ | |||
2237 2238 2239 2240 2241 2242 2243 | /// A standard SQLite return code. /// </returns> SQLiteErrorCode xFilter( IntPtr pCursor, int idxNum, IntPtr idxStr, int argc, | | | 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 | /// A standard SQLite return code. /// </returns> SQLiteErrorCode xFilter( IntPtr pCursor, int idxNum, IntPtr idxStr, int argc, IntPtr argv ); /////////////////////////////////////////////////////////////////////// /// <summary> /// <para> /// The xNext method advances a virtual table cursor to the next row of |
︙ | ︙ | |||
2517 2518 2519 2520 2521 2522 2523 | /// </param> /// <returns> /// A standard SQLite return code. /// </returns> SQLiteErrorCode xUpdate( IntPtr pVtab, int argc, | | | 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 | /// </param> /// <returns> /// A standard SQLite return code. /// </returns> SQLiteErrorCode xUpdate( IntPtr pVtab, int argc, IntPtr argv, ref long rowId ); /////////////////////////////////////////////////////////////////////// /// <summary> /// <para> |
︙ | ︙ | |||
3705 3706 3707 3708 3709 3710 3711 | } #endregion /////////////////////////////////////////////////////////////////////// #region UTF-8 String Array Helper Methods /// <summary> | | | | > | > > > > | > | > > | > | | > > > > > > | > | 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 | } #endregion /////////////////////////////////////////////////////////////////////// #region UTF-8 String Array Helper Methods /// <summary> /// Converts a logical array of native NUL-terminated UTF-8 string /// pointers into an array of managed strings. /// </summary> /// <param name="argc"> /// The number of elements in the logical array of native /// NUL-terminated UTF-8 string pointers. /// </param> /// <param name="argv"> /// The native pointer to the logical array of native NUL-terminated /// UTF-8 string pointers to convert. /// </param> /// <returns> /// The array of managed strings or null upon failure. /// </returns> public static string[] StringArrayFromUtf8SizeAndIntPtr( int argc, IntPtr argv ) { if (argc < 0) return null; if (argv == IntPtr.Zero) return null; string[] result = new string[argc]; for (int index = 0, offset = 0; index < result.Length; index++, offset += IntPtr.Size) { IntPtr pArg = SQLiteMarshal.ReadIntPtr(argv, offset); result[index] = (pArg != IntPtr.Zero) ? StringFromUtf8IntPtr(pArg) : null; } return result; } /////////////////////////////////////////////////////////////////////// /// <summary> |
︙ | ︙ | |||
4059 4060 4061 4062 4063 4064 4065 | } #endregion /////////////////////////////////////////////////////////////////////// #region SQLiteValue Helper Methods /// <summary> | | | > > > > > | | > | > | > > | | > > > > > > | > | 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 | } #endregion /////////////////////////////////////////////////////////////////////// #region SQLiteValue Helper Methods /// <summary> /// Converts a logical array of native pointers to native sqlite3_value /// structures into a managed array of <see cref="SQLiteValue" /> /// object instances. /// </summary> /// <param name="argc"> /// The number of elements in the logical array of native sqlite3_value /// structures. /// </param> /// <param name="argv"> /// The native pointer to the logical array of native sqlite3_value /// structures to convert. /// </param> /// <returns> /// The managed array of <see cref="SQLiteValue" /> object instances or /// null upon failure. /// </returns> public static SQLiteValue[] ValueArrayFromSizeAndIntPtr( int argc, IntPtr argv ) { if (argc < 0) return null; if (argv == IntPtr.Zero) return null; SQLiteValue[] result = new SQLiteValue[argc]; for (int index = 0, offset = 0; index < result.Length; index++, offset += IntPtr.Size) { IntPtr pArg = ReadIntPtr(argv, offset); result[index] = (pArg != IntPtr.Zero) ? new SQLiteValue(pArg) : null; } return result; } #endregion /////////////////////////////////////////////////////////////////////// |
︙ | ︙ | |||
4388 4389 4390 4391 4392 4393 4394 | /// <returns> /// See the <see cref="ISQLiteNativeModule.xCreate" /> method. /// </returns> public SQLiteErrorCode xCreate( IntPtr pDb, IntPtr pAux, int argc, | | | 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 | /// <returns> /// See the <see cref="ISQLiteNativeModule.xCreate" /> method. /// </returns> public SQLiteErrorCode xCreate( IntPtr pDb, IntPtr pAux, int argc, IntPtr argv, ref IntPtr pVtab, ref IntPtr pError ) { // CheckDisposed(); if (module == null) |
︙ | ︙ | |||
4437 4438 4439 4440 4441 4442 4443 | /// <returns> /// See the <see cref="ISQLiteNativeModule.xConnect" /> method. /// </returns> public SQLiteErrorCode xConnect( IntPtr pDb, IntPtr pAux, int argc, | | | 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 | /// <returns> /// See the <see cref="ISQLiteNativeModule.xConnect" /> method. /// </returns> public SQLiteErrorCode xConnect( IntPtr pDb, IntPtr pAux, int argc, IntPtr argv, ref IntPtr pVtab, ref IntPtr pError ) { // CheckDisposed(); if (module == null) |
︙ | ︙ | |||
4607 4608 4609 4610 4611 4612 4613 | /// See the <see cref="ISQLiteNativeModule.xFilter" /> method. /// </returns> public SQLiteErrorCode xFilter( IntPtr pCursor, int idxNum, IntPtr idxStr, int argc, | | | 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 | /// See the <see cref="ISQLiteNativeModule.xFilter" /> method. /// </returns> public SQLiteErrorCode xFilter( IntPtr pCursor, int idxNum, IntPtr idxStr, int argc, IntPtr argv ) { // CheckDisposed(); if (module == null) return ModuleNotAvailableCursorError(pCursor); |
︙ | ︙ | |||
4748 4749 4750 4751 4752 4753 4754 | /// </param> /// <returns> /// See the <see cref="ISQLiteNativeModule.xUpdate" /> method. /// </returns> public SQLiteErrorCode xUpdate( IntPtr pVtab, int argc, | | | 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 | /// </param> /// <returns> /// See the <see cref="ISQLiteNativeModule.xUpdate" /> method. /// </returns> public SQLiteErrorCode xUpdate( IntPtr pVtab, int argc, IntPtr argv, ref long rowId ) { // CheckDisposed(); if (module == null) return ModuleNotAvailableTableError(pVtab); |
︙ | ︙ | |||
6193 6194 6195 6196 6197 6198 6199 | /// <returns> /// See the <see cref="ISQLiteNativeModule.xCreate" /> method. /// </returns> private SQLiteErrorCode xCreate( IntPtr pDb, IntPtr pAux, int argc, | | | | | 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 | /// <returns> /// See the <see cref="ISQLiteNativeModule.xCreate" /> method. /// </returns> private SQLiteErrorCode xCreate( IntPtr pDb, IntPtr pAux, int argc, IntPtr argv, ref IntPtr pVtab, ref IntPtr pError ) { try { string fileName = SQLiteString.StringFromUtf8IntPtr( UnsafeNativeMethods.sqlite3_db_filename(pDb, IntPtr.Zero)); using (SQLiteConnection connection = new SQLiteConnection( pDb, fileName, false)) { SQLiteVirtualTable table = null; string error = null; if (Create(connection, pAux, SQLiteString.StringArrayFromUtf8SizeAndIntPtr(argc, argv), ref table, ref error) == SQLiteErrorCode.Ok) { if (table != null) { pVtab = TableToIntPtr(table); return SQLiteErrorCode.Ok; } else |
︙ | ︙ | |||
6268 6269 6270 6271 6272 6273 6274 | /// <returns> /// See the <see cref="ISQLiteNativeModule.xConnect" /> method. /// </returns> private SQLiteErrorCode xConnect( IntPtr pDb, IntPtr pAux, int argc, | | | | | 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 | /// <returns> /// See the <see cref="ISQLiteNativeModule.xConnect" /> method. /// </returns> private SQLiteErrorCode xConnect( IntPtr pDb, IntPtr pAux, int argc, IntPtr argv, ref IntPtr pVtab, ref IntPtr pError ) { try { string fileName = SQLiteString.StringFromUtf8IntPtr( UnsafeNativeMethods.sqlite3_db_filename(pDb, IntPtr.Zero)); using (SQLiteConnection connection = new SQLiteConnection( pDb, fileName, false)) { SQLiteVirtualTable table = null; string error = null; if (Connect(connection, pAux, SQLiteString.StringArrayFromUtf8SizeAndIntPtr(argc, argv), ref table, ref error) == SQLiteErrorCode.Ok) { if (table != null) { pVtab = TableToIntPtr(table); return SQLiteErrorCode.Ok; } else |
︙ | ︙ | |||
6611 6612 6613 6614 6615 6616 6617 | /// See the <see cref="ISQLiteNativeModule.xFilter" /> method. /// </returns> private SQLiteErrorCode xFilter( IntPtr pCursor, int idxNum, IntPtr idxStr, int argc, | | | | 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 | /// See the <see cref="ISQLiteNativeModule.xFilter" /> method. /// </returns> private SQLiteErrorCode xFilter( IntPtr pCursor, int idxNum, IntPtr idxStr, int argc, IntPtr argv ) { IntPtr pVtab = IntPtr.Zero; try { pVtab = TableFromCursor(pCursor); SQLiteVirtualTableCursor cursor = CursorFromIntPtr( pVtab, pCursor); if (cursor != null) { if (Filter(cursor, idxNum, SQLiteString.StringFromUtf8IntPtr(idxStr), SQLiteMarshal.ValueArrayFromSizeAndIntPtr(argc, argv)) == SQLiteErrorCode.Ok) { return SQLiteErrorCode.Ok; } } } catch (Exception e) /* NOTE: Must catch ALL. */ |
︙ | ︙ | |||
6824 6825 6826 6827 6828 6829 6830 | /// </param> /// <returns> /// See the <see cref="ISQLiteNativeModule.xUpdate" /> method. /// </returns> private SQLiteErrorCode xUpdate( IntPtr pVtab, int argc, | | | | | 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 | /// </param> /// <returns> /// See the <see cref="ISQLiteNativeModule.xUpdate" /> method. /// </returns> private SQLiteErrorCode xUpdate( IntPtr pVtab, int argc, IntPtr argv, ref long rowId ) { try { SQLiteVirtualTable table = TableFromIntPtr(pVtab); if (table != null) { return Update( table, SQLiteMarshal.ValueArrayFromSizeAndIntPtr( argc, argv), ref rowId); } } catch (Exception e) /* NOTE: Must catch ALL. */ { SetTableError(pVtab, e.ToString()); } |
︙ | ︙ | |||
7774 7775 7776 7777 7778 7779 7780 | ////////////////////////////////////// try { #if !PLATFORM_COMPACTFRAMEWORK UnsafeNativeMethods.sqlite3_dispose_module( ref nativeModule); | | > > | 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 | ////////////////////////////////////// try { #if !PLATFORM_COMPACTFRAMEWORK UnsafeNativeMethods.sqlite3_dispose_module( ref nativeModule); #elif !SQLITE_STANDARD if (pNativeModule != IntPtr.Zero) { try { UnsafeNativeMethods.sqlite3_dispose_module_interop( pNativeModule); } finally { SQLiteMemory.Free(pNativeModule); } } #else throw new NotImplementedException(); #endif } catch (Exception e) { try { if (LogExceptions) |
︙ | ︙ |
Changes to System.Data.SQLite/UnsafeNativeMethods.cs.
︙ | ︙ | |||
1668 1669 1670 1671 1672 1673 1674 | #if !PLATFORM_COMPACTFRAMEWORK [UnmanagedFunctionPointer(CallingConvention.Cdecl)] #endif public delegate SQLiteErrorCode xCreate( IntPtr pDb, IntPtr pAux, int argc, | < | < | | 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 | #if !PLATFORM_COMPACTFRAMEWORK [UnmanagedFunctionPointer(CallingConvention.Cdecl)] #endif public delegate SQLiteErrorCode xCreate( IntPtr pDb, IntPtr pAux, int argc, IntPtr argv, ref IntPtr pVtab, ref IntPtr pError ); /////////////////////////////////////////////////////////////////////////// #if !PLATFORM_COMPACTFRAMEWORK [UnmanagedFunctionPointer(CallingConvention.Cdecl)] #endif public delegate SQLiteErrorCode xConnect( IntPtr pDb, IntPtr pAux, int argc, IntPtr argv, ref IntPtr pVtab, ref IntPtr pError ); /////////////////////////////////////////////////////////////////////////// #if !PLATFORM_COMPACTFRAMEWORK |
︙ | ︙ | |||
1746 1747 1748 1749 1750 1751 1752 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] #endif public delegate SQLiteErrorCode xFilter( IntPtr pCursor, int idxNum, IntPtr idxStr, int argc, | < | | 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] #endif public delegate SQLiteErrorCode xFilter( IntPtr pCursor, int idxNum, IntPtr idxStr, int argc, IntPtr argv ); /////////////////////////////////////////////////////////////////////////// #if !PLATFORM_COMPACTFRAMEWORK [UnmanagedFunctionPointer(CallingConvention.Cdecl)] #endif |
︙ | ︙ | |||
1797 1798 1799 1800 1801 1802 1803 | #if !PLATFORM_COMPACTFRAMEWORK [UnmanagedFunctionPointer(CallingConvention.Cdecl)] #endif public delegate SQLiteErrorCode xUpdate( IntPtr pVtab, int argc, | < | | 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 | #if !PLATFORM_COMPACTFRAMEWORK [UnmanagedFunctionPointer(CallingConvention.Cdecl)] #endif public delegate SQLiteErrorCode xUpdate( IntPtr pVtab, int argc, IntPtr argv, ref long rowId ); /////////////////////////////////////////////////////////////////////////// #if !PLATFORM_COMPACTFRAMEWORK [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
︙ | ︙ | |||
1891 1892 1893 1894 1895 1896 1897 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] #endif public delegate SQLiteErrorCode xRollbackTo( IntPtr pVtab, int iSavepoint ); | < < < < < < < < < < < < | 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] #endif public delegate SQLiteErrorCode xRollbackTo( IntPtr pVtab, int iSavepoint ); /////////////////////////////////////////////////////////////////////////// #if !PLATFORM_COMPACTFRAMEWORK [UnmanagedFunctionPointer(CallingConvention.Cdecl)] #endif public delegate void xDestroyModule(IntPtr pClientData); #endif |
︙ | ︙ |