System.Data.SQLite
Check-in [8a682d20dc]
Not logged in

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

Overview
Comment:More work in progress.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | virtualTables
Files: files | file ages | folders
SHA1: 8a682d20dc6e68a8472cff27a56fa49b8e55f647
User & Date: mistachkin 2013-06-15 02:46:54
Context
2013-06-18
06:07
More work on input/output marshalling for the sqlite3_index_info structure. Also, refactoring to allow better portability to the .NET Compact Framework. check-in: ea5335378e user: mistachkin tags: virtualTables
2013-06-15
02:46
More work in progress. check-in: 8a682d20dc user: mistachkin tags: virtualTables
2013-06-13
22:49
Complete most of the initial virtual table module base class. Some fixes to types for marshalling. check-in: df6776ec88 user: mistachkin tags: virtualTables
Changes
Hide Diffs Unified Diffs Show Whitespace Changes Patch

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

307
308
309
310
311
312
313









314







315



316
317
318
319
320
321








322






323








324








325








326








327





328
329
330
331
332
333








334







335




336
337
338
339
340
341
342
...
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
...
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
...
665
666
667
668
669
670
671























672
673
674
675
676
677
678
...
936
937
938
939
940
941
942
943
944
945




946
947








948
949
950
951
952
953
954
....
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
....
1550
1551
1552
1553
1554
1555
1556

1557
1558
1559
1560
1561
1562
1563
        private UnsafeNativeMethods.sqlite3_index_constraint_usage constraintUsage;
    }

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

    public sealed class SQLiteIndexInputs
    {









        private SQLiteIndexConstraint[] Constraints;







        private SQLiteIndexOrderBy[] OrderBys;



    }

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

    public sealed class SQLiteIndexOutputs
    {








        private SQLiteIndexConstraintUsage[] ConstraintUsages;






        private int idxNum;           /* Number used to identify the index */








        private string idxStr;        /* String, possibly obtained from sqlite3_malloc */








        private int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */








        private int orderByConsumed;  /* True if output is already ordered */








        private double estimatedCost; /* Estimated cost of using this index */





    }

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

    public sealed class SQLiteIndex
    {








        public SQLiteIndexInputs inputs;







        public SQLiteIndexOutputs outputs;




    }

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

    public class SQLiteVirtualTableCursor
    {
        public SQLiteVirtualTableCursor(
................................................................................

    public interface ISQLiteNativeModule
    {
        // https://www.sqlite.org/vtab.html

        SQLiteErrorCode xCreate(IntPtr pDb, IntPtr pAux, int argc, ref IntPtr[] argv, ref IntPtr pVtab, ref IntPtr pError);
        SQLiteErrorCode xConnect(IntPtr pDb, IntPtr pAux, int argc, ref IntPtr[] argv, ref IntPtr pVtab, ref IntPtr pError);
        SQLiteErrorCode xBestIndex(IntPtr pVtab, IntPtr index);
        SQLiteErrorCode xDisconnect(IntPtr pVtab);
        SQLiteErrorCode xDestroy(IntPtr pVtab);
        SQLiteErrorCode xOpen(IntPtr pVtab, ref IntPtr pCursor);
        SQLiteErrorCode xClose(IntPtr pCursor);
        SQLiteErrorCode xFilter(IntPtr pCursor, int idxNum, IntPtr idxStr, int argc, IntPtr[] argv);
        SQLiteErrorCode xNext(IntPtr pCursor);
        bool xEof(IntPtr pCursor);
................................................................................
        SQLiteErrorCode Column(SQLiteVirtualTableCursor cursor, SQLiteContext context, int index);
        SQLiteErrorCode RowId(SQLiteVirtualTableCursor cursor, ref long rowId);
        SQLiteErrorCode Update(SQLiteValue[] values, ref long rowId);
        SQLiteErrorCode Begin();
        SQLiteErrorCode Sync();
        SQLiteErrorCode Commit();
        SQLiteErrorCode Rollback();
        bool FindFunction(string zName, ref SQLiteFunction function, ref IntPtr pClientData);
        SQLiteErrorCode Rename(string zNew);
        SQLiteErrorCode Savepoint(int iSavepoint);
        SQLiteErrorCode Release(int iSavepoint);
        SQLiteErrorCode RollbackTo(int iSavepoint);
    }

    ///////////////////////////////////////////////////////////////////////////
................................................................................

            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()
................................................................................
            return SQLiteErrorCode.Error;
        }

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

        public SQLiteErrorCode xBestIndex(
            IntPtr pVtab,
            IntPtr index
            )
        {




            return SQLiteErrorCode.Ok;
        }









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

        public SQLiteErrorCode xDisconnect(
            IntPtr pVtab
            )
        {
................................................................................
            )
        {
            try
            {
                SQLiteFunction function = null;

                if (FindFunction(
                        StringFromUtf8IntPtr(zName), ref function,
                        ref pClientData))
                {
                    if (function != null)
                    {
                        callback = function.ScalarCallback;
                        return true;
                    }
................................................................................
        ///////////////////////////////////////////////////////////////////////

        public abstract SQLiteErrorCode Rollback();

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

        public abstract bool FindFunction(

            string zName,
            ref SQLiteFunction function,
            ref IntPtr pClientData
            );

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








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






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

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

>
>
>
>
>






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







 







|







 







|







 







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







 







|


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







 







|







 







>







307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
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
367
368
369
370
371
372
373
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
...
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
...
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
...
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
....
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
....
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
....
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
        private UnsafeNativeMethods.sqlite3_index_constraint_usage constraintUsage;
    }

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

    public sealed class SQLiteIndexInputs
    {
        public SQLiteIndexInputs(int nConstraint, int nOrderBy)
        {
            constraints = new SQLiteIndexConstraint[nConstraint];
            orderBys = new SQLiteIndexOrderBy[nOrderBy];
        }

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

        private SQLiteIndexConstraint[] constraints;
        public SQLiteIndexConstraint[] Constraints
        {
            get { return constraints; }
        }

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

        private SQLiteIndexOrderBy[] orderBys;
        public SQLiteIndexOrderBy[] OrderBys
        {
            get { return orderBys; }
        }
    }

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

    public sealed class SQLiteIndexOutputs
    {
        public SQLiteIndexOutputs(int nConstraint)
        {
            constraintUsages = new SQLiteIndexConstraintUsage[nConstraint];
        }

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

        private SQLiteIndexConstraintUsage[] constraintUsages;
        public SQLiteIndexConstraintUsage[] ConstraintUsages
        {
            get { return constraintUsages; }
        }

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

        private int idxNum; /* Number used to identify the index */
        public int IdxNum
        {
            get { return idxNum; }
            set { idxNum = value; }
        }

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

        private string idxStr; /* String, possibly obtained from sqlite3_malloc */
        public string IdxStr
        {
            get { return idxStr; }
            set { idxStr = value; }
        }

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

        private int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
        public int NeedToFreeIdxStr
        {
            get { return needToFreeIdxStr; }
            set { needToFreeIdxStr = value; }
        }

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

        private int orderByConsumed; /* True if output is already ordered */
        public int OrderByConsumed
        {
            get { return orderByConsumed; }
            set { orderByConsumed = value; }
        }

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

        private double estimatedCost; /* Estimated cost of using this index */
        public double EstimatedCost
        {
            get { return estimatedCost; }
            set { estimatedCost = value; }
        }
    }

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

    public sealed class SQLiteIndex
    {
        public SQLiteIndex(int nConstraint, int nOrderBy)
        {
            inputs = new SQLiteIndexInputs(nConstraint, nOrderBy);
            outputs = new SQLiteIndexOutputs(nConstraint);
        }

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

        private SQLiteIndexInputs inputs;
        public SQLiteIndexInputs Inputs
        {
            get { return inputs; }
        }

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

        private SQLiteIndexOutputs outputs;
        public SQLiteIndexOutputs Outputs
        {
            get { return outputs; }
        }
    }

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

    public class SQLiteVirtualTableCursor
    {
        public SQLiteVirtualTableCursor(
................................................................................

    public interface ISQLiteNativeModule
    {
        // https://www.sqlite.org/vtab.html

        SQLiteErrorCode xCreate(IntPtr pDb, IntPtr pAux, int argc, ref IntPtr[] argv, ref IntPtr pVtab, ref IntPtr pError);
        SQLiteErrorCode xConnect(IntPtr pDb, IntPtr pAux, int argc, ref IntPtr[] argv, ref IntPtr pVtab, ref IntPtr pError);
        SQLiteErrorCode xBestIndex(IntPtr pVtab, IntPtr pIndex);
        SQLiteErrorCode xDisconnect(IntPtr pVtab);
        SQLiteErrorCode xDestroy(IntPtr pVtab);
        SQLiteErrorCode xOpen(IntPtr pVtab, ref IntPtr pCursor);
        SQLiteErrorCode xClose(IntPtr pCursor);
        SQLiteErrorCode xFilter(IntPtr pCursor, int idxNum, IntPtr idxStr, int argc, IntPtr[] argv);
        SQLiteErrorCode xNext(IntPtr pCursor);
        bool xEof(IntPtr pCursor);
................................................................................
        SQLiteErrorCode Column(SQLiteVirtualTableCursor cursor, SQLiteContext context, int index);
        SQLiteErrorCode RowId(SQLiteVirtualTableCursor cursor, ref long rowId);
        SQLiteErrorCode Update(SQLiteValue[] values, ref long rowId);
        SQLiteErrorCode Begin();
        SQLiteErrorCode Sync();
        SQLiteErrorCode Commit();
        SQLiteErrorCode Rollback();
        bool FindFunction(int nArg, string zName, ref SQLiteFunction function, ref IntPtr pClientData);
        SQLiteErrorCode Rename(string zNew);
        SQLiteErrorCode Savepoint(int iSavepoint);
        SQLiteErrorCode Release(int iSavepoint);
        SQLiteErrorCode RollbackTo(int iSavepoint);
    }

    ///////////////////////////////////////////////////////////////////////////
................................................................................

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

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

            return result;
        }

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

        private static UnsafeNativeMethods.sqlite3_index_info IndexFromIntPtr(
            IntPtr pIndex
            )
        {
            if (pIndex == IntPtr.Zero)
                return new UnsafeNativeMethods.sqlite3_index_info();

            return new UnsafeNativeMethods.sqlite3_index_info();
        }

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

        private static void IndexOutputsToIntPtr(
            UnsafeNativeMethods.sqlite3_index_info index,
            SQLiteIndexOutputs indexOutputs
            )
        {


        }
        #endregion

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

        #region Public Constructors
        public SQLiteModuleBase()
................................................................................
            return SQLiteErrorCode.Error;
        }

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

        public SQLiteErrorCode xBestIndex(
            IntPtr pVtab,
            IntPtr pIndex
            )
        {
            try
            {
                if (BestIndex(null) == SQLiteErrorCode.Ok)
                {
                    return SQLiteErrorCode.Ok;
                }
            }
            catch (Exception e) /* NOTE: Must catch ALL. */
            {
                SetTableError(pVtab, e.ToString());
            }

            return SQLiteErrorCode.Error;
        }

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

        public SQLiteErrorCode xDisconnect(
            IntPtr pVtab
            )
        {
................................................................................
            )
        {
            try
            {
                SQLiteFunction function = null;

                if (FindFunction(
                        nArg, StringFromUtf8IntPtr(zName), ref function,
                        ref pClientData))
                {
                    if (function != null)
                    {
                        callback = function.ScalarCallback;
                        return true;
                    }
................................................................................
        ///////////////////////////////////////////////////////////////////////

        public abstract SQLiteErrorCode Rollback();

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

        public abstract bool FindFunction(
            int nArg,
            string zName,
            ref SQLiteFunction function,
            ref IntPtr pClientData
            );

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

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

219
220
221
222
223
224
225

226
227
228
229
230
231
232
            CheckDisposed();
            throw new NotImplementedException();
        }

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

        public override bool FindFunction(

            string zName,
            ref SQLiteFunction function,
            ref IntPtr pClientData
            )
        {
            CheckDisposed();
            throw new NotImplementedException();







>







219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
            CheckDisposed();
            throw new NotImplementedException();
        }

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

        public override bool FindFunction(
            int nArg,
            string zName,
            ref SQLiteFunction function,
            ref IntPtr pClientData
            )
        {
            CheckDisposed();
            throw new NotImplementedException();

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

1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
....
1958
1959
1960
1961
1962
1963
1964

1965
1966

1967
1968
1969
1970
1971
1972
1973
    ///////////////////////////////////////////////////////////////////////////

#if !PLATFORM_COMPACTFRAMEWORK
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
#endif
    public delegate SQLiteErrorCode xBestIndex(
        IntPtr pVtab,
        IntPtr index
    );

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

#if !PLATFORM_COMPACTFRAMEWORK
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
#endif
................................................................................
    internal 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 */
    }







|







 







>


>







1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
....
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
    ///////////////////////////////////////////////////////////////////////////

#if !PLATFORM_COMPACTFRAMEWORK
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
#endif
    public delegate SQLiteErrorCode xBestIndex(
        IntPtr pVtab,
        IntPtr pIndex
    );

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

#if !PLATFORM_COMPACTFRAMEWORK
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
#endif
................................................................................
    internal 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;
        [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
        public sqlite3_index_orderby[] aOrderBy;
        /* Outputs */
        [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)]
        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 */
    }