System.Data.SQLite
Check-in [273b0c601f]
Not logged in

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

Overview
Comment:Initial phase of experimental support for implementing virtual tables in managed code. No docs, no tests, does not work yet, and may not even compile.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | virtualTables
Files: files | file ages | folders
SHA1: 273b0c601ff8c4e6b5514c4d61f7f20db0af0c4f
User & Date: mistachkin 2013-06-03 01:57:54
Context
2013-06-06
19:36
Support creating a SQLiteConnection instance from a pre-existing native connection handle (i.e. one that cannot be disposed). check-in: b6c0bcadb3 user: mistachkin tags: virtualTables
2013-06-03
01:57
Initial phase of experimental support for implementing virtual tables in managed code. No docs, no tests, does not work yet, and may not even compile. check-in: 273b0c601f user: mistachkin tags: virtualTables
2013-05-30
00:44
Add DateTimeFormatString connection string property to allow the DateTime format string used for all parsing and formatting to be overridden. Disable use of the new connection string parsing algorithm when the No_SQLiteConnectionNewParser environment variable is set. Pursuant to [bbdda6eae2]. check-in: 4f933521a1 user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added System.Data.SQLite/SQLiteModule.cs.



































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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
/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Joe Mistachkin (joe@mistachkin.com)
 *
 * Released to the public domain, use at your own risk!
 ********************************************************/

namespace System.Data.SQLite
{
    public class SQLiteModule : SQLiteModuleBase
    {
        #region IDisposable "Pattern" Members
        private bool disposed;
        private void CheckDisposed() /* throw */
        {
#if THROW_ON_DISPOSED
            if (disposed)
                throw new ObjectDisposedException(typeof(SQLiteModule).Name);
#endif
        }

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

        protected override void Dispose(bool disposing)
        {
            try
            {
                if (!disposed)
                {
                    //if (disposing)
                    //{
                    //    ////////////////////////////////////
                    //    // dispose managed resources here...
                    //    ////////////////////////////////////
                    //}

                    //////////////////////////////////////
                    // release unmanaged resources here...
                    //////////////////////////////////////

                    disposed = true;
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
        #endregion

        public override SQLiteErrorCode Create(SQLiteConnection connection, IntPtr pClientData, string[] argv, ref string error)
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Connect(SQLiteConnection connection, IntPtr pClientData, string[] argv, ref string error)
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode BestIndex(ref SQLiteIndex index)
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Disconnect()
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Destroy()
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Open(ref SQLiteVirtualTableCursor cursor)
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Close(SQLiteVirtualTableCursor cursor)
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Filter(SQLiteVirtualTableCursor cursor, int idxNum, string idxStr, SQLiteValue[] argv)
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Next(SQLiteVirtualTableCursor cursor)
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Eof(SQLiteVirtualTableCursor cursor)
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Column(SQLiteVirtualTableCursor cursor, SQLiteContext context, int index)
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode RowId(SQLiteVirtualTableCursor cursor, ref long rowId)
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Update(SQLiteValue[] values, ref long rowId)
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Begin()
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Sync()
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Commit()
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Rollback()
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode FindFunction(string zName, ref SQLiteFunction function, object[] args)
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Rename(string zNew)
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Savepoint(int iSavepoint)
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode Release(int iSavepoint)
        {
            throw new NotImplementedException();
        }

        public override SQLiteErrorCode RollbackTo(int iSavepoint)
        {
            throw new NotImplementedException();
        }
    }
}

Added System.Data.SQLite/SQLiteModuleBase.cs.

































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
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
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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Joe Mistachkin (joe@mistachkin.com)
 *
 * Released to the public domain, use at your own risk!
 ********************************************************/

using System.Runtime.InteropServices;
using System.Security;

#if !NET_40
using System.Security.Permissions;
#endif

namespace System.Data.SQLite
{




    public sealed class SQLiteContext
    {

    }

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

    public sealed class SQLiteValue
    {
    }

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

    public class SQLiteIndexConstraint
    {
        private SQLiteModuleBase.UnsafeNativeMethods.sqlite3_index_constraint constraint;
    }

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

    public class SQLiteIndexOrderBy
    {
        private SQLiteModuleBase.UnsafeNativeMethods.sqlite3_index_orderby orderBy;
    }

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

    public class SQLiteIndexConstraintUsage
    {
        private SQLiteModuleBase.UnsafeNativeMethods.sqlite3_index_constraint_usage constraintUsage;
    }

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

    public class SQLiteIndex
    {
        SQLiteIndexConstraint[] Constraints;
        SQLiteIndexOrderBy[] OrderBys;


        SQLiteIndexConstraintUsage[] ConstraintUsages;

        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 */
    }

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

    public class SQLiteVirtualTableCursor
    {
        private SQLiteModuleBase.UnsafeNativeMethods.sqlite3_vtab_cursor cursor;
    }

    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    public delegate int xFunc(
        IntPtr context,
        int argc,
        [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)]
        IntPtr[] argv
    );

    public interface ISQLiteNativeModule
    {
        SQLiteErrorCode xCreate(IntPtr db, IntPtr pAux, int argc, ref IntPtr[] argv, ref IntPtr vTab, ref IntPtr error);
        SQLiteErrorCode xConnect(IntPtr db, IntPtr pAux, int argc, ref IntPtr[] argv, ref IntPtr vTab, ref IntPtr error);
        SQLiteErrorCode xBestIndex(IntPtr vTab, IntPtr index);
        SQLiteErrorCode xDisconnect(IntPtr vTab);
        SQLiteErrorCode xDestroy(IntPtr vTab);
        SQLiteErrorCode xOpen(IntPtr vTab, ref IntPtr cursor);
        SQLiteErrorCode xClose(IntPtr cursor);
        SQLiteErrorCode xFilter(IntPtr cursor, int idxNum, IntPtr idxStr, int argc, IntPtr[] argv);
        SQLiteErrorCode xNext(IntPtr cursor);
        SQLiteErrorCode xEof(IntPtr cursor);
        SQLiteErrorCode xColumn(IntPtr cursor, IntPtr context, int index);
        SQLiteErrorCode xRowId(IntPtr cursor, ref long rowId);
        SQLiteErrorCode xUpdate(IntPtr vtab, int nData, ref IntPtr apData, ref long rowId);
        SQLiteErrorCode xBegin(IntPtr vtab);
        SQLiteErrorCode xSync(IntPtr vtab);
        SQLiteErrorCode xCommit(IntPtr vtab);
        SQLiteErrorCode xRollback(IntPtr vtab);
        SQLiteErrorCode xFindFunction(IntPtr pVtab, int nArg, IntPtr zName, ref xFunc pxFunc, ref IntPtr ppArg);
        SQLiteErrorCode xRename(IntPtr pVtab, IntPtr zNew);
        SQLiteErrorCode xSavepoint(IntPtr pVtab, int iSavepoint);
        SQLiteErrorCode xRelease(IntPtr pVtab, int iSavepoint);
        SQLiteErrorCode xRollbackTo(IntPtr pVtab, int iSavepoint);
    }

    public interface ISQLiteManagedModule
    {
        SQLiteErrorCode Create(SQLiteConnection connection, IntPtr pClientData, string[] argv, ref string error);
        SQLiteErrorCode Connect(SQLiteConnection connection, IntPtr pClientData, string[] argv, ref string error);
        SQLiteErrorCode BestIndex(ref SQLiteIndex index);
        SQLiteErrorCode Disconnect();
        SQLiteErrorCode Destroy();
        SQLiteErrorCode Open(ref SQLiteVirtualTableCursor cursor);
        SQLiteErrorCode Close(SQLiteVirtualTableCursor cursor);
        SQLiteErrorCode Filter(SQLiteVirtualTableCursor cursor, int idxNum, string idxStr, SQLiteValue[] argv);
        SQLiteErrorCode Next(SQLiteVirtualTableCursor cursor);
        SQLiteErrorCode Eof(SQLiteVirtualTableCursor cursor);
        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();
        SQLiteErrorCode FindFunction(string zName, ref SQLiteFunction function, object[] args);
        SQLiteErrorCode Rename(string zNew);
        SQLiteErrorCode Savepoint(int iSavepoint);
        SQLiteErrorCode Release(int iSavepoint);
        SQLiteErrorCode RollbackTo(int iSavepoint);
    }

#if NET_40
    [SecurityCritical()]
#else
    [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
#endif
    public abstract class SQLiteModuleBase : ISQLiteManagedModule, ISQLiteNativeModule,  IDisposable
    {
        #region Unsafe Native Methods Class
        [SuppressUnmanagedCodeSecurity()]
        internal static class UnsafeNativeMethods
        {
            // https://www.sqlite.org/vtab.html


            [StructLayout(LayoutKind.Sequential)]
            public struct sqlite3_module
            {
                public int iVersion;
                public xCreate xCreate;
                public xConnect xConnect;
                public xBestIndex xBestIndex;
                public xDisconnect xDisconnect;
                public xDestroy xDestroy;
                public xOpen xOpen;
                public xClose xClose;
                public xFilter xFilter;
                public xNext xNext;
                public xEof xEof;
                public xColumn xColumn;
                public xRowId xRowId;
                public xUpdate xUpdate;
                public xBegin xBegin;
                public xSync xSync;
                public xCommit xCommit;
                public xRollback xRollback;
                public xFindFunction xFindFunction;
                public xRename xRename;
                /* The methods above are in version 1 of the sqlite3_module
                 * object.  Those below are for version 2 and greater. */
                public xSavepoint xSavepoint;
                public xRelease xRelease;
                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)]
            public delegate SQLiteErrorCode xCreate(
                IntPtr db,
                IntPtr pAux,
                int argc,
                [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
                ref IntPtr[] argv,
                ref IntPtr vTab,
                ref IntPtr error
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xConnect(
                IntPtr db,
                IntPtr pAux,
                int argc,
                [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
                ref IntPtr[] argv,
                ref IntPtr vTab,
                ref IntPtr error
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xBestIndex(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr vTab,
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr index
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xDisconnect(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr vTab
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xDestroy(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr vTab
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xOpen(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr vTab,
                ref IntPtr cursor
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xClose(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr cursor
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xFilter(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr cursor,
                int idxNum,
                IntPtr idxStr,
                int argc,
                IntPtr[] argv
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xNext(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr cursor
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xEof(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr cursor
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xColumn(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr cursor,
                IntPtr context,
                int index
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xRowId(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr cursor,
                ref long rowId
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xUpdate(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr vtab,
                int nData,
                ref IntPtr apData,
                ref long rowId
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xBegin(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr vtab
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xSync(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr vtab
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xCommit(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr vtab
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xRollback(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr vtab
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xFindFunction(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr pVtab,
                int nArg,
                IntPtr zName,
                ref xFunc pxFunc,
                ref IntPtr ppArg
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xRename(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr pVtab,
                IntPtr zNew
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xSavepoint(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr pVtab,
                int iSavepoint
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xRelease(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr pVtab,
                int iSavepoint
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate SQLiteErrorCode xRollbackTo(
                [MarshalAs(UnmanagedType.LPStruct)]
                IntPtr pVtab,
                int iSavepoint
            );

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public delegate void xDestroyModule(
                IntPtr pClientData
            );

            private static readonly int SQLITE_INDEX_CONSTRAINT_EQ = 2;
            private static readonly int SQLITE_INDEX_CONSTRAINT_GT = 4;
            private static readonly int SQLITE_INDEX_CONSTRAINT_LE = 8;
            private static readonly int SQLITE_INDEX_CONSTRAINT_LT = 16;
            private static readonly int SQLITE_INDEX_CONSTRAINT_GE = 32;
            private static readonly int SQLITE_INDEX_CONSTRAINT_MATCH = 64;

            [DllImport("sqlite3", CallingConvention = CallingConvention.Cdecl)]
            internal static extern void sqlite3_create_module_v2(
                IntPtr db,
                IntPtr name,
                IntPtr pModule,
                IntPtr pClientData,
                xDestroyModule xDestroy
                );

            [DllImport("sqlite3", CallingConvention = CallingConvention.Cdecl)]
            internal static extern SQLiteErrorCode sqlite3_declare_vtab(IntPtr db, IntPtr zSQL);

            [DllImport("sqlite3", CallingConvention = CallingConvention.Cdecl)]
            internal static extern IntPtr sqlite3_mprintf(IntPtr format, __arglist);
        }
        #endregion

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

        #region Private Data
        private IntPtr database;
        #endregion

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

        private UnsafeNativeMethods.sqlite3_module CreateNativeModule()
        {
            UnsafeNativeMethods.sqlite3_module module =
                new UnsafeNativeMethods.sqlite3_module();

            module.iVersion = 2;
            module.xCreate = new UnsafeNativeMethods.xCreate(xCreate);
            module.xConnect = new UnsafeNativeMethods.xConnect(xConnect);
            module.xBestIndex = new UnsafeNativeMethods.xBestIndex(xBestIndex);
            module.xDisconnect = new UnsafeNativeMethods.xDisconnect(xDisconnect);
            module.xDestroy = new UnsafeNativeMethods.xDestroy(xDestroy);
            module.xOpen = new UnsafeNativeMethods.xOpen(xOpen);
            module.xClose = new UnsafeNativeMethods.xClose(xClose);
            module.xFilter = new UnsafeNativeMethods.xFilter(xFilter);
            module.xNext = new UnsafeNativeMethods.xNext(xNext);
            module.xEof = new UnsafeNativeMethods.xEof(xEof);
            module.xColumn = new UnsafeNativeMethods.xColumn(xColumn);
            module.xRowId = new UnsafeNativeMethods.xRowId(xRowId);
            module.xUpdate = new UnsafeNativeMethods.xUpdate(xUpdate);
            module.xBegin = new UnsafeNativeMethods.xBegin(xBegin);
            module.xSync = new UnsafeNativeMethods.xSync(xSync);
            module.xCommit = new UnsafeNativeMethods.xCommit(xCommit);
            module.xRollback = new UnsafeNativeMethods.xRollback(xRollback);
            module.xFindFunction = new UnsafeNativeMethods.xFindFunction(xFindFunction);
            module.xRename = new UnsafeNativeMethods.xRename(xRename);
            module.xSavepoint = new UnsafeNativeMethods.xSavepoint(xSavepoint);
            module.xRelease = new UnsafeNativeMethods.xRelease(xRelease);
            module.xRollbackTo = new UnsafeNativeMethods.xRollbackTo(xRollbackTo);

            IntPtr foo = IntPtr.Zero;

            Marshal.PtrToStructure(foo, typeof(UnsafeNativeMethods.sqlite3_module));

            return module;
        }

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

        public SQLiteModuleBase()
        {

        }

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

        public SQLiteErrorCode xCreate(
            IntPtr db,
            IntPtr pAux,
            int argc,
            ref IntPtr[] argv,
            ref IntPtr vTab,
            ref IntPtr error
            )
        {
            return SQLiteErrorCode.Ok;
        }

        public SQLiteErrorCode xConnect(
            IntPtr db,
            IntPtr pAux,
            int argc,
            ref IntPtr[] argv,
            ref IntPtr vTab,
            ref IntPtr error
        )
        {
            return SQLiteErrorCode.Ok;
        }

        public SQLiteErrorCode xBestIndex(
            IntPtr vTab,
            IntPtr index
        )
        {
            return SQLiteErrorCode.Ok;
        }


        public SQLiteErrorCode xDisconnect(
                IntPtr vTab
        )
        {
            return SQLiteErrorCode.Ok;
        }


        public SQLiteErrorCode xDestroy(
                IntPtr vTab
        )
        {
            return SQLiteErrorCode.Ok;
        }


        public SQLiteErrorCode xOpen(
            IntPtr vTab,
            ref IntPtr cursor
        )
        {
            return SQLiteErrorCode.Ok;
        }


        public SQLiteErrorCode xClose(
                IntPtr cursor
        )
        {
            return SQLiteErrorCode.Ok;
        }


        public SQLiteErrorCode xFilter(
            IntPtr cursor,
            int idxNum,
            IntPtr idxStr,
            int argc,
            IntPtr[] argv
        )
        {
            return SQLiteErrorCode.Ok;
        }


        public SQLiteErrorCode xNext(
            IntPtr cursor
        )
        {
            return SQLiteErrorCode.Ok;
        }


        public SQLiteErrorCode xEof(
                IntPtr cursor
        )
        {
            return SQLiteErrorCode.Ok;
        }


        public SQLiteErrorCode xColumn(
            IntPtr cursor,
            IntPtr context,
            int index
        )
        {
            return SQLiteErrorCode.Ok;
        }


        public SQLiteErrorCode xRowId(
            IntPtr cursor,
            ref long rowId
        )
        {
            return SQLiteErrorCode.Ok;
        }


        public SQLiteErrorCode xUpdate(
            IntPtr vtab,
            int nData,
            ref IntPtr apData,
            ref long rowId
        )
        {
            return SQLiteErrorCode.Ok;
        }

        public SQLiteErrorCode xBegin(
            IntPtr vtab
        )
        {
            return SQLiteErrorCode.Ok;
        }


        public SQLiteErrorCode xSync(
            IntPtr vtab
        )
        {
            return SQLiteErrorCode.Ok;
        }

        public SQLiteErrorCode xCommit(
            IntPtr vtab
        )
        {
            return SQLiteErrorCode.Ok;
        }


        public SQLiteErrorCode xRollback(
            IntPtr vtab
        )
        {
            return SQLiteErrorCode.Ok;
        }


        public SQLiteErrorCode xFindFunction(
            IntPtr pVtab,
            int nArg,
            IntPtr zName,
            ref xFunc pxFunc,
            ref IntPtr ppArg
        )
        {
            return SQLiteErrorCode.Ok;
        }


        public SQLiteErrorCode xRename(
            IntPtr pVtab,
            IntPtr zNew
        )
        {
            return SQLiteErrorCode.Ok;
        }


        public SQLiteErrorCode xSavepoint(
            IntPtr pVtab,
            int iSavepoint
        )
        {
            return SQLiteErrorCode.Ok;
        }


        public SQLiteErrorCode xRelease(
            IntPtr pVtab,
            int iSavepoint
        )
        {
            return SQLiteErrorCode.Ok;
        }

        public SQLiteErrorCode xRollbackTo(
            IntPtr pVtab,
            int iSavepoint
        )
        {
            return SQLiteErrorCode.Ok;
        }

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

        public abstract SQLiteErrorCode Create(SQLiteConnection connection, IntPtr pClientData, string[] argv, ref string error);
        public abstract SQLiteErrorCode Connect(SQLiteConnection connection, IntPtr pClientData, string[] argv, ref string error);
        public abstract SQLiteErrorCode BestIndex(ref SQLiteIndex index);
        public abstract SQLiteErrorCode Disconnect();
        public abstract SQLiteErrorCode Destroy();

        public abstract SQLiteErrorCode Open(ref SQLiteVirtualTableCursor cursor);
        public abstract SQLiteErrorCode Close(SQLiteVirtualTableCursor cursor);
        public abstract SQLiteErrorCode Filter(SQLiteVirtualTableCursor cursor, int idxNum, string idxStr, SQLiteValue[] values);
        public abstract SQLiteErrorCode Next(SQLiteVirtualTableCursor cursor);
        public abstract SQLiteErrorCode Eof(SQLiteVirtualTableCursor cursor);

        public abstract SQLiteErrorCode Column(SQLiteVirtualTableCursor cursor, SQLiteContext context, int index);
        public abstract SQLiteErrorCode RowId(SQLiteVirtualTableCursor cursor, ref long rowId);

        public abstract SQLiteErrorCode Update(SQLiteValue[] values, ref long rowId);

        public abstract SQLiteErrorCode Begin();
        public abstract SQLiteErrorCode Sync();
        public abstract SQLiteErrorCode Commit();
        public abstract SQLiteErrorCode Rollback();

        public abstract SQLiteErrorCode FindFunction(string zName, ref SQLiteFunction function, object[] args);

        public abstract SQLiteErrorCode Rename(string zNew);

        public abstract SQLiteErrorCode Savepoint(int iSavepoint);
        public abstract SQLiteErrorCode Release(int iSavepoint);
        public abstract SQLiteErrorCode RollbackTo(int iSavepoint);

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

        #region IDisposable Members
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        #endregion

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

        #region IDisposable "Pattern" Members
        private bool disposed;
        private void CheckDisposed() /* throw */
        {
#if THROW_ON_DISPOSED
            if (disposed)
                throw new ObjectDisposedException(typeof(SQLiteModuleBase).Name);
#endif
        }

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

        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                //if (disposing)
                //{
                //    ////////////////////////////////////
                //    // dispose managed resources here...
                //    ////////////////////////////////////
                //}

                //////////////////////////////////////
                // release unmanaged resources here...
                //////////////////////////////////////

                disposed = true;
            }
        }
        #endregion

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

        #region Destructor
        ~SQLiteModuleBase()
        {
            Dispose(false);
        }
        #endregion
    }
}

Changes to System.Data.SQLite/System.Data.SQLite.Files.targets.

64
65
66
67
68
69
70


71
72
73
74
75
76
77
  ******************************************************************************
  **                        Core Files (Full Framework)                       **
  ******************************************************************************
  -->

  <ItemGroup Condition="'$(IsCompactFramework)' == 'false'">
    <Compile Include="SQLiteEnlistment.cs" />


    <Compile Condition="'$(NetFx35)' != 'false' Or
                        '$(NetFx40)' != 'false' Or
                        '$(NetFx45)' != 'false'"
             Include="LINQ\SQLiteConnection_Linq.cs">
      <SubType>Component</SubType>
    </Compile>
    <Compile Condition="'$(NetFx35)' != 'false' Or







>
>







64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  ******************************************************************************
  **                        Core Files (Full Framework)                       **
  ******************************************************************************
  -->

  <ItemGroup Condition="'$(IsCompactFramework)' == 'false'">
    <Compile Include="SQLiteEnlistment.cs" />
    <Compile Include="SQLiteModule.cs" />
    <Compile Include="SQLiteModuleBase.cs" />
    <Compile Condition="'$(NetFx35)' != 'false' Or
                        '$(NetFx40)' != 'false' Or
                        '$(NetFx45)' != 'false'"
             Include="LINQ\SQLiteConnection_Linq.cs">
      <SubType>Component</SubType>
    </Compile>
    <Compile Condition="'$(NetFx35)' != 'false' Or