-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathVdbeInt_h.cs
More file actions
executable file
·1036 lines (1000 loc) · 29.6 KB
/
VdbeInt_h.cs
File metadata and controls
executable file
·1036 lines (1000 loc) · 29.6 KB
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
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
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
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using FILE = System.IO.TextWriter;
using i64 = System.Int64;
using u8 = System.Byte;
using u16 = System.UInt16;
using u32 = System.UInt32;
using u64 = System.UInt64;
using unsigned = System.UIntPtr;
using Pgno = System.UInt32;
#if !SQLITE_MAX_VARIABLE_NUMBER
using ynVar = System.Int16;
#else
using ynVar = System.Int32;
#endif
/*
** The yDbMask datatype for the bitmask of all attached databases.
*/
#if SQLITE_MAX_ATTACHED//>30
// typedef sqlite3_uint64 yDbMask;
using yDbMask = System.Int64;
#else
// typedef unsigned int yDbMask;
using yDbMask = System.Int32;
#endif
namespace System.Data.SQLite
{
using Op = Sqlite3.VdbeOp;
public partial class Sqlite3
{
/*
** 2003 September 6
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This is the header file for information that is private to the
** VDBE. This information used to all be at the top of the single
** source code file "vdbe.c". When that file became too big (over
** 6000 lines long) it was split up into several smaller files and
** this header information was factored out.
*************************************************************************
** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart
** C#-SQLite is an independent reimplementation of the SQLite software library
**
** SQLITE_SOURCE_ID: 2011-06-23 19:49:22 4374b7e83ea0a3fbc3691f9c0c936272862f32f2
**
*************************************************************************
*/
//#if !_VDBEINT_H_
//#define _VDBEINT_H_
/// <summary>
/// A cursor is a pointer into a single BTree within a database file.
/// The cursor can seek to a BTree entry with a particular key, or
/// loop over all entries of the Btree. You can also insert new BTree
/// entries or retrieve the key or data from the entry that the cursor
/// is currently pointing to.
///
/// Every cursor that the virtual machine has open is represented by an
/// instance of the following structure
/// </summary>
public class VdbeCursor
{
/// <summary>
/// The cursor structure of the backend
/// </summary>
public BtCursor pCursor;
/// <summary>
/// Separate file holding temporary table
/// </summary>
public Btree pBt;
/// <summary>
/// Info about index keys needed by index cursors
/// </summary>
public KeyInfo pKeyInfo;
/// <summary>
/// Index of cursor database in db->aDb[] (or -1)
/// </summary>
public int iDb;
/// <summary>
/// Register holding pseudotable content.
/// </summary>
public int pseudoTableReg;
/// <summary>
/// Number of fields in the header
/// </summary>
public int nField;
/// <summary>
/// True if zeroed out and ready for reuse
/// </summary>
public bool zeroed;
/// <summary>
/// True if lastRowid is valid
/// </summary>
public bool rowidIsValid;
/// <summary>
/// True if pointing to first entry
/// </summary>
public bool atFirst;
/// <summary>
/// Generate new record numbers semi-randomly
/// </summary>
public bool useRandomRowid;
/// <summary>
/// True if pointing to a row with no data
/// </summary>
public bool nullRow;
/// <summary>
/// A call to sqlite3BtreeMoveto() is needed
/// </summary>
public bool deferredMoveto;
/// <summary>
/// True if a table requiring integer keys
/// </summary>
public bool isTable;
/// <summary>
/// True if an index containing keys only - no data
/// </summary>
public bool isIndex;
/// <summary>
/// True if the underlying table is BTREE_UNORDERED
/// </summary>
public bool isOrdered;
#if !SQLITE_OMIT_VIRTUALTABLE
/// <summary>
/// The cursor for a virtual table
/// </summary>
public sqlite3_vtab_cursor pVtabCursor;
/// <summary>
/// Module for cursor pVtabCursor
/// </summary>
public sqlite3_module pModule;
#endif
/// <summary>
/// Sequence counter
/// </summary>
public i64 seqCount;
/// <summary>
/// Argument to the deferred sqlite3BtreeMoveto()
/// </summary>
public i64 movetoTarget;
/// <summary>
/// Last rowid from a Next or NextIdx operation
/// </summary>
public i64 lastRowid;
/// <summary>
/// Result of last sqlite3BtreeMoveto() done by an OP_NotExists or OP_IsUnique opcode on this cursor.
/// </summary>
public int seekResult;
/* Cached information about the header for the data record that the
** cursor is currently pointing to. Only valid if cacheStatus matches
** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
** the cache is out of date.
**
** aRow might point to (ephemeral) data for the current row, or it might
** be NULL.
*/
/// <summary>
/// Cache is valid if this matches Vdbe.cacheCtr
/// </summary>
public u32 cacheStatus;
/// <summary>
/// Total number of bytes in the record
/// </summary>
public Pgno payloadSize;
/// <summary>
/// Type values for all entries in the record
/// </summary>
public u32[] aType;
/// <summary>
/// Cached offsets to the start of each columns data
/// </summary>
public u32[] aOffset;
/// <summary>
/// Pointer to Data for the current row, if all on one page
/// </summary>
public int aRow;
public VdbeCursor Copy()
{
return (VdbeCursor)MemberwiseClone();
}
};
/// <summary>
/// When a sub-program is executed (OP_Program), a structure of this type
/// is allocated to store the current value of the program counter, as
/// well as the current memory cell array and various other frame specific
/// values stored in the Vdbe struct. When the sub-program is finished,
/// these values are copied back to the Vdbe from the VdbeFrame structure,
/// restoring the state of the VM to as it was before the sub-program
/// began executing.
///
/// The memory for a VdbeFrame object is allocated and managed by a memory
/// cell in the parent (calling) frame. When the memory cell is deleted or
/// overwritten, the VdbeFrame object is not freed immediately. Instead, it
/// is linked into the Vdbe.pDelFrame list. The contents of the Vdbe.pDelFrame
/// list is deleted when the VM is reset in VdbeHalt(). The reason for doing
/// this instead of deleting the VdbeFrame immediately is to avoid recursive
/// calls to sqlite3VdbeMemRelease() when the memory cells belonging to the
/// child frame are released.
///
/// The currently executing frame is stored in Vdbe.pFrame. Vdbe.pFrame is
/// set to NULL if the currently executing frame is the main program
/// </summary>
public class VdbeFrame
{
/// <summary>
/// VM this frame belongs to
/// </summary>
public Vdbe v;
/// <summary>
/// Program Counter in parent (calling) frame
/// </summary>
public int pc;
/// <summary>
/// Program instructions for parent frame
/// </summary>
public Op[] aOp;
/// <summary>
/// Size of aOp array
/// </summary>
public int nOp;
/// <summary>
/// Array of memory cells for parent frame
/// </summary>
public Mem[] aMem;
/// <summary>
/// Number of entries in aMem
/// </summary>
public int nMem;
/// <summary>
/// Array of Vdbe cursors for parent frame
/// </summary>
public VdbeCursor[] apCsr;
/// <summary>
/// Number of entries in apCsr
/// </summary>
public u16 nCursor;
/// <summary>
/// Copy of SubProgram.token
/// </summary>
public int token;
/// <summary>
/// Number of memory cells for child frame
/// </summary>
public int nChildMem;
/// <summary>
/// Number of cursors for child frame
/// </summary>
public int nChildCsr;
/// <summary>
/// Last insert rowid (sqlite3.lastRowid)
/// </summary>
public i64 lastRowid;
/// <summary>
/// Statement changes (Vdbe.nChanges)
/// </summary>
public int nChange;
/// <summary>
/// Parent of this frame, or NULL if parent is main
/// </summary>
public VdbeFrame pParent;
/// <summary>
/// Array of memory cells for child frame
/// </summary>
public Mem[] aChildMem;
/// <summary>
/// Array of cursors for child frame
/// </summary>
public VdbeCursor[] aChildCsr;
};
/*
** A value for VdbeCursor.cacheValid that means the cache is always invalid.
*/
const int CACHE_STALE = 0;
/// <summary>
/// Internally, the vdbe manipulates nearly all SQL values as Mem
/// structures. Each Mem struct may cache multiple representations (string,
/// integer etc.) of the same value
/// </summary>
public class Mem
{
/// <summary>
/// The associated database connection
/// </summary>
public sqlite3 db;
/// <summary>
/// String value
/// </summary>
public string z;
/// <summary>
/// Real value
/// </summary>
public double r;
public struct union_ip
{
#if DEBUG_CLASS_MEM || DEBUG_CLASS_ALL
/// <summary>
/// First operand
/// </summary>
public i64 _i;
public i64 i
{
get { return _i; }
set { _i = value; }
}
#else
/// <summary>
/// Integer value used when MEM_Int is set in flags
/// </summary>
public i64 i;
#endif
/// <summary>
/// Used when bit MEM_Zero is set in flags
/// </summary>
public int nZero;
/// <summary>
/// Used only when flags==MEM_Agg
/// </summary>
public FuncDef pDef;
/// <summary>
/// Used only when flags==MEM_RowSet
/// </summary>
public RowSet pRowSet;
/// <summary>
/// Used when flags==MEM_Frame
/// </summary>
public VdbeFrame pFrame;
};
public union_ip u;
/// <summary>
/// BLOB value
/// </summary>
public byte[] zBLOB;
/// <summary>
/// Number of characters in string value, excluding '\0'
/// </summary>
public int n;
#if DEBUG_CLASS_MEM || DEBUG_CLASS_ALL
/// <summary>
/// First operand
/// </summary>
public u16 _flags;
public u16 flags
{
get { return _flags; }
set { _flags = value; }
}
#else
/// <summary>
/// Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc.
/// </summary>
public u16 flags;
#endif
/// <summary>
/// One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc
/// </summary>
public u8 type;
/// <summary>
/// SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE
/// </summary>
public u8 enc;
#if SQLITE_DEBUG
/// <summary>
/// This Mem is a shallow copy of pScopyFrom
/// </summary>
public Mem pScopyFrom;
/// <summary>
/// So that sizeof(Mem) is a multiple of 8
/// </summary>
public object pFiller;
#endif
/// <summary>
/// If not null, call this function to delete Mem.z
/// </summary>
public dxDel xDel;
/// <summary>
/// Used when C# overload Z as MEM space
/// </summary>
public Mem _Mem;
/// <summary>
/// Used when C# overload Z as Sum context
/// </summary>
public SumCtx _SumCtx;
/// <summary>
/// Used when C# overload Z as SubProgram
/// </summary>
public SubProgram[] _SubProgram;
/// <summary>
/// Used when C# overload Z as STR context
/// </summary>
public StrAccum _StrAccum;
/// <summary>
/// Used when C# overload Z as MD5 context
/// </summary>
public object _MD5Context;
public Mem()
{
}
public Mem(sqlite3 db, string z, double r, int i, int n, u16 flags, u8 type, u8 enc
#if SQLITE_DEBUG
, Mem pScopyFrom, object pFiller /* pScopyFrom, pFiller */
#endif
)
{
this.db = db;
this.z = z;
this.r = r;
this.u.i = i;
this.n = n;
this.flags = flags;
#if SQLITE_DEBUG
this.pScopyFrom = pScopyFrom;
this.pFiller = pFiller;
#endif
this.type = type;
this.enc = enc;
}
public void CopyTo(ref Mem ct)
{
if (ct == null)
ct = new Mem();
ct.u = u;
ct.r = r;
ct.db = db;
ct.z = z;
if (zBLOB == null)
ct.zBLOB = null;
else
{
ct.zBLOB = sqlite3Malloc(zBLOB.Length);
Buffer.BlockCopy(zBLOB, 0, ct.zBLOB, 0, zBLOB.Length);
}
ct.n = n;
ct.flags = flags;
ct.type = type;
ct.enc = enc;
ct.xDel = xDel;
}
};
/* One or more of the following flags are set to indicate the validOK
** representations of the value stored in the Mem struct.
**
** If the MEM_Null flag is set, then the value is an SQL NULL value.
** No other flags may be set in this case.
**
** If the MEM_Str flag is set then Mem.z points at a string representation.
** Usually this is encoded in the same unicode encoding as the main
** database (see below for exceptions). If the MEM_Term flag is also
** set, then the string is nul terminated. The MEM_Int and MEM_Real
** flags may coexist with the MEM_Str flag.
*/
//#define MEM_Null 0x0001 /* Value is NULL */
//#define MEM_Str 0x0002 /* Value is a string */
//#define MEM_Int 0x0004 /* Value is an integer */
//#define MEM_Real 0x0008 /* Value is a real number */
//#define MEM_Blob 0x0010 /* Value is a BLOB */
//#define MEM_RowSet 0x0020 /* Value is a RowSet object */
//#define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
//#define MEM_Invalid 0x0080 /* Value is undefined */
//#define MEM_TypeMask 0x00ff /* Mask of type bits */
const int MEM_Null = 0x0001;
const int MEM_Str = 0x0002;
const int MEM_Int = 0x0004;
const int MEM_Real = 0x0008;
const int MEM_Blob = 0x0010;
const int MEM_RowSet = 0x0020;
const int MEM_Frame = 0x0040;
const int MEM_Invalid = 0x0080;
const int MEM_TypeMask = 0x00ff;
/* Whenever Mem contains a valid string or blob representation, one of
** the following flags must be set to determine the memory management
** policy for Mem.z. The MEM_Term flag tells us whether or not the
** string is \000 or \u0000 terminated
// */
//#define MEM_Term 0x0200 /* String rep is nul terminated */
//#define MEM_Dyn 0x0400 /* Need to call sqliteFree() on Mem.z */
//#define MEM_Static 0x0800 /* Mem.z points to a static string */
//#define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
//#define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
//#define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
//#if SQLITE_OMIT_INCRBLOB
// #undef MEM_Zero
// #define MEM_Zero 0x0000
//#endif
const int MEM_Term = 0x0200;
const int MEM_Dyn = 0x0400;
const int MEM_Static = 0x0800;
const int MEM_Ephem = 0x1000;
const int MEM_Agg = 0x2000;
#if !SQLITE_OMIT_INCRBLOB
const int MEM_Zero = 0x4000;
#else
const int MEM_Zero = 0x0000;
#endif
/*
** Clear any existing type flags from a Mem and replace them with f
*/
//#define MemSetTypeFlag(p, f) \
// ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
static void MemSetTypeFlag(Mem p, int f)
{
p.flags = (u16)(p.flags & ~(MEM_TypeMask | MEM_Zero) | f);
}// TODO -- Convert back to inline for speed
/*
** Return true if a memory cell is not marked as invalid. This macro
** is for use inside Debug.Assert() statements only.
*/
#if SQLITE_DEBUG
//#define memIsValid(M) ((M)->flags & MEM_Invalid)==0
static bool memIsValid( Mem M )
{
return ( ( M ).flags & MEM_Invalid ) == 0;
}
#else
static bool memIsValid(Mem M) { return true; }
#endif
/* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
** additional information about auxiliary information bound to arguments
** of the function. This is used to implement the sqlite3_get_auxdata()
** and sqlite3_set_auxdata() APIs. The "auxdata" is some auxiliary data
** that can be associated with a constant argument to a function. This
** allows functions such as "regexp" to compile their constant regular
** expression argument once and reused the compiled code for multiple
** invocations.
*/
public class AuxData
{
/// <summary>
/// Aux data for the i-th argument
/// </summary>
public object pAux;
};
public class VdbeFunc : FuncDef
{
/// <summary>
/// The definition of the function
/// </summary>
public FuncDef pFunc;
/// <summary>
/// Number of entries allocated for apAux[]
/// </summary>
public int nAux;
/// <summary>
/// One slot for each function argument
/// </summary>
public AuxData[] apAux = new AuxData[2];
};
/// <summary>
/// The "context" argument for a installable function. A pointer to an
/// instance of this structure is the first argument to the routines used
/// implement the SQL functions.
///
/// There is a typedef for this structure in sqlite.h. So all routines,
/// even the public interface to SQLite, can use a pointer to this structure.
/// But this file is the only place where the internal details of this
/// structure are known.
///
/// This structure is defined inside of vdbeInt.h because it uses substructures
/// (Mem) which are only defined there
/// </summary>
public class sqlite3_context
{
/// <summary>
/// Pointer to function information. MUST BE FIRST
/// </summary>
public FuncDef pFunc;
/// <summary>
/// Auxilary data, if created.
/// </summary>
public VdbeFunc pVdbeFunc;
/// <summary>
/// The return value is stored here
/// </summary>
public Mem s = new Mem();
/// <summary>
/// Memory cell used to store aggregate context
/// </summary>
public Mem pMem;
/// <summary>
/// Error code returned by the function.
/// </summary>
public int isError;
/// <summary>
/// Collating sequence
/// </summary>
public CollSeq pColl;
};
/// <summary>
/// An instance of the virtual machine. This structure contains the complete
/// state of the virtual machine.
///
/// The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
/// is really a pointer to an instance of this structure.
///
/// The Vdbe.inVtabMethod variable is set to non-zero for the duration of
/// any virtual table method invocations made by the vdbe program. It is
/// set to 2 for xDestroy method calls and 1 for all other methods. This
/// variable is used for two purposes: to allow xDestroy methods to execute
/// "DROP TABLE" statements and to prevent some nasty side effects of
/// malloc failure when SQLite is invoked recursively by a virtual table
/// method function
/// </summary>
public class Vdbe
{
/// <summary>
/// The database connection that owns this statement
/// </summary>
public sqlite3 db;
/// <summary>
/// Space to hold the virtual machine's program
/// </summary>
public Op[] aOp;
/// <summary>
/// The memory locations
/// </summary>
public Mem[] aMem;
/// <summary>
/// Arguments to currently executing user function
/// </summary>
public Mem[] apArg;
/// <summary>
/// Column names to return
/// </summary>
public Mem[] aColName;
/// <summary>
/// Pointer to an array of results
/// </summary>
public Mem[] pResultSet;
/// <summary>
/// Number of memory locations currently allocated
/// </summary>
public int nMem;
/// <summary>
/// Number of instructions in the program
/// </summary>
public int nOp;
/// <summary>
/// Number of slots allocated for aOp[]
/// </summary>
public int nOpAlloc;
/// <summary>
/// Number of labels used
/// </summary>
public int nLabel;
/// <summary>
/// Number of slots allocated in aLabel[]
/// </summary>
public int nLabelAlloc;
/// <summary>
/// Space to hold the labels
/// </summary>
public int[] aLabel;
/// <summary>
/// Number of columns in one row of the result set
/// </summary>
public u16 nResColumn;
/// <summary>
/// Number of slots in apCsr[]
/// </summary>
public u16 nCursor;
/// <summary>
/// Magic number for sanity checking
/// </summary>
public u32 magic;
/// <summary>
/// Error message written here
/// </summary>
public string zErrMsg;
/// <summary>
/// Linked list of VDBEs with the same Vdbe.db
/// </summary>
public Vdbe pPrev;
/// <summary>
/// Linked list of VDBEs with the same Vdbe.db
/// </summary>
public Vdbe pNext;
/// <summary>
/// One element of this array for each open cursor
/// </summary>
public VdbeCursor[] apCsr;
/// <summary>
/// Values for the OP_Variable opcode.
/// </summary>
public Mem[] aVar;
/// <summary>
/// Name of variables
/// </summary>
public string[] azVar;
/// <summary>
/// Number of entries in aVar[]
/// </summary>
public ynVar nVar;
/// <summary>
/// Number of entries in azVar[]
/// </summary>
public ynVar nzVar;
/// <summary>
/// VdbeCursor row cache generation counter
/// </summary>
public u32 cacheCtr;
/// <summary>
/// The program counter
/// </summary>
public int pc;
/// <summary>
/// Value to return
/// </summary>
public int rc;
/// <summary>
/// Recovery action to do in case of an error
/// </summary>
public u8 errorAction;
/// <summary>
/// True if EXPLAIN present on SQL command
/// </summary>
public int explain;
/// <summary>
/// True to update the change-counter
/// </summary>
public bool changeCntOn;
/// <summary>
/// True if the VM needs to be recompiled
/// </summary>
public bool expired;
/// <summary>
/// Automatically expire on reset
/// </summary>
public u8 runOnlyOnce;
/// <summary>
/// Minimum file format for writable database files
/// </summary>
public int minWriteFileFormat;
/// <summary>
/// See comments above
/// </summary>
public int inVtabMethod;
/// <summary>
/// True if uses a statement journal
/// </summary>
public bool usesStmtJournal;
/// <summary>
/// True for read-only statements
/// </summary>
public bool readOnly;
/// <summary>
/// Number of db changes made since last reset
/// </summary>
public int nChange;
/// <summary>
/// True if prepared with prepare_v2()
/// </summary>
public bool isPrepareV2;
/// <summary>
/// Bitmask of db.aDb[] entries referenced
/// </summary>
public yDbMask btreeMask;
/// <summary>
/// Subset of btreeMask that requires a lock
/// </summary>
public yDbMask lockMask;
/// <summary>
/// Statement number (or 0 if has not opened stmt)
/// </summary>
public int iStatement;
/// <summary>
/// Counters used by sqlite3_stmt_status()
/// </summary>
public int[] aCounter = new int[3];
#if !SQLITE_OMIT_TRACE
/// <summary>
/// Time when query started - used for profiling
/// </summary>
public i64 startTime;
#endif
/// <summary>
/// Number of imm. FK constraints this VM
/// </summary>
public i64 nFkConstraint;
/// <summary>
/// Number of def. constraints when stmt started
/// </summary>
public i64 nStmtDefCons;
/// <summary>
/// Text of the SQL statement that generated this
/// </summary>
public string zSql = "";
/// <summary>
/// Free this when deleting the vdbe
/// </summary>
public object pFree;
#if SQLITE_DEBUG
/// <summary>
/// Write an execution trace here, if not NULL
/// </summary>
public FILE trace;
#endif
/// <summary>
/// Parent frame
/// </summary>
public VdbeFrame pFrame;
/// <summary>
/// List of frame objects to free on VM reset
/// </summary>
public VdbeFrame pDelFrame;
/// <summary>
/// Number of frames in pFrame list
/// </summary>
public int nFrame;
/// <summary>
/// Binding to these vars invalidates VM
/// </summary>
public u32 expmask;
/// <summary>
/// Linked list of all sub-programs used by VM
/// </summary>
public SubProgram pProgram;
public Vdbe Copy()
{
Vdbe cp = (Vdbe)MemberwiseClone();
return cp;
}
public void CopyTo(Vdbe ct)
{
ct.db = db;
ct.pPrev = pPrev;
ct.pNext = pNext;
ct.nOp = nOp;
ct.nOpAlloc = nOpAlloc;
ct.aOp = aOp;
ct.nLabel = nLabel;
ct.nLabelAlloc = nLabelAlloc;
ct.aLabel = aLabel;
ct.apArg = apArg;
ct.aColName = aColName;
ct.nCursor = nCursor;
ct.apCsr = apCsr;
ct.aVar = aVar;
ct.azVar = azVar;
ct.nVar = nVar;
ct.nzVar = nzVar;
ct.magic = magic;
ct.nMem = nMem;
ct.aMem = aMem;
ct.cacheCtr = cacheCtr;
ct.pc = pc;
ct.rc = rc;
ct.errorAction = errorAction;
ct.nResColumn = nResColumn;
ct.zErrMsg = zErrMsg;
ct.pResultSet = pResultSet;
ct.explain = explain;
ct.changeCntOn = changeCntOn;
ct.expired = expired;
ct.minWriteFileFormat = minWriteFileFormat;
ct.inVtabMethod = inVtabMethod;
ct.usesStmtJournal = usesStmtJournal;
ct.readOnly = readOnly;
ct.nChange = nChange;
ct.isPrepareV2 = isPrepareV2;
#if !SQLITE_OMIT_TRACE
ct.startTime = startTime;
#endif
ct.btreeMask = btreeMask;
ct.lockMask = lockMask;
aCounter.CopyTo(ct.aCounter, 0);
ct.zSql = zSql;
ct.pFree = pFree;
#if SQLITE_DEBUG
ct.trace = trace;
#endif
ct.nFkConstraint = nFkConstraint;
ct.nStmtDefCons = nStmtDefCons;
ct.iStatement = iStatement;
ct.pFrame = pFrame;
ct.nFrame = nFrame;
ct.expmask = expmask;
ct.pProgram = pProgram;
#if SQLITE_SSE
ct.fetchId=fetchId;
ct.lru=lru;
#endif
#if SQLITE_ENABLE_MEMORY_MANAGEMENT
ct.pLruPrev=pLruPrev;
ct.pLruNext=pLruNext;
#endif
}
};
/*
** The following are allowed values for Vdbe.magic
*/
//#define VDBE_MAGIC_INIT 0x26bceaa5 /* Building a VDBE program */
//#define VDBE_MAGIC_RUN 0xbdf20da3 /* VDBE is ready to execute */
//#define VDBE_MAGIC_HALT 0x519c2973 /* VDBE has completed execution */
//#define VDBE_MAGIC_DEAD 0xb606c3c8 /* The VDBE has been deallocated */
const u32 VDBE_MAGIC_INIT = 0x26bceaa5; /* Building a VDBE program */
const u32 VDBE_MAGIC_RUN = 0xbdf20da3; /* VDBE is ready to execute */
const u32 VDBE_MAGIC_HALT = 0x519c2973; /* VDBE has completed execution */
const u32 VDBE_MAGIC_DEAD = 0xb606c3c8; /* The VDBE has been deallocated */
/*
** Function prototypes
*/
//void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor);
//void sqliteVdbePopStack(Vdbe*,int);
//int sqlite3VdbeCursorMoveto(VdbeCursor);
//#if (SQLITE_DEBUG) || defined(VDBE_PROFILE)
//void sqlite3VdbePrintOp(FILE*, int, Op);
//#endif
//u32 sqlite3VdbeSerialTypeLen(u32);
//u32 sqlite3VdbeSerialType(Mem*, int);
//u32sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
//u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem);
//void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
//int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int );
//int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int);
//int sqlite3VdbeIdxRowid(sqlite3 *, i64 );
//int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq);
//int sqlite3VdbeExec(Vdbe);
//int sqlite3VdbeList(Vdbe);
//int sqlite3VdbeHalt(Vdbe);
//int sqlite3VdbeChangeEncoding(Mem *, int);
//int sqlite3VdbeMemTooBig(Mem);
//int sqlite3VdbeMemCopy(Mem*, const Mem);
//void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);
//void sqlite3VdbeMemMove(Mem*, Mem);
//int sqlite3VdbeMemNulTerminate(Mem);
//int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void()(void));
//void sqlite3VdbeMemSetInt64(Mem*, i64);
#if SQLITE_OMIT_FLOATING_POINT
//# define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64
#else
//void sqlite3VdbeMemSetDouble(Mem*, double);
#endif
//void sqlite3VdbeMemSetNull(Mem);
//void sqlite3VdbeMemSetZeroBlob(Mem*,int);
//void sqlite3VdbeMemSetRowSet(Mem);
//int sqlite3VdbeMemMakeWriteable(Mem);
//int sqlite3VdbeMemStringify(Mem*, int);
//i64 sqlite3VdbeIntValue(Mem);
//int sqlite3VdbeMemIntegerify(Mem);
//double sqlite3VdbeRealValue(Mem);
//void sqlite3VdbeIntegerAffinity(Mem);
//int sqlite3VdbeMemRealify(Mem);
//int sqlite3VdbeMemNumerify(Mem);
//int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem);
//void sqlite3VdbeMemRelease(Mem p);
//void sqlite3VdbeMemReleaseExternal(Mem p);
//int sqlite3VdbeMemFinalize(Mem*, FuncDef);
//string sqlite3OpcodeName(int);
//int sqlite3VdbeMemGrow(Mem pMem, int n, int preserve);
//int sqlite3VdbeCloseStatement(Vdbe *, int);
//void sqlite3VdbeFrameDelete(VdbeFrame);
//int sqlite3VdbeFrameRestore(VdbeFrame );
//void sqlite3VdbeMemStoreType(Mem *pMem);
#if !(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE//>0
//void sqlite3VdbeEnter(Vdbe);
//void sqlite3VdbeLeave(Vdbe);
#else
//# define sqlite3VdbeEnter(X)
static void sqlite3VdbeEnter(Vdbe p)
{
}
//# define sqlite3VdbeLeave(X)