System.Data.SQLite
Check-in [08eaed4731]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Implement the xFilter virtual table method. More cleanup.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | virtualTables
Files: files | file ages | folders
SHA1: 08eaed4731c9a225f9e29bb21dde0d8ba5dcd21f
User & Date: mistachkin 2013-06-07 21:23:10
Context
2013-06-08
02:36
Reorganize native interop definitions into the UnsafeNativeMethods class. Enable compilation for the .NET Compact Framework. check-in: 2a9118d124 user: mistachkin tags: virtualTables
2013-06-07
21:23
Implement the xFilter virtual table method. More cleanup. check-in: 08eaed4731 user: mistachkin tags: virtualTables
19:14
Implement the SQLiteContext helper class. check-in: 95425066e0 user: mistachkin tags: virtualTables
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to System.Data.SQLite/SQLiteModuleBase.cs.

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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
...
814
815
816
817
818
819
820

















821
822
823
824
825
826
827
...
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
....
1217
1218
1219
1220
1221
1222
1223













1224








1225
1226
1227
1228
1229
1230
1231
                public xRollbackTo xRollbackTo;
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct sqlite3_vtab
            {
                [MarshalAs(UnmanagedType.LPStruct)]
                sqlite3_module pModule;
                int nRef; /* NO LONGER USED */
                IntPtr zErrMsg;
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct sqlite3_vtab_cursor
            {
                [MarshalAs(UnmanagedType.LPStruct)]
                sqlite3_vtab pVTab;
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct sqlite3_index_constraint
            {
                int iColumn;
                byte op;
                byte usable;
                int iTermOffset;
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct sqlite3_index_orderby
            {
                int iColumn; /* Column number */
                byte desc;   /* True for DESC.  False for ASC. */
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct sqlite3_index_constraint_usage
            {
                int argvIndex; /* if >0, constraint is part of argv to xFilter */
                byte omit;     /* Do not code a test for this constraint */
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct sqlite3_index_info
            {
                /* Inputs */
                int nConstraint;           /* Number of entries in aConstraint */
                [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)]
                sqlite3_index_constraint[] aConstraint;
                int nOrderBy;
                sqlite3_index_orderby[] aOrderBy;
                /* Outputs */
                sqlite3_index_constraint_usage[] aConstraintUsage;
                int idxNum;                /* Number used to identify the index */
                string idxStr;              /* String, possibly obtained from sqlite3_malloc */
                int needToFreeIdxStr;      /* Free idxStr using sqlite3_free() if true */
                int orderByConsumed;       /* True if output is already ordered */
                double estimatedCost;      /* Estimated cost of using this index */
            }





            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
................................................................................
            IntPtr[] result = new IntPtr[values.Length];

            for (int index = 0; index < result.Length; index++)
                result[index] = Utf8IntPtrFromString(values[index]);

            return result;
        }

















        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Public Constructors
        public SQLiteModuleBase()
        {
................................................................................
                    FreeCursor(result);
                    result = IntPtr.Zero;
                }
            }

            return result;
        }

        ///////////////////////////////////////////////////////////////////////



        ///////////////////////////////////////////////////////////////////////

        protected virtual void FreeCursor(IntPtr pCursor)
        {
            Free(pCursor);
        }
................................................................................
            IntPtr pCursor,
            int idxNum,
            IntPtr idxStr,
            int argc,
            IntPtr[] argv
            )
        {













            return SQLiteErrorCode.Ok;








        }

        ///////////////////////////////////////////////////////////////////////

        public SQLiteErrorCode xNext(
            IntPtr pCursor
            )







|
|
|






|





|
|
|
|





|
|





|
|






|

|
|
|

|
|
|
|
|
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
<
<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>







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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
...
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
...
930
931
932
933
934
935
936




937
938
939
940
941
942
943
....
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
                public xRollbackTo xRollbackTo;
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct sqlite3_vtab
            {
                [MarshalAs(UnmanagedType.LPStruct)]
                public sqlite3_module pModule;
                public int nRef; /* NO LONGER USED */
                public IntPtr zErrMsg;
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct sqlite3_vtab_cursor
            {
                [MarshalAs(UnmanagedType.LPStruct)]
                public sqlite3_vtab pVTab;
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct sqlite3_index_constraint
            {
                public int iColumn;
                public byte op;
                public byte usable;
                public int iTermOffset;
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct sqlite3_index_orderby
            {
                public int iColumn; /* Column number */
                public byte desc;   /* True for DESC.  False for ASC. */
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct sqlite3_index_constraint_usage
            {
                public int argvIndex; /* if >0, constraint is part of argv to xFilter */
                public byte omit;     /* Do not code a test for this constraint */
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct sqlite3_index_info
            {
                /* Inputs */
                public int nConstraint;           /* Number of entries in aConstraint */
                [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)]
                public sqlite3_index_constraint[] aConstraint;
                public int nOrderBy;
                public sqlite3_index_orderby[] aOrderBy;
                /* Outputs */
                public sqlite3_index_constraint_usage[] aConstraintUsage;
                public int idxNum;                /* Number used to identify the index */
                public string idxStr;              /* String, possibly obtained from sqlite3_malloc */
                public int needToFreeIdxStr;      /* Free idxStr using sqlite3_free() if true */
                public int orderByConsumed;       /* True if output is already ordered */
                public double estimatedCost;      /* Estimated cost of using this index */
            }





            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
................................................................................
            IntPtr[] result = new IntPtr[values.Length];

            for (int index = 0; index < result.Length; index++)
                result[index] = Utf8IntPtrFromString(values[index]);

            return result;
        }

        ///////////////////////////////////////////////////////////////////////

        private static SQLiteValue[] ValueArrayFromIntPtrArray(
            IntPtr[] values
            )
        {
            if (values == null)
                return null;

            SQLiteValue[] result = new SQLiteValue[values.Length];

            for (int index = 0; index < result.Length; index++)
                result[index] = new SQLiteValue(values[index]);

            return result;
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Public Constructors
        public SQLiteModuleBase()
        {
................................................................................
                    FreeCursor(result);
                    result = IntPtr.Zero;
                }
            }

            return result;
        }





        ///////////////////////////////////////////////////////////////////////

        protected virtual void FreeCursor(IntPtr pCursor)
        {
            Free(pCursor);
        }
................................................................................
            IntPtr pCursor,
            int idxNum,
            IntPtr idxStr,
            int argc,
            IntPtr[] argv
            )
        {
            IntPtr pVtab = IntPtr.Zero;

            try
            {
                pVtab = GetTableFromCursor(pCursor);

                SQLiteVirtualTableCursor cursor = MarshalCursorFromIntPtr(
                    pCursor);

                if (Filter(
                        cursor, idxNum, StringFromUtf8IntPtr(idxStr),
                        ValueArrayFromIntPtrArray(argv)) == SQLiteErrorCode.Ok)
                {
                    return SQLiteErrorCode.Ok;
                }
            }
            catch (Exception e) /* NOTE: Must catch ALL. */
            {
                SetTableError(pVtab, e.ToString());
            }

            return SQLiteErrorCode.Error;
        }

        ///////////////////////////////////////////////////////////////////////

        public SQLiteErrorCode xNext(
            IntPtr pCursor
            )