0000: ef bb bf 2f 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a .../************
0010: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0020: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0030: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0d 0a 20 2a ************.. *
0040: 20 41 44 4f 2e 4e 45 54 20 32 2e 30 20 44 61 74 ADO.NET 2.0 Dat
0050: 61 20 50 72 6f 76 69 64 65 72 20 66 6f 72 20 53 a Provider for S
0060: 51 4c 69 74 65 20 56 65 72 73 69 6f 6e 20 33 2e QLite Version 3.
0070: 58 0d 0a 20 2a 20 57 72 69 74 74 65 6e 20 62 79 X.. * Written by
0080: 20 52 6f 62 65 72 74 20 53 69 6d 70 73 6f 6e 20 Robert Simpson
0090: 28 72 6f 62 65 72 74 40 62 6c 61 63 6b 63 61 73 (robert@blackcas
00a0: 74 6c 65 73 6f 66 74 2e 63 6f 6d 29 0d 0a 20 2a tlesoft.com).. *
00b0: 20 0d 0a 20 2a 20 52 65 6c 65 61 73 65 64 20 74 .. * Released t
00c0: 6f 20 74 68 65 20 70 75 62 6c 69 63 20 64 6f 6d o the public dom
00d0: 61 69 6e 2c 20 75 73 65 20 61 74 20 79 6f 75 72 ain, use at your
00e0: 20 6f 77 6e 20 72 69 73 6b 21 0d 0a 20 2a 2a 2a own risk!.. ***
00f0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0100: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0110: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0120: 2a 2a 2a 2a 2a 2f 0d 0a 0d 0a 6e 61 6d 65 73 70 *****/....namesp
0130: 61 63 65 20 53 79 73 74 65 6d 2e 44 61 74 61 2e ace System.Data.
0140: 53 51 4c 69 74 65 0d 0a 7b 0d 0a 20 20 75 73 69 SQLite..{.. usi
0150: 6e 67 20 53 79 73 74 65 6d 3b 0d 0a 20 20 75 73 ng System;.. us
0160: 69 6e 67 20 53 79 73 74 65 6d 2e 43 6f 6c 6c 65 ing System.Colle
0170: 63 74 69 6f 6e 73 2e 47 65 6e 65 72 69 63 3b 0d ctions.Generic;.
0180: 0a 23 69 66 20 44 45 42 55 47 0d 0a 20 20 75 73 .#if DEBUG.. us
0190: 69 6e 67 20 53 79 73 74 65 6d 2e 44 69 61 67 6e ing System.Diagn
01a0: 6f 73 74 69 63 73 3b 0d 0a 23 65 6e 64 69 66 0d ostics;..#endif.
01b0: 0a 20 20 75 73 69 6e 67 20 53 79 73 74 65 6d 2e . using System.
01c0: 52 75 6e 74 69 6d 65 2e 49 6e 74 65 72 6f 70 53 Runtime.InteropS
01d0: 65 72 76 69 63 65 73 3b 0d 0a 20 20 75 73 69 6e ervices;.. usin
01e0: 67 20 53 79 73 74 65 6d 2e 54 65 78 74 3b 0d 0a g System.Text;..
01f0: 0d 0a 23 69 66 20 21 50 4c 41 54 46 4f 52 4d 5f ..#if !PLATFORM_
0200: 43 4f 4d 50 41 43 54 46 52 41 4d 45 57 4f 52 4b COMPACTFRAMEWORK
0210: 0d 0a 20 20 5b 55 6e 6d 61 6e 61 67 65 64 46 75 .. [UnmanagedFu
0220: 6e 63 74 69 6f 6e 50 6f 69 6e 74 65 72 28 43 61 nctionPointer(Ca
0230: 6c 6c 69 6e 67 43 6f 6e 76 65 6e 74 69 6f 6e 2e llingConvention.
0240: 43 64 65 63 6c 29 5d 0d 0a 23 65 6e 64 69 66 0d Cdecl)]..#endif.
0250: 0a 20 20 69 6e 74 65 72 6e 61 6c 20 64 65 6c 65 . internal dele
0260: 67 61 74 65 20 76 6f 69 64 20 53 51 4c 69 74 65 gate void SQLite
0270: 4c 6f 67 43 61 6c 6c 62 61 63 6b 28 49 6e 74 50 LogCallback(IntP
0280: 74 72 20 70 75 73 65 72 2c 20 69 6e 74 20 65 72 tr puser, int er
0290: 72 5f 63 6f 64 65 2c 20 49 6e 74 50 74 72 20 6d r_code, IntPtr m
02a0: 65 73 73 61 67 65 29 3b 0d 0a 0d 0a 20 20 2f 2f essage);.... //
02b0: 2f 20 3c 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 2f / <summary>.. /
02c0: 2f 2f 20 54 68 69 73 20 63 6c 61 73 73 20 69 6d // This class im
02d0: 70 6c 65 6d 65 6e 74 73 20 53 51 4c 69 74 65 42 plements SQLiteB
02e0: 61 73 65 20 63 6f 6d 70 6c 65 74 65 6c 79 2c 20 ase completely,
02f0: 61 6e 64 20 69 73 20 74 68 65 20 67 75 74 73 20 and is the guts
0300: 6f 66 20 74 68 65 20 63 6f 64 65 20 74 68 61 74 of the code that
0310: 20 69 6e 74 65 72 6f 70 27 73 20 53 51 4c 69 74 interop's SQLit
0320: 65 20 77 69 74 68 20 2e 4e 45 54 0d 0a 20 20 2f e with .NET.. /
0330: 2f 2f 20 3c 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 // </summary>..
0340: 20 69 6e 74 65 72 6e 61 6c 20 63 6c 61 73 73 20 internal class
0350: 53 51 4c 69 74 65 33 20 3a 20 53 51 4c 69 74 65 SQLite3 : SQLite
0360: 42 61 73 65 0d 0a 20 20 7b 0d 0a 20 20 20 20 70 Base.. {.. p
0370: 72 69 76 61 74 65 20 73 74 61 74 69 63 20 6f 62 rivate static ob
0380: 6a 65 63 74 20 73 79 6e 63 52 6f 6f 74 20 3d 20 ject syncRoot =
0390: 6e 65 77 20 6f 62 6a 65 63 74 28 29 3b 0d 0a 0d new object();...
03a0: 0a 20 20 20 20 2f 2f 0d 0a 20 20 20 20 2f 2f 20 . //.. //
03b0: 4e 4f 54 45 3a 20 54 68 69 73 20 69 73 20 74 68 NOTE: This is th
03c0: 65 20 70 75 62 6c 69 63 20 6b 65 79 20 66 6f 72 e public key for
03d0: 20 74 68 65 20 53 79 73 74 65 6d 2e 44 61 74 61 the System.Data
03e0: 2e 53 51 4c 69 74 65 20 61 73 73 65 6d 62 6c 79 .SQLite assembly
03f0: 2e 20 20 49 66 20 79 6f 75 20 63 68 61 6e 67 65 . If you change
0400: 20 74 68 65 0d 0a 20 20 20 20 2f 2f 20 20 20 20 the.. //
0410: 20 20 20 53 4e 4b 20 66 69 6c 65 2c 20 79 6f 75 SNK file, you
0420: 20 77 69 6c 6c 20 6e 65 65 64 20 74 6f 20 63 68 will need to ch
0430: 61 6e 67 65 20 74 68 69 73 20 61 73 20 77 65 6c ange this as wel
0440: 6c 2e 0d 0a 20 20 20 20 2f 2f 0d 0a 20 20 20 20 l... //..
0450: 69 6e 74 65 72 6e 61 6c 20 63 6f 6e 73 74 20 73 internal const s
0460: 74 72 69 6e 67 20 50 75 62 6c 69 63 4b 65 79 20 tring PublicKey
0470: 3d 0d 0a 20 20 20 20 20 20 20 20 22 30 30 32 34 =.. "0024
0480: 30 30 30 30 30 34 38 30 30 30 30 30 39 34 30 30 0000048000009400
0490: 30 30 30 30 30 36 30 32 30 30 30 30 30 30 32 34 0000060200000024
04a0: 30 30 30 30 35 32 35 33 34 31 33 31 30 30 30 34 0000525341310004
04b0: 30 30 30 30 30 31 30 30 30 31 30 30 30 35 61 32 00000100010005a2
04c0: 38 38 64 65 35 36 38 37 63 34 65 31 22 20 2b 0d 88de5687c4e1" +.
04d0: 0a 20 20 20 20 20 20 20 20 22 62 36 32 31 64 64 . "b621dd
04e0: 66 66 35 64 38 34 34 37 32 37 34 31 38 39 35 36 ff5d844727418956
04f0: 39 39 37 66 34 37 35 65 62 38 32 39 34 32 39 65 997f475eb829429e
0500: 34 31 31 61 66 66 33 65 39 33 66 39 37 62 37 30 411aff3e93f97b70
0510: 64 65 36 39 38 62 39 37 32 36 34 30 39 32 35 62 de698b972640925b
0520: 64 64 34 34 32 38 30 64 66 30 22 20 2b 0d 0a 20 dd44280df0" +..
0530: 20 20 20 20 20 20 20 22 61 32 35 61 38 34 33 32 "a25a8432
0540: 36 36 39 37 33 37 30 34 31 33 37 63 62 62 30 65 66973704137cbb0e
0550: 37 34 34 31 63 31 66 65 37 63 61 65 34 65 32 34 7441c1fe7cae4e24
0560: 34 30 61 65 39 31 61 62 38 63 64 65 33 39 33 33 40ae91ab8cde3933
0570: 66 65 62 63 62 31 61 63 34 38 64 64 33 33 62 34 febcb1ac48dd33b4
0580: 30 65 31 33 63 34 32 31 22 20 2b 0d 0a 20 20 20 0e13c421" +..
0590: 20 20 20 20 20 22 64 38 32 31 35 63 31 38 61 34 "d8215c18a4
05a0: 33 34 39 61 34 33 36 64 64 34 39 39 65 33 63 33 349a436dd499e3c3
05b0: 38 35 63 63 36 38 33 30 31 35 66 38 38 36 66 36 85cc683015f886f6
05c0: 63 31 30 62 64 39 30 31 31 35 65 62 32 62 64 36 c10bd90115eb2bd6
05d0: 31 62 36 37 37 35 30 38 33 39 65 33 61 31 39 39 1b67750839e3a199
05e0: 34 31 64 63 39 63 22 3b 0d 0a 0d 0a 23 69 66 20 41dc9c";....#if
05f0: 21 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 !PLATFORM_COMPAC
0600: 54 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 TFRAMEWORK..
0610: 69 6e 74 65 72 6e 61 6c 20 63 6f 6e 73 74 20 73 internal const s
0620: 74 72 69 6e 67 20 44 65 73 69 67 6e 65 72 56 65 tring DesignerVe
0630: 72 73 69 6f 6e 20 3d 20 22 31 2e 30 2e 38 31 2e rsion = "1.0.81.
0640: 30 22 3b 0d 0a 23 65 6e 64 69 66 0d 0a 0d 0a 20 0";..#endif....
0650: 20 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 72 79 3e /// <summary>
0660: 0d 0a 20 20 20 20 2f 2f 2f 20 54 68 65 20 6f 70 .. /// The op
0670: 61 71 75 65 20 70 6f 69 6e 74 65 72 20 72 65 74 aque pointer ret
0680: 75 72 6e 65 64 20 74 6f 20 75 73 20 62 79 20 74 urned to us by t
0690: 68 65 20 73 71 6c 69 74 65 20 70 72 6f 76 69 64 he sqlite provid
06a0: 65 72 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 73 75 er.. /// </su
06b0: 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 70 72 6f 74 mmary>.. prot
06c0: 65 63 74 65 64 20 53 51 4c 69 74 65 43 6f 6e 6e ected SQLiteConn
06d0: 65 63 74 69 6f 6e 48 61 6e 64 6c 65 20 5f 73 71 ectionHandle _sq
06e0: 6c 3b 0d 0a 20 20 20 20 70 72 6f 74 65 63 74 65 l;.. protecte
06f0: 64 20 73 74 72 69 6e 67 20 5f 66 69 6c 65 4e 61 d string _fileNa
0700: 6d 65 3b 0d 0a 20 20 20 20 70 72 6f 74 65 63 74 me;.. protect
0710: 65 64 20 62 6f 6f 6c 20 5f 75 73 65 50 6f 6f 6c ed bool _usePool
0720: 3b 0d 0a 20 20 20 20 70 72 6f 74 65 63 74 65 64 ;.. protected
0730: 20 69 6e 74 20 5f 70 6f 6f 6c 56 65 72 73 69 6f int _poolVersio
0740: 6e 3b 0d 0a 0d 0a 23 69 66 20 21 50 4c 41 54 46 n;....#if !PLATF
0750: 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 41 4d 45 ORM_COMPACTFRAME
0760: 57 4f 52 4b 0d 0a 20 20 20 20 70 72 69 76 61 74 WORK.. privat
0770: 65 20 62 6f 6f 6c 20 5f 62 75 69 6c 64 69 6e 67 e bool _building
0780: 53 63 68 65 6d 61 3b 0d 0a 23 65 6e 64 69 66 0d Schema;..#endif.
0790: 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 72 . /// <summar
07a0: 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 54 68 65 20 y>.. /// The
07b0: 75 73 65 72 2d 64 65 66 69 6e 65 64 20 66 75 6e user-defined fun
07c0: 63 74 69 6f 6e 73 20 72 65 67 69 73 74 65 72 65 ctions registere
07d0: 64 20 6f 6e 20 74 68 69 73 20 63 6f 6e 6e 65 63 d on this connec
07e0: 74 69 6f 6e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f tion.. /// </
07f0: 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 70 72 summary>.. pr
0800: 6f 74 65 63 74 65 64 20 53 51 4c 69 74 65 46 75 otected SQLiteFu
0810: 6e 63 74 69 6f 6e 5b 5d 20 5f 66 75 6e 63 74 69 nction[] _functi
0820: 6f 6e 73 41 72 72 61 79 3b 0d 0a 0d 0a 20 20 20 onsArray;....
0830: 20 69 6e 74 65 72 6e 61 6c 20 53 51 4c 69 74 65 internal SQLite
0840: 33 28 53 51 4c 69 74 65 44 61 74 65 46 6f 72 6d 3(SQLiteDateForm
0850: 61 74 73 20 66 6d 74 2c 20 44 61 74 65 54 69 6d ats fmt, DateTim
0860: 65 4b 69 6e 64 20 6b 69 6e 64 29 0d 0a 20 20 20 eKind kind)..
0870: 20 20 20 3a 20 62 61 73 65 28 66 6d 74 2c 20 6b : base(fmt, k
0880: 69 6e 64 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 ind).. {..
0890: 20 7d 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 2f 2f 2f }.... //////
08a0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
08b0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
08c0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
08d0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
08e0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
08f0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 0d 0a 0d 0a 20 20 20 /////////....
0900: 20 23 72 65 67 69 6f 6e 20 49 44 69 73 70 6f 73 #region IDispos
0910: 61 62 6c 65 20 22 50 61 74 74 65 72 6e 22 20 4d able "Pattern" M
0920: 65 6d 62 65 72 73 0d 0a 20 20 20 20 70 72 69 76 embers.. priv
0930: 61 74 65 20 62 6f 6f 6c 20 64 69 73 70 6f 73 65 ate bool dispose
0940: 64 3b 0d 0a 20 20 20 20 70 72 69 76 61 74 65 20 d;.. private
0950: 76 6f 69 64 20 43 68 65 63 6b 44 69 73 70 6f 73 void CheckDispos
0960: 65 64 28 29 20 2f 2a 20 74 68 72 6f 77 20 2a 2f ed() /* throw */
0970: 0d 0a 20 20 20 20 7b 0d 0a 23 69 66 20 54 48 52 .. {..#if THR
0980: 4f 57 5f 4f 4e 5f 44 49 53 50 4f 53 45 44 0d 0a OW_ON_DISPOSED..
0990: 20 20 20 20 20 20 20 20 69 66 20 28 64 69 73 70 if (disp
09a0: 6f 73 65 64 29 0d 0a 20 20 20 20 20 20 20 20 20 osed)..
09b0: 20 20 20 74 68 72 6f 77 20 6e 65 77 20 4f 62 6a throw new Obj
09c0: 65 63 74 44 69 73 70 6f 73 65 64 45 78 63 65 70 ectDisposedExcep
09d0: 74 69 6f 6e 28 74 79 70 65 6f 66 28 53 51 4c 69 tion(typeof(SQLi
09e0: 74 65 33 29 2e 4e 61 6d 65 29 3b 0d 0a 23 65 6e te3).Name);..#en
09f0: 64 69 66 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 dif.. }....
0a00: 20 20 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f //////////////
0a10: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0a20: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0a30: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0a40: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0a50: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0a60: 2f 0d 0a 0d 0a 20 20 20 20 70 72 6f 74 65 63 74 /.... protect
0a70: 65 64 20 6f 76 65 72 72 69 64 65 20 76 6f 69 64 ed override void
0a80: 20 44 69 73 70 6f 73 65 28 62 6f 6f 6c 20 64 69 Dispose(bool di
0a90: 73 70 6f 73 69 6e 67 29 0d 0a 20 20 20 20 7b 0d sposing).. {.
0aa0: 0a 20 20 20 20 20 20 20 20 74 72 79 0d 0a 20 20 . try..
0ab0: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
0ac0: 20 20 20 20 20 69 66 20 28 21 64 69 73 70 6f 73 if (!dispos
0ad0: 65 64 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ed)..
0ae0: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
0af0: 20 20 20 20 2f 2f 69 66 20 28 64 69 73 70 6f 73 //if (dispos
0b00: 69 6e 67 29 0d 0a 20 20 20 20 20 20 20 20 20 20 ing)..
0b10: 20 20 20 20 20 20 2f 2f 7b 0d 0a 20 20 20 20 20 //{..
0b20: 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 20 20 //
0b30: 20 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ///////////////
0b40: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0b50: 2f 2f 2f 2f 2f 0d 0a 20 20 20 20 20 20 20 20 20 /////..
0b60: 20 20 20 20 20 20 20 2f 2f 20 20 20 20 2f 2f 20 // //
0b70: 64 69 73 70 6f 73 65 20 6d 61 6e 61 67 65 64 20 dispose managed
0b80: 72 65 73 6f 75 72 63 65 73 20 68 65 72 65 2e 2e resources here..
0b90: 2e 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ...
0ba0: 20 20 20 2f 2f 20 20 20 20 2f 2f 2f 2f 2f 2f 2f // ///////
0bb0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0bc0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0d 0a 20 /////////////..
0bd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
0be0: 2f 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 /}....
0bf0: 20 20 20 20 20 20 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f //////////
0c00: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0c10: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0d 0a 20 20 ////////////..
0c20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f //
0c30: 20 72 65 6c 65 61 73 65 20 75 6e 6d 61 6e 61 67 release unmanag
0c40: 65 64 20 72 65 73 6f 75 72 63 65 73 20 68 65 72 ed resources her
0c50: 65 2e 2e 2e 0d 0a 20 20 20 20 20 20 20 20 20 20 e.....
0c60: 20 20 20 20 20 20 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f //////////
0c70: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0c80: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0d 0a 0d 0a ////////////....
0c90: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0ca0: 43 6c 6f 73 65 28 29 3b 0d 0a 0d 0a 20 20 20 20 Close();....
0cb0: 20 20 20 20 20 20 20 20 20 20 20 20 64 69 73 70 disp
0cc0: 6f 73 65 64 20 3d 20 74 72 75 65 3b 0d 0a 20 20 osed = true;..
0cd0: 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 }..
0ce0: 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 }..
0cf0: 66 69 6e 61 6c 6c 79 0d 0a 20 20 20 20 20 20 20 finally..
0d00: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
0d10: 62 61 73 65 2e 44 69 73 70 6f 73 65 28 64 69 73 base.Dispose(dis
0d20: 70 6f 73 69 6e 67 29 3b 0d 0a 20 20 20 20 20 20 posing);..
0d30: 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a 20 20 20 20 }.. }..
0d40: 23 65 6e 64 72 65 67 69 6f 6e 0d 0a 0d 0a 20 20 #endregion....
0d50: 20 20 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f //////////////
0d60: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0d70: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0d80: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0d90: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0da0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0db0: 2f 0d 0a 0d 0a 20 20 20 20 2f 2f 20 49 74 20 69 /.... // It i
0dc0: 73 6e 27 74 20 6e 65 63 65 73 73 61 72 79 20 74 sn't necessary t
0dd0: 6f 20 63 6c 65 61 6e 75 70 20 61 6e 79 20 66 75 o cleanup any fu
0de0: 6e 63 74 69 6f 6e 73 20 77 65 27 76 65 20 72 65 nctions we've re
0df0: 67 69 73 74 65 72 65 64 2e 20 20 49 66 20 74 68 gistered. If th
0e00: 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 0d 0a 20 20 e connection..
0e10: 20 20 2f 2f 20 67 6f 65 73 20 74 6f 20 74 68 65 // goes to the
0e20: 20 70 6f 6f 6c 20 61 6e 64 20 69 73 20 72 65 73 pool and is res
0e30: 75 72 72 65 63 74 65 64 20 6c 61 74 65 72 2c 20 urrected later,
0e40: 72 65 2d 72 65 67 69 73 74 65 72 65 64 20 66 75 re-registered fu
0e50: 6e 63 74 69 6f 6e 73 20 77 69 6c 6c 20 6f 76 65 nctions will ove
0e60: 72 77 72 69 74 65 20 74 68 65 0d 0a 20 20 20 20 rwrite the..
0e70: 2f 2f 20 70 72 65 76 69 6f 75 73 20 66 75 6e 63 // previous func
0e80: 74 69 6f 6e 73 2e 20 20 54 68 65 20 53 51 4c 69 tions. The SQLi
0e90: 74 65 46 75 6e 63 74 69 6f 6e 43 6f 6f 6b 69 65 teFunctionCookie
0ea0: 48 61 6e 64 6c 65 20 77 69 6c 6c 20 74 61 6b 65 Handle will take
0eb0: 20 63 61 72 65 20 6f 66 20 66 72 65 65 69 6e 67 care of freeing
0ec0: 20 75 6e 6d 61 6e 61 67 65 64 0d 0a 20 20 20 20 unmanaged..
0ed0: 2f 2f 20 72 65 73 6f 75 72 63 65 73 20 62 65 6c // resources bel
0ee0: 6f 6e 67 69 6e 67 20 74 6f 20 74 68 65 20 70 72 onging to the pr
0ef0: 65 76 69 6f 75 73 6c 79 2d 72 65 67 69 73 74 65 eviously-registe
0f00: 72 65 64 20 66 75 6e 63 74 69 6f 6e 73 2e 0d 0a red functions...
0f10: 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 internal ove
0f20: 72 72 69 64 65 20 76 6f 69 64 20 43 6c 6f 73 65 rride void Close
0f30: 28 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 ().. {..
0f40: 20 69 66 20 28 5f 73 71 6c 20 21 3d 20 6e 75 6c if (_sql != nul
0f50: 6c 29 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 20 20 l).. {..
0f60: 20 20 20 20 20 20 20 69 66 20 28 5f 75 73 65 50 if (_useP
0f70: 6f 6f 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 20 ool)..
0f80: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 {..
0f90: 20 53 51 4c 69 74 65 42 61 73 65 2e 52 65 73 65 SQLiteBase.Rese
0fa0: 74 43 6f 6e 6e 65 63 74 69 6f 6e 28 5f 73 71 6c tConnection(_sql
0fb0: 2c 20 5f 73 71 6c 29 3b 0d 0a 20 20 20 20 20 20 , _sql);..
0fc0: 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 43 6f SQLiteCo
0fd0: 6e 6e 65 63 74 69 6f 6e 50 6f 6f 6c 2e 41 64 64 nnectionPool.Add
0fe0: 28 5f 66 69 6c 65 4e 61 6d 65 2c 20 5f 73 71 6c (_fileName, _sql
0ff0: 2c 20 5f 70 6f 6f 6c 56 65 72 73 69 6f 6e 29 3b , _poolVersion);
1000: 0d 0a 0d 0a 23 69 66 20 44 45 42 55 47 20 26 26 ....#if DEBUG &&
1010: 20 21 4e 45 54 5f 43 4f 4d 50 41 43 54 5f 32 30 !NET_COMPACT_20
1020: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
1030: 54 72 61 63 65 2e 57 72 69 74 65 4c 69 6e 65 28 Trace.WriteLine(
1040: 53 74 72 69 6e 67 2e 46 6f 72 6d 61 74 28 22 43 String.Format("C
1050: 6c 6f 73 65 20 28 50 6f 6f 6c 29 3a 20 7b 30 7d lose (Pool): {0}
1060: 22 2c 20 5f 73 71 6c 29 29 3b 0d 0a 23 65 6e 64 ", _sql));..#end
1070: 69 66 0d 0a 20 20 20 20 20 20 20 20 20 20 7d 0d if.. }.
1080: 0a 20 20 20 20 20 20 20 20 20 20 65 6c 73 65 0d . else.
1090: 0a 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 . {..
10a0: 20 20 20 20 20 20 20 20 20 20 20 20 5f 73 71 6c _sql
10b0: 2e 44 69 73 70 6f 73 65 28 29 3b 0d 0a 20 20 20 .Dispose();..
10c0: 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 }..
10d0: 20 20 20 20 5f 73 71 6c 20 3d 20 6e 75 6c 6c 3b _sql = null;
10e0: 0d 0a 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 7d .. }.. }
10f0: 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 2f 2f 2f 2f 2f .... ////////
1100: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1110: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1120: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1130: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1140: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1150: 2f 2f 2f 2f 2f 2f 2f 0d 0a 0d 0a 20 20 20 20 69 ///////.... i
1160: 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 nternal override
1170: 20 76 6f 69 64 20 43 61 6e 63 65 6c 28 29 0d 0a void Cancel()..
1180: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 55 6e 73 {.. Uns
1190: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
11a0: 2e 73 71 6c 69 74 65 33 5f 69 6e 74 65 72 72 75 .sqlite3_interru
11b0: 70 74 28 5f 73 71 6c 29 3b 0d 0a 20 20 20 20 7d pt(_sql);.. }
11c0: 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c .... internal
11d0: 20 6f 76 65 72 72 69 64 65 20 73 74 72 69 6e 67 override string
11e0: 20 56 65 72 73 69 6f 6e 0d 0a 20 20 20 20 7b 0d Version.. {.
11f0: 0a 20 20 20 20 20 20 67 65 74 0d 0a 20 20 20 20 . get..
1200: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 72 65 74 {.. ret
1210: 75 72 6e 20 53 51 4c 69 74 65 33 2e 53 51 4c 69 urn SQLite3.SQLi
1220: 74 65 56 65 72 73 69 6f 6e 3b 0d 0a 20 20 20 20 teVersion;..
1230: 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 }.. }....
1240: 20 20 69 6e 74 65 72 6e 61 6c 20 73 74 61 74 69 internal stati
1250: 63 20 73 74 72 69 6e 67 20 44 65 66 69 6e 65 43 c string DefineC
1260: 6f 6e 73 74 61 6e 74 73 0d 0a 20 20 20 20 7b 0d onstants.. {.
1270: 0a 20 20 20 20 20 20 20 20 67 65 74 0d 0a 20 20 . get..
1280: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
1290: 20 20 20 20 20 53 74 72 69 6e 67 42 75 69 6c 64 StringBuild
12a0: 65 72 20 72 65 73 75 6c 74 20 3d 20 6e 65 77 20 er result = new
12b0: 53 74 72 69 6e 67 42 75 69 6c 64 65 72 28 29 3b StringBuilder();
12c0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 49 4c .. IL
12d0: 69 73 74 3c 73 74 72 69 6e 67 3e 20 6c 69 73 74 ist<string> list
12e0: 20 3d 20 53 51 4c 69 74 65 44 65 66 69 6e 65 43 = SQLiteDefineC
12f0: 6f 6e 73 74 61 6e 74 73 2e 4f 70 74 69 6f 6e 4c onstants.OptionL
1300: 69 73 74 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 ist;....
1310: 20 20 20 20 69 66 20 28 6c 69 73 74 20 21 3d 20 if (list !=
1320: 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 null)..
1330: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 {..
1340: 20 20 20 20 20 20 66 6f 72 65 61 63 68 20 28 73 foreach (s
1350: 74 72 69 6e 67 20 65 6c 65 6d 65 6e 74 20 69 6e tring element in
1360: 20 6c 69 73 74 29 0d 0a 20 20 20 20 20 20 20 20 list)..
1370: 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 {..
1380: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 i
1390: 66 20 28 65 6c 65 6d 65 6e 74 20 3d 3d 20 6e 75 f (element == nu
13a0: 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ll)..
13b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 63 6f 6e con
13c0: 74 69 6e 75 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 tinue;....
13d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 if
13e0: 20 28 72 65 73 75 6c 74 2e 4c 65 6e 67 74 68 20 (result.Length
13f0: 3e 20 30 29 0d 0a 20 20 20 20 20 20 20 20 20 20 > 0)..
1400: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 72 65 re
1410: 73 75 6c 74 2e 41 70 70 65 6e 64 28 27 20 27 29 sult.Append(' ')
1420: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ;....
1430: 20 20 20 20 20 20 20 20 20 72 65 73 75 6c 74 2e result.
1440: 41 70 70 65 6e 64 28 65 6c 65 6d 65 6e 74 29 3b Append(element);
1450: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
1460: 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 20 20 20 }..
1470: 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 }....
1480: 20 20 72 65 74 75 72 6e 20 72 65 73 75 6c 74 2e return result.
1490: 54 6f 53 74 72 69 6e 67 28 29 3b 0d 0a 20 20 20 ToString();..
14a0: 20 20 20 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a 0d }.. }...
14b0: 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 73 74 . internal st
14c0: 61 74 69 63 20 73 74 72 69 6e 67 20 53 51 4c 69 atic string SQLi
14d0: 74 65 56 65 72 73 69 6f 6e 0d 0a 20 20 20 20 7b teVersion.. {
14e0: 0d 0a 20 20 20 20 20 20 67 65 74 0d 0a 20 20 20 .. get..
14f0: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 72 65 {.. re
1500: 74 75 72 6e 20 55 54 46 38 54 6f 53 74 72 69 6e turn UTF8ToStrin
1510: 67 28 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 g(UnsafeNativeMe
1520: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 6c 69 thods.sqlite3_li
1530: 62 76 65 72 73 69 6f 6e 28 29 2c 20 2d 31 29 3b bversion(), -1);
1540: 0d 0a 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 7d .. }.. }
1550: 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c .... internal
1560: 20 73 74 61 74 69 63 20 73 74 72 69 6e 67 20 53 static string S
1570: 51 4c 69 74 65 53 6f 75 72 63 65 49 64 0d 0a 20 QLiteSourceId..
1580: 20 20 20 7b 0d 0a 20 20 20 20 20 20 67 65 74 0d {.. get.
1590: 0a 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 . {..
15a0: 20 20 72 65 74 75 72 6e 20 55 54 46 38 54 6f 53 return UTF8ToS
15b0: 74 72 69 6e 67 28 55 6e 73 61 66 65 4e 61 74 69 tring(UnsafeNati
15c0: 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 veMethods.sqlite
15d0: 33 5f 73 6f 75 72 63 65 69 64 28 29 2c 20 2d 31 3_sourceid(), -1
15e0: 29 3b 0d 0a 20 20 20 20 20 20 7d 0d 0a 20 20 20 );.. }..
15f0: 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e }.... intern
1600: 61 6c 20 6f 76 65 72 72 69 64 65 20 62 6f 6f 6c al override bool
1610: 20 41 75 74 6f 43 6f 6d 6d 69 74 0d 0a 20 20 20 AutoCommit..
1620: 20 7b 0d 0a 20 20 20 20 20 20 67 65 74 0d 0a 20 {.. get..
1630: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
1640: 72 65 74 75 72 6e 20 49 73 41 75 74 6f 63 6f 6d return IsAutocom
1650: 6d 69 74 28 5f 73 71 6c 29 3b 0d 0a 20 20 20 20 mit(_sql);..
1660: 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 }.. }....
1670: 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
1680: 69 64 65 20 6c 6f 6e 67 20 4c 61 73 74 49 6e 73 ide long LastIns
1690: 65 72 74 52 6f 77 49 64 0d 0a 20 20 20 20 7b 0d ertRowId.. {.
16a0: 0a 20 20 20 20 20 20 67 65 74 0d 0a 20 20 20 20 . get..
16b0: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 72 65 74 {.. ret
16c0: 75 72 6e 20 55 6e 73 61 66 65 4e 61 74 69 76 65 urn UnsafeNative
16d0: 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f Methods.sqlite3_
16e0: 6c 61 73 74 5f 69 6e 73 65 72 74 5f 72 6f 77 69 last_insert_rowi
16f0: 64 28 5f 73 71 6c 29 3b 0d 0a 20 20 20 20 20 20 d(_sql);..
1700: 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 }.. }....
1710: 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 internal overrid
1720: 65 20 69 6e 74 20 43 68 61 6e 67 65 73 0d 0a 20 e int Changes..
1730: 20 20 20 7b 0d 0a 20 20 20 20 20 20 67 65 74 0d {.. get.
1740: 0a 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 . {..
1750: 20 20 72 65 74 75 72 6e 20 55 6e 73 61 66 65 4e return UnsafeN
1760: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
1770: 69 74 65 33 5f 63 68 61 6e 67 65 73 28 5f 73 71 ite3_changes(_sq
1780: 6c 29 3b 0d 0a 20 20 20 20 20 20 7d 0d 0a 20 20 l);.. }..
1790: 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 }.... inter
17a0: 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 6c 6f 6e nal override lon
17b0: 67 20 4d 65 6d 6f 72 79 55 73 65 64 0d 0a 20 20 g MemoryUsed..
17c0: 20 20 7b 0d 0a 20 20 20 20 20 20 67 65 74 0d 0a {.. get..
17d0: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
17e0: 20 72 65 74 75 72 6e 20 55 6e 73 61 66 65 4e 61 return UnsafeNa
17f0: 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 tiveMethods.sqli
1800: 74 65 33 5f 6d 65 6d 6f 72 79 5f 75 73 65 64 28 te3_memory_used(
1810: 29 3b 0d 0a 20 20 20 20 20 20 7d 0d 0a 20 20 20 );.. }..
1820: 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e }.... intern
1830: 61 6c 20 6f 76 65 72 72 69 64 65 20 6c 6f 6e 67 al override long
1840: 20 4d 65 6d 6f 72 79 48 69 67 68 77 61 74 65 72 MemoryHighwater
1850: 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 67 .. {.. g
1860: 65 74 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 20 20 et.. {..
1870: 20 20 20 20 20 72 65 74 75 72 6e 20 55 6e 73 61 return Unsa
1880: 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
1890: 73 71 6c 69 74 65 33 5f 6d 65 6d 6f 72 79 5f 68 sqlite3_memory_h
18a0: 69 67 68 77 61 74 65 72 28 30 29 3b 0d 0a 20 20 ighwater(0);..
18b0: 20 20 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a }.. }....
18c0: 20 20 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 72 79 /// <summary
18d0: 3e 0d 0a 20 20 20 20 2f 2f 2f 20 53 68 75 74 64 >.. /// Shutd
18e0: 6f 77 6e 20 74 68 65 20 53 51 4c 69 74 65 20 65 own the SQLite e
18f0: 6e 67 69 6e 65 20 73 6f 20 74 68 61 74 20 69 74 ngine so that it
1900: 20 63 61 6e 20 62 65 20 72 65 73 74 61 72 74 65 can be restarte
1910: 64 20 77 69 74 68 20 64 69 66 66 65 72 65 6e 74 d with different
1920: 20 63 6f 6e 66 69 67 20 6f 70 74 69 6f 6e 73 2e config options.
1930: 0d 0a 20 20 20 20 2f 2f 2f 20 57 65 20 64 65 70 .. /// We dep
1940: 65 6e 64 20 6f 6e 20 61 75 74 6f 20 69 6e 69 74 end on auto init
1950: 69 61 6c 69 7a 61 74 69 6f 6e 20 74 6f 20 72 65 ialization to re
1960: 63 6f 76 65 72 2e 0d 0a 20 20 20 20 2f 2f 2f 20 cover... ///
1970: 3c 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 </summary>..
1980: 2f 2f 2f 20 3c 72 65 74 75 72 6e 73 3e 52 65 74 /// <returns>Ret
1990: 75 72 6e 73 20 61 20 72 65 73 75 6c 74 20 63 6f urns a result co
19a0: 64 65 3c 2f 72 65 74 75 72 6e 73 3e 0d 0a 20 20 de</returns>..
19b0: 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
19c0: 69 64 65 20 69 6e 74 20 53 68 75 74 64 6f 77 6e ide int Shutdown
19d0: 28 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 ().. {..
19e0: 20 20 20 69 6e 74 20 72 63 20 3d 20 55 6e 73 61 int rc = Unsa
19f0: 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
1a00: 73 71 6c 69 74 65 33 5f 73 68 75 74 64 6f 77 6e sqlite3_shutdown
1a10: 28 29 3b 0d 0a 20 20 20 20 20 20 20 20 72 65 74 ();.. ret
1a20: 75 72 6e 20 72 63 3b 0d 0a 20 20 20 20 7d 0d 0a urn rc;.. }..
1a30: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
1a40: 76 65 72 72 69 64 65 20 62 6f 6f 6c 20 49 73 4f verride bool IsO
1a50: 70 65 6e 28 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 pen().. {..
1a60: 20 20 20 20 20 20 72 65 74 75 72 6e 20 28 5f 73 return (_s
1a70: 71 6c 20 21 3d 20 6e 75 6c 6c 29 3b 0d 0a 20 20 ql != null);..
1a80: 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 }.... inter
1a90: 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 76 6f 69 nal override voi
1aa0: 64 20 4f 70 65 6e 28 73 74 72 69 6e 67 20 73 74 d Open(string st
1ab0: 72 46 69 6c 65 6e 61 6d 65 2c 20 53 51 4c 69 74 rFilename, SQLit
1ac0: 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 eConnectionFlags
1ad0: 20 63 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 connectionFlags
1ae0: 2c 20 53 51 4c 69 74 65 4f 70 65 6e 46 6c 61 67 , SQLiteOpenFlag
1af0: 73 45 6e 75 6d 20 6f 70 65 6e 46 6c 61 67 73 2c sEnum openFlags,
1b00: 20 69 6e 74 20 6d 61 78 50 6f 6f 6c 53 69 7a 65 int maxPoolSize
1b10: 2c 20 62 6f 6f 6c 20 75 73 65 50 6f 6f 6c 29 0d , bool usePool).
1b20: 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 69 66 . {.. if
1b30: 20 28 5f 73 71 6c 20 21 3d 20 6e 75 6c 6c 29 20 (_sql != null)
1b40: 72 65 74 75 72 6e 3b 0d 0a 0d 0a 20 20 20 20 20 return;....
1b50: 20 5f 75 73 65 50 6f 6f 6c 20 3d 20 75 73 65 50 _usePool = useP
1b60: 6f 6f 6c 3b 0d 0a 20 20 20 20 20 20 5f 66 69 6c ool;.. _fil
1b70: 65 4e 61 6d 65 20 3d 20 73 74 72 46 69 6c 65 6e eName = strFilen
1b80: 61 6d 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 69 66 ame;.... if
1b90: 20 28 75 73 65 50 6f 6f 6c 29 0d 0a 20 20 20 20 (usePool)..
1ba0: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 5f 73 71 {.. _sq
1bb0: 6c 20 3d 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 l = SQLiteConnec
1bc0: 74 69 6f 6e 50 6f 6f 6c 2e 52 65 6d 6f 76 65 28 tionPool.Remove(
1bd0: 73 74 72 46 69 6c 65 6e 61 6d 65 2c 20 6d 61 78 strFilename, max
1be0: 50 6f 6f 6c 53 69 7a 65 2c 20 6f 75 74 20 5f 70 PoolSize, out _p
1bf0: 6f 6f 6c 56 65 72 73 69 6f 6e 29 3b 0d 0a 0d 0a oolVersion);....
1c00: 23 69 66 20 44 45 42 55 47 20 26 26 20 21 4e 45 #if DEBUG && !NE
1c10: 54 5f 43 4f 4d 50 41 43 54 5f 32 30 0d 0a 20 20 T_COMPACT_20..
1c20: 20 20 20 20 20 20 54 72 61 63 65 2e 57 72 69 74 Trace.Writ
1c30: 65 4c 69 6e 65 28 53 74 72 69 6e 67 2e 46 6f 72 eLine(String.For
1c40: 6d 61 74 28 22 4f 70 65 6e 20 28 50 6f 6f 6c 29 mat("Open (Pool)
1c50: 3a 20 7b 30 7d 22 2c 20 28 5f 73 71 6c 20 21 3d : {0}", (_sql !=
1c60: 20 6e 75 6c 6c 29 20 3f 20 5f 73 71 6c 2e 54 6f null) ? _sql.To
1c70: 53 74 72 69 6e 67 28 29 20 3a 20 22 3c 6e 75 6c String() : "<nul
1c80: 6c 3e 22 29 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a l>"));..#endif..
1c90: 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 }....
1ca0: 20 69 66 20 28 5f 73 71 6c 20 3d 3d 20 6e 75 6c if (_sql == nul
1cb0: 6c 29 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 20 20 l).. {..
1cc0: 20 20 20 20 20 49 6e 74 50 74 72 20 64 62 3b 0d IntPtr db;.
1cd0: 0a 0d 0a 23 69 66 20 21 53 51 4c 49 54 45 5f 53 ...#if !SQLITE_S
1ce0: 54 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 20 20 TANDARD..
1cf0: 20 69 6e 74 20 6e 20 3d 20 55 6e 73 61 66 65 4e int n = UnsafeN
1d00: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
1d10: 69 74 65 33 5f 6f 70 65 6e 5f 69 6e 74 65 72 6f ite3_open_intero
1d20: 70 28 54 6f 55 54 46 38 28 73 74 72 46 69 6c 65 p(ToUTF8(strFile
1d30: 6e 61 6d 65 29 2c 20 28 69 6e 74 29 6f 70 65 6e name), (int)open
1d40: 46 6c 61 67 73 2c 20 6f 75 74 20 64 62 29 3b 0d Flags, out db);.
1d50: 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 .#else..
1d60: 69 6e 74 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 int n = UnsafeNa
1d70: 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 tiveMethods.sqli
1d80: 74 65 33 5f 6f 70 65 6e 5f 76 32 28 54 6f 55 54 te3_open_v2(ToUT
1d90: 46 38 28 73 74 72 46 69 6c 65 6e 61 6d 65 29 2c F8(strFilename),
1da0: 20 6f 75 74 20 64 62 2c 20 28 69 6e 74 29 6f 70 out db, (int)op
1db0: 65 6e 46 6c 61 67 73 2c 20 49 6e 74 50 74 72 2e enFlags, IntPtr.
1dc0: 5a 65 72 6f 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a Zero);..#endif..
1dd0: 0d 0a 23 69 66 20 44 45 42 55 47 20 26 26 20 21 ..#if DEBUG && !
1de0: 4e 45 54 5f 43 4f 4d 50 41 43 54 5f 32 30 0d 0a NET_COMPACT_20..
1df0: 20 20 20 20 20 20 20 20 54 72 61 63 65 2e 57 72 Trace.Wr
1e00: 69 74 65 4c 69 6e 65 28 53 74 72 69 6e 67 2e 46 iteLine(String.F
1e10: 6f 72 6d 61 74 28 22 4f 70 65 6e 3a 20 7b 30 7d ormat("Open: {0}
1e20: 22 2c 20 64 62 29 29 3b 0d 0a 23 65 6e 64 69 66 ", db));..#endif
1e30: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 .... if (
1e40: 6e 20 3e 20 30 29 20 74 68 72 6f 77 20 6e 65 77 n > 0) throw new
1e50: 20 53 51 4c 69 74 65 45 78 63 65 70 74 69 6f 6e SQLiteException
1e60: 28 6e 2c 20 6e 75 6c 6c 29 3b 0d 0a 0d 0a 20 20 (n, null);....
1e70: 20 20 20 20 20 20 5f 73 71 6c 20 3d 20 6e 65 77 _sql = new
1e80: 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f SQLiteConnectio
1e90: 6e 48 61 6e 64 6c 65 28 64 62 29 3b 0d 0a 20 20 nHandle(db);..
1ea0: 20 20 20 20 20 20 6c 6f 63 6b 20 28 5f 73 71 6c lock (_sql
1eb0: 29 20 7b 20 2f 2a 20 48 41 43 4b 3a 20 46 6f 72 ) { /* HACK: For
1ec0: 63 65 20 74 68 65 20 53 79 6e 63 42 6c 6f 63 6b ce the SyncBlock
1ed0: 20 74 6f 20 62 65 20 22 63 72 65 61 74 65 64 22 to be "created"
1ee0: 20 6e 6f 77 2e 20 2a 2f 20 7d 0d 0a 20 20 20 20 now. */ }..
1ef0: 20 20 7d 0d 0a 20 20 20 20 20 20 2f 2f 20 42 69 }.. // Bi
1f00: 6e 64 20 66 75 6e 63 74 69 6f 6e 73 20 74 6f 20 nd functions to
1f10: 74 68 69 73 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e this connection.
1f20: 20 20 49 66 20 61 6e 79 20 70 72 65 76 69 6f 75 If any previou
1f30: 73 20 66 75 6e 63 74 69 6f 6e 73 20 6f 66 20 74 s functions of t
1f40: 68 65 20 73 61 6d 65 20 6e 61 6d 65 0d 0a 20 20 he same name..
1f50: 20 20 20 20 2f 2f 20 77 65 72 65 20 61 6c 72 65 // were alre
1f60: 61 64 79 20 62 6f 75 6e 64 2c 20 74 68 65 6e 20 ady bound, then
1f70: 74 68 65 20 6e 65 77 20 62 69 6e 64 69 6e 67 73 the new bindings
1f80: 20 72 65 70 6c 61 63 65 20 74 68 65 20 6f 6c 64 replace the old
1f90: 2e 0d 0a 20 20 20 20 20 20 5f 66 75 6e 63 74 69 ... _functi
1fa0: 6f 6e 73 41 72 72 61 79 20 3d 20 53 51 4c 69 74 onsArray = SQLit
1fb0: 65 46 75 6e 63 74 69 6f 6e 2e 42 69 6e 64 46 75 eFunction.BindFu
1fc0: 6e 63 74 69 6f 6e 73 28 74 68 69 73 2c 20 63 6f nctions(this, co
1fd0: 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 29 3b 0d nnectionFlags);.
1fe0: 0a 20 20 20 20 20 20 53 65 74 54 69 6d 65 6f 75 . SetTimeou
1ff0: 74 28 30 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a t(0);.. }....
2000: 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 internal ove
2010: 72 72 69 64 65 20 76 6f 69 64 20 43 6c 65 61 72 rride void Clear
2020: 50 6f 6f 6c 28 29 0d 0a 20 20 20 20 7b 0d 0a 20 Pool().. {..
2030: 20 20 20 20 20 53 51 4c 69 74 65 43 6f 6e 6e 65 SQLiteConne
2040: 63 74 69 6f 6e 50 6f 6f 6c 2e 43 6c 65 61 72 50 ctionPool.ClearP
2050: 6f 6f 6c 28 5f 66 69 6c 65 4e 61 6d 65 29 3b 0d ool(_fileName);.
2060: 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e . }.... in
2070: 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 ternal override
2080: 69 6e 74 20 43 6f 75 6e 74 50 6f 6f 6c 28 29 0d int CountPool().
2090: 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 . {..
20a0: 44 69 63 74 69 6f 6e 61 72 79 3c 73 74 72 69 6e Dictionary<strin
20b0: 67 2c 20 69 6e 74 3e 20 63 6f 75 6e 74 73 20 3d g, int> counts =
20c0: 20 6e 75 6c 6c 3b 0d 0a 20 20 20 20 20 20 20 20 null;..
20d0: 69 6e 74 20 6f 70 65 6e 43 6f 75 6e 74 20 3d 20 int openCount =
20e0: 30 3b 0d 0a 20 20 20 20 20 20 20 20 69 6e 74 20 0;.. int
20f0: 63 6c 6f 73 65 43 6f 75 6e 74 20 3d 20 30 3b 0d closeCount = 0;.
2100: 0a 20 20 20 20 20 20 20 20 69 6e 74 20 74 6f 74 . int tot
2110: 61 6c 43 6f 75 6e 74 20 3d 20 30 3b 0d 0a 0d 0a alCount = 0;....
2120: 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 43 6f SQLiteCo
2130: 6e 6e 65 63 74 69 6f 6e 50 6f 6f 6c 2e 47 65 74 nnectionPool.Get
2140: 43 6f 75 6e 74 73 28 5f 66 69 6c 65 4e 61 6d 65 Counts(_fileName
2150: 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 72 ,.. r
2160: 65 66 20 63 6f 75 6e 74 73 2c 20 72 65 66 20 6f ef counts, ref o
2170: 70 65 6e 43 6f 75 6e 74 2c 20 72 65 66 20 63 6c penCount, ref cl
2180: 6f 73 65 43 6f 75 6e 74 2c 0d 0a 20 20 20 20 20 oseCount,..
2190: 20 20 20 20 20 20 20 72 65 66 20 74 6f 74 61 6c ref total
21a0: 43 6f 75 6e 74 29 3b 0d 0a 0d 0a 20 20 20 20 20 Count);....
21b0: 20 20 20 72 65 74 75 72 6e 20 74 6f 74 61 6c 43 return totalC
21c0: 6f 75 6e 74 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a ount;.. }....
21d0: 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 internal ove
21e0: 72 72 69 64 65 20 76 6f 69 64 20 53 65 74 54 69 rride void SetTi
21f0: 6d 65 6f 75 74 28 69 6e 74 20 6e 54 69 6d 65 6f meout(int nTimeo
2200: 75 74 4d 53 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 utMS).. {..
2210: 20 20 20 20 69 6e 74 20 6e 20 3d 20 55 6e 73 61 int n = Unsa
2220: 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
2230: 73 71 6c 69 74 65 33 5f 62 75 73 79 5f 74 69 6d sqlite3_busy_tim
2240: 65 6f 75 74 28 5f 73 71 6c 2c 20 6e 54 69 6d 65 eout(_sql, nTime
2250: 6f 75 74 4d 53 29 3b 0d 0a 20 20 20 20 20 20 69 outMS);.. i
2260: 66 20 28 6e 20 3e 20 30 29 20 74 68 72 6f 77 20 f (n > 0) throw
2270: 6e 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 74 new SQLiteExcept
2280: 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 72 ion(n, GetLastEr
2290: 72 6f 72 28 29 29 3b 0d 0a 20 20 20 20 7d 0d 0a ror());.. }..
22a0: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
22b0: 76 65 72 72 69 64 65 20 62 6f 6f 6c 20 53 74 65 verride bool Ste
22c0: 70 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e p(SQLiteStatemen
22d0: 74 20 73 74 6d 74 29 0d 0a 20 20 20 20 7b 0d 0a t stmt).. {..
22e0: 20 20 20 20 20 20 69 6e 74 20 6e 3b 0d 0a 20 20 int n;..
22f0: 20 20 20 20 52 61 6e 64 6f 6d 20 72 6e 64 20 3d Random rnd =
2300: 20 6e 75 6c 6c 3b 0d 0a 20 20 20 20 20 20 75 69 null;.. ui
2310: 6e 74 20 73 74 61 72 74 74 69 63 6b 20 3d 20 28 nt starttick = (
2320: 75 69 6e 74 29 45 6e 76 69 72 6f 6e 6d 65 6e 74 uint)Environment
2330: 2e 54 69 63 6b 43 6f 75 6e 74 3b 0d 0a 20 20 20 .TickCount;..
2340: 20 20 20 75 69 6e 74 20 74 69 6d 65 6f 75 74 20 uint timeout
2350: 3d 20 28 75 69 6e 74 29 28 73 74 6d 74 2e 5f 63 = (uint)(stmt._c
2360: 6f 6d 6d 61 6e 64 2e 5f 63 6f 6d 6d 61 6e 64 54 ommand._commandT
2370: 69 6d 65 6f 75 74 20 2a 20 31 30 30 30 29 3b 0d imeout * 1000);.
2380: 0a 0d 0a 20 20 20 20 20 20 77 68 69 6c 65 20 28 ... while (
2390: 74 72 75 65 29 0d 0a 20 20 20 20 20 20 7b 0d 0a true).. {..
23a0: 20 20 20 20 20 20 20 20 6e 20 3d 20 55 6e 73 61 n = Unsa
23b0: 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
23c0: 73 71 6c 69 74 65 33 5f 73 74 65 70 28 73 74 6d sqlite3_step(stm
23d0: 74 2e 5f 73 71 6c 69 74 65 5f 73 74 6d 74 29 3b t._sqlite_stmt);
23e0: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 .... if (
23f0: 6e 20 3d 3d 20 31 30 30 29 20 72 65 74 75 72 6e n == 100) return
2400: 20 74 72 75 65 3b 0d 0a 20 20 20 20 20 20 20 20 true;..
2410: 69 66 20 28 6e 20 3d 3d 20 31 30 31 29 20 72 65 if (n == 101) re
2420: 74 75 72 6e 20 66 61 6c 73 65 3b 0d 0a 0d 0a 20 turn false;....
2430: 20 20 20 20 20 20 20 69 66 20 28 6e 20 3e 20 30 if (n > 0
2440: 29 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 ).. {..
2450: 20 20 20 20 20 20 20 20 69 6e 74 20 72 3b 0d 0a int r;..
2460: 0d 0a 20 20 20 20 20 20 20 20 20 20 2f 2f 20 41 .. // A
2470: 6e 20 65 72 72 6f 72 20 6f 63 63 75 72 72 65 64 n error occurred
2480: 2c 20 61 74 74 65 6d 70 74 20 74 6f 20 72 65 73 , attempt to res
2490: 65 74 20 74 68 65 20 73 74 61 74 65 6d 65 6e 74 et the statement
24a0: 2e 20 20 49 66 20 74 68 65 20 72 65 73 65 74 20 . If the reset
24b0: 77 6f 72 6b 65 64 20 62 65 63 61 75 73 65 20 74 worked because t
24c0: 68 65 0d 0a 20 20 20 20 20 20 20 20 20 20 2f 2f he.. //
24d0: 20 73 63 68 65 6d 61 20 68 61 73 20 63 68 61 6e schema has chan
24e0: 67 65 64 2c 20 72 65 2d 74 72 79 20 74 68 65 20 ged, re-try the
24f0: 73 74 65 70 20 61 67 61 69 6e 2e 20 20 49 66 20 step again. If
2500: 69 74 20 65 72 72 6f 72 65 64 20 6f 75 72 20 62 it errored our b
2510: 65 63 61 75 73 65 20 74 68 65 20 64 61 74 61 62 ecause the datab
2520: 61 73 65 0d 0a 20 20 20 20 20 20 20 20 20 20 2f ase.. /
2530: 2f 20 69 73 20 6c 6f 63 6b 65 64 2c 20 74 68 65 / is locked, the
2540: 6e 20 6b 65 65 70 20 72 65 74 72 79 69 6e 67 20 n keep retrying
2550: 75 6e 74 69 6c 20 74 68 65 20 63 6f 6d 6d 61 6e until the comman
2560: 64 20 74 69 6d 65 6f 75 74 20 6f 63 63 75 72 73 d timeout occurs
2570: 2e 0d 0a 20 20 20 20 20 20 20 20 20 20 72 20 3d ... r =
2580: 20 52 65 73 65 74 28 73 74 6d 74 29 3b 0d 0a 0d Reset(stmt);...
2590: 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 28 72 . if (r
25a0: 20 3d 3d 20 30 29 0d 0a 20 20 20 20 20 20 20 20 == 0)..
25b0: 20 20 20 20 74 68 72 6f 77 20 6e 65 77 20 53 51 throw new SQ
25c0: 4c 69 74 65 45 78 63 65 70 74 69 6f 6e 28 6e 2c LiteException(n,
25d0: 20 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 29 GetLastError())
25e0: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 65 ;.... e
25f0: 6c 73 65 20 69 66 20 28 28 72 20 3d 3d 20 36 20 lse if ((r == 6
2600: 7c 7c 20 72 20 3d 3d 20 35 29 20 26 26 20 73 74 || r == 5) && st
2610: 6d 74 2e 5f 63 6f 6d 6d 61 6e 64 20 21 3d 20 6e mt._command != n
2620: 75 6c 6c 29 20 2f 2f 20 53 51 4c 49 54 45 5f 4c ull) // SQLITE_L
2630: 4f 43 4b 45 44 20 7c 7c 20 53 51 4c 49 54 45 5f OCKED || SQLITE_
2640: 42 55 53 59 0d 0a 20 20 20 20 20 20 20 20 20 20 BUSY..
2650: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 2f {.. /
2660: 2f 20 4b 65 65 70 20 74 72 79 69 6e 67 0d 0a 20 / Keep trying..
2670: 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 72 if (r
2680: 6e 64 20 3d 3d 20 6e 75 6c 6c 29 20 2f 2f 20 46 nd == null) // F
2690: 69 72 73 74 20 74 69 6d 65 20 77 65 27 76 65 20 irst time we've
26a0: 65 6e 63 6f 75 6e 74 65 72 65 64 20 74 68 65 20 encountered the
26b0: 6c 6f 63 6b 0d 0a 20 20 20 20 20 20 20 20 20 20 lock..
26c0: 20 20 20 20 72 6e 64 20 3d 20 6e 65 77 20 52 61 rnd = new Ra
26d0: 6e 64 6f 6d 28 29 3b 0d 0a 0d 0a 20 20 20 20 20 ndom();....
26e0: 20 20 20 20 20 20 20 2f 2f 20 49 66 20 77 65 27 // If we'
26f0: 76 65 20 65 78 63 65 65 64 65 64 20 74 68 65 20 ve exceeded the
2700: 63 6f 6d 6d 61 6e 64 27 73 20 74 69 6d 65 6f 75 command's timeou
2710: 74 2c 20 67 69 76 65 20 75 70 20 61 6e 64 20 74 t, give up and t
2720: 68 72 6f 77 20 61 6e 20 65 72 72 6f 72 0d 0a 20 hrow an error..
2730: 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 28 if ((
2740: 75 69 6e 74 29 45 6e 76 69 72 6f 6e 6d 65 6e 74 uint)Environment
2750: 2e 54 69 63 6b 43 6f 75 6e 74 20 2d 20 73 74 61 .TickCount - sta
2760: 72 74 74 69 63 6b 20 3e 20 74 69 6d 65 6f 75 74 rttick > timeout
2770: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 7b ).. {
2780: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
2790: 74 68 72 6f 77 20 6e 65 77 20 53 51 4c 69 74 65 throw new SQLite
27a0: 45 78 63 65 70 74 69 6f 6e 28 72 2c 20 47 65 74 Exception(r, Get
27b0: 4c 61 73 74 45 72 72 6f 72 28 29 29 3b 0d 0a 20 LastError());..
27c0: 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 }..
27d0: 20 20 20 20 20 20 20 20 20 20 65 6c 73 65 0d 0a else..
27e0: 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 {..
27f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 //
2800: 4f 74 68 65 72 77 69 73 65 20 73 6c 65 65 70 20 Otherwise sleep
2810: 66 6f 72 20 61 20 72 61 6e 64 6f 6d 20 61 6d 6f for a random amo
2820: 75 6e 74 20 6f 66 20 74 69 6d 65 20 75 70 20 74 unt of time up t
2830: 6f 20 31 35 30 6d 73 0d 0a 20 20 20 20 20 20 20 o 150ms..
2840: 20 20 20 20 20 20 20 53 79 73 74 65 6d 2e 54 68 System.Th
2850: 72 65 61 64 69 6e 67 2e 54 68 72 65 61 64 2e 53 reading.Thread.S
2860: 6c 65 65 70 28 72 6e 64 2e 4e 65 78 74 28 31 2c leep(rnd.Next(1,
2870: 20 31 35 30 29 29 3b 0d 0a 20 20 20 20 20 20 20 150));..
2880: 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 }..
2890: 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a }.. }..
28a0: 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a }.. }..
28b0: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
28c0: 76 65 72 72 69 64 65 20 69 6e 74 20 52 65 73 65 verride int Rese
28d0: 74 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e t(SQLiteStatemen
28e0: 74 20 73 74 6d 74 29 0d 0a 20 20 20 20 7b 0d 0a t stmt).. {..
28f0: 20 20 20 20 20 20 69 6e 74 20 6e 3b 0d 0a 0d 0a int n;....
2900: 23 69 66 20 21 53 51 4c 49 54 45 5f 53 54 41 4e #if !SQLITE_STAN
2910: 44 41 52 44 0d 0a 20 20 20 20 20 20 6e 20 3d 20 DARD.. n =
2920: 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 UnsafeNativeMeth
2930: 6f 64 73 2e 73 71 6c 69 74 65 33 5f 72 65 73 65 ods.sqlite3_rese
2940: 74 5f 69 6e 74 65 72 6f 70 28 73 74 6d 74 2e 5f t_interop(stmt._
2950: 73 71 6c 69 74 65 5f 73 74 6d 74 29 3b 0d 0a 23 sqlite_stmt);..#
2960: 65 6c 73 65 0d 0a 20 20 20 20 20 20 6e 20 3d 20 else.. n =
2970: 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 UnsafeNativeMeth
2980: 6f 64 73 2e 73 71 6c 69 74 65 33 5f 72 65 73 65 ods.sqlite3_rese
2990: 74 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 t(stmt._sqlite_s
29a0: 74 6d 74 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 0d tmt);..#endif...
29b0: 0a 20 20 20 20 20 20 2f 2f 20 49 66 20 74 68 65 . // If the
29c0: 20 73 63 68 65 6d 61 20 63 68 61 6e 67 65 64 2c schema changed,
29d0: 20 74 72 79 20 61 6e 64 20 72 65 2d 70 72 65 70 try and re-prep
29e0: 61 72 65 20 69 74 0d 0a 20 20 20 20 20 20 69 66 are it.. if
29f0: 20 28 6e 20 3d 3d 20 31 37 29 20 2f 2f 20 53 51 (n == 17) // SQ
2a00: 4c 49 54 45 5f 53 43 48 45 4d 41 0d 0a 20 20 20 LITE_SCHEMA..
2a10: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 2f 2f {.. //
2a20: 20 52 65 63 72 65 61 74 65 20 61 20 64 75 6d 6d Recreate a dumm
2a30: 79 20 73 74 61 74 65 6d 65 6e 74 0d 0a 20 20 20 y statement..
2a40: 20 20 20 20 20 73 74 72 69 6e 67 20 73 74 72 3b string str;
2a50: 0d 0a 20 20 20 20 20 20 20 20 75 73 69 6e 67 20 .. using
2a60: 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 (SQLiteStatement
2a70: 20 74 6d 70 20 3d 20 50 72 65 70 61 72 65 28 6e tmp = Prepare(n
2a80: 75 6c 6c 2c 20 73 74 6d 74 2e 5f 73 71 6c 53 74 ull, stmt._sqlSt
2a90: 61 74 65 6d 65 6e 74 2c 20 6e 75 6c 6c 2c 20 28 atement, null, (
2aa0: 75 69 6e 74 29 28 73 74 6d 74 2e 5f 63 6f 6d 6d uint)(stmt._comm
2ab0: 61 6e 64 2e 5f 63 6f 6d 6d 61 6e 64 54 69 6d 65 and._commandTime
2ac0: 6f 75 74 20 2a 20 31 30 30 30 29 2c 20 6f 75 74 out * 1000), out
2ad0: 20 73 74 72 29 29 0d 0a 20 20 20 20 20 20 20 20 str))..
2ae0: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 2f 2f 20 {.. //
2af0: 46 69 6e 61 6c 69 7a 65 20 74 68 65 20 65 78 69 Finalize the exi
2b00: 73 74 69 6e 67 20 73 74 61 74 65 6d 65 6e 74 0d sting statement.
2b10: 0a 20 20 20 20 20 20 20 20 20 20 73 74 6d 74 2e . stmt.
2b20: 5f 73 71 6c 69 74 65 5f 73 74 6d 74 2e 44 69 73 _sqlite_stmt.Dis
2b30: 70 6f 73 65 28 29 3b 0d 0a 20 20 20 20 20 20 20 pose();..
2b40: 20 20 20 2f 2f 20 52 65 61 73 73 69 67 6e 20 61 // Reassign a
2b50: 20 6e 65 77 20 73 74 61 74 65 6d 65 6e 74 20 70 new statement p
2b60: 6f 69 6e 74 65 72 20 74 6f 20 74 68 65 20 6f 6c ointer to the ol
2b70: 64 20 73 74 61 74 65 6d 65 6e 74 20 61 6e 64 20 d statement and
2b80: 63 6c 65 61 72 20 74 68 65 20 74 65 6d 70 6f 72 clear the tempor
2b90: 61 72 79 20 6f 6e 65 0d 0a 20 20 20 20 20 20 20 ary one..
2ba0: 20 20 20 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f stmt._sqlite_
2bb0: 73 74 6d 74 20 3d 20 74 6d 70 2e 5f 73 71 6c 69 stmt = tmp._sqli
2bc0: 74 65 5f 73 74 6d 74 3b 0d 0a 20 20 20 20 20 20 te_stmt;..
2bd0: 20 20 20 20 74 6d 70 2e 5f 73 71 6c 69 74 65 5f tmp._sqlite_
2be0: 73 74 6d 74 20 3d 20 6e 75 6c 6c 3b 0d 0a 0d 0a stmt = null;....
2bf0: 20 20 20 20 20 20 20 20 20 20 2f 2f 20 52 65 61 // Rea
2c00: 70 70 6c 79 20 70 61 72 61 6d 65 74 65 72 73 0d pply parameters.
2c10: 0a 20 20 20 20 20 20 20 20 20 20 73 74 6d 74 2e . stmt.
2c20: 42 69 6e 64 50 61 72 61 6d 65 74 65 72 73 28 29 BindParameters()
2c30: 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 ;.. }..
2c40: 20 20 20 20 20 20 72 65 74 75 72 6e 20 2d 31 3b return -1;
2c50: 20 2f 2f 20 52 65 73 65 74 20 77 61 73 20 4f 4b // Reset was OK
2c60: 2c 20 77 69 74 68 20 73 63 68 65 6d 61 20 63 68 , with schema ch
2c70: 61 6e 67 65 0d 0a 20 20 20 20 20 20 7d 0d 0a 20 ange.. }..
2c80: 20 20 20 20 20 65 6c 73 65 20 69 66 20 28 6e 20 else if (n
2c90: 3d 3d 20 36 20 7c 7c 20 6e 20 3d 3d 20 35 29 20 == 6 || n == 5)
2ca0: 2f 2f 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 45 44 // SQLITE_LOCKED
2cb0: 20 7c 7c 20 53 51 4c 49 54 45 5f 42 55 53 59 0d || SQLITE_BUSY.
2cc0: 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 . return
2cd0: 6e 3b 0d 0a 0d 0a 20 20 20 20 20 20 69 66 20 28 n;.... if (
2ce0: 6e 20 3e 20 30 29 0d 0a 20 20 20 20 20 20 20 20 n > 0)..
2cf0: 74 68 72 6f 77 20 6e 65 77 20 53 51 4c 69 74 65 throw new SQLite
2d00: 45 78 63 65 70 74 69 6f 6e 28 6e 2c 20 47 65 74 Exception(n, Get
2d10: 4c 61 73 74 45 72 72 6f 72 28 29 29 3b 0d 0a 0d LastError());...
2d20: 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 30 3b . return 0;
2d30: 20 2f 2f 20 57 65 20 72 65 73 65 74 20 4f 4b 2c // We reset OK,
2d40: 20 6e 6f 20 73 63 68 65 6d 61 20 63 68 61 6e 67 no schema chang
2d50: 65 73 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 es.. }....
2d60: 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 internal overri
2d70: 64 65 20 73 74 72 69 6e 67 20 47 65 74 4c 61 73 de string GetLas
2d80: 74 45 72 72 6f 72 28 29 0d 0a 20 20 20 20 7b 0d tError().. {.
2d90: 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 53 51 . return SQ
2da0: 4c 69 74 65 42 61 73 65 2e 47 65 74 4c 61 73 74 LiteBase.GetLast
2db0: 45 72 72 6f 72 28 5f 73 71 6c 2c 20 5f 73 71 6c Error(_sql, _sql
2dc0: 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 );.. }....
2dd0: 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 internal overri
2de0: 64 65 20 53 51 4c 69 74 65 53 74 61 74 65 6d 65 de SQLiteStateme
2df0: 6e 74 20 50 72 65 70 61 72 65 28 53 51 4c 69 74 nt Prepare(SQLit
2e00: 65 43 6f 6e 6e 65 63 74 69 6f 6e 20 63 6e 6e 2c eConnection cnn,
2e10: 20 73 74 72 69 6e 67 20 73 74 72 53 71 6c 2c 20 string strSql,
2e20: 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 20 SQLiteStatement
2e30: 70 72 65 76 69 6f 75 73 2c 20 75 69 6e 74 20 74 previous, uint t
2e40: 69 6d 65 6f 75 74 4d 53 2c 20 6f 75 74 20 73 74 imeoutMS, out st
2e50: 72 69 6e 67 20 73 74 72 52 65 6d 61 69 6e 29 0d ring strRemain).
2e60: 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 69 66 . {.. if
2e70: 20 28 21 53 74 72 69 6e 67 2e 49 73 4e 75 6c 6c (!String.IsNull
2e80: 4f 72 45 6d 70 74 79 28 73 74 72 53 71 6c 29 29 OrEmpty(strSql))
2e90: 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 .. {..
2ea0: 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 20 20 2f //.. /
2eb0: 2f 20 4e 4f 54 45 3a 20 53 51 4c 69 74 65 20 64 / NOTE: SQLite d
2ec0: 6f 65 73 20 6e 6f 74 20 73 75 70 70 6f 72 74 20 oes not support
2ed0: 74 68 65 20 63 6f 6e 63 65 70 74 20 6f 66 20 73 the concept of s
2ee0: 65 70 61 72 61 74 65 20 73 63 68 65 6d 61 73 0d eparate schemas.
2ef0: 0a 20 20 20 20 20 20 20 20 2f 2f 20 20 20 20 20 . //
2f00: 20 20 69 6e 20 6f 6e 65 20 64 61 74 61 62 61 73 in one databas
2f10: 65 3b 20 74 68 65 72 65 66 6f 72 65 2c 20 72 65 e; therefore, re
2f20: 6d 6f 76 65 20 74 68 65 20 62 61 73 65 20 73 63 move the base sc
2f30: 68 65 6d 61 20 6e 61 6d 65 0d 0a 20 20 20 20 20 hema name..
2f40: 20 20 20 2f 2f 20 20 20 20 20 20 20 75 73 65 64 // used
2f50: 20 74 6f 20 73 6d 6f 6f 74 68 20 69 6e 74 65 67 to smooth integ
2f60: 72 61 74 69 6f 6e 20 77 69 74 68 20 74 68 65 20 ration with the
2f70: 62 61 73 65 20 2e 4e 45 54 20 46 72 61 6d 65 77 base .NET Framew
2f80: 6f 72 6b 0d 0a 20 20 20 20 20 20 20 20 2f 2f 20 ork.. //
2f90: 20 20 20 20 20 20 64 61 74 61 20 63 6c 61 73 73 data class
2fa0: 65 73 2e 0d 0a 20 20 20 20 20 20 20 20 2f 2f 0d es... //.
2fb0: 0a 20 20 20 20 20 20 20 20 73 74 72 69 6e 67 20 . string
2fc0: 62 61 73 65 53 63 68 65 6d 61 4e 61 6d 65 20 3d baseSchemaName =
2fd0: 20 28 63 6e 6e 20 21 3d 20 6e 75 6c 6c 29 20 3f (cnn != null) ?
2fe0: 20 63 6e 6e 2e 5f 62 61 73 65 53 63 68 65 6d 61 cnn._baseSchema
2ff0: 4e 61 6d 65 20 3a 20 6e 75 6c 6c 3b 0d 0a 0d 0a Name : null;....
3000: 20 20 20 20 20 20 20 20 69 66 20 28 21 53 74 72 if (!Str
3010: 69 6e 67 2e 49 73 4e 75 6c 6c 4f 72 45 6d 70 74 ing.IsNullOrEmpt
3020: 79 28 62 61 73 65 53 63 68 65 6d 61 4e 61 6d 65 y(baseSchemaName
3030: 29 29 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 )).. {..
3040: 20 20 20 20 20 20 20 20 20 73 74 72 53 71 6c 20 strSql
3050: 3d 20 73 74 72 53 71 6c 2e 52 65 70 6c 61 63 65 = strSql.Replace
3060: 28 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 (..
3070: 20 53 74 72 69 6e 67 2e 46 6f 72 6d 61 74 28 22 String.Format("
3080: 5b 7b 30 7d 5d 2e 22 2c 20 62 61 73 65 53 63 68 [{0}].", baseSch
3090: 65 6d 61 4e 61 6d 65 29 2c 20 53 74 72 69 6e 67 emaName), String
30a0: 2e 45 6d 70 74 79 29 3b 0d 0a 0d 0a 20 20 20 20 .Empty);....
30b0: 20 20 20 20 20 20 73 74 72 53 71 6c 20 3d 20 73 strSql = s
30c0: 74 72 53 71 6c 2e 52 65 70 6c 61 63 65 28 0d 0a trSql.Replace(..
30d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 53 74 St
30e0: 72 69 6e 67 2e 46 6f 72 6d 61 74 28 22 7b 30 7d ring.Format("{0}
30f0: 2e 22 2c 20 62 61 73 65 53 63 68 65 6d 61 4e 61 .", baseSchemaNa
3100: 6d 65 29 2c 20 53 74 72 69 6e 67 2e 45 6d 70 74 me), String.Empt
3110: 79 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a y);.. }..
3120: 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 }....
3130: 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f SQLiteConnectio
3140: 6e 46 6c 61 67 73 20 66 6c 61 67 73 20 3d 0d 0a nFlags flags =..
3150: 20 20 20 20 20 20 20 20 20 20 28 63 6e 6e 20 21 (cnn !
3160: 3d 20 6e 75 6c 6c 29 20 3f 20 63 6e 6e 2e 46 6c = null) ? cnn.Fl
3170: 61 67 73 20 3a 20 53 51 4c 69 74 65 43 6f 6e 6e ags : SQLiteConn
3180: 65 63 74 69 6f 6e 46 6c 61 67 73 2e 44 65 66 61 ectionFlags.Defa
3190: 75 6c 74 3b 0d 0a 0d 0a 23 69 66 20 21 50 4c 41 ult;....#if !PLA
31a0: 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 41 TFORM_COMPACTFRA
31b0: 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 20 20 69 66 MEWORK.. if
31c0: 20 28 28 66 6c 61 67 73 20 26 20 53 51 4c 69 74 ((flags & SQLit
31d0: 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 eConnectionFlags
31e0: 2e 4c 6f 67 50 72 65 70 61 72 65 29 20 3d 3d 20 .LogPrepare) ==
31f0: 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e SQLiteConnection
3200: 46 6c 61 67 73 2e 4c 6f 67 50 72 65 70 61 72 65 Flags.LogPrepare
3210: 29 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 ).. {..
3220: 20 20 20 20 20 20 69 66 20 28 28 73 74 72 53 71 if ((strSq
3230: 6c 20 3d 3d 20 6e 75 6c 6c 29 20 7c 7c 20 28 73 l == null) || (s
3240: 74 72 53 71 6c 2e 4c 65 6e 67 74 68 20 3d 3d 20 trSql.Length ==
3250: 30 29 20 7c 7c 20 28 73 74 72 53 71 6c 2e 54 72 0) || (strSql.Tr
3260: 69 6d 28 29 2e 4c 65 6e 67 74 68 20 3d 3d 20 30 im().Length == 0
3270: 29 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ))..
3280: 20 20 53 51 4c 69 74 65 4c 6f 67 2e 4c 6f 67 4d SQLiteLog.LogM
3290: 65 73 73 61 67 65 28 30 2c 20 22 50 72 65 70 61 essage(0, "Prepa
32a0: 72 69 6e 67 20 7b 3c 6e 6f 74 68 69 6e 67 3e 7d ring {<nothing>}
32b0: 2e 2e 2e 22 29 3b 0d 0a 20 20 20 20 20 20 20 20 ...");..
32c0: 20 20 65 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 else..
32d0: 20 20 20 20 20 20 53 51 4c 69 74 65 4c 6f 67 2e SQLiteLog.
32e0: 4c 6f 67 4d 65 73 73 61 67 65 28 30 2c 20 53 74 LogMessage(0, St
32f0: 72 69 6e 67 2e 46 6f 72 6d 61 74 28 22 50 72 65 ring.Format("Pre
3300: 70 61 72 69 6e 67 20 7b 7b 7b 30 7d 7d 7d 2e 2e paring {{{0}}}..
3310: 2e 22 2c 20 73 74 72 53 71 6c 29 29 3b 0d 0a 20 .", strSql));..
3320: 20 20 20 20 20 7d 0d 0a 23 65 6e 64 69 66 0d 0a }..#endif..
3330: 0d 0a 20 20 20 20 20 20 49 6e 74 50 74 72 20 73 .. IntPtr s
3340: 74 6d 74 20 3d 20 49 6e 74 50 74 72 2e 5a 65 72 tmt = IntPtr.Zer
3350: 6f 3b 0d 0a 20 20 20 20 20 20 49 6e 74 50 74 72 o;.. IntPtr
3360: 20 70 74 72 20 3d 20 49 6e 74 50 74 72 2e 5a 65 ptr = IntPtr.Ze
3370: 72 6f 3b 0d 0a 20 20 20 20 20 20 69 6e 74 20 6c ro;.. int l
3380: 65 6e 20 3d 20 30 3b 0d 0a 20 20 20 20 20 20 69 en = 0;.. i
3390: 6e 74 20 6e 20 3d 20 31 37 3b 0d 0a 20 20 20 20 nt n = 17;..
33a0: 20 20 69 6e 74 20 72 65 74 72 69 65 73 20 3d 20 int retries =
33b0: 30 3b 0d 0a 20 20 20 20 20 20 62 79 74 65 5b 5d 0;.. byte[]
33c0: 20 62 20 3d 20 54 6f 55 54 46 38 28 73 74 72 53 b = ToUTF8(strS
33d0: 71 6c 29 3b 0d 0a 20 20 20 20 20 20 73 74 72 69 ql);.. stri
33e0: 6e 67 20 74 79 70 65 64 65 66 73 20 3d 20 6e 75 ng typedefs = nu
33f0: 6c 6c 3b 0d 0a 20 20 20 20 20 20 53 51 4c 69 74 ll;.. SQLit
3400: 65 53 74 61 74 65 6d 65 6e 74 20 63 6d 64 20 3d eStatement cmd =
3410: 20 6e 75 6c 6c 3b 0d 0a 20 20 20 20 20 20 52 61 null;.. Ra
3420: 6e 64 6f 6d 20 72 6e 64 20 3d 20 6e 75 6c 6c 3b ndom rnd = null;
3430: 0d 0a 20 20 20 20 20 20 75 69 6e 74 20 73 74 61 .. uint sta
3440: 72 74 74 69 63 6b 20 3d 20 28 75 69 6e 74 29 45 rttick = (uint)E
3450: 6e 76 69 72 6f 6e 6d 65 6e 74 2e 54 69 63 6b 43 nvironment.TickC
3460: 6f 75 6e 74 3b 0d 0a 0d 0a 20 20 20 20 20 20 47 ount;.... G
3470: 43 48 61 6e 64 6c 65 20 68 61 6e 64 6c 65 20 3d CHandle handle =
3480: 20 47 43 48 61 6e 64 6c 65 2e 41 6c 6c 6f 63 28 GCHandle.Alloc(
3490: 62 2c 20 47 43 48 61 6e 64 6c 65 54 79 70 65 2e b, GCHandleType.
34a0: 50 69 6e 6e 65 64 29 3b 0d 0a 20 20 20 20 20 20 Pinned);..
34b0: 49 6e 74 50 74 72 20 70 73 71 6c 20 3d 20 68 61 IntPtr psql = ha
34c0: 6e 64 6c 65 2e 41 64 64 72 4f 66 50 69 6e 6e 65 ndle.AddrOfPinne
34d0: 64 4f 62 6a 65 63 74 28 29 3b 0d 0a 20 20 20 20 dObject();..
34e0: 20 20 74 72 79 0d 0a 20 20 20 20 20 20 7b 0d 0a try.. {..
34f0: 20 20 20 20 20 20 20 20 77 68 69 6c 65 20 28 28 while ((
3500: 6e 20 3d 3d 20 31 37 20 7c 7c 20 6e 20 3d 3d 20 n == 17 || n ==
3510: 36 20 7c 7c 20 6e 20 3d 3d 20 35 29 20 26 26 20 6 || n == 5) &&
3520: 72 65 74 72 69 65 73 20 3c 20 33 29 0d 0a 20 20 retries < 3)..
3530: 20 20 20 20 20 20 7b 0d 0a 23 69 66 20 21 53 51 {..#if !SQ
3540: 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a 20 LITE_STANDARD..
3550: 20 20 20 20 20 20 20 20 20 6e 20 3d 20 55 6e 73 n = Uns
3560: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
3570: 2e 73 71 6c 69 74 65 33 5f 70 72 65 70 61 72 65 .sqlite3_prepare
3580: 5f 69 6e 74 65 72 6f 70 28 5f 73 71 6c 2c 20 70 _interop(_sql, p
3590: 73 71 6c 2c 20 62 2e 4c 65 6e 67 74 68 20 2d 20 sql, b.Length -
35a0: 31 2c 20 6f 75 74 20 73 74 6d 74 2c 20 6f 75 74 1, out stmt, out
35b0: 20 70 74 72 2c 20 6f 75 74 20 6c 65 6e 29 3b 0d ptr, out len);.
35c0: 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 .#else..
35d0: 20 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 n = UnsafeNati
35e0: 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 veMethods.sqlite
35f0: 33 5f 70 72 65 70 61 72 65 28 5f 73 71 6c 2c 20 3_prepare(_sql,
3600: 70 73 71 6c 2c 20 62 2e 4c 65 6e 67 74 68 20 2d psql, b.Length -
3610: 20 31 2c 20 6f 75 74 20 73 74 6d 74 2c 20 6f 75 1, out stmt, ou
3620: 74 20 70 74 72 29 3b 0d 0a 20 20 20 20 20 20 20 t ptr);..
3630: 20 20 20 6c 65 6e 20 3d 20 2d 31 3b 0d 0a 23 65 len = -1;..#e
3640: 6e 64 69 66 0d 0a 0d 0a 23 69 66 20 44 45 42 55 ndif....#if DEBU
3650: 47 20 26 26 20 21 4e 45 54 5f 43 4f 4d 50 41 43 G && !NET_COMPAC
3660: 54 5f 32 30 0d 0a 20 20 20 20 20 20 20 20 20 20 T_20..
3670: 54 72 61 63 65 2e 57 72 69 74 65 4c 69 6e 65 28 Trace.WriteLine(
3680: 53 74 72 69 6e 67 2e 46 6f 72 6d 61 74 28 22 50 String.Format("P
3690: 72 65 70 61 72 65 3a 20 7b 30 7d 22 2c 20 73 74 repare: {0}", st
36a0: 6d 74 29 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 0d mt));..#endif...
36b0: 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 28 6e . if (n
36c0: 20 3d 3d 20 31 37 29 0d 0a 20 20 20 20 20 20 20 == 17)..
36d0: 20 20 20 20 20 72 65 74 72 69 65 73 2b 2b 3b 0d retries++;.
36e0: 0a 20 20 20 20 20 20 20 20 20 20 65 6c 73 65 20 . else
36f0: 69 66 20 28 6e 20 3d 3d 20 31 29 0d 0a 20 20 20 if (n == 1)..
3700: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
3710: 20 20 20 20 20 20 69 66 20 28 53 74 72 69 6e 67 if (String
3720: 2e 43 6f 6d 70 61 72 65 28 47 65 74 4c 61 73 74 .Compare(GetLast
3730: 45 72 72 6f 72 28 29 2c 20 22 6e 65 61 72 20 5c Error(), "near \
3740: 22 54 59 50 45 53 5c 22 3a 20 73 79 6e 74 61 78 "TYPES\": syntax
3750: 20 65 72 72 6f 72 22 2c 20 53 74 72 69 6e 67 43 error", StringC
3760: 6f 6d 70 61 72 69 73 6f 6e 2e 4f 72 64 69 6e 61 omparison.Ordina
3770: 6c 49 67 6e 6f 72 65 43 61 73 65 29 20 3d 3d 20 lIgnoreCase) ==
3780: 30 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 0)..
3790: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 {..
37a0: 20 69 6e 74 20 70 6f 73 20 3d 20 73 74 72 53 71 int pos = strSq
37b0: 6c 2e 49 6e 64 65 78 4f 66 28 27 3b 27 29 3b 0d l.IndexOf(';');.
37c0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 . i
37d0: 66 20 28 70 6f 73 20 3d 3d 20 2d 31 29 20 70 6f f (pos == -1) po
37e0: 73 20 3d 20 73 74 72 53 71 6c 2e 4c 65 6e 67 74 s = strSql.Lengt
37f0: 68 20 2d 20 31 3b 0d 0a 0d 0a 20 20 20 20 20 20 h - 1;....
3800: 20 20 20 20 20 20 20 20 74 79 70 65 64 65 66 73 typedefs
3810: 20 3d 20 73 74 72 53 71 6c 2e 53 75 62 73 74 72 = strSql.Substr
3820: 69 6e 67 28 30 2c 20 70 6f 73 20 2b 20 31 29 3b ing(0, pos + 1);
3830: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
3840: 73 74 72 53 71 6c 20 3d 20 73 74 72 53 71 6c 2e strSql = strSql.
3850: 53 75 62 73 74 72 69 6e 67 28 70 6f 73 20 2b 20 Substring(pos +
3860: 31 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 1);....
3870: 20 20 20 20 20 73 74 72 52 65 6d 61 69 6e 20 3d strRemain =
3880: 20 22 22 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 "";....
3890: 20 20 20 20 20 20 77 68 69 6c 65 20 28 63 6d 64 while (cmd
38a0: 20 3d 3d 20 6e 75 6c 6c 20 26 26 20 73 74 72 53 == null && strS
38b0: 71 6c 2e 4c 65 6e 67 74 68 20 3e 20 30 29 0d 0a ql.Length > 0)..
38c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d {.
38d0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
38e0: 20 63 6d 64 20 3d 20 50 72 65 70 61 72 65 28 63 cmd = Prepare(c
38f0: 6e 6e 2c 20 73 74 72 53 71 6c 2c 20 70 72 65 76 nn, strSql, prev
3900: 69 6f 75 73 2c 20 74 69 6d 65 6f 75 74 4d 53 2c ious, timeoutMS,
3910: 20 6f 75 74 20 73 74 72 52 65 6d 61 69 6e 29 3b out strRemain);
3920: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
3930: 20 20 73 74 72 53 71 6c 20 3d 20 73 74 72 52 65 strSql = strRe
3940: 6d 61 69 6e 3b 0d 0a 20 20 20 20 20 20 20 20 20 main;..
3950: 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 }....
3960: 20 20 20 20 20 20 20 20 69 66 20 28 63 6d 64 20 if (cmd
3970: 21 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 != null)..
3980: 20 20 20 20 20 20 20 20 20 20 63 6d 64 2e 53 65 cmd.Se
3990: 74 54 79 70 65 73 28 74 79 70 65 64 65 66 73 29 tTypes(typedefs)
39a0: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ;....
39b0: 20 20 20 72 65 74 75 72 6e 20 63 6d 64 3b 0d 0a return cmd;..
39c0: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 23 }..#
39d0: 69 66 20 21 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d if !PLATFORM_COM
39e0: 50 41 43 54 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 PACTFRAMEWORK..
39f0: 20 20 20 20 20 20 20 20 20 20 20 65 6c 73 65 20 else
3a00: 69 66 20 28 5f 62 75 69 6c 64 69 6e 67 53 63 68 if (_buildingSch
3a10: 65 6d 61 20 3d 3d 20 66 61 6c 73 65 20 26 26 20 ema == false &&
3a20: 53 74 72 69 6e 67 2e 43 6f 6d 70 61 72 65 28 47 String.Compare(G
3a30: 65 74 4c 61 73 74 45 72 72 6f 72 28 29 2c 20 30 etLastError(), 0
3a40: 2c 20 22 6e 6f 20 73 75 63 68 20 74 61 62 6c 65 , "no such table
3a50: 3a 20 54 45 4d 50 2e 53 43 48 45 4d 41 22 2c 20 : TEMP.SCHEMA",
3a60: 30 2c 20 32 36 2c 20 53 74 72 69 6e 67 43 6f 6d 0, 26, StringCom
3a70: 70 61 72 69 73 6f 6e 2e 4f 72 64 69 6e 61 6c 49 parison.OrdinalI
3a80: 67 6e 6f 72 65 43 61 73 65 29 20 3d 3d 20 30 29 gnoreCase) == 0)
3a90: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d .. {.
3aa0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73 . s
3ab0: 74 72 52 65 6d 61 69 6e 20 3d 20 22 22 3b 0d 0a trRemain = "";..
3ac0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 5f 62 _b
3ad0: 75 69 6c 64 69 6e 67 53 63 68 65 6d 61 20 3d 20 uildingSchema =
3ae0: 74 72 75 65 3b 0d 0a 20 20 20 20 20 20 20 20 20 true;..
3af0: 20 20 20 20 20 74 72 79 0d 0a 20 20 20 20 20 20 try..
3b00: 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 {..
3b10: 20 20 20 20 20 20 20 20 20 20 20 49 53 51 4c 69 ISQLi
3b20: 74 65 53 63 68 65 6d 61 45 78 74 65 6e 73 69 6f teSchemaExtensio
3b30: 6e 73 20 65 78 74 20 3d 20 28 28 49 53 65 72 76 ns ext = ((IServ
3b40: 69 63 65 50 72 6f 76 69 64 65 72 29 53 51 4c 69 iceProvider)SQLi
3b50: 74 65 46 61 63 74 6f 72 79 2e 49 6e 73 74 61 6e teFactory.Instan
3b60: 63 65 29 2e 47 65 74 53 65 72 76 69 63 65 28 74 ce).GetService(t
3b70: 79 70 65 6f 66 28 49 53 51 4c 69 74 65 53 63 68 ypeof(ISQLiteSch
3b80: 65 6d 61 45 78 74 65 6e 73 69 6f 6e 73 29 29 20 emaExtensions))
3b90: 61 73 20 49 53 51 4c 69 74 65 53 63 68 65 6d 61 as ISQLiteSchema
3ba0: 45 78 74 65 6e 73 69 6f 6e 73 3b 0d 0a 0d 0a 20 Extensions;....
3bb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 i
3bc0: 66 20 28 65 78 74 20 21 3d 20 6e 75 6c 6c 29 0d f (ext != null).
3bd0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
3be0: 20 20 20 65 78 74 2e 42 75 69 6c 64 54 65 6d 70 ext.BuildTemp
3bf0: 53 63 68 65 6d 61 28 63 6e 6e 29 3b 0d 0a 0d 0a Schema(cnn);....
3c00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3c10: 77 68 69 6c 65 20 28 63 6d 64 20 3d 3d 20 6e 75 while (cmd == nu
3c20: 6c 6c 20 26 26 20 73 74 72 53 71 6c 2e 4c 65 6e ll && strSql.Len
3c30: 67 74 68 20 3e 20 30 29 0d 0a 20 20 20 20 20 20 gth > 0)..
3c40: 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 {..
3c50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 63 c
3c60: 6d 64 20 3d 20 50 72 65 70 61 72 65 28 63 6e 6e md = Prepare(cnn
3c70: 2c 20 73 74 72 53 71 6c 2c 20 70 72 65 76 69 6f , strSql, previo
3c80: 75 73 2c 20 74 69 6d 65 6f 75 74 4d 53 2c 20 6f us, timeoutMS, o
3c90: 75 74 20 73 74 72 52 65 6d 61 69 6e 29 3b 0d 0a ut strRemain);..
3ca0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3cb0: 20 20 73 74 72 53 71 6c 20 3d 20 73 74 72 52 65 strSql = strRe
3cc0: 6d 61 69 6e 3b 0d 0a 20 20 20 20 20 20 20 20 20 main;..
3cd0: 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 }....
3ce0: 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 retu
3cf0: 72 6e 20 63 6d 64 3b 0d 0a 20 20 20 20 20 20 20 rn cmd;..
3d00: 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 }..
3d10: 20 20 20 20 20 20 20 20 66 69 6e 61 6c 6c 79 0d finally.
3d20: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7b . {
3d30: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
3d40: 20 20 5f 62 75 69 6c 64 69 6e 67 53 63 68 65 6d _buildingSchem
3d50: 61 20 3d 20 66 61 6c 73 65 3b 0d 0a 20 20 20 20 a = false;..
3d60: 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 }..
3d70: 20 20 20 20 20 20 20 20 20 7d 0d 0a 23 65 6e 64 }..#end
3d80: 69 66 0d 0a 20 20 20 20 20 20 20 20 20 20 7d 0d if.. }.
3d90: 0a 20 20 20 20 20 20 20 20 20 20 65 6c 73 65 20 . else
3da0: 69 66 20 28 6e 20 3d 3d 20 36 20 7c 7c 20 6e 20 if (n == 6 || n
3db0: 3d 3d 20 35 29 20 2f 2f 20 4c 6f 63 6b 65 64 20 == 5) // Locked
3dc0: 2d 2d 20 64 65 6c 61 79 20 61 20 73 6d 61 6c 6c -- delay a small
3dd0: 20 61 6d 6f 75 6e 74 20 62 65 66 6f 72 65 20 72 amount before r
3de0: 65 74 72 79 69 6e 67 0d 0a 20 20 20 20 20 20 20 etrying..
3df0: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 {..
3e00: 20 20 2f 2f 20 4b 65 65 70 20 74 72 79 69 6e 67 // Keep trying
3e10: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 69 66 .. if
3e20: 20 28 72 6e 64 20 3d 3d 20 6e 75 6c 6c 29 20 2f (rnd == null) /
3e30: 2f 20 46 69 72 73 74 20 74 69 6d 65 20 77 65 27 / First time we'
3e40: 76 65 20 65 6e 63 6f 75 6e 74 65 72 65 64 20 74 ve encountered t
3e50: 68 65 20 6c 6f 63 6b 0d 0a 20 20 20 20 20 20 20 he lock..
3e60: 20 20 20 20 20 20 20 72 6e 64 20 3d 20 6e 65 77 rnd = new
3e70: 20 52 61 6e 64 6f 6d 28 29 3b 0d 0a 0d 0a 20 20 Random();....
3e80: 20 20 20 20 20 20 20 20 20 20 2f 2f 20 49 66 20 // If
3e90: 77 65 27 76 65 20 65 78 63 65 65 64 65 64 20 74 we've exceeded t
3ea0: 68 65 20 63 6f 6d 6d 61 6e 64 27 73 20 74 69 6d he command's tim
3eb0: 65 6f 75 74 2c 20 67 69 76 65 20 75 70 20 61 6e eout, give up an
3ec0: 64 20 74 68 72 6f 77 20 61 6e 20 65 72 72 6f 72 d throw an error
3ed0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 69 66 .. if
3ee0: 20 28 28 75 69 6e 74 29 45 6e 76 69 72 6f 6e 6d ((uint)Environm
3ef0: 65 6e 74 2e 54 69 63 6b 43 6f 75 6e 74 20 2d 20 ent.TickCount -
3f00: 73 74 61 72 74 74 69 63 6b 20 3e 20 74 69 6d 65 starttick > time
3f10: 6f 75 74 4d 53 29 0d 0a 20 20 20 20 20 20 20 20 outMS)..
3f20: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 {..
3f30: 20 20 20 20 20 74 68 72 6f 77 20 6e 65 77 20 53 throw new S
3f40: 51 4c 69 74 65 45 78 63 65 70 74 69 6f 6e 28 6e QLiteException(n
3f50: 2c 20 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 , GetLastError()
3f60: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 );..
3f70: 7d 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 65 }.. e
3f80: 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 20 20 20 lse..
3f90: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
3fa0: 20 20 2f 2f 20 4f 74 68 65 72 77 69 73 65 20 73 // Otherwise s
3fb0: 6c 65 65 70 20 66 6f 72 20 61 20 72 61 6e 64 6f leep for a rando
3fc0: 6d 20 61 6d 6f 75 6e 74 20 6f 66 20 74 69 6d 65 m amount of time
3fd0: 20 75 70 20 74 6f 20 31 35 30 6d 73 0d 0a 20 20 up to 150ms..
3fe0: 20 20 20 20 20 20 20 20 20 20 20 20 53 79 73 74 Syst
3ff0: 65 6d 2e 54 68 72 65 61 64 69 6e 67 2e 54 68 72 em.Threading.Thr
4000: 65 61 64 2e 53 6c 65 65 70 28 72 6e 64 2e 4e 65 ead.Sleep(rnd.Ne
4010: 78 74 28 31 2c 20 31 35 30 29 29 3b 0d 0a 20 20 xt(1, 150));..
4020: 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 }..
4030: 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 }..
4040: 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 }.... i
4050: 66 20 28 6e 20 3e 20 30 29 20 74 68 72 6f 77 20 f (n > 0) throw
4060: 6e 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 74 new SQLiteExcept
4070: 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 72 ion(n, GetLastEr
4080: 72 6f 72 28 29 29 3b 0d 0a 0d 0a 20 20 20 20 20 ror());....
4090: 20 20 20 73 74 72 52 65 6d 61 69 6e 20 3d 20 55 strRemain = U
40a0: 54 46 38 54 6f 53 74 72 69 6e 67 28 70 74 72 2c TF8ToString(ptr,
40b0: 20 6c 65 6e 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 len);....
40c0: 20 20 69 66 20 28 73 74 6d 74 20 21 3d 20 49 6e if (stmt != In
40d0: 74 50 74 72 2e 5a 65 72 6f 29 20 63 6d 64 20 3d tPtr.Zero) cmd =
40e0: 20 6e 65 77 20 53 51 4c 69 74 65 53 74 61 74 65 new SQLiteState
40f0: 6d 65 6e 74 28 74 68 69 73 2c 20 66 6c 61 67 73 ment(this, flags
4100: 2c 20 6e 65 77 20 53 51 4c 69 74 65 53 74 61 74 , new SQLiteStat
4110: 65 6d 65 6e 74 48 61 6e 64 6c 65 28 73 74 6d 74 ementHandle(stmt
4120: 29 2c 20 73 74 72 53 71 6c 2e 53 75 62 73 74 72 ), strSql.Substr
4130: 69 6e 67 28 30 2c 20 73 74 72 53 71 6c 2e 4c 65 ing(0, strSql.Le
4140: 6e 67 74 68 20 2d 20 73 74 72 52 65 6d 61 69 6e ngth - strRemain
4150: 2e 4c 65 6e 67 74 68 29 2c 20 70 72 65 76 69 6f .Length), previo
4160: 75 73 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 us);....
4170: 72 65 74 75 72 6e 20 63 6d 64 3b 0d 0a 20 20 20 return cmd;..
4180: 20 20 20 7d 0d 0a 20 20 20 20 20 20 66 69 6e 61 }.. fina
4190: 6c 6c 79 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 20 lly.. {..
41a0: 20 20 20 20 20 20 68 61 6e 64 6c 65 2e 46 72 65 handle.Fre
41b0: 65 28 29 3b 0d 0a 20 20 20 20 20 20 7d 0d 0a 20 e();.. }..
41c0: 20 20 20 7d 0d 0a 0d 0a 23 69 66 20 21 50 4c 41 }....#if !PLA
41d0: 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 41 TFORM_COMPACTFRA
41e0: 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 70 72 6f 74 MEWORK.. prot
41f0: 65 63 74 65 64 20 73 74 61 74 69 63 20 76 6f 69 ected static voi
4200: 64 20 4c 6f 67 42 69 6e 64 28 53 51 4c 69 74 65 d LogBind(SQLite
4210: 53 74 61 74 65 6d 65 6e 74 48 61 6e 64 6c 65 20 StatementHandle
4220: 68 61 6e 64 6c 65 2c 20 69 6e 74 20 69 6e 64 65 handle, int inde
4230: 78 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 x).. {..
4240: 20 20 20 49 6e 74 50 74 72 20 68 61 6e 64 6c 65 IntPtr handle
4250: 49 6e 74 50 74 72 20 3d 20 68 61 6e 64 6c 65 3b IntPtr = handle;
4260: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 53 51 4c 69 .... SQLi
4270: 74 65 4c 6f 67 2e 4c 6f 67 4d 65 73 73 61 67 65 teLog.LogMessage
4280: 28 30 2c 20 53 74 72 69 6e 67 2e 46 6f 72 6d 61 (0, String.Forma
4290: 74 28 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 t(..
42a0: 22 42 69 6e 64 69 6e 67 20 73 74 61 74 65 6d 65 "Binding stateme
42b0: 6e 74 20 7b 30 7d 20 70 61 72 61 6d 74 65 72 20 nt {0} paramter
42c0: 23 7b 31 7d 20 61 73 20 4e 55 4c 4c 2e 2e 2e 22 #{1} as NULL..."
42d0: 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 68 ,.. h
42e0: 61 6e 64 6c 65 49 6e 74 50 74 72 2c 20 69 6e 64 andleIntPtr, ind
42f0: 65 78 29 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a ex));.. }....
4300: 20 20 20 20 70 72 6f 74 65 63 74 65 64 20 73 74 protected st
4310: 61 74 69 63 20 76 6f 69 64 20 4c 6f 67 42 69 6e atic void LogBin
4320: 64 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e d(SQLiteStatemen
4330: 74 48 61 6e 64 6c 65 20 68 61 6e 64 6c 65 2c 20 tHandle handle,
4340: 69 6e 74 20 69 6e 64 65 78 2c 20 56 61 6c 75 65 int index, Value
4350: 54 79 70 65 20 76 61 6c 75 65 29 0d 0a 20 20 20 Type value)..
4360: 20 7b 0d 0a 20 20 20 20 20 20 20 20 49 6e 74 50 {.. IntP
4370: 74 72 20 68 61 6e 64 6c 65 49 6e 74 50 74 72 20 tr handleIntPtr
4380: 3d 20 68 61 6e 64 6c 65 3b 0d 0a 0d 0a 20 20 20 = handle;....
4390: 20 20 20 20 20 53 51 4c 69 74 65 4c 6f 67 2e 4c SQLiteLog.L
43a0: 6f 67 4d 65 73 73 61 67 65 28 30 2c 20 53 74 72 ogMessage(0, Str
43b0: 69 6e 67 2e 46 6f 72 6d 61 74 28 0d 0a 20 20 20 ing.Format(..
43c0: 20 20 20 20 20 20 20 20 20 22 42 69 6e 64 69 6e "Bindin
43d0: 67 20 73 74 61 74 65 6d 65 6e 74 20 7b 30 7d 20 g statement {0}
43e0: 70 61 72 61 6d 74 65 72 20 23 7b 31 7d 20 61 73 paramter #{1} as
43f0: 20 74 79 70 65 20 7b 32 7d 20 77 69 74 68 20 76 type {2} with v
4400: 61 6c 75 65 20 7b 7b 7b 33 7d 7d 7d 2e 2e 2e 22 alue {{{3}}}..."
4410: 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 68 ,.. h
4420: 61 6e 64 6c 65 49 6e 74 50 74 72 2c 20 69 6e 64 andleIntPtr, ind
4430: 65 78 2c 20 76 61 6c 75 65 2e 47 65 74 54 79 70 ex, value.GetTyp
4440: 65 28 29 2c 20 76 61 6c 75 65 29 29 3b 0d 0a 20 e(), value));..
4450: 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 70 72 69 76 }.... priv
4460: 61 74 65 20 73 74 61 74 69 63 20 73 74 72 69 6e ate static strin
4470: 67 20 46 6f 72 6d 61 74 44 61 74 65 54 69 6d 65 g FormatDateTime
4480: 28 44 61 74 65 54 69 6d 65 20 76 61 6c 75 65 29 (DateTime value)
4490: 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 .. {..
44a0: 20 53 74 72 69 6e 67 42 75 69 6c 64 65 72 20 72 StringBuilder r
44b0: 65 73 75 6c 74 20 3d 20 6e 65 77 20 53 74 72 69 esult = new Stri
44c0: 6e 67 42 75 69 6c 64 65 72 28 29 3b 0d 0a 0d 0a ngBuilder();....
44d0: 20 20 20 20 20 20 20 20 72 65 73 75 6c 74 2e 41 result.A
44e0: 70 70 65 6e 64 28 76 61 6c 75 65 2e 54 6f 53 74 ppend(value.ToSt
44f0: 72 69 6e 67 28 22 79 79 79 79 2d 4d 4d 2d 64 64 ring("yyyy-MM-dd
4500: 54 48 48 3a 6d 6d 3a 73 73 2e 46 46 46 46 46 46 THH:mm:ss.FFFFFF
4510: 46 4b 22 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 FK"));..
4520: 72 65 73 75 6c 74 2e 41 70 70 65 6e 64 28 27 20 result.Append('
4530: 27 29 3b 0d 0a 20 20 20 20 20 20 20 20 72 65 73 ');.. res
4540: 75 6c 74 2e 41 70 70 65 6e 64 28 76 61 6c 75 65 ult.Append(value
4550: 2e 4b 69 6e 64 29 3b 0d 0a 20 20 20 20 20 20 20 .Kind);..
4560: 20 72 65 73 75 6c 74 2e 41 70 70 65 6e 64 28 27 result.Append('
4570: 20 27 29 3b 0d 0a 20 20 20 20 20 20 20 20 72 65 ');.. re
4580: 73 75 6c 74 2e 41 70 70 65 6e 64 28 76 61 6c 75 sult.Append(valu
4590: 65 2e 54 69 63 6b 73 29 3b 0d 0a 0d 0a 20 20 20 e.Ticks);....
45a0: 20 20 20 20 20 72 65 74 75 72 6e 20 72 65 73 75 return resu
45b0: 6c 74 2e 54 6f 53 74 72 69 6e 67 28 29 3b 0d 0a lt.ToString();..
45c0: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 70 72 6f }.... pro
45d0: 74 65 63 74 65 64 20 73 74 61 74 69 63 20 76 6f tected static vo
45e0: 69 64 20 4c 6f 67 42 69 6e 64 28 53 51 4c 69 74 id LogBind(SQLit
45f0: 65 53 74 61 74 65 6d 65 6e 74 48 61 6e 64 6c 65 eStatementHandle
4600: 20 68 61 6e 64 6c 65 2c 20 69 6e 74 20 69 6e 64 handle, int ind
4610: 65 78 2c 20 44 61 74 65 54 69 6d 65 20 76 61 6c ex, DateTime val
4620: 75 65 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 ue).. {..
4630: 20 20 20 20 49 6e 74 50 74 72 20 68 61 6e 64 6c IntPtr handl
4640: 65 49 6e 74 50 74 72 20 3d 20 68 61 6e 64 6c 65 eIntPtr = handle
4650: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 53 51 4c ;.... SQL
4660: 69 74 65 4c 6f 67 2e 4c 6f 67 4d 65 73 73 61 67 iteLog.LogMessag
4670: 65 28 30 2c 20 53 74 72 69 6e 67 2e 46 6f 72 6d e(0, String.Form
4680: 61 74 28 0d 0a 20 20 20 20 20 20 20 20 20 20 20 at(..
4690: 20 22 42 69 6e 64 69 6e 67 20 73 74 61 74 65 6d "Binding statem
46a0: 65 6e 74 20 7b 30 7d 20 70 61 72 61 6d 74 65 72 ent {0} paramter
46b0: 20 23 7b 31 7d 20 61 73 20 74 79 70 65 20 7b 32 #{1} as type {2
46c0: 7d 20 77 69 74 68 20 76 61 6c 75 65 20 7b 7b 7b } with value {{{
46d0: 33 7d 7d 7d 2e 2e 2e 22 2c 0d 0a 20 20 20 20 20 3}}}...",..
46e0: 20 20 20 20 20 20 20 68 61 6e 64 6c 65 49 6e 74 handleInt
46f0: 50 74 72 2c 20 69 6e 64 65 78 2c 20 74 79 70 65 Ptr, index, type
4700: 6f 66 28 44 61 74 65 54 69 6d 65 29 2c 20 46 6f of(DateTime), Fo
4710: 72 6d 61 74 44 61 74 65 54 69 6d 65 28 76 61 6c rmatDateTime(val
4720: 75 65 29 29 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d ue)));.. }...
4730: 0a 20 20 20 20 70 72 6f 74 65 63 74 65 64 20 73 . protected s
4740: 74 61 74 69 63 20 76 6f 69 64 20 4c 6f 67 42 69 tatic void LogBi
4750: 6e 64 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 nd(SQLiteStateme
4760: 6e 74 48 61 6e 64 6c 65 20 68 61 6e 64 6c 65 2c ntHandle handle,
4770: 20 69 6e 74 20 69 6e 64 65 78 2c 20 73 74 72 69 int index, stri
4780: 6e 67 20 76 61 6c 75 65 29 0d 0a 20 20 20 20 7b ng value).. {
4790: 0d 0a 20 20 20 20 20 20 20 20 49 6e 74 50 74 72 .. IntPtr
47a0: 20 68 61 6e 64 6c 65 49 6e 74 50 74 72 20 3d 20 handleIntPtr =
47b0: 68 61 6e 64 6c 65 3b 0d 0a 0d 0a 20 20 20 20 20 handle;....
47c0: 20 20 20 53 51 4c 69 74 65 4c 6f 67 2e 4c 6f 67 SQLiteLog.Log
47d0: 4d 65 73 73 61 67 65 28 30 2c 20 53 74 72 69 6e Message(0, Strin
47e0: 67 2e 46 6f 72 6d 61 74 28 0d 0a 20 20 20 20 20 g.Format(..
47f0: 20 20 20 20 20 20 20 22 42 69 6e 64 69 6e 67 20 "Binding
4800: 73 74 61 74 65 6d 65 6e 74 20 7b 30 7d 20 70 61 statement {0} pa
4810: 72 61 6d 74 65 72 20 23 7b 31 7d 20 61 73 20 74 ramter #{1} as t
4820: 79 70 65 20 7b 32 7d 20 77 69 74 68 20 76 61 6c ype {2} with val
4830: 75 65 20 7b 7b 7b 33 7d 7d 7d 2e 2e 2e 22 2c 0d ue {{{3}}}...",.
4840: 0a 20 20 20 20 20 20 20 20 20 20 20 20 68 61 6e . han
4850: 64 6c 65 49 6e 74 50 74 72 2c 20 69 6e 64 65 78 dleIntPtr, index
4860: 2c 20 74 79 70 65 6f 66 28 53 74 72 69 6e 67 29 , typeof(String)
4870: 2c 20 28 76 61 6c 75 65 20 21 3d 20 6e 75 6c 6c , (value != null
4880: 29 20 3f 20 76 61 6c 75 65 20 3a 20 22 3c 6e 75 ) ? value : "<nu
4890: 6c 6c 3e 22 29 29 3b 0d 0a 20 20 20 20 7d 0d 0a ll>"));.. }..
48a0: 0d 0a 20 20 20 20 70 72 69 76 61 74 65 20 73 74 .. private st
48b0: 61 74 69 63 20 73 74 72 69 6e 67 20 54 6f 48 65 atic string ToHe
48c0: 78 61 64 65 63 69 6d 61 6c 53 74 72 69 6e 67 28 xadecimalString(
48d0: 0d 0a 20 20 20 20 20 20 20 20 62 79 74 65 5b 5d .. byte[]
48e0: 20 61 72 72 61 79 0d 0a 20 20 20 20 20 20 20 20 array..
48f0: 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 ).. {..
4900: 20 20 69 66 20 28 61 72 72 61 79 20 3d 3d 20 6e if (array == n
4910: 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 20 ull)..
4920: 20 20 72 65 74 75 72 6e 20 6e 75 6c 6c 3b 0d 0a return null;..
4930: 0d 0a 20 20 20 20 20 20 20 20 53 74 72 69 6e 67 .. String
4940: 42 75 69 6c 64 65 72 20 72 65 73 75 6c 74 20 3d Builder result =
4950: 20 6e 65 77 20 53 74 72 69 6e 67 42 75 69 6c 64 new StringBuild
4960: 65 72 28 61 72 72 61 79 2e 4c 65 6e 67 74 68 20 er(array.Length
4970: 2a 20 32 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 * 2);....
4980: 20 69 6e 74 20 6c 65 6e 67 74 68 20 3d 20 61 72 int length = ar
4990: 72 61 79 2e 4c 65 6e 67 74 68 3b 0d 0a 0d 0a 20 ray.Length;....
49a0: 20 20 20 20 20 20 20 66 6f 72 20 28 69 6e 74 20 for (int
49b0: 69 6e 64 65 78 20 3d 20 30 3b 20 69 6e 64 65 78 index = 0; index
49c0: 20 3c 20 6c 65 6e 67 74 68 3b 20 69 6e 64 65 78 < length; index
49d0: 2b 2b 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ++)..
49e0: 20 72 65 73 75 6c 74 2e 41 70 70 65 6e 64 28 61 result.Append(a
49f0: 72 72 61 79 5b 69 6e 64 65 78 5d 2e 54 6f 53 74 rray[index].ToSt
4a00: 72 69 6e 67 28 22 78 32 22 29 29 3b 0d 0a 0d 0a ring("x2"));....
4a10: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 72 return r
4a20: 65 73 75 6c 74 2e 54 6f 53 74 72 69 6e 67 28 29 esult.ToString()
4a30: 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 ;.. }....
4a40: 70 72 6f 74 65 63 74 65 64 20 73 74 61 74 69 63 protected static
4a50: 20 76 6f 69 64 20 4c 6f 67 42 69 6e 64 28 53 51 void LogBind(SQ
4a60: 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 48 61 6e LiteStatementHan
4a70: 64 6c 65 20 68 61 6e 64 6c 65 2c 20 69 6e 74 20 dle handle, int
4a80: 69 6e 64 65 78 2c 20 62 79 74 65 5b 5d 20 76 61 index, byte[] va
4a90: 6c 75 65 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 lue).. {..
4aa0: 20 20 20 20 20 49 6e 74 50 74 72 20 68 61 6e 64 IntPtr hand
4ab0: 6c 65 49 6e 74 50 74 72 20 3d 20 68 61 6e 64 6c leIntPtr = handl
4ac0: 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 53 51 e;.... SQ
4ad0: 4c 69 74 65 4c 6f 67 2e 4c 6f 67 4d 65 73 73 61 LiteLog.LogMessa
4ae0: 67 65 28 30 2c 20 53 74 72 69 6e 67 2e 46 6f 72 ge(0, String.For
4af0: 6d 61 74 28 0d 0a 20 20 20 20 20 20 20 20 20 20 mat(..
4b00: 20 20 22 42 69 6e 64 69 6e 67 20 73 74 61 74 65 "Binding state
4b10: 6d 65 6e 74 20 7b 30 7d 20 70 61 72 61 6d 74 65 ment {0} paramte
4b20: 72 20 23 7b 31 7d 20 61 73 20 74 79 70 65 20 7b r #{1} as type {
4b30: 32 7d 20 77 69 74 68 20 76 61 6c 75 65 20 7b 7b 2} with value {{
4b40: 7b 33 7d 7d 7d 2e 2e 2e 22 2c 0d 0a 20 20 20 20 {3}}}...",..
4b50: 20 20 20 20 20 20 20 20 68 61 6e 64 6c 65 49 6e handleIn
4b60: 74 50 74 72 2c 20 69 6e 64 65 78 2c 20 74 79 70 tPtr, index, typ
4b70: 65 6f 66 28 42 79 74 65 5b 5d 29 2c 20 28 76 61 eof(Byte[]), (va
4b80: 6c 75 65 20 21 3d 20 6e 75 6c 6c 29 20 3f 20 54 lue != null) ? T
4b90: 6f 48 65 78 61 64 65 63 69 6d 61 6c 53 74 72 69 oHexadecimalStri
4ba0: 6e 67 28 76 61 6c 75 65 29 20 3a 20 22 3c 6e 75 ng(value) : "<nu
4bb0: 6c 6c 3e 22 29 29 3b 0d 0a 20 20 20 20 7d 0d 0a ll>"));.. }..
4bc0: 23 65 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 69 6e #endif.... in
4bd0: 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 ternal override
4be0: 76 6f 69 64 20 42 69 6e 64 5f 44 6f 75 62 6c 65 void Bind_Double
4bf0: 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 (SQLiteStatement
4c00: 20 73 74 6d 74 2c 20 53 51 4c 69 74 65 43 6f 6e stmt, SQLiteCon
4c10: 6e 65 63 74 69 6f 6e 46 6c 61 67 73 20 66 6c 61 nectionFlags fla
4c20: 67 73 2c 20 69 6e 74 20 69 6e 64 65 78 2c 20 64 gs, int index, d
4c30: 6f 75 62 6c 65 20 76 61 6c 75 65 29 0d 0a 20 20 ouble value)..
4c40: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 53 51 4c {.. SQL
4c50: 69 74 65 53 74 61 74 65 6d 65 6e 74 48 61 6e 64 iteStatementHand
4c60: 6c 65 20 68 61 6e 64 6c 65 20 3d 20 73 74 6d 74 le handle = stmt
4c70: 2e 5f 73 71 6c 69 74 65 5f 73 74 6d 74 3b 0d 0a ._sqlite_stmt;..
4c80: 0d 0a 23 69 66 20 21 50 4c 41 54 46 4f 52 4d 5f ..#if !PLATFORM_
4c90: 43 4f 4d 50 41 43 54 46 52 41 4d 45 57 4f 52 4b COMPACTFRAMEWORK
4ca0: 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 28 66 .. if ((f
4cb0: 6c 61 67 73 20 26 20 53 51 4c 69 74 65 43 6f 6e lags & SQLiteCon
4cc0: 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 nectionFlags.Log
4cd0: 42 69 6e 64 29 20 3d 3d 20 53 51 4c 69 74 65 43 Bind) == SQLiteC
4ce0: 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2e 4c onnectionFlags.L
4cf0: 6f 67 42 69 6e 64 29 0d 0a 20 20 20 20 20 20 20 ogBind)..
4d00: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
4d10: 4c 6f 67 42 69 6e 64 28 68 61 6e 64 6c 65 2c 20 LogBind(handle,
4d20: 69 6e 64 65 78 2c 20 76 61 6c 75 65 29 3b 0d 0a index, value);..
4d30: 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 }....
4d40: 20 20 20 20 20 69 6e 74 20 6e 20 3d 20 55 6e 73 int n = Uns
4d50: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
4d60: 2e 73 71 6c 69 74 65 33 5f 62 69 6e 64 5f 64 6f .sqlite3_bind_do
4d70: 75 62 6c 65 28 68 61 6e 64 6c 65 2c 20 69 6e 64 uble(handle, ind
4d80: 65 78 2c 20 76 61 6c 75 65 29 3b 0d 0a 23 65 6c ex, value);..#el
4d90: 73 65 0d 0a 20 20 20 20 20 20 20 20 69 6e 74 20 se.. int
4da0: 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 n = UnsafeNative
4db0: 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f Methods.sqlite3_
4dc0: 62 69 6e 64 5f 64 6f 75 62 6c 65 5f 69 6e 74 65 bind_double_inte
4dd0: 72 6f 70 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 rop(handle, inde
4de0: 78 2c 20 72 65 66 20 76 61 6c 75 65 29 3b 0d 0a x, ref value);..
4df0: 23 65 6e 64 69 66 0d 0a 20 20 20 20 20 20 20 20 #endif..
4e00: 69 66 20 28 6e 20 3e 20 30 29 20 74 68 72 6f 77 if (n > 0) throw
4e10: 20 6e 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 new SQLiteExcep
4e20: 74 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 tion(n, GetLastE
4e30: 72 72 6f 72 28 29 29 3b 0d 0a 20 20 20 20 7d 0d rror());.. }.
4e40: 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 ... internal
4e50: 6f 76 65 72 72 69 64 65 20 76 6f 69 64 20 42 69 override void Bi
4e60: 6e 64 5f 49 6e 74 33 32 28 53 51 4c 69 74 65 53 nd_Int32(SQLiteS
4e70: 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 53 tatement stmt, S
4e80: 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 QLiteConnectionF
4e90: 6c 61 67 73 20 66 6c 61 67 73 2c 20 69 6e 74 20 lags flags, int
4ea0: 69 6e 64 65 78 2c 20 69 6e 74 20 76 61 6c 75 65 index, int value
4eb0: 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 ).. {..
4ec0: 20 20 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e SQLiteStatemen
4ed0: 74 48 61 6e 64 6c 65 20 68 61 6e 64 6c 65 20 3d tHandle handle =
4ee0: 20 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 stmt._sqlite_st
4ef0: 6d 74 3b 0d 0a 0d 0a 23 69 66 20 21 50 4c 41 54 mt;....#if !PLAT
4f00: 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 41 4d FORM_COMPACTFRAM
4f10: 45 57 4f 52 4b 0d 0a 20 20 20 20 20 20 20 20 69 EWORK.. i
4f20: 66 20 28 28 66 6c 61 67 73 20 26 20 53 51 4c 69 f ((flags & SQLi
4f30: 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 teConnectionFlag
4f40: 73 2e 4c 6f 67 42 69 6e 64 29 20 3d 3d 20 53 51 s.LogBind) == SQ
4f50: 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c LiteConnectionFl
4f60: 61 67 73 2e 4c 6f 67 42 69 6e 64 29 0d 0a 20 20 ags.LogBind)..
4f70: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
4f80: 20 20 20 20 20 4c 6f 67 42 69 6e 64 28 68 61 6e LogBind(han
4f90: 64 6c 65 2c 20 69 6e 64 65 78 2c 20 76 61 6c 75 dle, index, valu
4fa0: 65 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a e);.. }..
4fb0: 23 65 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 20 20 #endif....
4fc0: 20 20 69 6e 74 20 6e 20 3d 20 55 6e 73 61 66 65 int n = Unsafe
4fd0: 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 NativeMethods.sq
4fe0: 6c 69 74 65 33 5f 62 69 6e 64 5f 69 6e 74 28 68 lite3_bind_int(h
4ff0: 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 76 61 andle, index, va
5000: 6c 75 65 29 3b 0d 0a 20 20 20 20 20 20 20 20 69 lue);.. i
5010: 66 20 28 6e 20 3e 20 30 29 20 74 68 72 6f 77 20 f (n > 0) throw
5020: 6e 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 74 new SQLiteExcept
5030: 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 72 ion(n, GetLastEr
5040: 72 6f 72 28 29 29 3b 0d 0a 20 20 20 20 7d 0d 0a ror());.. }..
5050: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
5060: 76 65 72 72 69 64 65 20 76 6f 69 64 20 42 69 6e verride void Bin
5070: 64 5f 55 49 6e 74 33 32 28 53 51 4c 69 74 65 53 d_UInt32(SQLiteS
5080: 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 53 tatement stmt, S
5090: 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 QLiteConnectionF
50a0: 6c 61 67 73 20 66 6c 61 67 73 2c 20 69 6e 74 20 lags flags, int
50b0: 69 6e 64 65 78 2c 20 75 69 6e 74 20 76 61 6c 75 index, uint valu
50c0: 65 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 e).. {..
50d0: 20 20 20 53 51 4c 69 74 65 53 74 61 74 65 6d 65 SQLiteStateme
50e0: 6e 74 48 61 6e 64 6c 65 20 68 61 6e 64 6c 65 20 ntHandle handle
50f0: 3d 20 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 = stmt._sqlite_s
5100: 74 6d 74 3b 0d 0a 0d 0a 23 69 66 20 21 50 4c 41 tmt;....#if !PLA
5110: 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 41 TFORM_COMPACTFRA
5120: 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 20 20 20 20 MEWORK..
5130: 69 66 20 28 28 66 6c 61 67 73 20 26 20 53 51 4c if ((flags & SQL
5140: 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 iteConnectionFla
5150: 67 73 2e 4c 6f 67 42 69 6e 64 29 20 3d 3d 20 53 gs.LogBind) == S
5160: 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 QLiteConnectionF
5170: 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 0d 0a 20 lags.LogBind)..
5180: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
5190: 20 20 20 20 20 20 4c 6f 67 42 69 6e 64 28 68 61 LogBind(ha
51a0: 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 76 61 6c ndle, index, val
51b0: 75 65 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d ue);.. }.
51c0: 0a 23 65 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 20 .#endif....
51d0: 20 20 20 69 6e 74 20 6e 20 3d 20 55 6e 73 61 66 int n = Unsaf
51e0: 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
51f0: 71 6c 69 74 65 33 5f 62 69 6e 64 5f 75 69 6e 74 qlite3_bind_uint
5200: 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 (handle, index,
5210: 76 61 6c 75 65 29 3b 0d 0a 20 20 20 20 20 20 20 value);..
5220: 20 69 66 20 28 6e 20 3e 20 30 29 20 74 68 72 6f if (n > 0) thro
5230: 77 20 6e 65 77 20 53 51 4c 69 74 65 45 78 63 65 w new SQLiteExce
5240: 70 74 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 74 ption(n, GetLast
5250: 45 72 72 6f 72 28 29 29 3b 0d 0a 20 20 20 20 7d Error());.. }
5260: 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c .... internal
5270: 20 6f 76 65 72 72 69 64 65 20 76 6f 69 64 20 42 override void B
5280: 69 6e 64 5f 49 6e 74 36 34 28 53 51 4c 69 74 65 ind_Int64(SQLite
5290: 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 Statement stmt,
52a0: 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e SQLiteConnection
52b0: 46 6c 61 67 73 20 66 6c 61 67 73 2c 20 69 6e 74 Flags flags, int
52c0: 20 69 6e 64 65 78 2c 20 6c 6f 6e 67 20 76 61 6c index, long val
52d0: 75 65 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 ue).. {..
52e0: 20 20 20 20 53 51 4c 69 74 65 53 74 61 74 65 6d SQLiteStatem
52f0: 65 6e 74 48 61 6e 64 6c 65 20 68 61 6e 64 6c 65 entHandle handle
5300: 20 3d 20 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f = stmt._sqlite_
5310: 73 74 6d 74 3b 0d 0a 0d 0a 23 69 66 20 21 50 4c stmt;....#if !PL
5320: 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 ATFORM_COMPACTFR
5330: 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 20 20 20 AMEWORK..
5340: 20 69 66 20 28 28 66 6c 61 67 73 20 26 20 53 51 if ((flags & SQ
5350: 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c LiteConnectionFl
5360: 61 67 73 2e 4c 6f 67 42 69 6e 64 29 20 3d 3d 20 ags.LogBind) ==
5370: 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e SQLiteConnection
5380: 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 0d 0a Flags.LogBind)..
5390: 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 {..
53a0: 20 20 20 20 20 20 20 4c 6f 67 42 69 6e 64 28 68 LogBind(h
53b0: 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 76 61 andle, index, va
53c0: 6c 75 65 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d lue);.. }
53d0: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 6e 74 20 .... int
53e0: 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 n = UnsafeNative
53f0: 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f Methods.sqlite3_
5400: 62 69 6e 64 5f 69 6e 74 36 34 28 68 61 6e 64 6c bind_int64(handl
5410: 65 2c 20 69 6e 64 65 78 2c 20 76 61 6c 75 65 29 e, index, value)
5420: 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 ;..#else..
5430: 20 20 69 6e 74 20 6e 20 3d 20 55 6e 73 61 66 65 int n = Unsafe
5440: 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 NativeMethods.sq
5450: 6c 69 74 65 33 5f 62 69 6e 64 5f 69 6e 74 36 34 lite3_bind_int64
5460: 5f 69 6e 74 65 72 6f 70 28 68 61 6e 64 6c 65 2c _interop(handle,
5470: 20 69 6e 64 65 78 2c 20 72 65 66 20 76 61 6c 75 index, ref valu
5480: 65 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 e);..#endif..
5490: 20 20 20 20 20 69 66 20 28 6e 20 3e 20 30 29 20 if (n > 0)
54a0: 74 68 72 6f 77 20 6e 65 77 20 53 51 4c 69 74 65 throw new SQLite
54b0: 45 78 63 65 70 74 69 6f 6e 28 6e 2c 20 47 65 74 Exception(n, Get
54c0: 4c 61 73 74 45 72 72 6f 72 28 29 29 3b 0d 0a 20 LastError());..
54d0: 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 }.... inte
54e0: 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 76 6f rnal override vo
54f0: 69 64 20 42 69 6e 64 5f 55 49 6e 74 36 34 28 53 id Bind_UInt64(S
5500: 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 20 73 QLiteStatement s
5510: 74 6d 74 2c 20 53 51 4c 69 74 65 43 6f 6e 6e 65 tmt, SQLiteConne
5520: 63 74 69 6f 6e 46 6c 61 67 73 20 66 6c 61 67 73 ctionFlags flags
5530: 2c 20 69 6e 74 20 69 6e 64 65 78 2c 20 75 6c 6f , int index, ulo
5540: 6e 67 20 76 61 6c 75 65 29 0d 0a 20 20 20 20 7b ng value).. {
5550: 0d 0a 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 .. SQLite
5560: 53 74 61 74 65 6d 65 6e 74 48 61 6e 64 6c 65 20 StatementHandle
5570: 68 61 6e 64 6c 65 20 3d 20 73 74 6d 74 2e 5f 73 handle = stmt._s
5580: 71 6c 69 74 65 5f 73 74 6d 74 3b 0d 0a 0d 0a 23 qlite_stmt;....#
5590: 69 66 20 21 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d if !PLATFORM_COM
55a0: 50 41 43 54 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 PACTFRAMEWORK..
55b0: 20 20 20 20 20 20 20 69 66 20 28 28 66 6c 61 67 if ((flag
55c0: 73 20 26 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 s & SQLiteConnec
55d0: 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e tionFlags.LogBin
55e0: 64 29 20 3d 3d 20 53 51 4c 69 74 65 43 6f 6e 6e d) == SQLiteConn
55f0: 65 63 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 ectionFlags.LogB
5600: 69 6e 64 29 0d 0a 20 20 20 20 20 20 20 20 7b 0d ind).. {.
5610: 0a 20 20 20 20 20 20 20 20 20 20 20 20 4c 6f 67 . Log
5620: 42 69 6e 64 28 68 61 6e 64 6c 65 2c 20 69 6e 64 Bind(handle, ind
5630: 65 78 2c 20 76 61 6c 75 65 29 3b 0d 0a 20 20 20 ex, value);..
5640: 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 }....
5650: 20 20 69 6e 74 20 6e 20 3d 20 55 6e 73 61 66 65 int n = Unsafe
5660: 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 NativeMethods.sq
5670: 6c 69 74 65 33 5f 62 69 6e 64 5f 75 69 6e 74 36 lite3_bind_uint6
5680: 34 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 4(handle, index,
5690: 20 76 61 6c 75 65 29 3b 0d 0a 23 65 6c 73 65 0d value);..#else.
56a0: 0a 20 20 20 20 20 20 20 20 69 6e 74 20 6e 20 3d . int n =
56b0: 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 UnsafeNativeMet
56c0: 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 62 69 6e hods.sqlite3_bin
56d0: 64 5f 75 69 6e 74 36 34 5f 69 6e 74 65 72 6f 70 d_uint64_interop
56e0: 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 (handle, index,
56f0: 72 65 66 20 76 61 6c 75 65 29 3b 0d 0a 23 65 6e ref value);..#en
5700: 64 69 66 0d 0a 20 20 20 20 20 20 20 20 69 66 20 dif.. if
5710: 28 6e 20 3e 20 30 29 20 74 68 72 6f 77 20 6e 65 (n > 0) throw ne
5720: 77 20 53 51 4c 69 74 65 45 78 63 65 70 74 69 6f w SQLiteExceptio
5730: 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 72 72 6f n(n, GetLastErro
5740: 72 28 29 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a r());.. }....
5750: 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 internal ove
5760: 72 72 69 64 65 20 76 6f 69 64 20 42 69 6e 64 5f rride void Bind_
5770: 54 65 78 74 28 53 51 4c 69 74 65 53 74 61 74 65 Text(SQLiteState
5780: 6d 65 6e 74 20 73 74 6d 74 2c 20 53 51 4c 69 74 ment stmt, SQLit
5790: 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 eConnectionFlags
57a0: 20 66 6c 61 67 73 2c 20 69 6e 74 20 69 6e 64 65 flags, int inde
57b0: 78 2c 20 73 74 72 69 6e 67 20 76 61 6c 75 65 29 x, string value)
57c0: 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 .. {..
57d0: 20 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 SQLiteStatement
57e0: 48 61 6e 64 6c 65 20 68 61 6e 64 6c 65 20 3d 20 Handle handle =
57f0: 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 6d stmt._sqlite_stm
5800: 74 3b 0d 0a 0d 0a 23 69 66 20 21 50 4c 41 54 46 t;....#if !PLATF
5810: 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 41 4d 45 ORM_COMPACTFRAME
5820: 57 4f 52 4b 0d 0a 20 20 20 20 20 20 20 20 69 66 WORK.. if
5830: 20 28 28 66 6c 61 67 73 20 26 20 53 51 4c 69 74 ((flags & SQLit
5840: 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 eConnectionFlags
5850: 2e 4c 6f 67 42 69 6e 64 29 20 3d 3d 20 53 51 4c .LogBind) == SQL
5860: 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 iteConnectionFla
5870: 67 73 2e 4c 6f 67 42 69 6e 64 29 0d 0a 20 20 20 gs.LogBind)..
5880: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
5890: 20 20 20 20 4c 6f 67 42 69 6e 64 28 68 61 6e 64 LogBind(hand
58a0: 6c 65 2c 20 69 6e 64 65 78 2c 20 76 61 6c 75 65 le, index, value
58b0: 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a 23 );.. }..#
58c0: 65 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 20 20 20 endif....
58d0: 20 62 79 74 65 5b 5d 20 62 20 3d 20 54 6f 55 54 byte[] b = ToUT
58e0: 46 38 28 76 61 6c 75 65 29 3b 0d 0a 0d 0a 23 69 F8(value);....#i
58f0: 66 20 21 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d 50 f !PLATFORM_COMP
5900: 41 43 54 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 20 ACTFRAMEWORK..
5910: 20 20 20 20 20 20 69 66 20 28 28 66 6c 61 67 73 if ((flags
5920: 20 26 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 & SQLiteConnect
5930: 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 ionFlags.LogBind
5940: 29 20 3d 3d 20 53 51 4c 69 74 65 43 6f 6e 6e 65 ) == SQLiteConne
5950: 63 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 ctionFlags.LogBi
5960: 6e 64 29 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a nd).. {..
5970: 20 20 20 20 20 20 20 20 20 20 20 20 4c 6f 67 42 LogB
5980: 69 6e 64 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 ind(handle, inde
5990: 78 2c 20 62 29 3b 0d 0a 20 20 20 20 20 20 20 20 x, b);..
59a0: 7d 0d 0a 23 65 6e 64 69 66 0d 0a 0d 0a 20 20 20 }..#endif....
59b0: 20 20 20 20 20 69 6e 74 20 6e 20 3d 20 55 6e 73 int n = Uns
59c0: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
59d0: 2e 73 71 6c 69 74 65 33 5f 62 69 6e 64 5f 74 65 .sqlite3_bind_te
59e0: 78 74 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 xt(handle, index
59f0: 2c 20 62 2c 20 62 2e 4c 65 6e 67 74 68 20 2d 20 , b, b.Length -
5a00: 31 2c 20 28 49 6e 74 50 74 72 29 28 2d 31 29 29 1, (IntPtr)(-1))
5a10: 3b 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 6e ;.. if (n
5a20: 20 3e 20 30 29 20 74 68 72 6f 77 20 6e 65 77 20 > 0) throw new
5a30: 53 51 4c 69 74 65 45 78 63 65 70 74 69 6f 6e 28 SQLiteException(
5a40: 6e 2c 20 47 65 74 4c 61 73 74 45 72 72 6f 72 28 n, GetLastError(
5a50: 29 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 ));.. }....
5a60: 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
5a70: 69 64 65 20 76 6f 69 64 20 42 69 6e 64 5f 44 61 ide void Bind_Da
5a80: 74 65 54 69 6d 65 28 53 51 4c 69 74 65 53 74 61 teTime(SQLiteSta
5a90: 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 53 51 4c tement stmt, SQL
5aa0: 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 iteConnectionFla
5ab0: 67 73 20 66 6c 61 67 73 2c 20 69 6e 74 20 69 6e gs flags, int in
5ac0: 64 65 78 2c 20 44 61 74 65 54 69 6d 65 20 64 74 dex, DateTime dt
5ad0: 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 ).. {..
5ae0: 20 20 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e SQLiteStatemen
5af0: 74 48 61 6e 64 6c 65 20 68 61 6e 64 6c 65 20 3d tHandle handle =
5b00: 20 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 stmt._sqlite_st
5b10: 6d 74 3b 0d 0a 0d 0a 23 69 66 20 21 50 4c 41 54 mt;....#if !PLAT
5b20: 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 41 4d FORM_COMPACTFRAM
5b30: 45 57 4f 52 4b 0d 0a 20 20 20 20 20 20 20 20 69 EWORK.. i
5b40: 66 20 28 28 66 6c 61 67 73 20 26 20 53 51 4c 69 f ((flags & SQLi
5b50: 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 teConnectionFlag
5b60: 73 2e 4c 6f 67 42 69 6e 64 29 20 3d 3d 20 53 51 s.LogBind) == SQ
5b70: 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c LiteConnectionFl
5b80: 61 67 73 2e 4c 6f 67 42 69 6e 64 29 0d 0a 20 20 ags.LogBind)..
5b90: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
5ba0: 20 20 20 20 20 4c 6f 67 42 69 6e 64 28 68 61 6e LogBind(han
5bb0: 64 6c 65 2c 20 69 6e 64 65 78 2c 20 64 74 29 3b dle, index, dt);
5bc0: 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a 23 65 6e .. }..#en
5bd0: 64 69 66 0d 0a 0d 0a 20 20 20 20 20 20 20 20 73 dif.... s
5be0: 77 69 74 63 68 20 28 5f 64 61 74 65 74 69 6d 65 witch (_datetime
5bf0: 46 6f 72 6d 61 74 29 0d 0a 20 20 20 20 20 20 20 Format)..
5c00: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
5c10: 63 61 73 65 20 53 51 4c 69 74 65 44 61 74 65 46 case SQLiteDateF
5c20: 6f 72 6d 61 74 73 2e 54 69 63 6b 73 3a 0d 0a 20 ormats.Ticks:..
5c30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7b {
5c40: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
5c50: 20 20 20 20 20 20 6c 6f 6e 67 20 76 61 6c 75 65 long value
5c60: 20 3d 20 64 74 2e 54 69 63 6b 73 3b 0d 0a 0d 0a = dt.Ticks;....
5c70: 23 69 66 20 21 50 4c 41 54 46 4f 52 4d 5f 43 4f #if !PLATFORM_CO
5c80: 4d 50 41 43 54 46 52 41 4d 45 57 4f 52 4b 0d 0a MPACTFRAMEWORK..
5c90: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5ca0: 20 20 20 20 69 66 20 28 28 66 6c 61 67 73 20 26 if ((flags &
5cb0: 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f SQLiteConnectio
5cc0: 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 20 nFlags.LogBind)
5cd0: 3d 3d 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 == SQLiteConnect
5ce0: 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 ionFlags.LogBind
5cf0: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 )..
5d00: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
5d10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5d20: 20 20 4c 6f 67 42 69 6e 64 28 68 61 6e 64 6c 65 LogBind(handle
5d30: 2c 20 69 6e 64 65 78 2c 20 76 61 6c 75 65 29 3b , index, value);
5d40: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
5d50: 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 }....
5d60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 i
5d70: 6e 74 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 nt n = UnsafeNat
5d80: 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 iveMethods.sqlit
5d90: 65 33 5f 62 69 6e 64 5f 69 6e 74 36 34 28 68 61 e3_bind_int64(ha
5da0: 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 76 61 6c ndle, index, val
5db0: 75 65 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 ue);..#else..
5dc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5dd0: 20 69 6e 74 20 6e 20 3d 20 55 6e 73 61 66 65 4e int n = UnsafeN
5de0: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
5df0: 69 74 65 33 5f 62 69 6e 64 5f 69 6e 74 36 34 5f ite3_bind_int64_
5e00: 69 6e 74 65 72 6f 70 28 68 61 6e 64 6c 65 2c 20 interop(handle,
5e10: 69 6e 64 65 78 2c 20 72 65 66 20 76 61 6c 75 65 index, ref value
5e20: 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 );..#endif..
5e30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5e40: 69 66 20 28 6e 20 3e 20 30 29 20 74 68 72 6f 77 if (n > 0) throw
5e50: 20 6e 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 new SQLiteExcep
5e60: 74 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 tion(n, GetLastE
5e70: 72 72 6f 72 28 29 29 3b 0d 0a 20 20 20 20 20 20 rror());..
5e80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 62 72 br
5e90: 65 61 6b 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 eak;..
5ea0: 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 }..
5eb0: 20 20 20 20 20 63 61 73 65 20 53 51 4c 69 74 65 case SQLite
5ec0: 44 61 74 65 46 6f 72 6d 61 74 73 2e 4a 75 6c 69 DateFormats.Juli
5ed0: 61 6e 44 61 79 3a 0d 0a 20 20 20 20 20 20 20 20 anDay:..
5ee0: 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 {..
5ef0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 64 d
5f00: 6f 75 62 6c 65 20 76 61 6c 75 65 20 3d 20 54 6f ouble value = To
5f10: 4a 75 6c 69 61 6e 44 61 79 28 64 74 29 3b 0d 0a JulianDay(dt);..
5f20: 0d 0a 23 69 66 20 21 50 4c 41 54 46 4f 52 4d 5f ..#if !PLATFORM_
5f30: 43 4f 4d 50 41 43 54 46 52 41 4d 45 57 4f 52 4b COMPACTFRAMEWORK
5f40: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
5f50: 20 20 20 20 20 20 69 66 20 28 28 66 6c 61 67 73 if ((flags
5f60: 20 26 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 & SQLiteConnect
5f70: 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 ionFlags.LogBind
5f80: 29 20 3d 3d 20 53 51 4c 69 74 65 43 6f 6e 6e 65 ) == SQLiteConne
5f90: 63 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 ctionFlags.LogBi
5fa0: 6e 64 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 nd)..
5fb0: 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 {..
5fc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5fd0: 20 20 20 20 4c 6f 67 42 69 6e 64 28 68 61 6e 64 LogBind(hand
5fe0: 6c 65 2c 20 69 6e 64 65 78 2c 20 76 61 6c 75 65 le, index, value
5ff0: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 );..
6000: 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 }....
6010: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
6020: 20 69 6e 74 20 6e 20 3d 20 55 6e 73 61 66 65 4e int n = UnsafeN
6030: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
6040: 69 74 65 33 5f 62 69 6e 64 5f 64 6f 75 62 6c 65 ite3_bind_double
6050: 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 (handle, index,
6060: 76 61 6c 75 65 29 3b 0d 0a 23 65 6c 73 65 0d 0a value);..#else..
6070: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
6080: 20 20 20 20 69 6e 74 20 6e 20 3d 20 55 6e 73 61 int n = Unsa
6090: 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
60a0: 73 71 6c 69 74 65 33 5f 62 69 6e 64 5f 64 6f 75 sqlite3_bind_dou
60b0: 62 6c 65 5f 69 6e 74 65 72 6f 70 28 68 61 6e 64 ble_interop(hand
60c0: 6c 65 2c 20 69 6e 64 65 78 2c 20 72 65 66 20 76 le, index, ref v
60d0: 61 6c 75 65 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a alue);..#endif..
60e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
60f0: 20 20 20 20 69 66 20 28 6e 20 3e 20 30 29 20 74 if (n > 0) t
6100: 68 72 6f 77 20 6e 65 77 20 53 51 4c 69 74 65 45 hrow new SQLiteE
6110: 78 63 65 70 74 69 6f 6e 28 6e 2c 20 47 65 74 4c xception(n, GetL
6120: 61 73 74 45 72 72 6f 72 28 29 29 3b 0d 0a 20 20 astError());..
6130: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
6140: 20 20 62 72 65 61 6b 3b 0d 0a 20 20 20 20 20 20 break;..
6150: 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 }..
6160: 20 20 20 20 20 20 20 20 20 63 61 73 65 20 53 51 case SQ
6170: 4c 69 74 65 44 61 74 65 46 6f 72 6d 61 74 73 2e LiteDateFormats.
6180: 55 6e 69 78 45 70 6f 63 68 3a 0d 0a 20 20 20 20 UnixEpoch:..
6190: 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 {..
61a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
61b0: 20 20 20 6c 6f 6e 67 20 76 61 6c 75 65 20 3d 20 long value =
61c0: 43 6f 6e 76 65 72 74 2e 54 6f 49 6e 74 36 34 28 Convert.ToInt64(
61d0: 64 74 2e 53 75 62 74 72 61 63 74 28 55 6e 69 78 dt.Subtract(Unix
61e0: 45 70 6f 63 68 29 2e 54 6f 74 61 6c 53 65 63 6f Epoch).TotalSeco
61f0: 6e 64 73 29 3b 0d 0a 0d 0a 23 69 66 20 21 50 4c nds);....#if !PL
6200: 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 ATFORM_COMPACTFR
6210: 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 20 20 20 AMEWORK..
6220: 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 if
6230: 28 28 66 6c 61 67 73 20 26 20 53 51 4c 69 74 65 ((flags & SQLite
6240: 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2e ConnectionFlags.
6250: 4c 6f 67 42 69 6e 64 29 20 3d 3d 20 53 51 4c 69 LogBind) == SQLi
6260: 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 teConnectionFlag
6270: 73 2e 4c 6f 67 42 69 6e 64 29 0d 0a 20 20 20 20 s.LogBind)..
6280: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
6290: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 {..
62a0: 20 20 20 20 20 20 20 20 20 20 20 4c 6f 67 42 69 LogBi
62b0: 6e 64 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 nd(handle, index
62c0: 2c 20 76 61 6c 75 65 29 3b 0d 0a 20 20 20 20 20 , value);..
62d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d }
62e0: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ....
62f0: 20 20 20 20 20 20 20 20 69 6e 74 20 6e 20 3d 20 int n =
6300: 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 UnsafeNativeMeth
6310: 6f 64 73 2e 73 71 6c 69 74 65 33 5f 62 69 6e 64 ods.sqlite3_bind
6320: 5f 69 6e 74 36 34 28 68 61 6e 64 6c 65 2c 20 69 _int64(handle, i
6330: 6e 64 65 78 2c 20 76 61 6c 75 65 29 3b 0d 0a 23 ndex, value);..#
6340: 65 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 20 20 else..
6350: 20 20 20 20 20 20 20 20 20 20 69 6e 74 20 6e 20 int n
6360: 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 = UnsafeNativeMe
6370: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 62 69 thods.sqlite3_bi
6380: 6e 64 5f 69 6e 74 36 34 5f 69 6e 74 65 72 6f 70 nd_int64_interop
6390: 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 (handle, index,
63a0: 72 65 66 20 76 61 6c 75 65 29 3b 0d 0a 23 65 6e ref value);..#en
63b0: 64 69 66 0d 0a 20 20 20 20 20 20 20 20 20 20 20 dif..
63c0: 20 20 20 20 20 20 20 20 20 69 66 20 28 6e 20 3e if (n >
63d0: 20 30 29 20 74 68 72 6f 77 20 6e 65 77 20 53 51 0) throw new SQ
63e0: 4c 69 74 65 45 78 63 65 70 74 69 6f 6e 28 6e 2c LiteException(n,
63f0: 20 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 29 GetLastError())
6400: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ;..
6410: 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0d 0a 20 break;..
6420: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d }
6430: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 64 65 .. de
6440: 66 61 75 6c 74 3a 0d 0a 20 20 20 20 20 20 20 20 fault:..
6450: 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 {..
6460: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 62 b
6470: 79 74 65 5b 5d 20 62 20 3d 20 54 6f 55 54 46 38 yte[] b = ToUTF8
6480: 28 64 74 29 3b 0d 0a 0d 0a 23 69 66 20 21 50 4c (dt);....#if !PL
6490: 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 ATFORM_COMPACTFR
64a0: 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 20 20 20 AMEWORK..
64b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 if
64c0: 28 28 66 6c 61 67 73 20 26 20 53 51 4c 69 74 65 ((flags & SQLite
64d0: 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2e ConnectionFlags.
64e0: 4c 6f 67 42 69 6e 64 29 20 3d 3d 20 53 51 4c 69 LogBind) == SQLi
64f0: 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 teConnectionFlag
6500: 73 2e 4c 6f 67 42 69 6e 64 29 0d 0a 20 20 20 20 s.LogBind)..
6510: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
6520: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 {..
6530: 20 20 20 20 20 20 20 20 20 20 20 4c 6f 67 42 69 LogBi
6540: 6e 64 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 nd(handle, index
6550: 2c 20 62 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 , b);..
6560: 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 23 65 }..#e
6570: 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 20 20 20 20 ndif....
6580: 20 20 20 20 20 20 20 20 20 20 20 20 69 6e 74 20 int
6590: 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 n = UnsafeNative
65a0: 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f Methods.sqlite3_
65b0: 62 69 6e 64 5f 74 65 78 74 28 68 61 6e 64 6c 65 bind_text(handle
65c0: 2c 20 69 6e 64 65 78 2c 20 62 2c 20 62 2e 4c 65 , index, b, b.Le
65d0: 6e 67 74 68 20 2d 20 31 2c 20 28 49 6e 74 50 74 ngth - 1, (IntPt
65e0: 72 29 28 2d 31 29 29 3b 0d 0a 20 20 20 20 20 20 r)(-1));..
65f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 if
6600: 20 28 6e 20 3e 20 30 29 20 74 68 72 6f 77 20 6e (n > 0) throw n
6610: 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 74 69 ew SQLiteExcepti
6620: 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 72 72 on(n, GetLastErr
6630: 6f 72 28 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 or());..
6640: 20 20 20 20 20 20 20 20 20 20 20 20 62 72 65 61 brea
6650: 6b 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 k;..
6660: 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 7d }.. }
6670: 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 .. }.... i
6680: 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 nternal override
6690: 20 76 6f 69 64 20 42 69 6e 64 5f 42 6c 6f 62 28 void Bind_Blob(
66a0: 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 20 SQLiteStatement
66b0: 73 74 6d 74 2c 20 53 51 4c 69 74 65 43 6f 6e 6e stmt, SQLiteConn
66c0: 65 63 74 69 6f 6e 46 6c 61 67 73 20 66 6c 61 67 ectionFlags flag
66d0: 73 2c 20 69 6e 74 20 69 6e 64 65 78 2c 20 62 79 s, int index, by
66e0: 74 65 5b 5d 20 62 6c 6f 62 44 61 74 61 29 0d 0a te[] blobData)..
66f0: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 53 {.. S
6700: 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 48 61 QLiteStatementHa
6710: 6e 64 6c 65 20 68 61 6e 64 6c 65 20 3d 20 73 74 ndle handle = st
6720: 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 6d 74 3b mt._sqlite_stmt;
6730: 0d 0a 0d 0a 23 69 66 20 21 50 4c 41 54 46 4f 52 ....#if !PLATFOR
6740: 4d 5f 43 4f 4d 50 41 43 54 46 52 41 4d 45 57 4f M_COMPACTFRAMEWO
6750: 52 4b 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 RK.. if (
6760: 28 66 6c 61 67 73 20 26 20 53 51 4c 69 74 65 43 (flags & SQLiteC
6770: 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2e 4c onnectionFlags.L
6780: 6f 67 42 69 6e 64 29 20 3d 3d 20 53 51 4c 69 74 ogBind) == SQLit
6790: 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 eConnectionFlags
67a0: 2e 4c 6f 67 42 69 6e 64 29 0d 0a 20 20 20 20 20 .LogBind)..
67b0: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 {..
67c0: 20 20 4c 6f 67 42 69 6e 64 28 68 61 6e 64 6c 65 LogBind(handle
67d0: 2c 20 69 6e 64 65 78 2c 20 62 6c 6f 62 44 61 74 , index, blobDat
67e0: 61 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a a);.. }..
67f0: 23 65 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 20 20 #endif....
6800: 20 20 69 6e 74 20 6e 20 3d 20 55 6e 73 61 66 65 int n = Unsafe
6810: 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 NativeMethods.sq
6820: 6c 69 74 65 33 5f 62 69 6e 64 5f 62 6c 6f 62 28 lite3_bind_blob(
6830: 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 62 handle, index, b
6840: 6c 6f 62 44 61 74 61 2c 20 62 6c 6f 62 44 61 74 lobData, blobDat
6850: 61 2e 4c 65 6e 67 74 68 2c 20 28 49 6e 74 50 74 a.Length, (IntPt
6860: 72 29 28 2d 31 29 29 3b 0d 0a 20 20 20 20 20 20 r)(-1));..
6870: 20 20 69 66 20 28 6e 20 3e 20 30 29 20 74 68 72 if (n > 0) thr
6880: 6f 77 20 6e 65 77 20 53 51 4c 69 74 65 45 78 63 ow new SQLiteExc
6890: 65 70 74 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 eption(n, GetLas
68a0: 74 45 72 72 6f 72 28 29 29 3b 0d 0a 20 20 20 20 tError());..
68b0: 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 }.... interna
68c0: 6c 20 6f 76 65 72 72 69 64 65 20 76 6f 69 64 20 l override void
68d0: 42 69 6e 64 5f 4e 75 6c 6c 28 53 51 4c 69 74 65 Bind_Null(SQLite
68e0: 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 Statement stmt,
68f0: 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e SQLiteConnection
6900: 46 6c 61 67 73 20 66 6c 61 67 73 2c 20 69 6e 74 Flags flags, int
6910: 20 69 6e 64 65 78 29 0d 0a 20 20 20 20 7b 0d 0a index).. {..
6920: 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 53 74 SQLiteSt
6930: 61 74 65 6d 65 6e 74 48 61 6e 64 6c 65 20 68 61 atementHandle ha
6940: 6e 64 6c 65 20 3d 20 73 74 6d 74 2e 5f 73 71 6c ndle = stmt._sql
6950: 69 74 65 5f 73 74 6d 74 3b 0d 0a 0d 0a 23 69 66 ite_stmt;....#if
6960: 20 21 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 !PLATFORM_COMPA
6970: 43 54 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 CTFRAMEWORK..
6980: 20 20 20 20 20 69 66 20 28 28 66 6c 61 67 73 20 if ((flags
6990: 26 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 & SQLiteConnecti
69a0: 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 onFlags.LogBind)
69b0: 20 3d 3d 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 == SQLiteConnec
69c0: 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e tionFlags.LogBin
69d0: 64 29 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 d).. {..
69e0: 20 20 20 20 20 20 20 20 20 20 20 4c 6f 67 42 69 LogBi
69f0: 6e 64 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 nd(handle, index
6a00: 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a 23 );.. }..#
6a10: 65 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 20 20 20 endif....
6a20: 20 69 6e 74 20 6e 20 3d 20 55 6e 73 61 66 65 4e int n = UnsafeN
6a30: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
6a40: 69 74 65 33 5f 62 69 6e 64 5f 6e 75 6c 6c 28 68 ite3_bind_null(h
6a50: 61 6e 64 6c 65 2c 20 69 6e 64 65 78 29 3b 0d 0a andle, index);..
6a60: 20 20 20 20 20 20 20 20 69 66 20 28 6e 20 3e 20 if (n >
6a70: 30 29 20 74 68 72 6f 77 20 6e 65 77 20 53 51 4c 0) throw new SQL
6a80: 69 74 65 45 78 63 65 70 74 69 6f 6e 28 6e 2c 20 iteException(n,
6a90: 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 29 3b GetLastError());
6aa0: 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 .. }.... i
6ab0: 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 nternal override
6ac0: 20 69 6e 74 20 42 69 6e 64 5f 50 61 72 61 6d 43 int Bind_ParamC
6ad0: 6f 75 6e 74 28 53 51 4c 69 74 65 53 74 61 74 65 ount(SQLiteState
6ae0: 6d 65 6e 74 20 73 74 6d 74 2c 20 53 51 4c 69 74 ment stmt, SQLit
6af0: 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 eConnectionFlags
6b00: 20 66 6c 61 67 73 29 0d 0a 20 20 20 20 7b 0d 0a flags).. {..
6b10: 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 53 74 SQLiteSt
6b20: 61 74 65 6d 65 6e 74 48 61 6e 64 6c 65 20 68 61 atementHandle ha
6b30: 6e 64 6c 65 20 3d 20 73 74 6d 74 2e 5f 73 71 6c ndle = stmt._sql
6b40: 69 74 65 5f 73 74 6d 74 3b 0d 0a 20 20 20 20 20 ite_stmt;..
6b50: 20 20 20 69 6e 74 20 76 61 6c 75 65 20 3d 20 55 int value = U
6b60: 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
6b70: 64 73 2e 73 71 6c 69 74 65 33 5f 62 69 6e 64 5f ds.sqlite3_bind_
6b80: 70 61 72 61 6d 65 74 65 72 5f 63 6f 75 6e 74 28 parameter_count(
6b90: 68 61 6e 64 6c 65 29 3b 0d 0a 0d 0a 23 69 66 20 handle);....#if
6ba0: 21 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 !PLATFORM_COMPAC
6bb0: 54 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 TFRAMEWORK..
6bc0: 20 20 20 20 69 66 20 28 28 66 6c 61 67 73 20 26 if ((flags &
6bd0: 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f SQLiteConnectio
6be0: 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 20 nFlags.LogBind)
6bf0: 3d 3d 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 == SQLiteConnect
6c00: 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 ionFlags.LogBind
6c10: 29 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 ).. {..
6c20: 20 20 20 20 20 20 20 20 20 20 49 6e 74 50 74 72 IntPtr
6c30: 20 68 61 6e 64 6c 65 49 6e 74 50 74 72 20 3d 20 handleIntPtr =
6c40: 68 61 6e 64 6c 65 3b 0d 0a 0d 0a 20 20 20 20 20 handle;....
6c50: 20 20 20 20 20 20 20 53 51 4c 69 74 65 4c 6f 67 SQLiteLog
6c60: 2e 4c 6f 67 4d 65 73 73 61 67 65 28 30 2c 20 53 .LogMessage(0, S
6c70: 74 72 69 6e 67 2e 46 6f 72 6d 61 74 28 0d 0a 20 tring.Format(..
6c80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 "
6c90: 53 74 61 74 65 6d 65 6e 74 20 7b 30 7d 20 70 61 Statement {0} pa
6ca0: 72 61 6d 74 65 72 20 63 6f 75 6e 74 20 69 73 20 ramter count is
6cb0: 7b 31 7d 2e 22 2c 0d 0a 20 20 20 20 20 20 20 20 {1}.",..
6cc0: 20 20 20 20 20 20 20 20 68 61 6e 64 6c 65 49 6e handleIn
6cd0: 74 50 74 72 2c 20 76 61 6c 75 65 29 29 3b 0d 0a tPtr, value));..
6ce0: 20 20 20 20 20 20 20 20 7d 0d 0a 23 65 6e 64 69 }..#endi
6cf0: 66 0d 0a 0d 0a 20 20 20 20 20 20 20 20 72 65 74 f.... ret
6d00: 75 72 6e 20 76 61 6c 75 65 3b 0d 0a 20 20 20 20 urn value;..
6d10: 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 }.... interna
6d20: 6c 20 6f 76 65 72 72 69 64 65 20 73 74 72 69 6e l override strin
6d30: 67 20 42 69 6e 64 5f 50 61 72 61 6d 4e 61 6d 65 g Bind_ParamName
6d40: 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 (SQLiteStatement
6d50: 20 73 74 6d 74 2c 20 53 51 4c 69 74 65 43 6f 6e stmt, SQLiteCon
6d60: 6e 65 63 74 69 6f 6e 46 6c 61 67 73 20 66 6c 61 nectionFlags fla
6d70: 67 73 2c 20 69 6e 74 20 69 6e 64 65 78 29 0d 0a gs, int index)..
6d80: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 53 {.. S
6d90: 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 48 61 QLiteStatementHa
6da0: 6e 64 6c 65 20 68 61 6e 64 6c 65 20 3d 20 73 74 ndle handle = st
6db0: 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 6d 74 3b mt._sqlite_stmt;
6dc0: 0d 0a 20 20 20 20 20 20 20 20 73 74 72 69 6e 67 .. string
6dd0: 20 6e 61 6d 65 3b 0d 0a 0d 0a 23 69 66 20 21 53 name;....#if !S
6de0: 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a QLITE_STANDARD..
6df0: 20 20 20 20 20 20 20 20 69 6e 74 20 6c 65 6e 3b int len;
6e00: 0d 0a 20 20 20 20 20 20 20 20 6e 61 6d 65 20 3d .. name =
6e10: 20 55 54 46 38 54 6f 53 74 72 69 6e 67 28 55 6e UTF8ToString(Un
6e20: 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 safeNativeMethod
6e30: 73 2e 73 71 6c 69 74 65 33 5f 62 69 6e 64 5f 70 s.sqlite3_bind_p
6e40: 61 72 61 6d 65 74 65 72 5f 6e 61 6d 65 5f 69 6e arameter_name_in
6e50: 74 65 72 6f 70 28 68 61 6e 64 6c 65 2c 20 69 6e terop(handle, in
6e60: 64 65 78 2c 20 6f 75 74 20 6c 65 6e 29 2c 20 6c dex, out len), l
6e70: 65 6e 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 en);..#else..
6e80: 20 20 20 20 20 6e 61 6d 65 20 3d 20 55 54 46 38 name = UTF8
6e90: 54 6f 53 74 72 69 6e 67 28 55 6e 73 61 66 65 4e ToString(UnsafeN
6ea0: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
6eb0: 69 74 65 33 5f 62 69 6e 64 5f 70 61 72 61 6d 65 ite3_bind_parame
6ec0: 74 65 72 5f 6e 61 6d 65 28 68 61 6e 64 6c 65 2c ter_name(handle,
6ed0: 20 69 6e 64 65 78 29 2c 20 2d 31 29 3b 0d 0a 23 index), -1);..#
6ee0: 65 6e 64 69 66 0d 0a 0d 0a 23 69 66 20 21 50 4c endif....#if !PL
6ef0: 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 ATFORM_COMPACTFR
6f00: 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 20 20 20 AMEWORK..
6f10: 20 69 66 20 28 28 66 6c 61 67 73 20 26 20 53 51 if ((flags & SQ
6f20: 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c LiteConnectionFl
6f30: 61 67 73 2e 4c 6f 67 42 69 6e 64 29 20 3d 3d 20 ags.LogBind) ==
6f40: 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e SQLiteConnection
6f50: 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 0d 0a Flags.LogBind)..
6f60: 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 {..
6f70: 20 20 20 20 20 20 20 49 6e 74 50 74 72 20 68 61 IntPtr ha
6f80: 6e 64 6c 65 49 6e 74 50 74 72 20 3d 20 68 61 6e ndleIntPtr = han
6f90: 64 6c 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 dle;....
6fa0: 20 20 20 20 53 51 4c 69 74 65 4c 6f 67 2e 4c 6f SQLiteLog.Lo
6fb0: 67 4d 65 73 73 61 67 65 28 30 2c 20 53 74 72 69 gMessage(0, Stri
6fc0: 6e 67 2e 46 6f 72 6d 61 74 28 0d 0a 20 20 20 20 ng.Format(..
6fd0: 20 20 20 20 20 20 20 20 20 20 20 20 22 53 74 61 "Sta
6fe0: 74 65 6d 65 6e 74 20 7b 30 7d 20 70 61 72 61 6d tement {0} param
6ff0: 74 65 72 20 23 7b 31 7d 20 6e 61 6d 65 20 69 73 ter #{1} name is
7000: 20 7b 7b 7b 32 7d 7d 7d 2e 22 2c 0d 0a 20 20 20 {{{2}}}.",..
7010: 20 20 20 20 20 20 20 20 20 20 20 20 20 68 61 6e han
7020: 64 6c 65 49 6e 74 50 74 72 2c 20 69 6e 64 65 78 dleIntPtr, index
7030: 2c 20 6e 61 6d 65 29 29 3b 0d 0a 20 20 20 20 20 , name));..
7040: 20 20 20 7d 0d 0a 23 65 6e 64 69 66 0d 0a 0d 0a }..#endif....
7050: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 6e return n
7060: 61 6d 65 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 ame;.. }....
7070: 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 internal over
7080: 72 69 64 65 20 69 6e 74 20 42 69 6e 64 5f 50 61 ride int Bind_Pa
7090: 72 61 6d 49 6e 64 65 78 28 53 51 4c 69 74 65 53 ramIndex(SQLiteS
70a0: 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 53 tatement stmt, S
70b0: 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 QLiteConnectionF
70c0: 6c 61 67 73 20 66 6c 61 67 73 2c 20 73 74 72 69 lags flags, stri
70d0: 6e 67 20 70 61 72 61 6d 4e 61 6d 65 29 0d 0a 20 ng paramName)..
70e0: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 53 51 {.. SQ
70f0: 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 48 61 6e LiteStatementHan
7100: 64 6c 65 20 68 61 6e 64 6c 65 20 3d 20 73 74 6d dle handle = stm
7110: 74 2e 5f 73 71 6c 69 74 65 5f 73 74 6d 74 3b 0d t._sqlite_stmt;.
7120: 0a 20 20 20 20 20 20 20 20 69 6e 74 20 69 6e 64 . int ind
7130: 65 78 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 ex = UnsafeNativ
7140: 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
7150: 5f 62 69 6e 64 5f 70 61 72 61 6d 65 74 65 72 5f _bind_parameter_
7160: 69 6e 64 65 78 28 68 61 6e 64 6c 65 2c 20 54 6f index(handle, To
7170: 55 54 46 38 28 70 61 72 61 6d 4e 61 6d 65 29 29 UTF8(paramName))
7180: 3b 0d 0a 0d 0a 23 69 66 20 21 50 4c 41 54 46 4f ;....#if !PLATFO
7190: 52 4d 5f 43 4f 4d 50 41 43 54 46 52 41 4d 45 57 RM_COMPACTFRAMEW
71a0: 4f 52 4b 0d 0a 20 20 20 20 20 20 20 20 69 66 20 ORK.. if
71b0: 28 28 66 6c 61 67 73 20 26 20 53 51 4c 69 74 65 ((flags & SQLite
71c0: 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2e ConnectionFlags.
71d0: 4c 6f 67 42 69 6e 64 29 20 3d 3d 20 53 51 4c 69 LogBind) == SQLi
71e0: 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 teConnectionFlag
71f0: 73 2e 4c 6f 67 42 69 6e 64 29 0d 0a 20 20 20 20 s.LogBind)..
7200: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 {..
7210: 20 20 20 49 6e 74 50 74 72 20 68 61 6e 64 6c 65 IntPtr handle
7220: 49 6e 74 50 74 72 20 3d 20 68 61 6e 64 6c 65 3b IntPtr = handle;
7230: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ....
7240: 53 51 4c 69 74 65 4c 6f 67 2e 4c 6f 67 4d 65 73 SQLiteLog.LogMes
7250: 73 61 67 65 28 30 2c 20 53 74 72 69 6e 67 2e 46 sage(0, String.F
7260: 6f 72 6d 61 74 28 0d 0a 20 20 20 20 20 20 20 20 ormat(..
7270: 20 20 20 20 20 20 20 20 22 53 74 61 74 65 6d 65 "Stateme
7280: 6e 74 20 7b 30 7d 20 70 61 72 61 6d 74 65 72 20 nt {0} paramter
7290: 69 6e 64 65 78 20 6f 66 20 6e 61 6d 65 20 7b 7b index of name {{
72a0: 7b 31 7d 7d 7d 20 69 73 20 23 7b 32 7d 2e 22 2c {1}}} is #{2}.",
72b0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
72c0: 20 20 68 61 6e 64 6c 65 49 6e 74 50 74 72 2c 20 handleIntPtr,
72d0: 70 61 72 61 6d 4e 61 6d 65 2c 20 69 6e 64 65 78 paramName, index
72e0: 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a ));.. }..
72f0: 23 65 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 20 20 #endif....
7300: 20 20 72 65 74 75 72 6e 20 69 6e 64 65 78 3b 0d return index;.
7310: 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e . }.... in
7320: 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 ternal override
7330: 69 6e 74 20 43 6f 6c 75 6d 6e 43 6f 75 6e 74 28 int ColumnCount(
7340: 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 20 SQLiteStatement
7350: 73 74 6d 74 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 stmt).. {..
7360: 20 20 20 20 72 65 74 75 72 6e 20 55 6e 73 61 66 return Unsaf
7370: 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
7380: 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f 63 6f qlite3_column_co
7390: 75 6e 74 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 unt(stmt._sqlite
73a0: 5f 73 74 6d 74 29 3b 0d 0a 20 20 20 20 7d 0d 0a _stmt);.. }..
73b0: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
73c0: 76 65 72 72 69 64 65 20 73 74 72 69 6e 67 20 43 verride string C
73d0: 6f 6c 75 6d 6e 4e 61 6d 65 28 53 51 4c 69 74 65 olumnName(SQLite
73e0: 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 Statement stmt,
73f0: 69 6e 74 20 69 6e 64 65 78 29 0d 0a 20 20 20 20 int index)..
7400: 7b 0d 0a 23 69 66 20 21 53 51 4c 49 54 45 5f 53 {..#if !SQLITE_S
7410: 54 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 20 69 TANDARD.. i
7420: 6e 74 20 6c 65 6e 3b 0d 0a 20 20 20 20 20 20 72 nt len;.. r
7430: 65 74 75 72 6e 20 55 54 46 38 54 6f 53 74 72 69 eturn UTF8ToStri
7440: 6e 67 28 55 6e 73 61 66 65 4e 61 74 69 76 65 4d ng(UnsafeNativeM
7450: 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 ethods.sqlite3_c
7460: 6f 6c 75 6d 6e 5f 6e 61 6d 65 5f 69 6e 74 65 72 olumn_name_inter
7470: 6f 70 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f op(stmt._sqlite_
7480: 73 74 6d 74 2c 20 69 6e 64 65 78 2c 20 6f 75 74 stmt, index, out
7490: 20 6c 65 6e 29 2c 20 6c 65 6e 29 3b 0d 0a 23 65 len), len);..#e
74a0: 6c 73 65 0d 0a 20 20 20 20 20 20 72 65 74 75 72 lse.. retur
74b0: 6e 20 55 54 46 38 54 6f 53 74 72 69 6e 67 28 55 n UTF8ToString(U
74c0: 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
74d0: 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f 6c 75 6d ds.sqlite3_colum
74e0: 6e 5f 6e 61 6d 65 28 73 74 6d 74 2e 5f 73 71 6c n_name(stmt._sql
74f0: 69 74 65 5f 73 74 6d 74 2c 20 69 6e 64 65 78 29 ite_stmt, index)
7500: 2c 20 2d 31 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a , -1);..#endif..
7510: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 }.... int
7520: 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 54 ernal override T
7530: 79 70 65 41 66 66 69 6e 69 74 79 20 43 6f 6c 75 ypeAffinity Colu
7540: 6d 6e 41 66 66 69 6e 69 74 79 28 53 51 4c 69 74 mnAffinity(SQLit
7550: 65 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c eStatement stmt,
7560: 20 69 6e 74 20 69 6e 64 65 78 29 0d 0a 20 20 20 int index)..
7570: 20 7b 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e {.. return
7580: 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 UnsafeNativeMet
7590: 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f 6c hods.sqlite3_col
75a0: 75 6d 6e 5f 74 79 70 65 28 73 74 6d 74 2e 5f 73 umn_type(stmt._s
75b0: 71 6c 69 74 65 5f 73 74 6d 74 2c 20 69 6e 64 65 qlite_stmt, inde
75c0: 78 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 x);.. }....
75d0: 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
75e0: 69 64 65 20 73 74 72 69 6e 67 20 43 6f 6c 75 6d ide string Colum
75f0: 6e 54 79 70 65 28 53 51 4c 69 74 65 53 74 61 74 nType(SQLiteStat
7600: 65 6d 65 6e 74 20 73 74 6d 74 2c 20 69 6e 74 20 ement stmt, int
7610: 69 6e 64 65 78 2c 20 6f 75 74 20 54 79 70 65 41 index, out TypeA
7620: 66 66 69 6e 69 74 79 20 6e 41 66 66 69 6e 69 74 ffinity nAffinit
7630: 79 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 y).. {..
7640: 20 69 6e 74 20 6c 65 6e 3b 0d 0a 23 69 66 20 21 int len;..#if !
7650: 53 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d SQLITE_STANDARD.
7660: 0a 20 20 20 20 20 20 49 6e 74 50 74 72 20 70 20 . IntPtr p
7670: 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 = UnsafeNativeMe
7680: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f thods.sqlite3_co
7690: 6c 75 6d 6e 5f 64 65 63 6c 74 79 70 65 5f 69 6e lumn_decltype_in
76a0: 74 65 72 6f 70 28 73 74 6d 74 2e 5f 73 71 6c 69 terop(stmt._sqli
76b0: 74 65 5f 73 74 6d 74 2c 20 69 6e 64 65 78 2c 20 te_stmt, index,
76c0: 6f 75 74 20 6c 65 6e 29 3b 0d 0a 23 65 6c 73 65 out len);..#else
76d0: 0d 0a 20 20 20 20 20 20 6c 65 6e 20 3d 20 2d 31 .. len = -1
76e0: 3b 0d 0a 20 20 20 20 20 20 49 6e 74 50 74 72 20 ;.. IntPtr
76f0: 70 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 p = UnsafeNative
7700: 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f Methods.sqlite3_
7710: 63 6f 6c 75 6d 6e 5f 64 65 63 6c 74 79 70 65 28 column_decltype(
7720: 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 6d stmt._sqlite_stm
7730: 74 2c 20 69 6e 64 65 78 29 3b 0d 0a 23 65 6e 64 t, index);..#end
7740: 69 66 0d 0a 20 20 20 20 20 20 6e 41 66 66 69 6e if.. nAffin
7750: 69 74 79 20 3d 20 43 6f 6c 75 6d 6e 41 66 66 69 ity = ColumnAffi
7760: 6e 69 74 79 28 73 74 6d 74 2c 20 69 6e 64 65 78 nity(stmt, index
7770: 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 69 66 20 28 );.... if (
7780: 70 20 21 3d 20 49 6e 74 50 74 72 2e 5a 65 72 6f p != IntPtr.Zero
7790: 29 20 72 65 74 75 72 6e 20 55 54 46 38 54 6f 53 ) return UTF8ToS
77a0: 74 72 69 6e 67 28 70 2c 20 6c 65 6e 29 3b 0d 0a tring(p, len);..
77b0: 20 20 20 20 20 20 65 6c 73 65 0d 0a 20 20 20 20 else..
77c0: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 73 74 72 {.. str
77d0: 69 6e 67 5b 5d 20 61 72 20 3d 20 73 74 6d 74 2e ing[] ar = stmt.
77e0: 54 79 70 65 44 65 66 69 6e 69 74 69 6f 6e 73 3b TypeDefinitions;
77f0: 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 61 72 .. if (ar
7800: 20 21 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 != null)..
7810: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 {..
7820: 69 66 20 28 69 6e 64 65 78 20 3c 20 61 72 2e 4c if (index < ar.L
7830: 65 6e 67 74 68 20 26 26 20 61 72 5b 69 6e 64 65 ength && ar[inde
7840: 78 5d 20 21 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 x] != null)..
7850: 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 return
7860: 61 72 5b 69 6e 64 65 78 5d 3b 0d 0a 20 20 20 20 ar[index];..
7870: 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 72 }.. r
7880: 65 74 75 72 6e 20 53 74 72 69 6e 67 2e 45 6d 70 eturn String.Emp
7890: 74 79 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 2f ty;.... /
78a0: 2f 73 77 69 74 63 68 20 28 6e 41 66 66 69 6e 69 /switch (nAffini
78b0: 74 79 29 0d 0a 20 20 20 20 20 20 20 20 2f 2f 7b ty).. //{
78c0: 0d 0a 20 20 20 20 20 20 20 20 2f 2f 20 20 63 61 .. // ca
78d0: 73 65 20 54 79 70 65 41 66 66 69 6e 69 74 79 2e se TypeAffinity.
78e0: 49 6e 74 36 34 3a 0d 0a 20 20 20 20 20 20 20 20 Int64:..
78f0: 2f 2f 20 20 20 20 72 65 74 75 72 6e 20 22 42 49 // return "BI
7900: 47 49 4e 54 22 3b 0d 0a 20 20 20 20 20 20 20 20 GINT";..
7910: 2f 2f 20 20 63 61 73 65 20 54 79 70 65 41 66 66 // case TypeAff
7920: 69 6e 69 74 79 2e 44 6f 75 62 6c 65 3a 0d 0a 20 inity.Double:..
7930: 20 20 20 20 20 20 20 2f 2f 20 20 20 20 72 65 74 // ret
7940: 75 72 6e 20 22 44 4f 55 42 4c 45 22 3b 0d 0a 20 urn "DOUBLE";..
7950: 20 20 20 20 20 20 20 2f 2f 20 20 63 61 73 65 20 // case
7960: 54 79 70 65 41 66 66 69 6e 69 74 79 2e 42 6c 6f TypeAffinity.Blo
7970: 62 3a 0d 0a 20 20 20 20 20 20 20 20 2f 2f 20 20 b:.. //
7980: 20 20 72 65 74 75 72 6e 20 22 42 4c 4f 42 22 3b return "BLOB";
7990: 0d 0a 20 20 20 20 20 20 20 20 2f 2f 20 20 64 65 .. // de
79a0: 66 61 75 6c 74 3a 0d 0a 20 20 20 20 20 20 20 20 fault:..
79b0: 2f 2f 20 20 20 20 72 65 74 75 72 6e 20 22 54 45 // return "TE
79c0: 58 54 22 3b 0d 0a 20 20 20 20 20 20 20 20 2f 2f XT";.. //
79d0: 7d 0d 0a 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 }.. }..
79e0: 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 }.... interna
79f0: 6c 20 6f 76 65 72 72 69 64 65 20 69 6e 74 20 43 l override int C
7a00: 6f 6c 75 6d 6e 49 6e 64 65 78 28 53 51 4c 69 74 olumnIndex(SQLit
7a10: 65 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c eStatement stmt,
7a20: 20 73 74 72 69 6e 67 20 63 6f 6c 75 6d 6e 4e 61 string columnNa
7a30: 6d 65 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 me).. {..
7a40: 20 20 69 6e 74 20 78 20 3d 20 43 6f 6c 75 6d 6e int x = Column
7a50: 43 6f 75 6e 74 28 73 74 6d 74 29 3b 0d 0a 0d 0a Count(stmt);....
7a60: 20 20 20 20 20 20 66 6f 72 20 28 69 6e 74 20 6e for (int n
7a70: 20 3d 20 30 3b 20 6e 20 3c 20 78 3b 20 6e 2b 2b = 0; n < x; n++
7a80: 29 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 ).. {..
7a90: 20 20 20 20 69 66 20 28 53 74 72 69 6e 67 2e 43 if (String.C
7aa0: 6f 6d 70 61 72 65 28 63 6f 6c 75 6d 6e 4e 61 6d ompare(columnNam
7ab0: 65 2c 20 43 6f 6c 75 6d 6e 4e 61 6d 65 28 73 74 e, ColumnName(st
7ac0: 6d 74 2c 20 6e 29 2c 20 53 74 72 69 6e 67 43 6f mt, n), StringCo
7ad0: 6d 70 61 72 69 73 6f 6e 2e 4f 72 64 69 6e 61 6c mparison.Ordinal
7ae0: 49 67 6e 6f 72 65 43 61 73 65 29 20 3d 3d 20 30 IgnoreCase) == 0
7af0: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 72 65 74 ).. ret
7b00: 75 72 6e 20 6e 3b 0d 0a 20 20 20 20 20 20 7d 0d urn n;.. }.
7b10: 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 2d 31 . return -1
7b20: 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 ;.. }....
7b30: 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 internal overrid
7b40: 65 20 73 74 72 69 6e 67 20 43 6f 6c 75 6d 6e 4f e string ColumnO
7b50: 72 69 67 69 6e 61 6c 4e 61 6d 65 28 53 51 4c 69 riginalName(SQLi
7b60: 74 65 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 teStatement stmt
7b70: 2c 20 69 6e 74 20 69 6e 64 65 78 29 0d 0a 20 20 , int index)..
7b80: 20 20 7b 0d 0a 23 69 66 20 21 53 51 4c 49 54 45 {..#if !SQLITE
7b90: 5f 53 54 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 _STANDARD..
7ba0: 20 69 6e 74 20 6c 65 6e 3b 0d 0a 20 20 20 20 20 int len;..
7bb0: 20 72 65 74 75 72 6e 20 55 54 46 38 54 6f 53 74 return UTF8ToSt
7bc0: 72 69 6e 67 28 55 6e 73 61 66 65 4e 61 74 69 76 ring(UnsafeNativ
7bd0: 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
7be0: 5f 63 6f 6c 75 6d 6e 5f 6f 72 69 67 69 6e 5f 6e _column_origin_n
7bf0: 61 6d 65 5f 69 6e 74 65 72 6f 70 28 73 74 6d 74 ame_interop(stmt
7c00: 2e 5f 73 71 6c 69 74 65 5f 73 74 6d 74 2c 20 69 ._sqlite_stmt, i
7c10: 6e 64 65 78 2c 20 6f 75 74 20 6c 65 6e 29 2c 20 ndex, out len),
7c20: 6c 65 6e 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 len);..#else..
7c30: 20 20 20 20 72 65 74 75 72 6e 20 55 54 46 38 54 return UTF8T
7c40: 6f 53 74 72 69 6e 67 28 55 6e 73 61 66 65 4e 61 oString(UnsafeNa
7c50: 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 tiveMethods.sqli
7c60: 74 65 33 5f 63 6f 6c 75 6d 6e 5f 6f 72 69 67 69 te3_column_origi
7c70: 6e 5f 6e 61 6d 65 28 73 74 6d 74 2e 5f 73 71 6c n_name(stmt._sql
7c80: 69 74 65 5f 73 74 6d 74 2c 20 69 6e 64 65 78 29 ite_stmt, index)
7c90: 2c 20 2d 31 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a , -1);..#endif..
7ca0: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 }.... int
7cb0: 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 73 ernal override s
7cc0: 74 72 69 6e 67 20 43 6f 6c 75 6d 6e 44 61 74 61 tring ColumnData
7cd0: 62 61 73 65 4e 61 6d 65 28 53 51 4c 69 74 65 53 baseName(SQLiteS
7ce0: 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 69 tatement stmt, i
7cf0: 6e 74 20 69 6e 64 65 78 29 0d 0a 20 20 20 20 7b nt index).. {
7d00: 0d 0a 23 69 66 20 21 53 51 4c 49 54 45 5f 53 54 ..#if !SQLITE_ST
7d10: 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 20 69 6e ANDARD.. in
7d20: 74 20 6c 65 6e 3b 0d 0a 20 20 20 20 20 20 72 65 t len;.. re
7d30: 74 75 72 6e 20 55 54 46 38 54 6f 53 74 72 69 6e turn UTF8ToStrin
7d40: 67 28 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 g(UnsafeNativeMe
7d50: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f thods.sqlite3_co
7d60: 6c 75 6d 6e 5f 64 61 74 61 62 61 73 65 5f 6e 61 lumn_database_na
7d70: 6d 65 5f 69 6e 74 65 72 6f 70 28 73 74 6d 74 2e me_interop(stmt.
7d80: 5f 73 71 6c 69 74 65 5f 73 74 6d 74 2c 20 69 6e _sqlite_stmt, in
7d90: 64 65 78 2c 20 6f 75 74 20 6c 65 6e 29 2c 20 6c dex, out len), l
7da0: 65 6e 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 en);..#else..
7db0: 20 20 20 72 65 74 75 72 6e 20 55 54 46 38 54 6f return UTF8To
7dc0: 53 74 72 69 6e 67 28 55 6e 73 61 66 65 4e 61 74 String(UnsafeNat
7dd0: 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 iveMethods.sqlit
7de0: 65 33 5f 63 6f 6c 75 6d 6e 5f 64 61 74 61 62 61 e3_column_databa
7df0: 73 65 5f 6e 61 6d 65 28 73 74 6d 74 2e 5f 73 71 se_name(stmt._sq
7e00: 6c 69 74 65 5f 73 74 6d 74 2c 20 69 6e 64 65 78 lite_stmt, index
7e10: 29 2c 20 2d 31 29 3b 0d 0a 23 65 6e 64 69 66 0d ), -1);..#endif.
7e20: 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e . }.... in
7e30: 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 ternal override
7e40: 73 74 72 69 6e 67 20 43 6f 6c 75 6d 6e 54 61 62 string ColumnTab
7e50: 6c 65 4e 61 6d 65 28 53 51 4c 69 74 65 53 74 61 leName(SQLiteSta
7e60: 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 69 6e 74 tement stmt, int
7e70: 20 69 6e 64 65 78 29 0d 0a 20 20 20 20 7b 0d 0a index).. {..
7e80: 23 69 66 20 21 53 51 4c 49 54 45 5f 53 54 41 4e #if !SQLITE_STAN
7e90: 44 41 52 44 0d 0a 20 20 20 20 20 20 69 6e 74 20 DARD.. int
7ea0: 6c 65 6e 3b 0d 0a 20 20 20 20 20 20 72 65 74 75 len;.. retu
7eb0: 72 6e 20 55 54 46 38 54 6f 53 74 72 69 6e 67 28 rn UTF8ToString(
7ec0: 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 UnsafeNativeMeth
7ed0: 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f 6c 75 ods.sqlite3_colu
7ee0: 6d 6e 5f 74 61 62 6c 65 5f 6e 61 6d 65 5f 69 6e mn_table_name_in
7ef0: 74 65 72 6f 70 28 73 74 6d 74 2e 5f 73 71 6c 69 terop(stmt._sqli
7f00: 74 65 5f 73 74 6d 74 2c 20 69 6e 64 65 78 2c 20 te_stmt, index,
7f10: 6f 75 74 20 6c 65 6e 29 2c 20 6c 65 6e 29 3b 0d out len), len);.
7f20: 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 72 65 .#else.. re
7f30: 74 75 72 6e 20 55 54 46 38 54 6f 53 74 72 69 6e turn UTF8ToStrin
7f40: 67 28 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 g(UnsafeNativeMe
7f50: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f thods.sqlite3_co
7f60: 6c 75 6d 6e 5f 74 61 62 6c 65 5f 6e 61 6d 65 28 lumn_table_name(
7f70: 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 6d stmt._sqlite_stm
7f80: 74 2c 20 69 6e 64 65 78 29 2c 20 2d 31 29 3b 0d t, index), -1);.
7f90: 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 7d 0d 0a .#endif.. }..
7fa0: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
7fb0: 76 65 72 72 69 64 65 20 76 6f 69 64 20 43 6f 6c verride void Col
7fc0: 75 6d 6e 4d 65 74 61 44 61 74 61 28 73 74 72 69 umnMetaData(stri
7fd0: 6e 67 20 64 61 74 61 42 61 73 65 2c 20 73 74 72 ng dataBase, str
7fe0: 69 6e 67 20 74 61 62 6c 65 2c 20 73 74 72 69 6e ing table, strin
7ff0: 67 20 63 6f 6c 75 6d 6e 2c 20 6f 75 74 20 73 74 g column, out st
8000: 72 69 6e 67 20 64 61 74 61 54 79 70 65 2c 20 6f ring dataType, o
8010: 75 74 20 73 74 72 69 6e 67 20 63 6f 6c 6c 61 74 ut string collat
8020: 65 53 65 71 75 65 6e 63 65 2c 20 6f 75 74 20 62 eSequence, out b
8030: 6f 6f 6c 20 6e 6f 74 4e 75 6c 6c 2c 20 6f 75 74 ool notNull, out
8040: 20 62 6f 6f 6c 20 70 72 69 6d 61 72 79 4b 65 79 bool primaryKey
8050: 2c 20 6f 75 74 20 62 6f 6f 6c 20 61 75 74 6f 49 , out bool autoI
8060: 6e 63 72 65 6d 65 6e 74 29 0d 0a 20 20 20 20 7b ncrement).. {
8070: 0d 0a 20 20 20 20 20 20 49 6e 74 50 74 72 20 64 .. IntPtr d
8080: 61 74 61 54 79 70 65 50 74 72 3b 0d 0a 20 20 20 ataTypePtr;..
8090: 20 20 20 49 6e 74 50 74 72 20 63 6f 6c 6c 53 65 IntPtr collSe
80a0: 71 50 74 72 3b 0d 0a 20 20 20 20 20 20 69 6e 74 qPtr;.. int
80b0: 20 6e 6e 6f 74 4e 75 6c 6c 3b 0d 0a 20 20 20 20 nnotNull;..
80c0: 20 20 69 6e 74 20 6e 70 72 69 6d 61 72 79 4b 65 int nprimaryKe
80d0: 79 3b 0d 0a 20 20 20 20 20 20 69 6e 74 20 6e 61 y;.. int na
80e0: 75 74 6f 49 6e 63 3b 0d 0a 20 20 20 20 20 20 69 utoInc;.. i
80f0: 6e 74 20 6e 3b 0d 0a 20 20 20 20 20 20 69 6e 74 nt n;.. int
8100: 20 64 74 4c 65 6e 3b 0d 0a 20 20 20 20 20 20 69 dtLen;.. i
8110: 6e 74 20 63 73 4c 65 6e 3b 0d 0a 0d 0a 23 69 66 nt csLen;....#if
8120: 20 21 53 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 !SQLITE_STANDAR
8130: 44 0d 0a 20 20 20 20 20 20 6e 20 3d 20 55 6e 73 D.. n = Uns
8140: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
8150: 2e 73 71 6c 69 74 65 33 5f 74 61 62 6c 65 5f 63 .sqlite3_table_c
8160: 6f 6c 75 6d 6e 5f 6d 65 74 61 64 61 74 61 5f 69 olumn_metadata_i
8170: 6e 74 65 72 6f 70 28 5f 73 71 6c 2c 20 54 6f 55 nterop(_sql, ToU
8180: 54 46 38 28 64 61 74 61 42 61 73 65 29 2c 20 54 TF8(dataBase), T
8190: 6f 55 54 46 38 28 74 61 62 6c 65 29 2c 20 54 6f oUTF8(table), To
81a0: 55 54 46 38 28 63 6f 6c 75 6d 6e 29 2c 20 6f 75 UTF8(column), ou
81b0: 74 20 64 61 74 61 54 79 70 65 50 74 72 2c 20 6f t dataTypePtr, o
81c0: 75 74 20 63 6f 6c 6c 53 65 71 50 74 72 2c 20 6f ut collSeqPtr, o
81d0: 75 74 20 6e 6e 6f 74 4e 75 6c 6c 2c 20 6f 75 74 ut nnotNull, out
81e0: 20 6e 70 72 69 6d 61 72 79 4b 65 79 2c 20 6f 75 nprimaryKey, ou
81f0: 74 20 6e 61 75 74 6f 49 6e 63 2c 20 6f 75 74 20 t nautoInc, out
8200: 64 74 4c 65 6e 2c 20 6f 75 74 20 63 73 4c 65 6e dtLen, out csLen
8210: 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 );..#else..
8220: 20 64 74 4c 65 6e 20 3d 20 2d 31 3b 0d 0a 20 20 dtLen = -1;..
8230: 20 20 20 20 63 73 4c 65 6e 20 3d 20 2d 31 3b 0d csLen = -1;.
8240: 0a 0d 0a 20 20 20 20 20 20 6e 20 3d 20 55 6e 73 ... n = Uns
8250: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
8260: 2e 73 71 6c 69 74 65 33 5f 74 61 62 6c 65 5f 63 .sqlite3_table_c
8270: 6f 6c 75 6d 6e 5f 6d 65 74 61 64 61 74 61 28 5f olumn_metadata(_
8280: 73 71 6c 2c 20 54 6f 55 54 46 38 28 64 61 74 61 sql, ToUTF8(data
8290: 42 61 73 65 29 2c 20 54 6f 55 54 46 38 28 74 61 Base), ToUTF8(ta
82a0: 62 6c 65 29 2c 20 54 6f 55 54 46 38 28 63 6f 6c ble), ToUTF8(col
82b0: 75 6d 6e 29 2c 20 6f 75 74 20 64 61 74 61 54 79 umn), out dataTy
82c0: 70 65 50 74 72 2c 20 6f 75 74 20 63 6f 6c 6c 53 pePtr, out collS
82d0: 65 71 50 74 72 2c 20 6f 75 74 20 6e 6e 6f 74 4e eqPtr, out nnotN
82e0: 75 6c 6c 2c 20 6f 75 74 20 6e 70 72 69 6d 61 72 ull, out nprimar
82f0: 79 4b 65 79 2c 20 6f 75 74 20 6e 61 75 74 6f 49 yKey, out nautoI
8300: 6e 63 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 nc);..#endif..
8310: 20 20 20 20 69 66 20 28 6e 20 3e 20 30 29 20 74 if (n > 0) t
8320: 68 72 6f 77 20 6e 65 77 20 53 51 4c 69 74 65 45 hrow new SQLiteE
8330: 78 63 65 70 74 69 6f 6e 28 6e 2c 20 47 65 74 4c xception(n, GetL
8340: 61 73 74 45 72 72 6f 72 28 29 29 3b 0d 0a 0d 0a astError());....
8350: 20 20 20 20 20 20 64 61 74 61 54 79 70 65 20 3d dataType =
8360: 20 55 54 46 38 54 6f 53 74 72 69 6e 67 28 64 61 UTF8ToString(da
8370: 74 61 54 79 70 65 50 74 72 2c 20 64 74 4c 65 6e taTypePtr, dtLen
8380: 29 3b 0d 0a 20 20 20 20 20 20 63 6f 6c 6c 61 74 );.. collat
8390: 65 53 65 71 75 65 6e 63 65 20 3d 20 55 54 46 38 eSequence = UTF8
83a0: 54 6f 53 74 72 69 6e 67 28 63 6f 6c 6c 53 65 71 ToString(collSeq
83b0: 50 74 72 2c 20 63 73 4c 65 6e 29 3b 0d 0a 0d 0a Ptr, csLen);....
83c0: 20 20 20 20 20 20 6e 6f 74 4e 75 6c 6c 20 3d 20 notNull =
83d0: 28 6e 6e 6f 74 4e 75 6c 6c 20 3d 3d 20 31 29 3b (nnotNull == 1);
83e0: 0d 0a 20 20 20 20 20 20 70 72 69 6d 61 72 79 4b .. primaryK
83f0: 65 79 20 3d 20 28 6e 70 72 69 6d 61 72 79 4b 65 ey = (nprimaryKe
8400: 79 20 3d 3d 20 31 29 3b 0d 0a 20 20 20 20 20 20 y == 1);..
8410: 61 75 74 6f 49 6e 63 72 65 6d 65 6e 74 20 3d 20 autoIncrement =
8420: 28 6e 61 75 74 6f 49 6e 63 20 3d 3d 20 31 29 3b (nautoInc == 1);
8430: 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 .. }.... i
8440: 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 nternal override
8450: 20 64 6f 75 62 6c 65 20 47 65 74 44 6f 75 62 6c double GetDoubl
8460: 65 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e e(SQLiteStatemen
8470: 74 20 73 74 6d 74 2c 20 69 6e 74 20 69 6e 64 65 t stmt, int inde
8480: 78 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 x).. {..
8490: 20 64 6f 75 62 6c 65 20 76 61 6c 75 65 3b 0d 0a double value;..
84a0: 23 69 66 20 21 50 4c 41 54 46 4f 52 4d 5f 43 4f #if !PLATFORM_CO
84b0: 4d 50 41 43 54 46 52 41 4d 45 57 4f 52 4b 0d 0a MPACTFRAMEWORK..
84c0: 20 20 20 20 20 20 76 61 6c 75 65 20 3d 20 55 6e value = Un
84d0: 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 safeNativeMethod
84e0: 73 2e 73 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e s.sqlite3_column
84f0: 5f 64 6f 75 62 6c 65 28 73 74 6d 74 2e 5f 73 71 _double(stmt._sq
8500: 6c 69 74 65 5f 73 74 6d 74 2c 20 69 6e 64 65 78 lite_stmt, index
8510: 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 );..#else..
8520: 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 UnsafeNativeMet
8530: 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f 6c hods.sqlite3_col
8540: 75 6d 6e 5f 64 6f 75 62 6c 65 5f 69 6e 74 65 72 umn_double_inter
8550: 6f 70 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f op(stmt._sqlite_
8560: 73 74 6d 74 2c 20 69 6e 64 65 78 2c 20 6f 75 74 stmt, index, out
8570: 20 76 61 6c 75 65 29 3b 0d 0a 23 65 6e 64 69 66 value);..#endif
8580: 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 76 .. return v
8590: 61 6c 75 65 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a alue;.. }....
85a0: 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 internal ove
85b0: 72 72 69 64 65 20 69 6e 74 20 47 65 74 49 6e 74 rride int GetInt
85c0: 33 32 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 32(SQLiteStateme
85d0: 6e 74 20 73 74 6d 74 2c 20 69 6e 74 20 69 6e 64 nt stmt, int ind
85e0: 65 78 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 ex).. {..
85f0: 20 20 72 65 74 75 72 6e 20 55 6e 73 61 66 65 4e return UnsafeN
8600: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
8610: 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 ite3_column_int(
8620: 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 6d stmt._sqlite_stm
8630: 74 2c 20 69 6e 64 65 78 29 3b 0d 0a 20 20 20 20 t, index);..
8640: 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 }.... interna
8650: 6c 20 6f 76 65 72 72 69 64 65 20 6c 6f 6e 67 20 l override long
8660: 47 65 74 49 6e 74 36 34 28 53 51 4c 69 74 65 53 GetInt64(SQLiteS
8670: 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 69 tatement stmt, i
8680: 6e 74 20 69 6e 64 65 78 29 0d 0a 20 20 20 20 7b nt index).. {
8690: 0d 0a 20 20 20 20 20 20 6c 6f 6e 67 20 76 61 6c .. long val
86a0: 75 65 3b 0d 0a 23 69 66 20 21 50 4c 41 54 46 4f ue;..#if !PLATFO
86b0: 52 4d 5f 43 4f 4d 50 41 43 54 46 52 41 4d 45 57 RM_COMPACTFRAMEW
86c0: 4f 52 4b 0d 0a 20 20 20 20 20 20 76 61 6c 75 65 ORK.. value
86d0: 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d = UnsafeNativeM
86e0: 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 ethods.sqlite3_c
86f0: 6f 6c 75 6d 6e 5f 69 6e 74 36 34 28 73 74 6d 74 olumn_int64(stmt
8700: 2e 5f 73 71 6c 69 74 65 5f 73 74 6d 74 2c 20 69 ._sqlite_stmt, i
8710: 6e 64 65 78 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 ndex);..#else..
8720: 20 20 20 20 20 55 6e 73 61 66 65 4e 61 74 69 76 UnsafeNativ
8730: 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
8740: 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 36 34 5f 69 6e _column_int64_in
8750: 74 65 72 6f 70 28 73 74 6d 74 2e 5f 73 71 6c 69 terop(stmt._sqli
8760: 74 65 5f 73 74 6d 74 2c 20 69 6e 64 65 78 2c 20 te_stmt, index,
8770: 6f 75 74 20 76 61 6c 75 65 29 3b 0d 0a 23 65 6e out value);..#en
8780: 64 69 66 0d 0a 20 20 20 20 20 20 72 65 74 75 72 dif.. retur
8790: 6e 20 76 61 6c 75 65 3b 0d 0a 20 20 20 20 7d 0d n value;.. }.
87a0: 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 ... internal
87b0: 6f 76 65 72 72 69 64 65 20 73 74 72 69 6e 67 20 override string
87c0: 47 65 74 54 65 78 74 28 53 51 4c 69 74 65 53 74 GetText(SQLiteSt
87d0: 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 69 6e atement stmt, in
87e0: 74 20 69 6e 64 65 78 29 0d 0a 20 20 20 20 7b 0d t index).. {.
87f0: 0a 23 69 66 20 21 53 51 4c 49 54 45 5f 53 54 41 .#if !SQLITE_STA
8800: 4e 44 41 52 44 0d 0a 20 20 20 20 20 20 69 6e 74 NDARD.. int
8810: 20 6c 65 6e 3b 0d 0a 20 20 20 20 20 20 72 65 74 len;.. ret
8820: 75 72 6e 20 55 54 46 38 54 6f 53 74 72 69 6e 67 urn UTF8ToString
8830: 28 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 (UnsafeNativeMet
8840: 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f 6c hods.sqlite3_col
8850: 75 6d 6e 5f 74 65 78 74 5f 69 6e 74 65 72 6f 70 umn_text_interop
8860: 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 (stmt._sqlite_st
8870: 6d 74 2c 20 69 6e 64 65 78 2c 20 6f 75 74 20 6c mt, index, out l
8880: 65 6e 29 2c 20 6c 65 6e 29 3b 0d 0a 23 65 6c 73 en), len);..#els
8890: 65 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 e.. return
88a0: 55 54 46 38 54 6f 53 74 72 69 6e 67 28 55 6e 73 UTF8ToString(Uns
88b0: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
88c0: 2e 73 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f .sqlite3_column_
88d0: 74 65 78 74 28 73 74 6d 74 2e 5f 73 71 6c 69 74 text(stmt._sqlit
88e0: 65 5f 73 74 6d 74 2c 20 69 6e 64 65 78 29 2c 20 e_stmt, index),
88f0: 2d 31 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 -1);..#endif..
8900: 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 }.... inter
8910: 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 44 61 74 nal override Dat
8920: 65 54 69 6d 65 20 47 65 74 44 61 74 65 54 69 6d eTime GetDateTim
8930: 65 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e e(SQLiteStatemen
8940: 74 20 73 74 6d 74 2c 20 69 6e 74 20 69 6e 64 65 t stmt, int inde
8950: 78 29 0d 0a 20 20 20 20 7b 0d 0a 23 69 66 20 21 x).. {..#if !
8960: 53 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d SQLITE_STANDARD.
8970: 0a 20 20 20 20 20 20 69 6e 74 20 6c 65 6e 3b 0d . int len;.
8980: 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 54 6f . return To
8990: 44 61 74 65 54 69 6d 65 28 55 6e 73 61 66 65 4e DateTime(UnsafeN
89a0: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
89b0: 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 ite3_column_text
89c0: 5f 69 6e 74 65 72 6f 70 28 73 74 6d 74 2e 5f 73 _interop(stmt._s
89d0: 71 6c 69 74 65 5f 73 74 6d 74 2c 20 69 6e 64 65 qlite_stmt, inde
89e0: 78 2c 20 6f 75 74 20 6c 65 6e 29 2c 20 6c 65 6e x, out len), len
89f0: 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 );..#else..
8a00: 20 72 65 74 75 72 6e 20 54 6f 44 61 74 65 54 69 return ToDateTi
8a10: 6d 65 28 55 6e 73 61 66 65 4e 61 74 69 76 65 4d me(UnsafeNativeM
8a20: 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 ethods.sqlite3_c
8a30: 6f 6c 75 6d 6e 5f 74 65 78 74 28 73 74 6d 74 2e olumn_text(stmt.
8a40: 5f 73 71 6c 69 74 65 5f 73 74 6d 74 2c 20 69 6e _sqlite_stmt, in
8a50: 64 65 78 29 2c 20 2d 31 29 3b 0d 0a 23 65 6e 64 dex), -1);..#end
8a60: 69 66 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 if.. }....
8a70: 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 internal overri
8a80: 64 65 20 6c 6f 6e 67 20 47 65 74 42 79 74 65 73 de long GetBytes
8a90: 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 (SQLiteStatement
8aa0: 20 73 74 6d 74 2c 20 69 6e 74 20 69 6e 64 65 78 stmt, int index
8ab0: 2c 20 69 6e 74 20 6e 44 61 74 61 4f 66 66 73 65 , int nDataOffse
8ac0: 74 2c 20 62 79 74 65 5b 5d 20 62 44 65 73 74 2c t, byte[] bDest,
8ad0: 20 69 6e 74 20 6e 53 74 61 72 74 2c 20 69 6e 74 int nStart, int
8ae0: 20 6e 4c 65 6e 67 74 68 29 0d 0a 20 20 20 20 7b nLength).. {
8af0: 0d 0a 20 20 20 20 20 20 69 6e 74 20 6e 6c 65 6e .. int nlen
8b00: 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d = UnsafeNativeM
8b10: 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 ethods.sqlite3_c
8b20: 6f 6c 75 6d 6e 5f 62 79 74 65 73 28 73 74 6d 74 olumn_bytes(stmt
8b30: 2e 5f 73 71 6c 69 74 65 5f 73 74 6d 74 2c 20 69 ._sqlite_stmt, i
8b40: 6e 64 65 78 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 ndex);....
8b50: 2f 2f 20 49 66 20 6e 6f 20 64 65 73 74 69 6e 61 // If no destina
8b60: 74 69 6f 6e 20 62 75 66 66 65 72 2c 20 72 65 74 tion buffer, ret
8b70: 75 72 6e 20 74 68 65 20 73 69 7a 65 20 6e 65 65 urn the size nee
8b80: 64 65 64 2e 0d 0a 20 20 20 20 20 20 69 66 20 28 ded... if (
8b90: 62 44 65 73 74 20 3d 3d 20 6e 75 6c 6c 29 20 72 bDest == null) r
8ba0: 65 74 75 72 6e 20 6e 6c 65 6e 3b 0d 0a 0d 0a 20 eturn nlen;....
8bb0: 20 20 20 20 20 69 6e 74 20 6e 43 6f 70 69 65 64 int nCopied
8bc0: 20 3d 20 6e 4c 65 6e 67 74 68 3b 0d 0a 0d 0a 20 = nLength;....
8bd0: 20 20 20 20 20 69 66 20 28 6e 43 6f 70 69 65 64 if (nCopied
8be0: 20 2b 20 6e 53 74 61 72 74 20 3e 20 62 44 65 73 + nStart > bDes
8bf0: 74 2e 4c 65 6e 67 74 68 29 20 6e 43 6f 70 69 65 t.Length) nCopie
8c00: 64 20 3d 20 62 44 65 73 74 2e 4c 65 6e 67 74 68 d = bDest.Length
8c10: 20 2d 20 6e 53 74 61 72 74 3b 0d 0a 20 20 20 20 - nStart;..
8c20: 20 20 69 66 20 28 6e 43 6f 70 69 65 64 20 2b 20 if (nCopied +
8c30: 6e 44 61 74 61 4f 66 66 73 65 74 20 3e 20 6e 6c nDataOffset > nl
8c40: 65 6e 29 20 6e 43 6f 70 69 65 64 20 3d 20 6e 6c en) nCopied = nl
8c50: 65 6e 20 2d 20 6e 44 61 74 61 4f 66 66 73 65 74 en - nDataOffset
8c60: 3b 0d 0a 0d 0a 20 20 20 20 20 20 69 66 20 28 6e ;.... if (n
8c70: 43 6f 70 69 65 64 20 3e 20 30 29 0d 0a 20 20 20 Copied > 0)..
8c80: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 49 6e {.. In
8c90: 74 50 74 72 20 70 74 72 20 3d 20 55 6e 73 61 66 tPtr ptr = Unsaf
8ca0: 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
8cb0: 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f 62 6c qlite3_column_bl
8cc0: 6f 62 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f ob(stmt._sqlite_
8cd0: 73 74 6d 74 2c 20 69 6e 64 65 78 29 3b 0d 0a 0d stmt, index);...
8ce0: 0a 20 20 20 20 20 20 20 20 4d 61 72 73 68 61 6c . Marshal
8cf0: 2e 43 6f 70 79 28 28 49 6e 74 50 74 72 29 28 70 .Copy((IntPtr)(p
8d00: 74 72 2e 54 6f 49 6e 74 36 34 28 29 20 2b 20 6e tr.ToInt64() + n
8d10: 44 61 74 61 4f 66 66 73 65 74 29 2c 20 62 44 65 DataOffset), bDe
8d20: 73 74 2c 20 6e 53 74 61 72 74 2c 20 6e 43 6f 70 st, nStart, nCop
8d30: 69 65 64 29 3b 0d 0a 20 20 20 20 20 20 7d 0d 0a ied);.. }..
8d40: 20 20 20 20 20 20 65 6c 73 65 0d 0a 20 20 20 20 else..
8d50: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 6e 43 6f {.. nCo
8d60: 70 69 65 64 20 3d 20 30 3b 0d 0a 20 20 20 20 20 pied = 0;..
8d70: 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 72 65 74 75 }.... retu
8d80: 72 6e 20 6e 43 6f 70 69 65 64 3b 0d 0a 20 20 20 rn nCopied;..
8d90: 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e }.... intern
8da0: 61 6c 20 6f 76 65 72 72 69 64 65 20 6c 6f 6e 67 al override long
8db0: 20 47 65 74 43 68 61 72 73 28 53 51 4c 69 74 65 GetChars(SQLite
8dc0: 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 Statement stmt,
8dd0: 69 6e 74 20 69 6e 64 65 78 2c 20 69 6e 74 20 6e int index, int n
8de0: 44 61 74 61 4f 66 66 73 65 74 2c 20 63 68 61 72 DataOffset, char
8df0: 5b 5d 20 62 44 65 73 74 2c 20 69 6e 74 20 6e 53 [] bDest, int nS
8e00: 74 61 72 74 2c 20 69 6e 74 20 6e 4c 65 6e 67 74 tart, int nLengt
8e10: 68 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 h).. {..
8e20: 20 69 6e 74 20 6e 6c 65 6e 3b 0d 0a 20 20 20 20 int nlen;..
8e30: 20 20 69 6e 74 20 6e 43 6f 70 69 65 64 20 3d 20 int nCopied =
8e40: 6e 4c 65 6e 67 74 68 3b 0d 0a 0d 0a 20 20 20 20 nLength;....
8e50: 20 20 73 74 72 69 6e 67 20 73 74 72 20 3d 20 47 string str = G
8e60: 65 74 54 65 78 74 28 73 74 6d 74 2c 20 69 6e 64 etText(stmt, ind
8e70: 65 78 29 3b 0d 0a 20 20 20 20 20 20 6e 6c 65 6e ex);.. nlen
8e80: 20 3d 20 73 74 72 2e 4c 65 6e 67 74 68 3b 0d 0a = str.Length;..
8e90: 0d 0a 20 20 20 20 20 20 69 66 20 28 62 44 65 73 .. if (bDes
8ea0: 74 20 3d 3d 20 6e 75 6c 6c 29 20 72 65 74 75 72 t == null) retur
8eb0: 6e 20 6e 6c 65 6e 3b 0d 0a 0d 0a 20 20 20 20 20 n nlen;....
8ec0: 20 69 66 20 28 6e 43 6f 70 69 65 64 20 2b 20 6e if (nCopied + n
8ed0: 53 74 61 72 74 20 3e 20 62 44 65 73 74 2e 4c 65 Start > bDest.Le
8ee0: 6e 67 74 68 29 20 6e 43 6f 70 69 65 64 20 3d 20 ngth) nCopied =
8ef0: 62 44 65 73 74 2e 4c 65 6e 67 74 68 20 2d 20 6e bDest.Length - n
8f00: 53 74 61 72 74 3b 0d 0a 20 20 20 20 20 20 69 66 Start;.. if
8f10: 20 28 6e 43 6f 70 69 65 64 20 2b 20 6e 44 61 74 (nCopied + nDat
8f20: 61 4f 66 66 73 65 74 20 3e 20 6e 6c 65 6e 29 20 aOffset > nlen)
8f30: 6e 43 6f 70 69 65 64 20 3d 20 6e 6c 65 6e 20 2d nCopied = nlen -
8f40: 20 6e 44 61 74 61 4f 66 66 73 65 74 3b 0d 0a 0d nDataOffset;...
8f50: 0a 20 20 20 20 20 20 69 66 20 28 6e 43 6f 70 69 . if (nCopi
8f60: 65 64 20 3e 20 30 29 0d 0a 20 20 20 20 20 20 20 ed > 0)..
8f70: 20 73 74 72 2e 43 6f 70 79 54 6f 28 6e 44 61 74 str.CopyTo(nDat
8f80: 61 4f 66 66 73 65 74 2c 20 62 44 65 73 74 2c 20 aOffset, bDest,
8f90: 6e 53 74 61 72 74 2c 20 6e 43 6f 70 69 65 64 29 nStart, nCopied)
8fa0: 3b 0d 0a 20 20 20 20 20 20 65 6c 73 65 20 6e 43 ;.. else nC
8fb0: 6f 70 69 65 64 20 3d 20 30 3b 0d 0a 0d 0a 20 20 opied = 0;....
8fc0: 20 20 20 20 72 65 74 75 72 6e 20 6e 43 6f 70 69 return nCopi
8fd0: 65 64 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 ed;.. }....
8fe0: 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
8ff0: 69 64 65 20 62 6f 6f 6c 20 49 73 4e 75 6c 6c 28 ide bool IsNull(
9000: 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 20 SQLiteStatement
9010: 73 74 6d 74 2c 20 69 6e 74 20 69 6e 64 65 78 29 stmt, int index)
9020: 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 72 .. {.. r
9030: 65 74 75 72 6e 20 28 43 6f 6c 75 6d 6e 41 66 66 eturn (ColumnAff
9040: 69 6e 69 74 79 28 73 74 6d 74 2c 20 69 6e 64 65 inity(stmt, inde
9050: 78 29 20 3d 3d 20 54 79 70 65 41 66 66 69 6e 69 x) == TypeAffini
9060: 74 79 2e 4e 75 6c 6c 29 3b 0d 0a 20 20 20 20 7d ty.Null);.. }
9070: 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c .... internal
9080: 20 6f 76 65 72 72 69 64 65 20 69 6e 74 20 41 67 override int Ag
9090: 67 72 65 67 61 74 65 43 6f 75 6e 74 28 49 6e 74 gregateCount(Int
90a0: 50 74 72 20 63 6f 6e 74 65 78 74 29 0d 0a 20 20 Ptr context)..
90b0: 20 20 7b 0d 0a 20 20 20 20 20 20 72 65 74 75 72 {.. retur
90c0: 6e 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 n UnsafeNativeMe
90d0: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 61 67 thods.sqlite3_ag
90e0: 67 72 65 67 61 74 65 5f 63 6f 75 6e 74 28 63 6f gregate_count(co
90f0: 6e 74 65 78 74 29 3b 0d 0a 20 20 20 20 7d 0d 0a ntext);.. }..
9100: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
9110: 76 65 72 72 69 64 65 20 76 6f 69 64 20 43 72 65 verride void Cre
9120: 61 74 65 46 75 6e 63 74 69 6f 6e 28 73 74 72 69 ateFunction(stri
9130: 6e 67 20 73 74 72 46 75 6e 63 74 69 6f 6e 2c 20 ng strFunction,
9140: 69 6e 74 20 6e 41 72 67 73 2c 20 62 6f 6f 6c 20 int nArgs, bool
9150: 6e 65 65 64 43 6f 6c 6c 53 65 71 2c 20 53 51 4c needCollSeq, SQL
9160: 69 74 65 43 61 6c 6c 62 61 63 6b 20 66 75 6e 63 iteCallback func
9170: 2c 20 53 51 4c 69 74 65 43 61 6c 6c 62 61 63 6b , SQLiteCallback
9180: 20 66 75 6e 63 73 74 65 70 2c 20 53 51 4c 69 74 funcstep, SQLit
9190: 65 46 69 6e 61 6c 43 61 6c 6c 62 61 63 6b 20 66 eFinalCallback f
91a0: 75 6e 63 66 69 6e 61 6c 29 0d 0a 20 20 20 20 7b uncfinal).. {
91b0: 0d 0a 20 20 20 20 20 20 69 6e 74 20 6e 3b 0d 0a .. int n;..
91c0: 0d 0a 23 69 66 20 21 53 51 4c 49 54 45 5f 53 54 ..#if !SQLITE_ST
91d0: 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 20 6e 20 ANDARD.. n
91e0: 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 = UnsafeNativeMe
91f0: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 72 thods.sqlite3_cr
9200: 65 61 74 65 5f 66 75 6e 63 74 69 6f 6e 5f 69 6e eate_function_in
9210: 74 65 72 6f 70 28 5f 73 71 6c 2c 20 54 6f 55 54 terop(_sql, ToUT
9220: 46 38 28 73 74 72 46 75 6e 63 74 69 6f 6e 29 2c F8(strFunction),
9230: 20 6e 41 72 67 73 2c 20 34 2c 20 49 6e 74 50 74 nArgs, 4, IntPt
9240: 72 2e 5a 65 72 6f 2c 20 66 75 6e 63 2c 20 66 75 r.Zero, func, fu
9250: 6e 63 73 74 65 70 2c 20 66 75 6e 63 66 69 6e 61 ncstep, funcfina
9260: 6c 2c 20 28 6e 65 65 64 43 6f 6c 6c 53 65 71 20 l, (needCollSeq
9270: 3d 3d 20 74 72 75 65 29 20 3f 20 31 20 3a 20 30 == true) ? 1 : 0
9280: 29 3b 0d 0a 20 20 20 20 20 20 69 66 20 28 6e 20 );.. if (n
9290: 3d 3d 20 30 29 20 6e 20 3d 20 55 6e 73 61 66 65 == 0) n = Unsafe
92a0: 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 NativeMethods.sq
92b0: 6c 69 74 65 33 5f 63 72 65 61 74 65 5f 66 75 6e lite3_create_fun
92c0: 63 74 69 6f 6e 5f 69 6e 74 65 72 6f 70 28 5f 73 ction_interop(_s
92d0: 71 6c 2c 20 54 6f 55 54 46 38 28 73 74 72 46 75 ql, ToUTF8(strFu
92e0: 6e 63 74 69 6f 6e 29 2c 20 6e 41 72 67 73 2c 20 nction), nArgs,
92f0: 31 2c 20 49 6e 74 50 74 72 2e 5a 65 72 6f 2c 20 1, IntPtr.Zero,
9300: 66 75 6e 63 2c 20 66 75 6e 63 73 74 65 70 2c 20 func, funcstep,
9310: 66 75 6e 63 66 69 6e 61 6c 2c 20 28 6e 65 65 64 funcfinal, (need
9320: 43 6f 6c 6c 53 65 71 20 3d 3d 20 74 72 75 65 29 CollSeq == true)
9330: 20 3f 20 31 20 3a 20 30 29 3b 0d 0a 23 65 6c 73 ? 1 : 0);..#els
9340: 65 0d 0a 20 20 20 20 20 20 6e 20 3d 20 55 6e 73 e.. n = Uns
9350: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
9360: 2e 73 71 6c 69 74 65 33 5f 63 72 65 61 74 65 5f .sqlite3_create_
9370: 66 75 6e 63 74 69 6f 6e 28 5f 73 71 6c 2c 20 54 function(_sql, T
9380: 6f 55 54 46 38 28 73 74 72 46 75 6e 63 74 69 6f oUTF8(strFunctio
9390: 6e 29 2c 20 6e 41 72 67 73 2c 20 34 2c 20 49 6e n), nArgs, 4, In
93a0: 74 50 74 72 2e 5a 65 72 6f 2c 20 66 75 6e 63 2c tPtr.Zero, func,
93b0: 20 66 75 6e 63 73 74 65 70 2c 20 66 75 6e 63 66 funcstep, funcf
93c0: 69 6e 61 6c 29 3b 0d 0a 20 20 20 20 20 20 69 66 inal);.. if
93d0: 20 28 6e 20 3d 3d 20 30 29 20 6e 20 3d 20 55 6e (n == 0) n = Un
93e0: 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 safeNativeMethod
93f0: 73 2e 73 71 6c 69 74 65 33 5f 63 72 65 61 74 65 s.sqlite3_create
9400: 5f 66 75 6e 63 74 69 6f 6e 28 5f 73 71 6c 2c 20 _function(_sql,
9410: 54 6f 55 54 46 38 28 73 74 72 46 75 6e 63 74 69 ToUTF8(strFuncti
9420: 6f 6e 29 2c 20 6e 41 72 67 73 2c 20 31 2c 20 49 on), nArgs, 1, I
9430: 6e 74 50 74 72 2e 5a 65 72 6f 2c 20 66 75 6e 63 ntPtr.Zero, func
9440: 2c 20 66 75 6e 63 73 74 65 70 2c 20 66 75 6e 63 , funcstep, func
9450: 66 69 6e 61 6c 29 3b 0d 0a 23 65 6e 64 69 66 0d final);..#endif.
9460: 0a 20 20 20 20 20 20 69 66 20 28 6e 20 3e 20 30 . if (n > 0
9470: 29 20 74 68 72 6f 77 20 6e 65 77 20 53 51 4c 69 ) throw new SQLi
9480: 74 65 45 78 63 65 70 74 69 6f 6e 28 6e 2c 20 47 teException(n, G
9490: 65 74 4c 61 73 74 45 72 72 6f 72 28 29 29 3b 0d etLastError());.
94a0: 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e . }.... in
94b0: 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 ternal override
94c0: 76 6f 69 64 20 43 72 65 61 74 65 43 6f 6c 6c 61 void CreateColla
94d0: 74 69 6f 6e 28 73 74 72 69 6e 67 20 73 74 72 43 tion(string strC
94e0: 6f 6c 6c 61 74 69 6f 6e 2c 20 53 51 4c 69 74 65 ollation, SQLite
94f0: 43 6f 6c 6c 61 74 69 6f 6e 20 66 75 6e 63 2c 20 Collation func,
9500: 53 51 4c 69 74 65 43 6f 6c 6c 61 74 69 6f 6e 20 SQLiteCollation
9510: 66 75 6e 63 31 36 29 0d 0a 20 20 20 20 7b 0d 0a func16).. {..
9520: 20 20 20 20 20 20 69 6e 74 20 6e 20 3d 20 55 6e int n = Un
9530: 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 safeNativeMethod
9540: 73 2e 73 71 6c 69 74 65 33 5f 63 72 65 61 74 65 s.sqlite3_create
9550: 5f 63 6f 6c 6c 61 74 69 6f 6e 28 5f 73 71 6c 2c _collation(_sql,
9560: 20 54 6f 55 54 46 38 28 73 74 72 43 6f 6c 6c 61 ToUTF8(strColla
9570: 74 69 6f 6e 29 2c 20 32 2c 20 49 6e 74 50 74 72 tion), 2, IntPtr
9580: 2e 5a 65 72 6f 2c 20 66 75 6e 63 31 36 29 3b 0d .Zero, func16);.
9590: 0a 20 20 20 20 20 20 69 66 20 28 6e 20 3d 3d 20 . if (n ==
95a0: 30 29 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 0) n = UnsafeNat
95b0: 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 iveMethods.sqlit
95c0: 65 33 5f 63 72 65 61 74 65 5f 63 6f 6c 6c 61 74 e3_create_collat
95d0: 69 6f 6e 28 5f 73 71 6c 2c 20 54 6f 55 54 46 38 ion(_sql, ToUTF8
95e0: 28 73 74 72 43 6f 6c 6c 61 74 69 6f 6e 29 2c 20 (strCollation),
95f0: 31 2c 20 49 6e 74 50 74 72 2e 5a 65 72 6f 2c 20 1, IntPtr.Zero,
9600: 66 75 6e 63 29 3b 0d 0a 20 20 20 20 20 20 69 66 func);.. if
9610: 20 28 6e 20 3e 20 30 29 20 74 68 72 6f 77 20 6e (n > 0) throw n
9620: 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 74 69 ew SQLiteExcepti
9630: 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 72 72 on(n, GetLastErr
9640: 6f 72 28 29 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d or());.. }...
9650: 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 . internal ov
9660: 65 72 72 69 64 65 20 69 6e 74 20 43 6f 6e 74 65 erride int Conte
9670: 78 74 43 6f 6c 6c 61 74 65 43 6f 6d 70 61 72 65 xtCollateCompare
9680: 28 43 6f 6c 6c 61 74 69 6f 6e 45 6e 63 6f 64 69 (CollationEncodi
9690: 6e 67 45 6e 75 6d 20 65 6e 63 2c 20 49 6e 74 50 ngEnum enc, IntP
96a0: 74 72 20 63 6f 6e 74 65 78 74 2c 20 73 74 72 69 tr context, stri
96b0: 6e 67 20 73 31 2c 20 73 74 72 69 6e 67 20 73 32 ng s1, string s2
96c0: 29 0d 0a 20 20 20 20 7b 0d 0a 23 69 66 20 21 53 ).. {..#if !S
96d0: 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a QLITE_STANDARD..
96e0: 20 20 20 20 20 20 62 79 74 65 5b 5d 20 62 31 3b byte[] b1;
96f0: 0d 0a 20 20 20 20 20 20 62 79 74 65 5b 5d 20 62 .. byte[] b
9700: 32 3b 0d 0a 20 20 20 20 20 20 53 79 73 74 65 6d 2;.. System
9710: 2e 54 65 78 74 2e 45 6e 63 6f 64 69 6e 67 20 63 .Text.Encoding c
9720: 6f 6e 76 65 72 74 65 72 20 3d 20 6e 75 6c 6c 3b onverter = null;
9730: 0d 0a 0d 0a 20 20 20 20 20 20 73 77 69 74 63 68 .... switch
9740: 20 28 65 6e 63 29 0d 0a 20 20 20 20 20 20 7b 0d (enc).. {.
9750: 0a 20 20 20 20 20 20 20 20 63 61 73 65 20 43 6f . case Co
9760: 6c 6c 61 74 69 6f 6e 45 6e 63 6f 64 69 6e 67 45 llationEncodingE
9770: 6e 75 6d 2e 55 54 46 38 3a 0d 0a 20 20 20 20 20 num.UTF8:..
9780: 20 20 20 20 20 63 6f 6e 76 65 72 74 65 72 20 3d converter =
9790: 20 53 79 73 74 65 6d 2e 54 65 78 74 2e 45 6e 63 System.Text.Enc
97a0: 6f 64 69 6e 67 2e 55 54 46 38 3b 0d 0a 20 20 20 oding.UTF8;..
97b0: 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0d 0a 20 break;..
97c0: 20 20 20 20 20 20 20 63 61 73 65 20 43 6f 6c 6c case Coll
97d0: 61 74 69 6f 6e 45 6e 63 6f 64 69 6e 67 45 6e 75 ationEncodingEnu
97e0: 6d 2e 55 54 46 31 36 4c 45 3a 0d 0a 20 20 20 20 m.UTF16LE:..
97f0: 20 20 20 20 20 20 63 6f 6e 76 65 72 74 65 72 20 converter
9800: 3d 20 53 79 73 74 65 6d 2e 54 65 78 74 2e 45 6e = System.Text.En
9810: 63 6f 64 69 6e 67 2e 55 6e 69 63 6f 64 65 3b 0d coding.Unicode;.
9820: 0a 20 20 20 20 20 20 20 20 20 20 62 72 65 61 6b . break
9830: 3b 0d 0a 20 20 20 20 20 20 20 20 63 61 73 65 20 ;.. case
9840: 43 6f 6c 6c 61 74 69 6f 6e 45 6e 63 6f 64 69 6e CollationEncodin
9850: 67 45 6e 75 6d 2e 55 54 46 31 36 42 45 3a 0d 0a gEnum.UTF16BE:..
9860: 20 20 20 20 20 20 20 20 20 20 63 6f 6e 76 65 72 conver
9870: 74 65 72 20 3d 20 53 79 73 74 65 6d 2e 54 65 78 ter = System.Tex
9880: 74 2e 45 6e 63 6f 64 69 6e 67 2e 42 69 67 45 6e t.Encoding.BigEn
9890: 64 69 61 6e 55 6e 69 63 6f 64 65 3b 0d 0a 20 20 dianUnicode;..
98a0: 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0d 0a break;..
98b0: 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 }....
98c0: 20 62 31 20 3d 20 63 6f 6e 76 65 72 74 65 72 2e b1 = converter.
98d0: 47 65 74 42 79 74 65 73 28 73 31 29 3b 0d 0a 20 GetBytes(s1);..
98e0: 20 20 20 20 20 62 32 20 3d 20 63 6f 6e 76 65 72 b2 = conver
98f0: 74 65 72 2e 47 65 74 42 79 74 65 73 28 73 32 29 ter.GetBytes(s2)
9900: 3b 0d 0a 0d 0a 20 20 20 20 20 20 72 65 74 75 72 ;.... retur
9910: 6e 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 n UnsafeNativeMe
9920: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f thods.sqlite3_co
9930: 6e 74 65 78 74 5f 63 6f 6c 6c 63 6f 6d 70 61 72 ntext_collcompar
9940: 65 28 63 6f 6e 74 65 78 74 2c 20 62 31 2c 20 62 e(context, b1, b
9950: 31 2e 4c 65 6e 67 74 68 2c 20 62 32 2c 20 62 32 1.Length, b2, b2
9960: 2e 4c 65 6e 67 74 68 29 3b 0d 0a 23 65 6c 73 65 .Length);..#else
9970: 0d 0a 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 .. throw ne
9980: 77 20 4e 6f 74 49 6d 70 6c 65 6d 65 6e 74 65 64 w NotImplemented
9990: 45 78 63 65 70 74 69 6f 6e 28 29 3b 0d 0a 23 65 Exception();..#e
99a0: 6e 64 69 66 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 ndif.. }....
99b0: 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 internal over
99c0: 72 69 64 65 20 69 6e 74 20 43 6f 6e 74 65 78 74 ride int Context
99d0: 43 6f 6c 6c 61 74 65 43 6f 6d 70 61 72 65 28 43 CollateCompare(C
99e0: 6f 6c 6c 61 74 69 6f 6e 45 6e 63 6f 64 69 6e 67 ollationEncoding
99f0: 45 6e 75 6d 20 65 6e 63 2c 20 49 6e 74 50 74 72 Enum enc, IntPtr
9a00: 20 63 6f 6e 74 65 78 74 2c 20 63 68 61 72 5b 5d context, char[]
9a10: 20 63 31 2c 20 63 68 61 72 5b 5d 20 63 32 29 0d c1, char[] c2).
9a20: 0a 20 20 20 20 7b 0d 0a 23 69 66 20 21 53 51 4c . {..#if !SQL
9a30: 49 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a 20 20 ITE_STANDARD..
9a40: 20 20 20 20 62 79 74 65 5b 5d 20 62 31 3b 0d 0a byte[] b1;..
9a50: 20 20 20 20 20 20 62 79 74 65 5b 5d 20 62 32 3b byte[] b2;
9a60: 0d 0a 20 20 20 20 20 20 53 79 73 74 65 6d 2e 54 .. System.T
9a70: 65 78 74 2e 45 6e 63 6f 64 69 6e 67 20 63 6f 6e ext.Encoding con
9a80: 76 65 72 74 65 72 20 3d 20 6e 75 6c 6c 3b 0d 0a verter = null;..
9a90: 0d 0a 20 20 20 20 20 20 73 77 69 74 63 68 20 28 .. switch (
9aa0: 65 6e 63 29 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 enc).. {..
9ab0: 20 20 20 20 20 20 20 63 61 73 65 20 43 6f 6c 6c case Coll
9ac0: 61 74 69 6f 6e 45 6e 63 6f 64 69 6e 67 45 6e 75 ationEncodingEnu
9ad0: 6d 2e 55 54 46 38 3a 0d 0a 20 20 20 20 20 20 20 m.UTF8:..
9ae0: 20 20 20 63 6f 6e 76 65 72 74 65 72 20 3d 20 53 converter = S
9af0: 79 73 74 65 6d 2e 54 65 78 74 2e 45 6e 63 6f 64 ystem.Text.Encod
9b00: 69 6e 67 2e 55 54 46 38 3b 0d 0a 20 20 20 20 20 ing.UTF8;..
9b10: 20 20 20 20 20 62 72 65 61 6b 3b 0d 0a 20 20 20 break;..
9b20: 20 20 20 20 20 63 61 73 65 20 43 6f 6c 6c 61 74 case Collat
9b30: 69 6f 6e 45 6e 63 6f 64 69 6e 67 45 6e 75 6d 2e ionEncodingEnum.
9b40: 55 54 46 31 36 4c 45 3a 0d 0a 20 20 20 20 20 20 UTF16LE:..
9b50: 20 20 20 20 63 6f 6e 76 65 72 74 65 72 20 3d 20 converter =
9b60: 53 79 73 74 65 6d 2e 54 65 78 74 2e 45 6e 63 6f System.Text.Enco
9b70: 64 69 6e 67 2e 55 6e 69 63 6f 64 65 3b 0d 0a 20 ding.Unicode;..
9b80: 20 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0d break;.
9b90: 0a 20 20 20 20 20 20 20 20 63 61 73 65 20 43 6f . case Co
9ba0: 6c 6c 61 74 69 6f 6e 45 6e 63 6f 64 69 6e 67 45 llationEncodingE
9bb0: 6e 75 6d 2e 55 54 46 31 36 42 45 3a 0d 0a 20 20 num.UTF16BE:..
9bc0: 20 20 20 20 20 20 20 20 63 6f 6e 76 65 72 74 65 converte
9bd0: 72 20 3d 20 53 79 73 74 65 6d 2e 54 65 78 74 2e r = System.Text.
9be0: 45 6e 63 6f 64 69 6e 67 2e 42 69 67 45 6e 64 69 Encoding.BigEndi
9bf0: 61 6e 55 6e 69 63 6f 64 65 3b 0d 0a 20 20 20 20 anUnicode;..
9c00: 20 20 20 20 20 20 62 72 65 61 6b 3b 0d 0a 20 20 break;..
9c10: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 62 }.... b
9c20: 31 20 3d 20 63 6f 6e 76 65 72 74 65 72 2e 47 65 1 = converter.Ge
9c30: 74 42 79 74 65 73 28 63 31 29 3b 0d 0a 20 20 20 tBytes(c1);..
9c40: 20 20 20 62 32 20 3d 20 63 6f 6e 76 65 72 74 65 b2 = converte
9c50: 72 2e 47 65 74 42 79 74 65 73 28 63 32 29 3b 0d r.GetBytes(c2);.
9c60: 0a 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 ... return
9c70: 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 UnsafeNativeMeth
9c80: 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f 6e 74 ods.sqlite3_cont
9c90: 65 78 74 5f 63 6f 6c 6c 63 6f 6d 70 61 72 65 28 ext_collcompare(
9ca0: 63 6f 6e 74 65 78 74 2c 20 62 31 2c 20 62 31 2e context, b1, b1.
9cb0: 4c 65 6e 67 74 68 2c 20 62 32 2c 20 62 32 2e 4c Length, b2, b2.L
9cc0: 65 6e 67 74 68 29 3b 0d 0a 23 65 6c 73 65 0d 0a ength);..#else..
9cd0: 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 77 20 throw new
9ce0: 4e 6f 74 49 6d 70 6c 65 6d 65 6e 74 65 64 45 78 NotImplementedEx
9cf0: 63 65 70 74 69 6f 6e 28 29 3b 0d 0a 23 65 6e 64 ception();..#end
9d00: 69 66 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 if.. }....
9d10: 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 internal overri
9d20: 64 65 20 43 6f 6c 6c 61 74 69 6f 6e 53 65 71 75 de CollationSequ
9d30: 65 6e 63 65 20 47 65 74 43 6f 6c 6c 61 74 69 6f ence GetCollatio
9d40: 6e 53 65 71 75 65 6e 63 65 28 53 51 4c 69 74 65 nSequence(SQLite
9d50: 46 75 6e 63 74 69 6f 6e 20 66 75 6e 63 2c 20 49 Function func, I
9d60: 6e 74 50 74 72 20 63 6f 6e 74 65 78 74 29 0d 0a ntPtr context)..
9d70: 20 20 20 20 7b 0d 0a 23 69 66 20 21 53 51 4c 49 {..#if !SQLI
9d80: 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a 20 20 20 TE_STANDARD..
9d90: 20 20 20 43 6f 6c 6c 61 74 69 6f 6e 53 65 71 75 CollationSequ
9da0: 65 6e 63 65 20 73 65 71 20 3d 20 6e 65 77 20 43 ence seq = new C
9db0: 6f 6c 6c 61 74 69 6f 6e 53 65 71 75 65 6e 63 65 ollationSequence
9dc0: 28 29 3b 0d 0a 20 20 20 20 20 20 69 6e 74 20 6c ();.. int l
9dd0: 65 6e 3b 0d 0a 20 20 20 20 20 20 69 6e 74 20 74 en;.. int t
9de0: 79 70 65 3b 0d 0a 20 20 20 20 20 20 69 6e 74 20 ype;.. int
9df0: 65 6e 63 3b 0d 0a 20 20 20 20 20 20 49 6e 74 50 enc;.. IntP
9e00: 74 72 20 70 20 3d 20 55 6e 73 61 66 65 4e 61 74 tr p = UnsafeNat
9e10: 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 iveMethods.sqlit
9e20: 65 33 5f 63 6f 6e 74 65 78 74 5f 63 6f 6c 6c 73 e3_context_colls
9e30: 65 71 28 63 6f 6e 74 65 78 74 2c 20 6f 75 74 20 eq(context, out
9e40: 74 79 70 65 2c 20 6f 75 74 20 65 6e 63 2c 20 6f type, out enc, o
9e50: 75 74 20 6c 65 6e 29 3b 0d 0a 0d 0a 20 20 20 20 ut len);....
9e60: 20 20 69 66 20 28 70 20 21 3d 20 6e 75 6c 6c 29 if (p != null)
9e70: 20 73 65 71 2e 4e 61 6d 65 20 3d 20 55 54 46 38 seq.Name = UTF8
9e80: 54 6f 53 74 72 69 6e 67 28 70 2c 20 6c 65 6e 29 ToString(p, len)
9e90: 3b 0d 0a 20 20 20 20 20 20 73 65 71 2e 54 79 70 ;.. seq.Typ
9ea0: 65 20 3d 20 28 43 6f 6c 6c 61 74 69 6f 6e 54 79 e = (CollationTy
9eb0: 70 65 45 6e 75 6d 29 74 79 70 65 3b 0d 0a 20 20 peEnum)type;..
9ec0: 20 20 20 20 73 65 71 2e 5f 66 75 6e 63 20 3d 20 seq._func =
9ed0: 66 75 6e 63 3b 0d 0a 20 20 20 20 20 20 73 65 71 func;.. seq
9ee0: 2e 45 6e 63 6f 64 69 6e 67 20 3d 20 28 43 6f 6c .Encoding = (Col
9ef0: 6c 61 74 69 6f 6e 45 6e 63 6f 64 69 6e 67 45 6e lationEncodingEn
9f00: 75 6d 29 65 6e 63 3b 0d 0a 0d 0a 20 20 20 20 20 um)enc;....
9f10: 20 72 65 74 75 72 6e 20 73 65 71 3b 0d 0a 23 65 return seq;..#e
9f20: 6c 73 65 0d 0a 20 20 20 20 20 20 74 68 72 6f 77 lse.. throw
9f30: 20 6e 65 77 20 4e 6f 74 49 6d 70 6c 65 6d 65 6e new NotImplemen
9f40: 74 65 64 45 78 63 65 70 74 69 6f 6e 28 29 3b 0d tedException();.
9f50: 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 7d 0d 0a .#endif.. }..
9f60: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
9f70: 76 65 72 72 69 64 65 20 6c 6f 6e 67 20 47 65 74 verride long Get
9f80: 50 61 72 61 6d 56 61 6c 75 65 42 79 74 65 73 28 ParamValueBytes(
9f90: 49 6e 74 50 74 72 20 70 2c 20 69 6e 74 20 6e 44 IntPtr p, int nD
9fa0: 61 74 61 4f 66 66 73 65 74 2c 20 62 79 74 65 5b ataOffset, byte[
9fb0: 5d 20 62 44 65 73 74 2c 20 69 6e 74 20 6e 53 74 ] bDest, int nSt
9fc0: 61 72 74 2c 20 69 6e 74 20 6e 4c 65 6e 67 74 68 art, int nLength
9fd0: 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 ).. {..
9fe0: 69 6e 74 20 6e 6c 65 6e 20 3d 20 55 6e 73 61 66 int nlen = Unsaf
9ff0: 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
a000: 71 6c 69 74 65 33 5f 76 61 6c 75 65 5f 62 79 74 qlite3_value_byt
a010: 65 73 28 70 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 es(p);....
a020: 2f 2f 20 49 66 20 6e 6f 20 64 65 73 74 69 6e 61 // If no destina
a030: 74 69 6f 6e 20 62 75 66 66 65 72 2c 20 72 65 74 tion buffer, ret
a040: 75 72 6e 20 74 68 65 20 73 69 7a 65 20 6e 65 65 urn the size nee
a050: 64 65 64 2e 0d 0a 20 20 20 20 20 20 69 66 20 28 ded... if (
a060: 62 44 65 73 74 20 3d 3d 20 6e 75 6c 6c 29 20 72 bDest == null) r
a070: 65 74 75 72 6e 20 6e 6c 65 6e 3b 0d 0a 0d 0a 20 eturn nlen;....
a080: 20 20 20 20 20 69 6e 74 20 6e 43 6f 70 69 65 64 int nCopied
a090: 20 3d 20 6e 4c 65 6e 67 74 68 3b 0d 0a 0d 0a 20 = nLength;....
a0a0: 20 20 20 20 20 69 66 20 28 6e 43 6f 70 69 65 64 if (nCopied
a0b0: 20 2b 20 6e 53 74 61 72 74 20 3e 20 62 44 65 73 + nStart > bDes
a0c0: 74 2e 4c 65 6e 67 74 68 29 20 6e 43 6f 70 69 65 t.Length) nCopie
a0d0: 64 20 3d 20 62 44 65 73 74 2e 4c 65 6e 67 74 68 d = bDest.Length
a0e0: 20 2d 20 6e 53 74 61 72 74 3b 0d 0a 20 20 20 20 - nStart;..
a0f0: 20 20 69 66 20 28 6e 43 6f 70 69 65 64 20 2b 20 if (nCopied +
a100: 6e 44 61 74 61 4f 66 66 73 65 74 20 3e 20 6e 6c nDataOffset > nl
a110: 65 6e 29 20 6e 43 6f 70 69 65 64 20 3d 20 6e 6c en) nCopied = nl
a120: 65 6e 20 2d 20 6e 44 61 74 61 4f 66 66 73 65 74 en - nDataOffset
a130: 3b 0d 0a 0d 0a 20 20 20 20 20 20 69 66 20 28 6e ;.... if (n
a140: 43 6f 70 69 65 64 20 3e 20 30 29 0d 0a 20 20 20 Copied > 0)..
a150: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 49 6e {.. In
a160: 74 50 74 72 20 70 74 72 20 3d 20 55 6e 73 61 66 tPtr ptr = Unsaf
a170: 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
a180: 71 6c 69 74 65 33 5f 76 61 6c 75 65 5f 62 6c 6f qlite3_value_blo
a190: 62 28 70 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 b(p);....
a1a0: 20 4d 61 72 73 68 61 6c 2e 43 6f 70 79 28 28 49 Marshal.Copy((I
a1b0: 6e 74 50 74 72 29 28 70 74 72 2e 54 6f 49 6e 74 ntPtr)(ptr.ToInt
a1c0: 36 34 28 29 20 2b 20 6e 44 61 74 61 4f 66 66 73 64() + nDataOffs
a1d0: 65 74 29 2c 20 62 44 65 73 74 2c 20 6e 53 74 61 et), bDest, nSta
a1e0: 72 74 2c 20 6e 43 6f 70 69 65 64 29 3b 0d 0a 20 rt, nCopied);..
a1f0: 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 65 6c }.. el
a200: 73 65 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 20 20 se.. {..
a210: 20 20 20 20 20 6e 43 6f 70 69 65 64 20 3d 20 30 nCopied = 0
a220: 3b 0d 0a 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 ;.. }....
a230: 20 20 20 20 72 65 74 75 72 6e 20 6e 43 6f 70 69 return nCopi
a240: 65 64 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 ed;.. }....
a250: 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
a260: 69 64 65 20 64 6f 75 62 6c 65 20 47 65 74 50 61 ide double GetPa
a270: 72 61 6d 56 61 6c 75 65 44 6f 75 62 6c 65 28 49 ramValueDouble(I
a280: 6e 74 50 74 72 20 70 74 72 29 0d 0a 20 20 20 20 ntPtr ptr)..
a290: 7b 0d 0a 20 20 20 20 20 20 64 6f 75 62 6c 65 20 {.. double
a2a0: 76 61 6c 75 65 3b 0d 0a 23 69 66 20 21 50 4c 41 value;..#if !PLA
a2b0: 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 41 TFORM_COMPACTFRA
a2c0: 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 20 20 76 61 MEWORK.. va
a2d0: 6c 75 65 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 lue = UnsafeNati
a2e0: 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 veMethods.sqlite
a2f0: 33 5f 76 61 6c 75 65 5f 64 6f 75 62 6c 65 28 70 3_value_double(p
a300: 74 72 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 tr);..#else..
a310: 20 20 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d UnsafeNativeM
a320: 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 76 ethods.sqlite3_v
a330: 61 6c 75 65 5f 64 6f 75 62 6c 65 5f 69 6e 74 65 alue_double_inte
a340: 72 6f 70 28 70 74 72 2c 20 6f 75 74 20 76 61 6c rop(ptr, out val
a350: 75 65 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 ue);..#endif..
a360: 20 20 20 20 72 65 74 75 72 6e 20 76 61 6c 75 65 return value
a370: 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 ;.. }....
a380: 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 internal overrid
a390: 65 20 69 6e 74 20 47 65 74 50 61 72 61 6d 56 61 e int GetParamVa
a3a0: 6c 75 65 49 6e 74 33 32 28 49 6e 74 50 74 72 20 lueInt32(IntPtr
a3b0: 70 74 72 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 ptr).. {..
a3c0: 20 20 20 72 65 74 75 72 6e 20 55 6e 73 61 66 65 return Unsafe
a3d0: 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 NativeMethods.sq
a3e0: 6c 69 74 65 33 5f 76 61 6c 75 65 5f 69 6e 74 28 lite3_value_int(
a3f0: 70 74 72 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a ptr);.. }....
a400: 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 internal ove
a410: 72 72 69 64 65 20 6c 6f 6e 67 20 47 65 74 50 61 rride long GetPa
a420: 72 61 6d 56 61 6c 75 65 49 6e 74 36 34 28 49 6e ramValueInt64(In
a430: 74 50 74 72 20 70 74 72 29 0d 0a 20 20 20 20 7b tPtr ptr).. {
a440: 0d 0a 20 20 20 20 20 20 49 6e 74 36 34 20 76 61 .. Int64 va
a450: 6c 75 65 3b 0d 0a 23 69 66 20 21 50 4c 41 54 46 lue;..#if !PLATF
a460: 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 41 4d 45 ORM_COMPACTFRAME
a470: 57 4f 52 4b 0d 0a 20 20 20 20 20 20 76 61 6c 75 WORK.. valu
a480: 65 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 e = UnsafeNative
a490: 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f Methods.sqlite3_
a4a0: 76 61 6c 75 65 5f 69 6e 74 36 34 28 70 74 72 29 value_int64(ptr)
a4b0: 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 ;..#else..
a4c0: 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 UnsafeNativeMeth
a4d0: 6f 64 73 2e 73 71 6c 69 74 65 33 5f 76 61 6c 75 ods.sqlite3_valu
a4e0: 65 5f 69 6e 74 36 34 5f 69 6e 74 65 72 6f 70 28 e_int64_interop(
a4f0: 70 74 72 2c 20 6f 75 74 20 76 61 6c 75 65 29 3b ptr, out value);
a500: 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 20 20 ..#endif..
a510: 72 65 74 75 72 6e 20 76 61 6c 75 65 3b 0d 0a 20 return value;..
a520: 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 }.... inte
a530: 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 73 74 rnal override st
a540: 72 69 6e 67 20 47 65 74 50 61 72 61 6d 56 61 6c ring GetParamVal
a550: 75 65 54 65 78 74 28 49 6e 74 50 74 72 20 70 74 ueText(IntPtr pt
a560: 72 29 0d 0a 20 20 20 20 7b 0d 0a 23 69 66 20 21 r).. {..#if !
a570: 53 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d SQLITE_STANDARD.
a580: 0a 20 20 20 20 20 20 69 6e 74 20 6c 65 6e 3b 0d . int len;.
a590: 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 55 54 . return UT
a5a0: 46 38 54 6f 53 74 72 69 6e 67 28 55 6e 73 61 66 F8ToString(Unsaf
a5b0: 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
a5c0: 71 6c 69 74 65 33 5f 76 61 6c 75 65 5f 74 65 78 qlite3_value_tex
a5d0: 74 5f 69 6e 74 65 72 6f 70 28 70 74 72 2c 20 6f t_interop(ptr, o
a5e0: 75 74 20 6c 65 6e 29 2c 20 6c 65 6e 29 3b 0d 0a ut len), len);..
a5f0: 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 72 65 74 #else.. ret
a600: 75 72 6e 20 55 54 46 38 54 6f 53 74 72 69 6e 67 urn UTF8ToString
a610: 28 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 (UnsafeNativeMet
a620: 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 76 61 6c hods.sqlite3_val
a630: 75 65 5f 74 65 78 74 28 70 74 72 29 2c 20 2d 31 ue_text(ptr), -1
a640: 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 );..#endif..
a650: 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 }.... interna
a660: 6c 20 6f 76 65 72 72 69 64 65 20 54 79 70 65 41 l override TypeA
a670: 66 66 69 6e 69 74 79 20 47 65 74 50 61 72 61 6d ffinity GetParam
a680: 56 61 6c 75 65 54 79 70 65 28 49 6e 74 50 74 72 ValueType(IntPtr
a690: 20 70 74 72 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 ptr).. {..
a6a0: 20 20 20 20 72 65 74 75 72 6e 20 55 6e 73 61 66 return Unsaf
a6b0: 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
a6c0: 71 6c 69 74 65 33 5f 76 61 6c 75 65 5f 74 79 70 qlite3_value_typ
a6d0: 65 28 70 74 72 29 3b 0d 0a 20 20 20 20 7d 0d 0a e(ptr);.. }..
a6e0: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
a6f0: 76 65 72 72 69 64 65 20 76 6f 69 64 20 52 65 74 verride void Ret
a700: 75 72 6e 42 6c 6f 62 28 49 6e 74 50 74 72 20 63 urnBlob(IntPtr c
a710: 6f 6e 74 65 78 74 2c 20 62 79 74 65 5b 5d 20 76 ontext, byte[] v
a720: 61 6c 75 65 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 alue).. {..
a730: 20 20 20 20 55 6e 73 61 66 65 4e 61 74 69 76 65 UnsafeNative
a740: 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f Methods.sqlite3_
a750: 72 65 73 75 6c 74 5f 62 6c 6f 62 28 63 6f 6e 74 result_blob(cont
a760: 65 78 74 2c 20 76 61 6c 75 65 2c 20 76 61 6c 75 ext, value, valu
a770: 65 2e 4c 65 6e 67 74 68 2c 20 28 49 6e 74 50 74 e.Length, (IntPt
a780: 72 29 28 2d 31 29 29 3b 0d 0a 20 20 20 20 7d 0d r)(-1));.. }.
a790: 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 ... internal
a7a0: 6f 76 65 72 72 69 64 65 20 76 6f 69 64 20 52 65 override void Re
a7b0: 74 75 72 6e 44 6f 75 62 6c 65 28 49 6e 74 50 74 turnDouble(IntPt
a7c0: 72 20 63 6f 6e 74 65 78 74 2c 20 64 6f 75 62 6c r context, doubl
a7d0: 65 20 76 61 6c 75 65 29 0d 0a 20 20 20 20 7b 0d e value).. {.
a7e0: 0a 23 69 66 20 21 50 4c 41 54 46 4f 52 4d 5f 43 .#if !PLATFORM_C
a7f0: 4f 4d 50 41 43 54 46 52 41 4d 45 57 4f 52 4b 0d OMPACTFRAMEWORK.
a800: 0a 20 20 20 20 20 20 55 6e 73 61 66 65 4e 61 74 . UnsafeNat
a810: 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 iveMethods.sqlit
a820: 65 33 5f 72 65 73 75 6c 74 5f 64 6f 75 62 6c 65 e3_result_double
a830: 28 63 6f 6e 74 65 78 74 2c 20 76 61 6c 75 65 29 (context, value)
a840: 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 ;..#else..
a850: 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 UnsafeNativeMeth
a860: 6f 64 73 2e 73 71 6c 69 74 65 33 5f 72 65 73 75 ods.sqlite3_resu
a870: 6c 74 5f 64 6f 75 62 6c 65 5f 69 6e 74 65 72 6f lt_double_intero
a880: 70 28 63 6f 6e 74 65 78 74 2c 20 72 65 66 20 76 p(context, ref v
a890: 61 6c 75 65 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a alue);..#endif..
a8a0: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 }.... int
a8b0: 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 76 ernal override v
a8c0: 6f 69 64 20 52 65 74 75 72 6e 45 72 72 6f 72 28 oid ReturnError(
a8d0: 49 6e 74 50 74 72 20 63 6f 6e 74 65 78 74 2c 20 IntPtr context,
a8e0: 73 74 72 69 6e 67 20 76 61 6c 75 65 29 0d 0a 20 string value)..
a8f0: 20 20 20 7b 0d 0a 20 20 20 20 20 20 55 6e 73 61 {.. Unsa
a900: 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
a910: 73 71 6c 69 74 65 33 5f 72 65 73 75 6c 74 5f 65 sqlite3_result_e
a920: 72 72 6f 72 28 63 6f 6e 74 65 78 74 2c 20 54 6f rror(context, To
a930: 55 54 46 38 28 76 61 6c 75 65 29 2c 20 76 61 6c UTF8(value), val
a940: 75 65 2e 4c 65 6e 67 74 68 29 3b 0d 0a 20 20 20 ue.Length);..
a950: 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e }.... intern
a960: 61 6c 20 6f 76 65 72 72 69 64 65 20 76 6f 69 64 al override void
a970: 20 52 65 74 75 72 6e 49 6e 74 33 32 28 49 6e 74 ReturnInt32(Int
a980: 50 74 72 20 63 6f 6e 74 65 78 74 2c 20 69 6e 74 Ptr context, int
a990: 20 76 61 6c 75 65 29 0d 0a 20 20 20 20 7b 0d 0a value).. {..
a9a0: 20 20 20 20 20 20 55 6e 73 61 66 65 4e 61 74 69 UnsafeNati
a9b0: 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 veMethods.sqlite
a9c0: 33 5f 72 65 73 75 6c 74 5f 69 6e 74 28 63 6f 6e 3_result_int(con
a9d0: 74 65 78 74 2c 20 76 61 6c 75 65 29 3b 0d 0a 20 text, value);..
a9e0: 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 }.... inte
a9f0: 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 76 6f rnal override vo
aa00: 69 64 20 52 65 74 75 72 6e 49 6e 74 36 34 28 49 id ReturnInt64(I
aa10: 6e 74 50 74 72 20 63 6f 6e 74 65 78 74 2c 20 6c ntPtr context, l
aa20: 6f 6e 67 20 76 61 6c 75 65 29 0d 0a 20 20 20 20 ong value)..
aa30: 7b 0d 0a 23 69 66 20 21 50 4c 41 54 46 4f 52 4d {..#if !PLATFORM
aa40: 5f 43 4f 4d 50 41 43 54 46 52 41 4d 45 57 4f 52 _COMPACTFRAMEWOR
aa50: 4b 0d 0a 20 20 20 20 20 20 55 6e 73 61 66 65 4e K.. UnsafeN
aa60: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
aa70: 69 74 65 33 5f 72 65 73 75 6c 74 5f 69 6e 74 36 ite3_result_int6
aa80: 34 28 63 6f 6e 74 65 78 74 2c 20 76 61 6c 75 65 4(context, value
aa90: 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 );..#else..
aaa0: 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 UnsafeNativeMet
aab0: 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 72 65 73 hods.sqlite3_res
aac0: 75 6c 74 5f 69 6e 74 36 34 5f 69 6e 74 65 72 6f ult_int64_intero
aad0: 70 28 63 6f 6e 74 65 78 74 2c 20 72 65 66 20 76 p(context, ref v
aae0: 61 6c 75 65 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a alue);..#endif..
aaf0: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 }.... int
ab00: 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 76 ernal override v
ab10: 6f 69 64 20 52 65 74 75 72 6e 4e 75 6c 6c 28 49 oid ReturnNull(I
ab20: 6e 74 50 74 72 20 63 6f 6e 74 65 78 74 29 0d 0a ntPtr context)..
ab30: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 55 6e 73 {.. Uns
ab40: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
ab50: 2e 73 71 6c 69 74 65 33 5f 72 65 73 75 6c 74 5f .sqlite3_result_
ab60: 6e 75 6c 6c 28 63 6f 6e 74 65 78 74 29 3b 0d 0a null(context);..
ab70: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 }.... int
ab80: 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 76 ernal override v
ab90: 6f 69 64 20 52 65 74 75 72 6e 54 65 78 74 28 49 oid ReturnText(I
aba0: 6e 74 50 74 72 20 63 6f 6e 74 65 78 74 2c 20 73 ntPtr context, s
abb0: 74 72 69 6e 67 20 76 61 6c 75 65 29 0d 0a 20 20 tring value)..
abc0: 20 20 7b 0d 0a 20 20 20 20 20 20 62 79 74 65 5b {.. byte[
abd0: 5d 20 62 20 3d 20 54 6f 55 54 46 38 28 76 61 6c ] b = ToUTF8(val
abe0: 75 65 29 3b 0d 0a 20 20 20 20 20 20 55 6e 73 61 ue);.. Unsa
abf0: 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
ac00: 73 71 6c 69 74 65 33 5f 72 65 73 75 6c 74 5f 74 sqlite3_result_t
ac10: 65 78 74 28 63 6f 6e 74 65 78 74 2c 20 54 6f 55 ext(context, ToU
ac20: 54 46 38 28 76 61 6c 75 65 29 2c 20 62 2e 4c 65 TF8(value), b.Le
ac30: 6e 67 74 68 20 2d 20 31 2c 20 28 49 6e 74 50 74 ngth - 1, (IntPt
ac40: 72 29 28 2d 31 29 29 3b 0d 0a 20 20 20 20 7d 0d r)(-1));.. }.
ac50: 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 ... internal
ac60: 6f 76 65 72 72 69 64 65 20 49 6e 74 50 74 72 20 override IntPtr
ac70: 41 67 67 72 65 67 61 74 65 43 6f 6e 74 65 78 74 AggregateContext
ac80: 28 49 6e 74 50 74 72 20 63 6f 6e 74 65 78 74 29 (IntPtr context)
ac90: 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 72 .. {.. r
aca0: 65 74 75 72 6e 20 55 6e 73 61 66 65 4e 61 74 69 eturn UnsafeNati
acb0: 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 veMethods.sqlite
acc0: 33 5f 61 67 67 72 65 67 61 74 65 5f 63 6f 6e 74 3_aggregate_cont
acd0: 65 78 74 28 63 6f 6e 74 65 78 74 2c 20 31 29 3b ext(context, 1);
ace0: 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 2f .. }.... /
acf0: 2f 2f 20 45 6e 61 62 6c 65 73 20 6f 72 20 64 69 // Enables or di
ad00: 73 61 62 6c 65 64 20 65 78 74 65 6e 64 65 64 20 sabled extended
ad10: 72 65 73 75 6c 74 20 63 6f 64 65 73 20 72 65 74 result codes ret
ad20: 75 72 6e 65 64 20 62 79 20 53 51 4c 69 74 65 0d urned by SQLite.
ad30: 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 . internal ov
ad40: 65 72 72 69 64 65 20 76 6f 69 64 20 53 65 74 45 erride void SetE
ad50: 78 74 65 6e 64 65 64 52 65 73 75 6c 74 43 6f 64 xtendedResultCod
ad60: 65 73 28 62 6f 6f 6c 20 62 4f 6e 4f 66 66 29 0d es(bool bOnOff).
ad70: 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 55 6e . {.. Un
ad80: 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 safeNativeMethod
ad90: 73 2e 73 71 6c 69 74 65 33 5f 65 78 74 65 6e 64 s.sqlite3_extend
ada0: 65 64 5f 72 65 73 75 6c 74 5f 63 6f 64 65 73 28 ed_result_codes(
adb0: 5f 73 71 6c 2c 20 28 62 4f 6e 4f 66 66 20 3f 20 _sql, (bOnOff ?
adc0: 2d 31 20 3a 20 30 29 29 3b 0d 0a 20 20 20 20 7d -1 : 0));.. }
add0: 0d 0a 20 20 20 20 2f 2f 2f 20 47 65 74 73 20 74 .. /// Gets t
ade0: 68 65 20 6c 61 73 74 20 53 51 4c 69 74 65 20 65 he last SQLite e
adf0: 72 72 6f 72 20 63 6f 64 65 0d 0a 20 20 20 20 69 rror code.. i
ae00: 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 nternal override
ae10: 20 69 6e 74 20 52 65 73 75 6c 74 43 6f 64 65 28 int ResultCode(
ae20: 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 ).. {..
ae30: 72 65 74 75 72 6e 20 55 6e 73 61 66 65 4e 61 74 return UnsafeNat
ae40: 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 iveMethods.sqlit
ae50: 65 33 5f 65 72 72 63 6f 64 65 28 5f 73 71 6c 29 e3_errcode(_sql)
ae60: 3b 0d 0a 20 20 20 20 7d 0d 0a 20 20 20 20 2f 2f ;.. }.. //
ae70: 2f 20 47 65 74 73 20 74 68 65 20 6c 61 73 74 20 / Gets the last
ae80: 53 51 4c 69 74 65 20 65 78 74 65 6e 64 65 64 20 SQLite extended
ae90: 65 72 72 6f 72 20 63 6f 64 65 0d 0a 20 20 20 20 error code..
aea0: 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 internal overrid
aeb0: 65 20 69 6e 74 20 45 78 74 65 6e 64 65 64 52 65 e int ExtendedRe
aec0: 73 75 6c 74 43 6f 64 65 28 29 0d 0a 20 20 20 20 sultCode()..
aed0: 7b 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 {.. return
aee0: 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 UnsafeNativeMeth
aef0: 6f 64 73 2e 73 71 6c 69 74 65 33 5f 65 78 74 65 ods.sqlite3_exte
af00: 6e 64 65 64 5f 65 72 72 63 6f 64 65 28 5f 73 71 nded_errcode(_sq
af10: 6c 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 l);.. }....
af20: 20 20 2f 2f 2f 20 41 64 64 20 61 20 6c 6f 67 20 /// Add a log
af30: 6d 65 73 73 61 67 65 20 76 69 61 20 74 68 65 20 message via the
af40: 53 51 4c 69 74 65 20 73 71 6c 69 74 65 33 5f 6c SQLite sqlite3_l
af50: 6f 67 20 69 6e 74 65 72 66 61 63 65 2e 0d 0a 20 og interface...
af60: 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 internal over
af70: 72 69 64 65 20 76 6f 69 64 20 4c 6f 67 4d 65 73 ride void LogMes
af80: 73 61 67 65 28 69 6e 74 20 69 45 72 72 43 6f 64 sage(int iErrCod
af90: 65 2c 20 73 74 72 69 6e 67 20 7a 4d 65 73 73 61 e, string zMessa
afa0: 67 65 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 ge).. {..
afb0: 20 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 UnsafeNativeMe
afc0: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 6c 6f thods.sqlite3_lo
afd0: 67 28 69 45 72 72 43 6f 64 65 2c 20 54 6f 55 54 g(iErrCode, ToUT
afe0: 46 38 28 7a 4d 65 73 73 61 67 65 29 29 3b 0d 0a F8(zMessage));..
aff0: 20 20 20 20 7d 0d 0a 0d 0a 23 69 66 20 49 4e 54 }....#if INT
b000: 45 52 4f 50 5f 43 4f 44 45 43 0d 0a 20 20 20 20 EROP_CODEC..
b010: 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 internal overrid
b020: 65 20 76 6f 69 64 20 53 65 74 50 61 73 73 77 6f e void SetPasswo
b030: 72 64 28 62 79 74 65 5b 5d 20 70 61 73 73 77 6f rd(byte[] passwo
b040: 72 64 42 79 74 65 73 29 0d 0a 20 20 20 20 7b 0d rdBytes).. {.
b050: 0a 20 20 20 20 20 20 69 6e 74 20 6e 20 3d 20 55 . int n = U
b060: 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
b070: 64 73 2e 73 71 6c 69 74 65 33 5f 6b 65 79 28 5f ds.sqlite3_key(_
b080: 73 71 6c 2c 20 70 61 73 73 77 6f 72 64 42 79 74 sql, passwordByt
b090: 65 73 2c 20 70 61 73 73 77 6f 72 64 42 79 74 65 es, passwordByte
b0a0: 73 2e 4c 65 6e 67 74 68 29 3b 0d 0a 20 20 20 20 s.Length);..
b0b0: 20 20 69 66 20 28 6e 20 3e 20 30 29 20 74 68 72 if (n > 0) thr
b0c0: 6f 77 20 6e 65 77 20 53 51 4c 69 74 65 45 78 63 ow new SQLiteExc
b0d0: 65 70 74 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 eption(n, GetLas
b0e0: 74 45 72 72 6f 72 28 29 29 3b 0d 0a 20 20 20 20 tError());..
b0f0: 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 }.... interna
b100: 6c 20 6f 76 65 72 72 69 64 65 20 76 6f 69 64 20 l override void
b110: 43 68 61 6e 67 65 50 61 73 73 77 6f 72 64 28 62 ChangePassword(b
b120: 79 74 65 5b 5d 20 6e 65 77 50 61 73 73 77 6f 72 yte[] newPasswor
b130: 64 42 79 74 65 73 29 0d 0a 20 20 20 20 7b 0d 0a dBytes).. {..
b140: 20 20 20 20 20 20 69 6e 74 20 6e 20 3d 20 55 6e int n = Un
b150: 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 safeNativeMethod
b160: 73 2e 73 71 6c 69 74 65 33 5f 72 65 6b 65 79 28 s.sqlite3_rekey(
b170: 5f 73 71 6c 2c 20 6e 65 77 50 61 73 73 77 6f 72 _sql, newPasswor
b180: 64 42 79 74 65 73 2c 20 28 6e 65 77 50 61 73 73 dBytes, (newPass
b190: 77 6f 72 64 42 79 74 65 73 20 3d 3d 20 6e 75 6c wordBytes == nul
b1a0: 6c 29 20 3f 20 30 20 3a 20 6e 65 77 50 61 73 73 l) ? 0 : newPass
b1b0: 77 6f 72 64 42 79 74 65 73 2e 4c 65 6e 67 74 68 wordBytes.Length
b1c0: 29 3b 0d 0a 20 20 20 20 20 20 69 66 20 28 6e 20 );.. if (n
b1d0: 3e 20 30 29 20 74 68 72 6f 77 20 6e 65 77 20 53 > 0) throw new S
b1e0: 51 4c 69 74 65 45 78 63 65 70 74 69 6f 6e 28 6e QLiteException(n
b1f0: 2c 20 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 , GetLastError()
b200: 29 3b 0d 0a 20 20 20 20 7d 0d 0a 23 65 6e 64 69 );.. }..#endi
b210: 66 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 f.... interna
b220: 6c 20 6f 76 65 72 72 69 64 65 20 76 6f 69 64 20 l override void
b230: 53 65 74 55 70 64 61 74 65 48 6f 6f 6b 28 53 51 SetUpdateHook(SQ
b240: 4c 69 74 65 55 70 64 61 74 65 43 61 6c 6c 62 61 LiteUpdateCallba
b250: 63 6b 20 66 75 6e 63 29 0d 0a 20 20 20 20 7b 0d ck func).. {.
b260: 0a 20 20 20 20 20 20 55 6e 73 61 66 65 4e 61 74 . UnsafeNat
b270: 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 iveMethods.sqlit
b280: 65 33 5f 75 70 64 61 74 65 5f 68 6f 6f 6b 28 5f e3_update_hook(_
b290: 73 71 6c 2c 20 66 75 6e 63 2c 20 49 6e 74 50 74 sql, func, IntPt
b2a0: 72 2e 5a 65 72 6f 29 3b 0d 0a 20 20 20 20 7d 0d r.Zero);.. }.
b2b0: 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 ... internal
b2c0: 6f 76 65 72 72 69 64 65 20 76 6f 69 64 20 53 65 override void Se
b2d0: 74 43 6f 6d 6d 69 74 48 6f 6f 6b 28 53 51 4c 69 tCommitHook(SQLi
b2e0: 74 65 43 6f 6d 6d 69 74 43 61 6c 6c 62 61 63 6b teCommitCallback
b2f0: 20 66 75 6e 63 29 0d 0a 20 20 20 20 7b 0d 0a 20 func).. {..
b300: 20 20 20 20 20 55 6e 73 61 66 65 4e 61 74 69 76 UnsafeNativ
b310: 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
b320: 5f 63 6f 6d 6d 69 74 5f 68 6f 6f 6b 28 5f 73 71 _commit_hook(_sq
b330: 6c 2c 20 66 75 6e 63 2c 20 49 6e 74 50 74 72 2e l, func, IntPtr.
b340: 5a 65 72 6f 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d Zero);.. }...
b350: 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 . internal ov
b360: 65 72 72 69 64 65 20 76 6f 69 64 20 53 65 74 54 erride void SetT
b370: 72 61 63 65 43 61 6c 6c 62 61 63 6b 28 53 51 4c raceCallback(SQL
b380: 69 74 65 54 72 61 63 65 43 61 6c 6c 62 61 63 6b iteTraceCallback
b390: 20 66 75 6e 63 29 0d 0a 20 20 20 20 7b 0d 0a 20 func).. {..
b3a0: 20 20 20 20 20 55 6e 73 61 66 65 4e 61 74 69 76 UnsafeNativ
b3b0: 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
b3c0: 5f 74 72 61 63 65 28 5f 73 71 6c 2c 20 66 75 6e _trace(_sql, fun
b3d0: 63 2c 20 49 6e 74 50 74 72 2e 5a 65 72 6f 29 3b c, IntPtr.Zero);
b3e0: 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 .. }.... i
b3f0: 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 nternal override
b400: 20 76 6f 69 64 20 53 65 74 52 6f 6c 6c 62 61 63 void SetRollbac
b410: 6b 48 6f 6f 6b 28 53 51 4c 69 74 65 52 6f 6c 6c kHook(SQLiteRoll
b420: 62 61 63 6b 43 61 6c 6c 62 61 63 6b 20 66 75 6e backCallback fun
b430: 63 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 c).. {..
b440: 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 UnsafeNativeMet
b450: 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 72 6f 6c hods.sqlite3_rol
b460: 6c 62 61 63 6b 5f 68 6f 6f 6b 28 5f 73 71 6c 2c lback_hook(_sql,
b470: 20 66 75 6e 63 2c 20 49 6e 74 50 74 72 2e 5a 65 func, IntPtr.Ze
b480: 72 6f 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 ro);.. }....
b490: 20 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 72 79 3e /// <summary>
b4a0: 0d 0a 20 20 20 20 2f 2f 2f 20 41 6c 6c 6f 77 73 .. /// Allows
b4b0: 20 74 68 65 20 73 65 74 74 69 6e 67 20 6f 66 20 the setting of
b4c0: 61 20 6c 6f 67 67 69 6e 67 20 63 61 6c 6c 62 61 a logging callba
b4d0: 63 6b 20 69 6e 76 6f 6b 65 64 20 62 79 20 53 51 ck invoked by SQ
b4e0: 4c 69 74 65 20 77 68 65 6e 20 61 0d 0a 20 20 20 Lite when a..
b4f0: 20 2f 2f 2f 20 6c 6f 67 20 65 76 65 6e 74 20 6f /// log event o
b500: 63 63 75 72 73 2e 20 20 4f 6e 6c 79 20 6f 6e 65 ccurs. Only one
b510: 20 63 61 6c 6c 62 61 63 6b 20 6d 61 79 20 62 65 callback may be
b520: 20 73 65 74 2e 20 20 49 66 20 4e 55 4c 4c 20 69 set. If NULL i
b530: 73 20 70 61 73 73 65 64 2c 0d 0a 20 20 20 20 2f s passed,.. /
b540: 2f 2f 20 74 68 65 20 6c 6f 67 67 69 6e 67 20 63 // the logging c
b550: 61 6c 6c 62 61 63 6b 20 69 73 20 75 6e 72 65 67 allback is unreg
b560: 69 73 74 65 72 65 64 2e 0d 0a 20 20 20 20 2f 2f istered... //
b570: 2f 20 3c 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 / </summary>..
b580: 20 20 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 6d /// <param nam
b590: 65 3d 22 66 75 6e 63 22 3e 54 68 65 20 63 61 6c e="func">The cal
b5a0: 6c 62 61 63 6b 20 66 75 6e 63 74 69 6f 6e 20 74 lback function t
b5b0: 6f 20 69 6e 76 6f 6b 65 2e 3c 2f 70 61 72 61 6d o invoke.</param
b5c0: 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 72 65 74 75 >.. /// <retu
b5d0: 72 6e 73 3e 52 65 74 75 72 6e 73 20 61 20 72 65 rns>Returns a re
b5e0: 73 75 6c 74 20 63 6f 64 65 3c 2f 72 65 74 75 72 sult code</retur
b5f0: 6e 73 3e 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 ns>.. interna
b600: 6c 20 6f 76 65 72 72 69 64 65 20 69 6e 74 20 53 l override int S
b610: 65 74 4c 6f 67 43 61 6c 6c 62 61 63 6b 28 53 51 etLogCallback(SQ
b620: 4c 69 74 65 4c 6f 67 43 61 6c 6c 62 61 63 6b 20 LiteLogCallback
b630: 66 75 6e 63 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 func).. {..
b640: 20 20 20 20 20 20 69 6e 74 20 72 63 20 3d 20 55 int rc = U
b650: 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
b660: 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f 6e 66 69 ds.sqlite3_confi
b670: 67 28 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 g(..
b680: 28 69 6e 74 29 53 51 4c 69 74 65 43 6f 6e 66 69 (int)SQLiteConfi
b690: 67 4f 70 73 45 6e 75 6d 2e 53 51 4c 49 54 45 5f gOpsEnum.SQLITE_
b6a0: 43 4f 4e 46 49 47 5f 4c 4f 47 2c 20 66 75 6e 63 CONFIG_LOG, func
b6b0: 2c 20 28 49 6e 74 50 74 72 29 30 29 3b 0d 0a 0d , (IntPtr)0);...
b6c0: 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 . return
b6d0: 72 63 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 rc;.. }....
b6e0: 20 20 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f //////////////
b6f0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
b700: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
b710: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
b720: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
b730: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
b740: 2f 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 /.... /// <su
b750: 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 mmary>.. ///
b760: 43 72 65 61 74 65 73 20 61 20 6e 65 77 20 53 51 Creates a new SQ
b770: 4c 69 74 65 20 62 61 63 6b 75 70 20 6f 62 6a 65 Lite backup obje
b780: 63 74 20 62 61 73 65 64 20 6f 6e 20 74 68 65 20 ct based on the
b790: 70 72 6f 76 69 64 65 64 20 64 65 73 74 69 6e 61 provided destina
b7a0: 74 69 6f 6e 0d 0a 20 20 20 20 2f 2f 2f 20 64 61 tion.. /// da
b7b0: 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f tabase connectio
b7c0: 6e 2e 20 20 54 68 65 20 73 6f 75 72 63 65 20 64 n. The source d
b7d0: 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 atabase connecti
b7e0: 6f 6e 20 69 73 20 74 68 65 20 6f 6e 65 0d 0a 20 on is the one..
b7f0: 20 20 20 2f 2f 2f 20 61 73 73 6f 63 69 61 74 65 /// associate
b800: 64 20 77 69 74 68 20 74 68 69 73 20 6f 62 6a 65 d with this obje
b810: 63 74 2e 20 20 54 68 65 20 73 6f 75 72 63 65 20 ct. The source
b820: 61 6e 64 20 64 65 73 74 69 6e 61 74 69 6f 6e 20 and destination
b830: 64 61 74 61 62 61 73 65 0d 0a 20 20 20 20 2f 2f database.. //
b840: 2f 20 63 6f 6e 6e 65 63 74 69 6f 6e 73 20 63 61 / connections ca
b850: 6e 6e 6f 74 20 62 65 20 74 68 65 20 73 61 6d 65 nnot be the same
b860: 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 73 75 6d ... /// </sum
b870: 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c mary>.. /// <
b880: 70 61 72 61 6d 20 6e 61 6d 65 3d 22 64 65 73 74 param name="dest
b890: 43 6e 6e 22 3e 54 68 65 20 64 65 73 74 69 6e 61 Cnn">The destina
b8a0: 74 69 6f 6e 20 64 61 74 61 62 61 73 65 20 63 6f tion database co
b8b0: 6e 6e 65 63 74 69 6f 6e 2e 3c 2f 70 61 72 61 6d nnection.</param
b8c0: 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 72 61 >.. /// <para
b8d0: 6d 20 6e 61 6d 65 3d 22 64 65 73 74 4e 61 6d 65 m name="destName
b8e0: 22 3e 54 68 65 20 64 65 73 74 69 6e 61 74 69 6f ">The destinatio
b8f0: 6e 20 64 61 74 61 62 61 73 65 20 6e 61 6d 65 2e n database name.
b900: 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f </param>.. //
b910: 2f 20 3c 70 61 72 61 6d 20 6e 61 6d 65 3d 22 73 / <param name="s
b920: 6f 75 72 63 65 4e 61 6d 65 22 3e 54 68 65 20 73 ourceName">The s
b930: 6f 75 72 63 65 20 64 61 74 61 62 61 73 65 20 6e ource database n
b940: 61 6d 65 2e 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 ame.</param>..
b950: 20 20 2f 2f 2f 20 3c 72 65 74 75 72 6e 73 3e 54 /// <returns>T
b960: 68 65 20 6e 65 77 6c 79 20 63 72 65 61 74 65 64 he newly created
b970: 20 62 61 63 6b 75 70 20 6f 62 6a 65 63 74 2e 3c backup object.<
b980: 2f 72 65 74 75 72 6e 73 3e 0d 0a 20 20 20 20 69 /returns>.. i
b990: 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 nternal override
b9a0: 20 53 51 4c 69 74 65 42 61 63 6b 75 70 20 49 6e SQLiteBackup In
b9b0: 69 74 69 61 6c 69 7a 65 42 61 63 6b 75 70 28 0d itializeBackup(.
b9c0: 0a 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 43 . SQLiteC
b9d0: 6f 6e 6e 65 63 74 69 6f 6e 20 64 65 73 74 43 6e onnection destCn
b9e0: 6e 2c 0d 0a 20 20 20 20 20 20 20 20 73 74 72 69 n,.. stri
b9f0: 6e 67 20 64 65 73 74 4e 61 6d 65 2c 0d 0a 20 20 ng destName,..
ba00: 20 20 20 20 20 20 73 74 72 69 6e 67 20 73 6f 75 string sou
ba10: 72 63 65 4e 61 6d 65 0d 0a 20 20 20 20 20 20 20 rceName..
ba20: 20 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 ).. {..
ba30: 20 20 20 69 66 20 28 64 65 73 74 43 6e 6e 20 3d if (destCnn =
ba40: 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 = null)..
ba50: 20 20 20 20 20 74 68 72 6f 77 20 6e 65 77 20 41 throw new A
ba60: 72 67 75 6d 65 6e 74 4e 75 6c 6c 45 78 63 65 70 rgumentNullExcep
ba70: 74 69 6f 6e 28 22 64 65 73 74 43 6e 6e 22 29 3b tion("destCnn");
ba80: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 .... if (
ba90: 64 65 73 74 4e 61 6d 65 20 3d 3d 20 6e 75 6c 6c destName == null
baa0: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 74 ).. t
bab0: 68 72 6f 77 20 6e 65 77 20 41 72 67 75 6d 65 6e hrow new Argumen
bac0: 74 4e 75 6c 6c 45 78 63 65 70 74 69 6f 6e 28 22 tNullException("
bad0: 64 65 73 74 4e 61 6d 65 22 29 3b 0d 0a 0d 0a 20 destName");....
bae0: 20 20 20 20 20 20 20 69 66 20 28 73 6f 75 72 63 if (sourc
baf0: 65 4e 61 6d 65 20 3d 3d 20 6e 75 6c 6c 29 0d 0a eName == null)..
bb00: 20 20 20 20 20 20 20 20 20 20 20 20 74 68 72 6f thro
bb10: 77 20 6e 65 77 20 41 72 67 75 6d 65 6e 74 4e 75 w new ArgumentNu
bb20: 6c 6c 45 78 63 65 70 74 69 6f 6e 28 22 73 6f 75 llException("sou
bb30: 72 63 65 4e 61 6d 65 22 29 3b 0d 0a 0d 0a 20 20 rceName");....
bb40: 20 20 20 20 20 20 53 51 4c 69 74 65 33 20 64 65 SQLite3 de
bb50: 73 74 53 71 6c 69 74 65 33 20 3d 20 64 65 73 74 stSqlite3 = dest
bb60: 43 6e 6e 2e 5f 73 71 6c 20 61 73 20 53 51 4c 69 Cnn._sql as SQLi
bb70: 74 65 33 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 te3;....
bb80: 69 66 20 28 64 65 73 74 53 71 6c 69 74 65 33 20 if (destSqlite3
bb90: 3d 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 == null)..
bba0: 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 77 20 throw new
bbb0: 41 72 67 75 6d 65 6e 74 45 78 63 65 70 74 69 6f ArgumentExceptio
bbc0: 6e 28 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 n(..
bbd0: 20 20 20 20 22 44 65 73 74 69 6e 61 74 69 6f 6e "Destination
bbe0: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 68 61 73 20 connection has
bbf0: 6e 6f 20 77 72 61 70 70 65 72 2e 22 2c 0d 0a 20 no wrapper.",..
bc00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 "
bc10: 64 65 73 74 43 6e 6e 22 29 3b 0d 0a 0d 0a 20 20 destCnn");....
bc20: 20 20 20 20 20 20 53 51 4c 69 74 65 43 6f 6e 6e SQLiteConn
bc30: 65 63 74 69 6f 6e 48 61 6e 64 6c 65 20 64 65 73 ectionHandle des
bc40: 74 48 61 6e 64 6c 65 20 3d 20 64 65 73 74 53 71 tHandle = destSq
bc50: 6c 69 74 65 33 2e 5f 73 71 6c 3b 0d 0a 0d 0a 20 lite3._sql;....
bc60: 20 20 20 20 20 20 20 69 66 20 28 64 65 73 74 48 if (destH
bc70: 61 6e 64 6c 65 20 3d 3d 20 6e 75 6c 6c 29 0d 0a andle == null)..
bc80: 20 20 20 20 20 20 20 20 20 20 20 20 74 68 72 6f thro
bc90: 77 20 6e 65 77 20 41 72 67 75 6d 65 6e 74 45 78 w new ArgumentEx
bca0: 63 65 70 74 69 6f 6e 28 0d 0a 20 20 20 20 20 20 ception(..
bcb0: 20 20 20 20 20 20 20 20 20 20 22 44 65 73 74 69 "Desti
bcc0: 6e 61 74 69 6f 6e 20 63 6f 6e 6e 65 63 74 69 6f nation connectio
bcd0: 6e 20 68 61 73 20 61 6e 20 69 6e 76 61 6c 69 64 n has an invalid
bce0: 20 68 61 6e 64 6c 65 2e 22 2c 0d 0a 20 20 20 20 handle.",..
bcf0: 20 20 20 20 20 20 20 20 20 20 20 20 22 64 65 73 "des
bd00: 74 43 6e 6e 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 tCnn");....
bd10: 20 20 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 SQLiteConnect
bd20: 69 6f 6e 48 61 6e 64 6c 65 20 73 6f 75 72 63 65 ionHandle source
bd30: 48 61 6e 64 6c 65 20 3d 20 5f 73 71 6c 3b 0d 0a Handle = _sql;..
bd40: 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 73 6f .. if (so
bd50: 75 72 63 65 48 61 6e 64 6c 65 20 3d 3d 20 6e 75 urceHandle == nu
bd60: 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ll)..
bd70: 20 74 68 72 6f 77 20 6e 65 77 20 49 6e 76 61 6c throw new Inval
bd80: 69 64 4f 70 65 72 61 74 69 6f 6e 45 78 63 65 70 idOperationExcep
bd90: 74 69 6f 6e 28 0d 0a 20 20 20 20 20 20 20 20 20 tion(..
bda0: 20 20 20 20 20 20 20 22 53 6f 75 72 63 65 20 63 "Source c
bdb0: 6f 6e 6e 65 63 74 69 6f 6e 20 68 61 73 20 61 6e onnection has an
bdc0: 20 69 6e 76 61 6c 69 64 20 68 61 6e 64 6c 65 2e invalid handle.
bdd0: 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 62 ");.... b
bde0: 79 74 65 5b 5d 20 7a 44 65 73 74 4e 61 6d 65 20 yte[] zDestName
bdf0: 3d 20 54 6f 55 54 46 38 28 64 65 73 74 4e 61 6d = ToUTF8(destNam
be00: 65 29 3b 0d 0a 20 20 20 20 20 20 20 20 62 79 74 e);.. byt
be10: 65 5b 5d 20 7a 53 6f 75 72 63 65 4e 61 6d 65 20 e[] zSourceName
be20: 3d 20 54 6f 55 54 46 38 28 73 6f 75 72 63 65 4e = ToUTF8(sourceN
be30: 61 6d 65 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 ame);....
be40: 20 49 6e 74 50 74 72 20 62 61 63 6b 75 70 20 3d IntPtr backup =
be50: 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 UnsafeNativeMet
be60: 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 62 61 63 hods.sqlite3_bac
be70: 6b 75 70 5f 69 6e 69 74 28 0d 0a 20 20 20 20 20 kup_init(..
be80: 20 20 20 20 20 20 20 64 65 73 74 48 61 6e 64 6c destHandl
be90: 65 2c 20 7a 44 65 73 74 4e 61 6d 65 2c 20 73 6f e, zDestName, so
bea0: 75 72 63 65 48 61 6e 64 6c 65 2c 20 7a 53 6f 75 urceHandle, zSou
beb0: 72 63 65 4e 61 6d 65 29 3b 0d 0a 0d 0a 20 20 20 rceName);....
bec0: 20 20 20 20 20 69 66 20 28 62 61 63 6b 75 70 20 if (backup
bed0: 3d 3d 20 49 6e 74 50 74 72 2e 5a 65 72 6f 29 0d == IntPtr.Zero).
bee0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 74 68 72 . thr
bef0: 6f 77 20 6e 65 77 20 53 51 4c 69 74 65 45 78 63 ow new SQLiteExc
bf00: 65 70 74 69 6f 6e 28 52 65 73 75 6c 74 43 6f 64 eption(ResultCod
bf10: 65 28 29 2c 20 47 65 74 4c 61 73 74 45 72 72 6f e(), GetLastErro
bf20: 72 28 29 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 r());....
bf30: 20 72 65 74 75 72 6e 20 6e 65 77 20 53 51 4c 69 return new SQLi
bf40: 74 65 42 61 63 6b 75 70 28 0d 0a 20 20 20 20 20 teBackup(..
bf50: 20 20 20 20 20 20 20 74 68 69 73 2c 20 6e 65 77 this, new
bf60: 20 53 51 4c 69 74 65 42 61 63 6b 75 70 48 61 6e SQLiteBackupHan
bf70: 64 6c 65 28 62 61 63 6b 75 70 29 2c 20 64 65 73 dle(backup), des
bf80: 74 48 61 6e 64 6c 65 2c 20 7a 44 65 73 74 4e 61 tHandle, zDestNa
bf90: 6d 65 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 20 me,..
bfa0: 20 73 6f 75 72 63 65 48 61 6e 64 6c 65 2c 20 7a sourceHandle, z
bfb0: 53 6f 75 72 63 65 4e 61 6d 65 29 3b 0d 0a 20 20 SourceName);..
bfc0: 20 20 7d 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 20 3c }.... /// <
bfd0: 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f summary>.. //
bfe0: 2f 20 43 6f 70 69 65 73 20 75 70 20 74 6f 20 4e / Copies up to N
bff0: 20 70 61 67 65 73 20 66 72 6f 6d 20 74 68 65 20 pages from the
c000: 73 6f 75 72 63 65 20 64 61 74 61 62 61 73 65 20 source database
c010: 74 6f 20 74 68 65 20 64 65 73 74 69 6e 61 74 69 to the destinati
c020: 6f 6e 0d 0a 20 20 20 20 2f 2f 2f 20 64 61 74 61 on.. /// data
c030: 62 61 73 65 20 61 73 73 6f 63 69 61 74 65 64 20 base associated
c040: 77 69 74 68 20 74 68 65 20 73 70 65 63 69 66 69 with the specifi
c050: 65 64 20 62 61 63 6b 75 70 20 6f 62 6a 65 63 74 ed backup object
c060: 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 73 75 6d ... /// </sum
c070: 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c mary>.. /// <
c080: 70 61 72 61 6d 20 6e 61 6d 65 3d 22 62 61 63 6b param name="back
c090: 75 70 22 3e 54 68 65 20 62 61 63 6b 75 70 20 6f up">The backup o
c0a0: 62 6a 65 63 74 20 74 6f 20 75 73 65 2e 3c 2f 70 bject to use.</p
c0b0: 61 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c aram>.. /// <
c0c0: 70 61 72 61 6d 20 6e 61 6d 65 3d 22 6e 50 61 67 param name="nPag
c0d0: 65 22 3e 0d 0a 20 20 20 20 2f 2f 2f 20 54 68 65 e">.. /// The
c0e0: 20 6e 75 6d 62 65 72 20 6f 66 20 70 61 67 65 73 number of pages
c0f0: 20 74 6f 20 63 6f 70 79 2c 20 6e 65 67 61 74 69 to copy, negati
c100: 76 65 20 74 6f 20 63 6f 70 79 20 61 6c 6c 20 72 ve to copy all r
c110: 65 6d 61 69 6e 69 6e 67 20 70 61 67 65 73 2e 0d emaining pages..
c120: 0a 20 20 20 20 2f 2f 2f 20 3c 2f 70 61 72 61 6d . /// </param
c130: 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 72 61 >.. /// <para
c140: 6d 20 6e 61 6d 65 3d 22 72 65 74 72 79 22 3e 0d m name="retry">.
c150: 0a 20 20 20 20 2f 2f 2f 20 53 65 74 20 74 6f 20 . /// Set to
c160: 74 72 75 65 20 69 66 20 74 68 65 20 6f 70 65 72 true if the oper
c170: 61 74 69 6f 6e 20 6e 65 65 64 73 20 74 6f 20 62 ation needs to b
c180: 65 20 72 65 74 72 69 65 64 20 64 75 65 20 74 6f e retried due to
c190: 20 64 61 74 61 62 61 73 65 0d 0a 20 20 20 20 2f database.. /
c1a0: 2f 2f 20 6c 6f 63 6b 69 6e 67 20 69 73 73 75 65 // locking issue
c1b0: 73 3b 20 6f 74 68 65 72 77 69 73 65 2c 20 73 65 s; otherwise, se
c1c0: 74 20 74 6f 20 66 61 6c 73 65 2e 0d 0a 20 20 20 t to false...
c1d0: 20 2f 2f 2f 20 3c 2f 70 61 72 61 6d 3e 0d 0a 20 /// </param>..
c1e0: 20 20 20 2f 2f 2f 20 3c 72 65 74 75 72 6e 73 3e /// <returns>
c1f0: 0d 0a 20 20 20 20 2f 2f 2f 20 54 72 75 65 20 69 .. /// True i
c200: 66 20 74 68 65 72 65 20 61 72 65 20 6d 6f 72 65 f there are more
c210: 20 70 61 67 65 73 20 74 6f 20 62 65 20 63 6f 70 pages to be cop
c220: 69 65 64 2c 20 66 61 6c 73 65 20 6f 74 68 65 72 ied, false other
c230: 77 69 73 65 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c wise... /// <
c240: 2f 72 65 74 75 72 6e 73 3e 0d 0a 20 20 20 20 69 /returns>.. i
c250: 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 nternal override
c260: 20 62 6f 6f 6c 20 53 74 65 70 42 61 63 6b 75 70 bool StepBackup
c270: 28 0d 0a 20 20 20 20 20 20 20 20 53 51 4c 69 74 (.. SQLit
c280: 65 42 61 63 6b 75 70 20 62 61 63 6b 75 70 2c 0d eBackup backup,.
c290: 0a 20 20 20 20 20 20 20 20 69 6e 74 20 6e 50 61 . int nPa
c2a0: 67 65 2c 0d 0a 20 20 20 20 20 20 20 20 6f 75 74 ge,.. out
c2b0: 20 62 6f 6f 6c 20 72 65 74 72 79 0d 0a 20 20 20 bool retry..
c2c0: 20 20 20 20 20 29 0d 0a 20 20 20 20 7b 0d 0a 20 ).. {..
c2d0: 20 20 20 20 20 20 20 72 65 74 72 79 20 3d 20 66 retry = f
c2e0: 61 6c 73 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 alse;....
c2f0: 20 69 66 20 28 62 61 63 6b 75 70 20 3d 3d 20 6e if (backup == n
c300: 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 20 ull)..
c310: 20 20 74 68 72 6f 77 20 6e 65 77 20 41 72 67 75 throw new Argu
c320: 6d 65 6e 74 4e 75 6c 6c 45 78 63 65 70 74 69 6f mentNullExceptio
c330: 6e 28 22 62 61 63 6b 75 70 22 29 3b 0d 0a 0d 0a n("backup");....
c340: 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 42 61 SQLiteBa
c350: 63 6b 75 70 48 61 6e 64 6c 65 20 68 61 6e 64 6c ckupHandle handl
c360: 65 20 3d 20 62 61 63 6b 75 70 2e 5f 73 71 6c 69 e = backup._sqli
c370: 74 65 5f 62 61 63 6b 75 70 3b 0d 0a 0d 0a 20 20 te_backup;....
c380: 20 20 20 20 20 20 69 66 20 28 68 61 6e 64 6c 65 if (handle
c390: 20 3d 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 == null)..
c3a0: 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 77 throw new
c3b0: 20 49 6e 76 61 6c 69 64 4f 70 65 72 61 74 69 6f InvalidOperatio
c3c0: 6e 45 78 63 65 70 74 69 6f 6e 28 0d 0a 20 20 20 nException(..
c3d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 22 42 61 "Ba
c3e0: 63 6b 75 70 20 6f 62 6a 65 63 74 20 68 61 73 20 ckup object has
c3f0: 61 6e 20 69 6e 76 61 6c 69 64 20 68 61 6e 64 6c an invalid handl
c400: 65 2e 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 e.");....
c410: 20 69 6e 74 20 6e 20 3d 20 55 6e 73 61 66 65 4e int n = UnsafeN
c420: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
c430: 69 74 65 33 5f 62 61 63 6b 75 70 5f 73 74 65 70 ite3_backup_step
c440: 28 68 61 6e 64 6c 65 2c 20 6e 50 61 67 65 29 3b (handle, nPage);
c450: 0d 0a 20 20 20 20 20 20 20 20 62 61 63 6b 75 70 .. backup
c460: 2e 5f 73 74 65 70 52 65 73 75 6c 74 20 3d 20 6e ._stepResult = n
c470: 3b 20 2f 2a 20 4e 4f 54 45 3a 20 53 61 76 65 20 ; /* NOTE: Save
c480: 66 6f 72 20 75 73 65 20 62 79 20 46 69 6e 69 73 for use by Finis
c490: 68 42 61 63 6b 75 70 2e 20 2a 2f 0d 0a 0d 0a 20 hBackup. */....
c4a0: 20 20 20 20 20 20 20 69 66 20 28 6e 20 3d 3d 20 if (n ==
c4b0: 28 69 6e 74 29 53 51 4c 69 74 65 45 72 72 6f 72 (int)SQLiteError
c4c0: 43 6f 64 65 2e 4f 6b 29 0d 0a 20 20 20 20 20 20 Code.Ok)..
c4d0: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 {..
c4e0: 20 72 65 74 75 72 6e 20 74 72 75 65 3b 0d 0a 20 return true;..
c4f0: 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 }..
c500: 20 20 65 6c 73 65 20 69 66 20 28 6e 20 3d 3d 20 else if (n ==
c510: 28 69 6e 74 29 53 51 4c 69 74 65 45 72 72 6f 72 (int)SQLiteError
c520: 43 6f 64 65 2e 42 75 73 79 29 0d 0a 20 20 20 20 Code.Busy)..
c530: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 {..
c540: 20 20 20 72 65 74 72 79 20 3d 20 74 72 75 65 3b retry = true;
c550: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 72 65 .. re
c560: 74 75 72 6e 20 74 72 75 65 3b 0d 0a 20 20 20 20 turn true;..
c570: 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 65 }.. e
c580: 6c 73 65 20 69 66 20 28 6e 20 3d 3d 20 28 69 6e lse if (n == (in
c590: 74 29 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 t)SQLiteErrorCod
c5a0: 65 2e 4c 6f 63 6b 65 64 29 0d 0a 20 20 20 20 20 e.Locked)..
c5b0: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 {..
c5c0: 20 20 72 65 74 72 79 20 3d 20 74 72 75 65 3b 0d retry = true;.
c5d0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 . ret
c5e0: 75 72 6e 20 74 72 75 65 3b 0d 0a 20 20 20 20 20 urn true;..
c5f0: 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 65 6c }.. el
c600: 73 65 20 69 66 20 28 6e 20 3d 3d 20 28 69 6e 74 se if (n == (int
c610: 29 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 )SQLiteErrorCode
c620: 2e 44 6f 6e 65 29 0d 0a 20 20 20 20 20 20 20 20 .Done)..
c630: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 72 {.. r
c640: 65 74 75 72 6e 20 66 61 6c 73 65 3b 0d 0a 20 20 eturn false;..
c650: 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 }..
c660: 20 65 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 7b else.. {
c670: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 74 68 .. th
c680: 72 6f 77 20 6e 65 77 20 53 51 4c 69 74 65 45 78 row new SQLiteEx
c690: 63 65 70 74 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 ception(n, GetLa
c6a0: 73 74 45 72 72 6f 72 28 29 29 3b 0d 0a 20 20 20 stError());..
c6b0: 20 20 20 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a 0d }.. }...
c6c0: 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 72 . /// <summar
c6d0: 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 52 65 74 75 y>.. /// Retu
c6e0: 72 6e 73 20 74 68 65 20 6e 75 6d 62 65 72 20 6f rns the number o
c6f0: 66 20 70 61 67 65 73 20 72 65 6d 61 69 6e 69 6e f pages remainin
c700: 67 20 74 6f 20 62 65 20 63 6f 70 69 65 64 20 66 g to be copied f
c710: 72 6f 6d 20 74 68 65 20 73 6f 75 72 63 65 0d 0a rom the source..
c720: 20 20 20 20 2f 2f 2f 20 64 61 74 61 62 61 73 65 /// database
c730: 20 74 6f 20 74 68 65 20 64 65 73 74 69 6e 61 74 to the destinat
c740: 69 6f 6e 20 64 61 74 61 62 61 73 65 20 61 73 73 ion database ass
c750: 6f 63 69 61 74 65 64 20 77 69 74 68 20 74 68 65 ociated with the
c760: 20 73 70 65 63 69 66 69 65 64 0d 0a 20 20 20 20 specified..
c770: 2f 2f 2f 20 62 61 63 6b 75 70 20 6f 62 6a 65 63 /// backup objec
c780: 74 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 73 75 t... /// </su
c790: 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 mmary>.. ///
c7a0: 3c 70 61 72 61 6d 20 6e 61 6d 65 3d 22 62 61 63 <param name="bac
c7b0: 6b 75 70 22 3e 54 68 65 20 62 61 63 6b 75 70 20 kup">The backup
c7c0: 6f 62 6a 65 63 74 20 74 6f 20 63 68 65 63 6b 2e object to check.
c7d0: 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f </param>.. //
c7e0: 2f 20 3c 72 65 74 75 72 6e 73 3e 54 68 65 20 6e / <returns>The n
c7f0: 75 6d 62 65 72 20 6f 66 20 70 61 67 65 73 20 72 umber of pages r
c800: 65 6d 61 69 6e 69 6e 67 20 74 6f 20 62 65 20 63 emaining to be c
c810: 6f 70 69 65 64 2e 3c 2f 72 65 74 75 72 6e 73 3e opied.</returns>
c820: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
c830: 76 65 72 72 69 64 65 20 69 6e 74 20 52 65 6d 61 verride int Rema
c840: 69 6e 69 6e 67 42 61 63 6b 75 70 28 0d 0a 20 20 iningBackup(..
c850: 20 20 20 20 20 20 53 51 4c 69 74 65 42 61 63 6b SQLiteBack
c860: 75 70 20 62 61 63 6b 75 70 0d 0a 20 20 20 20 20 up backup..
c870: 20 20 20 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 ).. {..
c880: 20 20 20 20 20 69 66 20 28 62 61 63 6b 75 70 20 if (backup
c890: 3d 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 == null)..
c8a0: 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 77 20 throw new
c8b0: 41 72 67 75 6d 65 6e 74 4e 75 6c 6c 45 78 63 65 ArgumentNullExce
c8c0: 70 74 69 6f 6e 28 22 62 61 63 6b 75 70 22 29 3b ption("backup");
c8d0: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 53 51 4c 69 .... SQLi
c8e0: 74 65 42 61 63 6b 75 70 48 61 6e 64 6c 65 20 68 teBackupHandle h
c8f0: 61 6e 64 6c 65 20 3d 20 62 61 63 6b 75 70 2e 5f andle = backup._
c900: 73 71 6c 69 74 65 5f 62 61 63 6b 75 70 3b 0d 0a sqlite_backup;..
c910: 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 68 61 .. if (ha
c920: 6e 64 6c 65 20 3d 3d 20 6e 75 6c 6c 29 0d 0a 20 ndle == null)..
c930: 20 20 20 20 20 20 20 20 20 20 20 74 68 72 6f 77 throw
c940: 20 6e 65 77 20 49 6e 76 61 6c 69 64 4f 70 65 72 new InvalidOper
c950: 61 74 69 6f 6e 45 78 63 65 70 74 69 6f 6e 28 0d ationException(.
c960: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
c970: 20 22 42 61 63 6b 75 70 20 6f 62 6a 65 63 74 20 "Backup object
c980: 68 61 73 20 61 6e 20 69 6e 76 61 6c 69 64 20 68 has an invalid h
c990: 61 6e 64 6c 65 2e 22 29 3b 0d 0a 0d 0a 20 20 20 andle.");....
c9a0: 20 20 20 20 20 72 65 74 75 72 6e 20 55 6e 73 61 return Unsa
c9b0: 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
c9c0: 73 71 6c 69 74 65 33 5f 62 61 63 6b 75 70 5f 72 sqlite3_backup_r
c9d0: 65 6d 61 69 6e 69 6e 67 28 68 61 6e 64 6c 65 29 emaining(handle)
c9e0: 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 ;.. }....
c9f0: 2f 2f 2f 20 3c 73 75 6d 6d 61 72 79 3e 0d 0a 20 /// <summary>..
ca00: 20 20 20 2f 2f 2f 20 52 65 74 75 72 6e 73 20 74 /// Returns t
ca10: 68 65 20 74 6f 74 61 6c 20 6e 75 6d 62 65 72 20 he total number
ca20: 6f 66 20 70 61 67 65 73 20 69 6e 20 74 68 65 20 of pages in the
ca30: 73 6f 75 72 63 65 20 64 61 74 61 62 61 73 65 20 source database
ca40: 61 73 73 6f 63 69 61 74 65 64 0d 0a 20 20 20 20 associated..
ca50: 2f 2f 2f 20 77 69 74 68 20 74 68 65 20 73 70 65 /// with the spe
ca60: 63 69 66 69 65 64 20 62 61 63 6b 75 70 20 6f 62 cified backup ob
ca70: 6a 65 63 74 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c ject... /// <
ca80: 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f /summary>.. /
ca90: 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 6d 65 3d 22 // <param name="
caa0: 62 61 63 6b 75 70 22 3e 54 68 65 20 62 61 63 6b backup">The back
cab0: 75 70 20 6f 62 6a 65 63 74 20 74 6f 20 63 68 65 up object to che
cac0: 63 6b 2e 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 20 ck.</param>..
cad0: 20 2f 2f 2f 20 3c 72 65 74 75 72 6e 73 3e 54 68 /// <returns>Th
cae0: 65 20 74 6f 74 61 6c 20 6e 75 6d 62 65 72 20 6f e total number o
caf0: 66 20 70 61 67 65 73 20 69 6e 20 74 68 65 20 73 f pages in the s
cb00: 6f 75 72 63 65 20 64 61 74 61 62 61 73 65 2e 3c ource database.<
cb10: 2f 72 65 74 75 72 6e 73 3e 0d 0a 20 20 20 20 69 /returns>.. i
cb20: 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 nternal override
cb30: 20 69 6e 74 20 50 61 67 65 43 6f 75 6e 74 42 61 int PageCountBa
cb40: 63 6b 75 70 28 0d 0a 20 20 20 20 20 20 20 20 53 ckup(.. S
cb50: 51 4c 69 74 65 42 61 63 6b 75 70 20 62 61 63 6b QLiteBackup back
cb60: 75 70 0d 0a 20 20 20 20 20 20 20 20 29 0d 0a 20 up.. )..
cb70: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 69 66 {.. if
cb80: 20 28 62 61 63 6b 75 70 20 3d 3d 20 6e 75 6c 6c (backup == null
cb90: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 74 ).. t
cba0: 68 72 6f 77 20 6e 65 77 20 41 72 67 75 6d 65 6e hrow new Argumen
cbb0: 74 4e 75 6c 6c 45 78 63 65 70 74 69 6f 6e 28 22 tNullException("
cbc0: 62 61 63 6b 75 70 22 29 3b 0d 0a 0d 0a 20 20 20 backup");....
cbd0: 20 20 20 20 20 53 51 4c 69 74 65 42 61 63 6b 75 SQLiteBacku
cbe0: 70 48 61 6e 64 6c 65 20 68 61 6e 64 6c 65 20 3d pHandle handle =
cbf0: 20 62 61 63 6b 75 70 2e 5f 73 71 6c 69 74 65 5f backup._sqlite_
cc00: 62 61 63 6b 75 70 3b 0d 0a 0d 0a 20 20 20 20 20 backup;....
cc10: 20 20 20 69 66 20 28 68 61 6e 64 6c 65 20 3d 3d if (handle ==
cc20: 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 null)..
cc30: 20 20 20 20 74 68 72 6f 77 20 6e 65 77 20 49 6e throw new In
cc40: 76 61 6c 69 64 4f 70 65 72 61 74 69 6f 6e 45 78 validOperationEx
cc50: 63 65 70 74 69 6f 6e 28 0d 0a 20 20 20 20 20 20 ception(..
cc60: 20 20 20 20 20 20 20 20 20 20 22 42 61 63 6b 75 "Backu
cc70: 70 20 6f 62 6a 65 63 74 20 68 61 73 20 61 6e 20 p object has an
cc80: 69 6e 76 61 6c 69 64 20 68 61 6e 64 6c 65 2e 22 invalid handle."
cc90: 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 72 65 );.... re
cca0: 74 75 72 6e 20 55 6e 73 61 66 65 4e 61 74 69 76 turn UnsafeNativ
ccb0: 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
ccc0: 5f 62 61 63 6b 75 70 5f 70 61 67 65 63 6f 75 6e _backup_pagecoun
ccd0: 74 28 68 61 6e 64 6c 65 29 3b 0d 0a 20 20 20 20 t(handle);..
cce0: 7d 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 }.... /// <su
ccf0: 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 mmary>.. ///
cd00: 44 65 73 74 72 6f 79 73 20 74 68 65 20 62 61 63 Destroys the bac
cd10: 6b 75 70 20 6f 62 6a 65 63 74 2c 20 72 6f 6c 6c kup object, roll
cd20: 69 6e 67 20 62 61 63 6b 20 61 6e 79 20 62 61 63 ing back any bac
cd30: 6b 75 70 20 74 68 61 74 20 6d 61 79 20 62 65 20 kup that may be
cd40: 69 6e 0d 0a 20 20 20 20 2f 2f 2f 20 70 72 6f 67 in.. /// prog
cd50: 65 73 73 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f ess... /// </
cd60: 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f summary>.. //
cd70: 2f 20 3c 70 61 72 61 6d 20 6e 61 6d 65 3d 22 62 / <param name="b
cd80: 61 63 6b 75 70 22 3e 54 68 65 20 62 61 63 6b 75 ackup">The backu
cd90: 70 20 6f 62 6a 65 63 74 20 74 6f 20 64 65 73 74 p object to dest
cda0: 72 6f 79 2e 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 roy.</param>..
cdb0: 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
cdc0: 69 64 65 20 76 6f 69 64 20 46 69 6e 69 73 68 42 ide void FinishB
cdd0: 61 63 6b 75 70 28 0d 0a 20 20 20 20 20 20 20 20 ackup(..
cde0: 53 51 4c 69 74 65 42 61 63 6b 75 70 20 62 61 63 SQLiteBackup bac
cdf0: 6b 75 70 0d 0a 20 20 20 20 20 20 20 20 29 0d 0a kup.. )..
ce00: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 69 {.. i
ce10: 66 20 28 62 61 63 6b 75 70 20 3d 3d 20 6e 75 6c f (backup == nul
ce20: 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 l)..
ce30: 74 68 72 6f 77 20 6e 65 77 20 41 72 67 75 6d 65 throw new Argume
ce40: 6e 74 4e 75 6c 6c 45 78 63 65 70 74 69 6f 6e 28 ntNullException(
ce50: 22 62 61 63 6b 75 70 22 29 3b 0d 0a 0d 0a 20 20 "backup");....
ce60: 20 20 20 20 20 20 53 51 4c 69 74 65 42 61 63 6b SQLiteBack
ce70: 75 70 48 61 6e 64 6c 65 20 68 61 6e 64 6c 65 20 upHandle handle
ce80: 3d 20 62 61 63 6b 75 70 2e 5f 73 71 6c 69 74 65 = backup._sqlite
ce90: 5f 62 61 63 6b 75 70 3b 0d 0a 0d 0a 20 20 20 20 _backup;....
cea0: 20 20 20 20 69 66 20 28 68 61 6e 64 6c 65 20 3d if (handle =
ceb0: 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 = null)..
cec0: 20 20 20 20 20 74 68 72 6f 77 20 6e 65 77 20 49 throw new I
ced0: 6e 76 61 6c 69 64 4f 70 65 72 61 74 69 6f 6e 45 nvalidOperationE
cee0: 78 63 65 70 74 69 6f 6e 28 0d 0a 20 20 20 20 20 xception(..
cef0: 20 20 20 20 20 20 20 20 20 20 20 22 42 61 63 6b "Back
cf00: 75 70 20 6f 62 6a 65 63 74 20 68 61 73 20 61 6e up object has an
cf10: 20 69 6e 76 61 6c 69 64 20 68 61 6e 64 6c 65 2e invalid handle.
cf20: 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 ");.... i
cf30: 6e 74 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 nt n = UnsafeNat
cf40: 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 iveMethods.sqlit
cf50: 65 33 5f 62 61 63 6b 75 70 5f 66 69 6e 69 73 68 e3_backup_finish
cf60: 28 68 61 6e 64 6c 65 29 3b 0d 0a 20 20 20 20 20 (handle);..
cf70: 20 20 20 68 61 6e 64 6c 65 2e 53 65 74 48 61 6e handle.SetHan
cf80: 64 6c 65 41 73 49 6e 76 61 6c 69 64 28 29 3b 0d dleAsInvalid();.
cf90: 0a 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 28 ... if ((
cfa0: 6e 20 3e 20 30 29 20 26 26 20 28 6e 20 21 3d 20 n > 0) && (n !=
cfb0: 62 61 63 6b 75 70 2e 5f 73 74 65 70 52 65 73 75 backup._stepResu
cfc0: 6c 74 29 29 0d 0a 20 20 20 20 20 20 20 20 20 20 lt))..
cfd0: 20 20 74 68 72 6f 77 20 6e 65 77 20 53 51 4c 69 throw new SQLi
cfe0: 74 65 45 78 63 65 70 74 69 6f 6e 28 6e 2c 20 47 teException(n, G
cff0: 65 74 4c 61 73 74 45 72 72 6f 72 28 29 29 3b 0d etLastError());.
d000: 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 2f 2f . }.... //
d010: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
d020: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
d030: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
d040: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
d050: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
d060: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0d 0a 0d /////////////...
d070: 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 72 . /// <summar
d080: 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 44 65 74 65 y>.. /// Dete
d090: 72 6d 69 6e 65 73 20 69 66 20 74 68 65 20 53 51 rmines if the SQ
d0a0: 4c 69 74 65 20 63 6f 72 65 20 6c 69 62 72 61 72 Lite core librar
d0b0: 79 20 68 61 73 20 62 65 65 6e 20 69 6e 69 74 69 y has been initi
d0c0: 61 6c 69 7a 65 64 20 66 6f 72 20 74 68 65 0d 0a alized for the..
d0d0: 20 20 20 20 2f 2f 2f 20 63 75 72 72 65 6e 74 20 /// current
d0e0: 70 72 6f 63 65 73 73 2e 0d 0a 20 20 20 20 2f 2f process... //
d0f0: 2f 20 3c 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 / </summary>..
d100: 20 20 2f 2f 2f 20 3c 72 65 74 75 72 6e 73 3e 0d /// <returns>.
d110: 0a 20 20 20 20 2f 2f 2f 20 41 20 62 6f 6f 6c 65 . /// A boole
d120: 61 6e 20 69 6e 64 69 63 61 74 69 6e 67 20 77 68 an indicating wh
d130: 65 74 68 65 72 20 6f 72 20 6e 6f 74 20 74 68 65 ether or not the
d140: 20 53 51 4c 69 74 65 20 63 6f 72 65 20 6c 69 62 SQLite core lib
d150: 72 61 72 79 20 68 61 73 20 62 65 65 6e 0d 0a 20 rary has been..
d160: 20 20 20 2f 2f 2f 20 69 6e 69 74 69 61 6c 69 7a /// initializ
d170: 65 64 20 66 6f 72 20 74 68 65 20 63 75 72 72 65 ed for the curre
d180: 6e 74 20 70 72 6f 63 65 73 73 2e 0d 0a 20 20 20 nt process...
d190: 20 2f 2f 2f 20 3c 2f 72 65 74 75 72 6e 73 3e 0d /// </returns>.
d1a0: 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 . internal ov
d1b0: 65 72 72 69 64 65 20 62 6f 6f 6c 20 49 73 49 6e erride bool IsIn
d1c0: 69 74 69 61 6c 69 7a 65 64 28 29 0d 0a 20 20 20 itialized()..
d1d0: 20 7b 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75 {.. retu
d1e0: 72 6e 20 53 74 61 74 69 63 49 73 49 6e 69 74 69 rn StaticIsIniti
d1f0: 61 6c 69 7a 65 64 28 29 3b 0d 0a 20 20 20 20 7d alized();.. }
d200: 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 6d .... /// <sum
d210: 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 44 mary>.. /// D
d220: 65 74 65 72 6d 69 6e 65 73 20 69 66 20 74 68 65 etermines if the
d230: 20 53 51 4c 69 74 65 20 63 6f 72 65 20 6c 69 62 SQLite core lib
d240: 72 61 72 79 20 68 61 73 20 62 65 65 6e 20 69 6e rary has been in
d250: 69 74 69 61 6c 69 7a 65 64 20 66 6f 72 20 74 68 itialized for th
d260: 65 0d 0a 20 20 20 20 2f 2f 2f 20 63 75 72 72 65 e.. /// curre
d270: 6e 74 20 70 72 6f 63 65 73 73 2e 0d 0a 20 20 20 nt process...
d280: 20 2f 2f 2f 20 3c 2f 73 75 6d 6d 61 72 79 3e 0d /// </summary>.
d290: 0a 20 20 20 20 2f 2f 2f 20 3c 72 65 74 75 72 6e . /// <return
d2a0: 73 3e 0d 0a 20 20 20 20 2f 2f 2f 20 41 20 62 6f s>.. /// A bo
d2b0: 6f 6c 65 61 6e 20 69 6e 64 69 63 61 74 69 6e 67 olean indicating
d2c0: 20 77 68 65 74 68 65 72 20 6f 72 20 6e 6f 74 20 whether or not
d2d0: 74 68 65 20 53 51 4c 69 74 65 20 63 6f 72 65 20 the SQLite core
d2e0: 6c 69 62 72 61 72 79 20 68 61 73 20 62 65 65 6e library has been
d2f0: 0d 0a 20 20 20 20 2f 2f 2f 20 69 6e 69 74 69 61 .. /// initia
d300: 6c 69 7a 65 64 20 66 6f 72 20 74 68 65 20 63 75 lized for the cu
d310: 72 72 65 6e 74 20 70 72 6f 63 65 73 73 2e 0d 0a rrent process...
d320: 20 20 20 20 2f 2f 2f 20 3c 2f 72 65 74 75 72 6e /// </return
d330: 73 3e 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c s>.. internal
d340: 20 73 74 61 74 69 63 20 62 6f 6f 6c 20 53 74 61 static bool Sta
d350: 74 69 63 49 73 49 6e 69 74 69 61 6c 69 7a 65 64 ticIsInitialized
d360: 28 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 ().. {..
d370: 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 20 20 2f //.. /
d380: 2f 20 42 55 47 46 49 58 3a 20 50 72 65 76 65 6e / BUGFIX: Preven
d390: 74 20 72 61 63 65 73 20 77 69 74 68 20 6f 74 68 t races with oth
d3a0: 65 72 20 74 68 72 65 61 64 73 20 66 6f 72 20 74 er threads for t
d3b0: 68 69 73 20 65 6e 74 69 72 65 20 62 6c 6f 63 6b his entire block
d3c0: 2c 20 64 75 65 0d 0a 20 20 20 20 20 20 20 20 2f , due.. /
d3d0: 2f 20 20 20 20 20 20 20 20 20 74 6f 20 74 68 65 / to the
d3e0: 20 74 72 79 2f 66 69 6e 61 6c 6c 79 20 73 65 6d try/finally sem
d3f0: 61 6e 74 69 63 73 2e 20 20 53 65 65 20 74 69 63 antics. See tic
d400: 6b 65 74 20 5b 37 32 39 30 35 63 39 61 37 37 5d ket [72905c9a77]
d410: 2e 0d 0a 20 20 20 20 20 20 20 20 2f 2f 0d 0a 20 ... //..
d420: 20 20 20 20 20 20 20 6c 6f 63 6b 20 28 73 79 6e lock (syn
d430: 63 52 6f 6f 74 29 0d 0a 20 20 20 20 20 20 20 20 cRoot)..
d440: 7b 0d 0a 23 69 66 20 21 50 4c 41 54 46 4f 52 4d {..#if !PLATFORM
d450: 5f 43 4f 4d 50 41 43 54 46 52 41 4d 45 57 4f 52 _COMPACTFRAMEWOR
d460: 4b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 2f K.. /
d470: 2f 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 2f /.. /
d480: 2f 20 4e 4f 54 45 3a 20 53 61 76 65 20 74 68 65 / NOTE: Save the
d490: 20 73 74 61 74 65 20 6f 66 20 74 68 65 20 6c 6f state of the lo
d4a0: 67 67 69 6e 67 20 63 6c 61 73 73 20 61 6e 64 20 gging class and
d4b0: 74 68 65 6e 20 72 65 73 74 6f 72 65 20 69 74 0d then restore it.
d4c0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 . //
d4d0: 20 20 20 20 20 20 61 66 74 65 72 20 77 65 20 61 after we a
d4e0: 72 65 20 64 6f 6e 65 20 74 6f 20 61 76 6f 69 64 re done to avoid
d4f0: 20 6c 6f 67 67 69 6e 67 20 74 6f 6f 20 6d 61 6e logging too man
d500: 79 20 66 61 6c 73 65 20 65 72 72 6f 72 73 2e 0d y false errors..
d510: 0a 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 0d . //.
d520: 0a 20 20 20 20 20 20 20 20 20 20 20 20 62 6f 6f . boo
d530: 6c 20 73 61 76 65 64 45 6e 61 62 6c 65 64 20 3d l savedEnabled =
d540: 20 53 51 4c 69 74 65 4c 6f 67 2e 45 6e 61 62 6c SQLiteLog.Enabl
d550: 65 64 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ed;..
d560: 20 53 51 4c 69 74 65 4c 6f 67 2e 45 6e 61 62 6c SQLiteLog.Enabl
d570: 65 64 20 3d 20 66 61 6c 73 65 3b 0d 0a 0d 0a 20 ed = false;....
d580: 20 20 20 20 20 20 20 20 20 20 20 74 72 79 0d 0a try..
d590: 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 23 {..#
d5a0: 65 6e 64 69 66 0d 0a 20 20 20 20 20 20 20 20 20 endif..
d5b0: 20 20 20 20 20 20 20 2f 2f 0d 0a 20 20 20 20 20 //..
d5c0: 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 4e 4f // NO
d5d0: 54 45 3a 20 54 68 69 73 20 6d 65 74 68 6f 64 20 TE: This method
d5e0: 5b 61 62 5d 75 73 65 73 20 74 68 65 20 66 61 63 [ab]uses the fac
d5f0: 74 20 74 68 61 74 20 53 51 4c 69 74 65 20 77 69 t that SQLite wi
d600: 6c 6c 20 61 6c 77 61 79 73 0d 0a 20 20 20 20 20 ll always..
d610: 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 20 20 //
d620: 20 20 20 20 72 65 74 75 72 6e 20 53 51 4c 49 54 return SQLIT
d630: 45 5f 45 52 52 4f 52 20 66 6f 72 20 61 6e 79 20 E_ERROR for any
d640: 75 6e 6b 6e 6f 77 6e 20 63 6f 6e 66 69 67 75 72 unknown configur
d650: 61 74 69 6f 6e 20 6f 70 74 69 6f 6e 0d 0a 20 20 ation option..
d660: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f //
d670: 20 20 20 20 20 20 20 2a 75 6e 6c 65 73 73 2a 20 *unless*
d680: 74 68 65 20 53 51 4c 69 74 65 20 6c 69 62 72 61 the SQLite libra
d690: 72 79 20 68 61 73 20 61 6c 72 65 61 64 79 20 62 ry has already b
d6a0: 65 65 6e 20 69 6e 69 74 69 61 6c 69 7a 65 64 2e een initialized.
d6b0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
d6c0: 20 20 2f 2f 20 20 20 20 20 20 20 49 6e 20 74 68 // In th
d6d0: 61 74 20 63 61 73 65 20 69 74 20 77 69 6c 6c 20 at case it will
d6e0: 61 6c 77 61 79 73 20 72 65 74 75 72 6e 20 53 51 always return SQ
d6f0: 4c 49 54 45 5f 4d 49 53 55 53 45 2e 0d 0a 20 20 LITE_MISUSE...
d700: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f //
d710: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
d720: 20 20 69 6e 74 20 72 63 20 3d 20 55 6e 73 61 66 int rc = Unsaf
d730: 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
d740: 71 6c 69 74 65 33 5f 63 6f 6e 66 69 67 28 0d 0a qlite3_config(..
d750: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
d760: 20 20 20 20 28 69 6e 74 29 53 51 4c 69 74 65 43 (int)SQLiteC
d770: 6f 6e 66 69 67 4f 70 73 45 6e 75 6d 2e 53 51 4c onfigOpsEnum.SQL
d780: 49 54 45 5f 43 4f 4e 46 49 47 5f 4e 4f 4e 45 2c ITE_CONFIG_NONE,
d790: 20 6e 75 6c 6c 2c 20 28 49 6e 74 50 74 72 29 30 null, (IntPtr)0
d7a0: 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 );....
d7b0: 20 20 20 20 20 20 72 65 74 75 72 6e 20 28 72 63 return (rc
d7c0: 20 3d 3d 20 2f 2a 20 53 51 4c 49 54 45 5f 4d 49 == /* SQLITE_MI
d7d0: 53 55 53 45 20 2a 2f 20 32 31 29 3b 0d 0a 23 69 SUSE */ 21);..#i
d7e0: 66 20 21 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d 50 f !PLATFORM_COMP
d7f0: 41 43 54 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 20 ACTFRAMEWORK..
d800: 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 }..
d810: 20 20 20 20 20 20 20 20 20 66 69 6e 61 6c 6c 79 finally
d820: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d .. {.
d830: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
d840: 20 53 51 4c 69 74 65 4c 6f 67 2e 45 6e 61 62 6c SQLiteLog.Enabl
d850: 65 64 20 3d 20 73 61 76 65 64 45 6e 61 62 6c 65 ed = savedEnable
d860: 64 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 d;..
d870: 7d 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 20 }..#endif..
d880: 20 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 }.. }....
d890: 20 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 72 79 3e /// <summary>
d8a0: 0d 0a 20 20 20 20 2f 2f 2f 20 48 65 6c 70 65 72 .. /// Helper
d8b0: 20 66 75 6e 63 74 69 6f 6e 20 74 6f 20 72 65 74 function to ret
d8c0: 72 69 65 76 65 20 61 20 63 6f 6c 75 6d 6e 20 6f rieve a column o
d8d0: 66 20 64 61 74 61 20 66 72 6f 6d 20 61 6e 20 61 f data from an a
d8e0: 63 74 69 76 65 20 73 74 61 74 65 6d 65 6e 74 2e ctive statement.
d8f0: 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 73 75 6d 6d .. /// </summ
d900: 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 ary>.. /// <p
d910: 61 72 61 6d 20 6e 61 6d 65 3d 22 73 74 6d 74 22 aram name="stmt"
d920: 3e 54 68 65 20 73 74 61 74 65 6d 65 6e 74 20 62 >The statement b
d930: 65 69 6e 67 20 73 74 65 70 28 29 27 64 20 74 68 eing step()'d th
d940: 72 6f 75 67 68 3c 2f 70 61 72 61 6d 3e 0d 0a 20 rough</param>..
d950: 20 20 20 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 /// <param na
d960: 6d 65 3d 22 69 6e 64 65 78 22 3e 54 68 65 20 63 me="index">The c
d970: 6f 6c 75 6d 6e 20 69 6e 64 65 78 20 74 6f 20 72 olumn index to r
d980: 65 74 72 69 65 76 65 3c 2f 70 61 72 61 6d 3e 0d etrieve</param>.
d990: 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 72 61 6d 20 . /// <param
d9a0: 6e 61 6d 65 3d 22 74 79 70 22 3e 54 68 65 20 74 name="typ">The t
d9b0: 79 70 65 20 6f 66 20 64 61 74 61 20 63 6f 6e 74 ype of data cont
d9c0: 61 69 6e 65 64 20 69 6e 20 74 68 65 20 63 6f 6c ained in the col
d9d0: 75 6d 6e 2e 20 20 49 66 20 55 6e 69 6e 69 74 69 umn. If Uniniti
d9e0: 61 6c 69 7a 65 64 2c 20 74 68 69 73 20 66 75 6e alized, this fun
d9f0: 63 74 69 6f 6e 20 77 69 6c 6c 20 72 65 74 72 69 ction will retri
da00: 65 76 65 20 74 68 65 20 64 61 74 61 74 79 70 65 eve the datatype
da10: 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 3c 2f 70 information.</p
da20: 61 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c aram>.. /// <
da30: 72 65 74 75 72 6e 73 3e 52 65 74 75 72 6e 73 20 returns>Returns
da40: 74 68 65 20 64 61 74 61 20 69 6e 20 74 68 65 20 the data in the
da50: 63 6f 6c 75 6d 6e 3c 2f 72 65 74 75 72 6e 73 3e column</returns>
da60: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
da70: 76 65 72 72 69 64 65 20 6f 62 6a 65 63 74 20 47 verride object G
da80: 65 74 56 61 6c 75 65 28 53 51 4c 69 74 65 53 74 etValue(SQLiteSt
da90: 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 69 6e atement stmt, in
daa0: 74 20 69 6e 64 65 78 2c 20 53 51 4c 69 74 65 54 t index, SQLiteT
dab0: 79 70 65 20 74 79 70 29 0d 0a 20 20 20 20 7b 0d ype typ).. {.
dac0: 0a 20 20 20 20 20 20 69 66 20 28 49 73 4e 75 6c . if (IsNul
dad0: 6c 28 73 74 6d 74 2c 20 69 6e 64 65 78 29 29 20 l(stmt, index))
dae0: 72 65 74 75 72 6e 20 44 42 4e 75 6c 6c 2e 56 61 return DBNull.Va
daf0: 6c 75 65 3b 0d 0a 20 20 20 20 20 20 54 79 70 65 lue;.. Type
db00: 41 66 66 69 6e 69 74 79 20 61 66 66 20 3d 20 74 Affinity aff = t
db10: 79 70 2e 41 66 66 69 6e 69 74 79 3b 0d 0a 20 20 yp.Affinity;..
db20: 20 20 20 20 54 79 70 65 20 74 20 3d 20 6e 75 6c Type t = nul
db30: 6c 3b 0d 0a 0d 0a 20 20 20 20 20 20 69 66 20 28 l;.... if (
db40: 74 79 70 2e 54 79 70 65 20 21 3d 20 44 62 54 79 typ.Type != DbTy
db50: 70 65 2e 4f 62 6a 65 63 74 29 0d 0a 20 20 20 20 pe.Object)..
db60: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 74 20 3d {.. t =
db70: 20 53 51 4c 69 74 65 43 6f 6e 76 65 72 74 2e 53 SQLiteConvert.S
db80: 51 4c 69 74 65 54 79 70 65 54 6f 54 79 70 65 28 QLiteTypeToType(
db90: 74 79 70 29 3b 0d 0a 20 20 20 20 20 20 20 20 61 typ);.. a
dba0: 66 66 20 3d 20 54 79 70 65 54 6f 41 66 66 69 6e ff = TypeToAffin
dbb0: 69 74 79 28 74 29 3b 0d 0a 20 20 20 20 20 20 7d ity(t);.. }
dbc0: 0d 0a 0d 0a 20 20 20 20 20 20 73 77 69 74 63 68 .... switch
dbd0: 20 28 61 66 66 29 0d 0a 20 20 20 20 20 20 7b 0d (aff).. {.
dbe0: 0a 20 20 20 20 20 20 20 20 63 61 73 65 20 54 79 . case Ty
dbf0: 70 65 41 66 66 69 6e 69 74 79 2e 42 6c 6f 62 3a peAffinity.Blob:
dc00: 0d 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 28 .. if (
dc10: 74 79 70 2e 54 79 70 65 20 3d 3d 20 44 62 54 79 typ.Type == DbTy
dc20: 70 65 2e 47 75 69 64 20 26 26 20 74 79 70 2e 41 pe.Guid && typ.A
dc30: 66 66 69 6e 69 74 79 20 3d 3d 20 54 79 70 65 41 ffinity == TypeA
dc40: 66 66 69 6e 69 74 79 2e 54 65 78 74 29 0d 0a 20 ffinity.Text)..
dc50: 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 retur
dc60: 6e 20 6e 65 77 20 47 75 69 64 28 47 65 74 54 65 n new Guid(GetTe
dc70: 78 74 28 73 74 6d 74 2c 20 69 6e 64 65 78 29 29 xt(stmt, index))
dc80: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 69 ;.... i
dc90: 6e 74 20 6e 20 3d 20 28 69 6e 74 29 47 65 74 42 nt n = (int)GetB
dca0: 79 74 65 73 28 73 74 6d 74 2c 20 69 6e 64 65 78 ytes(stmt, index
dcb0: 2c 20 30 2c 20 6e 75 6c 6c 2c 20 30 2c 20 30 29 , 0, null, 0, 0)
dcc0: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 62 79 74 ;.. byt
dcd0: 65 5b 5d 20 62 20 3d 20 6e 65 77 20 62 79 74 65 e[] b = new byte
dce0: 5b 6e 5d 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 [n];..
dcf0: 47 65 74 42 79 74 65 73 28 73 74 6d 74 2c 20 69 GetBytes(stmt, i
dd00: 6e 64 65 78 2c 20 30 2c 20 62 2c 20 30 2c 20 6e ndex, 0, b, 0, n
dd10: 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 );....
dd20: 69 66 20 28 74 79 70 2e 54 79 70 65 20 3d 3d 20 if (typ.Type ==
dd30: 44 62 54 79 70 65 2e 47 75 69 64 20 26 26 20 6e DbType.Guid && n
dd40: 20 3d 3d 20 31 36 29 0d 0a 20 20 20 20 20 20 20 == 16)..
dd50: 20 20 20 20 20 72 65 74 75 72 6e 20 6e 65 77 20 return new
dd60: 47 75 69 64 28 62 29 3b 0d 0a 0d 0a 20 20 20 20 Guid(b);....
dd70: 20 20 20 20 20 20 72 65 74 75 72 6e 20 62 3b 0d return b;.
dd80: 0a 20 20 20 20 20 20 20 20 63 61 73 65 20 54 79 . case Ty
dd90: 70 65 41 66 66 69 6e 69 74 79 2e 44 61 74 65 54 peAffinity.DateT
dda0: 69 6d 65 3a 0d 0a 20 20 20 20 20 20 20 20 20 20 ime:..
ddb0: 72 65 74 75 72 6e 20 47 65 74 44 61 74 65 54 69 return GetDateTi
ddc0: 6d 65 28 73 74 6d 74 2c 20 69 6e 64 65 78 29 3b me(stmt, index);
ddd0: 0d 0a 20 20 20 20 20 20 20 20 63 61 73 65 20 54 .. case T
dde0: 79 70 65 41 66 66 69 6e 69 74 79 2e 44 6f 75 62 ypeAffinity.Doub
ddf0: 6c 65 3a 0d 0a 20 20 20 20 20 20 20 20 20 20 69 le:.. i
de00: 66 20 28 74 20 3d 3d 20 6e 75 6c 6c 29 20 72 65 f (t == null) re
de10: 74 75 72 6e 20 47 65 74 44 6f 75 62 6c 65 28 73 turn GetDouble(s
de20: 74 6d 74 2c 20 69 6e 64 65 78 29 3b 0d 0a 20 20 tmt, index);..
de30: 20 20 20 20 20 20 20 20 65 6c 73 65 0d 0a 20 20 else..
de40: 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e return
de50: 20 43 6f 6e 76 65 72 74 2e 43 68 61 6e 67 65 54 Convert.ChangeT
de60: 79 70 65 28 47 65 74 44 6f 75 62 6c 65 28 73 74 ype(GetDouble(st
de70: 6d 74 2c 20 69 6e 64 65 78 29 2c 20 74 2c 20 6e mt, index), t, n
de80: 75 6c 6c 29 3b 0d 0a 20 20 20 20 20 20 20 20 63 ull);.. c
de90: 61 73 65 20 54 79 70 65 41 66 66 69 6e 69 74 79 ase TypeAffinity
dea0: 2e 49 6e 74 36 34 3a 0d 0a 20 20 20 20 20 20 20 .Int64:..
deb0: 20 20 20 69 66 20 28 74 20 3d 3d 20 6e 75 6c 6c if (t == null
dec0: 29 20 72 65 74 75 72 6e 20 47 65 74 49 6e 74 36 ) return GetInt6
ded0: 34 28 73 74 6d 74 2c 20 69 6e 64 65 78 29 3b 0d 4(stmt, index);.
dee0: 0a 20 20 20 20 20 20 20 20 20 20 65 6c 73 65 0d . else.
def0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 . ret
df00: 75 72 6e 20 43 6f 6e 76 65 72 74 2e 43 68 61 6e urn Convert.Chan
df10: 67 65 54 79 70 65 28 47 65 74 49 6e 74 36 34 28 geType(GetInt64(
df20: 73 74 6d 74 2c 20 69 6e 64 65 78 29 2c 20 74 2c stmt, index), t,
df30: 20 6e 75 6c 6c 29 3b 0d 0a 20 20 20 20 20 20 20 null);..
df40: 20 64 65 66 61 75 6c 74 3a 0d 0a 20 20 20 20 20 default:..
df50: 20 20 20 20 20 72 65 74 75 72 6e 20 47 65 74 54 return GetT
df60: 65 78 74 28 73 74 6d 74 2c 20 69 6e 64 65 78 29 ext(stmt, index)
df70: 3b 0d 0a 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 ;.. }..
df80: 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 }.... interna
df90: 6c 20 6f 76 65 72 72 69 64 65 20 69 6e 74 20 47 l override int G
dfa0: 65 74 43 75 72 73 6f 72 46 6f 72 54 61 62 6c 65 etCursorForTable
dfb0: 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 (SQLiteStatement
dfc0: 20 73 74 6d 74 2c 20 69 6e 74 20 64 62 2c 20 69 stmt, int db, i
dfd0: 6e 74 20 72 6f 6f 74 50 61 67 65 29 0d 0a 20 20 nt rootPage)..
dfe0: 20 20 7b 0d 0a 23 69 66 20 21 53 51 4c 49 54 45 {..#if !SQLITE
dff0: 5f 53 54 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 _STANDARD..
e000: 20 72 65 74 75 72 6e 20 55 6e 73 61 66 65 4e 61 return UnsafeNa
e010: 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 tiveMethods.sqli
e020: 74 65 33 5f 74 61 62 6c 65 5f 63 75 72 73 6f 72 te3_table_cursor
e030: 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 (stmt._sqlite_st
e040: 6d 74 2c 20 64 62 2c 20 72 6f 6f 74 50 61 67 65 mt, db, rootPage
e050: 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 );..#else..
e060: 20 72 65 74 75 72 6e 20 2d 31 3b 0d 0a 23 65 6e return -1;..#en
e070: 64 69 66 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 dif.. }....
e080: 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
e090: 69 64 65 20 6c 6f 6e 67 20 47 65 74 52 6f 77 49 ide long GetRowI
e0a0: 64 46 6f 72 43 75 72 73 6f 72 28 53 51 4c 69 74 dForCursor(SQLit
e0b0: 65 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c eStatement stmt,
e0c0: 20 69 6e 74 20 63 75 72 73 6f 72 29 0d 0a 20 20 int cursor)..
e0d0: 20 20 7b 0d 0a 23 69 66 20 21 53 51 4c 49 54 45 {..#if !SQLITE
e0e0: 5f 53 54 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 _STANDARD..
e0f0: 20 6c 6f 6e 67 20 72 6f 77 69 64 3b 0d 0a 20 20 long rowid;..
e100: 20 20 20 20 69 6e 74 20 72 63 20 3d 20 55 6e 73 int rc = Uns
e110: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
e120: 2e 73 71 6c 69 74 65 33 5f 63 75 72 73 6f 72 5f .sqlite3_cursor_
e130: 72 6f 77 69 64 28 73 74 6d 74 2e 5f 73 71 6c 69 rowid(stmt._sqli
e140: 74 65 5f 73 74 6d 74 2c 20 63 75 72 73 6f 72 2c te_stmt, cursor,
e150: 20 6f 75 74 20 72 6f 77 69 64 29 3b 0d 0a 20 20 out rowid);..
e160: 20 20 20 20 69 66 20 28 72 63 20 3d 3d 20 30 29 if (rc == 0)
e170: 20 72 65 74 75 72 6e 20 72 6f 77 69 64 3b 0d 0a return rowid;..
e180: 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 30 .. return 0
e190: 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 ;..#else..
e1a0: 72 65 74 75 72 6e 20 30 3b 0d 0a 23 65 6e 64 69 return 0;..#endi
e1b0: 66 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 f.. }....
e1c0: 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 internal overrid
e1d0: 65 20 76 6f 69 64 20 47 65 74 49 6e 64 65 78 43 e void GetIndexC
e1e0: 6f 6c 75 6d 6e 45 78 74 65 6e 64 65 64 49 6e 66 olumnExtendedInf
e1f0: 6f 28 73 74 72 69 6e 67 20 64 61 74 61 62 61 73 o(string databas
e200: 65 2c 20 73 74 72 69 6e 67 20 69 6e 64 65 78 2c e, string index,
e210: 20 73 74 72 69 6e 67 20 63 6f 6c 75 6d 6e 2c 20 string column,
e220: 6f 75 74 20 69 6e 74 20 73 6f 72 74 4d 6f 64 65 out int sortMode
e230: 2c 20 6f 75 74 20 69 6e 74 20 6f 6e 45 72 72 6f , out int onErro
e240: 72 2c 20 6f 75 74 20 73 74 72 69 6e 67 20 63 6f r, out string co
e250: 6c 6c 61 74 69 6f 6e 53 65 71 75 65 6e 63 65 29 llationSequence)
e260: 0d 0a 20 20 20 20 7b 0d 0a 23 69 66 20 21 53 51 .. {..#if !SQ
e270: 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a 20 LITE_STANDARD..
e280: 20 20 20 20 20 49 6e 74 50 74 72 20 63 6f 6c 6c IntPtr coll
e290: 3b 0d 0a 20 20 20 20 20 20 69 6e 74 20 63 6f 6c ;.. int col
e2a0: 6c 6c 65 6e 3b 0d 0a 20 20 20 20 20 20 69 6e 74 llen;.. int
e2b0: 20 72 63 3b 0d 0a 0d 0a 20 20 20 20 20 20 72 63 rc;.... rc
e2c0: 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d = UnsafeNativeM
e2d0: 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 69 ethods.sqlite3_i
e2e0: 6e 64 65 78 5f 63 6f 6c 75 6d 6e 5f 69 6e 66 6f ndex_column_info
e2f0: 5f 69 6e 74 65 72 6f 70 28 5f 73 71 6c 2c 20 54 _interop(_sql, T
e300: 6f 55 54 46 38 28 64 61 74 61 62 61 73 65 29 2c oUTF8(database),
e310: 20 54 6f 55 54 46 38 28 69 6e 64 65 78 29 2c 20 ToUTF8(index),
e320: 54 6f 55 54 46 38 28 63 6f 6c 75 6d 6e 29 2c 20 ToUTF8(column),
e330: 6f 75 74 20 73 6f 72 74 4d 6f 64 65 2c 20 6f 75 out sortMode, ou
e340: 74 20 6f 6e 45 72 72 6f 72 2c 20 6f 75 74 20 63 t onError, out c
e350: 6f 6c 6c 2c 20 6f 75 74 20 63 6f 6c 6c 6c 65 6e oll, out colllen
e360: 29 3b 0d 0a 20 20 20 20 20 20 69 66 20 28 72 63 );.. if (rc
e370: 20 21 3d 20 30 29 20 74 68 72 6f 77 20 6e 65 77 != 0) throw new
e380: 20 53 51 4c 69 74 65 45 78 63 65 70 74 69 6f 6e SQLiteException
e390: 28 72 63 2c 20 22 22 29 3b 0d 0a 0d 0a 20 20 20 (rc, "");....
e3a0: 20 20 20 63 6f 6c 6c 61 74 69 6f 6e 53 65 71 75 collationSequ
e3b0: 65 6e 63 65 20 3d 20 55 54 46 38 54 6f 53 74 72 ence = UTF8ToStr
e3c0: 69 6e 67 28 63 6f 6c 6c 2c 20 63 6f 6c 6c 6c 65 ing(coll, collle
e3d0: 6e 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 n);..#else..
e3e0: 20 20 73 6f 72 74 4d 6f 64 65 20 3d 20 30 3b 0d sortMode = 0;.
e3f0: 0a 20 20 20 20 20 20 6f 6e 45 72 72 6f 72 20 3d . onError =
e400: 20 32 3b 0d 0a 20 20 20 20 20 20 63 6f 6c 6c 61 2;.. colla
e410: 74 69 6f 6e 53 65 71 75 65 6e 63 65 20 3d 20 22 tionSequence = "
e420: 42 49 4e 41 52 59 22 3b 0d 0a 23 65 6e 64 69 66 BINARY";..#endif
e430: 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 .. }.... i
e440: 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 nternal override
e450: 20 69 6e 74 20 46 69 6c 65 43 6f 6e 74 72 6f 6c int FileControl
e460: 28 73 74 72 69 6e 67 20 7a 44 62 4e 61 6d 65 2c (string zDbName,
e470: 20 69 6e 74 20 6f 70 2c 20 49 6e 74 50 74 72 20 int op, IntPtr
e480: 70 41 72 67 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 pArg).. {..
e490: 20 20 20 20 72 65 74 75 72 6e 20 55 6e 73 61 66 return Unsaf
e4a0: 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
e4b0: 71 6c 69 74 65 33 5f 66 69 6c 65 5f 63 6f 6e 74 qlite3_file_cont
e4c0: 72 6f 6c 28 5f 73 71 6c 2c 20 28 7a 44 62 4e 61 rol(_sql, (zDbNa
e4d0: 6d 65 20 21 3d 20 6e 75 6c 6c 29 20 3f 20 54 6f me != null) ? To
e4e0: 55 54 46 38 28 7a 44 62 4e 61 6d 65 29 20 3a 20 UTF8(zDbName) :
e4f0: 6e 75 6c 6c 2c 20 6f 70 2c 20 70 41 72 67 29 3b null, op, pArg);
e500: 0d 0a 20 20 20 20 7d 0d 0a 20 20 7d 0d 0a 7d 0d .. }.. }..}.
e510: 0a .