0000: 2f 2a 2a 2a 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 0d 0a 20 2a 20 41 44 *********.. * AD
0040: 4f 2e 4e 45 54 20 32 2e 30 20 44 61 74 61 20 50 O.NET 2.0 Data P
0050: 72 6f 76 69 64 65 72 20 66 6f 72 20 53 51 4c 69 rovider for SQLi
0060: 74 65 20 56 65 72 73 69 6f 6e 20 33 2e 58 0d 0a te Version 3.X..
0070: 20 2a 20 57 72 69 74 74 65 6e 20 62 79 20 52 6f * Written by Ro
0080: 62 65 72 74 20 53 69 6d 70 73 6f 6e 20 28 72 6f bert Simpson (ro
0090: 62 65 72 74 40 62 6c 61 63 6b 63 61 73 74 6c 65 bert@blackcastle
00a0: 73 6f 66 74 2e 63 6f 6d 29 0d 0a 20 2a 20 0d 0a soft.com).. * ..
00b0: 20 2a 20 52 65 6c 65 61 73 65 64 20 74 6f 20 74 * Released to t
00c0: 68 65 20 70 75 62 6c 69 63 20 64 6f 6d 61 69 6e he public domain
00d0: 2c 20 75 73 65 20 61 74 20 79 6f 75 72 20 6f 77 , use at your ow
00e0: 6e 20 72 69 73 6b 21 0d 0a 20 2a 2a 2a 2a 2a 2a n 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 2f 0d 0a 0d 0a 6e 61 6d 65 73 70 61 63 65 **/....namespace
0130: 20 53 79 73 74 65 6d 2e 44 61 74 61 2e 53 51 4c System.Data.SQL
0140: 69 74 65 0d 0a 7b 0d 0a 20 20 75 73 69 6e 67 20 ite..{.. using
0150: 53 79 73 74 65 6d 3b 0d 0a 20 20 75 73 69 6e 67 System;.. using
0160: 20 53 79 73 74 65 6d 2e 43 6f 6c 6c 65 63 74 69 System.Collecti
0170: 6f 6e 73 2e 47 65 6e 65 72 69 63 3b 0d 0a 0d 0a ons.Generic;....
0180: 23 69 66 20 21 4e 45 54 5f 43 4f 4d 50 41 43 54 #if !NET_COMPACT
0190: 5f 32 30 20 26 26 20 28 54 52 41 43 45 5f 43 4f _20 && (TRACE_CO
01a0: 4e 4e 45 43 54 49 4f 4e 20 7c 7c 20 54 52 41 43 NNECTION || TRAC
01b0: 45 5f 53 54 41 54 45 4d 45 4e 54 29 0d 0a 20 20 E_STATEMENT)..
01c0: 75 73 69 6e 67 20 53 79 73 74 65 6d 2e 44 69 61 using System.Dia
01d0: 67 6e 6f 73 74 69 63 73 3b 0d 0a 23 65 6e 64 69 gnostics;..#endi
01e0: 66 0d 0a 0d 0a 20 20 75 73 69 6e 67 20 53 79 73 f.... using Sys
01f0: 74 65 6d 2e 47 6c 6f 62 61 6c 69 7a 61 74 69 6f tem.Globalizatio
0200: 6e 3b 0d 0a 20 20 75 73 69 6e 67 20 53 79 73 74 n;.. using Syst
0210: 65 6d 2e 52 75 6e 74 69 6d 65 2e 49 6e 74 65 72 em.Runtime.Inter
0220: 6f 70 53 65 72 76 69 63 65 73 3b 0d 0a 20 20 75 opServices;.. u
0230: 73 69 6e 67 20 53 79 73 74 65 6d 2e 54 65 78 74 sing System.Text
0240: 3b 0d 0a 0d 0a 20 20 2f 2f 2f 20 3c 73 75 6d 6d ;.... /// <summ
0250: 61 72 79 3e 0d 0a 20 20 2f 2f 2f 20 54 68 69 73 ary>.. /// This
0260: 20 69 73 20 74 68 65 20 6d 65 74 68 6f 64 20 73 is the method s
0270: 69 67 6e 61 74 75 72 65 20 66 6f 72 20 74 68 65 ignature for the
0280: 20 53 51 4c 69 74 65 20 63 6f 72 65 20 6c 69 62 SQLite core lib
0290: 72 61 72 79 20 6c 6f 67 67 69 6e 67 20 63 61 6c rary logging cal
02a0: 6c 62 61 63 6b 0d 0a 20 20 2f 2f 2f 20 66 75 6e lback.. /// fun
02b0: 63 74 69 6f 6e 20 66 6f 72 20 75 73 65 20 77 69 ction for use wi
02c0: 74 68 20 73 71 6c 69 74 65 33 5f 6c 6f 67 28 29 th sqlite3_log()
02d0: 20 61 6e 64 20 74 68 65 20 53 51 4c 49 54 45 5f and the SQLITE_
02e0: 43 4f 4e 46 49 47 5f 4c 4f 47 2e 0d 0a 20 20 2f CONFIG_LOG... /
02f0: 2f 2f 0d 0a 20 20 2f 2f 2f 20 57 41 52 4e 49 4e //.. /// WARNIN
0300: 47 3a 20 54 68 69 73 20 64 65 6c 65 67 61 74 65 G: This delegate
0310: 20 69 73 20 75 73 65 64 20 6d 6f 72 65 2d 6f 72 is used more-or
0320: 2d 6c 65 73 73 20 64 69 72 65 63 74 6c 79 20 62 -less directly b
0330: 79 20 6e 61 74 69 76 65 20 63 6f 64 65 2c 20 64 y native code, d
0340: 6f 0d 0a 20 20 2f 2f 2f 20 20 20 20 20 20 20 20 o.. ///
0350: 20 20 6e 6f 74 20 6d 6f 64 69 66 79 20 69 74 73 not modify its
0360: 20 74 79 70 65 20 73 69 67 6e 61 74 75 72 65 2e type signature.
0370: 0d 0a 20 20 2f 2f 2f 20 3c 2f 73 75 6d 6d 61 72 .. /// </summar
0380: 79 3e 0d 0a 20 20 2f 2f 2f 20 3c 70 61 72 61 6d y>.. /// <param
0390: 20 6e 61 6d 65 3d 22 70 55 73 65 72 44 61 74 61 name="pUserData
03a0: 22 3e 0d 0a 20 20 2f 2f 2f 20 54 68 65 20 65 78 ">.. /// The ex
03b0: 74 72 61 20 64 61 74 61 20 61 73 73 6f 63 69 61 tra data associa
03c0: 74 65 64 20 77 69 74 68 20 74 68 69 73 20 6d 65 ted with this me
03d0: 73 73 61 67 65 2c 20 69 66 20 61 6e 79 2e 0d 0a ssage, if any...
03e0: 20 20 2f 2f 2f 20 3c 2f 70 61 72 61 6d 3e 0d 0a /// </param>..
03f0: 20 20 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 6d /// <param nam
0400: 65 3d 22 65 72 72 6f 72 43 6f 64 65 22 3e 0d 0a e="errorCode">..
0410: 20 20 2f 2f 2f 20 54 68 65 20 65 72 72 6f 72 20 /// The error
0420: 63 6f 64 65 20 61 73 73 6f 63 69 61 74 65 64 20 code associated
0430: 77 69 74 68 20 74 68 69 73 20 6d 65 73 73 61 67 with this messag
0440: 65 2e 0d 0a 20 20 2f 2f 2f 20 3c 2f 70 61 72 61 e... /// </para
0450: 6d 3e 0d 0a 20 20 2f 2f 2f 20 3c 70 61 72 61 6d m>.. /// <param
0460: 20 6e 61 6d 65 3d 22 70 4d 65 73 73 61 67 65 22 name="pMessage"
0470: 3e 0d 0a 20 20 2f 2f 2f 20 54 68 65 20 6d 65 73 >.. /// The mes
0480: 73 61 67 65 20 73 74 72 69 6e 67 20 74 6f 20 62 sage string to b
0490: 65 20 6c 6f 67 67 65 64 2e 0d 0a 20 20 2f 2f 2f e logged... ///
04a0: 20 3c 2f 70 61 72 61 6d 3e 0d 0a 23 69 66 20 21 </param>..#if !
04b0: 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 PLATFORM_COMPACT
04c0: 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 20 5b 55 6e FRAMEWORK.. [Un
04d0: 6d 61 6e 61 67 65 64 46 75 6e 63 74 69 6f 6e 50 managedFunctionP
04e0: 6f 69 6e 74 65 72 28 43 61 6c 6c 69 6e 67 43 6f ointer(CallingCo
04f0: 6e 76 65 6e 74 69 6f 6e 2e 43 64 65 63 6c 29 5d nvention.Cdecl)]
0500: 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 69 6e 74 65 ..#endif.. inte
0510: 72 6e 61 6c 20 64 65 6c 65 67 61 74 65 20 76 6f rnal delegate vo
0520: 69 64 20 53 51 4c 69 74 65 4c 6f 67 43 61 6c 6c id SQLiteLogCall
0530: 62 61 63 6b 28 49 6e 74 50 74 72 20 70 55 73 65 back(IntPtr pUse
0540: 72 44 61 74 61 2c 20 69 6e 74 20 65 72 72 6f 72 rData, int error
0550: 43 6f 64 65 2c 20 49 6e 74 50 74 72 20 70 4d 65 Code, IntPtr pMe
0560: 73 73 61 67 65 29 3b 0d 0a 0d 0a 20 20 2f 2f 2f ssage);.... ///
0570: 20 3c 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 2f 2f <summary>.. //
0580: 2f 20 54 68 69 73 20 63 6c 61 73 73 20 69 6d 70 / This class imp
0590: 6c 65 6d 65 6e 74 73 20 53 51 4c 69 74 65 42 61 lements SQLiteBa
05a0: 73 65 20 63 6f 6d 70 6c 65 74 65 6c 79 2c 20 61 se completely, a
05b0: 6e 64 20 69 73 20 74 68 65 20 67 75 74 73 20 6f nd is the guts o
05c0: 66 20 74 68 65 20 63 6f 64 65 20 74 68 61 74 20 f the code that
05d0: 69 6e 74 65 72 6f 70 27 73 20 53 51 4c 69 74 65 interop's SQLite
05e0: 20 77 69 74 68 20 2e 4e 45 54 0d 0a 20 20 2f 2f with .NET.. //
05f0: 2f 20 3c 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 / </summary>..
0600: 69 6e 74 65 72 6e 61 6c 20 63 6c 61 73 73 20 53 internal class S
0610: 51 4c 69 74 65 33 20 3a 20 53 51 4c 69 74 65 42 QLite3 : SQLiteB
0620: 61 73 65 0d 0a 20 20 7b 0d 0a 20 20 20 20 70 72 ase.. {.. pr
0630: 69 76 61 74 65 20 73 74 61 74 69 63 20 6f 62 6a ivate static obj
0640: 65 63 74 20 73 79 6e 63 52 6f 6f 74 20 3d 20 6e ect syncRoot = n
0650: 65 77 20 6f 62 6a 65 63 74 28 29 3b 0d 0a 0d 0a ew object();....
0660: 20 20 20 20 2f 2f 0d 0a 20 20 20 20 2f 2f 20 4e //.. // N
0670: 4f 54 45 3a 20 54 68 69 73 20 69 73 20 74 68 65 OTE: This is the
0680: 20 70 75 62 6c 69 63 20 6b 65 79 20 66 6f 72 20 public key for
0690: 74 68 65 20 53 79 73 74 65 6d 2e 44 61 74 61 2e the System.Data.
06a0: 53 51 4c 69 74 65 20 61 73 73 65 6d 62 6c 79 2e SQLite assembly.
06b0: 20 20 49 66 20 79 6f 75 20 63 68 61 6e 67 65 20 If you change
06c0: 74 68 65 0d 0a 20 20 20 20 2f 2f 20 20 20 20 20 the.. //
06d0: 20 20 53 4e 4b 20 66 69 6c 65 2c 20 79 6f 75 20 SNK file, you
06e0: 77 69 6c 6c 20 6e 65 65 64 20 74 6f 20 63 68 61 will need to cha
06f0: 6e 67 65 20 74 68 69 73 20 61 73 20 77 65 6c 6c nge this as well
0700: 2e 0d 0a 20 20 20 20 2f 2f 0d 0a 20 20 20 20 69 ... //.. i
0710: 6e 74 65 72 6e 61 6c 20 63 6f 6e 73 74 20 73 74 nternal const st
0720: 72 69 6e 67 20 50 75 62 6c 69 63 4b 65 79 20 3d ring PublicKey =
0730: 0d 0a 20 20 20 20 20 20 20 20 22 30 30 32 34 30 .. "00240
0740: 30 30 30 30 34 38 30 30 30 30 30 39 34 30 30 30 0000480000094000
0750: 30 30 30 30 36 30 32 30 30 30 30 30 30 32 34 30 0000602000000240
0760: 30 30 30 35 32 35 33 34 31 33 31 30 30 30 34 30 0005253413100040
0770: 30 30 30 30 31 30 30 30 31 30 30 30 35 61 32 38 0000100010005a28
0780: 38 64 65 35 36 38 37 63 34 65 31 22 20 2b 0d 0a 8de5687c4e1" +..
0790: 20 20 20 20 20 20 20 20 22 62 36 32 31 64 64 66 "b621ddf
07a0: 66 35 64 38 34 34 37 32 37 34 31 38 39 35 36 39 f5d8447274189569
07b0: 39 37 66 34 37 35 65 62 38 32 39 34 32 39 65 34 97f475eb829429e4
07c0: 31 31 61 66 66 33 65 39 33 66 39 37 62 37 30 64 11aff3e93f97b70d
07d0: 65 36 39 38 62 39 37 32 36 34 30 39 32 35 62 64 e698b972640925bd
07e0: 64 34 34 32 38 30 64 66 30 22 20 2b 0d 0a 20 20 d44280df0" +..
07f0: 20 20 20 20 20 20 22 61 32 35 61 38 34 33 32 36 "a25a84326
0800: 36 39 37 33 37 30 34 31 33 37 63 62 62 30 65 37 6973704137cbb0e7
0810: 34 34 31 63 31 66 65 37 63 61 65 34 65 32 34 34 441c1fe7cae4e244
0820: 30 61 65 39 31 61 62 38 63 64 65 33 39 33 33 66 0ae91ab8cde3933f
0830: 65 62 63 62 31 61 63 34 38 64 64 33 33 62 34 30 ebcb1ac48dd33b40
0840: 65 31 33 63 34 32 31 22 20 2b 0d 0a 20 20 20 20 e13c421" +..
0850: 20 20 20 20 22 64 38 32 31 35 63 31 38 61 34 33 "d8215c18a43
0860: 34 39 61 34 33 36 64 64 34 39 39 65 33 63 33 38 49a436dd499e3c38
0870: 35 63 63 36 38 33 30 31 35 66 38 38 36 66 36 63 5cc683015f886f6c
0880: 31 30 62 64 39 30 31 31 35 65 62 32 62 64 36 31 10bd90115eb2bd61
0890: 62 36 37 37 35 30 38 33 39 65 33 61 31 39 39 34 b67750839e3a1994
08a0: 31 64 63 39 63 22 3b 0d 0a 0d 0a 23 69 66 20 21 1dc9c";....#if !
08b0: 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 PLATFORM_COMPACT
08c0: 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 69 FRAMEWORK.. i
08d0: 6e 74 65 72 6e 61 6c 20 63 6f 6e 73 74 20 73 74 nternal const st
08e0: 72 69 6e 67 20 44 65 73 69 67 6e 65 72 56 65 72 ring DesignerVer
08f0: 73 69 6f 6e 20 3d 20 22 31 2e 30 2e 39 34 2e 30 sion = "1.0.94.0
0900: 22 3b 0d 0a 23 65 6e 64 69 66 0d 0a 0d 0a 20 20 ";..#endif....
0910: 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 72 79 3e 0d /// <summary>.
0920: 0a 20 20 20 20 2f 2f 2f 20 54 68 65 20 6f 70 61 . /// The opa
0930: 71 75 65 20 70 6f 69 6e 74 65 72 20 72 65 74 75 que pointer retu
0940: 72 6e 65 64 20 74 6f 20 75 73 20 62 79 20 74 68 rned to us by th
0950: 65 20 73 71 6c 69 74 65 20 70 72 6f 76 69 64 65 e sqlite provide
0960: 72 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 73 75 6d r.. /// </sum
0970: 6d 61 72 79 3e 0d 0a 20 20 20 20 70 72 6f 74 65 mary>.. prote
0980: 63 74 65 64 20 69 6e 74 65 72 6e 61 6c 20 53 51 cted internal SQ
0990: 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 48 61 LiteConnectionHa
09a0: 6e 64 6c 65 20 5f 73 71 6c 3b 0d 0a 20 20 20 20 ndle _sql;..
09b0: 70 72 6f 74 65 63 74 65 64 20 73 74 72 69 6e 67 protected string
09c0: 20 5f 66 69 6c 65 4e 61 6d 65 3b 0d 0a 20 20 20 _fileName;..
09d0: 20 70 72 6f 74 65 63 74 65 64 20 62 6f 6f 6c 20 protected bool
09e0: 5f 75 73 65 50 6f 6f 6c 3b 0d 0a 20 20 20 20 70 _usePool;.. p
09f0: 72 6f 74 65 63 74 65 64 20 69 6e 74 20 5f 70 6f rotected int _po
0a00: 6f 6c 56 65 72 73 69 6f 6e 3b 0d 0a 0d 0a 23 69 olVersion;....#i
0a10: 66 20 28 4e 45 54 5f 33 35 20 7c 7c 20 4e 45 54 f (NET_35 || NET
0a20: 5f 34 30 20 7c 7c 20 4e 45 54 5f 34 35 20 7c 7c _40 || NET_45 ||
0a30: 20 4e 45 54 5f 34 35 31 29 20 26 26 20 21 50 4c NET_451) && !PL
0a40: 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 ATFORM_COMPACTFR
0a50: 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 70 72 69 AMEWORK.. pri
0a60: 76 61 74 65 20 62 6f 6f 6c 20 5f 62 75 69 6c 64 vate bool _build
0a70: 69 6e 67 53 63 68 65 6d 61 3b 0d 0a 23 65 6e 64 ingSchema;..#end
0a80: 69 66 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 20 3c 73 if.... /// <s
0a90: 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f ummary>.. ///
0aa0: 20 54 68 65 20 75 73 65 72 2d 64 65 66 69 6e 65 The user-define
0ab0: 64 20 66 75 6e 63 74 69 6f 6e 73 20 72 65 67 69 d functions regi
0ac0: 73 74 65 72 65 64 20 6f 6e 20 74 68 69 73 20 63 stered on this c
0ad0: 6f 6e 6e 65 63 74 69 6f 6e 0d 0a 20 20 20 20 2f onnection.. /
0ae0: 2f 2f 20 3c 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 // </summary>..
0af0: 20 20 20 70 72 6f 74 65 63 74 65 64 20 4c 69 73 protected Lis
0b00: 74 3c 53 51 4c 69 74 65 46 75 6e 63 74 69 6f 6e t<SQLiteFunction
0b10: 3e 20 5f 66 75 6e 63 74 69 6f 6e 73 3b 0d 0a 0d > _functions;...
0b20: 0a 23 69 66 20 49 4e 54 45 52 4f 50 5f 56 49 52 .#if INTEROP_VIR
0b30: 54 55 41 4c 5f 54 41 42 4c 45 0d 0a 20 20 20 20 TUAL_TABLE..
0b40: 2f 2f 2f 20 3c 73 75 6d 6d 61 72 79 3e 0d 0a 20 /// <summary>..
0b50: 20 20 20 2f 2f 2f 20 54 68 65 20 6d 6f 64 75 6c /// The modul
0b60: 65 73 20 63 72 65 61 74 65 64 20 75 73 69 6e 67 es created using
0b70: 20 74 68 69 73 20 63 6f 6e 6e 65 63 74 69 6f 6e this connection
0b80: 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 73 75 6d ... /// </sum
0b90: 6d 61 72 79 3e 0d 0a 20 20 20 20 70 72 6f 74 65 mary>.. prote
0ba0: 63 74 65 64 20 44 69 63 74 69 6f 6e 61 72 79 3c cted Dictionary<
0bb0: 73 74 72 69 6e 67 2c 20 53 51 4c 69 74 65 4d 6f string, SQLiteMo
0bc0: 64 75 6c 65 3e 20 5f 6d 6f 64 75 6c 65 73 3b 0d dule> _modules;.
0bd0: 0a 23 65 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 2f .#endif.... /
0be0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0bf0: 2f 2f 2f 2f 2f 2f 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 2f 2f 2f 2f ////////////////
0c20: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0c30: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0d 0a //////////////..
0c40: 0d 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 .. /// <summa
0c50: 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 43 6f 6e ry>.. /// Con
0c60: 73 74 72 75 63 74 73 20 74 68 65 20 6f 62 6a 65 structs the obje
0c70: 63 74 20 75 73 65 64 20 74 6f 20 69 6e 74 65 72 ct used to inter
0c80: 61 63 74 20 77 69 74 68 20 74 68 65 20 53 51 4c act with the SQL
0c90: 69 74 65 20 63 6f 72 65 20 6c 69 62 72 61 72 79 ite core library
0ca0: 0d 0a 20 20 20 20 2f 2f 2f 20 75 73 69 6e 67 20 .. /// using
0cb0: 74 68 65 20 55 54 46 2d 38 20 74 65 78 74 20 65 the UTF-8 text e
0cc0: 6e 63 6f 64 69 6e 67 2e 0d 0a 20 20 20 20 2f 2f ncoding... //
0cd0: 2f 20 3c 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 / </summary>..
0ce0: 20 20 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 6d /// <param nam
0cf0: 65 3d 22 66 6d 74 22 3e 0d 0a 20 20 20 20 2f 2f e="fmt">.. //
0d00: 2f 20 54 68 65 20 44 61 74 65 54 69 6d 65 20 66 / The DateTime f
0d10: 6f 72 6d 61 74 20 74 6f 20 62 65 20 75 73 65 64 ormat to be used
0d20: 20 77 68 65 6e 20 63 6f 6e 76 65 72 74 69 6e 67 when converting
0d30: 20 73 74 72 69 6e 67 20 76 61 6c 75 65 73 20 74 string values t
0d40: 6f 20 61 0d 0a 20 20 20 20 2f 2f 2f 20 44 61 74 o a.. /// Dat
0d50: 65 54 69 6d 65 20 61 6e 64 20 62 69 6e 64 69 6e eTime and bindin
0d60: 67 20 44 61 74 65 54 69 6d 65 20 70 61 72 61 6d g DateTime param
0d70: 65 74 65 72 73 2e 0d 0a 20 20 20 20 2f 2f 2f 20 eters... ///
0d80: 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f </param>.. //
0d90: 2f 20 3c 70 61 72 61 6d 20 6e 61 6d 65 3d 22 6b / <param name="k
0da0: 69 6e 64 22 3e 0d 0a 20 20 20 20 2f 2f 2f 20 54 ind">.. /// T
0db0: 68 65 20 3c 73 65 65 20 63 72 65 66 3d 22 44 61 he <see cref="Da
0dc0: 74 65 54 69 6d 65 4b 69 6e 64 22 20 2f 3e 20 74 teTimeKind" /> t
0dd0: 6f 20 62 65 20 75 73 65 64 20 77 68 65 6e 20 63 o be used when c
0de0: 72 65 61 74 69 6e 67 20 44 61 74 65 54 69 6d 65 reating DateTime
0df0: 0d 0a 20 20 20 20 2f 2f 2f 20 76 61 6c 75 65 73 .. /// values
0e00: 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 70 61 72 ... /// </par
0e10: 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 am>.. /// <pa
0e20: 72 61 6d 20 6e 61 6d 65 3d 22 66 6d 74 53 74 72 ram name="fmtStr
0e30: 69 6e 67 22 3e 0d 0a 20 20 20 20 2f 2f 2f 20 54 ing">.. /// T
0e40: 68 65 20 66 6f 72 6d 61 74 20 73 74 72 69 6e 67 he format string
0e50: 20 74 6f 20 62 65 20 75 73 65 64 20 77 68 65 6e to be used when
0e60: 20 70 61 72 73 69 6e 67 20 61 6e 64 20 66 6f 72 parsing and for
0e70: 6d 61 74 74 69 6e 67 20 44 61 74 65 54 69 6d 65 matting DateTime
0e80: 0d 0a 20 20 20 20 2f 2f 2f 20 76 61 6c 75 65 73 .. /// values
0e90: 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 70 61 72 ... /// </par
0ea0: 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 am>.. /// <pa
0eb0: 72 61 6d 20 6e 61 6d 65 3d 22 64 62 22 3e 0d 0a ram name="db">..
0ec0: 20 20 20 20 2f 2f 2f 20 54 68 65 20 6e 61 74 69 /// The nati
0ed0: 76 65 20 68 61 6e 64 6c 65 20 74 6f 20 62 65 20 ve handle to be
0ee0: 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 associated with
0ef0: 74 68 65 20 64 61 74 61 62 61 73 65 20 63 6f 6e the database con
0f00: 6e 65 63 74 69 6f 6e 2e 0d 0a 20 20 20 20 2f 2f nection... //
0f10: 2f 20 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 20 20 / </param>..
0f20: 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 6d 65 3d /// <param name=
0f30: 22 66 69 6c 65 4e 61 6d 65 22 3e 0d 0a 20 20 20 "fileName">..
0f40: 20 2f 2f 2f 20 54 68 65 20 66 75 6c 6c 79 20 71 /// The fully q
0f50: 75 61 6c 69 66 69 65 64 20 66 69 6c 65 20 6e 61 ualified file na
0f60: 6d 65 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 me associated wi
0f70: 74 68 20 3c 70 61 72 61 6d 72 65 66 20 6e 61 6d th <paramref nam
0f80: 65 3d 22 64 62 20 22 2f 3e 2e 0d 0a 20 20 20 20 e="db "/>...
0f90: 2f 2f 2f 20 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 /// </param>..
0fa0: 20 20 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 6d /// <param nam
0fb0: 65 3d 22 6f 77 6e 48 61 6e 64 6c 65 22 3e 0d 0a e="ownHandle">..
0fc0: 20 20 20 20 2f 2f 2f 20 4e 6f 6e 2d 7a 65 72 6f /// Non-zero
0fd0: 20 69 66 20 74 68 65 20 6e 65 77 6c 79 20 63 72 if the newly cr
0fe0: 65 61 74 65 64 20 6f 62 6a 65 63 74 20 69 6e 73 eated object ins
0ff0: 74 61 6e 63 65 20 77 69 6c 6c 20 6e 65 65 64 20 tance will need
1000: 74 6f 20 64 69 73 70 6f 73 65 0d 0a 20 20 20 20 to dispose..
1010: 2f 2f 2f 20 6f 66 20 3c 70 61 72 61 6d 72 65 66 /// of <paramref
1020: 20 6e 61 6d 65 3d 22 64 62 22 20 2f 3e 20 77 68 name="db" /> wh
1030: 65 6e 20 69 74 20 69 73 20 6e 6f 20 6c 6f 6e 67 en it is no long
1040: 65 72 20 6e 65 65 64 65 64 2e 0d 0a 20 20 20 20 er needed...
1050: 2f 2f 2f 20 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 /// </param>..
1060: 20 20 69 6e 74 65 72 6e 61 6c 20 53 51 4c 69 74 internal SQLit
1070: 65 33 28 0d 0a 20 20 20 20 20 20 20 20 53 51 4c e3(.. SQL
1080: 69 74 65 44 61 74 65 46 6f 72 6d 61 74 73 20 66 iteDateFormats f
1090: 6d 74 2c 0d 0a 20 20 20 20 20 20 20 20 44 61 74 mt,.. Dat
10a0: 65 54 69 6d 65 4b 69 6e 64 20 6b 69 6e 64 2c 0d eTimeKind kind,.
10b0: 0a 20 20 20 20 20 20 20 20 73 74 72 69 6e 67 20 . string
10c0: 66 6d 74 53 74 72 69 6e 67 2c 0d 0a 20 20 20 20 fmtString,..
10d0: 20 20 20 20 49 6e 74 50 74 72 20 64 62 2c 0d 0a IntPtr db,..
10e0: 20 20 20 20 20 20 20 20 73 74 72 69 6e 67 20 66 string f
10f0: 69 6c 65 4e 61 6d 65 2c 0d 0a 20 20 20 20 20 20 ileName,..
1100: 20 20 62 6f 6f 6c 20 6f 77 6e 48 61 6e 64 6c 65 bool ownHandle
1110: 0d 0a 20 20 20 20 20 20 20 20 29 0d 0a 20 20 20 .. )..
1120: 20 20 20 3a 20 62 61 73 65 28 66 6d 74 2c 20 6b : base(fmt, k
1130: 69 6e 64 2c 20 66 6d 74 53 74 72 69 6e 67 29 0d ind, fmtString).
1140: 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 . {..
1150: 69 66 20 28 64 62 20 21 3d 20 49 6e 74 50 74 72 if (db != IntPtr
1160: 2e 5a 65 72 6f 29 0d 0a 20 20 20 20 20 20 20 20 .Zero)..
1170: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 5f {.. _
1180: 73 71 6c 20 3d 20 6e 65 77 20 53 51 4c 69 74 65 sql = new SQLite
1190: 43 6f 6e 6e 65 63 74 69 6f 6e 48 61 6e 64 6c 65 ConnectionHandle
11a0: 28 64 62 2c 20 6f 77 6e 48 61 6e 64 6c 65 29 3b (db, ownHandle);
11b0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 5f 66 .. _f
11c0: 69 6c 65 4e 61 6d 65 20 3d 20 66 69 6c 65 4e 61 ileName = fileNa
11d0: 6d 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 me;....
11e0: 20 20 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 SQLiteConnect
11f0: 69 6f 6e 2e 4f 6e 43 68 61 6e 67 65 64 28 6e 75 ion.OnChanged(nu
1200: 6c 6c 2c 20 6e 65 77 20 43 6f 6e 6e 65 63 74 69 ll, new Connecti
1210: 6f 6e 45 76 65 6e 74 41 72 67 73 28 0d 0a 20 20 onEventArgs(..
1220: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 53 51 SQ
1230: 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 45 76 LiteConnectionEv
1240: 65 6e 74 54 79 70 65 2e 4e 65 77 43 72 69 74 69 entType.NewCriti
1250: 63 61 6c 48 61 6e 64 6c 65 2c 20 6e 75 6c 6c 2c calHandle, null,
1260: 20 6e 75 6c 6c 2c 0d 0a 20 20 20 20 20 20 20 20 null,..
1270: 20 20 20 20 20 20 20 20 6e 75 6c 6c 2c 20 6e 75 null, nu
1280: 6c 6c 2c 20 5f 73 71 6c 2c 20 66 69 6c 65 4e 61 ll, _sql, fileNa
1290: 6d 65 2c 20 6e 65 77 20 6f 62 6a 65 63 74 5b 5d me, new object[]
12a0: 20 7b 20 66 6d 74 2c 20 6b 69 6e 64 2c 0d 0a 20 { fmt, kind,..
12b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 66 f
12c0: 6d 74 53 74 72 69 6e 67 2c 20 64 62 2c 20 66 69 mtString, db, fi
12d0: 6c 65 4e 61 6d 65 2c 20 6f 77 6e 48 61 6e 64 6c leName, ownHandl
12e0: 65 20 7d 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 e }));..
12f0: 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 }.. }....
1300: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1310: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1320: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1330: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1340: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1350: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0d ///////////////.
1360: 0a 0d 0a 20 20 20 20 23 72 65 67 69 6f 6e 20 49 ... #region I
1370: 44 69 73 70 6f 73 61 62 6c 65 20 22 50 61 74 74 Disposable "Patt
1380: 65 72 6e 22 20 4d 65 6d 62 65 72 73 0d 0a 20 20 ern" Members..
1390: 20 20 70 72 69 76 61 74 65 20 62 6f 6f 6c 20 64 private bool d
13a0: 69 73 70 6f 73 65 64 3b 0d 0a 20 20 20 20 70 72 isposed;.. pr
13b0: 69 76 61 74 65 20 76 6f 69 64 20 43 68 65 63 6b ivate void Check
13c0: 44 69 73 70 6f 73 65 64 28 29 20 2f 2a 20 74 68 Disposed() /* th
13d0: 72 6f 77 20 2a 2f 0d 0a 20 20 20 20 7b 0d 0a 23 row */.. {..#
13e0: 69 66 20 54 48 52 4f 57 5f 4f 4e 5f 44 49 53 50 if THROW_ON_DISP
13f0: 4f 53 45 44 0d 0a 20 20 20 20 20 20 20 20 69 66 OSED.. if
1400: 20 28 64 69 73 70 6f 73 65 64 29 0d 0a 20 20 20 (disposed)..
1410: 20 20 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e throw n
1420: 65 77 20 4f 62 6a 65 63 74 44 69 73 70 6f 73 65 ew ObjectDispose
1430: 64 45 78 63 65 70 74 69 6f 6e 28 74 79 70 65 6f dException(typeo
1440: 66 28 53 51 4c 69 74 65 33 29 2e 4e 61 6d 65 29 f(SQLite3).Name)
1450: 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 7d ;..#endif.. }
1460: 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 2f 2f 2f 2f 2f .... ////////
1470: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1480: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1490: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
14a0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
14b0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
14c0: 2f 2f 2f 2f 2f 2f 2f 0d 0a 0d 0a 20 20 20 20 70 ///////.... p
14d0: 72 6f 74 65 63 74 65 64 20 6f 76 65 72 72 69 64 rotected overrid
14e0: 65 20 76 6f 69 64 20 44 69 73 70 6f 73 65 28 62 e void Dispose(b
14f0: 6f 6f 6c 20 64 69 73 70 6f 73 69 6e 67 29 0d 0a ool disposing)..
1500: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 74 {.. t
1510: 72 79 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 ry.. {..
1520: 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 21 if (!
1530: 64 69 73 70 6f 73 65 64 29 0d 0a 20 20 20 20 20 disposed)..
1540: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
1550: 20 20 20 20 20 20 20 20 20 20 2f 2f 69 66 20 28 //if (
1560: 64 69 73 70 6f 73 69 6e 67 29 0d 0a 20 20 20 20 disposing)..
1570: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 7b 0d //{.
1580: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
1590: 20 2f 2f 20 20 20 20 2f 2f 2f 2f 2f 2f 2f 2f 2f // /////////
15a0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
15b0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0d 0a 20 20 20 ///////////..
15c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 //
15d0: 20 20 20 2f 2f 20 64 69 73 70 6f 73 65 20 6d 61 // dispose ma
15e0: 6e 61 67 65 64 20 72 65 73 6f 75 72 63 65 73 20 naged resources
15f0: 68 65 72 65 2e 2e 2e 0d 0a 20 20 20 20 20 20 20 here.....
1600: 20 20 20 20 20 20 20 20 20 2f 2f 20 20 20 20 2f // /
1610: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1620: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1630: 2f 2f 2f 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ///..
1640: 20 20 20 20 20 2f 2f 7d 0d 0a 0d 0a 20 20 20 20 //}....
1650: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 2f 2f ////
1660: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1670: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1680: 2f 2f 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 //..
1690: 20 20 20 20 2f 2f 20 72 65 6c 65 61 73 65 20 75 // release u
16a0: 6e 6d 61 6e 61 67 65 64 20 72 65 73 6f 75 72 63 nmanaged resourc
16b0: 65 73 20 68 65 72 65 2e 2e 2e 0d 0a 20 20 20 20 es here.....
16c0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 2f 2f ////
16d0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
16e0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
16f0: 2f 2f 0d 0a 0d 0a 23 69 66 20 49 4e 54 45 52 4f //....#if INTERO
1700: 50 5f 56 49 52 54 55 41 4c 5f 54 41 42 4c 45 0d P_VIRTUAL_TABLE.
1710: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
1720: 20 44 69 73 70 6f 73 65 4d 6f 64 75 6c 65 73 28 DisposeModules(
1730: 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 0d 0a 20 20 );..#endif....
1740: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 43 6c Cl
1750: 6f 73 65 28 66 61 6c 73 65 29 3b 20 2f 2a 20 44 ose(false); /* D
1760: 69 73 70 6f 73 69 6e 67 2c 20 63 61 6e 6e 6f 74 isposing, cannot
1770: 20 74 68 72 6f 77 2e 20 2a 2f 0d 0a 20 20 20 20 throw. */..
1780: 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 }..
1790: 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 66 69 }.. fi
17a0: 6e 61 6c 6c 79 0d 0a 20 20 20 20 20 20 20 20 7b nally.. {
17b0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 62 61 .. ba
17c0: 73 65 2e 44 69 73 70 6f 73 65 28 64 69 73 70 6f se.Dispose(dispo
17d0: 73 69 6e 67 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 sing);....
17e0: 20 20 20 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 //..
17f0: 20 20 20 20 20 20 2f 2f 20 4e 4f 54 45 3a 20 45 // NOTE: E
1800: 76 65 72 79 74 68 69 6e 67 20 73 68 6f 75 6c 64 verything should
1810: 20 62 65 20 66 75 6c 6c 79 20 64 69 73 70 6f 73 be fully dispos
1820: 65 64 20 61 74 20 74 68 69 73 20 70 6f 69 6e 74 ed at this point
1830: 2e 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 2f ... /
1840: 2f 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 64 /.. d
1850: 69 73 70 6f 73 65 64 20 3d 20 74 72 75 65 3b 0d isposed = true;.
1860: 0a 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 . }..
1870: 7d 0d 0a 20 20 20 20 23 65 6e 64 72 65 67 69 6f }.. #endregio
1880: 6e 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 2f 2f 2f 2f n.... ///////
1890: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
18a0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
18b0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
18c0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
18d0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
18e0: 2f 2f 2f 2f 2f 2f 2f 2f 0d 0a 0d 0a 23 69 66 20 ////////....#if
18f0: 49 4e 54 45 52 4f 50 5f 56 49 52 54 55 41 4c 5f INTEROP_VIRTUAL_
1900: 54 41 42 4c 45 0d 0a 20 20 20 20 2f 2f 2f 20 3c TABLE.. /// <
1910: 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f summary>.. //
1920: 2f 20 54 68 69 73 20 6d 65 74 68 6f 64 20 61 74 / This method at
1930: 74 65 6d 70 74 73 20 74 6f 20 64 69 73 70 6f 73 tempts to dispos
1940: 65 20 6f 66 20 61 6c 6c 20 74 68 65 20 3c 73 65 e of all the <se
1950: 65 20 63 72 65 66 3d 22 53 51 4c 69 74 65 4d 6f e cref="SQLiteMo
1960: 64 75 6c 65 22 20 2f 3e 20 64 65 72 69 76 65 64 dule" /> derived
1970: 0d 0a 20 20 20 20 2f 2f 2f 20 6f 62 6a 65 63 74 .. /// object
1980: 20 69 6e 73 74 61 6e 63 65 73 20 63 75 72 72 65 instances curre
1990: 6e 74 6c 79 20 61 73 73 6f 63 69 61 74 65 64 20 ntly associated
19a0: 77 69 74 68 20 74 68 65 20 6e 61 74 69 76 65 20 with the native
19b0: 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 database connect
19c0: 69 6f 6e 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f ion... /// </
19d0: 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 70 72 summary>.. pr
19e0: 69 76 61 74 65 20 76 6f 69 64 20 44 69 73 70 6f ivate void Dispo
19f0: 73 65 4d 6f 64 75 6c 65 73 28 29 0d 0a 20 20 20 seModules()..
1a00: 20 7b 0d 0a 20 20 20 20 20 20 20 20 2f 2f 0d 0a {.. //..
1a10: 20 20 20 20 20 20 20 20 2f 2f 20 4e 4f 54 45 3a // NOTE:
1a20: 20 49 66 20 61 6e 79 20 6d 6f 64 75 6c 65 73 20 If any modules
1a30: 77 65 72 65 20 63 72 65 61 74 65 64 2c 20 61 74 were created, at
1a40: 74 65 6d 70 74 20 74 6f 20 64 69 73 70 6f 73 65 tempt to dispose
1a50: 20 6f 66 0d 0a 20 20 20 20 20 20 20 20 2f 2f 20 of.. //
1a60: 20 20 20 20 20 20 74 68 65 6d 20 6e 6f 77 2e 20 them now.
1a70: 20 54 68 69 73 20 63 6f 64 65 20 69 73 20 64 65 This code is de
1a80: 73 69 67 6e 65 64 20 74 6f 20 61 76 6f 69 64 20 signed to avoid
1a90: 74 68 72 6f 77 69 6e 67 0d 0a 20 20 20 20 20 20 throwing..
1aa0: 20 20 2f 2f 20 20 20 20 20 20 20 65 78 63 65 70 // excep
1ab0: 74 69 6f 6e 73 20 75 6e 6c 65 73 73 20 74 68 65 tions unless the
1ac0: 20 44 69 73 70 6f 73 65 20 6d 65 74 68 6f 64 20 Dispose method
1ad0: 6f 66 20 74 68 65 20 6d 6f 64 75 6c 65 0d 0a 20 of the module..
1ae0: 20 20 20 20 20 20 20 2f 2f 20 20 20 20 20 20 20 //
1af0: 69 74 73 65 6c 66 20 74 68 72 6f 77 73 20 61 6e itself throws an
1b00: 20 65 78 63 65 70 74 69 6f 6e 2e 0d 0a 20 20 20 exception...
1b10: 20 20 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 20 //..
1b20: 20 69 66 20 28 5f 6d 6f 64 75 6c 65 73 20 21 3d if (_modules !=
1b30: 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 null)..
1b40: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 66 {.. f
1b50: 6f 72 65 61 63 68 20 28 4b 65 79 56 61 6c 75 65 oreach (KeyValue
1b60: 50 61 69 72 3c 73 74 72 69 6e 67 2c 20 53 51 4c Pair<string, SQL
1b70: 69 74 65 4d 6f 64 75 6c 65 3e 20 70 61 69 72 20 iteModule> pair
1b80: 69 6e 20 5f 6d 6f 64 75 6c 65 73 29 0d 0a 20 20 in _modules)..
1b90: 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 {..
1ba0: 20 20 20 20 20 20 20 20 20 20 20 20 20 53 51 4c SQL
1bb0: 69 74 65 4d 6f 64 75 6c 65 20 6d 6f 64 75 6c 65 iteModule module
1bc0: 20 3d 20 70 61 69 72 2e 56 61 6c 75 65 3b 0d 0a = pair.Value;..
1bd0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
1be0: 20 20 69 66 20 28 6d 6f 64 75 6c 65 20 3d 3d 20 if (module ==
1bf0: 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 null)..
1c00: 20 20 20 20 20 20 20 20 20 20 20 63 6f 6e 74 69 conti
1c10: 6e 75 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 nue;....
1c20: 20 20 20 20 20 20 20 20 6d 6f 64 75 6c 65 2e 44 module.D
1c30: 69 73 70 6f 73 65 28 29 3b 0d 0a 20 20 20 20 20 ispose();..
1c40: 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 }....
1c50: 20 20 20 20 20 20 20 20 5f 6d 6f 64 75 6c 65 73 _modules
1c60: 2e 43 6c 65 61 72 28 29 3b 0d 0a 20 20 20 20 20 .Clear();..
1c70: 20 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a 23 65 6e }.. }..#en
1c80: 64 69 66 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 2f 2f dif.... /////
1c90: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1ca0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1cb0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1cc0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1cd0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1ce0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0d 0a 0d 0a 20 20 //////////....
1cf0: 20 20 2f 2f 20 49 74 20 69 73 6e 27 74 20 6e 65 // It isn't ne
1d00: 63 65 73 73 61 72 79 20 74 6f 20 63 6c 65 61 6e cessary to clean
1d10: 75 70 20 61 6e 79 20 66 75 6e 63 74 69 6f 6e 73 up any functions
1d20: 20 77 65 27 76 65 20 72 65 67 69 73 74 65 72 65 we've registere
1d30: 64 2e 20 20 49 66 20 74 68 65 20 63 6f 6e 6e 65 d. If the conne
1d40: 63 74 69 6f 6e 0d 0a 20 20 20 20 2f 2f 20 67 6f ction.. // go
1d50: 65 73 20 74 6f 20 74 68 65 20 70 6f 6f 6c 20 61 es to the pool a
1d60: 6e 64 20 69 73 20 72 65 73 75 72 72 65 63 74 65 nd is resurrecte
1d70: 64 20 6c 61 74 65 72 2c 20 72 65 2d 72 65 67 69 d later, re-regi
1d80: 73 74 65 72 65 64 20 66 75 6e 63 74 69 6f 6e 73 stered functions
1d90: 20 77 69 6c 6c 20 6f 76 65 72 77 72 69 74 65 20 will overwrite
1da0: 74 68 65 0d 0a 20 20 20 20 2f 2f 20 70 72 65 76 the.. // prev
1db0: 69 6f 75 73 20 66 75 6e 63 74 69 6f 6e 73 2e 20 ious functions.
1dc0: 20 54 68 65 20 53 51 4c 69 74 65 46 75 6e 63 74 The SQLiteFunct
1dd0: 69 6f 6e 43 6f 6f 6b 69 65 48 61 6e 64 6c 65 20 ionCookieHandle
1de0: 77 69 6c 6c 20 74 61 6b 65 20 63 61 72 65 20 6f will take care o
1df0: 66 20 66 72 65 65 69 6e 67 20 75 6e 6d 61 6e 61 f freeing unmana
1e00: 67 65 64 0d 0a 20 20 20 20 2f 2f 20 72 65 73 6f ged.. // reso
1e10: 75 72 63 65 73 20 62 65 6c 6f 6e 67 69 6e 67 20 urces belonging
1e20: 74 6f 20 74 68 65 20 70 72 65 76 69 6f 75 73 6c to the previousl
1e30: 79 2d 72 65 67 69 73 74 65 72 65 64 20 66 75 6e y-registered fun
1e40: 63 74 69 6f 6e 73 2e 0d 0a 20 20 20 20 69 6e 74 ctions... int
1e50: 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 76 ernal override v
1e60: 6f 69 64 20 43 6c 6f 73 65 28 62 6f 6f 6c 20 63 oid Close(bool c
1e70: 61 6e 54 68 72 6f 77 29 0d 0a 20 20 20 20 7b 0d anThrow).. {.
1e80: 0a 20 20 20 20 20 20 69 66 20 28 5f 73 71 6c 20 . if (_sql
1e90: 21 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 != null)..
1ea0: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 {.. if
1eb0: 28 21 5f 73 71 6c 2e 4f 77 6e 48 61 6e 64 6c 65 (!_sql.OwnHandle
1ec0: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 7b 0d 0a ).. {..
1ed0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 5f 73 _s
1ee0: 71 6c 20 3d 20 6e 75 6c 6c 3b 0d 0a 20 20 20 20 ql = null;..
1ef0: 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e return
1f00: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 7d 0d 0a ;.. }..
1f10: 0d 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 28 .. if (
1f20: 5f 75 73 65 50 6f 6f 6c 29 0d 0a 20 20 20 20 20 _usePool)..
1f30: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
1f40: 20 20 20 20 20 20 69 66 20 28 53 51 4c 69 74 65 if (SQLite
1f50: 42 61 73 65 2e 52 65 73 65 74 43 6f 6e 6e 65 63 Base.ResetConnec
1f60: 74 69 6f 6e 28 5f 73 71 6c 2c 20 5f 73 71 6c 2c tion(_sql, _sql,
1f70: 20 63 61 6e 54 68 72 6f 77 29 29 0d 0a 20 20 20 canThrow))..
1f80: 20 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 23 69 {..#i
1f90: 66 20 49 4e 54 45 52 4f 50 5f 56 49 52 54 55 41 f INTEROP_VIRTUA
1fa0: 4c 5f 54 41 42 4c 45 0d 0a 20 20 20 20 20 20 20 L_TABLE..
1fb0: 20 20 20 20 20 20 20 20 20 20 20 44 69 73 70 6f Dispo
1fc0: 73 65 4d 6f 64 75 6c 65 73 28 29 3b 0d 0a 23 65 seModules();..#e
1fd0: 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 20 20 20 20 ndif....
1fe0: 20 20 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 SQLite
1ff0: 43 6f 6e 6e 65 63 74 69 6f 6e 50 6f 6f 6c 2e 41 ConnectionPool.A
2000: 64 64 28 5f 66 69 6c 65 4e 61 6d 65 2c 20 5f 73 dd(_fileName, _s
2010: 71 6c 2c 20 5f 70 6f 6f 6c 56 65 72 73 69 6f 6e ql, _poolVersion
2020: 29 3b 0d 0a 0d 0a 23 69 66 20 21 4e 45 54 5f 43 );....#if !NET_C
2030: 4f 4d 50 41 43 54 5f 32 30 20 26 26 20 54 52 41 OMPACT_20 && TRA
2040: 43 45 5f 43 4f 4e 4e 45 43 54 49 4f 4e 0d 0a 20 CE_CONNECTION..
2050: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2060: 20 54 72 61 63 65 2e 57 72 69 74 65 4c 69 6e 65 Trace.WriteLine
2070: 28 53 74 72 69 6e 67 2e 46 6f 72 6d 61 74 28 22 (String.Format("
2080: 43 6c 6f 73 65 20 28 50 6f 6f 6c 29 20 53 75 63 Close (Pool) Suc
2090: 63 65 73 73 3a 20 7b 30 7d 22 2c 20 5f 73 71 6c cess: {0}", _sql
20a0: 29 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 ));..#endif..
20b0: 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 23 69 }..#i
20c0: 66 20 21 4e 45 54 5f 43 4f 4d 50 41 43 54 5f 32 f !NET_COMPACT_2
20d0: 30 20 26 26 20 54 52 41 43 45 5f 43 4f 4e 4e 45 0 && TRACE_CONNE
20e0: 43 54 49 4f 4e 0d 0a 20 20 20 20 20 20 20 20 20 CTION..
20f0: 20 20 20 20 20 65 6c 73 65 0d 0a 20 20 20 20 20 else..
2100: 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 {..
2110: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 54 72 Tr
2120: 61 63 65 2e 57 72 69 74 65 4c 69 6e 65 28 53 74 ace.WriteLine(St
2130: 72 69 6e 67 2e 46 6f 72 6d 61 74 28 22 43 6c 6f ring.Format("Clo
2140: 73 65 20 28 50 6f 6f 6c 29 20 46 61 69 6c 75 72 se (Pool) Failur
2150: 65 3a 20 7b 30 7d 22 2c 20 5f 73 71 6c 29 29 3b e: {0}", _sql));
2160: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
2170: 7d 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 20 }..#endif..
2180: 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 }..
2190: 20 20 65 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 else..
21a0: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 {..
21b0: 20 20 20 5f 73 71 6c 2e 44 69 73 70 6f 73 65 28 _sql.Dispose(
21c0: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 7d 0d );.. }.
21d0: 0a 20 20 20 20 20 20 20 20 20 20 5f 73 71 6c 20 . _sql
21e0: 3d 20 6e 75 6c 6c 3b 0d 0a 20 20 20 20 20 20 7d = null;.. }
21f0: 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 2f .. }.... /
2200: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
2210: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
2220: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
2230: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
2240: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
2250: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0d 0a //////////////..
2260: 0d 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 .. /// <summa
2270: 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 41 74 74 ry>.. /// Att
2280: 65 6d 70 74 73 20 74 6f 20 69 6e 74 65 72 72 75 empts to interru
2290: 70 74 20 74 68 65 20 71 75 65 72 79 20 63 75 72 pt the query cur
22a0: 72 65 6e 74 6c 79 20 65 78 65 63 75 74 69 6e 67 rently executing
22b0: 20 6f 6e 20 74 68 65 20 61 73 73 6f 63 69 61 74 on the associat
22c0: 65 64 0d 0a 20 20 20 20 2f 2f 2f 20 6e 61 74 69 ed.. /// nati
22d0: 76 65 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e ve database conn
22e0: 65 63 74 69 6f 6e 2e 0d 0a 20 20 20 20 2f 2f 2f ection... ///
22f0: 20 3c 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 </summary>..
2300: 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 internal overri
2310: 64 65 20 76 6f 69 64 20 43 61 6e 63 65 6c 28 29 de void Cancel()
2320: 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 55 .. {.. U
2330: 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
2340: 64 73 2e 73 71 6c 69 74 65 33 5f 69 6e 74 65 72 ds.sqlite3_inter
2350: 72 75 70 74 28 5f 73 71 6c 29 3b 0d 0a 20 20 20 rupt(_sql);..
2360: 20 7d 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 20 3c 73 }.... /// <s
2370: 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f ummary>.. ///
2380: 20 54 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 62 This function b
2390: 69 6e 64 73 20 61 20 75 73 65 72 2d 64 65 66 69 inds a user-defi
23a0: 6e 65 64 20 66 75 6e 63 74 69 6f 6e 20 74 6f 20 ned function to
23b0: 74 68 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e 0d the connection..
23c0: 0a 20 20 20 20 2f 2f 2f 20 3c 2f 73 75 6d 6d 61 . /// </summa
23d0: 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 ry>.. /// <pa
23e0: 72 61 6d 20 6e 61 6d 65 3d 22 66 75 6e 63 74 69 ram name="functi
23f0: 6f 6e 41 74 74 72 69 62 75 74 65 22 3e 0d 0a 20 onAttribute">..
2400: 20 20 20 2f 2f 2f 20 54 68 65 20 3c 73 65 65 20 /// The <see
2410: 63 72 65 66 3d 22 53 51 4c 69 74 65 46 75 6e 63 cref="SQLiteFunc
2420: 74 69 6f 6e 41 74 74 72 69 62 75 74 65 22 2f 3e tionAttribute"/>
2430: 20 6f 62 6a 65 63 74 20 69 6e 73 74 61 6e 63 65 object instance
2440: 20 63 6f 6e 74 61 69 6e 69 6e 67 0d 0a 20 20 20 containing..
2450: 20 2f 2f 2f 20 74 68 65 20 6d 65 74 61 64 61 74 /// the metadat
2460: 61 20 66 6f 72 20 74 68 65 20 66 75 6e 63 74 69 a for the functi
2470: 6f 6e 20 74 6f 20 62 65 20 62 6f 75 6e 64 2e 0d on to be bound..
2480: 0a 20 20 20 20 2f 2f 2f 20 3c 2f 70 61 72 61 6d . /// </param
2490: 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 72 61 >.. /// <para
24a0: 6d 20 6e 61 6d 65 3d 22 66 75 6e 63 74 69 6f 6e m name="function
24b0: 22 3e 0d 0a 20 20 20 20 2f 2f 2f 20 54 68 65 20 ">.. /// The
24c0: 3c 73 65 65 20 63 72 65 66 3d 22 53 51 4c 69 74 <see cref="SQLit
24d0: 65 46 75 6e 63 74 69 6f 6e 22 2f 3e 20 6f 62 6a eFunction"/> obj
24e0: 65 63 74 20 69 6e 73 74 61 6e 63 65 20 74 68 61 ect instance tha
24f0: 74 20 69 6d 70 6c 65 6d 65 6e 74 73 20 74 68 65 t implements the
2500: 0d 0a 20 20 20 20 2f 2f 2f 20 66 75 6e 63 74 69 .. /// functi
2510: 6f 6e 20 74 6f 20 62 65 20 62 6f 75 6e 64 2e 0d on to be bound..
2520: 0a 20 20 20 20 2f 2f 2f 20 3c 2f 70 61 72 61 6d . /// </param
2530: 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 72 61 >.. /// <para
2540: 6d 20 6e 61 6d 65 3d 22 66 6c 61 67 73 22 3e 0d m name="flags">.
2550: 0a 20 20 20 20 2f 2f 2f 20 54 68 65 20 66 6c 61 . /// The fla
2560: 67 73 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 gs associated wi
2570: 74 68 20 74 68 65 20 70 61 72 65 6e 74 20 63 6f th the parent co
2580: 6e 6e 65 63 74 69 6f 6e 20 6f 62 6a 65 63 74 2e nnection object.
2590: 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 70 61 72 61 .. /// </para
25a0: 6d 3e 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c m>.. internal
25b0: 20 6f 76 65 72 72 69 64 65 20 76 6f 69 64 20 42 override void B
25c0: 69 6e 64 46 75 6e 63 74 69 6f 6e 28 0d 0a 20 20 indFunction(..
25d0: 20 20 20 20 20 20 53 51 4c 69 74 65 46 75 6e 63 SQLiteFunc
25e0: 74 69 6f 6e 41 74 74 72 69 62 75 74 65 20 66 75 tionAttribute fu
25f0: 6e 63 74 69 6f 6e 41 74 74 72 69 62 75 74 65 2c nctionAttribute,
2600: 0d 0a 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 .. SQLite
2610: 46 75 6e 63 74 69 6f 6e 20 66 75 6e 63 74 69 6f Function functio
2620: 6e 2c 0d 0a 20 20 20 20 20 20 20 20 53 51 4c 69 n,.. SQLi
2630: 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 teConnectionFlag
2640: 73 20 66 6c 61 67 73 0d 0a 20 20 20 20 20 20 20 s flags..
2650: 20 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 ).. {..
2660: 20 20 20 53 51 4c 69 74 65 46 75 6e 63 74 69 6f SQLiteFunctio
2670: 6e 2e 42 69 6e 64 46 75 6e 63 74 69 6f 6e 28 74 n.BindFunction(t
2680: 68 69 73 2c 20 66 75 6e 63 74 69 6f 6e 41 74 74 his, functionAtt
2690: 72 69 62 75 74 65 2c 20 66 75 6e 63 74 69 6f 6e ribute, function
26a0: 2c 20 66 6c 61 67 73 29 3b 0d 0a 0d 0a 20 20 20 , flags);....
26b0: 20 20 20 20 20 69 66 20 28 5f 66 75 6e 63 74 69 if (_functi
26c0: 6f 6e 73 20 3d 3d 20 6e 75 6c 6c 29 0d 0a 20 20 ons == null)..
26d0: 20 20 20 20 20 20 20 20 20 20 5f 66 75 6e 63 74 _funct
26e0: 69 6f 6e 73 20 3d 20 6e 65 77 20 4c 69 73 74 3c ions = new List<
26f0: 53 51 4c 69 74 65 46 75 6e 63 74 69 6f 6e 3e 28 SQLiteFunction>(
2700: 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 5f 66 );.... _f
2710: 75 6e 63 74 69 6f 6e 73 2e 41 64 64 28 66 75 6e unctions.Add(fun
2720: 63 74 69 6f 6e 29 3b 0d 0a 20 20 20 20 7d 0d 0a ction);.. }..
2730: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
2740: 76 65 72 72 69 64 65 20 73 74 72 69 6e 67 20 56 verride string V
2750: 65 72 73 69 6f 6e 0d 0a 20 20 20 20 7b 0d 0a 20 ersion.. {..
2760: 20 20 20 20 20 67 65 74 0d 0a 20 20 20 20 20 20 get..
2770: 7b 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 {.. retur
2780: 6e 20 53 51 4c 69 74 65 56 65 72 73 69 6f 6e 3b n SQLiteVersion;
2790: 0d 0a 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 7d .. }.. }
27a0: 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c .... internal
27b0: 20 6f 76 65 72 72 69 64 65 20 69 6e 74 20 56 65 override int Ve
27c0: 72 73 69 6f 6e 4e 75 6d 62 65 72 0d 0a 20 20 20 rsionNumber..
27d0: 20 7b 0d 0a 20 20 20 20 20 20 67 65 74 0d 0a 20 {.. get..
27e0: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
27f0: 72 65 74 75 72 6e 20 53 51 4c 69 74 65 56 65 72 return SQLiteVer
2800: 73 69 6f 6e 4e 75 6d 62 65 72 3b 0d 0a 20 20 20 sionNumber;..
2810: 20 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 }.. }....
2820: 20 20 20 69 6e 74 65 72 6e 61 6c 20 73 74 61 74 internal stat
2830: 69 63 20 73 74 72 69 6e 67 20 44 65 66 69 6e 65 ic string Define
2840: 43 6f 6e 73 74 61 6e 74 73 0d 0a 20 20 20 20 7b Constants.. {
2850: 0d 0a 20 20 20 20 20 20 20 20 67 65 74 0d 0a 20 .. get..
2860: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
2870: 20 20 20 20 20 20 53 74 72 69 6e 67 42 75 69 6c StringBuil
2880: 64 65 72 20 72 65 73 75 6c 74 20 3d 20 6e 65 77 der result = new
2890: 20 53 74 72 69 6e 67 42 75 69 6c 64 65 72 28 29 StringBuilder()
28a0: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 49 ;.. I
28b0: 4c 69 73 74 3c 73 74 72 69 6e 67 3e 20 6c 69 73 List<string> lis
28c0: 74 20 3d 20 53 51 4c 69 74 65 44 65 66 69 6e 65 t = SQLiteDefine
28d0: 43 6f 6e 73 74 61 6e 74 73 2e 4f 70 74 69 6f 6e Constants.Option
28e0: 4c 69 73 74 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 List;....
28f0: 20 20 20 20 20 69 66 20 28 6c 69 73 74 20 21 3d if (list !=
2900: 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 null)..
2910: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 {..
2920: 20 20 20 20 20 20 20 66 6f 72 65 61 63 68 20 28 foreach (
2930: 73 74 72 69 6e 67 20 65 6c 65 6d 65 6e 74 20 69 string element i
2940: 6e 20 6c 69 73 74 29 0d 0a 20 20 20 20 20 20 20 n list)..
2950: 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 {..
2960: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2970: 69 66 20 28 65 6c 65 6d 65 6e 74 20 3d 3d 20 6e if (element == n
2980: 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 20 ull)..
2990: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 63 6f co
29a0: 6e 74 69 6e 75 65 3b 0d 0a 0d 0a 20 20 20 20 20 ntinue;....
29b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 i
29c0: 66 20 28 72 65 73 75 6c 74 2e 4c 65 6e 67 74 68 f (result.Length
29d0: 20 3e 20 30 29 0d 0a 20 20 20 20 20 20 20 20 20 > 0)..
29e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 72 r
29f0: 65 73 75 6c 74 2e 41 70 70 65 6e 64 28 27 20 27 esult.Append(' '
2a00: 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 );....
2a10: 20 20 20 20 20 20 20 20 20 20 72 65 73 75 6c 74 result
2a20: 2e 41 70 70 65 6e 64 28 65 6c 65 6d 65 6e 74 29 .Append(element)
2a30: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ;..
2a40: 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 20 20 }..
2a50: 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 }....
2a60: 20 20 20 72 65 74 75 72 6e 20 72 65 73 75 6c 74 return result
2a70: 2e 54 6f 53 74 72 69 6e 67 28 29 3b 0d 0a 20 20 .ToString();..
2a80: 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a }.. }..
2a90: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 73 .. internal s
2aa0: 74 61 74 69 63 20 73 74 72 69 6e 67 20 53 51 4c tatic string SQL
2ab0: 69 74 65 56 65 72 73 69 6f 6e 0d 0a 20 20 20 20 iteVersion..
2ac0: 7b 0d 0a 20 20 20 20 20 20 67 65 74 0d 0a 20 20 {.. get..
2ad0: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 72 {.. r
2ae0: 65 74 75 72 6e 20 55 54 46 38 54 6f 53 74 72 69 eturn UTF8ToStri
2af0: 6e 67 28 55 6e 73 61 66 65 4e 61 74 69 76 65 4d ng(UnsafeNativeM
2b00: 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 6c ethods.sqlite3_l
2b10: 69 62 76 65 72 73 69 6f 6e 28 29 2c 20 2d 31 29 ibversion(), -1)
2b20: 3b 0d 0a 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 ;.. }..
2b30: 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 }.... interna
2b40: 6c 20 73 74 61 74 69 63 20 69 6e 74 20 53 51 4c l static int SQL
2b50: 69 74 65 56 65 72 73 69 6f 6e 4e 75 6d 62 65 72 iteVersionNumber
2b60: 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 67 .. {.. g
2b70: 65 74 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 20 20 et.. {..
2b80: 20 20 20 20 20 72 65 74 75 72 6e 20 55 6e 73 61 return Unsa
2b90: 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
2ba0: 73 71 6c 69 74 65 33 5f 6c 69 62 76 65 72 73 69 sqlite3_libversi
2bb0: 6f 6e 5f 6e 75 6d 62 65 72 28 29 3b 0d 0a 20 20 on_number();..
2bc0: 20 20 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a }.. }....
2bd0: 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 73 74 61 internal sta
2be0: 74 69 63 20 73 74 72 69 6e 67 20 53 51 4c 69 74 tic string SQLit
2bf0: 65 53 6f 75 72 63 65 49 64 0d 0a 20 20 20 20 7b eSourceId.. {
2c00: 0d 0a 20 20 20 20 20 20 67 65 74 0d 0a 20 20 20 .. get..
2c10: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 72 65 {.. re
2c20: 74 75 72 6e 20 55 54 46 38 54 6f 53 74 72 69 6e turn UTF8ToStrin
2c30: 67 28 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 g(UnsafeNativeMe
2c40: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 73 6f thods.sqlite3_so
2c50: 75 72 63 65 69 64 28 29 2c 20 2d 31 29 3b 0d 0a urceid(), -1);..
2c60: 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a }.. }..
2c70: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 73 .. internal s
2c80: 74 61 74 69 63 20 73 74 72 69 6e 67 20 53 51 4c tatic string SQL
2c90: 69 74 65 43 6f 6d 70 69 6c 65 4f 70 74 69 6f 6e iteCompileOption
2ca0: 73 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 s.. {..
2cb0: 20 20 67 65 74 0d 0a 20 20 20 20 20 20 20 20 7b get.. {
2cc0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 53 74 .. St
2cd0: 72 69 6e 67 42 75 69 6c 64 65 72 20 72 65 73 75 ringBuilder resu
2ce0: 6c 74 20 3d 20 6e 65 77 20 53 74 72 69 6e 67 42 lt = new StringB
2cf0: 75 69 6c 64 65 72 28 29 3b 0d 0a 20 20 20 20 20 uilder();..
2d00: 20 20 20 20 20 20 20 69 6e 74 20 69 6e 64 65 78 int index
2d10: 20 3d 20 30 3b 0d 0a 20 20 20 20 20 20 20 20 20 = 0;..
2d20: 20 20 20 49 6e 74 50 74 72 20 7a 56 61 6c 75 65 IntPtr zValue
2d30: 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d = UnsafeNativeM
2d40: 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 ethods.sqlite3_c
2d50: 6f 6d 70 69 6c 65 6f 70 74 69 6f 6e 5f 67 65 74 ompileoption_get
2d60: 28 69 6e 64 65 78 2b 2b 29 3b 0d 0a 0d 0a 20 20 (index++);....
2d70: 20 20 20 20 20 20 20 20 20 20 77 68 69 6c 65 20 while
2d80: 28 7a 56 61 6c 75 65 20 21 3d 20 49 6e 74 50 74 (zValue != IntPt
2d90: 72 2e 5a 65 72 6f 29 0d 0a 20 20 20 20 20 20 20 r.Zero)..
2da0: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
2db0: 20 20 20 20 20 20 20 20 69 66 20 28 72 65 73 75 if (resu
2dc0: 6c 74 2e 4c 65 6e 67 74 68 20 3e 20 30 29 0d 0a lt.Length > 0)..
2dd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2de0: 20 20 20 20 72 65 73 75 6c 74 2e 41 70 70 65 6e result.Appen
2df0: 64 28 27 20 27 29 3b 0d 0a 0d 0a 20 20 20 20 20 d(' ');....
2e00: 20 20 20 20 20 20 20 20 20 20 20 72 65 73 75 6c resul
2e10: 74 2e 41 70 70 65 6e 64 28 55 54 46 38 54 6f 53 t.Append(UTF8ToS
2e20: 74 72 69 6e 67 28 7a 56 61 6c 75 65 2c 20 2d 31 tring(zValue, -1
2e30: 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ));..
2e40: 20 20 20 20 20 7a 56 61 6c 75 65 20 3d 20 55 6e zValue = Un
2e50: 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 safeNativeMethod
2e60: 73 2e 73 71 6c 69 74 65 33 5f 63 6f 6d 70 69 6c s.sqlite3_compil
2e70: 65 6f 70 74 69 6f 6e 5f 67 65 74 28 69 6e 64 65 eoption_get(inde
2e80: 78 2b 2b 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 x++);..
2e90: 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 }....
2ea0: 20 20 20 20 72 65 74 75 72 6e 20 72 65 73 75 6c return resul
2eb0: 74 2e 54 6f 53 74 72 69 6e 67 28 29 3b 0d 0a 20 t.ToString();..
2ec0: 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 7d 0d }.. }.
2ed0: 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 ... internal
2ee0: 73 74 61 74 69 63 20 73 74 72 69 6e 67 20 49 6e static string In
2ef0: 74 65 72 6f 70 56 65 72 73 69 6f 6e 0d 0a 20 20 teropVersion..
2f00: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 67 65 74 {.. get
2f10: 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 23 69 66 .. {..#if
2f20: 20 21 53 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 !SQLITE_STANDAR
2f30: 44 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 72 D.. r
2f40: 65 74 75 72 6e 20 55 54 46 38 54 6f 53 74 72 69 eturn UTF8ToStri
2f50: 6e 67 28 55 6e 73 61 66 65 4e 61 74 69 76 65 4d ng(UnsafeNativeM
2f60: 65 74 68 6f 64 73 2e 69 6e 74 65 72 6f 70 5f 6c ethods.interop_l
2f70: 69 62 76 65 72 73 69 6f 6e 28 29 2c 20 2d 31 29 ibversion(), -1)
2f80: 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 ;..#else..
2f90: 20 20 20 20 20 20 72 65 74 75 72 6e 20 6e 75 6c return nul
2fa0: 6c 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 l;..#endif..
2fb0: 20 20 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a }.. }....
2fc0: 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 73 74 61 internal sta
2fd0: 74 69 63 20 73 74 72 69 6e 67 20 49 6e 74 65 72 tic string Inter
2fe0: 6f 70 53 6f 75 72 63 65 49 64 0d 0a 20 20 20 20 opSourceId..
2ff0: 7b 0d 0a 20 20 20 20 20 20 20 20 67 65 74 0d 0a {.. get..
3000: 20 20 20 20 20 20 20 20 7b 0d 0a 23 69 66 20 21 {..#if !
3010: 53 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d SQLITE_STANDARD.
3020: 0a 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 . ret
3030: 75 72 6e 20 55 54 46 38 54 6f 53 74 72 69 6e 67 urn UTF8ToString
3040: 28 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 (UnsafeNativeMet
3050: 68 6f 64 73 2e 69 6e 74 65 72 6f 70 5f 73 6f 75 hods.interop_sou
3060: 72 63 65 69 64 28 29 2c 20 2d 31 29 3b 0d 0a 23 rceid(), -1);..#
3070: 65 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 20 20 else..
3080: 20 20 72 65 74 75 72 6e 20 6e 75 6c 6c 3b 0d 0a return null;..
3090: 23 65 6e 64 69 66 0d 0a 20 20 20 20 20 20 20 20 #endif..
30a0: 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 }.. }....
30b0: 69 6e 74 65 72 6e 61 6c 20 73 74 61 74 69 63 20 internal static
30c0: 73 74 72 69 6e 67 20 49 6e 74 65 72 6f 70 43 6f string InteropCo
30d0: 6d 70 69 6c 65 4f 70 74 69 6f 6e 73 0d 0a 20 20 mpileOptions..
30e0: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 67 65 74 {.. get
30f0: 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 23 69 66 .. {..#if
3100: 20 21 53 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 !SQLITE_STANDAR
3110: 44 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 53 D.. S
3120: 74 72 69 6e 67 42 75 69 6c 64 65 72 20 72 65 73 tringBuilder res
3130: 75 6c 74 20 3d 20 6e 65 77 20 53 74 72 69 6e 67 ult = new String
3140: 42 75 69 6c 64 65 72 28 29 3b 0d 0a 20 20 20 20 Builder();..
3150: 20 20 20 20 20 20 20 20 69 6e 74 20 69 6e 64 65 int inde
3160: 78 20 3d 20 30 3b 0d 0a 20 20 20 20 20 20 20 20 x = 0;..
3170: 20 20 20 20 49 6e 74 50 74 72 20 7a 56 61 6c 75 IntPtr zValu
3180: 65 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 e = UnsafeNative
3190: 4d 65 74 68 6f 64 73 2e 69 6e 74 65 72 6f 70 5f Methods.interop_
31a0: 63 6f 6d 70 69 6c 65 6f 70 74 69 6f 6e 5f 67 65 compileoption_ge
31b0: 74 28 69 6e 64 65 78 2b 2b 29 3b 0d 0a 0d 0a 20 t(index++);....
31c0: 20 20 20 20 20 20 20 20 20 20 20 77 68 69 6c 65 while
31d0: 20 28 7a 56 61 6c 75 65 20 21 3d 20 49 6e 74 50 (zValue != IntP
31e0: 74 72 2e 5a 65 72 6f 29 0d 0a 20 20 20 20 20 20 tr.Zero)..
31f0: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
3200: 20 20 20 20 20 20 20 20 20 69 66 20 28 72 65 73 if (res
3210: 75 6c 74 2e 4c 65 6e 67 74 68 20 3e 20 30 29 0d ult.Length > 0).
3220: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
3230: 20 20 20 20 20 72 65 73 75 6c 74 2e 41 70 70 65 result.Appe
3240: 6e 64 28 27 20 27 29 3b 0d 0a 0d 0a 20 20 20 20 nd(' ');....
3250: 20 20 20 20 20 20 20 20 20 20 20 20 72 65 73 75 resu
3260: 6c 74 2e 41 70 70 65 6e 64 28 55 54 46 38 54 6f lt.Append(UTF8To
3270: 53 74 72 69 6e 67 28 7a 56 61 6c 75 65 2c 20 2d String(zValue, -
3280: 31 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 1));..
3290: 20 20 20 20 20 20 7a 56 61 6c 75 65 20 3d 20 55 zValue = U
32a0: 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
32b0: 64 73 2e 69 6e 74 65 72 6f 70 5f 63 6f 6d 70 69 ds.interop_compi
32c0: 6c 65 6f 70 74 69 6f 6e 5f 67 65 74 28 69 6e 64 leoption_get(ind
32d0: 65 78 2b 2b 29 3b 0d 0a 20 20 20 20 20 20 20 20 ex++);..
32e0: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 }....
32f0: 20 20 20 20 20 72 65 74 75 72 6e 20 72 65 73 75 return resu
3300: 6c 74 2e 54 6f 53 74 72 69 6e 67 28 29 3b 0d 0a lt.ToString();..
3310: 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 20 #else..
3320: 20 20 20 72 65 74 75 72 6e 20 6e 75 6c 6c 3b 0d return null;.
3330: 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 20 20 20 .#endif..
3340: 20 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 }.. }....
3350: 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 internal overri
3360: 64 65 20 62 6f 6f 6c 20 41 75 74 6f 43 6f 6d 6d de bool AutoComm
3370: 69 74 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 it.. {..
3380: 20 67 65 74 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 get.. {..
3390: 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 49 73 return Is
33a0: 41 75 74 6f 63 6f 6d 6d 69 74 28 5f 73 71 6c 2c Autocommit(_sql,
33b0: 20 5f 73 71 6c 29 3b 0d 0a 20 20 20 20 20 20 7d _sql);.. }
33c0: 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 .. }.... i
33d0: 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 nternal override
33e0: 20 6c 6f 6e 67 20 4c 61 73 74 49 6e 73 65 72 74 long LastInsert
33f0: 52 6f 77 49 64 0d 0a 20 20 20 20 7b 0d 0a 20 20 RowId.. {..
3400: 20 20 20 20 67 65 74 0d 0a 20 20 20 20 20 20 7b get.. {
3410: 0d 0a 23 69 66 20 21 50 4c 41 54 46 4f 52 4d 5f ..#if !PLATFORM_
3420: 43 4f 4d 50 41 43 54 46 52 41 4d 45 57 4f 52 4b COMPACTFRAMEWORK
3430: 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e .. return
3440: 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 UnsafeNativeMet
3450: 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 6c 61 73 hods.sqlite3_las
3460: 74 5f 69 6e 73 65 72 74 5f 72 6f 77 69 64 28 5f t_insert_rowid(_
3470: 73 71 6c 29 3b 0d 0a 23 65 6c 69 66 20 21 53 51 sql);..#elif !SQ
3480: 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a 20 LITE_STANDARD..
3490: 20 20 20 20 20 20 20 6c 6f 6e 67 20 72 6f 77 49 long rowI
34a0: 64 20 3d 20 30 3b 0d 0a 20 20 20 20 20 20 20 20 d = 0;..
34b0: 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 UnsafeNativeMeth
34c0: 6f 64 73 2e 73 71 6c 69 74 65 33 5f 6c 61 73 74 ods.sqlite3_last
34d0: 5f 69 6e 73 65 72 74 5f 72 6f 77 69 64 5f 69 6e _insert_rowid_in
34e0: 74 65 72 6f 70 28 5f 73 71 6c 2c 20 72 65 66 20 terop(_sql, ref
34f0: 72 6f 77 49 64 29 3b 0d 0a 20 20 20 20 20 20 20 rowId);..
3500: 20 72 65 74 75 72 6e 20 72 6f 77 49 64 3b 0d 0a return rowId;..
3510: 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 74 #else.. t
3520: 68 72 6f 77 20 6e 65 77 20 4e 6f 74 49 6d 70 6c hrow new NotImpl
3530: 65 6d 65 6e 74 65 64 45 78 63 65 70 74 69 6f 6e ementedException
3540: 28 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 ();..#endif..
3550: 20 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 }.. }....
3560: 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 internal over
3570: 72 69 64 65 20 69 6e 74 20 43 68 61 6e 67 65 73 ride int Changes
3580: 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 67 .. {.. g
3590: 65 74 0d 0a 20 20 20 20 20 20 7b 0d 0a 23 69 66 et.. {..#if
35a0: 20 21 53 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 !SQLITE_STANDAR
35b0: 44 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 D.. retur
35c0: 6e 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 n UnsafeNativeMe
35d0: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 68 thods.sqlite3_ch
35e0: 61 6e 67 65 73 5f 69 6e 74 65 72 6f 70 28 5f 73 anges_interop(_s
35f0: 71 6c 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 ql);..#else..
3600: 20 20 20 20 20 72 65 74 75 72 6e 20 55 6e 73 61 return Unsa
3610: 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
3620: 73 71 6c 69 74 65 33 5f 63 68 61 6e 67 65 73 28 sqlite3_changes(
3630: 5f 73 71 6c 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a _sql);..#endif..
3640: 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a }.. }..
3650: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
3660: 76 65 72 72 69 64 65 20 6c 6f 6e 67 20 4d 65 6d verride long Mem
3670: 6f 72 79 55 73 65 64 0d 0a 20 20 20 20 7b 0d 0a oryUsed.. {..
3680: 20 20 20 20 20 20 20 20 67 65 74 0d 0a 20 20 20 get..
3690: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
36a0: 20 20 20 20 72 65 74 75 72 6e 20 53 74 61 74 69 return Stati
36b0: 63 4d 65 6d 6f 72 79 55 73 65 64 3b 0d 0a 20 20 cMemoryUsed;..
36c0: 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a }.. }..
36d0: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 73 .. internal s
36e0: 74 61 74 69 63 20 6c 6f 6e 67 20 53 74 61 74 69 tatic long Stati
36f0: 63 4d 65 6d 6f 72 79 55 73 65 64 0d 0a 20 20 20 cMemoryUsed..
3700: 20 7b 0d 0a 20 20 20 20 20 20 20 20 67 65 74 0d {.. get.
3710: 0a 20 20 20 20 20 20 20 20 7b 0d 0a 23 69 66 20 . {..#if
3720: 21 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 !PLATFORM_COMPAC
3730: 54 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 TFRAMEWORK..
3740: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 55 return U
3750: 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
3760: 64 73 2e 73 71 6c 69 74 65 33 5f 6d 65 6d 6f 72 ds.sqlite3_memor
3770: 79 5f 75 73 65 64 28 29 3b 0d 0a 23 65 6c 69 66 y_used();..#elif
3780: 20 21 53 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 !SQLITE_STANDAR
3790: 44 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 6c D.. l
37a0: 6f 6e 67 20 62 79 74 65 73 20 3d 20 30 3b 0d 0a ong bytes = 0;..
37b0: 20 20 20 20 20 20 20 20 20 20 20 20 55 6e 73 61 Unsa
37c0: 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
37d0: 73 71 6c 69 74 65 33 5f 6d 65 6d 6f 72 79 5f 75 sqlite3_memory_u
37e0: 73 65 64 5f 69 6e 74 65 72 6f 70 28 72 65 66 20 sed_interop(ref
37f0: 62 79 74 65 73 29 3b 0d 0a 20 20 20 20 20 20 20 bytes);..
3800: 20 20 20 20 20 72 65 74 75 72 6e 20 62 79 74 65 return byte
3810: 73 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 s;..#else..
3820: 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 77 throw new
3830: 20 4e 6f 74 49 6d 70 6c 65 6d 65 6e 74 65 64 45 NotImplementedE
3840: 78 63 65 70 74 69 6f 6e 28 29 3b 0d 0a 23 65 6e xception();..#en
3850: 64 69 66 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a dif.. }..
3860: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 }.... int
3870: 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 6c ernal override l
3880: 6f 6e 67 20 4d 65 6d 6f 72 79 48 69 67 68 77 61 ong MemoryHighwa
3890: 74 65 72 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 ter.. {..
38a0: 20 20 20 20 67 65 74 0d 0a 20 20 20 20 20 20 20 get..
38b0: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
38c0: 72 65 74 75 72 6e 20 53 74 61 74 69 63 4d 65 6d return StaticMem
38d0: 6f 72 79 48 69 67 68 77 61 74 65 72 3b 0d 0a 20 oryHighwater;..
38e0: 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 7d 0d }.. }.
38f0: 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 ... internal
3900: 73 74 61 74 69 63 20 6c 6f 6e 67 20 53 74 61 74 static long Stat
3910: 69 63 4d 65 6d 6f 72 79 48 69 67 68 77 61 74 65 icMemoryHighwate
3920: 72 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 r.. {..
3930: 20 20 67 65 74 0d 0a 20 20 20 20 20 20 20 20 7b get.. {
3940: 0d 0a 23 69 66 20 21 50 4c 41 54 46 4f 52 4d 5f ..#if !PLATFORM_
3950: 43 4f 4d 50 41 43 54 46 52 41 4d 45 57 4f 52 4b COMPACTFRAMEWORK
3960: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 72 65 .. re
3970: 74 75 72 6e 20 55 6e 73 61 66 65 4e 61 74 69 76 turn UnsafeNativ
3980: 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
3990: 5f 6d 65 6d 6f 72 79 5f 68 69 67 68 77 61 74 65 _memory_highwate
39a0: 72 28 30 29 3b 0d 0a 23 65 6c 69 66 20 21 53 51 r(0);..#elif !SQ
39b0: 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a 20 LITE_STANDARD..
39c0: 20 20 20 20 20 20 20 20 20 20 20 6c 6f 6e 67 20 long
39d0: 62 79 74 65 73 20 3d 20 30 3b 0d 0a 20 20 20 20 bytes = 0;..
39e0: 20 20 20 20 20 20 20 20 55 6e 73 61 66 65 4e 61 UnsafeNa
39f0: 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 tiveMethods.sqli
3a00: 74 65 33 5f 6d 65 6d 6f 72 79 5f 68 69 67 68 77 te3_memory_highw
3a10: 61 74 65 72 5f 69 6e 74 65 72 6f 70 28 30 2c 20 ater_interop(0,
3a20: 72 65 66 20 62 79 74 65 73 29 3b 0d 0a 20 20 20 ref bytes);..
3a30: 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 return
3a40: 62 79 74 65 73 3b 0d 0a 23 65 6c 73 65 0d 0a 20 bytes;..#else..
3a50: 20 20 20 20 20 20 20 20 20 20 20 74 68 72 6f 77 throw
3a60: 20 6e 65 77 20 4e 6f 74 49 6d 70 6c 65 6d 65 6e new NotImplemen
3a70: 74 65 64 45 78 63 65 70 74 69 6f 6e 28 29 3b 0d tedException();.
3a80: 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 20 20 20 .#endif..
3a90: 20 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 }.. }....
3aa0: 20 2f 2f 2f 20 3c 73 75 6d 6d 61 72 79 3e 0d 0a /// <summary>..
3ab0: 20 20 20 20 2f 2f 2f 20 52 65 74 75 72 6e 73 20 /// Returns
3ac0: 6e 6f 6e 2d 7a 65 72 6f 20 69 66 20 74 68 65 20 non-zero if the
3ad0: 75 6e 64 65 72 6c 79 69 6e 67 20 6e 61 74 69 76 underlying nativ
3ae0: 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 68 61 6e e connection han
3af0: 64 6c 65 20 69 73 20 6f 77 6e 65 64 0d 0a 20 20 dle is owned..
3b00: 20 20 2f 2f 2f 20 62 79 20 74 68 69 73 20 69 6e /// by this in
3b10: 73 74 61 6e 63 65 2e 0d 0a 20 20 20 20 2f 2f 2f stance... ///
3b20: 20 3c 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 </summary>..
3b30: 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 internal overri
3b40: 64 65 20 62 6f 6f 6c 20 4f 77 6e 48 61 6e 64 6c de bool OwnHandl
3b50: 65 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 e.. {..
3b60: 20 20 67 65 74 0d 0a 20 20 20 20 20 20 20 20 7b get.. {
3b70: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 69 66 .. if
3b80: 20 28 5f 73 71 6c 20 3d 3d 20 6e 75 6c 6c 29 0d (_sql == null).
3b90: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
3ba0: 20 74 68 72 6f 77 20 6e 65 77 20 53 51 4c 69 74 throw new SQLit
3bb0: 65 45 78 63 65 70 74 69 6f 6e 28 22 6e 6f 20 63 eException("no c
3bc0: 6f 6e 6e 65 63 74 69 6f 6e 20 68 61 6e 64 6c 65 onnection handle
3bd0: 20 61 76 61 69 6c 61 62 6c 65 22 29 3b 0d 0a 0d available");...
3be0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 . ret
3bf0: 75 72 6e 20 5f 73 71 6c 2e 4f 77 6e 48 61 6e 64 urn _sql.OwnHand
3c00: 6c 65 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a le;.. }..
3c10: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 }.... int
3c20: 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 53 ernal override S
3c30: 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 20 53 QLiteErrorCode S
3c40: 65 74 4d 65 6d 6f 72 79 53 74 61 74 75 73 28 62 etMemoryStatus(b
3c50: 6f 6f 6c 20 76 61 6c 75 65 29 0d 0a 20 20 20 20 ool value)..
3c60: 7b 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 {.. retur
3c70: 6e 20 53 74 61 74 69 63 53 65 74 4d 65 6d 6f 72 n StaticSetMemor
3c80: 79 53 74 61 74 75 73 28 76 61 6c 75 65 29 3b 0d yStatus(value);.
3c90: 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e . }.... in
3ca0: 74 65 72 6e 61 6c 20 73 74 61 74 69 63 20 53 51 ternal static SQ
3cb0: 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 20 53 74 LiteErrorCode St
3cc0: 61 74 69 63 53 65 74 4d 65 6d 6f 72 79 53 74 61 aticSetMemorySta
3cd0: 74 75 73 28 62 6f 6f 6c 20 76 61 6c 75 65 29 0d tus(bool value).
3ce0: 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 . {..
3cf0: 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 20 SQLiteErrorCode
3d00: 72 63 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 rc = UnsafeNativ
3d10: 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
3d20: 5f 63 6f 6e 66 69 67 5f 69 6e 74 28 0d 0a 20 20 _config_int(..
3d30: 20 20 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 SQLite
3d40: 43 6f 6e 66 69 67 4f 70 73 45 6e 75 6d 2e 53 51 ConfigOpsEnum.SQ
3d50: 4c 49 54 45 5f 43 4f 4e 46 49 47 5f 4d 45 4d 53 LITE_CONFIG_MEMS
3d60: 54 41 54 55 53 2c 20 76 61 6c 75 65 20 3f 20 31 TATUS, value ? 1
3d70: 20 3a 20 30 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 : 0);....
3d80: 20 20 72 65 74 75 72 6e 20 72 63 3b 0d 0a 20 20 return rc;..
3d90: 20 20 7d 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 20 3c }.... /// <
3da0: 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f summary>.. //
3db0: 2f 20 41 74 74 65 6d 70 74 73 20 74 6f 20 66 72 / Attempts to fr
3dc0: 65 65 20 61 73 20 6d 75 63 68 20 68 65 61 70 20 ee as much heap
3dd0: 6d 65 6d 6f 72 79 20 61 73 20 70 6f 73 73 69 62 memory as possib
3de0: 6c 65 20 66 6f 72 20 74 68 65 20 64 61 74 61 62 le for the datab
3df0: 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e 0d ase connection..
3e00: 0a 20 20 20 20 2f 2f 2f 20 3c 2f 73 75 6d 6d 61 . /// </summa
3e10: 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 72 65 ry>.. /// <re
3e20: 74 75 72 6e 73 3e 41 20 73 74 61 6e 64 61 72 64 turns>A standard
3e30: 20 53 51 4c 69 74 65 20 72 65 74 75 72 6e 20 63 SQLite return c
3e40: 6f 64 65 20 28 69 2e 65 2e 20 7a 65 72 6f 20 66 ode (i.e. zero f
3e50: 6f 72 20 73 75 63 63 65 73 73 20 61 6e 64 20 6e or success and n
3e60: 6f 6e 2d 7a 65 72 6f 20 66 6f 72 20 66 61 69 6c on-zero for fail
3e70: 75 72 65 29 2e 3c 2f 72 65 74 75 72 6e 73 3e 0d ure).</returns>.
3e80: 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 . internal ov
3e90: 65 72 72 69 64 65 20 53 51 4c 69 74 65 45 72 72 erride SQLiteErr
3ea0: 6f 72 43 6f 64 65 20 52 65 6c 65 61 73 65 4d 65 orCode ReleaseMe
3eb0: 6d 6f 72 79 28 29 0d 0a 20 20 20 20 7b 0d 0a 20 mory().. {..
3ec0: 20 20 20 20 20 20 20 53 51 4c 69 74 65 45 72 72 SQLiteErr
3ed0: 6f 72 43 6f 64 65 20 72 63 20 3d 20 55 6e 73 61 orCode rc = Unsa
3ee0: 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
3ef0: 73 71 6c 69 74 65 33 5f 64 62 5f 72 65 6c 65 61 sqlite3_db_relea
3f00: 73 65 5f 6d 65 6d 6f 72 79 28 5f 73 71 6c 29 3b se_memory(_sql);
3f10: 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e .. return
3f20: 20 72 63 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 rc;.. }....
3f30: 20 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 72 79 3e /// <summary>
3f40: 0d 0a 20 20 20 20 2f 2f 2f 20 41 74 74 65 6d 70 .. /// Attemp
3f50: 74 73 20 74 6f 20 66 72 65 65 20 4e 20 62 79 74 ts to free N byt
3f60: 65 73 20 6f 66 20 68 65 61 70 20 6d 65 6d 6f 72 es of heap memor
3f70: 79 20 62 79 20 64 65 61 6c 6c 6f 63 61 74 69 6e y by deallocatin
3f80: 67 20 6e 6f 6e 2d 65 73 73 65 6e 74 69 61 6c 20 g non-essential
3f90: 6d 65 6d 6f 72 79 0d 0a 20 20 20 20 2f 2f 2f 20 memory.. ///
3fa0: 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 68 65 6c 64 allocations held
3fb0: 20 62 79 20 74 68 65 20 64 61 74 61 62 61 73 65 by the database
3fc0: 20 6c 69 62 72 61 72 79 2e 20 4d 65 6d 6f 72 79 library. Memory
3fd0: 20 75 73 65 64 20 74 6f 20 63 61 63 68 65 20 64 used to cache d
3fe0: 61 74 61 62 61 73 65 20 70 61 67 65 73 0d 0a 20 atabase pages..
3ff0: 20 20 20 2f 2f 2f 20 74 6f 20 69 6d 70 72 6f 76 /// to improv
4000: 65 20 70 65 72 66 6f 72 6d 61 6e 63 65 20 69 73 e performance is
4010: 20 61 6e 20 65 78 61 6d 70 6c 65 20 6f 66 20 6e an example of n
4020: 6f 6e 2d 65 73 73 65 6e 74 69 61 6c 20 6d 65 6d on-essential mem
4030: 6f 72 79 2e 20 20 54 68 69 73 20 69 73 20 61 20 ory. This is a
4040: 6e 6f 2d 6f 70 0d 0a 20 20 20 20 2f 2f 2f 20 72 no-op.. /// r
4050: 65 74 75 72 6e 69 6e 67 20 7a 65 72 6f 20 69 66 eturning zero if
4060: 20 74 68 65 20 53 51 4c 69 74 65 20 63 6f 72 65 the SQLite core
4070: 20 6c 69 62 72 61 72 79 20 77 61 73 20 6e 6f 74 library was not
4080: 20 63 6f 6d 70 69 6c 65 64 20 77 69 74 68 20 74 compiled with t
4090: 68 65 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 0d he compile-time.
40a0: 0a 20 20 20 20 2f 2f 2f 20 6f 70 74 69 6f 6e 20 . /// option
40b0: 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 4d 45 SQLITE_ENABLE_ME
40c0: 4d 4f 52 59 5f 4d 41 4e 41 47 45 4d 45 4e 54 2e MORY_MANAGEMENT.
40d0: 20 20 4f 70 74 69 6f 6e 61 6c 6c 79 2c 20 61 74 Optionally, at
40e0: 74 65 6d 70 74 73 20 74 6f 20 72 65 73 65 74 20 tempts to reset
40f0: 61 6e 64 2f 6f 72 0d 0a 20 20 20 20 2f 2f 2f 20 and/or.. ///
4100: 63 6f 6d 70 61 63 74 20 74 68 65 20 57 69 6e 33 compact the Win3
4110: 32 20 6e 61 74 69 76 65 20 68 65 61 70 2c 20 69 2 native heap, i
4120: 66 20 61 70 70 6c 69 63 61 62 6c 65 2e 0d 0a 20 f applicable...
4130: 20 20 20 2f 2f 2f 20 3c 2f 73 75 6d 6d 61 72 79 /// </summary
4140: 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 72 61 >.. /// <para
4150: 6d 20 6e 61 6d 65 3d 22 6e 42 79 74 65 73 22 3e m name="nBytes">
4160: 0d 0a 20 20 20 20 2f 2f 2f 20 54 68 65 20 72 65 .. /// The re
4170: 71 75 65 73 74 65 64 20 6e 75 6d 62 65 72 20 6f quested number o
4180: 66 20 62 79 74 65 73 20 74 6f 20 66 72 65 65 2e f bytes to free.
4190: 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 70 61 72 61 .. /// </para
41a0: 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 72 m>.. /// <par
41b0: 61 6d 20 6e 61 6d 65 3d 22 72 65 73 65 74 22 3e am name="reset">
41c0: 0d 0a 20 20 20 20 2f 2f 2f 20 4e 6f 6e 2d 7a 65 .. /// Non-ze
41d0: 72 6f 20 74 6f 20 61 74 74 65 6d 70 74 20 61 20 ro to attempt a
41e0: 68 65 61 70 20 72 65 73 65 74 2e 0d 0a 20 20 20 heap reset...
41f0: 20 2f 2f 2f 20 3c 2f 70 61 72 61 6d 3e 0d 0a 20 /// </param>..
4200: 20 20 20 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 /// <param na
4210: 6d 65 3d 22 63 6f 6d 70 61 63 74 22 3e 0d 0a 20 me="compact">..
4220: 20 20 20 2f 2f 2f 20 4e 6f 6e 2d 7a 65 72 6f 20 /// Non-zero
4230: 74 6f 20 61 74 74 65 6d 70 74 20 68 65 61 70 20 to attempt heap
4240: 63 6f 6d 70 61 63 74 69 6f 6e 2e 0d 0a 20 20 20 compaction...
4250: 20 2f 2f 2f 20 3c 2f 70 61 72 61 6d 3e 0d 0a 20 /// </param>..
4260: 20 20 20 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 /// <param na
4270: 6d 65 3d 22 6e 46 72 65 65 22 3e 0d 0a 20 20 20 me="nFree">..
4280: 20 2f 2f 2f 20 54 68 65 20 6e 75 6d 62 65 72 20 /// The number
4290: 6f 66 20 62 79 74 65 73 20 61 63 74 75 61 6c 6c of bytes actuall
42a0: 79 20 66 72 65 65 64 2e 20 20 54 68 69 73 20 76 y freed. This v
42b0: 61 6c 75 65 20 6d 61 79 20 62 65 20 7a 65 72 6f alue may be zero
42c0: 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 70 61 72 ... /// </par
42d0: 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 am>.. /// <pa
42e0: 72 61 6d 20 6e 61 6d 65 3d 22 72 65 73 65 74 4f ram name="resetO
42f0: 6b 22 3e 0d 0a 20 20 20 20 2f 2f 2f 20 54 68 69 k">.. /// Thi
4300: 73 20 76 61 6c 75 65 20 77 69 6c 6c 20 62 65 20 s value will be
4310: 6e 6f 6e 2d 7a 65 72 6f 20 69 66 20 74 68 65 20 non-zero if the
4320: 68 65 61 70 20 72 65 73 65 74 20 77 61 73 20 73 heap reset was s
4330: 75 63 63 65 73 73 66 75 6c 2e 0d 0a 20 20 20 20 uccessful...
4340: 2f 2f 2f 20 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 /// </param>..
4350: 20 20 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 6d /// <param nam
4360: 65 3d 22 6e 4c 61 72 67 65 73 74 22 3e 0d 0a 20 e="nLargest">..
4370: 20 20 20 2f 2f 2f 20 54 68 65 20 73 69 7a 65 20 /// The size
4380: 6f 66 20 74 68 65 20 6c 61 72 67 65 73 74 20 63 of the largest c
4390: 6f 6d 6d 69 74 74 65 64 20 66 72 65 65 20 62 6c ommitted free bl
43a0: 6f 63 6b 20 69 6e 20 74 68 65 20 68 65 61 70 2c ock in the heap,
43b0: 20 69 6e 20 62 79 74 65 73 2e 0d 0a 20 20 20 20 in bytes...
43c0: 2f 2f 2f 20 54 68 69 73 20 76 61 6c 75 65 20 77 /// This value w
43d0: 69 6c 6c 20 62 65 20 7a 65 72 6f 20 75 6e 6c 65 ill be zero unle
43e0: 73 73 20 68 65 61 70 20 63 6f 6d 70 61 63 74 69 ss heap compacti
43f0: 6f 6e 20 69 73 20 65 6e 61 62 6c 65 64 2e 0d 0a on is enabled...
4400: 20 20 20 20 2f 2f 2f 20 3c 2f 70 61 72 61 6d 3e /// </param>
4410: 0d 0a 20 20 20 20 2f 2f 2f 20 3c 72 65 74 75 72 .. /// <retur
4420: 6e 73 3e 0d 0a 20 20 20 20 2f 2f 2f 20 41 20 73 ns>.. /// A s
4430: 74 61 6e 64 61 72 64 20 53 51 4c 69 74 65 20 72 tandard SQLite r
4440: 65 74 75 72 6e 20 63 6f 64 65 20 28 69 2e 65 2e eturn code (i.e.
4450: 20 7a 65 72 6f 20 66 6f 72 20 73 75 63 63 65 73 zero for succes
4460: 73 20 61 6e 64 20 6e 6f 6e 2d 7a 65 72 6f 0d 0a s and non-zero..
4470: 20 20 20 20 2f 2f 2f 20 66 6f 72 20 66 61 69 6c /// for fail
4480: 75 72 65 29 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c ure)... /// <
4490: 2f 72 65 74 75 72 6e 73 3e 0d 0a 20 20 20 20 69 /returns>.. i
44a0: 6e 74 65 72 6e 61 6c 20 73 74 61 74 69 63 20 53 nternal static S
44b0: 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 20 53 QLiteErrorCode S
44c0: 74 61 74 69 63 52 65 6c 65 61 73 65 4d 65 6d 6f taticReleaseMemo
44d0: 72 79 28 0d 0a 20 20 20 20 20 20 20 20 69 6e 74 ry(.. int
44e0: 20 6e 42 79 74 65 73 2c 0d 0a 20 20 20 20 20 20 nBytes,..
44f0: 20 20 62 6f 6f 6c 20 72 65 73 65 74 2c 0d 0a 20 bool reset,..
4500: 20 20 20 20 20 20 20 62 6f 6f 6c 20 63 6f 6d 70 bool comp
4510: 61 63 74 2c 0d 0a 20 20 20 20 20 20 20 20 72 65 act,.. re
4520: 66 20 69 6e 74 20 6e 46 72 65 65 2c 0d 0a 20 20 f int nFree,..
4530: 20 20 20 20 20 20 72 65 66 20 62 6f 6f 6c 20 72 ref bool r
4540: 65 73 65 74 4f 6b 2c 0d 0a 20 20 20 20 20 20 20 esetOk,..
4550: 20 72 65 66 20 75 69 6e 74 20 6e 4c 61 72 67 65 ref uint nLarge
4560: 73 74 0d 0a 20 20 20 20 20 20 20 20 29 0d 0a 20 st.. )..
4570: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 53 51 {.. SQ
4580: 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 20 72 63 LiteErrorCode rc
4590: 20 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f = SQLiteErrorCo
45a0: 64 65 2e 4f 6b 3b 0d 0a 0d 0a 20 20 20 20 20 20 de.Ok;....
45b0: 20 20 69 6e 74 20 6e 46 72 65 65 4c 6f 63 61 6c int nFreeLocal
45c0: 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d = UnsafeNativeM
45d0: 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 72 ethods.sqlite3_r
45e0: 65 6c 65 61 73 65 5f 6d 65 6d 6f 72 79 28 6e 42 elease_memory(nB
45f0: 79 74 65 73 29 3b 0d 0a 20 20 20 20 20 20 20 20 ytes);..
4600: 75 69 6e 74 20 6e 4c 61 72 67 65 73 74 4c 6f 63 uint nLargestLoc
4610: 61 6c 20 3d 20 30 3b 0d 0a 20 20 20 20 20 20 20 al = 0;..
4620: 20 62 6f 6f 6c 20 72 65 73 65 74 4f 6b 4c 6f 63 bool resetOkLoc
4630: 61 6c 20 3d 20 66 61 6c 73 65 3b 0d 0a 0d 0a 23 al = false;....#
4640: 69 66 20 21 44 45 42 55 47 20 26 26 20 57 49 4e if !DEBUG && WIN
4650: 44 4f 57 53 20 2f 2f 20 4e 4f 54 45 3a 20 53 68 DOWS // NOTE: Sh
4660: 6f 75 6c 64 20 62 65 20 22 57 49 4e 33 32 48 45 ould be "WIN32HE
4670: 41 50 20 26 26 20 21 4d 45 4d 44 45 42 55 47 20 AP && !MEMDEBUG
4680: 26 26 20 57 49 4e 44 4f 57 53 22 0d 0a 20 20 20 && WINDOWS"..
4690: 20 20 20 20 20 69 66 20 28 28 72 63 20 3d 3d 20 if ((rc ==
46a0: 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 2e SQLiteErrorCode.
46b0: 4f 6b 29 20 26 26 20 72 65 73 65 74 29 0d 0a 20 Ok) && reset)..
46c0: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
46d0: 20 20 20 20 20 20 72 63 20 3d 20 55 6e 73 61 66 rc = Unsaf
46e0: 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
46f0: 71 6c 69 74 65 33 5f 77 69 6e 33 32 5f 72 65 73 qlite3_win32_res
4700: 65 74 5f 68 65 61 70 28 29 3b 0d 0a 0d 0a 20 20 et_heap();....
4710: 20 20 20 20 20 20 20 20 20 20 69 66 20 28 72 63 if (rc
4720: 20 3d 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 43 == SQLiteErrorC
4730: 6f 64 65 2e 4f 6b 29 0d 0a 20 20 20 20 20 20 20 ode.Ok)..
4740: 20 20 20 20 20 20 20 20 20 72 65 73 65 74 4f 6b resetOk
4750: 4c 6f 63 61 6c 20 3d 20 74 72 75 65 3b 0d 0a 20 Local = true;..
4760: 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 }....
4770: 20 20 20 20 69 66 20 28 28 72 63 20 3d 3d 20 53 if ((rc == S
4780: 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 2e 4f QLiteErrorCode.O
4790: 6b 29 20 26 26 20 63 6f 6d 70 61 63 74 29 0d 0a k) && compact)..
47a0: 20 20 20 20 20 20 20 20 20 20 20 20 72 63 20 3d rc =
47b0: 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 UnsafeNativeMet
47c0: 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 77 69 6e hods.sqlite3_win
47d0: 33 32 5f 63 6f 6d 70 61 63 74 5f 68 65 61 70 28 32_compact_heap(
47e0: 72 65 66 20 6e 4c 61 72 67 65 73 74 4c 6f 63 61 ref nLargestLoca
47f0: 6c 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 l);..#else..
4800: 20 20 20 20 69 66 20 28 72 65 73 65 74 20 7c 7c if (reset ||
4810: 20 63 6f 6d 70 61 63 74 29 0d 0a 20 20 20 20 20 compact)..
4820: 20 20 20 20 20 20 20 72 63 20 3d 20 53 51 4c 69 rc = SQLi
4830: 74 65 45 72 72 6f 72 43 6f 64 65 2e 4e 6f 74 46 teErrorCode.NotF
4840: 6f 75 6e 64 3b 0d 0a 23 65 6e 64 69 66 0d 0a 0d ound;..#endif...
4850: 0a 20 20 20 20 20 20 20 20 6e 46 72 65 65 20 3d . nFree =
4860: 20 6e 46 72 65 65 4c 6f 63 61 6c 3b 0d 0a 20 20 nFreeLocal;..
4870: 20 20 20 20 20 20 6e 4c 61 72 67 65 73 74 20 3d nLargest =
4880: 20 6e 4c 61 72 67 65 73 74 4c 6f 63 61 6c 3b 0d nLargestLocal;.
4890: 0a 20 20 20 20 20 20 20 20 72 65 73 65 74 4f 6b . resetOk
48a0: 20 3d 20 72 65 73 65 74 4f 6b 4c 6f 63 61 6c 3b = resetOkLocal;
48b0: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75 .... retu
48c0: 72 6e 20 72 63 3b 0d 0a 20 20 20 20 7d 0d 0a 0d rn rc;.. }...
48d0: 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 72 . /// <summar
48e0: 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 53 68 75 74 y>.. /// Shut
48f0: 64 6f 77 6e 20 74 68 65 20 53 51 4c 69 74 65 20 down the SQLite
4900: 65 6e 67 69 6e 65 20 73 6f 20 74 68 61 74 20 69 engine so that i
4910: 74 20 63 61 6e 20 62 65 20 72 65 73 74 61 72 74 t can be restart
4920: 65 64 20 77 69 74 68 20 64 69 66 66 65 72 65 6e ed with differen
4930: 74 0d 0a 20 20 20 20 2f 2f 2f 20 63 6f 6e 66 69 t.. /// confi
4940: 67 75 72 61 74 69 6f 6e 20 6f 70 74 69 6f 6e 73 guration options
4950: 2e 20 20 57 65 20 64 65 70 65 6e 64 20 6f 6e 20 . We depend on
4960: 61 75 74 6f 20 69 6e 69 74 69 61 6c 69 7a 61 74 auto initializat
4970: 69 6f 6e 20 74 6f 20 72 65 63 6f 76 65 72 2e 0d ion to recover..
4980: 0a 20 20 20 20 2f 2f 2f 20 3c 2f 73 75 6d 6d 61 . /// </summa
4990: 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 72 65 ry>.. /// <re
49a0: 74 75 72 6e 73 3e 52 65 74 75 72 6e 73 20 61 20 turns>Returns a
49b0: 73 74 61 6e 64 61 72 64 20 53 51 4c 69 74 65 20 standard SQLite
49c0: 72 65 73 75 6c 74 20 63 6f 64 65 2e 3c 2f 72 65 result code.</re
49d0: 74 75 72 6e 73 3e 0d 0a 20 20 20 20 69 6e 74 65 turns>.. inte
49e0: 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 53 51 rnal override SQ
49f0: 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 20 53 68 LiteErrorCode Sh
4a00: 75 74 64 6f 77 6e 28 29 0d 0a 20 20 20 20 7b 0d utdown().. {.
4a10: 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 . return
4a20: 53 74 61 74 69 63 53 68 75 74 64 6f 77 6e 28 66 StaticShutdown(f
4a30: 61 6c 73 65 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d alse);.. }...
4a40: 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 72 . /// <summar
4a50: 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 53 68 75 74 y>.. /// Shut
4a60: 64 6f 77 6e 20 74 68 65 20 53 51 4c 69 74 65 20 down the SQLite
4a70: 65 6e 67 69 6e 65 20 73 6f 20 74 68 61 74 20 69 engine so that i
4a80: 74 20 63 61 6e 20 62 65 20 72 65 73 74 61 72 74 t can be restart
4a90: 65 64 20 77 69 74 68 20 64 69 66 66 65 72 65 6e ed with differen
4aa0: 74 0d 0a 20 20 20 20 2f 2f 2f 20 63 6f 6e 66 69 t.. /// confi
4ab0: 67 75 72 61 74 69 6f 6e 20 6f 70 74 69 6f 6e 73 guration options
4ac0: 2e 20 20 57 65 20 64 65 70 65 6e 64 20 6f 6e 20 . We depend on
4ad0: 61 75 74 6f 20 69 6e 69 74 69 61 6c 69 7a 61 74 auto initializat
4ae0: 69 6f 6e 20 74 6f 20 72 65 63 6f 76 65 72 2e 0d ion to recover..
4af0: 0a 20 20 20 20 2f 2f 2f 20 3c 2f 73 75 6d 6d 61 . /// </summa
4b00: 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 ry>.. /// <pa
4b10: 72 61 6d 20 6e 61 6d 65 3d 22 64 69 72 65 63 74 ram name="direct
4b20: 6f 72 69 65 73 22 3e 0d 0a 20 20 20 20 2f 2f 2f ories">.. ///
4b30: 20 4e 6f 6e 2d 7a 65 72 6f 20 74 6f 20 72 65 73 Non-zero to res
4b40: 65 74 20 74 68 65 20 64 61 74 61 62 61 73 65 20 et the database
4b50: 61 6e 64 20 74 65 6d 70 6f 72 61 72 79 20 64 69 and temporary di
4b60: 72 65 63 74 6f 72 69 65 73 20 74 6f 20 74 68 65 rectories to the
4b70: 69 72 0d 0a 20 20 20 20 2f 2f 2f 20 64 65 66 61 ir.. /// defa
4b80: 75 6c 74 20 76 61 6c 75 65 73 2c 20 77 68 69 63 ult values, whic
4b90: 68 20 73 68 6f 75 6c 64 20 62 65 20 6e 75 6c 6c h should be null
4ba0: 20 66 6f 72 20 62 6f 74 68 2e 20 20 54 68 69 73 for both. This
4bb0: 20 70 61 72 61 6d 65 74 65 72 20 68 61 73 20 6e parameter has n
4bc0: 6f 0d 0a 20 20 20 20 2f 2f 2f 20 65 66 66 65 63 o.. /// effec
4bd0: 74 20 6f 6e 20 6e 6f 6e 2d 57 69 6e 64 6f 77 73 t on non-Windows
4be0: 20 6f 70 65 72 61 74 69 6e 67 20 73 79 73 74 65 operating syste
4bf0: 6d 73 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 70 ms... /// </p
4c00: 61 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c aram>.. /// <
4c10: 72 65 74 75 72 6e 73 3e 52 65 74 75 72 6e 73 20 returns>Returns
4c20: 61 20 73 74 61 6e 64 61 72 64 20 53 51 4c 69 74 a standard SQLit
4c30: 65 20 72 65 73 75 6c 74 20 63 6f 64 65 2e 3c 2f e result code.</
4c40: 72 65 74 75 72 6e 73 3e 0d 0a 20 20 20 20 69 6e returns>.. in
4c50: 74 65 72 6e 61 6c 20 73 74 61 74 69 63 20 53 51 ternal static SQ
4c60: 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 20 53 74 LiteErrorCode St
4c70: 61 74 69 63 53 68 75 74 64 6f 77 6e 28 0d 0a 20 aticShutdown(..
4c80: 20 20 20 20 20 20 20 62 6f 6f 6c 20 64 69 72 65 bool dire
4c90: 63 74 6f 72 69 65 73 0d 0a 20 20 20 20 20 20 20 ctories..
4ca0: 20 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 ).. {..
4cb0: 20 20 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f SQLiteErrorCo
4cc0: 64 65 20 72 63 20 3d 20 53 51 4c 69 74 65 45 72 de rc = SQLiteEr
4cd0: 72 6f 72 43 6f 64 65 2e 4f 6b 3b 0d 0a 0d 0a 20 rorCode.Ok;....
4ce0: 20 20 20 20 20 20 20 69 66 20 28 64 69 72 65 63 if (direc
4cf0: 74 6f 72 69 65 73 29 0d 0a 20 20 20 20 20 20 20 tories)..
4d00: 20 7b 0d 0a 23 69 66 20 57 49 4e 44 4f 57 53 0d {..#if WINDOWS.
4d10: 0a 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 . if
4d20: 28 72 63 20 3d 3d 20 53 51 4c 69 74 65 45 72 72 (rc == SQLiteErr
4d30: 6f 72 43 6f 64 65 2e 4f 6b 29 0d 0a 20 20 20 20 orCode.Ok)..
4d40: 20 20 20 20 20 20 20 20 20 20 20 20 72 63 20 3d rc =
4d50: 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 UnsafeNativeMet
4d60: 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 77 69 6e hods.sqlite3_win
4d70: 33 32 5f 73 65 74 5f 64 69 72 65 63 74 6f 72 79 32_set_directory
4d80: 28 31 2c 20 6e 75 6c 6c 29 3b 0d 0a 0d 0a 20 20 (1, null);....
4d90: 20 20 20 20 20 20 20 20 20 20 69 66 20 28 72 63 if (rc
4da0: 20 3d 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 43 == SQLiteErrorC
4db0: 6f 64 65 2e 4f 6b 29 0d 0a 20 20 20 20 20 20 20 ode.Ok)..
4dc0: 20 20 20 20 20 20 20 20 20 72 63 20 3d 20 55 6e rc = Un
4dd0: 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 safeNativeMethod
4de0: 73 2e 73 71 6c 69 74 65 33 5f 77 69 6e 33 32 5f s.sqlite3_win32_
4df0: 73 65 74 5f 64 69 72 65 63 74 6f 72 79 28 32 2c set_directory(2,
4e00: 20 6e 75 6c 6c 29 3b 0d 0a 23 65 6c 73 65 0d 0a null);..#else..
4e10: 23 69 66 20 21 4e 45 54 5f 43 4f 4d 50 41 43 54 #if !NET_COMPACT
4e20: 5f 32 30 20 26 26 20 54 52 41 43 45 5f 43 4f 4e _20 && TRACE_CON
4e30: 4e 45 43 54 49 4f 4e 0d 0a 20 20 20 20 20 20 20 NECTION..
4e40: 20 20 20 20 20 54 72 61 63 65 2e 57 72 69 74 65 Trace.Write
4e50: 4c 69 6e 65 28 0d 0a 20 20 20 20 20 20 20 20 20 Line(..
4e60: 20 20 20 20 20 20 20 22 53 68 75 74 64 6f 77 6e "Shutdown
4e70: 3a 20 43 61 6e 6e 6f 74 20 72 65 73 65 74 20 64 : Cannot reset d
4e80: 69 72 65 63 74 6f 72 69 65 73 20 6f 6e 20 74 68 irectories on th
4e90: 69 73 20 70 6c 61 74 66 6f 72 6d 2e 22 29 3b 0d is platform.");.
4ea0: 0a 23 65 6e 64 69 66 0d 0a 23 65 6e 64 69 66 0d .#endif..#endif.
4eb0: 0a 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 . }....
4ec0: 20 20 20 20 20 20 69 66 20 28 72 63 20 3d 3d 20 if (rc ==
4ed0: 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 2e SQLiteErrorCode.
4ee0: 4f 6b 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 Ok)..
4ef0: 20 72 63 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 rc = UnsafeNati
4f00: 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 veMethods.sqlite
4f10: 33 5f 73 68 75 74 64 6f 77 6e 28 29 3b 0d 0a 0d 3_shutdown();...
4f20: 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 . return
4f30: 72 63 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 rc;.. }....
4f40: 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 72 79 3e 0d /// <summary>.
4f50: 0a 20 20 20 20 2f 2f 2f 20 44 65 74 65 72 6d 69 . /// Determi
4f60: 6e 65 73 20 69 66 20 74 68 65 20 61 73 73 6f 63 nes if the assoc
4f70: 69 61 74 65 64 20 6e 61 74 69 76 65 20 63 6f 6e iated native con
4f80: 6e 65 63 74 69 6f 6e 20 68 61 6e 64 6c 65 20 69 nection handle i
4f90: 73 20 6f 70 65 6e 2e 0d 0a 20 20 20 20 2f 2f 2f s open... ///
4fa0: 20 3c 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 </summary>..
4fb0: 20 2f 2f 2f 20 3c 72 65 74 75 72 6e 73 3e 0d 0a /// <returns>..
4fc0: 20 20 20 20 2f 2f 2f 20 4e 6f 6e 2d 7a 65 72 6f /// Non-zero
4fd0: 20 69 66 20 74 68 65 20 61 73 73 6f 63 69 61 74 if the associat
4fe0: 65 64 20 6e 61 74 69 76 65 20 63 6f 6e 6e 65 63 ed native connec
4ff0: 74 69 6f 6e 20 68 61 6e 64 6c 65 20 69 73 20 6f tion handle is o
5000: 70 65 6e 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f pen... /// </
5010: 72 65 74 75 72 6e 73 3e 0d 0a 20 20 20 20 69 6e returns>.. in
5020: 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 ternal override
5030: 62 6f 6f 6c 20 49 73 4f 70 65 6e 28 29 0d 0a 20 bool IsOpen()..
5040: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 72 65 {.. re
5050: 74 75 72 6e 20 28 5f 73 71 6c 20 21 3d 20 6e 75 turn (_sql != nu
5060: 6c 6c 29 20 26 26 20 21 5f 73 71 6c 2e 49 73 49 ll) && !_sql.IsI
5070: 6e 76 61 6c 69 64 20 26 26 20 21 5f 73 71 6c 2e nvalid && !_sql.
5080: 49 73 43 6c 6f 73 65 64 3b 0d 0a 20 20 20 20 7d IsClosed;.. }
5090: 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c .... internal
50a0: 20 6f 76 65 72 72 69 64 65 20 76 6f 69 64 20 4f override void O
50b0: 70 65 6e 28 73 74 72 69 6e 67 20 73 74 72 46 69 pen(string strFi
50c0: 6c 65 6e 61 6d 65 2c 20 53 51 4c 69 74 65 43 6f lename, SQLiteCo
50d0: 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 20 63 6f nnectionFlags co
50e0: 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2c 20 53 nnectionFlags, S
50f0: 51 4c 69 74 65 4f 70 65 6e 46 6c 61 67 73 45 6e QLiteOpenFlagsEn
5100: 75 6d 20 6f 70 65 6e 46 6c 61 67 73 2c 20 69 6e um openFlags, in
5110: 74 20 6d 61 78 50 6f 6f 6c 53 69 7a 65 2c 20 62 t maxPoolSize, b
5120: 6f 6f 6c 20 75 73 65 50 6f 6f 6c 29 0d 0a 20 20 ool usePool)..
5130: 20 20 7b 0d 0a 20 20 20 20 20 20 2f 2f 0d 0a 20 {.. //..
5140: 20 20 20 20 20 2f 2f 20 4e 4f 54 45 3a 20 49 66 // NOTE: If
5150: 20 74 68 65 20 64 61 74 61 62 61 73 65 20 63 6f the database co
5160: 6e 6e 65 63 74 69 6f 6e 20 69 73 20 63 75 72 72 nnection is curr
5170: 65 6e 74 6c 79 20 6f 70 65 6e 2c 20 61 74 74 65 ently open, atte
5180: 6d 70 74 20 74 6f 0d 0a 20 20 20 20 20 20 2f 2f mpt to.. //
5190: 20 20 20 20 20 20 20 63 6c 6f 73 65 20 69 74 20 close it
51a0: 6e 6f 77 2e 20 20 54 68 69 73 20 6d 75 73 74 20 now. This must
51b0: 62 65 20 64 6f 6e 65 20 62 65 63 61 75 73 65 20 be done because
51c0: 74 68 65 20 66 69 6c 65 20 6e 61 6d 65 20 6f 72 the file name or
51d0: 0d 0a 20 20 20 20 20 20 2f 2f 20 20 20 20 20 20 .. //
51e0: 20 6f 74 68 65 72 20 70 61 72 61 6d 65 74 65 72 other parameter
51f0: 73 20 74 68 61 74 20 6d 61 79 20 69 6d 70 61 63 s that may impac
5200: 74 20 74 68 65 20 75 6e 64 65 72 6c 79 69 6e 67 t the underlying
5210: 20 64 61 74 61 62 61 73 65 0d 0a 20 20 20 20 20 database..
5220: 20 2f 2f 20 20 20 20 20 20 20 63 6f 6e 6e 65 63 // connec
5230: 74 69 6f 6e 20 6d 61 79 20 68 61 76 65 20 63 68 tion may have ch
5240: 61 6e 67 65 64 2e 0d 0a 20 20 20 20 20 20 2f 2f anged... //
5250: 0d 0a 20 20 20 20 20 20 69 66 20 28 5f 73 71 6c .. if (_sql
5260: 20 21 3d 20 6e 75 6c 6c 29 20 43 6c 6f 73 65 28 != null) Close(
5270: 74 72 75 65 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 true);....
5280: 2f 2f 0d 0a 20 20 20 20 20 20 2f 2f 20 4e 4f 54 //.. // NOT
5290: 45 3a 20 49 66 20 74 68 65 20 63 6f 6e 6e 65 63 E: If the connec
52a0: 74 69 6f 6e 20 77 61 73 20 6e 6f 74 20 63 6c 6f tion was not clo
52b0: 73 65 64 20 73 75 63 63 65 73 73 66 75 6c 6c 79 sed successfully
52c0: 2c 20 74 68 72 6f 77 20 61 6e 0d 0a 20 20 20 20 , throw an..
52d0: 20 20 2f 2f 20 20 20 20 20 20 20 65 78 63 65 70 // excep
52e0: 74 69 6f 6e 20 6e 6f 77 2e 0d 0a 20 20 20 20 20 tion now...
52f0: 20 2f 2f 0d 0a 20 20 20 20 20 20 69 66 20 28 5f //.. if (_
5300: 73 71 6c 20 21 3d 20 6e 75 6c 6c 29 0d 0a 20 20 sql != null)..
5310: 20 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 throw ne
5320: 77 20 53 51 4c 69 74 65 45 78 63 65 70 74 69 6f w SQLiteExceptio
5330: 6e 28 22 63 6f 6e 6e 65 63 74 69 6f 6e 20 68 61 n("connection ha
5340: 6e 64 6c 65 20 69 73 20 73 74 69 6c 6c 20 61 63 ndle is still ac
5350: 74 69 76 65 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 tive");....
5360: 20 5f 75 73 65 50 6f 6f 6c 20 3d 20 75 73 65 50 _usePool = useP
5370: 6f 6f 6c 3b 0d 0a 20 20 20 20 20 20 5f 66 69 6c ool;.. _fil
5380: 65 4e 61 6d 65 20 3d 20 73 74 72 46 69 6c 65 6e eName = strFilen
5390: 61 6d 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 69 66 ame;.... if
53a0: 20 28 75 73 65 50 6f 6f 6c 29 0d 0a 20 20 20 20 (usePool)..
53b0: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 5f 73 71 {.. _sq
53c0: 6c 20 3d 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 l = SQLiteConnec
53d0: 74 69 6f 6e 50 6f 6f 6c 2e 52 65 6d 6f 76 65 28 tionPool.Remove(
53e0: 73 74 72 46 69 6c 65 6e 61 6d 65 2c 20 6d 61 78 strFilename, max
53f0: 50 6f 6f 6c 53 69 7a 65 2c 20 6f 75 74 20 5f 70 PoolSize, out _p
5400: 6f 6f 6c 56 65 72 73 69 6f 6e 29 3b 0d 0a 0d 0a oolVersion);....
5410: 23 69 66 20 21 4e 45 54 5f 43 4f 4d 50 41 43 54 #if !NET_COMPACT
5420: 5f 32 30 20 26 26 20 54 52 41 43 45 5f 43 4f 4e _20 && TRACE_CON
5430: 4e 45 43 54 49 4f 4e 0d 0a 20 20 20 20 20 20 20 NECTION..
5440: 20 54 72 61 63 65 2e 57 72 69 74 65 4c 69 6e 65 Trace.WriteLine
5450: 28 53 74 72 69 6e 67 2e 46 6f 72 6d 61 74 28 22 (String.Format("
5460: 4f 70 65 6e 20 28 50 6f 6f 6c 29 3a 20 7b 30 7d Open (Pool): {0}
5470: 22 2c 20 28 5f 73 71 6c 20 21 3d 20 6e 75 6c 6c ", (_sql != null
5480: 29 20 3f 20 5f 73 71 6c 2e 54 6f 53 74 72 69 6e ) ? _sql.ToStrin
5490: 67 28 29 20 3a 20 22 3c 6e 75 6c 6c 3e 22 29 29 g() : "<null>"))
54a0: 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 20 ;..#endif..
54b0: 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 69 66 20 28 }.... if (
54c0: 5f 73 71 6c 20 3d 3d 20 6e 75 6c 6c 29 0d 0a 20 _sql == null)..
54d0: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
54e0: 74 72 79 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a try.. {..
54f0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 64 // d
5500: 6f 20 6e 6f 74 68 69 6e 67 2e 0d 0a 20 20 20 20 o nothing...
5510: 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 66 }.. f
5520: 69 6e 61 6c 6c 79 20 2f 2a 20 4e 4f 54 45 3a 20 inally /* NOTE:
5530: 54 68 72 65 61 64 2e 41 62 6f 72 74 28 29 20 70 Thread.Abort() p
5540: 72 6f 74 65 63 74 69 6f 6e 2e 20 2a 2f 0d 0a 20 rotection. */..
5550: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
5560: 20 20 20 20 49 6e 74 50 74 72 20 64 62 3b 0d 0a IntPtr db;..
5570: 20 20 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 SQLite
5580: 45 72 72 6f 72 43 6f 64 65 20 6e 3b 0d 0a 0d 0a ErrorCode n;....
5590: 23 69 66 20 21 53 51 4c 49 54 45 5f 53 54 41 4e #if !SQLITE_STAN
55a0: 44 41 52 44 0d 0a 20 20 20 20 20 20 20 20 20 20 DARD..
55b0: 69 66 20 28 28 63 6f 6e 6e 65 63 74 69 6f 6e 46 if ((connectionF
55c0: 6c 61 67 73 20 26 20 53 51 4c 69 74 65 43 6f 6e lags & SQLiteCon
55d0: 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2e 4e 6f 45 nectionFlags.NoE
55e0: 78 74 65 6e 73 69 6f 6e 46 75 6e 63 74 69 6f 6e xtensionFunction
55f0: 73 29 20 21 3d 20 53 51 4c 69 74 65 43 6f 6e 6e s) != SQLiteConn
5600: 65 63 74 69 6f 6e 46 6c 61 67 73 2e 4e 6f 45 78 ectionFlags.NoEx
5610: 74 65 6e 73 69 6f 6e 46 75 6e 63 74 69 6f 6e 73 tensionFunctions
5620: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 7b 0d 0a ).. {..
5630: 20 20 20 20 20 20 20 20 20 20 20 20 6e 20 3d 20 n =
5640: 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 UnsafeNativeMeth
5650: 6f 64 73 2e 73 71 6c 69 74 65 33 5f 6f 70 65 6e ods.sqlite3_open
5660: 5f 69 6e 74 65 72 6f 70 28 54 6f 55 54 46 38 28 _interop(ToUTF8(
5670: 73 74 72 46 69 6c 65 6e 61 6d 65 29 2c 20 6f 70 strFilename), op
5680: 65 6e 46 6c 61 67 73 2c 20 6f 75 74 20 64 62 29 enFlags, out db)
5690: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 7d 0d 0a ;.. }..
56a0: 20 20 20 20 20 20 20 20 20 20 65 6c 73 65 0d 0a else..
56b0: 23 65 6e 64 69 66 0d 0a 20 20 20 20 20 20 20 20 #endif..
56c0: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 {..
56d0: 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 n = UnsafeNativ
56e0: 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
56f0: 5f 6f 70 65 6e 5f 76 32 28 54 6f 55 54 46 38 28 _open_v2(ToUTF8(
5700: 73 74 72 46 69 6c 65 6e 61 6d 65 29 2c 20 6f 75 strFilename), ou
5710: 74 20 64 62 2c 20 6f 70 65 6e 46 6c 61 67 73 2c t db, openFlags,
5720: 20 49 6e 74 50 74 72 2e 5a 65 72 6f 29 3b 0d 0a IntPtr.Zero);..
5730: 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 23 }....#
5740: 69 66 20 21 4e 45 54 5f 43 4f 4d 50 41 43 54 5f if !NET_COMPACT_
5750: 32 30 20 26 26 20 54 52 41 43 45 5f 43 4f 4e 4e 20 && TRACE_CONN
5760: 45 43 54 49 4f 4e 0d 0a 20 20 20 20 20 20 20 20 ECTION..
5770: 20 20 54 72 61 63 65 2e 57 72 69 74 65 4c 69 6e Trace.WriteLin
5780: 65 28 53 74 72 69 6e 67 2e 46 6f 72 6d 61 74 28 e(String.Format(
5790: 22 4f 70 65 6e 3a 20 7b 30 7d 22 2c 20 64 62 29 "Open: {0}", db)
57a0: 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 0d 0a 20 20 );..#endif....
57b0: 20 20 20 20 20 20 20 20 69 66 20 28 6e 20 21 3d if (n !=
57c0: 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 SQLiteErrorCode
57d0: 2e 4f 6b 29 20 74 68 72 6f 77 20 6e 65 77 20 53 .Ok) throw new S
57e0: 51 4c 69 74 65 45 78 63 65 70 74 69 6f 6e 28 6e QLiteException(n
57f0: 2c 20 6e 75 6c 6c 29 3b 0d 0a 20 20 20 20 20 20 , null);..
5800: 20 20 20 20 5f 73 71 6c 20 3d 20 6e 65 77 20 53 _sql = new S
5810: 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 48 QLiteConnectionH
5820: 61 6e 64 6c 65 28 64 62 2c 20 74 72 75 65 29 3b andle(db, true);
5830: 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 .. }..
5840: 20 20 20 20 20 6c 6f 63 6b 20 28 5f 73 71 6c 29 lock (_sql)
5850: 20 7b 20 2f 2a 20 48 41 43 4b 3a 20 46 6f 72 63 { /* HACK: Forc
5860: 65 20 74 68 65 20 53 79 6e 63 42 6c 6f 63 6b 20 e the SyncBlock
5870: 74 6f 20 62 65 20 22 63 72 65 61 74 65 64 22 20 to be "created"
5880: 6e 6f 77 2e 20 2a 2f 20 7d 0d 0a 0d 0a 20 20 20 now. */ }....
5890: 20 20 20 20 20 53 51 4c 69 74 65 43 6f 6e 6e 65 SQLiteConne
58a0: 63 74 69 6f 6e 2e 4f 6e 43 68 61 6e 67 65 64 28 ction.OnChanged(
58b0: 6e 75 6c 6c 2c 20 6e 65 77 20 43 6f 6e 6e 65 63 null, new Connec
58c0: 74 69 6f 6e 45 76 65 6e 74 41 72 67 73 28 0d 0a tionEventArgs(..
58d0: 20 20 20 20 20 20 20 20 20 20 20 20 53 51 4c 69 SQLi
58e0: 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 45 76 65 6e teConnectionEven
58f0: 74 54 79 70 65 2e 4e 65 77 43 72 69 74 69 63 61 tType.NewCritica
5900: 6c 48 61 6e 64 6c 65 2c 20 6e 75 6c 6c 2c 20 6e lHandle, null, n
5910: 75 6c 6c 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 ull,..
5920: 20 20 6e 75 6c 6c 2c 20 6e 75 6c 6c 2c 20 5f 73 null, null, _s
5930: 71 6c 2c 20 73 74 72 46 69 6c 65 6e 61 6d 65 2c ql, strFilename,
5940: 20 6e 65 77 20 6f 62 6a 65 63 74 5b 5d 20 7b 20 new object[] {
5950: 73 74 72 46 69 6c 65 6e 61 6d 65 2c 0d 0a 20 20 strFilename,..
5960: 20 20 20 20 20 20 20 20 20 20 63 6f 6e 6e 65 63 connec
5970: 74 69 6f 6e 46 6c 61 67 73 2c 20 6f 70 65 6e 46 tionFlags, openF
5980: 6c 61 67 73 2c 20 6d 61 78 50 6f 6f 6c 53 69 7a lags, maxPoolSiz
5990: 65 2c 20 75 73 65 50 6f 6f 6c 20 7d 29 29 3b 0d e, usePool }));.
59a0: 0a 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 . }....
59b0: 20 20 2f 2f 20 42 69 6e 64 20 66 75 6e 63 74 69 // Bind functi
59c0: 6f 6e 73 20 74 6f 20 74 68 69 73 20 63 6f 6e 6e ons to this conn
59d0: 65 63 74 69 6f 6e 2e 20 20 49 66 20 61 6e 79 20 ection. If any
59e0: 70 72 65 76 69 6f 75 73 20 66 75 6e 63 74 69 6f previous functio
59f0: 6e 73 20 6f 66 20 74 68 65 20 73 61 6d 65 20 6e ns of the same n
5a00: 61 6d 65 0d 0a 20 20 20 20 20 20 2f 2f 20 77 65 ame.. // we
5a10: 72 65 20 61 6c 72 65 61 64 79 20 62 6f 75 6e 64 re already bound
5a20: 2c 20 74 68 65 6e 20 74 68 65 20 6e 65 77 20 62 , then the new b
5a30: 69 6e 64 69 6e 67 73 20 72 65 70 6c 61 63 65 20 indings replace
5a40: 74 68 65 20 6f 6c 64 2e 0d 0a 20 20 20 20 20 20 the old...
5a50: 69 66 20 28 28 63 6f 6e 6e 65 63 74 69 6f 6e 46 if ((connectionF
5a60: 6c 61 67 73 20 26 20 53 51 4c 69 74 65 43 6f 6e lags & SQLiteCon
5a70: 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2e 4e 6f 42 nectionFlags.NoB
5a80: 69 6e 64 46 75 6e 63 74 69 6f 6e 73 29 20 21 3d indFunctions) !=
5a90: 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f SQLiteConnectio
5aa0: 6e 46 6c 61 67 73 2e 4e 6f 42 69 6e 64 46 75 6e nFlags.NoBindFun
5ab0: 63 74 69 6f 6e 73 29 0d 0a 20 20 20 20 20 20 7b ctions).. {
5ac0: 0d 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 28 .. if (
5ad0: 5f 66 75 6e 63 74 69 6f 6e 73 20 3d 3d 20 6e 75 _functions == nu
5ae0: 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ll)..
5af0: 20 20 20 5f 66 75 6e 63 74 69 6f 6e 73 20 3d 20 _functions =
5b00: 6e 65 77 20 4c 69 73 74 3c 53 51 4c 69 74 65 46 new List<SQLiteF
5b10: 75 6e 63 74 69 6f 6e 3e 28 29 3b 0d 0a 0d 0a 20 unction>();....
5b20: 20 20 20 20 20 20 20 20 20 5f 66 75 6e 63 74 69 _functi
5b30: 6f 6e 73 2e 41 64 64 52 61 6e 67 65 28 6e 65 77 ons.AddRange(new
5b40: 20 4c 69 73 74 3c 53 51 4c 69 74 65 46 75 6e 63 List<SQLiteFunc
5b50: 74 69 6f 6e 3e 28 53 51 4c 69 74 65 46 75 6e 63 tion>(SQLiteFunc
5b60: 74 69 6f 6e 2e 42 69 6e 64 46 75 6e 63 74 69 6f tion.BindFunctio
5b70: 6e 73 28 74 68 69 73 2c 20 63 6f 6e 6e 65 63 74 ns(this, connect
5b80: 69 6f 6e 46 6c 61 67 73 29 29 29 3b 0d 0a 20 20 ionFlags)));..
5b90: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 53 }.... S
5ba0: 65 74 54 69 6d 65 6f 75 74 28 30 29 3b 0d 0a 20 etTimeout(0);..
5bb0: 20 20 20 20 20 47 43 2e 4b 65 65 70 41 6c 69 76 GC.KeepAliv
5bc0: 65 28 5f 73 71 6c 29 3b 0d 0a 20 20 20 20 7d 0d e(_sql);.. }.
5bd0: 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 ... internal
5be0: 6f 76 65 72 72 69 64 65 20 76 6f 69 64 20 43 6c override void Cl
5bf0: 65 61 72 50 6f 6f 6c 28 29 0d 0a 20 20 20 20 7b earPool().. {
5c00: 0d 0a 20 20 20 20 20 20 53 51 4c 69 74 65 43 6f .. SQLiteCo
5c10: 6e 6e 65 63 74 69 6f 6e 50 6f 6f 6c 2e 43 6c 65 nnectionPool.Cle
5c20: 61 72 50 6f 6f 6c 28 5f 66 69 6c 65 4e 61 6d 65 arPool(_fileName
5c30: 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 );.. }....
5c40: 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 internal overri
5c50: 64 65 20 69 6e 74 20 43 6f 75 6e 74 50 6f 6f 6c de int CountPool
5c60: 28 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 ().. {..
5c70: 20 20 20 44 69 63 74 69 6f 6e 61 72 79 3c 73 74 Dictionary<st
5c80: 72 69 6e 67 2c 20 69 6e 74 3e 20 63 6f 75 6e 74 ring, int> count
5c90: 73 20 3d 20 6e 75 6c 6c 3b 0d 0a 20 20 20 20 20 s = null;..
5ca0: 20 20 20 69 6e 74 20 6f 70 65 6e 43 6f 75 6e 74 int openCount
5cb0: 20 3d 20 30 3b 0d 0a 20 20 20 20 20 20 20 20 69 = 0;.. i
5cc0: 6e 74 20 63 6c 6f 73 65 43 6f 75 6e 74 20 3d 20 nt closeCount =
5cd0: 30 3b 0d 0a 20 20 20 20 20 20 20 20 69 6e 74 20 0;.. int
5ce0: 74 6f 74 61 6c 43 6f 75 6e 74 20 3d 20 30 3b 0d totalCount = 0;.
5cf0: 0a 0d 0a 20 20 20 20 20 20 20 20 53 51 4c 69 74 ... SQLit
5d00: 65 43 6f 6e 6e 65 63 74 69 6f 6e 50 6f 6f 6c 2e eConnectionPool.
5d10: 47 65 74 43 6f 75 6e 74 73 28 5f 66 69 6c 65 4e GetCounts(_fileN
5d20: 61 6d 65 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 ame,..
5d30: 20 20 72 65 66 20 63 6f 75 6e 74 73 2c 20 72 65 ref counts, re
5d40: 66 20 6f 70 65 6e 43 6f 75 6e 74 2c 20 72 65 66 f openCount, ref
5d50: 20 63 6c 6f 73 65 43 6f 75 6e 74 2c 0d 0a 20 20 closeCount,..
5d60: 20 20 20 20 20 20 20 20 20 20 72 65 66 20 74 6f ref to
5d70: 74 61 6c 43 6f 75 6e 74 29 3b 0d 0a 0d 0a 20 20 talCount);....
5d80: 20 20 20 20 20 20 72 65 74 75 72 6e 20 74 6f 74 return tot
5d90: 61 6c 43 6f 75 6e 74 3b 0d 0a 20 20 20 20 7d 0d alCount;.. }.
5da0: 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 ... internal
5db0: 6f 76 65 72 72 69 64 65 20 76 6f 69 64 20 53 65 override void Se
5dc0: 74 54 69 6d 65 6f 75 74 28 69 6e 74 20 6e 54 69 tTimeout(int nTi
5dd0: 6d 65 6f 75 74 4d 53 29 0d 0a 20 20 20 20 7b 0d meoutMS).. {.
5de0: 0a 20 20 20 20 20 20 49 6e 74 50 74 72 20 64 62 . IntPtr db
5df0: 20 3d 20 5f 73 71 6c 3b 0d 0a 20 20 20 20 20 20 = _sql;..
5e00: 69 66 20 28 64 62 20 3d 3d 20 49 6e 74 50 74 72 if (db == IntPtr
5e10: 2e 5a 65 72 6f 29 20 74 68 72 6f 77 20 6e 65 77 .Zero) throw new
5e20: 20 53 51 4c 69 74 65 45 78 63 65 70 74 69 6f 6e SQLiteException
5e30: 28 22 6e 6f 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 ("no connection
5e40: 68 61 6e 64 6c 65 20 61 76 61 69 6c 61 62 6c 65 handle available
5e50: 22 29 3b 0d 0a 20 20 20 20 20 20 53 51 4c 69 74 ");.. SQLit
5e60: 65 45 72 72 6f 72 43 6f 64 65 20 6e 20 3d 20 55 eErrorCode n = U
5e70: 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
5e80: 64 73 2e 73 71 6c 69 74 65 33 5f 62 75 73 79 5f ds.sqlite3_busy_
5e90: 74 69 6d 65 6f 75 74 28 64 62 2c 20 6e 54 69 6d timeout(db, nTim
5ea0: 65 6f 75 74 4d 53 29 3b 0d 0a 20 20 20 20 20 20 eoutMS);..
5eb0: 69 66 20 28 6e 20 21 3d 20 53 51 4c 69 74 65 45 if (n != SQLiteE
5ec0: 72 72 6f 72 43 6f 64 65 2e 4f 6b 29 20 74 68 72 rrorCode.Ok) thr
5ed0: 6f 77 20 6e 65 77 20 53 51 4c 69 74 65 45 78 63 ow new SQLiteExc
5ee0: 65 70 74 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 eption(n, GetLas
5ef0: 74 45 72 72 6f 72 28 29 29 3b 0d 0a 20 20 20 20 tError());..
5f00: 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 }.... interna
5f10: 6c 20 6f 76 65 72 72 69 64 65 20 62 6f 6f 6c 20 l override bool
5f20: 53 74 65 70 28 53 51 4c 69 74 65 53 74 61 74 65 Step(SQLiteState
5f30: 6d 65 6e 74 20 73 74 6d 74 29 0d 0a 20 20 20 20 ment stmt)..
5f40: 7b 0d 0a 20 20 20 20 20 20 53 51 4c 69 74 65 45 {.. SQLiteE
5f50: 72 72 6f 72 43 6f 64 65 20 6e 3b 0d 0a 20 20 20 rrorCode n;..
5f60: 20 20 20 52 61 6e 64 6f 6d 20 72 6e 64 20 3d 20 Random rnd =
5f70: 6e 75 6c 6c 3b 0d 0a 20 20 20 20 20 20 75 69 6e null;.. uin
5f80: 74 20 73 74 61 72 74 74 69 63 6b 20 3d 20 28 75 t starttick = (u
5f90: 69 6e 74 29 45 6e 76 69 72 6f 6e 6d 65 6e 74 2e int)Environment.
5fa0: 54 69 63 6b 43 6f 75 6e 74 3b 0d 0a 20 20 20 20 TickCount;..
5fb0: 20 20 75 69 6e 74 20 74 69 6d 65 6f 75 74 20 3d uint timeout =
5fc0: 20 28 75 69 6e 74 29 28 73 74 6d 74 2e 5f 63 6f (uint)(stmt._co
5fd0: 6d 6d 61 6e 64 2e 5f 63 6f 6d 6d 61 6e 64 54 69 mmand._commandTi
5fe0: 6d 65 6f 75 74 20 2a 20 31 30 30 30 29 3b 0d 0a meout * 1000);..
5ff0: 0d 0a 20 20 20 20 20 20 77 68 69 6c 65 20 28 74 .. while (t
6000: 72 75 65 29 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 rue).. {..
6010: 20 20 20 20 20 20 20 6e 20 3d 20 55 6e 73 61 66 n = Unsaf
6020: 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
6030: 71 6c 69 74 65 33 5f 73 74 65 70 28 73 74 6d 74 qlite3_step(stmt
6040: 2e 5f 73 71 6c 69 74 65 5f 73 74 6d 74 29 3b 0d ._sqlite_stmt);.
6050: 0a 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 6e ... if (n
6060: 20 3d 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 43 == SQLiteErrorC
6070: 6f 64 65 2e 52 6f 77 29 20 72 65 74 75 72 6e 20 ode.Row) return
6080: 74 72 75 65 3b 0d 0a 20 20 20 20 20 20 20 20 69 true;.. i
6090: 66 20 28 6e 20 3d 3d 20 53 51 4c 69 74 65 45 72 f (n == SQLiteEr
60a0: 72 6f 72 43 6f 64 65 2e 44 6f 6e 65 29 20 72 65 rorCode.Done) re
60b0: 74 75 72 6e 20 66 61 6c 73 65 3b 0d 0a 0d 0a 20 turn false;....
60c0: 20 20 20 20 20 20 20 69 66 20 28 6e 20 21 3d 20 if (n !=
60d0: 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 2e SQLiteErrorCode.
60e0: 4f 6b 29 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a Ok).. {..
60f0: 20 20 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 SQLite
6100: 45 72 72 6f 72 43 6f 64 65 20 72 3b 0d 0a 0d 0a ErrorCode r;....
6110: 20 20 20 20 20 20 20 20 20 20 2f 2f 20 41 6e 20 // An
6120: 65 72 72 6f 72 20 6f 63 63 75 72 72 65 64 2c 20 error occurred,
6130: 61 74 74 65 6d 70 74 20 74 6f 20 72 65 73 65 74 attempt to reset
6140: 20 74 68 65 20 73 74 61 74 65 6d 65 6e 74 2e 20 the statement.
6150: 20 49 66 20 74 68 65 20 72 65 73 65 74 20 77 6f If the reset wo
6160: 72 6b 65 64 20 62 65 63 61 75 73 65 20 74 68 65 rked because the
6170: 0d 0a 20 20 20 20 20 20 20 20 20 20 2f 2f 20 73 .. // s
6180: 63 68 65 6d 61 20 68 61 73 20 63 68 61 6e 67 65 chema has change
6190: 64 2c 20 72 65 2d 74 72 79 20 74 68 65 20 73 74 d, re-try the st
61a0: 65 70 20 61 67 61 69 6e 2e 20 20 49 66 20 69 74 ep again. If it
61b0: 20 65 72 72 6f 72 65 64 20 6f 75 72 20 62 65 63 errored our bec
61c0: 61 75 73 65 20 74 68 65 20 64 61 74 61 62 61 73 ause the databas
61d0: 65 0d 0a 20 20 20 20 20 20 20 20 20 20 2f 2f 20 e.. //
61e0: 69 73 20 6c 6f 63 6b 65 64 2c 20 74 68 65 6e 20 is locked, then
61f0: 6b 65 65 70 20 72 65 74 72 79 69 6e 67 20 75 6e keep retrying un
6200: 74 69 6c 20 74 68 65 20 63 6f 6d 6d 61 6e 64 20 til the command
6210: 74 69 6d 65 6f 75 74 20 6f 63 63 75 72 73 2e 0d timeout occurs..
6220: 0a 20 20 20 20 20 20 20 20 20 20 72 20 3d 20 52 . r = R
6230: 65 73 65 74 28 73 74 6d 74 29 3b 0d 0a 0d 0a 20 eset(stmt);....
6240: 20 20 20 20 20 20 20 20 20 69 66 20 28 72 20 3d if (r =
6250: 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 = SQLiteErrorCod
6260: 65 2e 4f 6b 29 0d 0a 20 20 20 20 20 20 20 20 20 e.Ok)..
6270: 20 20 20 74 68 72 6f 77 20 6e 65 77 20 53 51 4c throw new SQL
6280: 69 74 65 45 78 63 65 70 74 69 6f 6e 28 6e 2c 20 iteException(n,
6290: 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 29 3b GetLastError());
62a0: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 65 6c .... el
62b0: 73 65 20 69 66 20 28 28 72 20 3d 3d 20 53 51 4c se if ((r == SQL
62c0: 69 74 65 45 72 72 6f 72 43 6f 64 65 2e 4c 6f 63 iteErrorCode.Loc
62d0: 6b 65 64 20 7c 7c 20 72 20 3d 3d 20 53 51 4c 69 ked || r == SQLi
62e0: 74 65 45 72 72 6f 72 43 6f 64 65 2e 42 75 73 79 teErrorCode.Busy
62f0: 29 20 26 26 20 73 74 6d 74 2e 5f 63 6f 6d 6d 61 ) && stmt._comma
6300: 6e 64 20 21 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 nd != null)..
6310: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
6320: 20 20 20 20 20 20 2f 2f 20 4b 65 65 70 20 74 72 // Keep tr
6330: 79 69 6e 67 0d 0a 20 20 20 20 20 20 20 20 20 20 ying..
6340: 20 20 69 66 20 28 72 6e 64 20 3d 3d 20 6e 75 6c if (rnd == nul
6350: 6c 29 20 2f 2f 20 46 69 72 73 74 20 74 69 6d 65 l) // First time
6360: 20 77 65 27 76 65 20 65 6e 63 6f 75 6e 74 65 72 we've encounter
6370: 65 64 20 74 68 65 20 6c 6f 63 6b 0d 0a 20 20 20 ed the lock..
6380: 20 20 20 20 20 20 20 20 20 20 20 72 6e 64 20 3d rnd =
6390: 20 6e 65 77 20 52 61 6e 64 6f 6d 28 29 3b 0d 0a new Random();..
63a0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f .. //
63b0: 20 49 66 20 77 65 27 76 65 20 65 78 63 65 65 64 If we've exceed
63c0: 65 64 20 74 68 65 20 63 6f 6d 6d 61 6e 64 27 73 ed the command's
63d0: 20 74 69 6d 65 6f 75 74 2c 20 67 69 76 65 20 75 timeout, give u
63e0: 70 20 61 6e 64 20 74 68 72 6f 77 20 61 6e 20 65 p and throw an e
63f0: 72 72 6f 72 0d 0a 20 20 20 20 20 20 20 20 20 20 rror..
6400: 20 20 69 66 20 28 28 75 69 6e 74 29 45 6e 76 69 if ((uint)Envi
6410: 72 6f 6e 6d 65 6e 74 2e 54 69 63 6b 43 6f 75 6e ronment.TickCoun
6420: 74 20 2d 20 73 74 61 72 74 74 69 63 6b 20 3e 20 t - starttick >
6430: 74 69 6d 65 6f 75 74 29 0d 0a 20 20 20 20 20 20 timeout)..
6440: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
6450: 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 77 throw new
6460: 20 53 51 4c 69 74 65 45 78 63 65 70 74 69 6f 6e SQLiteException
6470: 28 72 2c 20 47 65 74 4c 61 73 74 45 72 72 6f 72 (r, GetLastError
6480: 28 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 ());..
6490: 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 20 20 20 }..
64a0: 20 65 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 20 else..
64b0: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 {..
64c0: 20 20 20 20 2f 2f 20 4f 74 68 65 72 77 69 73 65 // Otherwise
64d0: 20 73 6c 65 65 70 20 66 6f 72 20 61 20 72 61 6e sleep for a ran
64e0: 64 6f 6d 20 61 6d 6f 75 6e 74 20 6f 66 20 74 69 dom amount of ti
64f0: 6d 65 20 75 70 20 74 6f 20 31 35 30 6d 73 0d 0a me up to 150ms..
6500: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 53 79 Sy
6510: 73 74 65 6d 2e 54 68 72 65 61 64 69 6e 67 2e 54 stem.Threading.T
6520: 68 72 65 61 64 2e 53 6c 65 65 70 28 72 6e 64 2e hread.Sleep(rnd.
6530: 4e 65 78 74 28 31 2c 20 31 35 30 29 29 3b 0d 0a Next(1, 150));..
6540: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 }..
6550: 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 }..
6560: 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 7d 0d 0a }.. }..
6570: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 }.... int
6580: 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 53 ernal override S
6590: 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 20 52 QLiteErrorCode R
65a0: 65 73 65 74 28 53 51 4c 69 74 65 53 74 61 74 65 eset(SQLiteState
65b0: 6d 65 6e 74 20 73 74 6d 74 29 0d 0a 20 20 20 20 ment stmt)..
65c0: 7b 0d 0a 20 20 20 20 20 20 53 51 4c 69 74 65 45 {.. SQLiteE
65d0: 72 72 6f 72 43 6f 64 65 20 6e 3b 0d 0a 0d 0a 23 rrorCode n;....#
65e0: 69 66 20 21 53 51 4c 49 54 45 5f 53 54 41 4e 44 if !SQLITE_STAND
65f0: 41 52 44 0d 0a 20 20 20 20 20 20 6e 20 3d 20 55 ARD.. n = U
6600: 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
6610: 64 73 2e 73 71 6c 69 74 65 33 5f 72 65 73 65 74 ds.sqlite3_reset
6620: 5f 69 6e 74 65 72 6f 70 28 73 74 6d 74 2e 5f 73 _interop(stmt._s
6630: 71 6c 69 74 65 5f 73 74 6d 74 29 3b 0d 0a 23 65 qlite_stmt);..#e
6640: 6c 73 65 0d 0a 20 20 20 20 20 20 6e 20 3d 20 55 lse.. n = U
6650: 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
6660: 64 73 2e 73 71 6c 69 74 65 33 5f 72 65 73 65 74 ds.sqlite3_reset
6670: 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 (stmt._sqlite_st
6680: 6d 74 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 0d 0a mt);..#endif....
6690: 20 20 20 20 20 20 2f 2f 20 49 66 20 74 68 65 20 // If the
66a0: 73 63 68 65 6d 61 20 63 68 61 6e 67 65 64 2c 20 schema changed,
66b0: 74 72 79 20 61 6e 64 20 72 65 2d 70 72 65 70 61 try and re-prepa
66c0: 72 65 20 69 74 0d 0a 20 20 20 20 20 20 69 66 20 re it.. if
66d0: 28 6e 20 3d 3d 20 53 51 4c 69 74 65 45 72 72 6f (n == SQLiteErro
66e0: 72 43 6f 64 65 2e 53 63 68 65 6d 61 29 0d 0a 20 rCode.Schema)..
66f0: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
6700: 2f 2f 20 52 65 63 72 65 61 74 65 20 61 20 64 75 // Recreate a du
6710: 6d 6d 79 20 73 74 61 74 65 6d 65 6e 74 0d 0a 20 mmy statement..
6720: 20 20 20 20 20 20 20 73 74 72 69 6e 67 20 73 74 string st
6730: 72 3b 0d 0a 20 20 20 20 20 20 20 20 75 73 69 6e r;.. usin
6740: 67 20 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 g (SQLiteStateme
6750: 6e 74 20 74 6d 70 20 3d 20 50 72 65 70 61 72 65 nt tmp = Prepare
6760: 28 6e 75 6c 6c 2c 20 73 74 6d 74 2e 5f 73 71 6c (null, stmt._sql
6770: 53 74 61 74 65 6d 65 6e 74 2c 20 6e 75 6c 6c 2c Statement, null,
6780: 20 28 75 69 6e 74 29 28 73 74 6d 74 2e 5f 63 6f (uint)(stmt._co
6790: 6d 6d 61 6e 64 2e 5f 63 6f 6d 6d 61 6e 64 54 69 mmand._commandTi
67a0: 6d 65 6f 75 74 20 2a 20 31 30 30 30 29 2c 20 6f meout * 1000), o
67b0: 75 74 20 73 74 72 29 29 0d 0a 20 20 20 20 20 20 ut str))..
67c0: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 2f {.. /
67d0: 2f 20 46 69 6e 61 6c 69 7a 65 20 74 68 65 20 65 / Finalize the e
67e0: 78 69 73 74 69 6e 67 20 73 74 61 74 65 6d 65 6e xisting statemen
67f0: 74 0d 0a 20 20 20 20 20 20 20 20 20 20 73 74 6d t.. stm
6800: 74 2e 5f 73 71 6c 69 74 65 5f 73 74 6d 74 2e 44 t._sqlite_stmt.D
6810: 69 73 70 6f 73 65 28 29 3b 0d 0a 20 20 20 20 20 ispose();..
6820: 20 20 20 20 20 2f 2f 20 52 65 61 73 73 69 67 6e // Reassign
6830: 20 61 20 6e 65 77 20 73 74 61 74 65 6d 65 6e 74 a new statement
6840: 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 68 65 20 pointer to the
6850: 6f 6c 64 20 73 74 61 74 65 6d 65 6e 74 20 61 6e old statement an
6860: 64 20 63 6c 65 61 72 20 74 68 65 20 74 65 6d 70 d clear the temp
6870: 6f 72 61 72 79 20 6f 6e 65 0d 0a 20 20 20 20 20 orary one..
6880: 20 20 20 20 20 73 74 6d 74 2e 5f 73 71 6c 69 74 stmt._sqlit
6890: 65 5f 73 74 6d 74 20 3d 20 74 6d 70 2e 5f 73 71 e_stmt = tmp._sq
68a0: 6c 69 74 65 5f 73 74 6d 74 3b 0d 0a 20 20 20 20 lite_stmt;..
68b0: 20 20 20 20 20 20 74 6d 70 2e 5f 73 71 6c 69 74 tmp._sqlit
68c0: 65 5f 73 74 6d 74 20 3d 20 6e 75 6c 6c 3b 0d 0a e_stmt = null;..
68d0: 0d 0a 20 20 20 20 20 20 20 20 20 20 2f 2f 20 52 .. // R
68e0: 65 61 70 70 6c 79 20 70 61 72 61 6d 65 74 65 72 eapply parameter
68f0: 73 0d 0a 20 20 20 20 20 20 20 20 20 20 73 74 6d s.. stm
6900: 74 2e 42 69 6e 64 50 61 72 61 6d 65 74 65 72 73 t.BindParameters
6910: 28 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a ();.. }..
6920: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 53 return S
6930: 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 2e 55 QLiteErrorCode.U
6940: 6e 6b 6e 6f 77 6e 3b 20 2f 2f 20 52 65 73 65 74 nknown; // Reset
6950: 20 77 61 73 20 4f 4b 2c 20 77 69 74 68 20 73 63 was OK, with sc
6960: 68 65 6d 61 20 63 68 61 6e 67 65 0d 0a 20 20 20 hema change..
6970: 20 20 20 7d 0d 0a 20 20 20 20 20 20 65 6c 73 65 }.. else
6980: 20 69 66 20 28 6e 20 3d 3d 20 53 51 4c 69 74 65 if (n == SQLite
6990: 45 72 72 6f 72 43 6f 64 65 2e 4c 6f 63 6b 65 64 ErrorCode.Locked
69a0: 20 7c 7c 20 6e 20 3d 3d 20 53 51 4c 69 74 65 45 || n == SQLiteE
69b0: 72 72 6f 72 43 6f 64 65 2e 42 75 73 79 29 0d 0a rrorCode.Busy)..
69c0: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 6e return n
69d0: 3b 0d 0a 0d 0a 20 20 20 20 20 20 69 66 20 28 6e ;.... if (n
69e0: 20 21 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 43 != SQLiteErrorC
69f0: 6f 64 65 2e 4f 6b 29 0d 0a 20 20 20 20 20 20 20 ode.Ok)..
6a00: 20 74 68 72 6f 77 20 6e 65 77 20 53 51 4c 69 74 throw new SQLit
6a10: 65 45 78 63 65 70 74 69 6f 6e 28 6e 2c 20 47 65 eException(n, Ge
6a20: 74 4c 61 73 74 45 72 72 6f 72 28 29 29 3b 0d 0a tLastError());..
6a30: 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 6e .. return n
6a40: 3b 20 2f 2f 20 57 65 20 72 65 73 65 74 20 4f 4b ; // We reset OK
6a50: 2c 20 6e 6f 20 73 63 68 65 6d 61 20 63 68 61 6e , no schema chan
6a60: 67 65 73 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 ges.. }....
6a70: 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
6a80: 69 64 65 20 73 74 72 69 6e 67 20 47 65 74 4c 61 ide string GetLa
6a90: 73 74 45 72 72 6f 72 28 29 0d 0a 20 20 20 20 7b stError().. {
6aa0: 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e .. return
6ab0: 20 47 65 74 4c 61 73 74 45 72 72 6f 72 28 6e 75 GetLastError(nu
6ac0: 6c 6c 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 ll);.. }....
6ad0: 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 internal over
6ae0: 72 69 64 65 20 73 74 72 69 6e 67 20 47 65 74 4c ride string GetL
6af0: 61 73 74 45 72 72 6f 72 28 73 74 72 69 6e 67 20 astError(string
6b00: 64 65 66 56 61 6c 75 65 29 0d 0a 20 20 20 20 7b defValue).. {
6b10: 0d 0a 20 20 20 20 20 20 20 20 73 74 72 69 6e 67 .. string
6b20: 20 72 65 73 75 6c 74 20 3d 20 53 51 4c 69 74 65 result = SQLite
6b30: 42 61 73 65 2e 47 65 74 4c 61 73 74 45 72 72 6f Base.GetLastErro
6b40: 72 28 5f 73 71 6c 2c 20 5f 73 71 6c 29 3b 0d 0a r(_sql, _sql);..
6b50: 20 20 20 20 20 20 20 20 69 66 20 28 53 74 72 69 if (Stri
6b60: 6e 67 2e 49 73 4e 75 6c 6c 4f 72 45 6d 70 74 79 ng.IsNullOrEmpty
6b70: 28 72 65 73 75 6c 74 29 29 20 72 65 73 75 6c 74 (result)) result
6b80: 20 3d 20 64 65 66 56 61 6c 75 65 3b 0d 0a 20 20 = defValue;..
6b90: 20 20 20 20 20 20 72 65 74 75 72 6e 20 72 65 73 return res
6ba0: 75 6c 74 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 ult;.. }....
6bb0: 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 internal over
6bc0: 72 69 64 65 20 53 51 4c 69 74 65 53 74 61 74 65 ride SQLiteState
6bd0: 6d 65 6e 74 20 50 72 65 70 61 72 65 28 53 51 4c ment Prepare(SQL
6be0: 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 20 63 6e iteConnection cn
6bf0: 6e 2c 20 73 74 72 69 6e 67 20 73 74 72 53 71 6c n, string strSql
6c00: 2c 20 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e , SQLiteStatemen
6c10: 74 20 70 72 65 76 69 6f 75 73 2c 20 75 69 6e 74 t previous, uint
6c20: 20 74 69 6d 65 6f 75 74 4d 53 2c 20 6f 75 74 20 timeoutMS, out
6c30: 73 74 72 69 6e 67 20 73 74 72 52 65 6d 61 69 6e string strRemain
6c40: 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 ).. {..
6c50: 69 66 20 28 21 53 74 72 69 6e 67 2e 49 73 4e 75 if (!String.IsNu
6c60: 6c 6c 4f 72 45 6d 70 74 79 28 73 74 72 53 71 6c llOrEmpty(strSql
6c70: 29 29 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 20 20 )).. {..
6c80: 20 20 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 20 //..
6c90: 20 2f 2f 20 4e 4f 54 45 3a 20 53 51 4c 69 74 65 // NOTE: SQLite
6ca0: 20 64 6f 65 73 20 6e 6f 74 20 73 75 70 70 6f 72 does not suppor
6cb0: 74 20 74 68 65 20 63 6f 6e 63 65 70 74 20 6f 66 t the concept of
6cc0: 20 73 65 70 61 72 61 74 65 20 73 63 68 65 6d 61 separate schema
6cd0: 73 0d 0a 20 20 20 20 20 20 20 20 2f 2f 20 20 20 s.. //
6ce0: 20 20 20 20 69 6e 20 6f 6e 65 20 64 61 74 61 62 in one datab
6cf0: 61 73 65 3b 20 74 68 65 72 65 66 6f 72 65 2c 20 ase; therefore,
6d00: 72 65 6d 6f 76 65 20 74 68 65 20 62 61 73 65 20 remove the base
6d10: 73 63 68 65 6d 61 20 6e 61 6d 65 0d 0a 20 20 20 schema name..
6d20: 20 20 20 20 20 2f 2f 20 20 20 20 20 20 20 75 73 // us
6d30: 65 64 20 74 6f 20 73 6d 6f 6f 74 68 20 69 6e 74 ed to smooth int
6d40: 65 67 72 61 74 69 6f 6e 20 77 69 74 68 20 74 68 egration with th
6d50: 65 20 62 61 73 65 20 2e 4e 45 54 20 46 72 61 6d e base .NET Fram
6d60: 65 77 6f 72 6b 0d 0a 20 20 20 20 20 20 20 20 2f ework.. /
6d70: 2f 20 20 20 20 20 20 20 64 61 74 61 20 63 6c 61 / data cla
6d80: 73 73 65 73 2e 0d 0a 20 20 20 20 20 20 20 20 2f sses... /
6d90: 2f 0d 0a 20 20 20 20 20 20 20 20 73 74 72 69 6e /.. strin
6da0: 67 20 62 61 73 65 53 63 68 65 6d 61 4e 61 6d 65 g baseSchemaName
6db0: 20 3d 20 28 63 6e 6e 20 21 3d 20 6e 75 6c 6c 29 = (cnn != null)
6dc0: 20 3f 20 63 6e 6e 2e 5f 62 61 73 65 53 63 68 65 ? cnn._baseSche
6dd0: 6d 61 4e 61 6d 65 20 3a 20 6e 75 6c 6c 3b 0d 0a maName : null;..
6de0: 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 21 53 .. if (!S
6df0: 74 72 69 6e 67 2e 49 73 4e 75 6c 6c 4f 72 45 6d tring.IsNullOrEm
6e00: 70 74 79 28 62 61 73 65 53 63 68 65 6d 61 4e 61 pty(baseSchemaNa
6e10: 6d 65 29 29 0d 0a 20 20 20 20 20 20 20 20 7b 0d me)).. {.
6e20: 0a 20 20 20 20 20 20 20 20 20 20 73 74 72 53 71 . strSq
6e30: 6c 20 3d 20 73 74 72 53 71 6c 2e 52 65 70 6c 61 l = strSql.Repla
6e40: 63 65 28 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ce(..
6e50: 20 20 20 53 74 72 69 6e 67 2e 46 6f 72 6d 61 74 String.Format
6e60: 28 43 75 6c 74 75 72 65 49 6e 66 6f 2e 49 6e 76 (CultureInfo.Inv
6e70: 61 72 69 61 6e 74 43 75 6c 74 75 72 65 2c 0d 0a ariantCulture,..
6e80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 5b "[
6e90: 7b 30 7d 5d 2e 22 2c 20 62 61 73 65 53 63 68 65 {0}].", baseSche
6ea0: 6d 61 4e 61 6d 65 29 2c 20 53 74 72 69 6e 67 2e maName), String.
6eb0: 45 6d 70 74 79 29 3b 0d 0a 0d 0a 20 20 20 20 20 Empty);....
6ec0: 20 20 20 20 20 73 74 72 53 71 6c 20 3d 20 73 74 strSql = st
6ed0: 72 53 71 6c 2e 52 65 70 6c 61 63 65 28 0d 0a 20 rSql.Replace(..
6ee0: 20 20 20 20 20 20 20 20 20 20 20 20 20 53 74 72 Str
6ef0: 69 6e 67 2e 46 6f 72 6d 61 74 28 43 75 6c 74 75 ing.Format(Cultu
6f00: 72 65 49 6e 66 6f 2e 49 6e 76 61 72 69 61 6e 74 reInfo.Invariant
6f10: 43 75 6c 74 75 72 65 2c 0d 0a 20 20 20 20 20 20 Culture,..
6f20: 20 20 20 20 20 20 20 20 22 7b 30 7d 2e 22 2c 20 "{0}.",
6f30: 62 61 73 65 53 63 68 65 6d 61 4e 61 6d 65 29 2c baseSchemaName),
6f40: 20 53 74 72 69 6e 67 2e 45 6d 70 74 79 29 3b 0d String.Empty);.
6f50: 0a 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 . }..
6f60: 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 53 51 4c }.... SQL
6f70: 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 iteConnectionFla
6f80: 67 73 20 66 6c 61 67 73 20 3d 0d 0a 20 20 20 20 gs flags =..
6f90: 20 20 20 20 20 20 28 63 6e 6e 20 21 3d 20 6e 75 (cnn != nu
6fa0: 6c 6c 29 20 3f 20 63 6e 6e 2e 46 6c 61 67 73 20 ll) ? cnn.Flags
6fb0: 3a 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 : SQLiteConnecti
6fc0: 6f 6e 46 6c 61 67 73 2e 44 65 66 61 75 6c 74 3b onFlags.Default;
6fd0: 0d 0a 0d 0a 20 20 20 20 20 20 69 66 20 28 28 66 .... if ((f
6fe0: 6c 61 67 73 20 26 20 53 51 4c 69 74 65 43 6f 6e lags & SQLiteCon
6ff0: 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 nectionFlags.Log
7000: 50 72 65 70 61 72 65 29 20 3d 3d 20 53 51 4c 69 Prepare) == SQLi
7010: 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 teConnectionFlag
7020: 73 2e 4c 6f 67 50 72 65 70 61 72 65 29 0d 0a 20 s.LogPrepare)..
7030: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
7040: 20 20 69 66 20 28 28 73 74 72 53 71 6c 20 3d 3d if ((strSql ==
7050: 20 6e 75 6c 6c 29 20 7c 7c 20 28 73 74 72 53 71 null) || (strSq
7060: 6c 2e 4c 65 6e 67 74 68 20 3d 3d 20 30 29 20 7c l.Length == 0) |
7070: 7c 20 28 73 74 72 53 71 6c 2e 54 72 69 6d 28 29 | (strSql.Trim()
7080: 2e 4c 65 6e 67 74 68 20 3d 3d 20 30 29 29 0d 0a .Length == 0))..
7090: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 53 51 SQ
70a0: 4c 69 74 65 4c 6f 67 2e 4c 6f 67 4d 65 73 73 61 LiteLog.LogMessa
70b0: 67 65 28 22 50 72 65 70 61 72 69 6e 67 20 7b 3c ge("Preparing {<
70c0: 6e 6f 74 68 69 6e 67 3e 7d 2e 2e 2e 22 29 3b 0d nothing>}...");.
70d0: 0a 20 20 20 20 20 20 20 20 20 20 65 6c 73 65 0d . else.
70e0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 53 . S
70f0: 51 4c 69 74 65 4c 6f 67 2e 4c 6f 67 4d 65 73 73 QLiteLog.LogMess
7100: 61 67 65 28 53 74 72 69 6e 67 2e 46 6f 72 6d 61 age(String.Forma
7110: 74 28 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 t(..
7120: 20 20 20 20 20 20 43 75 6c 74 75 72 65 49 6e 66 CultureInf
7130: 6f 2e 43 75 72 72 65 6e 74 43 75 6c 74 75 72 65 o.CurrentCulture
7140: 2c 20 22 50 72 65 70 61 72 69 6e 67 20 7b 7b 7b , "Preparing {{{
7150: 30 7d 7d 7d 2e 2e 2e 22 2c 20 73 74 72 53 71 6c 0}}}...", strSql
7160: 29 29 3b 0d 0a 20 20 20 20 20 20 7d 0d 0a 0d 0a ));.. }....
7170: 20 20 20 20 20 20 49 6e 74 50 74 72 20 73 74 6d IntPtr stm
7180: 74 20 3d 20 49 6e 74 50 74 72 2e 5a 65 72 6f 3b t = IntPtr.Zero;
7190: 0d 0a 20 20 20 20 20 20 49 6e 74 50 74 72 20 70 .. IntPtr p
71a0: 74 72 20 3d 20 49 6e 74 50 74 72 2e 5a 65 72 6f tr = IntPtr.Zero
71b0: 3b 0d 0a 20 20 20 20 20 20 69 6e 74 20 6c 65 6e ;.. int len
71c0: 20 3d 20 30 3b 0d 0a 20 20 20 20 20 20 53 51 4c = 0;.. SQL
71d0: 69 74 65 45 72 72 6f 72 43 6f 64 65 20 6e 20 3d iteErrorCode n =
71e0: 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 SQLiteErrorCode
71f0: 2e 53 63 68 65 6d 61 3b 0d 0a 20 20 20 20 20 20 .Schema;..
7200: 69 6e 74 20 72 65 74 72 69 65 73 20 3d 20 30 3b int retries = 0;
7210: 0d 0a 20 20 20 20 20 20 62 79 74 65 5b 5d 20 62 .. byte[] b
7220: 20 3d 20 54 6f 55 54 46 38 28 73 74 72 53 71 6c = ToUTF8(strSql
7230: 29 3b 0d 0a 20 20 20 20 20 20 73 74 72 69 6e 67 );.. string
7240: 20 74 79 70 65 64 65 66 73 20 3d 20 6e 75 6c 6c typedefs = null
7250: 3b 0d 0a 20 20 20 20 20 20 53 51 4c 69 74 65 53 ;.. SQLiteS
7260: 74 61 74 65 6d 65 6e 74 20 63 6d 64 20 3d 20 6e tatement cmd = n
7270: 75 6c 6c 3b 0d 0a 20 20 20 20 20 20 52 61 6e 64 ull;.. Rand
7280: 6f 6d 20 72 6e 64 20 3d 20 6e 75 6c 6c 3b 0d 0a om rnd = null;..
7290: 20 20 20 20 20 20 75 69 6e 74 20 73 74 61 72 74 uint start
72a0: 74 69 63 6b 20 3d 20 28 75 69 6e 74 29 45 6e 76 tick = (uint)Env
72b0: 69 72 6f 6e 6d 65 6e 74 2e 54 69 63 6b 43 6f 75 ironment.TickCou
72c0: 6e 74 3b 0d 0a 0d 0a 20 20 20 20 20 20 47 43 48 nt;.... GCH
72d0: 61 6e 64 6c 65 20 68 61 6e 64 6c 65 20 3d 20 47 andle handle = G
72e0: 43 48 61 6e 64 6c 65 2e 41 6c 6c 6f 63 28 62 2c CHandle.Alloc(b,
72f0: 20 47 43 48 61 6e 64 6c 65 54 79 70 65 2e 50 69 GCHandleType.Pi
7300: 6e 6e 65 64 29 3b 0d 0a 20 20 20 20 20 20 49 6e nned);.. In
7310: 74 50 74 72 20 70 73 71 6c 20 3d 20 68 61 6e 64 tPtr psql = hand
7320: 6c 65 2e 41 64 64 72 4f 66 50 69 6e 6e 65 64 4f le.AddrOfPinnedO
7330: 62 6a 65 63 74 28 29 3b 0d 0a 20 20 20 20 20 20 bject();..
7340: 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 48 SQLiteStatementH
7350: 61 6e 64 6c 65 20 73 74 61 74 65 6d 65 6e 74 48 andle statementH
7360: 61 6e 64 6c 65 20 3d 20 6e 75 6c 6c 3b 0d 0a 20 andle = null;..
7370: 20 20 20 20 20 74 72 79 0d 0a 20 20 20 20 20 20 try..
7380: 7b 0d 0a 20 20 20 20 20 20 20 20 77 68 69 6c 65 {.. while
7390: 20 28 28 6e 20 3d 3d 20 53 51 4c 69 74 65 45 72 ((n == SQLiteEr
73a0: 72 6f 72 43 6f 64 65 2e 53 63 68 65 6d 61 20 7c rorCode.Schema |
73b0: 7c 20 6e 20 3d 3d 20 53 51 4c 69 74 65 45 72 72 | n == SQLiteErr
73c0: 6f 72 43 6f 64 65 2e 4c 6f 63 6b 65 64 20 7c 7c orCode.Locked ||
73d0: 20 6e 20 3d 3d 20 53 51 4c 69 74 65 45 72 72 6f n == SQLiteErro
73e0: 72 43 6f 64 65 2e 42 75 73 79 29 20 26 26 20 72 rCode.Busy) && r
73f0: 65 74 72 69 65 73 20 3c 20 33 29 0d 0a 20 20 20 etries < 3)..
7400: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
7410: 20 20 74 72 79 0d 0a 20 20 20 20 20 20 20 20 20 try..
7420: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
7430: 2f 2f 20 64 6f 20 6e 6f 74 68 69 6e 67 2e 0d 0a // do nothing...
7440: 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 }..
7450: 20 20 20 20 20 20 20 66 69 6e 61 6c 6c 79 20 2f finally /
7460: 2a 20 4e 4f 54 45 3a 20 54 68 72 65 61 64 2e 41 * NOTE: Thread.A
7470: 62 6f 72 74 28 29 20 70 72 6f 74 65 63 74 69 6f bort() protectio
7480: 6e 2e 20 2a 2f 0d 0a 20 20 20 20 20 20 20 20 20 n. */..
7490: 20 7b 0d 0a 23 69 66 20 21 53 51 4c 49 54 45 5f {..#if !SQLITE_
74a0: 53 54 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 20 STANDARD..
74b0: 20 20 20 20 20 20 6e 20 3d 20 55 6e 73 61 66 65 n = Unsafe
74c0: 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 NativeMethods.sq
74d0: 6c 69 74 65 33 5f 70 72 65 70 61 72 65 5f 69 6e lite3_prepare_in
74e0: 74 65 72 6f 70 28 5f 73 71 6c 2c 20 70 73 71 6c terop(_sql, psql
74f0: 2c 20 62 2e 4c 65 6e 67 74 68 20 2d 20 31 2c 20 , b.Length - 1,
7500: 6f 75 74 20 73 74 6d 74 2c 20 6f 75 74 20 70 74 out stmt, out pt
7510: 72 2c 20 6f 75 74 20 6c 65 6e 29 3b 0d 0a 23 65 r, out len);..#e
7520: 6c 73 65 0d 0a 23 69 66 20 55 53 45 5f 50 52 45 lse..#if USE_PRE
7530: 50 41 52 45 5f 56 32 0d 0a 20 20 20 20 20 20 20 PARE_V2..
7540: 20 20 20 20 20 6e 20 3d 20 55 6e 73 61 66 65 4e n = UnsafeN
7550: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
7560: 69 74 65 33 5f 70 72 65 70 61 72 65 5f 76 32 28 ite3_prepare_v2(
7570: 5f 73 71 6c 2c 20 70 73 71 6c 2c 20 62 2e 4c 65 _sql, psql, b.Le
7580: 6e 67 74 68 20 2d 20 31 2c 20 6f 75 74 20 73 74 ngth - 1, out st
7590: 6d 74 2c 20 6f 75 74 20 70 74 72 29 3b 0d 0a 23 mt, out ptr);..#
75a0: 65 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 20 20 else..
75b0: 20 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 n = UnsafeNati
75c0: 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 veMethods.sqlite
75d0: 33 5f 70 72 65 70 61 72 65 28 5f 73 71 6c 2c 20 3_prepare(_sql,
75e0: 70 73 71 6c 2c 20 62 2e 4c 65 6e 67 74 68 20 2d psql, b.Length -
75f0: 20 31 2c 20 6f 75 74 20 73 74 6d 74 2c 20 6f 75 1, out stmt, ou
7600: 74 20 70 74 72 29 3b 0d 0a 23 65 6e 64 69 66 0d t ptr);..#endif.
7610: 0a 20 20 20 20 20 20 20 20 20 20 20 20 6c 65 6e . len
7620: 20 3d 20 2d 31 3b 0d 0a 23 65 6e 64 69 66 0d 0a = -1;..#endif..
7630: 0d 0a 23 69 66 20 21 4e 45 54 5f 43 4f 4d 50 41 ..#if !NET_COMPA
7640: 43 54 5f 32 30 20 26 26 20 54 52 41 43 45 5f 53 CT_20 && TRACE_S
7650: 54 41 54 45 4d 45 4e 54 0d 0a 20 20 20 20 20 20 TATEMENT..
7660: 20 20 20 20 20 20 54 72 61 63 65 2e 57 72 69 74 Trace.Writ
7670: 65 4c 69 6e 65 28 53 74 72 69 6e 67 2e 46 6f 72 eLine(String.For
7680: 6d 61 74 28 22 50 72 65 70 61 72 65 20 28 7b 30 mat("Prepare ({0
7690: 7d 29 3a 20 7b 31 7d 22 2c 20 6e 2c 20 73 74 6d }): {1}", n, stm
76a0: 74 29 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 0d 0a t));..#endif....
76b0: 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 if (
76c0: 28 6e 20 3d 3d 20 53 51 4c 69 74 65 45 72 72 6f (n == SQLiteErro
76d0: 72 43 6f 64 65 2e 4f 6b 29 20 26 26 20 28 73 74 rCode.Ok) && (st
76e0: 6d 74 20 21 3d 20 49 6e 74 50 74 72 2e 5a 65 72 mt != IntPtr.Zer
76f0: 6f 29 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 o))..
7700: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
7710: 20 20 69 66 20 28 73 74 61 74 65 6d 65 6e 74 48 if (statementH
7720: 61 6e 64 6c 65 20 21 3d 20 6e 75 6c 6c 29 20 73 andle != null) s
7730: 74 61 74 65 6d 65 6e 74 48 61 6e 64 6c 65 2e 44 tatementHandle.D
7740: 69 73 70 6f 73 65 28 29 3b 0d 0a 20 20 20 20 20 ispose();..
7750: 20 20 20 20 20 20 20 20 20 73 74 61 74 65 6d 65 stateme
7760: 6e 74 48 61 6e 64 6c 65 20 3d 20 6e 65 77 20 53 ntHandle = new S
7770: 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 48 61 QLiteStatementHa
7780: 6e 64 6c 65 28 5f 73 71 6c 2c 20 73 74 6d 74 29 ndle(_sql, stmt)
7790: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 7d ;.. }
77a0: 0d 0a 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 0d .. }...
77b0: 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 28 73 . if (s
77c0: 74 61 74 65 6d 65 6e 74 48 61 6e 64 6c 65 20 21 tatementHandle !
77d0: 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 = null)..
77e0: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 {..
77f0: 20 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 SQLiteConnecti
7800: 6f 6e 2e 4f 6e 43 68 61 6e 67 65 64 28 6e 75 6c on.OnChanged(nul
7810: 6c 2c 20 6e 65 77 20 43 6f 6e 6e 65 63 74 69 6f l, new Connectio
7820: 6e 45 76 65 6e 74 41 72 67 73 28 0d 0a 20 20 20 nEventArgs(..
7830: 20 20 20 20 20 20 20 20 20 20 20 53 51 4c 69 74 SQLit
7840: 65 43 6f 6e 6e 65 63 74 69 6f 6e 45 76 65 6e 74 eConnectionEvent
7850: 54 79 70 65 2e 4e 65 77 43 72 69 74 69 63 61 6c Type.NewCritical
7860: 48 61 6e 64 6c 65 2c 20 6e 75 6c 6c 2c 20 6e 75 Handle, null, nu
7870: 6c 6c 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ll,..
7880: 20 20 20 6e 75 6c 6c 2c 20 6e 75 6c 6c 2c 20 73 null, null, s
7890: 74 61 74 65 6d 65 6e 74 48 61 6e 64 6c 65 2c 20 tatementHandle,
78a0: 73 74 72 53 71 6c 2c 20 6e 65 77 20 6f 62 6a 65 strSql, new obje
78b0: 63 74 5b 5d 20 7b 20 63 6e 6e 2c 0d 0a 20 20 20 ct[] { cnn,..
78c0: 20 20 20 20 20 20 20 20 20 20 20 73 74 72 53 71 strSq
78d0: 6c 2c 20 70 72 65 76 69 6f 75 73 2c 20 74 69 6d l, previous, tim
78e0: 65 6f 75 74 4d 53 20 7d 29 29 3b 0d 0a 20 20 20 eoutMS }));..
78f0: 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 }....
7900: 20 20 20 20 20 20 69 66 20 28 6e 20 3d 3d 20 53 if (n == S
7910: 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 2e 53 QLiteErrorCode.S
7920: 63 68 65 6d 61 29 0d 0a 20 20 20 20 20 20 20 20 chema)..
7930: 20 20 20 20 72 65 74 72 69 65 73 2b 2b 3b 0d 0a retries++;..
7940: 20 20 20 20 20 20 20 20 20 20 65 6c 73 65 20 69 else i
7950: 66 20 28 6e 20 3d 3d 20 53 51 4c 69 74 65 45 72 f (n == SQLiteEr
7960: 72 6f 72 43 6f 64 65 2e 45 72 72 6f 72 29 0d 0a rorCode.Error)..
7970: 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 {..
7980: 20 20 20 20 20 20 20 20 20 69 66 20 28 53 74 72 if (Str
7990: 69 6e 67 2e 43 6f 6d 70 61 72 65 28 47 65 74 4c ing.Compare(GetL
79a0: 61 73 74 45 72 72 6f 72 28 29 2c 20 22 6e 65 61 astError(), "nea
79b0: 72 20 5c 22 54 59 50 45 53 5c 22 3a 20 73 79 6e r \"TYPES\": syn
79c0: 74 61 78 20 65 72 72 6f 72 22 2c 20 53 74 72 69 tax error", Stri
79d0: 6e 67 43 6f 6d 70 61 72 69 73 6f 6e 2e 4f 72 64 ngComparison.Ord
79e0: 69 6e 61 6c 49 67 6e 6f 72 65 43 61 73 65 29 20 inalIgnoreCase)
79f0: 3d 3d 20 30 29 0d 0a 20 20 20 20 20 20 20 20 20 == 0)..
7a00: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 {..
7a10: 20 20 20 20 69 6e 74 20 70 6f 73 20 3d 20 73 74 int pos = st
7a20: 72 53 71 6c 2e 49 6e 64 65 78 4f 66 28 27 3b 27 rSql.IndexOf(';'
7a30: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 );..
7a40: 20 20 69 66 20 28 70 6f 73 20 3d 3d 20 2d 31 29 if (pos == -1)
7a50: 20 70 6f 73 20 3d 20 73 74 72 53 71 6c 2e 4c 65 pos = strSql.Le
7a60: 6e 67 74 68 20 2d 20 31 3b 0d 0a 0d 0a 20 20 20 ngth - 1;....
7a70: 20 20 20 20 20 20 20 20 20 20 20 74 79 70 65 64 typed
7a80: 65 66 73 20 3d 20 73 74 72 53 71 6c 2e 53 75 62 efs = strSql.Sub
7a90: 73 74 72 69 6e 67 28 30 2c 20 70 6f 73 20 2b 20 string(0, pos +
7aa0: 31 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 1);..
7ab0: 20 20 20 73 74 72 53 71 6c 20 3d 20 73 74 72 53 strSql = strS
7ac0: 71 6c 2e 53 75 62 73 74 72 69 6e 67 28 70 6f 73 ql.Substring(pos
7ad0: 20 2b 20 31 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 + 1);....
7ae0: 20 20 20 20 20 20 20 20 73 74 72 52 65 6d 61 69 strRemai
7af0: 6e 20 3d 20 22 22 3b 0d 0a 0d 0a 20 20 20 20 20 n = "";....
7b00: 20 20 20 20 20 20 20 20 20 77 68 69 6c 65 20 28 while (
7b10: 63 6d 64 20 3d 3d 20 6e 75 6c 6c 20 26 26 20 73 cmd == null && s
7b20: 74 72 53 71 6c 2e 4c 65 6e 67 74 68 20 3e 20 30 trSql.Length > 0
7b30: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 )..
7b40: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
7b50: 20 20 20 20 63 6d 64 20 3d 20 50 72 65 70 61 72 cmd = Prepar
7b60: 65 28 63 6e 6e 2c 20 73 74 72 53 71 6c 2c 20 70 e(cnn, strSql, p
7b70: 72 65 76 69 6f 75 73 2c 20 74 69 6d 65 6f 75 74 revious, timeout
7b80: 4d 53 2c 20 6f 75 74 20 73 74 72 52 65 6d 61 69 MS, out strRemai
7b90: 6e 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 n);..
7ba0: 20 20 20 20 20 73 74 72 53 71 6c 20 3d 20 73 74 strSql = st
7bb0: 72 52 65 6d 61 69 6e 3b 0d 0a 20 20 20 20 20 20 rRemain;..
7bc0: 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 }....
7bd0: 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 63 if (c
7be0: 6d 64 20 21 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 md != null)..
7bf0: 20 20 20 20 20 20 20 20 20 20 20 20 20 63 6d 64 cmd
7c00: 2e 53 65 74 54 79 70 65 73 28 74 79 70 65 64 65 .SetTypes(typede
7c10: 66 73 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 fs);....
7c20: 20 20 20 20 20 20 72 65 74 75 72 6e 20 63 6d 64 return cmd
7c30: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 7d ;.. }
7c40: 0d 0a 23 69 66 20 28 4e 45 54 5f 33 35 20 7c 7c ..#if (NET_35 ||
7c50: 20 4e 45 54 5f 34 30 20 7c 7c 20 4e 45 54 5f 34 NET_40 || NET_4
7c60: 35 20 7c 7c 20 4e 45 54 5f 34 35 31 29 20 26 26 5 || NET_451) &&
7c70: 20 21 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 !PLATFORM_COMPA
7c80: 43 54 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 CTFRAMEWORK..
7c90: 20 20 20 20 20 20 20 20 20 65 6c 73 65 20 69 66 else if
7ca0: 20 28 5f 62 75 69 6c 64 69 6e 67 53 63 68 65 6d (_buildingSchem
7cb0: 61 20 3d 3d 20 66 61 6c 73 65 20 26 26 20 53 74 a == false && St
7cc0: 72 69 6e 67 2e 43 6f 6d 70 61 72 65 28 47 65 74 ring.Compare(Get
7cd0: 4c 61 73 74 45 72 72 6f 72 28 29 2c 20 30 2c 20 LastError(), 0,
7ce0: 22 6e 6f 20 73 75 63 68 20 74 61 62 6c 65 3a 20 "no such table:
7cf0: 54 45 4d 50 2e 53 43 48 45 4d 41 22 2c 20 30 2c TEMP.SCHEMA", 0,
7d00: 20 32 36 2c 20 53 74 72 69 6e 67 43 6f 6d 70 61 26, StringCompa
7d10: 72 69 73 6f 6e 2e 4f 72 64 69 6e 61 6c 49 67 6e rison.OrdinalIgn
7d20: 6f 72 65 43 61 73 65 29 20 3d 3d 20 30 29 0d 0a oreCase) == 0)..
7d30: 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 {..
7d40: 20 20 20 20 20 20 20 20 20 20 20 20 20 73 74 72 str
7d50: 52 65 6d 61 69 6e 20 3d 20 22 22 3b 0d 0a 20 20 Remain = "";..
7d60: 20 20 20 20 20 20 20 20 20 20 20 20 5f 62 75 69 _bui
7d70: 6c 64 69 6e 67 53 63 68 65 6d 61 20 3d 20 74 72 ldingSchema = tr
7d80: 75 65 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ue;..
7d90: 20 20 20 74 72 79 0d 0a 20 20 20 20 20 20 20 20 try..
7da0: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
7db0: 20 20 20 20 20 20 20 20 20 49 53 51 4c 69 74 65 ISQLite
7dc0: 53 63 68 65 6d 61 45 78 74 65 6e 73 69 6f 6e 73 SchemaExtensions
7dd0: 20 65 78 74 20 3d 20 28 28 49 53 65 72 76 69 63 ext = ((IServic
7de0: 65 50 72 6f 76 69 64 65 72 29 53 51 4c 69 74 65 eProvider)SQLite
7df0: 46 61 63 74 6f 72 79 2e 49 6e 73 74 61 6e 63 65 Factory.Instance
7e00: 29 2e 47 65 74 53 65 72 76 69 63 65 28 74 79 70 ).GetService(typ
7e10: 65 6f 66 28 49 53 51 4c 69 74 65 53 63 68 65 6d eof(ISQLiteSchem
7e20: 61 45 78 74 65 6e 73 69 6f 6e 73 29 29 20 61 73 aExtensions)) as
7e30: 20 49 53 51 4c 69 74 65 53 63 68 65 6d 61 45 78 ISQLiteSchemaEx
7e40: 74 65 6e 73 69 6f 6e 73 3b 0d 0a 0d 0a 20 20 20 tensions;....
7e50: 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 if
7e60: 28 65 78 74 20 21 3d 20 6e 75 6c 6c 29 0d 0a 20 (ext != null)..
7e70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
7e80: 20 65 78 74 2e 42 75 69 6c 64 54 65 6d 70 53 63 ext.BuildTempSc
7e90: 68 65 6d 61 28 63 6e 6e 29 3b 0d 0a 0d 0a 20 20 hema(cnn);....
7ea0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 77 68 wh
7eb0: 69 6c 65 20 28 63 6d 64 20 3d 3d 20 6e 75 6c 6c ile (cmd == null
7ec0: 20 26 26 20 73 74 72 53 71 6c 2e 4c 65 6e 67 74 && strSql.Lengt
7ed0: 68 20 3e 20 30 29 0d 0a 20 20 20 20 20 20 20 20 h > 0)..
7ee0: 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 {..
7ef0: 20 20 20 20 20 20 20 20 20 20 20 20 20 63 6d 64 cmd
7f00: 20 3d 20 50 72 65 70 61 72 65 28 63 6e 6e 2c 20 = Prepare(cnn,
7f10: 73 74 72 53 71 6c 2c 20 70 72 65 76 69 6f 75 73 strSql, previous
7f20: 2c 20 74 69 6d 65 6f 75 74 4d 53 2c 20 6f 75 74 , timeoutMS, out
7f30: 20 73 74 72 52 65 6d 61 69 6e 29 3b 0d 0a 20 20 strRemain);..
7f40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
7f50: 73 74 72 53 71 6c 20 3d 20 73 74 72 52 65 6d 61 strSql = strRema
7f60: 69 6e 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 in;..
7f70: 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 }....
7f80: 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e return
7f90: 20 63 6d 64 3b 0d 0a 20 20 20 20 20 20 20 20 20 cmd;..
7fa0: 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 }..
7fb0: 20 20 20 20 20 20 66 69 6e 61 6c 6c 79 0d 0a 20 finally..
7fc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d 0a {..
7fd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
7fe0: 5f 62 75 69 6c 64 69 6e 67 53 63 68 65 6d 61 20 _buildingSchema
7ff0: 3d 20 66 61 6c 73 65 3b 0d 0a 20 20 20 20 20 20 = false;..
8000: 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 }..
8010: 20 20 20 20 20 20 20 7d 0d 0a 23 65 6e 64 69 66 }..#endif
8020: 0d 0a 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 .. }..
8030: 20 20 20 20 20 20 20 20 20 65 6c 73 65 20 69 66 else if
8040: 20 28 6e 20 3d 3d 20 53 51 4c 69 74 65 45 72 72 (n == SQLiteErr
8050: 6f 72 43 6f 64 65 2e 4c 6f 63 6b 65 64 20 7c 7c orCode.Locked ||
8060: 20 6e 20 3d 3d 20 53 51 4c 69 74 65 45 72 72 6f n == SQLiteErro
8070: 72 43 6f 64 65 2e 42 75 73 79 29 20 2f 2f 20 4c rCode.Busy) // L
8080: 6f 63 6b 65 64 20 2d 2d 20 64 65 6c 61 79 20 61 ocked -- delay a
8090: 20 73 6d 61 6c 6c 20 61 6d 6f 75 6e 74 20 62 65 small amount be
80a0: 66 6f 72 65 20 72 65 74 72 79 69 6e 67 0d 0a 20 fore retrying..
80b0: 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 {..
80c0: 20 20 20 20 20 20 20 20 2f 2f 20 4b 65 65 70 20 // Keep
80d0: 74 72 79 69 6e 67 0d 0a 20 20 20 20 20 20 20 20 trying..
80e0: 20 20 20 20 69 66 20 28 72 6e 64 20 3d 3d 20 6e if (rnd == n
80f0: 75 6c 6c 29 20 2f 2f 20 46 69 72 73 74 20 74 69 ull) // First ti
8100: 6d 65 20 77 65 27 76 65 20 65 6e 63 6f 75 6e 74 me we've encount
8110: 65 72 65 64 20 74 68 65 20 6c 6f 63 6b 0d 0a 20 ered the lock..
8120: 20 20 20 20 20 20 20 20 20 20 20 20 20 72 6e 64 rnd
8130: 20 3d 20 6e 65 77 20 52 61 6e 64 6f 6d 28 29 3b = new Random();
8140: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ....
8150: 2f 2f 20 49 66 20 77 65 27 76 65 20 65 78 63 65 // If we've exce
8160: 65 64 65 64 20 74 68 65 20 63 6f 6d 6d 61 6e 64 eded the command
8170: 27 73 20 74 69 6d 65 6f 75 74 2c 20 67 69 76 65 's timeout, give
8180: 20 75 70 20 61 6e 64 20 74 68 72 6f 77 20 61 6e up and throw an
8190: 20 65 72 72 6f 72 0d 0a 20 20 20 20 20 20 20 20 error..
81a0: 20 20 20 20 69 66 20 28 28 75 69 6e 74 29 45 6e if ((uint)En
81b0: 76 69 72 6f 6e 6d 65 6e 74 2e 54 69 63 6b 43 6f vironment.TickCo
81c0: 75 6e 74 20 2d 20 73 74 61 72 74 74 69 63 6b 20 unt - starttick
81d0: 3e 20 74 69 6d 65 6f 75 74 4d 53 29 0d 0a 20 20 > timeoutMS)..
81e0: 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 {..
81f0: 20 20 20 20 20 20 20 20 20 20 20 74 68 72 6f 77 throw
8200: 20 6e 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 new SQLiteExcep
8210: 74 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 tion(n, GetLastE
8220: 72 72 6f 72 28 29 29 3b 0d 0a 20 20 20 20 20 20 rror());..
8230: 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 }..
8240: 20 20 20 20 20 65 6c 73 65 0d 0a 20 20 20 20 20 else..
8250: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
8260: 20 20 20 20 20 20 20 20 2f 2f 20 4f 74 68 65 72 // Other
8270: 77 69 73 65 20 73 6c 65 65 70 20 66 6f 72 20 61 wise sleep for a
8280: 20 72 61 6e 64 6f 6d 20 61 6d 6f 75 6e 74 20 6f random amount o
8290: 66 20 74 69 6d 65 20 75 70 20 74 6f 20 31 35 30 f time up to 150
82a0: 6d 73 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ms..
82b0: 20 20 53 79 73 74 65 6d 2e 54 68 72 65 61 64 69 System.Threadi
82c0: 6e 67 2e 54 68 72 65 61 64 2e 53 6c 65 65 70 28 ng.Thread.Sleep(
82d0: 72 6e 64 2e 4e 65 78 74 28 31 2c 20 31 35 30 29 rnd.Next(1, 150)
82e0: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 );..
82f0: 7d 0d 0a 20 20 20 20 20 20 20 20 20 20 7d 0d 0a }.. }..
8300: 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 }....
8310: 20 20 20 20 20 69 66 20 28 6e 20 21 3d 20 53 51 if (n != SQ
8320: 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 2e 4f 6b LiteErrorCode.Ok
8330: 29 20 74 68 72 6f 77 20 6e 65 77 20 53 51 4c 69 ) throw new SQLi
8340: 74 65 45 78 63 65 70 74 69 6f 6e 28 6e 2c 20 47 teException(n, G
8350: 65 74 4c 61 73 74 45 72 72 6f 72 28 29 29 3b 0d etLastError());.
8360: 0a 0d 0a 20 20 20 20 20 20 20 20 73 74 72 52 65 ... strRe
8370: 6d 61 69 6e 20 3d 20 55 54 46 38 54 6f 53 74 72 main = UTF8ToStr
8380: 69 6e 67 28 70 74 72 2c 20 6c 65 6e 29 3b 0d 0a ing(ptr, len);..
8390: 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 73 74 .. if (st
83a0: 61 74 65 6d 65 6e 74 48 61 6e 64 6c 65 20 21 3d atementHandle !=
83b0: 20 6e 75 6c 6c 29 20 63 6d 64 20 3d 20 6e 65 77 null) cmd = new
83c0: 20 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 SQLiteStatement
83d0: 28 74 68 69 73 2c 20 66 6c 61 67 73 2c 20 73 74 (this, flags, st
83e0: 61 74 65 6d 65 6e 74 48 61 6e 64 6c 65 2c 20 73 atementHandle, s
83f0: 74 72 53 71 6c 2e 53 75 62 73 74 72 69 6e 67 28 trSql.Substring(
8400: 30 2c 20 73 74 72 53 71 6c 2e 4c 65 6e 67 74 68 0, strSql.Length
8410: 20 2d 20 73 74 72 52 65 6d 61 69 6e 2e 4c 65 6e - strRemain.Len
8420: 67 74 68 29 2c 20 70 72 65 76 69 6f 75 73 29 3b gth), previous);
8430: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75 .... retu
8440: 72 6e 20 63 6d 64 3b 0d 0a 20 20 20 20 20 20 7d rn cmd;.. }
8450: 0d 0a 20 20 20 20 20 20 66 69 6e 61 6c 6c 79 0d .. finally.
8460: 0a 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 . {..
8470: 20 20 68 61 6e 64 6c 65 2e 46 72 65 65 28 29 3b handle.Free();
8480: 0d 0a 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 7d .. }.. }
8490: 0d 0a 0d 0a 20 20 20 20 70 72 6f 74 65 63 74 65 .... protecte
84a0: 64 20 73 74 61 74 69 63 20 76 6f 69 64 20 4c 6f d static void Lo
84b0: 67 42 69 6e 64 28 53 51 4c 69 74 65 53 74 61 74 gBind(SQLiteStat
84c0: 65 6d 65 6e 74 48 61 6e 64 6c 65 20 68 61 6e 64 ementHandle hand
84d0: 6c 65 2c 20 69 6e 74 20 69 6e 64 65 78 29 0d 0a le, int index)..
84e0: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 49 {.. I
84f0: 6e 74 50 74 72 20 68 61 6e 64 6c 65 49 6e 74 50 ntPtr handleIntP
8500: 74 72 20 3d 20 68 61 6e 64 6c 65 3b 0d 0a 0d 0a tr = handle;....
8510: 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 4c 6f SQLiteLo
8520: 67 2e 4c 6f 67 4d 65 73 73 61 67 65 28 53 74 72 g.LogMessage(Str
8530: 69 6e 67 2e 46 6f 72 6d 61 74 28 0d 0a 20 20 20 ing.Format(..
8540: 20 20 20 20 20 20 20 20 20 43 75 6c 74 75 72 65 Culture
8550: 49 6e 66 6f 2e 43 75 72 72 65 6e 74 43 75 6c 74 Info.CurrentCult
8560: 75 72 65 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 ure,..
8570: 20 20 22 42 69 6e 64 69 6e 67 20 73 74 61 74 65 "Binding state
8580: 6d 65 6e 74 20 7b 30 7d 20 70 61 72 61 6d 74 65 ment {0} paramte
8590: 72 20 23 7b 31 7d 20 61 73 20 4e 55 4c 4c 2e 2e r #{1} as NULL..
85a0: 2e 22 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 20 .",..
85b0: 20 68 61 6e 64 6c 65 49 6e 74 50 74 72 2c 20 69 handleIntPtr, i
85c0: 6e 64 65 78 29 29 3b 0d 0a 20 20 20 20 7d 0d 0a ndex));.. }..
85d0: 0d 0a 20 20 20 20 70 72 6f 74 65 63 74 65 64 20 .. protected
85e0: 73 74 61 74 69 63 20 76 6f 69 64 20 4c 6f 67 42 static void LogB
85f0: 69 6e 64 28 53 51 4c 69 74 65 53 74 61 74 65 6d ind(SQLiteStatem
8600: 65 6e 74 48 61 6e 64 6c 65 20 68 61 6e 64 6c 65 entHandle handle
8610: 2c 20 69 6e 74 20 69 6e 64 65 78 2c 20 56 61 6c , int index, Val
8620: 75 65 54 79 70 65 20 76 61 6c 75 65 29 0d 0a 20 ueType value)..
8630: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 49 6e {.. In
8640: 74 50 74 72 20 68 61 6e 64 6c 65 49 6e 74 50 74 tPtr handleIntPt
8650: 72 20 3d 20 68 61 6e 64 6c 65 3b 0d 0a 0d 0a 20 r = handle;....
8660: 20 20 20 20 20 20 20 53 51 4c 69 74 65 4c 6f 67 SQLiteLog
8670: 2e 4c 6f 67 4d 65 73 73 61 67 65 28 53 74 72 69 .LogMessage(Stri
8680: 6e 67 2e 46 6f 72 6d 61 74 28 0d 0a 20 20 20 20 ng.Format(..
8690: 20 20 20 20 20 20 20 20 22 42 69 6e 64 69 6e 67 "Binding
86a0: 20 73 74 61 74 65 6d 65 6e 74 20 7b 30 7d 20 70 statement {0} p
86b0: 61 72 61 6d 74 65 72 20 23 7b 31 7d 20 61 73 20 aramter #{1} as
86c0: 74 79 70 65 20 7b 32 7d 20 77 69 74 68 20 76 61 type {2} with va
86d0: 6c 75 65 20 7b 7b 7b 33 7d 7d 7d 2e 2e 2e 22 2c lue {{{3}}}...",
86e0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 68 61 .. ha
86f0: 6e 64 6c 65 49 6e 74 50 74 72 2c 20 69 6e 64 65 ndleIntPtr, inde
8700: 78 2c 20 76 61 6c 75 65 2e 47 65 74 54 79 70 65 x, value.GetType
8710: 28 29 2c 20 76 61 6c 75 65 29 29 3b 0d 0a 20 20 (), value));..
8720: 20 20 7d 0d 0a 0d 0a 20 20 20 20 70 72 69 76 61 }.... priva
8730: 74 65 20 73 74 61 74 69 63 20 73 74 72 69 6e 67 te static string
8740: 20 46 6f 72 6d 61 74 44 61 74 65 54 69 6d 65 28 FormatDateTime(
8750: 44 61 74 65 54 69 6d 65 20 76 61 6c 75 65 29 0d DateTime value).
8760: 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 . {..
8770: 53 74 72 69 6e 67 42 75 69 6c 64 65 72 20 72 65 StringBuilder re
8780: 73 75 6c 74 20 3d 20 6e 65 77 20 53 74 72 69 6e sult = new Strin
8790: 67 42 75 69 6c 64 65 72 28 29 3b 0d 0a 0d 0a 20 gBuilder();....
87a0: 20 20 20 20 20 20 20 72 65 73 75 6c 74 2e 41 70 result.Ap
87b0: 70 65 6e 64 28 76 61 6c 75 65 2e 54 6f 53 74 72 pend(value.ToStr
87c0: 69 6e 67 28 22 79 79 79 79 2d 4d 4d 2d 64 64 54 ing("yyyy-MM-ddT
87d0: 48 48 3a 6d 6d 3a 73 73 2e 46 46 46 46 46 46 46 HH:mm:ss.FFFFFFF
87e0: 4b 22 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 72 K"));.. r
87f0: 65 73 75 6c 74 2e 41 70 70 65 6e 64 28 27 20 27 esult.Append(' '
8800: 29 3b 0d 0a 20 20 20 20 20 20 20 20 72 65 73 75 );.. resu
8810: 6c 74 2e 41 70 70 65 6e 64 28 76 61 6c 75 65 2e lt.Append(value.
8820: 4b 69 6e 64 29 3b 0d 0a 20 20 20 20 20 20 20 20 Kind);..
8830: 72 65 73 75 6c 74 2e 41 70 70 65 6e 64 28 27 20 result.Append('
8840: 27 29 3b 0d 0a 20 20 20 20 20 20 20 20 72 65 73 ');.. res
8850: 75 6c 74 2e 41 70 70 65 6e 64 28 76 61 6c 75 65 ult.Append(value
8860: 2e 54 69 63 6b 73 29 3b 0d 0a 0d 0a 20 20 20 20 .Ticks);....
8870: 20 20 20 20 72 65 74 75 72 6e 20 72 65 73 75 6c return resul
8880: 74 2e 54 6f 53 74 72 69 6e 67 28 29 3b 0d 0a 20 t.ToString();..
8890: 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 70 72 6f 74 }.... prot
88a0: 65 63 74 65 64 20 73 74 61 74 69 63 20 76 6f 69 ected static voi
88b0: 64 20 4c 6f 67 42 69 6e 64 28 53 51 4c 69 74 65 d LogBind(SQLite
88c0: 53 74 61 74 65 6d 65 6e 74 48 61 6e 64 6c 65 20 StatementHandle
88d0: 68 61 6e 64 6c 65 2c 20 69 6e 74 20 69 6e 64 65 handle, int inde
88e0: 78 2c 20 44 61 74 65 54 69 6d 65 20 76 61 6c 75 x, DateTime valu
88f0: 65 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 e).. {..
8900: 20 20 20 49 6e 74 50 74 72 20 68 61 6e 64 6c 65 IntPtr handle
8910: 49 6e 74 50 74 72 20 3d 20 68 61 6e 64 6c 65 3b IntPtr = handle;
8920: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 53 51 4c 69 .... SQLi
8930: 74 65 4c 6f 67 2e 4c 6f 67 4d 65 73 73 61 67 65 teLog.LogMessage
8940: 28 53 74 72 69 6e 67 2e 46 6f 72 6d 61 74 28 0d (String.Format(.
8950: 0a 20 20 20 20 20 20 20 20 20 20 20 20 22 42 69 . "Bi
8960: 6e 64 69 6e 67 20 73 74 61 74 65 6d 65 6e 74 20 nding statement
8970: 7b 30 7d 20 70 61 72 61 6d 74 65 72 20 23 7b 31 {0} paramter #{1
8980: 7d 20 61 73 20 74 79 70 65 20 7b 32 7d 20 77 69 } as type {2} wi
8990: 74 68 20 76 61 6c 75 65 20 7b 7b 7b 33 7d 7d 7d th value {{{3}}}
89a0: 2e 2e 2e 22 2c 0d 0a 20 20 20 20 20 20 20 20 20 ...",..
89b0: 20 20 20 68 61 6e 64 6c 65 49 6e 74 50 74 72 2c handleIntPtr,
89c0: 20 69 6e 64 65 78 2c 20 74 79 70 65 6f 66 28 44 index, typeof(D
89d0: 61 74 65 54 69 6d 65 29 2c 20 46 6f 72 6d 61 74 ateTime), Format
89e0: 44 61 74 65 54 69 6d 65 28 76 61 6c 75 65 29 29 DateTime(value))
89f0: 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 );.. }....
8a00: 20 70 72 6f 74 65 63 74 65 64 20 73 74 61 74 69 protected stati
8a10: 63 20 76 6f 69 64 20 4c 6f 67 42 69 6e 64 28 53 c void LogBind(S
8a20: 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 48 61 QLiteStatementHa
8a30: 6e 64 6c 65 20 68 61 6e 64 6c 65 2c 20 69 6e 74 ndle handle, int
8a40: 20 69 6e 64 65 78 2c 20 73 74 72 69 6e 67 20 76 index, string v
8a50: 61 6c 75 65 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 alue).. {..
8a60: 20 20 20 20 20 20 49 6e 74 50 74 72 20 68 61 6e IntPtr han
8a70: 64 6c 65 49 6e 74 50 74 72 20 3d 20 68 61 6e 64 dleIntPtr = hand
8a80: 6c 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 53 le;.... S
8a90: 51 4c 69 74 65 4c 6f 67 2e 4c 6f 67 4d 65 73 73 QLiteLog.LogMess
8aa0: 61 67 65 28 53 74 72 69 6e 67 2e 46 6f 72 6d 61 age(String.Forma
8ab0: 74 28 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 t(..
8ac0: 22 42 69 6e 64 69 6e 67 20 73 74 61 74 65 6d 65 "Binding stateme
8ad0: 6e 74 20 7b 30 7d 20 70 61 72 61 6d 74 65 72 20 nt {0} paramter
8ae0: 23 7b 31 7d 20 61 73 20 74 79 70 65 20 7b 32 7d #{1} as type {2}
8af0: 20 77 69 74 68 20 76 61 6c 75 65 20 7b 7b 7b 33 with value {{{3
8b00: 7d 7d 7d 2e 2e 2e 22 2c 0d 0a 20 20 20 20 20 20 }}}...",..
8b10: 20 20 20 20 20 20 68 61 6e 64 6c 65 49 6e 74 50 handleIntP
8b20: 74 72 2c 20 69 6e 64 65 78 2c 20 74 79 70 65 6f tr, index, typeo
8b30: 66 28 53 74 72 69 6e 67 29 2c 20 28 76 61 6c 75 f(String), (valu
8b40: 65 20 21 3d 20 6e 75 6c 6c 29 20 3f 20 76 61 6c e != null) ? val
8b50: 75 65 20 3a 20 22 3c 6e 75 6c 6c 3e 22 29 29 3b ue : "<null>"));
8b60: 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 70 .. }.... p
8b70: 72 69 76 61 74 65 20 73 74 61 74 69 63 20 73 74 rivate static st
8b80: 72 69 6e 67 20 54 6f 48 65 78 61 64 65 63 69 6d ring ToHexadecim
8b90: 61 6c 53 74 72 69 6e 67 28 0d 0a 20 20 20 20 20 alString(..
8ba0: 20 20 20 62 79 74 65 5b 5d 20 61 72 72 61 79 0d byte[] array.
8bb0: 0a 20 20 20 20 20 20 20 20 29 0d 0a 20 20 20 20 . )..
8bc0: 7b 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 61 {.. if (a
8bd0: 72 72 61 79 20 3d 3d 20 6e 75 6c 6c 29 0d 0a 20 rray == null)..
8be0: 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 retur
8bf0: 6e 20 6e 75 6c 6c 3b 0d 0a 0d 0a 20 20 20 20 20 n null;....
8c00: 20 20 20 53 74 72 69 6e 67 42 75 69 6c 64 65 72 StringBuilder
8c10: 20 72 65 73 75 6c 74 20 3d 20 6e 65 77 20 53 74 result = new St
8c20: 72 69 6e 67 42 75 69 6c 64 65 72 28 61 72 72 61 ringBuilder(arra
8c30: 79 2e 4c 65 6e 67 74 68 20 2a 20 32 29 3b 0d 0a y.Length * 2);..
8c40: 0d 0a 20 20 20 20 20 20 20 20 69 6e 74 20 6c 65 .. int le
8c50: 6e 67 74 68 20 3d 20 61 72 72 61 79 2e 4c 65 6e ngth = array.Len
8c60: 67 74 68 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 gth;....
8c70: 66 6f 72 20 28 69 6e 74 20 69 6e 64 65 78 20 3d for (int index =
8c80: 20 30 3b 20 69 6e 64 65 78 20 3c 20 6c 65 6e 67 0; index < leng
8c90: 74 68 3b 20 69 6e 64 65 78 2b 2b 29 0d 0a 20 20 th; index++)..
8ca0: 20 20 20 20 20 20 20 20 20 20 72 65 73 75 6c 74 result
8cb0: 2e 41 70 70 65 6e 64 28 61 72 72 61 79 5b 69 6e .Append(array[in
8cc0: 64 65 78 5d 2e 54 6f 53 74 72 69 6e 67 28 22 78 dex].ToString("x
8cd0: 32 22 29 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 2"));....
8ce0: 20 72 65 74 75 72 6e 20 72 65 73 75 6c 74 2e 54 return result.T
8cf0: 6f 53 74 72 69 6e 67 28 29 3b 0d 0a 20 20 20 20 oString();..
8d00: 7d 0d 0a 0d 0a 20 20 20 20 70 72 6f 74 65 63 74 }.... protect
8d10: 65 64 20 73 74 61 74 69 63 20 76 6f 69 64 20 4c ed static void L
8d20: 6f 67 42 69 6e 64 28 53 51 4c 69 74 65 53 74 61 ogBind(SQLiteSta
8d30: 74 65 6d 65 6e 74 48 61 6e 64 6c 65 20 68 61 6e tementHandle han
8d40: 64 6c 65 2c 20 69 6e 74 20 69 6e 64 65 78 2c 20 dle, int index,
8d50: 62 79 74 65 5b 5d 20 76 61 6c 75 65 29 0d 0a 20 byte[] value)..
8d60: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 49 6e {.. In
8d70: 74 50 74 72 20 68 61 6e 64 6c 65 49 6e 74 50 74 tPtr handleIntPt
8d80: 72 20 3d 20 68 61 6e 64 6c 65 3b 0d 0a 0d 0a 20 r = handle;....
8d90: 20 20 20 20 20 20 20 53 51 4c 69 74 65 4c 6f 67 SQLiteLog
8da0: 2e 4c 6f 67 4d 65 73 73 61 67 65 28 53 74 72 69 .LogMessage(Stri
8db0: 6e 67 2e 46 6f 72 6d 61 74 28 0d 0a 20 20 20 20 ng.Format(..
8dc0: 20 20 20 20 20 20 20 20 22 42 69 6e 64 69 6e 67 "Binding
8dd0: 20 73 74 61 74 65 6d 65 6e 74 20 7b 30 7d 20 70 statement {0} p
8de0: 61 72 61 6d 74 65 72 20 23 7b 31 7d 20 61 73 20 aramter #{1} as
8df0: 74 79 70 65 20 7b 32 7d 20 77 69 74 68 20 76 61 type {2} with va
8e00: 6c 75 65 20 7b 7b 7b 33 7d 7d 7d 2e 2e 2e 22 2c lue {{{3}}}...",
8e10: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 68 61 .. ha
8e20: 6e 64 6c 65 49 6e 74 50 74 72 2c 20 69 6e 64 65 ndleIntPtr, inde
8e30: 78 2c 20 74 79 70 65 6f 66 28 42 79 74 65 5b 5d x, typeof(Byte[]
8e40: 29 2c 20 28 76 61 6c 75 65 20 21 3d 20 6e 75 6c ), (value != nul
8e50: 6c 29 20 3f 20 54 6f 48 65 78 61 64 65 63 69 6d l) ? ToHexadecim
8e60: 61 6c 53 74 72 69 6e 67 28 76 61 6c 75 65 29 20 alString(value)
8e70: 3a 20 22 3c 6e 75 6c 6c 3e 22 29 29 3b 0d 0a 20 : "<null>"));..
8e80: 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 }.... inte
8e90: 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 76 6f rnal override vo
8ea0: 69 64 20 42 69 6e 64 5f 44 6f 75 62 6c 65 28 53 id Bind_Double(S
8eb0: 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 20 73 QLiteStatement s
8ec0: 74 6d 74 2c 20 53 51 4c 69 74 65 43 6f 6e 6e 65 tmt, SQLiteConne
8ed0: 63 74 69 6f 6e 46 6c 61 67 73 20 66 6c 61 67 73 ctionFlags flags
8ee0: 2c 20 69 6e 74 20 69 6e 64 65 78 2c 20 64 6f 75 , int index, dou
8ef0: 62 6c 65 20 76 61 6c 75 65 29 0d 0a 20 20 20 20 ble value)..
8f00: 7b 0d 0a 20 20 20 20 20 20 20 20 53 51 4c 69 74 {.. SQLit
8f10: 65 53 74 61 74 65 6d 65 6e 74 48 61 6e 64 6c 65 eStatementHandle
8f20: 20 68 61 6e 64 6c 65 20 3d 20 73 74 6d 74 2e 5f handle = stmt._
8f30: 73 71 6c 69 74 65 5f 73 74 6d 74 3b 0d 0a 0d 0a sqlite_stmt;....
8f40: 20 20 20 20 20 20 20 20 69 66 20 28 28 66 6c 61 if ((fla
8f50: 67 73 20 26 20 53 51 4c 69 74 65 43 6f 6e 6e 65 gs & SQLiteConne
8f60: 63 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 ctionFlags.LogBi
8f70: 6e 64 29 20 3d 3d 20 53 51 4c 69 74 65 43 6f 6e nd) == SQLiteCon
8f80: 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 nectionFlags.Log
8f90: 42 69 6e 64 29 0d 0a 20 20 20 20 20 20 20 20 7b Bind).. {
8fa0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 4c 6f .. Lo
8fb0: 67 42 69 6e 64 28 68 61 6e 64 6c 65 2c 20 69 6e gBind(handle, in
8fc0: 64 65 78 2c 20 76 61 6c 75 65 29 3b 0d 0a 20 20 dex, value);..
8fd0: 20 20 20 20 20 20 7d 0d 0a 0d 0a 23 69 66 20 21 }....#if !
8fe0: 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 PLATFORM_COMPACT
8ff0: 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 20 FRAMEWORK..
9000: 20 20 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f SQLiteErrorCo
9010: 64 65 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 de n = UnsafeNat
9020: 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 iveMethods.sqlit
9030: 65 33 5f 62 69 6e 64 5f 64 6f 75 62 6c 65 28 68 e3_bind_double(h
9040: 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 76 61 andle, index, va
9050: 6c 75 65 29 3b 0d 0a 23 65 6c 69 66 20 21 53 51 lue);..#elif !SQ
9060: 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a 20 LITE_STANDARD..
9070: 20 20 20 20 20 20 20 53 51 4c 69 74 65 45 72 72 SQLiteErr
9080: 6f 72 43 6f 64 65 20 6e 20 3d 20 55 6e 73 61 66 orCode n = Unsaf
9090: 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
90a0: 71 6c 69 74 65 33 5f 62 69 6e 64 5f 64 6f 75 62 qlite3_bind_doub
90b0: 6c 65 5f 69 6e 74 65 72 6f 70 28 68 61 6e 64 6c le_interop(handl
90c0: 65 2c 20 69 6e 64 65 78 2c 20 72 65 66 20 76 61 e, index, ref va
90d0: 6c 75 65 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 lue);..#else..
90e0: 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 77 20 throw new
90f0: 4e 6f 74 49 6d 70 6c 65 6d 65 6e 74 65 64 45 78 NotImplementedEx
9100: 63 65 70 74 69 6f 6e 28 29 3b 0d 0a 23 65 6e 64 ception();..#end
9110: 69 66 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 if.. if (
9120: 6e 20 21 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 n != SQLiteError
9130: 43 6f 64 65 2e 4f 6b 29 20 74 68 72 6f 77 20 6e Code.Ok) throw n
9140: 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 74 69 ew SQLiteExcepti
9150: 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 72 72 on(n, GetLastErr
9160: 6f 72 28 29 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d or());.. }...
9170: 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 . internal ov
9180: 65 72 72 69 64 65 20 76 6f 69 64 20 42 69 6e 64 erride void Bind
9190: 5f 49 6e 74 33 32 28 53 51 4c 69 74 65 53 74 61 _Int32(SQLiteSta
91a0: 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 53 51 4c tement stmt, SQL
91b0: 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 iteConnectionFla
91c0: 67 73 20 66 6c 61 67 73 2c 20 69 6e 74 20 69 6e gs flags, int in
91d0: 64 65 78 2c 20 69 6e 74 20 76 61 6c 75 65 29 0d dex, int value).
91e0: 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 . {..
91f0: 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 48 SQLiteStatementH
9200: 61 6e 64 6c 65 20 68 61 6e 64 6c 65 20 3d 20 73 andle handle = s
9210: 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 6d 74 tmt._sqlite_stmt
9220: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 66 20 ;.... if
9230: 28 28 66 6c 61 67 73 20 26 20 53 51 4c 69 74 65 ((flags & SQLite
9240: 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2e ConnectionFlags.
9250: 4c 6f 67 42 69 6e 64 29 20 3d 3d 20 53 51 4c 69 LogBind) == SQLi
9260: 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 teConnectionFlag
9270: 73 2e 4c 6f 67 42 69 6e 64 29 0d 0a 20 20 20 20 s.LogBind)..
9280: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 {..
9290: 20 20 20 4c 6f 67 42 69 6e 64 28 68 61 6e 64 6c LogBind(handl
92a0: 65 2c 20 69 6e 64 65 78 2c 20 76 61 6c 75 65 29 e, index, value)
92b0: 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a ;.. }....
92c0: 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 45 72 SQLiteEr
92d0: 72 6f 72 43 6f 64 65 20 6e 20 3d 20 55 6e 73 61 rorCode n = Unsa
92e0: 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
92f0: 73 71 6c 69 74 65 33 5f 62 69 6e 64 5f 69 6e 74 sqlite3_bind_int
9300: 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 (handle, index,
9310: 76 61 6c 75 65 29 3b 0d 0a 20 20 20 20 20 20 20 value);..
9320: 20 69 66 20 28 6e 20 21 3d 20 53 51 4c 69 74 65 if (n != SQLite
9330: 45 72 72 6f 72 43 6f 64 65 2e 4f 6b 29 20 74 68 ErrorCode.Ok) th
9340: 72 6f 77 20 6e 65 77 20 53 51 4c 69 74 65 45 78 row new SQLiteEx
9350: 63 65 70 74 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 ception(n, GetLa
9360: 73 74 45 72 72 6f 72 28 29 29 3b 0d 0a 20 20 20 stError());..
9370: 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e }.... intern
9380: 61 6c 20 6f 76 65 72 72 69 64 65 20 76 6f 69 64 al override void
9390: 20 42 69 6e 64 5f 55 49 6e 74 33 32 28 53 51 4c Bind_UInt32(SQL
93a0: 69 74 65 53 74 61 74 65 6d 65 6e 74 20 73 74 6d iteStatement stm
93b0: 74 2c 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 t, SQLiteConnect
93c0: 69 6f 6e 46 6c 61 67 73 20 66 6c 61 67 73 2c 20 ionFlags flags,
93d0: 69 6e 74 20 69 6e 64 65 78 2c 20 75 69 6e 74 20 int index, uint
93e0: 76 61 6c 75 65 29 0d 0a 20 20 20 20 7b 0d 0a 20 value).. {..
93f0: 20 20 20 20 20 20 20 53 51 4c 69 74 65 53 74 61 SQLiteSta
9400: 74 65 6d 65 6e 74 48 61 6e 64 6c 65 20 68 61 6e tementHandle han
9410: 64 6c 65 20 3d 20 73 74 6d 74 2e 5f 73 71 6c 69 dle = stmt._sqli
9420: 74 65 5f 73 74 6d 74 3b 0d 0a 0d 0a 23 69 66 20 te_stmt;....#if
9430: 21 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 !PLATFORM_COMPAC
9440: 54 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 TFRAMEWORK..
9450: 20 20 20 20 69 66 20 28 28 66 6c 61 67 73 20 26 if ((flags &
9460: 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f SQLiteConnectio
9470: 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 20 nFlags.LogBind)
9480: 3d 3d 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 == SQLiteConnect
9490: 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 ionFlags.LogBind
94a0: 29 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 ).. {..
94b0: 20 20 20 20 20 20 20 20 20 20 4c 6f 67 42 69 6e LogBin
94c0: 64 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c d(handle, index,
94d0: 20 76 61 6c 75 65 29 3b 0d 0a 20 20 20 20 20 20 value);..
94e0: 20 20 7d 0d 0a 23 65 6e 64 69 66 0d 0a 0d 0a 20 }..#endif....
94f0: 20 20 20 20 20 20 20 53 51 4c 69 74 65 45 72 72 SQLiteErr
9500: 6f 72 43 6f 64 65 20 6e 3b 0d 0a 0d 0a 20 20 20 orCode n;....
9510: 20 20 20 20 20 69 66 20 28 28 66 6c 61 67 73 20 if ((flags
9520: 26 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 & SQLiteConnecti
9530: 6f 6e 46 6c 61 67 73 2e 42 69 6e 64 55 49 6e 74 onFlags.BindUInt
9540: 33 32 41 73 49 6e 74 36 34 29 20 3d 3d 20 53 51 32AsInt64) == SQ
9550: 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c LiteConnectionFl
9560: 61 67 73 2e 42 69 6e 64 55 49 6e 74 33 32 41 73 ags.BindUInt32As
9570: 49 6e 74 36 34 29 0d 0a 20 20 20 20 20 20 20 20 Int64)..
9580: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 6c {.. l
9590: 6f 6e 67 20 76 61 6c 75 65 32 20 3d 20 76 61 6c ong value2 = val
95a0: 75 65 3b 0d 0a 0d 0a 23 69 66 20 21 50 4c 41 54 ue;....#if !PLAT
95b0: 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 41 4d FORM_COMPACTFRAM
95c0: 45 57 4f 52 4b 0d 0a 20 20 20 20 20 20 20 20 20 EWORK..
95d0: 20 20 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 n = UnsafeNat
95e0: 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 iveMethods.sqlit
95f0: 65 33 5f 62 69 6e 64 5f 69 6e 74 36 34 28 68 61 e3_bind_int64(ha
9600: 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 76 61 6c ndle, index, val
9610: 75 65 32 29 3b 0d 0a 23 65 6c 69 66 20 21 53 51 ue2);..#elif !SQ
9620: 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a 20 LITE_STANDARD..
9630: 20 20 20 20 20 20 20 20 20 20 20 6e 20 3d 20 55 n = U
9640: 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
9650: 64 73 2e 73 71 6c 69 74 65 33 5f 62 69 6e 64 5f ds.sqlite3_bind_
9660: 69 6e 74 36 34 5f 69 6e 74 65 72 6f 70 28 68 61 int64_interop(ha
9670: 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 72 65 66 ndle, index, ref
9680: 20 76 61 6c 75 65 32 29 3b 0d 0a 23 65 6c 73 65 value2);..#else
9690: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 74 68 .. th
96a0: 72 6f 77 20 6e 65 77 20 4e 6f 74 49 6d 70 6c 65 row new NotImple
96b0: 6d 65 6e 74 65 64 45 78 63 65 70 74 69 6f 6e 28 mentedException(
96c0: 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 );..#endif..
96d0: 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 65 }.. e
96e0: 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a lse.. {..
96f0: 20 20 20 20 20 20 20 20 20 20 20 20 6e 20 3d 20 n =
9700: 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 UnsafeNativeMeth
9710: 6f 64 73 2e 73 71 6c 69 74 65 33 5f 62 69 6e 64 ods.sqlite3_bind
9720: 5f 75 69 6e 74 28 68 61 6e 64 6c 65 2c 20 69 6e _uint(handle, in
9730: 64 65 78 2c 20 76 61 6c 75 65 29 3b 0d 0a 20 20 dex, value);..
9740: 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 }..
9750: 20 69 66 20 28 6e 20 21 3d 20 53 51 4c 69 74 65 if (n != SQLite
9760: 45 72 72 6f 72 43 6f 64 65 2e 4f 6b 29 20 74 68 ErrorCode.Ok) th
9770: 72 6f 77 20 6e 65 77 20 53 51 4c 69 74 65 45 78 row new SQLiteEx
9780: 63 65 70 74 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 ception(n, GetLa
9790: 73 74 45 72 72 6f 72 28 29 29 3b 0d 0a 20 20 20 stError());..
97a0: 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e }.... intern
97b0: 61 6c 20 6f 76 65 72 72 69 64 65 20 76 6f 69 64 al override void
97c0: 20 42 69 6e 64 5f 49 6e 74 36 34 28 53 51 4c 69 Bind_Int64(SQLi
97d0: 74 65 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 teStatement stmt
97e0: 2c 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 , SQLiteConnecti
97f0: 6f 6e 46 6c 61 67 73 20 66 6c 61 67 73 2c 20 69 onFlags flags, i
9800: 6e 74 20 69 6e 64 65 78 2c 20 6c 6f 6e 67 20 76 nt index, long v
9810: 61 6c 75 65 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 alue).. {..
9820: 20 20 20 20 20 20 53 51 4c 69 74 65 53 74 61 74 SQLiteStat
9830: 65 6d 65 6e 74 48 61 6e 64 6c 65 20 68 61 6e 64 ementHandle hand
9840: 6c 65 20 3d 20 73 74 6d 74 2e 5f 73 71 6c 69 74 le = stmt._sqlit
9850: 65 5f 73 74 6d 74 3b 0d 0a 0d 0a 23 69 66 20 21 e_stmt;....#if !
9860: 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 PLATFORM_COMPACT
9870: 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 20 FRAMEWORK..
9880: 20 20 20 69 66 20 28 28 66 6c 61 67 73 20 26 20 if ((flags &
9890: 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e SQLiteConnection
98a0: 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 20 3d Flags.LogBind) =
98b0: 3d 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 = SQLiteConnecti
98c0: 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 onFlags.LogBind)
98d0: 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 .. {..
98e0: 20 20 20 20 20 20 20 20 20 4c 6f 67 42 69 6e 64 LogBind
98f0: 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 (handle, index,
9900: 76 61 6c 75 65 29 3b 0d 0a 20 20 20 20 20 20 20 value);..
9910: 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 53 51 }.... SQ
9920: 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 20 6e 20 LiteErrorCode n
9930: 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 = UnsafeNativeMe
9940: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 62 69 thods.sqlite3_bi
9950: 6e 64 5f 69 6e 74 36 34 28 68 61 6e 64 6c 65 2c nd_int64(handle,
9960: 20 69 6e 64 65 78 2c 20 76 61 6c 75 65 29 3b 0d index, value);.
9970: 0a 23 65 6c 69 66 20 21 53 51 4c 49 54 45 5f 53 .#elif !SQLITE_S
9980: 54 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 20 20 TANDARD..
9990: 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 SQLiteErrorCode
99a0: 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 n = UnsafeNativ
99b0: 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
99c0: 5f 62 69 6e 64 5f 69 6e 74 36 34 5f 69 6e 74 65 _bind_int64_inte
99d0: 72 6f 70 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 rop(handle, inde
99e0: 78 2c 20 72 65 66 20 76 61 6c 75 65 29 3b 0d 0a x, ref value);..
99f0: 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 74 #else.. t
9a00: 68 72 6f 77 20 6e 65 77 20 4e 6f 74 49 6d 70 6c hrow new NotImpl
9a10: 65 6d 65 6e 74 65 64 45 78 63 65 70 74 69 6f 6e ementedException
9a20: 28 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 ();..#endif..
9a30: 20 20 20 20 20 69 66 20 28 6e 20 21 3d 20 53 51 if (n != SQ
9a40: 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 2e 4f 6b LiteErrorCode.Ok
9a50: 29 20 74 68 72 6f 77 20 6e 65 77 20 53 51 4c 69 ) throw new SQLi
9a60: 74 65 45 78 63 65 70 74 69 6f 6e 28 6e 2c 20 47 teException(n, G
9a70: 65 74 4c 61 73 74 45 72 72 6f 72 28 29 29 3b 0d etLastError());.
9a80: 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e . }.... in
9a90: 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 ternal override
9aa0: 76 6f 69 64 20 42 69 6e 64 5f 55 49 6e 74 36 34 void Bind_UInt64
9ab0: 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 (SQLiteStatement
9ac0: 20 73 74 6d 74 2c 20 53 51 4c 69 74 65 43 6f 6e stmt, SQLiteCon
9ad0: 6e 65 63 74 69 6f 6e 46 6c 61 67 73 20 66 6c 61 nectionFlags fla
9ae0: 67 73 2c 20 69 6e 74 20 69 6e 64 65 78 2c 20 75 gs, int index, u
9af0: 6c 6f 6e 67 20 76 61 6c 75 65 29 0d 0a 20 20 20 long value)..
9b00: 20 7b 0d 0a 20 20 20 20 20 20 20 20 53 51 4c 69 {.. SQLi
9b10: 74 65 53 74 61 74 65 6d 65 6e 74 48 61 6e 64 6c teStatementHandl
9b20: 65 20 68 61 6e 64 6c 65 20 3d 20 73 74 6d 74 2e e handle = stmt.
9b30: 5f 73 71 6c 69 74 65 5f 73 74 6d 74 3b 0d 0a 0d _sqlite_stmt;...
9b40: 0a 23 69 66 20 21 50 4c 41 54 46 4f 52 4d 5f 43 .#if !PLATFORM_C
9b50: 4f 4d 50 41 43 54 46 52 41 4d 45 57 4f 52 4b 0d OMPACTFRAMEWORK.
9b60: 0a 20 20 20 20 20 20 20 20 69 66 20 28 28 66 6c . if ((fl
9b70: 61 67 73 20 26 20 53 51 4c 69 74 65 43 6f 6e 6e ags & SQLiteConn
9b80: 65 63 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 ectionFlags.LogB
9b90: 69 6e 64 29 20 3d 3d 20 53 51 4c 69 74 65 43 6f ind) == SQLiteCo
9ba0: 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f nnectionFlags.Lo
9bb0: 67 42 69 6e 64 29 0d 0a 20 20 20 20 20 20 20 20 gBind)..
9bc0: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 4c {.. L
9bd0: 6f 67 42 69 6e 64 28 68 61 6e 64 6c 65 2c 20 69 ogBind(handle, i
9be0: 6e 64 65 78 2c 20 76 61 6c 75 65 29 3b 0d 0a 20 ndex, value);..
9bf0: 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 }....
9c00: 20 20 20 20 53 51 4c 69 74 65 45 72 72 6f 72 43 SQLiteErrorC
9c10: 6f 64 65 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 ode n = UnsafeNa
9c20: 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 tiveMethods.sqli
9c30: 74 65 33 5f 62 69 6e 64 5f 75 69 6e 74 36 34 28 te3_bind_uint64(
9c40: 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 76 handle, index, v
9c50: 61 6c 75 65 29 3b 0d 0a 23 65 6c 69 66 20 21 53 alue);..#elif !S
9c60: 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a QLITE_STANDARD..
9c70: 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 45 72 SQLiteEr
9c80: 72 6f 72 43 6f 64 65 20 6e 20 3d 20 55 6e 73 61 rorCode n = Unsa
9c90: 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
9ca0: 73 71 6c 69 74 65 33 5f 62 69 6e 64 5f 75 69 6e sqlite3_bind_uin
9cb0: 74 36 34 5f 69 6e 74 65 72 6f 70 28 68 61 6e 64 t64_interop(hand
9cc0: 6c 65 2c 20 69 6e 64 65 78 2c 20 72 65 66 20 76 le, index, ref v
9cd0: 61 6c 75 65 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 alue);..#else..
9ce0: 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 77 throw new
9cf0: 20 4e 6f 74 49 6d 70 6c 65 6d 65 6e 74 65 64 45 NotImplementedE
9d00: 78 63 65 70 74 69 6f 6e 28 29 3b 0d 0a 23 65 6e xception();..#en
9d10: 64 69 66 0d 0a 20 20 20 20 20 20 20 20 69 66 20 dif.. if
9d20: 28 6e 20 21 3d 20 53 51 4c 69 74 65 45 72 72 6f (n != SQLiteErro
9d30: 72 43 6f 64 65 2e 4f 6b 29 20 74 68 72 6f 77 20 rCode.Ok) throw
9d40: 6e 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 74 new SQLiteExcept
9d50: 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 72 ion(n, GetLastEr
9d60: 72 6f 72 28 29 29 3b 0d 0a 20 20 20 20 7d 0d 0a ror());.. }..
9d70: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
9d80: 76 65 72 72 69 64 65 20 76 6f 69 64 20 42 69 6e verride void Bin
9d90: 64 5f 54 65 78 74 28 53 51 4c 69 74 65 53 74 61 d_Text(SQLiteSta
9da0: 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 53 51 4c tement stmt, SQL
9db0: 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 iteConnectionFla
9dc0: 67 73 20 66 6c 61 67 73 2c 20 69 6e 74 20 69 6e gs flags, int in
9dd0: 64 65 78 2c 20 73 74 72 69 6e 67 20 76 61 6c 75 dex, string valu
9de0: 65 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 e).. {..
9df0: 20 20 20 53 51 4c 69 74 65 53 74 61 74 65 6d 65 SQLiteStateme
9e00: 6e 74 48 61 6e 64 6c 65 20 68 61 6e 64 6c 65 20 ntHandle handle
9e10: 3d 20 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 = stmt._sqlite_s
9e20: 74 6d 74 3b 0d 0a 0d 0a 23 69 66 20 21 50 4c 41 tmt;....#if !PLA
9e30: 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 41 TFORM_COMPACTFRA
9e40: 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 20 20 20 20 MEWORK..
9e50: 69 66 20 28 28 66 6c 61 67 73 20 26 20 53 51 4c if ((flags & SQL
9e60: 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 iteConnectionFla
9e70: 67 73 2e 4c 6f 67 42 69 6e 64 29 20 3d 3d 20 53 gs.LogBind) == S
9e80: 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 QLiteConnectionF
9e90: 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 0d 0a 20 lags.LogBind)..
9ea0: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
9eb0: 20 20 20 20 20 20 4c 6f 67 42 69 6e 64 28 68 61 LogBind(ha
9ec0: 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 76 61 6c ndle, index, val
9ed0: 75 65 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d ue);.. }.
9ee0: 0a 23 65 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 20 .#endif....
9ef0: 20 20 20 62 79 74 65 5b 5d 20 62 20 3d 20 54 6f byte[] b = To
9f00: 55 54 46 38 28 76 61 6c 75 65 29 3b 0d 0a 0d 0a UTF8(value);....
9f10: 23 69 66 20 21 50 4c 41 54 46 4f 52 4d 5f 43 4f #if !PLATFORM_CO
9f20: 4d 50 41 43 54 46 52 41 4d 45 57 4f 52 4b 0d 0a MPACTFRAMEWORK..
9f30: 20 20 20 20 20 20 20 20 69 66 20 28 28 66 6c 61 if ((fla
9f40: 67 73 20 26 20 53 51 4c 69 74 65 43 6f 6e 6e 65 gs & SQLiteConne
9f50: 63 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 ctionFlags.LogBi
9f60: 6e 64 29 20 3d 3d 20 53 51 4c 69 74 65 43 6f 6e nd) == SQLiteCon
9f70: 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 nectionFlags.Log
9f80: 42 69 6e 64 29 0d 0a 20 20 20 20 20 20 20 20 7b Bind).. {
9f90: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 4c 6f .. Lo
9fa0: 67 42 69 6e 64 28 68 61 6e 64 6c 65 2c 20 69 6e gBind(handle, in
9fb0: 64 65 78 2c 20 62 29 3b 0d 0a 20 20 20 20 20 20 dex, b);..
9fc0: 20 20 7d 0d 0a 23 65 6e 64 69 66 0d 0a 0d 0a 20 }..#endif....
9fd0: 20 20 20 20 20 20 20 53 51 4c 69 74 65 45 72 72 SQLiteErr
9fe0: 6f 72 43 6f 64 65 20 6e 20 3d 20 55 6e 73 61 66 orCode n = 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 62 69 6e 64 5f 74 65 78 74 qlite3_bind_text
a010: 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 (handle, index,
a020: 62 2c 20 62 2e 4c 65 6e 67 74 68 20 2d 20 31 2c b, b.Length - 1,
a030: 20 28 49 6e 74 50 74 72 29 28 2d 31 29 29 3b 0d (IntPtr)(-1));.
a040: 0a 20 20 20 20 20 20 20 20 69 66 20 28 6e 20 21 . if (n !
a050: 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 = SQLiteErrorCod
a060: 65 2e 4f 6b 29 20 74 68 72 6f 77 20 6e 65 77 20 e.Ok) throw new
a070: 53 51 4c 69 74 65 45 78 63 65 70 74 69 6f 6e 28 SQLiteException(
a080: 6e 2c 20 47 65 74 4c 61 73 74 45 72 72 6f 72 28 n, GetLastError(
a090: 29 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 ));.. }....
a0a0: 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
a0b0: 69 64 65 20 76 6f 69 64 20 42 69 6e 64 5f 44 61 ide void Bind_Da
a0c0: 74 65 54 69 6d 65 28 53 51 4c 69 74 65 53 74 61 teTime(SQLiteSta
a0d0: 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 53 51 4c tement stmt, SQL
a0e0: 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 iteConnectionFla
a0f0: 67 73 20 66 6c 61 67 73 2c 20 69 6e 74 20 69 6e gs flags, int in
a100: 64 65 78 2c 20 44 61 74 65 54 69 6d 65 20 64 74 dex, DateTime dt
a110: 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 ).. {..
a120: 20 20 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e SQLiteStatemen
a130: 74 48 61 6e 64 6c 65 20 68 61 6e 64 6c 65 20 3d tHandle handle =
a140: 20 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 stmt._sqlite_st
a150: 6d 74 3b 0d 0a 0d 0a 23 69 66 20 21 50 4c 41 54 mt;....#if !PLAT
a160: 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 41 4d FORM_COMPACTFRAM
a170: 45 57 4f 52 4b 0d 0a 20 20 20 20 20 20 20 20 69 EWORK.. i
a180: 66 20 28 28 66 6c 61 67 73 20 26 20 53 51 4c 69 f ((flags & SQLi
a190: 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 teConnectionFlag
a1a0: 73 2e 4c 6f 67 42 69 6e 64 29 20 3d 3d 20 53 51 s.LogBind) == SQ
a1b0: 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c LiteConnectionFl
a1c0: 61 67 73 2e 4c 6f 67 42 69 6e 64 29 0d 0a 20 20 ags.LogBind)..
a1d0: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
a1e0: 20 20 20 20 20 4c 6f 67 42 69 6e 64 28 68 61 6e LogBind(han
a1f0: 64 6c 65 2c 20 69 6e 64 65 78 2c 20 64 74 29 3b dle, index, dt);
a200: 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a 23 65 6e .. }..#en
a210: 64 69 66 0d 0a 0d 0a 20 20 20 20 20 20 20 20 73 dif.... s
a220: 77 69 74 63 68 20 28 5f 64 61 74 65 74 69 6d 65 witch (_datetime
a230: 46 6f 72 6d 61 74 29 0d 0a 20 20 20 20 20 20 20 Format)..
a240: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
a250: 63 61 73 65 20 53 51 4c 69 74 65 44 61 74 65 46 case SQLiteDateF
a260: 6f 72 6d 61 74 73 2e 54 69 63 6b 73 3a 0d 0a 20 ormats.Ticks:..
a270: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7b {
a280: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
a290: 20 20 20 20 20 20 6c 6f 6e 67 20 76 61 6c 75 65 long value
a2a0: 20 3d 20 64 74 2e 54 69 63 6b 73 3b 0d 0a 0d 0a = dt.Ticks;....
a2b0: 23 69 66 20 21 50 4c 41 54 46 4f 52 4d 5f 43 4f #if !PLATFORM_CO
a2c0: 4d 50 41 43 54 46 52 41 4d 45 57 4f 52 4b 0d 0a MPACTFRAMEWORK..
a2d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a2e0: 20 20 20 20 69 66 20 28 28 66 6c 61 67 73 20 26 if ((flags &
a2f0: 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f SQLiteConnectio
a300: 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 20 nFlags.LogBind)
a310: 3d 3d 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 == SQLiteConnect
a320: 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 ionFlags.LogBind
a330: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 )..
a340: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
a350: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a360: 20 20 4c 6f 67 42 69 6e 64 28 68 61 6e 64 6c 65 LogBind(handle
a370: 2c 20 69 6e 64 65 78 2c 20 76 61 6c 75 65 29 3b , index, value);
a380: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
a390: 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 }....
a3a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 53 S
a3b0: 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 20 6e QLiteErrorCode n
a3c0: 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d = UnsafeNativeM
a3d0: 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 62 ethods.sqlite3_b
a3e0: 69 6e 64 5f 69 6e 74 36 34 28 68 61 6e 64 6c 65 ind_int64(handle
a3f0: 2c 20 69 6e 64 65 78 2c 20 76 61 6c 75 65 29 3b , index, value);
a400: 0d 0a 23 65 6c 69 66 20 21 53 51 4c 49 54 45 5f ..#elif !SQLITE_
a410: 53 54 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 20 STANDARD..
a420: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 53 51 SQ
a430: 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 20 6e 20 LiteErrorCode n
a440: 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 = UnsafeNativeMe
a450: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 62 69 thods.sqlite3_bi
a460: 6e 64 5f 69 6e 74 36 34 5f 69 6e 74 65 72 6f 70 nd_int64_interop
a470: 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 (handle, index,
a480: 72 65 66 20 76 61 6c 75 65 29 3b 0d 0a 23 65 6c ref value);..#el
a490: 73 65 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 se..
a4a0: 20 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 throw ne
a4b0: 77 20 4e 6f 74 49 6d 70 6c 65 6d 65 6e 74 65 64 w NotImplemented
a4c0: 45 78 63 65 70 74 69 6f 6e 28 29 3b 0d 0a 23 65 Exception();..#e
a4d0: 6e 64 69 66 0d 0a 20 20 20 20 20 20 20 20 20 20 ndif..
a4e0: 20 20 20 20 20 20 20 20 20 20 69 66 20 28 6e 20 if (n
a4f0: 21 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f != SQLiteErrorCo
a500: 64 65 2e 4f 6b 29 20 74 68 72 6f 77 20 6e 65 77 de.Ok) throw new
a510: 20 53 51 4c 69 74 65 45 78 63 65 70 74 69 6f 6e SQLiteException
a520: 28 6e 2c 20 47 65 74 4c 61 73 74 45 72 72 6f 72 (n, GetLastError
a530: 28 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 ());..
a540: 20 20 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b break;
a550: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
a560: 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 20 20 20 }..
a570: 20 63 61 73 65 20 53 51 4c 69 74 65 44 61 74 65 case SQLiteDate
a580: 46 6f 72 6d 61 74 73 2e 4a 75 6c 69 61 6e 44 61 Formats.JulianDa
a590: 79 3a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 y:..
a5a0: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 {..
a5b0: 20 20 20 20 20 20 20 20 20 20 20 64 6f 75 62 6c doubl
a5c0: 65 20 76 61 6c 75 65 20 3d 20 54 6f 4a 75 6c 69 e value = ToJuli
a5d0: 61 6e 44 61 79 28 64 74 29 3b 0d 0a 0d 0a 23 69 anDay(dt);....#i
a5e0: 66 20 21 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d 50 f !PLATFORM_COMP
a5f0: 41 43 54 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 20 ACTFRAMEWORK..
a600: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a610: 20 20 69 66 20 28 28 66 6c 61 67 73 20 26 20 53 if ((flags & S
a620: 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 QLiteConnectionF
a630: 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 20 3d 3d lags.LogBind) ==
a640: 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f SQLiteConnectio
a650: 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 0d nFlags.LogBind).
a660: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
a670: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
a680: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a690: 4c 6f 67 42 69 6e 64 28 68 61 6e 64 6c 65 2c 20 LogBind(handle,
a6a0: 69 6e 64 65 78 2c 20 76 61 6c 75 65 29 3b 0d 0a index, value);..
a6b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a6c0: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 }....
a6d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 53 51 4c SQL
a6e0: 69 74 65 45 72 72 6f 72 43 6f 64 65 20 6e 20 3d iteErrorCode n =
a6f0: 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 UnsafeNativeMet
a700: 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 62 69 6e hods.sqlite3_bin
a710: 64 5f 64 6f 75 62 6c 65 28 68 61 6e 64 6c 65 2c d_double(handle,
a720: 20 69 6e 64 65 78 2c 20 76 61 6c 75 65 29 3b 0d index, value);.
a730: 0a 23 65 6c 69 66 20 21 53 51 4c 49 54 45 5f 53 .#elif !SQLITE_S
a740: 54 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 20 20 TANDARD..
a750: 20 20 20 20 20 20 20 20 20 20 20 20 20 53 51 4c SQL
a760: 69 74 65 45 72 72 6f 72 43 6f 64 65 20 6e 20 3d iteErrorCode n =
a770: 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 UnsafeNativeMet
a780: 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 62 69 6e hods.sqlite3_bin
a790: 64 5f 64 6f 75 62 6c 65 5f 69 6e 74 65 72 6f 70 d_double_interop
a7a0: 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 (handle, index,
a7b0: 72 65 66 20 76 61 6c 75 65 29 3b 0d 0a 23 65 6c ref value);..#el
a7c0: 73 65 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 se..
a7d0: 20 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 throw ne
a7e0: 77 20 4e 6f 74 49 6d 70 6c 65 6d 65 6e 74 65 64 w NotImplemented
a7f0: 45 78 63 65 70 74 69 6f 6e 28 29 3b 0d 0a 23 65 Exception();..#e
a800: 6e 64 69 66 0d 0a 20 20 20 20 20 20 20 20 20 20 ndif..
a810: 20 20 20 20 20 20 20 20 20 20 69 66 20 28 6e 20 if (n
a820: 21 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f != SQLiteErrorCo
a830: 64 65 2e 4f 6b 29 20 74 68 72 6f 77 20 6e 65 77 de.Ok) throw new
a840: 20 53 51 4c 69 74 65 45 78 63 65 70 74 69 6f 6e SQLiteException
a850: 28 6e 2c 20 47 65 74 4c 61 73 74 45 72 72 6f 72 (n, GetLastError
a860: 28 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 ());..
a870: 20 20 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b break;
a880: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
a890: 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 20 20 20 }..
a8a0: 20 63 61 73 65 20 53 51 4c 69 74 65 44 61 74 65 case SQLiteDate
a8b0: 46 6f 72 6d 61 74 73 2e 55 6e 69 78 45 70 6f 63 Formats.UnixEpoc
a8c0: 68 3a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 h:..
a8d0: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 {..
a8e0: 20 20 20 20 20 20 20 20 20 20 20 6c 6f 6e 67 20 long
a8f0: 76 61 6c 75 65 20 3d 20 43 6f 6e 76 65 72 74 2e value = Convert.
a900: 54 6f 49 6e 74 36 34 28 64 74 2e 53 75 62 74 72 ToInt64(dt.Subtr
a910: 61 63 74 28 55 6e 69 78 45 70 6f 63 68 29 2e 54 act(UnixEpoch).T
a920: 6f 74 61 6c 53 65 63 6f 6e 64 73 29 3b 0d 0a 0d otalSeconds);...
a930: 0a 23 69 66 20 21 50 4c 41 54 46 4f 52 4d 5f 43 .#if !PLATFORM_C
a940: 4f 4d 50 41 43 54 46 52 41 4d 45 57 4f 52 4b 0d OMPACTFRAMEWORK.
a950: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
a960: 20 20 20 20 20 69 66 20 28 28 66 6c 61 67 73 20 if ((flags
a970: 26 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 & SQLiteConnecti
a980: 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 onFlags.LogBind)
a990: 20 3d 3d 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 == SQLiteConnec
a9a0: 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e tionFlags.LogBin
a9b0: 64 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 d)..
a9c0: 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 {..
a9d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a9e0: 20 20 20 4c 6f 67 42 69 6e 64 28 68 61 6e 64 6c LogBind(handl
a9f0: 65 2c 20 69 6e 64 65 78 2c 20 76 61 6c 75 65 29 e, index, value)
aa00: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ;..
aa10: 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 }....
aa20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
aa30: 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 20 SQLiteErrorCode
aa40: 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 n = UnsafeNative
aa50: 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f Methods.sqlite3_
aa60: 62 69 6e 64 5f 69 6e 74 36 34 28 68 61 6e 64 6c bind_int64(handl
aa70: 65 2c 20 69 6e 64 65 78 2c 20 76 61 6c 75 65 29 e, index, value)
aa80: 3b 0d 0a 23 65 6c 69 66 20 21 53 51 4c 49 54 45 ;..#elif !SQLITE
aa90: 5f 53 54 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 _STANDARD..
aaa0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 53 S
aab0: 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 20 6e QLiteErrorCode n
aac0: 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d = UnsafeNativeM
aad0: 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 62 ethods.sqlite3_b
aae0: 69 6e 64 5f 69 6e 74 36 34 5f 69 6e 74 65 72 6f ind_int64_intero
aaf0: 70 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 2c p(handle, index,
ab00: 20 72 65 66 20 76 61 6c 75 65 29 3b 0d 0a 23 65 ref value);..#e
ab10: 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 20 20 20 lse..
ab20: 20 20 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e throw n
ab30: 65 77 20 4e 6f 74 49 6d 70 6c 65 6d 65 6e 74 65 ew NotImplemente
ab40: 64 45 78 63 65 70 74 69 6f 6e 28 29 3b 0d 0a 23 dException();..#
ab50: 65 6e 64 69 66 0d 0a 20 20 20 20 20 20 20 20 20 endif..
ab60: 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 6e if (n
ab70: 20 21 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 43 != SQLiteErrorC
ab80: 6f 64 65 2e 4f 6b 29 20 74 68 72 6f 77 20 6e 65 ode.Ok) throw ne
ab90: 77 20 53 51 4c 69 74 65 45 78 63 65 70 74 69 6f w SQLiteExceptio
aba0: 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 72 72 6f n(n, GetLastErro
abb0: 72 28 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 r());..
abc0: 20 20 20 20 20 20 20 20 20 20 20 62 72 65 61 6b break
abd0: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ;..
abe0: 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 20 20 }..
abf0: 20 20 64 65 66 61 75 6c 74 3a 0d 0a 20 20 20 20 default:..
ac00: 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 {..
ac10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
ac20: 20 20 20 62 79 74 65 5b 5d 20 62 20 3d 20 54 6f byte[] b = To
ac30: 55 54 46 38 28 64 74 29 3b 0d 0a 0d 0a 23 69 66 UTF8(dt);....#if
ac40: 20 21 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 !PLATFORM_COMPA
ac50: 43 54 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 CTFRAMEWORK..
ac60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
ac70: 20 69 66 20 28 28 66 6c 61 67 73 20 26 20 53 51 if ((flags & SQ
ac80: 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c LiteConnectionFl
ac90: 61 67 73 2e 4c 6f 67 42 69 6e 64 29 20 3d 3d 20 ags.LogBind) ==
aca0: 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e SQLiteConnection
acb0: 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 0d 0a Flags.LogBind)..
acc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
acd0: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 {..
ace0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 4c L
acf0: 6f 67 42 69 6e 64 28 68 61 6e 64 6c 65 2c 20 69 ogBind(handle, i
ad00: 6e 64 65 78 2c 20 62 29 3b 0d 0a 20 20 20 20 20 ndex, b);..
ad10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d }
ad20: 0d 0a 23 65 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 ..#endif....
ad30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
ad40: 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 20 SQLiteErrorCode
ad50: 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 n = UnsafeNative
ad60: 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f Methods.sqlite3_
ad70: 62 69 6e 64 5f 74 65 78 74 28 68 61 6e 64 6c 65 bind_text(handle
ad80: 2c 20 69 6e 64 65 78 2c 20 62 2c 20 62 2e 4c 65 , index, b, b.Le
ad90: 6e 67 74 68 20 2d 20 31 2c 20 28 49 6e 74 50 74 ngth - 1, (IntPt
ada0: 72 29 28 2d 31 29 29 3b 0d 0a 20 20 20 20 20 20 r)(-1));..
adb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 if
adc0: 20 28 6e 20 21 3d 20 53 51 4c 69 74 65 45 72 72 (n != SQLiteErr
add0: 6f 72 43 6f 64 65 2e 4f 6b 29 20 74 68 72 6f 77 orCode.Ok) throw
ade0: 20 6e 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 new SQLiteExcep
adf0: 74 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 tion(n, GetLastE
ae00: 72 72 6f 72 28 29 29 3b 0d 0a 20 20 20 20 20 20 rror());..
ae10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 62 72 br
ae20: 65 61 6b 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 eak;..
ae30: 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 }..
ae40: 20 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 }.. }....
ae50: 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 internal overri
ae60: 64 65 20 76 6f 69 64 20 42 69 6e 64 5f 42 6c 6f de void Bind_Blo
ae70: 62 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e b(SQLiteStatemen
ae80: 74 20 73 74 6d 74 2c 20 53 51 4c 69 74 65 43 6f t stmt, SQLiteCo
ae90: 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 20 66 6c nnectionFlags fl
aea0: 61 67 73 2c 20 69 6e 74 20 69 6e 64 65 78 2c 20 ags, int index,
aeb0: 62 79 74 65 5b 5d 20 62 6c 6f 62 44 61 74 61 29 byte[] blobData)
aec0: 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 .. {..
aed0: 20 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 SQLiteStatement
aee0: 48 61 6e 64 6c 65 20 68 61 6e 64 6c 65 20 3d 20 Handle handle =
aef0: 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 6d stmt._sqlite_stm
af00: 74 3b 0d 0a 0d 0a 23 69 66 20 21 50 4c 41 54 46 t;....#if !PLATF
af10: 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 41 4d 45 ORM_COMPACTFRAME
af20: 57 4f 52 4b 0d 0a 20 20 20 20 20 20 20 20 69 66 WORK.. if
af30: 20 28 28 66 6c 61 67 73 20 26 20 53 51 4c 69 74 ((flags & SQLit
af40: 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 eConnectionFlags
af50: 2e 4c 6f 67 42 69 6e 64 29 20 3d 3d 20 53 51 4c .LogBind) == SQL
af60: 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 iteConnectionFla
af70: 67 73 2e 4c 6f 67 42 69 6e 64 29 0d 0a 20 20 20 gs.LogBind)..
af80: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
af90: 20 20 20 20 4c 6f 67 42 69 6e 64 28 68 61 6e 64 LogBind(hand
afa0: 6c 65 2c 20 69 6e 64 65 78 2c 20 62 6c 6f 62 44 le, index, blobD
afb0: 61 74 61 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d ata);.. }
afc0: 0d 0a 23 65 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 ..#endif....
afd0: 20 20 20 20 53 51 4c 69 74 65 45 72 72 6f 72 43 SQLiteErrorC
afe0: 6f 64 65 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 ode n = UnsafeNa
aff0: 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 tiveMethods.sqli
b000: 74 65 33 5f 62 69 6e 64 5f 62 6c 6f 62 28 68 61 te3_bind_blob(ha
b010: 6e 64 6c 65 2c 20 69 6e 64 65 78 2c 20 62 6c 6f ndle, index, blo
b020: 62 44 61 74 61 2c 20 62 6c 6f 62 44 61 74 61 2e bData, blobData.
b030: 4c 65 6e 67 74 68 2c 20 28 49 6e 74 50 74 72 29 Length, (IntPtr)
b040: 28 2d 31 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 (-1));..
b050: 69 66 20 28 6e 20 21 3d 20 53 51 4c 69 74 65 45 if (n != SQLiteE
b060: 72 72 6f 72 43 6f 64 65 2e 4f 6b 29 20 74 68 72 rrorCode.Ok) thr
b070: 6f 77 20 6e 65 77 20 53 51 4c 69 74 65 45 78 63 ow new SQLiteExc
b080: 65 70 74 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 eption(n, GetLas
b090: 74 45 72 72 6f 72 28 29 29 3b 0d 0a 20 20 20 20 tError());..
b0a0: 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 }.... interna
b0b0: 6c 20 6f 76 65 72 72 69 64 65 20 76 6f 69 64 20 l override void
b0c0: 42 69 6e 64 5f 4e 75 6c 6c 28 53 51 4c 69 74 65 Bind_Null(SQLite
b0d0: 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 Statement stmt,
b0e0: 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e SQLiteConnection
b0f0: 46 6c 61 67 73 20 66 6c 61 67 73 2c 20 69 6e 74 Flags flags, int
b100: 20 69 6e 64 65 78 29 0d 0a 20 20 20 20 7b 0d 0a index).. {..
b110: 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 53 74 SQLiteSt
b120: 61 74 65 6d 65 6e 74 48 61 6e 64 6c 65 20 68 61 atementHandle ha
b130: 6e 64 6c 65 20 3d 20 73 74 6d 74 2e 5f 73 71 6c ndle = stmt._sql
b140: 69 74 65 5f 73 74 6d 74 3b 0d 0a 0d 0a 23 69 66 ite_stmt;....#if
b150: 20 21 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 !PLATFORM_COMPA
b160: 43 54 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 CTFRAMEWORK..
b170: 20 20 20 20 20 69 66 20 28 28 66 6c 61 67 73 20 if ((flags
b180: 26 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 & SQLiteConnecti
b190: 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 onFlags.LogBind)
b1a0: 20 3d 3d 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 == SQLiteConnec
b1b0: 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e tionFlags.LogBin
b1c0: 64 29 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 d).. {..
b1d0: 20 20 20 20 20 20 20 20 20 20 20 4c 6f 67 42 69 LogBi
b1e0: 6e 64 28 68 61 6e 64 6c 65 2c 20 69 6e 64 65 78 nd(handle, index
b1f0: 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a 23 );.. }..#
b200: 65 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 20 20 20 endif....
b210: 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 SQLiteErrorCode
b220: 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 n = UnsafeNativ
b230: 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
b240: 5f 62 69 6e 64 5f 6e 75 6c 6c 28 68 61 6e 64 6c _bind_null(handl
b250: 65 2c 20 69 6e 64 65 78 29 3b 0d 0a 20 20 20 20 e, index);..
b260: 20 20 20 20 69 66 20 28 6e 20 21 3d 20 53 51 4c if (n != SQL
b270: 69 74 65 45 72 72 6f 72 43 6f 64 65 2e 4f 6b 29 iteErrorCode.Ok)
b280: 20 74 68 72 6f 77 20 6e 65 77 20 53 51 4c 69 74 throw new SQLit
b290: 65 45 78 63 65 70 74 69 6f 6e 28 6e 2c 20 47 65 eException(n, Ge
b2a0: 74 4c 61 73 74 45 72 72 6f 72 28 29 29 3b 0d 0a tLastError());..
b2b0: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 }.... int
b2c0: 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 69 ernal override i
b2d0: 6e 74 20 42 69 6e 64 5f 50 61 72 61 6d 43 6f 75 nt Bind_ParamCou
b2e0: 6e 74 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 nt(SQLiteStateme
b2f0: 6e 74 20 73 74 6d 74 2c 20 53 51 4c 69 74 65 43 nt stmt, SQLiteC
b300: 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 20 66 onnectionFlags f
b310: 6c 61 67 73 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 lags).. {..
b320: 20 20 20 20 20 20 53 51 4c 69 74 65 53 74 61 74 SQLiteStat
b330: 65 6d 65 6e 74 48 61 6e 64 6c 65 20 68 61 6e 64 ementHandle hand
b340: 6c 65 20 3d 20 73 74 6d 74 2e 5f 73 71 6c 69 74 le = stmt._sqlit
b350: 65 5f 73 74 6d 74 3b 0d 0a 20 20 20 20 20 20 20 e_stmt;..
b360: 20 69 6e 74 20 76 61 6c 75 65 20 3d 20 55 6e 73 int value = Uns
b370: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
b380: 2e 73 71 6c 69 74 65 33 5f 62 69 6e 64 5f 70 61 .sqlite3_bind_pa
b390: 72 61 6d 65 74 65 72 5f 63 6f 75 6e 74 28 68 61 rameter_count(ha
b3a0: 6e 64 6c 65 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 ndle);....
b3b0: 20 20 69 66 20 28 28 66 6c 61 67 73 20 26 20 53 if ((flags & S
b3c0: 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 QLiteConnectionF
b3d0: 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 20 3d 3d lags.LogBind) ==
b3e0: 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f SQLiteConnectio
b3f0: 6e 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 0d nFlags.LogBind).
b400: 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 . {..
b410: 20 20 20 20 20 20 20 20 49 6e 74 50 74 72 20 68 IntPtr h
b420: 61 6e 64 6c 65 49 6e 74 50 74 72 20 3d 20 68 61 andleIntPtr = ha
b430: 6e 64 6c 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 ndle;....
b440: 20 20 20 20 20 53 51 4c 69 74 65 4c 6f 67 2e 4c SQLiteLog.L
b450: 6f 67 4d 65 73 73 61 67 65 28 53 74 72 69 6e 67 ogMessage(String
b460: 2e 46 6f 72 6d 61 74 28 0d 0a 20 20 20 20 20 20 .Format(..
b470: 20 20 20 20 20 20 20 20 20 20 43 75 6c 74 75 72 Cultur
b480: 65 49 6e 66 6f 2e 43 75 72 72 65 6e 74 43 75 6c eInfo.CurrentCul
b490: 74 75 72 65 2c 0d 0a 20 20 20 20 20 20 20 20 20 ture,..
b4a0: 20 20 20 20 20 20 20 22 53 74 61 74 65 6d 65 6e "Statemen
b4b0: 74 20 7b 30 7d 20 70 61 72 61 6d 74 65 72 20 63 t {0} paramter c
b4c0: 6f 75 6e 74 20 69 73 20 7b 31 7d 2e 22 2c 0d 0a ount is {1}.",..
b4d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b4e0: 68 61 6e 64 6c 65 49 6e 74 50 74 72 2c 20 76 61 handleIntPtr, va
b4f0: 6c 75 65 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 lue));..
b500: 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 72 65 74 }.... ret
b510: 75 72 6e 20 76 61 6c 75 65 3b 0d 0a 20 20 20 20 urn value;..
b520: 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 }.... interna
b530: 6c 20 6f 76 65 72 72 69 64 65 20 73 74 72 69 6e l override strin
b540: 67 20 42 69 6e 64 5f 50 61 72 61 6d 4e 61 6d 65 g Bind_ParamName
b550: 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 (SQLiteStatement
b560: 20 73 74 6d 74 2c 20 53 51 4c 69 74 65 43 6f 6e stmt, SQLiteCon
b570: 6e 65 63 74 69 6f 6e 46 6c 61 67 73 20 66 6c 61 nectionFlags fla
b580: 67 73 2c 20 69 6e 74 20 69 6e 64 65 78 29 0d 0a gs, int index)..
b590: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 53 {.. S
b5a0: 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 48 61 QLiteStatementHa
b5b0: 6e 64 6c 65 20 68 61 6e 64 6c 65 20 3d 20 73 74 ndle handle = st
b5c0: 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 6d 74 3b mt._sqlite_stmt;
b5d0: 0d 0a 20 20 20 20 20 20 20 20 73 74 72 69 6e 67 .. string
b5e0: 20 6e 61 6d 65 3b 0d 0a 0d 0a 23 69 66 20 21 53 name;....#if !S
b5f0: 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a QLITE_STANDARD..
b600: 20 20 20 20 20 20 20 20 69 6e 74 20 6c 65 6e 3b int len;
b610: 0d 0a 20 20 20 20 20 20 20 20 6e 61 6d 65 20 3d .. name =
b620: 20 55 54 46 38 54 6f 53 74 72 69 6e 67 28 55 6e UTF8ToString(Un
b630: 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 safeNativeMethod
b640: 73 2e 73 71 6c 69 74 65 33 5f 62 69 6e 64 5f 70 s.sqlite3_bind_p
b650: 61 72 61 6d 65 74 65 72 5f 6e 61 6d 65 5f 69 6e arameter_name_in
b660: 74 65 72 6f 70 28 68 61 6e 64 6c 65 2c 20 69 6e terop(handle, in
b670: 64 65 78 2c 20 6f 75 74 20 6c 65 6e 29 2c 20 6c dex, out len), l
b680: 65 6e 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 en);..#else..
b690: 20 20 20 20 20 6e 61 6d 65 20 3d 20 55 54 46 38 name = UTF8
b6a0: 54 6f 53 74 72 69 6e 67 28 55 6e 73 61 66 65 4e ToString(UnsafeN
b6b0: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
b6c0: 69 74 65 33 5f 62 69 6e 64 5f 70 61 72 61 6d 65 ite3_bind_parame
b6d0: 74 65 72 5f 6e 61 6d 65 28 68 61 6e 64 6c 65 2c ter_name(handle,
b6e0: 20 69 6e 64 65 78 29 2c 20 2d 31 29 3b 0d 0a 23 index), -1);..#
b6f0: 65 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 20 20 20 endif....
b700: 20 69 66 20 28 28 66 6c 61 67 73 20 26 20 53 51 if ((flags & SQ
b710: 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c LiteConnectionFl
b720: 61 67 73 2e 4c 6f 67 42 69 6e 64 29 20 3d 3d 20 ags.LogBind) ==
b730: 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e SQLiteConnection
b740: 46 6c 61 67 73 2e 4c 6f 67 42 69 6e 64 29 0d 0a Flags.LogBind)..
b750: 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 {..
b760: 20 20 20 20 20 20 20 49 6e 74 50 74 72 20 68 61 IntPtr ha
b770: 6e 64 6c 65 49 6e 74 50 74 72 20 3d 20 68 61 6e ndleIntPtr = han
b780: 64 6c 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 dle;....
b790: 20 20 20 20 53 51 4c 69 74 65 4c 6f 67 2e 4c 6f SQLiteLog.Lo
b7a0: 67 4d 65 73 73 61 67 65 28 53 74 72 69 6e 67 2e gMessage(String.
b7b0: 46 6f 72 6d 61 74 28 0d 0a 20 20 20 20 20 20 20 Format(..
b7c0: 20 20 20 20 20 20 20 20 20 43 75 6c 74 75 72 65 Culture
b7d0: 49 6e 66 6f 2e 43 75 72 72 65 6e 74 43 75 6c 74 Info.CurrentCult
b7e0: 75 72 65 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 ure,..
b7f0: 20 20 20 20 20 20 22 53 74 61 74 65 6d 65 6e 74 "Statement
b800: 20 7b 30 7d 20 70 61 72 61 6d 74 65 72 20 23 7b {0} paramter #{
b810: 31 7d 20 6e 61 6d 65 20 69 73 20 7b 7b 7b 32 7d 1} name is {{{2}
b820: 7d 7d 2e 22 2c 0d 0a 20 20 20 20 20 20 20 20 20 }}.",..
b830: 20 20 20 20 20 20 20 68 61 6e 64 6c 65 49 6e 74 handleInt
b840: 50 74 72 2c 20 69 6e 64 65 78 2c 20 6e 61 6d 65 Ptr, index, name
b850: 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a ));.. }..
b860: 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e .. return
b870: 20 6e 61 6d 65 3b 0d 0a 20 20 20 20 7d 0d 0a 0d name;.. }...
b880: 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 . internal ov
b890: 65 72 72 69 64 65 20 69 6e 74 20 42 69 6e 64 5f erride int Bind_
b8a0: 50 61 72 61 6d 49 6e 64 65 78 28 53 51 4c 69 74 ParamIndex(SQLit
b8b0: 65 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c eStatement stmt,
b8c0: 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f SQLiteConnectio
b8d0: 6e 46 6c 61 67 73 20 66 6c 61 67 73 2c 20 73 74 nFlags flags, st
b8e0: 72 69 6e 67 20 70 61 72 61 6d 4e 61 6d 65 29 0d ring paramName).
b8f0: 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 . {..
b900: 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 48 SQLiteStatementH
b910: 61 6e 64 6c 65 20 68 61 6e 64 6c 65 20 3d 20 73 andle handle = s
b920: 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 6d 74 tmt._sqlite_stmt
b930: 3b 0d 0a 20 20 20 20 20 20 20 20 69 6e 74 20 69 ;.. int i
b940: 6e 64 65 78 20 3d 20 55 6e 73 61 66 65 4e 61 74 ndex = UnsafeNat
b950: 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 iveMethods.sqlit
b960: 65 33 5f 62 69 6e 64 5f 70 61 72 61 6d 65 74 65 e3_bind_paramete
b970: 72 5f 69 6e 64 65 78 28 68 61 6e 64 6c 65 2c 20 r_index(handle,
b980: 54 6f 55 54 46 38 28 70 61 72 61 6d 4e 61 6d 65 ToUTF8(paramName
b990: 29 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 ));.... i
b9a0: 66 20 28 28 66 6c 61 67 73 20 26 20 53 51 4c 69 f ((flags & SQLi
b9b0: 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 teConnectionFlag
b9c0: 73 2e 4c 6f 67 42 69 6e 64 29 20 3d 3d 20 53 51 s.LogBind) == SQ
b9d0: 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c LiteConnectionFl
b9e0: 61 67 73 2e 4c 6f 67 42 69 6e 64 29 0d 0a 20 20 ags.LogBind)..
b9f0: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
ba00: 20 20 20 20 20 49 6e 74 50 74 72 20 68 61 6e 64 IntPtr hand
ba10: 6c 65 49 6e 74 50 74 72 20 3d 20 68 61 6e 64 6c leIntPtr = handl
ba20: 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 e;....
ba30: 20 20 53 51 4c 69 74 65 4c 6f 67 2e 4c 6f 67 4d SQLiteLog.LogM
ba40: 65 73 73 61 67 65 28 53 74 72 69 6e 67 2e 46 6f essage(String.Fo
ba50: 72 6d 61 74 28 0d 0a 20 20 20 20 20 20 20 20 20 rmat(..
ba60: 20 20 20 20 20 20 20 43 75 6c 74 75 72 65 49 6e CultureIn
ba70: 66 6f 2e 43 75 72 72 65 6e 74 43 75 6c 74 75 72 fo.CurrentCultur
ba80: 65 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 e,..
ba90: 20 20 20 20 22 53 74 61 74 65 6d 65 6e 74 20 7b "Statement {
baa0: 30 7d 20 70 61 72 61 6d 74 65 72 20 69 6e 64 65 0} paramter inde
bab0: 78 20 6f 66 20 6e 61 6d 65 20 7b 7b 7b 31 7d 7d x of name {{{1}}
bac0: 7d 20 69 73 20 23 7b 32 7d 2e 22 2c 0d 0a 20 20 } is #{2}.",..
bad0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 68 61 ha
bae0: 6e 64 6c 65 49 6e 74 50 74 72 2c 20 70 61 72 61 ndleIntPtr, para
baf0: 6d 4e 61 6d 65 2c 20 69 6e 64 65 78 29 29 3b 0d mName, index));.
bb00: 0a 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 . }....
bb10: 20 20 20 20 20 20 72 65 74 75 72 6e 20 69 6e 64 return ind
bb20: 65 78 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 ex;.. }....
bb30: 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
bb40: 69 64 65 20 69 6e 74 20 43 6f 6c 75 6d 6e 43 6f ide int ColumnCo
bb50: 75 6e 74 28 53 51 4c 69 74 65 53 74 61 74 65 6d unt(SQLiteStatem
bb60: 65 6e 74 20 73 74 6d 74 29 0d 0a 20 20 20 20 7b ent stmt).. {
bb70: 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 55 .. return U
bb80: 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
bb90: 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f 6c 75 6d ds.sqlite3_colum
bba0: 6e 5f 63 6f 75 6e 74 28 73 74 6d 74 2e 5f 73 71 n_count(stmt._sq
bbb0: 6c 69 74 65 5f 73 74 6d 74 29 3b 0d 0a 20 20 20 lite_stmt);..
bbc0: 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e }.... intern
bbd0: 61 6c 20 6f 76 65 72 72 69 64 65 20 73 74 72 69 al override stri
bbe0: 6e 67 20 43 6f 6c 75 6d 6e 4e 61 6d 65 28 53 51 ng ColumnName(SQ
bbf0: 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 20 73 74 LiteStatement st
bc00: 6d 74 2c 20 69 6e 74 20 69 6e 64 65 78 29 0d 0a mt, int index)..
bc10: 20 20 20 20 7b 0d 0a 23 69 66 20 21 53 51 4c 49 {..#if !SQLI
bc20: 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a 20 20 20 TE_STANDARD..
bc30: 20 20 20 69 6e 74 20 6c 65 6e 3b 0d 0a 20 20 20 int len;..
bc40: 20 20 20 49 6e 74 50 74 72 20 70 20 3d 20 55 6e IntPtr p = Un
bc50: 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 safeNativeMethod
bc60: 73 2e 73 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e s.sqlite3_column
bc70: 5f 6e 61 6d 65 5f 69 6e 74 65 72 6f 70 28 73 74 _name_interop(st
bc80: 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 6d 74 2c mt._sqlite_stmt,
bc90: 20 69 6e 64 65 78 2c 20 6f 75 74 20 6c 65 6e 29 index, out len)
bca0: 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 ;..#else..
bcb0: 49 6e 74 50 74 72 20 70 20 3d 20 55 6e 73 61 66 IntPtr p = Unsaf
bcc0: 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
bcd0: 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f 6e 61 qlite3_column_na
bce0: 6d 65 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f me(stmt._sqlite_
bcf0: 73 74 6d 74 2c 20 69 6e 64 65 78 29 3b 0d 0a 23 stmt, index);..#
bd00: 65 6e 64 69 66 0d 0a 20 20 20 20 20 20 69 66 20 endif.. if
bd10: 28 70 20 3d 3d 20 49 6e 74 50 74 72 2e 5a 65 72 (p == IntPtr.Zer
bd20: 6f 29 0d 0a 20 20 20 20 20 20 20 20 74 68 72 6f o).. thro
bd30: 77 20 6e 65 77 20 53 51 4c 69 74 65 45 78 63 65 w new SQLiteExce
bd40: 70 74 69 6f 6e 28 53 51 4c 69 74 65 45 72 72 6f ption(SQLiteErro
bd50: 72 43 6f 64 65 2e 4e 6f 4d 65 6d 2c 20 47 65 74 rCode.NoMem, Get
bd60: 4c 61 73 74 45 72 72 6f 72 28 29 29 3b 0d 0a 23 LastError());..#
bd70: 69 66 20 21 53 51 4c 49 54 45 5f 53 54 41 4e 44 if !SQLITE_STAND
bd80: 41 52 44 0d 0a 20 20 20 20 20 20 72 65 74 75 72 ARD.. retur
bd90: 6e 20 55 54 46 38 54 6f 53 74 72 69 6e 67 28 70 n UTF8ToString(p
bda0: 2c 20 6c 65 6e 29 3b 0d 0a 23 65 6c 73 65 0d 0a , len);..#else..
bdb0: 20 20 20 20 20 20 72 65 74 75 72 6e 20 55 54 46 return UTF
bdc0: 38 54 6f 53 74 72 69 6e 67 28 70 2c 20 2d 31 29 8ToString(p, -1)
bdd0: 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 7d ;..#endif.. }
bde0: 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c .... internal
bdf0: 20 6f 76 65 72 72 69 64 65 20 54 79 70 65 41 66 override TypeAf
be00: 66 69 6e 69 74 79 20 43 6f 6c 75 6d 6e 41 66 66 finity ColumnAff
be10: 69 6e 69 74 79 28 53 51 4c 69 74 65 53 74 61 74 inity(SQLiteStat
be20: 65 6d 65 6e 74 20 73 74 6d 74 2c 20 69 6e 74 20 ement stmt, int
be30: 69 6e 64 65 78 29 0d 0a 20 20 20 20 7b 0d 0a 20 index).. {..
be40: 20 20 20 20 20 72 65 74 75 72 6e 20 55 6e 73 61 return Unsa
be50: 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
be60: 73 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f 74 sqlite3_column_t
be70: 79 70 65 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 ype(stmt._sqlite
be80: 5f 73 74 6d 74 2c 20 69 6e 64 65 78 29 3b 0d 0a _stmt, index);..
be90: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 }.... int
bea0: 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 73 ernal override s
beb0: 74 72 69 6e 67 20 43 6f 6c 75 6d 6e 54 79 70 65 tring ColumnType
bec0: 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 (SQLiteStatement
bed0: 20 73 74 6d 74 2c 20 69 6e 74 20 69 6e 64 65 78 stmt, int index
bee0: 2c 20 6f 75 74 20 54 79 70 65 41 66 66 69 6e 69 , out TypeAffini
bef0: 74 79 20 6e 41 66 66 69 6e 69 74 79 29 0d 0a 20 ty nAffinity)..
bf00: 20 20 20 7b 0d 0a 20 20 20 20 20 20 69 6e 74 20 {.. int
bf10: 6c 65 6e 3b 0d 0a 23 69 66 20 21 53 51 4c 49 54 len;..#if !SQLIT
bf20: 45 5f 53 54 41 4e 44 41 52 44 0d 0a 20 20 20 20 E_STANDARD..
bf30: 20 20 49 6e 74 50 74 72 20 70 20 3d 20 55 6e 73 IntPtr p = Uns
bf40: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
bf50: 2e 73 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f .sqlite3_column_
bf60: 64 65 63 6c 74 79 70 65 5f 69 6e 74 65 72 6f 70 decltype_interop
bf70: 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 (stmt._sqlite_st
bf80: 6d 74 2c 20 69 6e 64 65 78 2c 20 6f 75 74 20 6c mt, index, out l
bf90: 65 6e 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 en);..#else..
bfa0: 20 20 20 6c 65 6e 20 3d 20 2d 31 3b 0d 0a 20 20 len = -1;..
bfb0: 20 20 20 20 49 6e 74 50 74 72 20 70 20 3d 20 55 IntPtr p = U
bfc0: 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
bfd0: 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f 6c 75 6d ds.sqlite3_colum
bfe0: 6e 5f 64 65 63 6c 74 79 70 65 28 73 74 6d 74 2e n_decltype(stmt.
bff0: 5f 73 71 6c 69 74 65 5f 73 74 6d 74 2c 20 69 6e _sqlite_stmt, in
c000: 64 65 78 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 dex);..#endif..
c010: 20 20 20 20 20 6e 41 66 66 69 6e 69 74 79 20 3d nAffinity =
c020: 20 43 6f 6c 75 6d 6e 41 66 66 69 6e 69 74 79 28 ColumnAffinity(
c030: 73 74 6d 74 2c 20 69 6e 64 65 78 29 3b 0d 0a 0d stmt, index);...
c040: 0a 20 20 20 20 20 20 69 66 20 28 70 20 21 3d 20 . if (p !=
c050: 49 6e 74 50 74 72 2e 5a 65 72 6f 29 20 72 65 74 IntPtr.Zero) ret
c060: 75 72 6e 20 55 54 46 38 54 6f 53 74 72 69 6e 67 urn UTF8ToString
c070: 28 70 2c 20 6c 65 6e 29 3b 0d 0a 20 20 20 20 20 (p, len);..
c080: 20 65 6c 73 65 0d 0a 20 20 20 20 20 20 7b 0d 0a else.. {..
c090: 20 20 20 20 20 20 20 20 73 74 72 69 6e 67 5b 5d string[]
c0a0: 20 61 72 20 3d 20 73 74 6d 74 2e 54 79 70 65 44 ar = stmt.TypeD
c0b0: 65 66 69 6e 69 74 69 6f 6e 73 3b 0d 0a 20 20 20 efinitions;..
c0c0: 20 20 20 20 20 69 66 20 28 61 72 20 21 3d 20 6e if (ar != n
c0d0: 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 7b 0d ull).. {.
c0e0: 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 28 69 . if (i
c0f0: 6e 64 65 78 20 3c 20 61 72 2e 4c 65 6e 67 74 68 ndex < ar.Length
c100: 20 26 26 20 61 72 5b 69 6e 64 65 78 5d 20 21 3d && ar[index] !=
c110: 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 null)..
c120: 20 20 20 20 72 65 74 75 72 6e 20 61 72 5b 69 6e return ar[in
c130: 64 65 78 5d 3b 0d 0a 20 20 20 20 20 20 20 20 7d dex];.. }
c140: 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e .. return
c150: 20 53 74 72 69 6e 67 2e 45 6d 70 74 79 3b 0d 0a String.Empty;..
c160: 0d 0a 20 20 20 20 20 20 20 20 2f 2f 73 77 69 74 .. //swit
c170: 63 68 20 28 6e 41 66 66 69 6e 69 74 79 29 0d 0a ch (nAffinity)..
c180: 20 20 20 20 20 20 20 20 2f 2f 7b 0d 0a 20 20 20 //{..
c190: 20 20 20 20 20 2f 2f 20 20 63 61 73 65 20 54 79 // case Ty
c1a0: 70 65 41 66 66 69 6e 69 74 79 2e 49 6e 74 36 34 peAffinity.Int64
c1b0: 3a 0d 0a 20 20 20 20 20 20 20 20 2f 2f 20 20 20 :.. //
c1c0: 20 72 65 74 75 72 6e 20 22 42 49 47 49 4e 54 22 return "BIGINT"
c1d0: 3b 0d 0a 20 20 20 20 20 20 20 20 2f 2f 20 20 63 ;.. // c
c1e0: 61 73 65 20 54 79 70 65 41 66 66 69 6e 69 74 79 ase TypeAffinity
c1f0: 2e 44 6f 75 62 6c 65 3a 0d 0a 20 20 20 20 20 20 .Double:..
c200: 20 20 2f 2f 20 20 20 20 72 65 74 75 72 6e 20 22 // return "
c210: 44 4f 55 42 4c 45 22 3b 0d 0a 20 20 20 20 20 20 DOUBLE";..
c220: 20 20 2f 2f 20 20 63 61 73 65 20 54 79 70 65 41 // case TypeA
c230: 66 66 69 6e 69 74 79 2e 42 6c 6f 62 3a 0d 0a 20 ffinity.Blob:..
c240: 20 20 20 20 20 20 20 2f 2f 20 20 20 20 72 65 74 // ret
c250: 75 72 6e 20 22 42 4c 4f 42 22 3b 0d 0a 20 20 20 urn "BLOB";..
c260: 20 20 20 20 20 2f 2f 20 20 64 65 66 61 75 6c 74 // default
c270: 3a 0d 0a 20 20 20 20 20 20 20 20 2f 2f 20 20 20 :.. //
c280: 20 72 65 74 75 72 6e 20 22 54 45 58 54 22 3b 0d return "TEXT";.
c290: 0a 20 20 20 20 20 20 20 20 2f 2f 7d 0d 0a 20 20 . //}..
c2a0: 20 20 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a }.. }....
c2b0: 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 internal ove
c2c0: 72 72 69 64 65 20 69 6e 74 20 43 6f 6c 75 6d 6e rride int Column
c2d0: 49 6e 64 65 78 28 53 51 4c 69 74 65 53 74 61 74 Index(SQLiteStat
c2e0: 65 6d 65 6e 74 20 73 74 6d 74 2c 20 73 74 72 69 ement stmt, stri
c2f0: 6e 67 20 63 6f 6c 75 6d 6e 4e 61 6d 65 29 0d 0a ng columnName)..
c300: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 69 6e 74 {.. int
c310: 20 78 20 3d 20 43 6f 6c 75 6d 6e 43 6f 75 6e 74 x = ColumnCount
c320: 28 73 74 6d 74 29 3b 0d 0a 0d 0a 20 20 20 20 20 (stmt);....
c330: 20 66 6f 72 20 28 69 6e 74 20 6e 20 3d 20 30 3b for (int n = 0;
c340: 20 6e 20 3c 20 78 3b 20 6e 2b 2b 29 0d 0a 20 20 n < x; n++)..
c350: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 69 {.. i
c360: 66 20 28 53 74 72 69 6e 67 2e 43 6f 6d 70 61 72 f (String.Compar
c370: 65 28 63 6f 6c 75 6d 6e 4e 61 6d 65 2c 20 43 6f e(columnName, Co
c380: 6c 75 6d 6e 4e 61 6d 65 28 73 74 6d 74 2c 20 6e lumnName(stmt, n
c390: 29 2c 20 53 74 72 69 6e 67 43 6f 6d 70 61 72 69 ), StringCompari
c3a0: 73 6f 6e 2e 4f 72 64 69 6e 61 6c 49 67 6e 6f 72 son.OrdinalIgnor
c3b0: 65 43 61 73 65 29 20 3d 3d 20 30 29 0d 0a 20 20 eCase) == 0)..
c3c0: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 6e return n
c3d0: 3b 0d 0a 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 ;.. }..
c3e0: 20 20 72 65 74 75 72 6e 20 2d 31 3b 0d 0a 20 20 return -1;..
c3f0: 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 }.... inter
c400: 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 73 74 72 nal override str
c410: 69 6e 67 20 43 6f 6c 75 6d 6e 4f 72 69 67 69 6e ing ColumnOrigin
c420: 61 6c 4e 61 6d 65 28 53 51 4c 69 74 65 53 74 61 alName(SQLiteSta
c430: 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 69 6e 74 tement stmt, int
c440: 20 69 6e 64 65 78 29 0d 0a 20 20 20 20 7b 0d 0a index).. {..
c450: 23 69 66 20 21 53 51 4c 49 54 45 5f 53 54 41 4e #if !SQLITE_STAN
c460: 44 41 52 44 0d 0a 20 20 20 20 20 20 69 6e 74 20 DARD.. int
c470: 6c 65 6e 3b 0d 0a 20 20 20 20 20 20 72 65 74 75 len;.. retu
c480: 72 6e 20 55 54 46 38 54 6f 53 74 72 69 6e 67 28 rn UTF8ToString(
c490: 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 UnsafeNativeMeth
c4a0: 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f 6c 75 ods.sqlite3_colu
c4b0: 6d 6e 5f 6f 72 69 67 69 6e 5f 6e 61 6d 65 5f 69 mn_origin_name_i
c4c0: 6e 74 65 72 6f 70 28 73 74 6d 74 2e 5f 73 71 6c nterop(stmt._sql
c4d0: 69 74 65 5f 73 74 6d 74 2c 20 69 6e 64 65 78 2c ite_stmt, index,
c4e0: 20 6f 75 74 20 6c 65 6e 29 2c 20 6c 65 6e 29 3b out len), len);
c4f0: 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 72 ..#else.. r
c500: 65 74 75 72 6e 20 55 54 46 38 54 6f 53 74 72 69 eturn UTF8ToStri
c510: 6e 67 28 55 6e 73 61 66 65 4e 61 74 69 76 65 4d ng(UnsafeNativeM
c520: 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 ethods.sqlite3_c
c530: 6f 6c 75 6d 6e 5f 6f 72 69 67 69 6e 5f 6e 61 6d olumn_origin_nam
c540: 65 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 e(stmt._sqlite_s
c550: 74 6d 74 2c 20 69 6e 64 65 78 29 2c 20 2d 31 29 tmt, index), -1)
c560: 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 7d ;..#endif.. }
c570: 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c .... internal
c580: 20 6f 76 65 72 72 69 64 65 20 73 74 72 69 6e 67 override string
c590: 20 43 6f 6c 75 6d 6e 44 61 74 61 62 61 73 65 4e ColumnDatabaseN
c5a0: 61 6d 65 28 53 51 4c 69 74 65 53 74 61 74 65 6d ame(SQLiteStatem
c5b0: 65 6e 74 20 73 74 6d 74 2c 20 69 6e 74 20 69 6e ent stmt, int in
c5c0: 64 65 78 29 0d 0a 20 20 20 20 7b 0d 0a 23 69 66 dex).. {..#if
c5d0: 20 21 53 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 !SQLITE_STANDAR
c5e0: 44 0d 0a 20 20 20 20 20 20 69 6e 74 20 6c 65 6e D.. int len
c5f0: 3b 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 ;.. return
c600: 55 54 46 38 54 6f 53 74 72 69 6e 67 28 55 6e 73 UTF8ToString(Uns
c610: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
c620: 2e 73 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f .sqlite3_column_
c630: 64 61 74 61 62 61 73 65 5f 6e 61 6d 65 5f 69 6e database_name_in
c640: 74 65 72 6f 70 28 73 74 6d 74 2e 5f 73 71 6c 69 terop(stmt._sqli
c650: 74 65 5f 73 74 6d 74 2c 20 69 6e 64 65 78 2c 20 te_stmt, index,
c660: 6f 75 74 20 6c 65 6e 29 2c 20 6c 65 6e 29 3b 0d out len), len);.
c670: 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 72 65 .#else.. re
c680: 74 75 72 6e 20 55 54 46 38 54 6f 53 74 72 69 6e turn UTF8ToStrin
c690: 67 28 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 g(UnsafeNativeMe
c6a0: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f thods.sqlite3_co
c6b0: 6c 75 6d 6e 5f 64 61 74 61 62 61 73 65 5f 6e 61 lumn_database_na
c6c0: 6d 65 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f me(stmt._sqlite_
c6d0: 73 74 6d 74 2c 20 69 6e 64 65 78 29 2c 20 2d 31 stmt, index), -1
c6e0: 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 );..#endif..
c6f0: 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 }.... interna
c700: 6c 20 6f 76 65 72 72 69 64 65 20 73 74 72 69 6e l override strin
c710: 67 20 43 6f 6c 75 6d 6e 54 61 62 6c 65 4e 61 6d g ColumnTableNam
c720: 65 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e e(SQLiteStatemen
c730: 74 20 73 74 6d 74 2c 20 69 6e 74 20 69 6e 64 65 t stmt, int inde
c740: 78 29 0d 0a 20 20 20 20 7b 0d 0a 23 69 66 20 21 x).. {..#if !
c750: 53 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d SQLITE_STANDARD.
c760: 0a 20 20 20 20 20 20 69 6e 74 20 6c 65 6e 3b 0d . int len;.
c770: 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 55 54 . return UT
c780: 46 38 54 6f 53 74 72 69 6e 67 28 55 6e 73 61 66 F8ToString(Unsaf
c790: 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
c7a0: 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f 74 61 qlite3_column_ta
c7b0: 62 6c 65 5f 6e 61 6d 65 5f 69 6e 74 65 72 6f 70 ble_name_interop
c7c0: 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 (stmt._sqlite_st
c7d0: 6d 74 2c 20 69 6e 64 65 78 2c 20 6f 75 74 20 6c mt, index, out l
c7e0: 65 6e 29 2c 20 6c 65 6e 29 3b 0d 0a 23 65 6c 73 en), len);..#els
c7f0: 65 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 e.. return
c800: 55 54 46 38 54 6f 53 74 72 69 6e 67 28 55 6e 73 UTF8ToString(Uns
c810: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
c820: 2e 73 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f .sqlite3_column_
c830: 74 61 62 6c 65 5f 6e 61 6d 65 28 73 74 6d 74 2e table_name(stmt.
c840: 5f 73 71 6c 69 74 65 5f 73 74 6d 74 2c 20 69 6e _sqlite_stmt, in
c850: 64 65 78 29 2c 20 2d 31 29 3b 0d 0a 23 65 6e 64 dex), -1);..#end
c860: 69 66 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 if.. }....
c870: 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 internal overri
c880: 64 65 20 76 6f 69 64 20 43 6f 6c 75 6d 6e 4d 65 de void ColumnMe
c890: 74 61 44 61 74 61 28 73 74 72 69 6e 67 20 64 61 taData(string da
c8a0: 74 61 42 61 73 65 2c 20 73 74 72 69 6e 67 20 74 taBase, string t
c8b0: 61 62 6c 65 2c 20 73 74 72 69 6e 67 20 63 6f 6c able, string col
c8c0: 75 6d 6e 2c 20 6f 75 74 20 73 74 72 69 6e 67 20 umn, out string
c8d0: 64 61 74 61 54 79 70 65 2c 20 6f 75 74 20 73 74 dataType, out st
c8e0: 72 69 6e 67 20 63 6f 6c 6c 61 74 65 53 65 71 75 ring collateSequ
c8f0: 65 6e 63 65 2c 20 6f 75 74 20 62 6f 6f 6c 20 6e ence, out bool n
c900: 6f 74 4e 75 6c 6c 2c 20 6f 75 74 20 62 6f 6f 6c otNull, out bool
c910: 20 70 72 69 6d 61 72 79 4b 65 79 2c 20 6f 75 74 primaryKey, out
c920: 20 62 6f 6f 6c 20 61 75 74 6f 49 6e 63 72 65 6d bool autoIncrem
c930: 65 6e 74 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 ent).. {..
c940: 20 20 20 49 6e 74 50 74 72 20 64 61 74 61 54 79 IntPtr dataTy
c950: 70 65 50 74 72 3b 0d 0a 20 20 20 20 20 20 49 6e pePtr;.. In
c960: 74 50 74 72 20 63 6f 6c 6c 53 65 71 50 74 72 3b tPtr collSeqPtr;
c970: 0d 0a 20 20 20 20 20 20 69 6e 74 20 6e 6e 6f 74 .. int nnot
c980: 4e 75 6c 6c 3b 0d 0a 20 20 20 20 20 20 69 6e 74 Null;.. int
c990: 20 6e 70 72 69 6d 61 72 79 4b 65 79 3b 0d 0a 20 nprimaryKey;..
c9a0: 20 20 20 20 20 69 6e 74 20 6e 61 75 74 6f 49 6e int nautoIn
c9b0: 63 3b 0d 0a 20 20 20 20 20 20 53 51 4c 69 74 65 c;.. SQLite
c9c0: 45 72 72 6f 72 43 6f 64 65 20 6e 3b 0d 0a 20 20 ErrorCode n;..
c9d0: 20 20 20 20 69 6e 74 20 64 74 4c 65 6e 3b 0d 0a int dtLen;..
c9e0: 20 20 20 20 20 20 69 6e 74 20 63 73 4c 65 6e 3b int csLen;
c9f0: 0d 0a 0d 0a 23 69 66 20 21 53 51 4c 49 54 45 5f ....#if !SQLITE_
ca00: 53 54 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 20 STANDARD..
ca10: 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 n = UnsafeNative
ca20: 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f Methods.sqlite3_
ca30: 74 61 62 6c 65 5f 63 6f 6c 75 6d 6e 5f 6d 65 74 table_column_met
ca40: 61 64 61 74 61 5f 69 6e 74 65 72 6f 70 28 5f 73 adata_interop(_s
ca50: 71 6c 2c 20 54 6f 55 54 46 38 28 64 61 74 61 42 ql, ToUTF8(dataB
ca60: 61 73 65 29 2c 20 54 6f 55 54 46 38 28 74 61 62 ase), ToUTF8(tab
ca70: 6c 65 29 2c 20 54 6f 55 54 46 38 28 63 6f 6c 75 le), ToUTF8(colu
ca80: 6d 6e 29 2c 20 6f 75 74 20 64 61 74 61 54 79 70 mn), out dataTyp
ca90: 65 50 74 72 2c 20 6f 75 74 20 63 6f 6c 6c 53 65 ePtr, out collSe
caa0: 71 50 74 72 2c 20 6f 75 74 20 6e 6e 6f 74 4e 75 qPtr, out nnotNu
cab0: 6c 6c 2c 20 6f 75 74 20 6e 70 72 69 6d 61 72 79 ll, out nprimary
cac0: 4b 65 79 2c 20 6f 75 74 20 6e 61 75 74 6f 49 6e Key, out nautoIn
cad0: 63 2c 20 6f 75 74 20 64 74 4c 65 6e 2c 20 6f 75 c, out dtLen, ou
cae0: 74 20 63 73 4c 65 6e 29 3b 0d 0a 23 65 6c 73 65 t csLen);..#else
caf0: 0d 0a 20 20 20 20 20 20 64 74 4c 65 6e 20 3d 20 .. dtLen =
cb00: 2d 31 3b 0d 0a 20 20 20 20 20 20 63 73 4c 65 6e -1;.. csLen
cb10: 20 3d 20 2d 31 3b 0d 0a 0d 0a 20 20 20 20 20 20 = -1;....
cb20: 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 n = UnsafeNative
cb30: 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f Methods.sqlite3_
cb40: 74 61 62 6c 65 5f 63 6f 6c 75 6d 6e 5f 6d 65 74 table_column_met
cb50: 61 64 61 74 61 28 5f 73 71 6c 2c 20 54 6f 55 54 adata(_sql, ToUT
cb60: 46 38 28 64 61 74 61 42 61 73 65 29 2c 20 54 6f F8(dataBase), To
cb70: 55 54 46 38 28 74 61 62 6c 65 29 2c 20 54 6f 55 UTF8(table), ToU
cb80: 54 46 38 28 63 6f 6c 75 6d 6e 29 2c 20 6f 75 74 TF8(column), out
cb90: 20 64 61 74 61 54 79 70 65 50 74 72 2c 20 6f 75 dataTypePtr, ou
cba0: 74 20 63 6f 6c 6c 53 65 71 50 74 72 2c 20 6f 75 t collSeqPtr, ou
cbb0: 74 20 6e 6e 6f 74 4e 75 6c 6c 2c 20 6f 75 74 20 t nnotNull, out
cbc0: 6e 70 72 69 6d 61 72 79 4b 65 79 2c 20 6f 75 74 nprimaryKey, out
cbd0: 20 6e 61 75 74 6f 49 6e 63 29 3b 0d 0a 23 65 6e nautoInc);..#en
cbe0: 64 69 66 0d 0a 20 20 20 20 20 20 69 66 20 28 6e dif.. if (n
cbf0: 20 21 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 43 != SQLiteErrorC
cc00: 6f 64 65 2e 4f 6b 29 20 74 68 72 6f 77 20 6e 65 ode.Ok) throw ne
cc10: 77 20 53 51 4c 69 74 65 45 78 63 65 70 74 69 6f w SQLiteExceptio
cc20: 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 72 72 6f n(n, GetLastErro
cc30: 72 28 29 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 64 r());.... d
cc40: 61 74 61 54 79 70 65 20 3d 20 55 54 46 38 54 6f ataType = UTF8To
cc50: 53 74 72 69 6e 67 28 64 61 74 61 54 79 70 65 50 String(dataTypeP
cc60: 74 72 2c 20 64 74 4c 65 6e 29 3b 0d 0a 20 20 20 tr, dtLen);..
cc70: 20 20 20 63 6f 6c 6c 61 74 65 53 65 71 75 65 6e collateSequen
cc80: 63 65 20 3d 20 55 54 46 38 54 6f 53 74 72 69 6e ce = UTF8ToStrin
cc90: 67 28 63 6f 6c 6c 53 65 71 50 74 72 2c 20 63 73 g(collSeqPtr, cs
cca0: 4c 65 6e 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 6e Len);.... n
ccb0: 6f 74 4e 75 6c 6c 20 3d 20 28 6e 6e 6f 74 4e 75 otNull = (nnotNu
ccc0: 6c 6c 20 3d 3d 20 31 29 3b 0d 0a 20 20 20 20 20 ll == 1);..
ccd0: 20 70 72 69 6d 61 72 79 4b 65 79 20 3d 20 28 6e primaryKey = (n
cce0: 70 72 69 6d 61 72 79 4b 65 79 20 3d 3d 20 31 29 primaryKey == 1)
ccf0: 3b 0d 0a 20 20 20 20 20 20 61 75 74 6f 49 6e 63 ;.. autoInc
cd00: 72 65 6d 65 6e 74 20 3d 20 28 6e 61 75 74 6f 49 rement = (nautoI
cd10: 6e 63 20 3d 3d 20 31 29 3b 0d 0a 20 20 20 20 7d nc == 1);.. }
cd20: 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c .... internal
cd30: 20 6f 76 65 72 72 69 64 65 20 64 6f 75 62 6c 65 override double
cd40: 20 47 65 74 44 6f 75 62 6c 65 28 53 51 4c 69 74 GetDouble(SQLit
cd50: 65 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c eStatement stmt,
cd60: 20 69 6e 74 20 69 6e 64 65 78 29 0d 0a 20 20 20 int index)..
cd70: 20 7b 0d 0a 20 20 20 20 20 20 64 6f 75 62 6c 65 {.. double
cd80: 20 76 61 6c 75 65 3b 0d 0a 23 69 66 20 21 50 4c value;..#if !PL
cd90: 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 ATFORM_COMPACTFR
cda0: 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 20 20 76 AMEWORK.. v
cdb0: 61 6c 75 65 20 3d 20 55 6e 73 61 66 65 4e 61 74 alue = UnsafeNat
cdc0: 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 iveMethods.sqlit
cdd0: 65 33 5f 63 6f 6c 75 6d 6e 5f 64 6f 75 62 6c 65 e3_column_double
cde0: 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 (stmt._sqlite_st
cdf0: 6d 74 2c 20 69 6e 64 65 78 29 3b 0d 0a 23 65 6c mt, index);..#el
ce00: 69 66 20 21 53 51 4c 49 54 45 5f 53 54 41 4e 44 if !SQLITE_STAND
ce10: 41 52 44 0d 0a 20 20 20 20 20 20 55 6e 73 61 66 ARD.. Unsaf
ce20: 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
ce30: 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f 64 6f qlite3_column_do
ce40: 75 62 6c 65 5f 69 6e 74 65 72 6f 70 28 73 74 6d uble_interop(stm
ce50: 74 2e 5f 73 71 6c 69 74 65 5f 73 74 6d 74 2c 20 t._sqlite_stmt,
ce60: 69 6e 64 65 78 2c 20 6f 75 74 20 76 61 6c 75 65 index, out value
ce70: 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 );..#else..
ce80: 20 74 68 72 6f 77 20 6e 65 77 20 4e 6f 74 49 6d throw new NotIm
ce90: 70 6c 65 6d 65 6e 74 65 64 45 78 63 65 70 74 69 plementedExcepti
cea0: 6f 6e 28 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 on();..#endif..
ceb0: 20 20 20 20 20 72 65 74 75 72 6e 20 76 61 6c 75 return valu
cec0: 65 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 e;.. }....
ced0: 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 internal overri
cee0: 64 65 20 73 62 79 74 65 20 47 65 74 53 42 79 74 de sbyte GetSByt
cef0: 65 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e e(SQLiteStatemen
cf00: 74 20 73 74 6d 74 2c 20 69 6e 74 20 69 6e 64 65 t stmt, int inde
cf10: 78 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 x).. {..
cf20: 20 72 65 74 75 72 6e 20 75 6e 63 68 65 63 6b 65 return unchecke
cf30: 64 28 28 73 62 79 74 65 29 28 47 65 74 49 6e 74 d((sbyte)(GetInt
cf40: 33 32 28 73 74 6d 74 2c 20 69 6e 64 65 78 29 20 32(stmt, index)
cf50: 26 20 62 79 74 65 2e 4d 61 78 56 61 6c 75 65 29 & byte.MaxValue)
cf60: 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 );.. }....
cf70: 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 internal overri
cf80: 64 65 20 62 79 74 65 20 47 65 74 42 79 74 65 28 de byte GetByte(
cf90: 53 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 20 SQLiteStatement
cfa0: 73 74 6d 74 2c 20 69 6e 74 20 69 6e 64 65 78 29 stmt, int index)
cfb0: 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 72 .. {.. r
cfc0: 65 74 75 72 6e 20 75 6e 63 68 65 63 6b 65 64 28 eturn unchecked(
cfd0: 28 62 79 74 65 29 28 47 65 74 49 6e 74 33 32 28 (byte)(GetInt32(
cfe0: 73 74 6d 74 2c 20 69 6e 64 65 78 29 20 26 20 62 stmt, index) & b
cff0: 79 74 65 2e 4d 61 78 56 61 6c 75 65 29 29 3b 0d yte.MaxValue));.
d000: 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e . }.... in
d010: 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 ternal override
d020: 73 68 6f 72 74 20 47 65 74 49 6e 74 31 36 28 53 short GetInt16(S
d030: 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 20 73 QLiteStatement s
d040: 74 6d 74 2c 20 69 6e 74 20 69 6e 64 65 78 29 0d tmt, int index).
d050: 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 72 65 . {.. re
d060: 74 75 72 6e 20 75 6e 63 68 65 63 6b 65 64 28 28 turn unchecked((
d070: 73 68 6f 72 74 29 28 47 65 74 49 6e 74 33 32 28 short)(GetInt32(
d080: 73 74 6d 74 2c 20 69 6e 64 65 78 29 20 26 20 75 stmt, index) & u
d090: 73 68 6f 72 74 2e 4d 61 78 56 61 6c 75 65 29 29 short.MaxValue))
d0a0: 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 ;.. }....
d0b0: 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 internal overrid
d0c0: 65 20 75 73 68 6f 72 74 20 47 65 74 55 49 6e 74 e ushort GetUInt
d0d0: 31 36 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 16(SQLiteStateme
d0e0: 6e 74 20 73 74 6d 74 2c 20 69 6e 74 20 69 6e 64 nt stmt, int ind
d0f0: 65 78 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 ex).. {..
d100: 20 20 72 65 74 75 72 6e 20 75 6e 63 68 65 63 6b return uncheck
d110: 65 64 28 28 75 73 68 6f 72 74 29 28 47 65 74 49 ed((ushort)(GetI
d120: 6e 74 33 32 28 73 74 6d 74 2c 20 69 6e 64 65 78 nt32(stmt, index
d130: 29 20 26 20 75 73 68 6f 72 74 2e 4d 61 78 56 61 ) & ushort.MaxVa
d140: 6c 75 65 29 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d lue));.. }...
d150: 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 . internal ov
d160: 65 72 72 69 64 65 20 69 6e 74 20 47 65 74 49 6e erride int GetIn
d170: 74 33 32 28 53 51 4c 69 74 65 53 74 61 74 65 6d t32(SQLiteStatem
d180: 65 6e 74 20 73 74 6d 74 2c 20 69 6e 74 20 69 6e ent stmt, int in
d190: 64 65 78 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 dex).. {..
d1a0: 20 20 20 72 65 74 75 72 6e 20 55 6e 73 61 66 65 return Unsafe
d1b0: 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 NativeMethods.sq
d1c0: 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 lite3_column_int
d1d0: 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 (stmt._sqlite_st
d1e0: 6d 74 2c 20 69 6e 64 65 78 29 3b 0d 0a 20 20 20 mt, index);..
d1f0: 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e }.... intern
d200: 61 6c 20 6f 76 65 72 72 69 64 65 20 75 69 6e 74 al override uint
d210: 20 47 65 74 55 49 6e 74 33 32 28 53 51 4c 69 74 GetUInt32(SQLit
d220: 65 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c eStatement stmt,
d230: 20 69 6e 74 20 69 6e 64 65 78 29 0d 0a 20 20 20 int index)..
d240: 20 7b 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e {.. return
d250: 20 75 6e 63 68 65 63 6b 65 64 28 28 75 69 6e 74 unchecked((uint
d260: 29 47 65 74 49 6e 74 33 32 28 73 74 6d 74 2c 20 )GetInt32(stmt,
d270: 69 6e 64 65 78 29 29 3b 0d 0a 20 20 20 20 7d 0d index));.. }.
d280: 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 ... internal
d290: 6f 76 65 72 72 69 64 65 20 6c 6f 6e 67 20 47 65 override long Ge
d2a0: 74 49 6e 74 36 34 28 53 51 4c 69 74 65 53 74 61 tInt64(SQLiteSta
d2b0: 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 69 6e 74 tement stmt, int
d2c0: 20 69 6e 64 65 78 29 0d 0a 20 20 20 20 7b 0d 0a index).. {..
d2d0: 20 20 20 20 20 20 6c 6f 6e 67 20 76 61 6c 75 65 long value
d2e0: 3b 0d 0a 23 69 66 20 21 50 4c 41 54 46 4f 52 4d ;..#if !PLATFORM
d2f0: 5f 43 4f 4d 50 41 43 54 46 52 41 4d 45 57 4f 52 _COMPACTFRAMEWOR
d300: 4b 0d 0a 20 20 20 20 20 20 76 61 6c 75 65 20 3d K.. value =
d310: 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 UnsafeNativeMet
d320: 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f 6c hods.sqlite3_col
d330: 75 6d 6e 5f 69 6e 74 36 34 28 73 74 6d 74 2e 5f umn_int64(stmt._
d340: 73 71 6c 69 74 65 5f 73 74 6d 74 2c 20 69 6e 64 sqlite_stmt, ind
d350: 65 78 29 3b 0d 0a 23 65 6c 69 66 20 21 53 51 4c ex);..#elif !SQL
d360: 49 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a 20 20 ITE_STANDARD..
d370: 20 20 20 20 55 6e 73 61 66 65 4e 61 74 69 76 65 UnsafeNative
d380: 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f Methods.sqlite3_
d390: 63 6f 6c 75 6d 6e 5f 69 6e 74 36 34 5f 69 6e 74 column_int64_int
d3a0: 65 72 6f 70 28 73 74 6d 74 2e 5f 73 71 6c 69 74 erop(stmt._sqlit
d3b0: 65 5f 73 74 6d 74 2c 20 69 6e 64 65 78 2c 20 6f e_stmt, index, o
d3c0: 75 74 20 76 61 6c 75 65 29 3b 0d 0a 23 65 6c 73 ut value);..#els
d3d0: 65 0d 0a 20 20 20 20 20 20 74 68 72 6f 77 20 6e e.. throw n
d3e0: 65 77 20 4e 6f 74 49 6d 70 6c 65 6d 65 6e 74 65 ew NotImplemente
d3f0: 64 45 78 63 65 70 74 69 6f 6e 28 29 3b 0d 0a 23 dException();..#
d400: 65 6e 64 69 66 0d 0a 20 20 20 20 20 20 72 65 74 endif.. ret
d410: 75 72 6e 20 76 61 6c 75 65 3b 0d 0a 20 20 20 20 urn value;..
d420: 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 }.... interna
d430: 6c 20 6f 76 65 72 72 69 64 65 20 75 6c 6f 6e 67 l override ulong
d440: 20 47 65 74 55 49 6e 74 36 34 28 53 51 4c 69 74 GetUInt64(SQLit
d450: 65 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c eStatement stmt,
d460: 20 69 6e 74 20 69 6e 64 65 78 29 0d 0a 20 20 20 int index)..
d470: 20 7b 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e {.. return
d480: 20 75 6e 63 68 65 63 6b 65 64 28 28 75 6c 6f 6e unchecked((ulon
d490: 67 29 47 65 74 49 6e 74 36 34 28 73 74 6d 74 2c g)GetInt64(stmt,
d4a0: 20 69 6e 64 65 78 29 29 3b 0d 0a 20 20 20 20 7d index));.. }
d4b0: 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c .... internal
d4c0: 20 6f 76 65 72 72 69 64 65 20 73 74 72 69 6e 67 override string
d4d0: 20 47 65 74 54 65 78 74 28 53 51 4c 69 74 65 53 GetText(SQLiteS
d4e0: 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 69 tatement stmt, i
d4f0: 6e 74 20 69 6e 64 65 78 29 0d 0a 20 20 20 20 7b nt index).. {
d500: 0d 0a 23 69 66 20 21 53 51 4c 49 54 45 5f 53 54 ..#if !SQLITE_ST
d510: 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 20 69 6e ANDARD.. in
d520: 74 20 6c 65 6e 3b 0d 0a 20 20 20 20 20 20 72 65 t len;.. re
d530: 74 75 72 6e 20 55 54 46 38 54 6f 53 74 72 69 6e turn UTF8ToStrin
d540: 67 28 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 g(UnsafeNativeMe
d550: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 6f thods.sqlite3_co
d560: 6c 75 6d 6e 5f 74 65 78 74 5f 69 6e 74 65 72 6f lumn_text_intero
d570: 70 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 p(stmt._sqlite_s
d580: 74 6d 74 2c 20 69 6e 64 65 78 2c 20 6f 75 74 20 tmt, index, out
d590: 6c 65 6e 29 2c 20 6c 65 6e 29 3b 0d 0a 23 65 6c len), len);..#el
d5a0: 73 65 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e se.. return
d5b0: 20 55 54 46 38 54 6f 53 74 72 69 6e 67 28 55 6e UTF8ToString(Un
d5c0: 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 safeNativeMethod
d5d0: 73 2e 73 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e s.sqlite3_column
d5e0: 5f 74 65 78 74 28 73 74 6d 74 2e 5f 73 71 6c 69 _text(stmt._sqli
d5f0: 74 65 5f 73 74 6d 74 2c 20 69 6e 64 65 78 29 2c te_stmt, index),
d600: 0d 0a 20 20 20 20 20 20 20 20 55 6e 73 61 66 65 .. Unsafe
d610: 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 NativeMethods.sq
d620: 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f 62 79 74 lite3_column_byt
d630: 65 73 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f es(stmt._sqlite_
d640: 73 74 6d 74 2c 20 69 6e 64 65 78 29 29 3b 0d 0a stmt, index));..
d650: 23 65 6e 64 69 66 0d 0a 20 20 20 20 7d 0d 0a 0d #endif.. }...
d660: 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 . internal ov
d670: 65 72 72 69 64 65 20 44 61 74 65 54 69 6d 65 20 erride DateTime
d680: 47 65 74 44 61 74 65 54 69 6d 65 28 53 51 4c 69 GetDateTime(SQLi
d690: 74 65 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 teStatement stmt
d6a0: 2c 20 69 6e 74 20 69 6e 64 65 78 29 0d 0a 20 20 , int index)..
d6b0: 20 20 7b 0d 0a 20 20 20 20 20 20 69 66 20 28 5f {.. if (_
d6c0: 64 61 74 65 74 69 6d 65 46 6f 72 6d 61 74 20 3d datetimeFormat =
d6d0: 3d 20 53 51 4c 69 74 65 44 61 74 65 46 6f 72 6d = SQLiteDateForm
d6e0: 61 74 73 2e 54 69 63 6b 73 29 0d 0a 20 20 20 20 ats.Ticks)..
d6f0: 20 20 20 20 72 65 74 75 72 6e 20 54 6f 44 61 74 return ToDat
d700: 65 54 69 6d 65 28 47 65 74 49 6e 74 36 34 28 73 eTime(GetInt64(s
d710: 74 6d 74 2c 20 69 6e 64 65 78 29 2c 20 5f 64 61 tmt, index), _da
d720: 74 65 74 69 6d 65 4b 69 6e 64 29 3b 0d 0a 20 20 tetimeKind);..
d730: 20 20 20 20 65 6c 73 65 20 69 66 20 28 5f 64 61 else if (_da
d740: 74 65 74 69 6d 65 46 6f 72 6d 61 74 20 3d 3d 20 tetimeFormat ==
d750: 53 51 4c 69 74 65 44 61 74 65 46 6f 72 6d 61 74 SQLiteDateFormat
d760: 73 2e 4a 75 6c 69 61 6e 44 61 79 29 0d 0a 20 20 s.JulianDay)..
d770: 20 20 20 20 20 20 72 65 74 75 72 6e 20 54 6f 44 return ToD
d780: 61 74 65 54 69 6d 65 28 47 65 74 44 6f 75 62 6c ateTime(GetDoubl
d790: 65 28 73 74 6d 74 2c 20 69 6e 64 65 78 29 2c 20 e(stmt, index),
d7a0: 5f 64 61 74 65 74 69 6d 65 4b 69 6e 64 29 3b 0d _datetimeKind);.
d7b0: 0a 20 20 20 20 20 20 65 6c 73 65 20 69 66 20 28 . else if (
d7c0: 5f 64 61 74 65 74 69 6d 65 46 6f 72 6d 61 74 20 _datetimeFormat
d7d0: 3d 3d 20 53 51 4c 69 74 65 44 61 74 65 46 6f 72 == SQLiteDateFor
d7e0: 6d 61 74 73 2e 55 6e 69 78 45 70 6f 63 68 29 0d mats.UnixEpoch).
d7f0: 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 . return
d800: 54 6f 44 61 74 65 54 69 6d 65 28 47 65 74 49 6e ToDateTime(GetIn
d810: 74 33 32 28 73 74 6d 74 2c 20 69 6e 64 65 78 29 t32(stmt, index)
d820: 2c 20 5f 64 61 74 65 74 69 6d 65 4b 69 6e 64 29 , _datetimeKind)
d830: 3b 0d 0a 0d 0a 23 69 66 20 21 53 51 4c 49 54 45 ;....#if !SQLITE
d840: 5f 53 54 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 _STANDARD..
d850: 20 69 6e 74 20 6c 65 6e 3b 0d 0a 20 20 20 20 20 int len;..
d860: 20 72 65 74 75 72 6e 20 54 6f 44 61 74 65 54 69 return ToDateTi
d870: 6d 65 28 55 6e 73 61 66 65 4e 61 74 69 76 65 4d me(UnsafeNativeM
d880: 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 ethods.sqlite3_c
d890: 6f 6c 75 6d 6e 5f 74 65 78 74 5f 69 6e 74 65 72 olumn_text_inter
d8a0: 6f 70 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f op(stmt._sqlite_
d8b0: 73 74 6d 74 2c 20 69 6e 64 65 78 2c 20 6f 75 74 stmt, index, out
d8c0: 20 6c 65 6e 29 2c 20 6c 65 6e 29 3b 0d 0a 23 65 len), len);..#e
d8d0: 6c 73 65 0d 0a 20 20 20 20 20 20 72 65 74 75 72 lse.. retur
d8e0: 6e 20 54 6f 44 61 74 65 54 69 6d 65 28 55 6e 73 n ToDateTime(Uns
d8f0: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
d900: 2e 73 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f .sqlite3_column_
d910: 74 65 78 74 28 73 74 6d 74 2e 5f 73 71 6c 69 74 text(stmt._sqlit
d920: 65 5f 73 74 6d 74 2c 20 69 6e 64 65 78 29 2c 0d e_stmt, index),.
d930: 0a 20 20 20 20 20 20 20 20 55 6e 73 61 66 65 4e . UnsafeN
d940: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
d950: 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f 62 79 74 65 ite3_column_byte
d960: 73 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 s(stmt._sqlite_s
d970: 74 6d 74 2c 20 69 6e 64 65 78 29 29 3b 0d 0a 23 tmt, index));..#
d980: 65 6e 64 69 66 0d 0a 20 20 20 20 7d 0d 0a 0d 0a endif.. }....
d990: 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 internal ove
d9a0: 72 72 69 64 65 20 6c 6f 6e 67 20 47 65 74 42 79 rride long GetBy
d9b0: 74 65 73 28 53 51 4c 69 74 65 53 74 61 74 65 6d tes(SQLiteStatem
d9c0: 65 6e 74 20 73 74 6d 74 2c 20 69 6e 74 20 69 6e ent stmt, int in
d9d0: 64 65 78 2c 20 69 6e 74 20 6e 44 61 74 61 4f 66 dex, int nDataOf
d9e0: 66 73 65 74 2c 20 62 79 74 65 5b 5d 20 62 44 65 fset, byte[] bDe
d9f0: 73 74 2c 20 69 6e 74 20 6e 53 74 61 72 74 2c 20 st, int nStart,
da00: 69 6e 74 20 6e 4c 65 6e 67 74 68 29 0d 0a 20 20 int nLength)..
da10: 20 20 7b 0d 0a 20 20 20 20 20 20 69 6e 74 20 6e {.. int n
da20: 6c 65 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 len = UnsafeNati
da30: 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 veMethods.sqlite
da40: 33 5f 63 6f 6c 75 6d 6e 5f 62 79 74 65 73 28 73 3_column_bytes(s
da50: 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 74 6d 74 tmt._sqlite_stmt
da60: 2c 20 69 6e 64 65 78 29 3b 0d 0a 0d 0a 20 20 20 , index);....
da70: 20 20 20 2f 2f 20 49 66 20 6e 6f 20 64 65 73 74 // If no dest
da80: 69 6e 61 74 69 6f 6e 20 62 75 66 66 65 72 2c 20 ination buffer,
da90: 72 65 74 75 72 6e 20 74 68 65 20 73 69 7a 65 20 return the size
daa0: 6e 65 65 64 65 64 2e 0d 0a 20 20 20 20 20 20 69 needed... i
dab0: 66 20 28 62 44 65 73 74 20 3d 3d 20 6e 75 6c 6c f (bDest == null
dac0: 29 20 72 65 74 75 72 6e 20 6e 6c 65 6e 3b 0d 0a ) return nlen;..
dad0: 0d 0a 20 20 20 20 20 20 69 6e 74 20 6e 43 6f 70 .. int nCop
dae0: 69 65 64 20 3d 20 6e 4c 65 6e 67 74 68 3b 0d 0a ied = nLength;..
daf0: 0d 0a 20 20 20 20 20 20 69 66 20 28 6e 43 6f 70 .. if (nCop
db00: 69 65 64 20 2b 20 6e 53 74 61 72 74 20 3e 20 62 ied + nStart > b
db10: 44 65 73 74 2e 4c 65 6e 67 74 68 29 20 6e 43 6f Dest.Length) nCo
db20: 70 69 65 64 20 3d 20 62 44 65 73 74 2e 4c 65 6e pied = bDest.Len
db30: 67 74 68 20 2d 20 6e 53 74 61 72 74 3b 0d 0a 20 gth - nStart;..
db40: 20 20 20 20 20 69 66 20 28 6e 43 6f 70 69 65 64 if (nCopied
db50: 20 2b 20 6e 44 61 74 61 4f 66 66 73 65 74 20 3e + nDataOffset >
db60: 20 6e 6c 65 6e 29 20 6e 43 6f 70 69 65 64 20 3d nlen) nCopied =
db70: 20 6e 6c 65 6e 20 2d 20 6e 44 61 74 61 4f 66 66 nlen - nDataOff
db80: 73 65 74 3b 0d 0a 0d 0a 20 20 20 20 20 20 69 66 set;.... if
db90: 20 28 6e 43 6f 70 69 65 64 20 3e 20 30 29 0d 0a (nCopied > 0)..
dba0: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
dbb0: 20 49 6e 74 50 74 72 20 70 74 72 20 3d 20 55 6e IntPtr ptr = Un
dbc0: 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 safeNativeMethod
dbd0: 73 2e 73 71 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e s.sqlite3_column
dbe0: 5f 62 6c 6f 62 28 73 74 6d 74 2e 5f 73 71 6c 69 _blob(stmt._sqli
dbf0: 74 65 5f 73 74 6d 74 2c 20 69 6e 64 65 78 29 3b te_stmt, index);
dc00: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 4d 61 72 73 .... Mars
dc10: 68 61 6c 2e 43 6f 70 79 28 28 49 6e 74 50 74 72 hal.Copy((IntPtr
dc20: 29 28 70 74 72 2e 54 6f 49 6e 74 36 34 28 29 20 )(ptr.ToInt64()
dc30: 2b 20 6e 44 61 74 61 4f 66 66 73 65 74 29 2c 20 + nDataOffset),
dc40: 62 44 65 73 74 2c 20 6e 53 74 61 72 74 2c 20 6e bDest, nStart, n
dc50: 43 6f 70 69 65 64 29 3b 0d 0a 20 20 20 20 20 20 Copied);..
dc60: 7d 0d 0a 20 20 20 20 20 20 65 6c 73 65 0d 0a 20 }.. else..
dc70: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
dc80: 6e 43 6f 70 69 65 64 20 3d 20 30 3b 0d 0a 20 20 nCopied = 0;..
dc90: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 72 }.... r
dca0: 65 74 75 72 6e 20 6e 43 6f 70 69 65 64 3b 0d 0a eturn nCopied;..
dcb0: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 }.... int
dcc0: 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 6c ernal override l
dcd0: 6f 6e 67 20 47 65 74 43 68 61 72 73 28 53 51 4c ong GetChars(SQL
dce0: 69 74 65 53 74 61 74 65 6d 65 6e 74 20 73 74 6d iteStatement stm
dcf0: 74 2c 20 69 6e 74 20 69 6e 64 65 78 2c 20 69 6e t, int index, in
dd00: 74 20 6e 44 61 74 61 4f 66 66 73 65 74 2c 20 63 t nDataOffset, c
dd10: 68 61 72 5b 5d 20 62 44 65 73 74 2c 20 69 6e 74 har[] bDest, int
dd20: 20 6e 53 74 61 72 74 2c 20 69 6e 74 20 6e 4c 65 nStart, int nLe
dd30: 6e 67 74 68 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 ngth).. {..
dd40: 20 20 20 20 69 6e 74 20 6e 6c 65 6e 3b 0d 0a 20 int nlen;..
dd50: 20 20 20 20 20 69 6e 74 20 6e 43 6f 70 69 65 64 int nCopied
dd60: 20 3d 20 6e 4c 65 6e 67 74 68 3b 0d 0a 0d 0a 20 = nLength;....
dd70: 20 20 20 20 20 73 74 72 69 6e 67 20 73 74 72 20 string str
dd80: 3d 20 47 65 74 54 65 78 74 28 73 74 6d 74 2c 20 = GetText(stmt,
dd90: 69 6e 64 65 78 29 3b 0d 0a 20 20 20 20 20 20 6e index);.. n
dda0: 6c 65 6e 20 3d 20 73 74 72 2e 4c 65 6e 67 74 68 len = str.Length
ddb0: 3b 0d 0a 0d 0a 20 20 20 20 20 20 69 66 20 28 62 ;.... if (b
ddc0: 44 65 73 74 20 3d 3d 20 6e 75 6c 6c 29 20 72 65 Dest == null) re
ddd0: 74 75 72 6e 20 6e 6c 65 6e 3b 0d 0a 0d 0a 20 20 turn nlen;....
dde0: 20 20 20 20 69 66 20 28 6e 43 6f 70 69 65 64 20 if (nCopied
ddf0: 2b 20 6e 53 74 61 72 74 20 3e 20 62 44 65 73 74 + nStart > bDest
de00: 2e 4c 65 6e 67 74 68 29 20 6e 43 6f 70 69 65 64 .Length) nCopied
de10: 20 3d 20 62 44 65 73 74 2e 4c 65 6e 67 74 68 20 = bDest.Length
de20: 2d 20 6e 53 74 61 72 74 3b 0d 0a 20 20 20 20 20 - nStart;..
de30: 20 69 66 20 28 6e 43 6f 70 69 65 64 20 2b 20 6e if (nCopied + n
de40: 44 61 74 61 4f 66 66 73 65 74 20 3e 20 6e 6c 65 DataOffset > nle
de50: 6e 29 20 6e 43 6f 70 69 65 64 20 3d 20 6e 6c 65 n) nCopied = nle
de60: 6e 20 2d 20 6e 44 61 74 61 4f 66 66 73 65 74 3b n - nDataOffset;
de70: 0d 0a 0d 0a 20 20 20 20 20 20 69 66 20 28 6e 43 .... if (nC
de80: 6f 70 69 65 64 20 3e 20 30 29 0d 0a 20 20 20 20 opied > 0)..
de90: 20 20 20 20 73 74 72 2e 43 6f 70 79 54 6f 28 6e str.CopyTo(n
dea0: 44 61 74 61 4f 66 66 73 65 74 2c 20 62 44 65 73 DataOffset, bDes
deb0: 74 2c 20 6e 53 74 61 72 74 2c 20 6e 43 6f 70 69 t, nStart, nCopi
dec0: 65 64 29 3b 0d 0a 20 20 20 20 20 20 65 6c 73 65 ed);.. else
ded0: 20 6e 43 6f 70 69 65 64 20 3d 20 30 3b 0d 0a 0d nCopied = 0;...
dee0: 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 6e 43 . return nC
def0: 6f 70 69 65 64 3b 0d 0a 20 20 20 20 7d 0d 0a 0d opied;.. }...
df00: 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 . internal ov
df10: 65 72 72 69 64 65 20 62 6f 6f 6c 20 49 73 4e 75 erride bool IsNu
df20: 6c 6c 28 53 51 4c 69 74 65 53 74 61 74 65 6d 65 ll(SQLiteStateme
df30: 6e 74 20 73 74 6d 74 2c 20 69 6e 74 20 69 6e 64 nt stmt, int ind
df40: 65 78 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 ex).. {..
df50: 20 20 72 65 74 75 72 6e 20 28 43 6f 6c 75 6d 6e return (Column
df60: 41 66 66 69 6e 69 74 79 28 73 74 6d 74 2c 20 69 Affinity(stmt, i
df70: 6e 64 65 78 29 20 3d 3d 20 54 79 70 65 41 66 66 ndex) == TypeAff
df80: 69 6e 69 74 79 2e 4e 75 6c 6c 29 3b 0d 0a 20 20 inity.Null);..
df90: 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 }.... inter
dfa0: 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 69 6e 74 nal override int
dfb0: 20 41 67 67 72 65 67 61 74 65 43 6f 75 6e 74 28 AggregateCount(
dfc0: 49 6e 74 50 74 72 20 63 6f 6e 74 65 78 74 29 0d IntPtr context).
dfd0: 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 72 65 . {.. re
dfe0: 74 75 72 6e 20 55 6e 73 61 66 65 4e 61 74 69 76 turn UnsafeNativ
dff0: 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
e000: 5f 61 67 67 72 65 67 61 74 65 5f 63 6f 75 6e 74 _aggregate_count
e010: 28 63 6f 6e 74 65 78 74 29 3b 0d 0a 20 20 20 20 (context);..
e020: 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 }.... interna
e030: 6c 20 6f 76 65 72 72 69 64 65 20 76 6f 69 64 20 l override void
e040: 43 72 65 61 74 65 46 75 6e 63 74 69 6f 6e 28 73 CreateFunction(s
e050: 74 72 69 6e 67 20 73 74 72 46 75 6e 63 74 69 6f tring strFunctio
e060: 6e 2c 20 69 6e 74 20 6e 41 72 67 73 2c 20 62 6f n, int nArgs, bo
e070: 6f 6c 20 6e 65 65 64 43 6f 6c 6c 53 65 71 2c 20 ol needCollSeq,
e080: 53 51 4c 69 74 65 43 61 6c 6c 62 61 63 6b 20 66 SQLiteCallback f
e090: 75 6e 63 2c 20 53 51 4c 69 74 65 43 61 6c 6c 62 unc, SQLiteCallb
e0a0: 61 63 6b 20 66 75 6e 63 73 74 65 70 2c 20 53 51 ack funcstep, SQ
e0b0: 4c 69 74 65 46 69 6e 61 6c 43 61 6c 6c 62 61 63 LiteFinalCallbac
e0c0: 6b 20 66 75 6e 63 66 69 6e 61 6c 29 0d 0a 20 20 k funcfinal)..
e0d0: 20 20 7b 0d 0a 20 20 20 20 20 20 53 51 4c 69 74 {.. SQLit
e0e0: 65 45 72 72 6f 72 43 6f 64 65 20 6e 3b 0d 0a 0d eErrorCode n;...
e0f0: 0a 23 69 66 20 21 53 51 4c 49 54 45 5f 53 54 41 .#if !SQLITE_STA
e100: 4e 44 41 52 44 0d 0a 20 20 20 20 20 20 6e 20 3d NDARD.. n =
e110: 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 UnsafeNativeMet
e120: 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 63 72 65 hods.sqlite3_cre
e130: 61 74 65 5f 66 75 6e 63 74 69 6f 6e 5f 69 6e 74 ate_function_int
e140: 65 72 6f 70 28 5f 73 71 6c 2c 20 54 6f 55 54 46 erop(_sql, ToUTF
e150: 38 28 73 74 72 46 75 6e 63 74 69 6f 6e 29 2c 20 8(strFunction),
e160: 6e 41 72 67 73 2c 20 34 2c 20 49 6e 74 50 74 72 nArgs, 4, IntPtr
e170: 2e 5a 65 72 6f 2c 20 66 75 6e 63 2c 20 66 75 6e .Zero, func, fun
e180: 63 73 74 65 70 2c 20 66 75 6e 63 66 69 6e 61 6c cstep, funcfinal
e190: 2c 20 28 6e 65 65 64 43 6f 6c 6c 53 65 71 20 3d , (needCollSeq =
e1a0: 3d 20 74 72 75 65 29 20 3f 20 31 20 3a 20 30 29 = true) ? 1 : 0)
e1b0: 3b 0d 0a 20 20 20 20 20 20 69 66 20 28 6e 20 3d ;.. if (n =
e1c0: 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 = SQLiteErrorCod
e1d0: 65 2e 4f 6b 29 20 6e 20 3d 20 55 6e 73 61 66 65 e.Ok) n = Unsafe
e1e0: 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 NativeMethods.sq
e1f0: 6c 69 74 65 33 5f 63 72 65 61 74 65 5f 66 75 6e lite3_create_fun
e200: 63 74 69 6f 6e 5f 69 6e 74 65 72 6f 70 28 5f 73 ction_interop(_s
e210: 71 6c 2c 20 54 6f 55 54 46 38 28 73 74 72 46 75 ql, ToUTF8(strFu
e220: 6e 63 74 69 6f 6e 29 2c 20 6e 41 72 67 73 2c 20 nction), nArgs,
e230: 31 2c 20 49 6e 74 50 74 72 2e 5a 65 72 6f 2c 20 1, IntPtr.Zero,
e240: 66 75 6e 63 2c 20 66 75 6e 63 73 74 65 70 2c 20 func, funcstep,
e250: 66 75 6e 63 66 69 6e 61 6c 2c 20 28 6e 65 65 64 funcfinal, (need
e260: 43 6f 6c 6c 53 65 71 20 3d 3d 20 74 72 75 65 29 CollSeq == true)
e270: 20 3f 20 31 20 3a 20 30 29 3b 0d 0a 23 65 6c 73 ? 1 : 0);..#els
e280: 65 0d 0a 20 20 20 20 20 20 6e 20 3d 20 55 6e 73 e.. n = Uns
e290: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
e2a0: 2e 73 71 6c 69 74 65 33 5f 63 72 65 61 74 65 5f .sqlite3_create_
e2b0: 66 75 6e 63 74 69 6f 6e 28 5f 73 71 6c 2c 20 54 function(_sql, T
e2c0: 6f 55 54 46 38 28 73 74 72 46 75 6e 63 74 69 6f oUTF8(strFunctio
e2d0: 6e 29 2c 20 6e 41 72 67 73 2c 20 34 2c 20 49 6e n), nArgs, 4, In
e2e0: 74 50 74 72 2e 5a 65 72 6f 2c 20 66 75 6e 63 2c tPtr.Zero, func,
e2f0: 20 66 75 6e 63 73 74 65 70 2c 20 66 75 6e 63 66 funcstep, funcf
e300: 69 6e 61 6c 29 3b 0d 0a 20 20 20 20 20 20 69 66 inal);.. if
e310: 20 28 6e 20 3d 3d 20 53 51 4c 69 74 65 45 72 72 (n == SQLiteErr
e320: 6f 72 43 6f 64 65 2e 4f 6b 29 20 6e 20 3d 20 55 orCode.Ok) n = U
e330: 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
e340: 64 73 2e 73 71 6c 69 74 65 33 5f 63 72 65 61 74 ds.sqlite3_creat
e350: 65 5f 66 75 6e 63 74 69 6f 6e 28 5f 73 71 6c 2c e_function(_sql,
e360: 20 54 6f 55 54 46 38 28 73 74 72 46 75 6e 63 74 ToUTF8(strFunct
e370: 69 6f 6e 29 2c 20 6e 41 72 67 73 2c 20 31 2c 20 ion), nArgs, 1,
e380: 49 6e 74 50 74 72 2e 5a 65 72 6f 2c 20 66 75 6e IntPtr.Zero, fun
e390: 63 2c 20 66 75 6e 63 73 74 65 70 2c 20 66 75 6e c, funcstep, fun
e3a0: 63 66 69 6e 61 6c 29 3b 0d 0a 23 65 6e 64 69 66 cfinal);..#endif
e3b0: 0d 0a 20 20 20 20 20 20 69 66 20 28 6e 20 21 3d .. if (n !=
e3c0: 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 SQLiteErrorCode
e3d0: 2e 4f 6b 29 20 74 68 72 6f 77 20 6e 65 77 20 53 .Ok) throw new S
e3e0: 51 4c 69 74 65 45 78 63 65 70 74 69 6f 6e 28 6e QLiteException(n
e3f0: 2c 20 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 , GetLastError()
e400: 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 );.. }....
e410: 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 internal overri
e420: 64 65 20 76 6f 69 64 20 43 72 65 61 74 65 43 6f de void CreateCo
e430: 6c 6c 61 74 69 6f 6e 28 73 74 72 69 6e 67 20 73 llation(string s
e440: 74 72 43 6f 6c 6c 61 74 69 6f 6e 2c 20 53 51 4c trCollation, SQL
e450: 69 74 65 43 6f 6c 6c 61 74 69 6f 6e 20 66 75 6e iteCollation fun
e460: 63 2c 20 53 51 4c 69 74 65 43 6f 6c 6c 61 74 69 c, SQLiteCollati
e470: 6f 6e 20 66 75 6e 63 31 36 29 0d 0a 20 20 20 20 on func16)..
e480: 7b 0d 0a 20 20 20 20 20 20 53 51 4c 69 74 65 45 {.. SQLiteE
e490: 72 72 6f 72 43 6f 64 65 20 6e 20 3d 20 55 6e 73 rrorCode n = Uns
e4a0: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
e4b0: 2e 73 71 6c 69 74 65 33 5f 63 72 65 61 74 65 5f .sqlite3_create_
e4c0: 63 6f 6c 6c 61 74 69 6f 6e 28 5f 73 71 6c 2c 20 collation(_sql,
e4d0: 54 6f 55 54 46 38 28 73 74 72 43 6f 6c 6c 61 74 ToUTF8(strCollat
e4e0: 69 6f 6e 29 2c 20 32 2c 20 49 6e 74 50 74 72 2e ion), 2, IntPtr.
e4f0: 5a 65 72 6f 2c 20 66 75 6e 63 31 36 29 3b 0d 0a Zero, func16);..
e500: 20 20 20 20 20 20 69 66 20 28 6e 20 3d 3d 20 53 if (n == S
e510: 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 2e 4f QLiteErrorCode.O
e520: 6b 29 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 k) n = UnsafeNat
e530: 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 iveMethods.sqlit
e540: 65 33 5f 63 72 65 61 74 65 5f 63 6f 6c 6c 61 74 e3_create_collat
e550: 69 6f 6e 28 5f 73 71 6c 2c 20 54 6f 55 54 46 38 ion(_sql, ToUTF8
e560: 28 73 74 72 43 6f 6c 6c 61 74 69 6f 6e 29 2c 20 (strCollation),
e570: 31 2c 20 49 6e 74 50 74 72 2e 5a 65 72 6f 2c 20 1, IntPtr.Zero,
e580: 66 75 6e 63 29 3b 0d 0a 20 20 20 20 20 20 69 66 func);.. if
e590: 20 28 6e 20 21 3d 20 53 51 4c 69 74 65 45 72 72 (n != SQLiteErr
e5a0: 6f 72 43 6f 64 65 2e 4f 6b 29 20 74 68 72 6f 77 orCode.Ok) throw
e5b0: 20 6e 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 new SQLiteExcep
e5c0: 74 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 tion(n, GetLastE
e5d0: 72 72 6f 72 28 29 29 3b 0d 0a 20 20 20 20 7d 0d rror());.. }.
e5e0: 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 ... internal
e5f0: 6f 76 65 72 72 69 64 65 20 69 6e 74 20 43 6f 6e override int Con
e600: 74 65 78 74 43 6f 6c 6c 61 74 65 43 6f 6d 70 61 textCollateCompa
e610: 72 65 28 43 6f 6c 6c 61 74 69 6f 6e 45 6e 63 6f re(CollationEnco
e620: 64 69 6e 67 45 6e 75 6d 20 65 6e 63 2c 20 49 6e dingEnum enc, In
e630: 74 50 74 72 20 63 6f 6e 74 65 78 74 2c 20 73 74 tPtr context, st
e640: 72 69 6e 67 20 73 31 2c 20 73 74 72 69 6e 67 20 ring s1, string
e650: 73 32 29 0d 0a 20 20 20 20 7b 0d 0a 23 69 66 20 s2).. {..#if
e660: 21 53 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 !SQLITE_STANDARD
e670: 0d 0a 20 20 20 20 20 20 62 79 74 65 5b 5d 20 62 .. byte[] b
e680: 31 3b 0d 0a 20 20 20 20 20 20 62 79 74 65 5b 5d 1;.. byte[]
e690: 20 62 32 3b 0d 0a 20 20 20 20 20 20 53 79 73 74 b2;.. Syst
e6a0: 65 6d 2e 54 65 78 74 2e 45 6e 63 6f 64 69 6e 67 em.Text.Encoding
e6b0: 20 63 6f 6e 76 65 72 74 65 72 20 3d 20 6e 75 6c converter = nul
e6c0: 6c 3b 0d 0a 0d 0a 20 20 20 20 20 20 73 77 69 74 l;.... swit
e6d0: 63 68 20 28 65 6e 63 29 0d 0a 20 20 20 20 20 20 ch (enc)..
e6e0: 7b 0d 0a 20 20 20 20 20 20 20 20 63 61 73 65 20 {.. case
e6f0: 43 6f 6c 6c 61 74 69 6f 6e 45 6e 63 6f 64 69 6e CollationEncodin
e700: 67 45 6e 75 6d 2e 55 54 46 38 3a 0d 0a 20 20 20 gEnum.UTF8:..
e710: 20 20 20 20 20 20 20 63 6f 6e 76 65 72 74 65 72 converter
e720: 20 3d 20 53 79 73 74 65 6d 2e 54 65 78 74 2e 45 = System.Text.E
e730: 6e 63 6f 64 69 6e 67 2e 55 54 46 38 3b 0d 0a 20 ncoding.UTF8;..
e740: 20 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0d break;.
e750: 0a 20 20 20 20 20 20 20 20 63 61 73 65 20 43 6f . case Co
e760: 6c 6c 61 74 69 6f 6e 45 6e 63 6f 64 69 6e 67 45 llationEncodingE
e770: 6e 75 6d 2e 55 54 46 31 36 4c 45 3a 0d 0a 20 20 num.UTF16LE:..
e780: 20 20 20 20 20 20 20 20 63 6f 6e 76 65 72 74 65 converte
e790: 72 20 3d 20 53 79 73 74 65 6d 2e 54 65 78 74 2e r = System.Text.
e7a0: 45 6e 63 6f 64 69 6e 67 2e 55 6e 69 63 6f 64 65 Encoding.Unicode
e7b0: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 62 72 65 ;.. bre
e7c0: 61 6b 3b 0d 0a 20 20 20 20 20 20 20 20 63 61 73 ak;.. cas
e7d0: 65 20 43 6f 6c 6c 61 74 69 6f 6e 45 6e 63 6f 64 e CollationEncod
e7e0: 69 6e 67 45 6e 75 6d 2e 55 54 46 31 36 42 45 3a ingEnum.UTF16BE:
e7f0: 0d 0a 20 20 20 20 20 20 20 20 20 20 63 6f 6e 76 .. conv
e800: 65 72 74 65 72 20 3d 20 53 79 73 74 65 6d 2e 54 erter = System.T
e810: 65 78 74 2e 45 6e 63 6f 64 69 6e 67 2e 42 69 67 ext.Encoding.Big
e820: 45 6e 64 69 61 6e 55 6e 69 63 6f 64 65 3b 0d 0a EndianUnicode;..
e830: 20 20 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b break;
e840: 0d 0a 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 .. }....
e850: 20 20 20 62 31 20 3d 20 63 6f 6e 76 65 72 74 65 b1 = converte
e860: 72 2e 47 65 74 42 79 74 65 73 28 73 31 29 3b 0d r.GetBytes(s1);.
e870: 0a 20 20 20 20 20 20 62 32 20 3d 20 63 6f 6e 76 . b2 = conv
e880: 65 72 74 65 72 2e 47 65 74 42 79 74 65 73 28 73 erter.GetBytes(s
e890: 32 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 72 65 74 2);.... ret
e8a0: 75 72 6e 20 55 6e 73 61 66 65 4e 61 74 69 76 65 urn UnsafeNative
e8b0: 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f Methods.sqlite3_
e8c0: 63 6f 6e 74 65 78 74 5f 63 6f 6c 6c 63 6f 6d 70 context_collcomp
e8d0: 61 72 65 5f 69 6e 74 65 72 6f 70 28 63 6f 6e 74 are_interop(cont
e8e0: 65 78 74 2c 20 62 31 2c 20 62 31 2e 4c 65 6e 67 ext, b1, b1.Leng
e8f0: 74 68 2c 20 62 32 2c 20 62 32 2e 4c 65 6e 67 74 th, b2, b2.Lengt
e900: 68 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 h);..#else..
e910: 20 20 74 68 72 6f 77 20 6e 65 77 20 4e 6f 74 49 throw new NotI
e920: 6d 70 6c 65 6d 65 6e 74 65 64 45 78 63 65 70 74 mplementedExcept
e930: 69 6f 6e 28 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a ion();..#endif..
e940: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 }.... int
e950: 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 69 ernal override i
e960: 6e 74 20 43 6f 6e 74 65 78 74 43 6f 6c 6c 61 74 nt ContextCollat
e970: 65 43 6f 6d 70 61 72 65 28 43 6f 6c 6c 61 74 69 eCompare(Collati
e980: 6f 6e 45 6e 63 6f 64 69 6e 67 45 6e 75 6d 20 65 onEncodingEnum e
e990: 6e 63 2c 20 49 6e 74 50 74 72 20 63 6f 6e 74 65 nc, IntPtr conte
e9a0: 78 74 2c 20 63 68 61 72 5b 5d 20 63 31 2c 20 63 xt, char[] c1, c
e9b0: 68 61 72 5b 5d 20 63 32 29 0d 0a 20 20 20 20 7b har[] c2).. {
e9c0: 0d 0a 23 69 66 20 21 53 51 4c 49 54 45 5f 53 54 ..#if !SQLITE_ST
e9d0: 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 20 62 79 ANDARD.. by
e9e0: 74 65 5b 5d 20 62 31 3b 0d 0a 20 20 20 20 20 20 te[] b1;..
e9f0: 62 79 74 65 5b 5d 20 62 32 3b 0d 0a 20 20 20 20 byte[] b2;..
ea00: 20 20 53 79 73 74 65 6d 2e 54 65 78 74 2e 45 6e System.Text.En
ea10: 63 6f 64 69 6e 67 20 63 6f 6e 76 65 72 74 65 72 coding converter
ea20: 20 3d 20 6e 75 6c 6c 3b 0d 0a 0d 0a 20 20 20 20 = null;....
ea30: 20 20 73 77 69 74 63 68 20 28 65 6e 63 29 0d 0a switch (enc)..
ea40: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
ea50: 20 63 61 73 65 20 43 6f 6c 6c 61 74 69 6f 6e 45 case CollationE
ea60: 6e 63 6f 64 69 6e 67 45 6e 75 6d 2e 55 54 46 38 ncodingEnum.UTF8
ea70: 3a 0d 0a 20 20 20 20 20 20 20 20 20 20 63 6f 6e :.. con
ea80: 76 65 72 74 65 72 20 3d 20 53 79 73 74 65 6d 2e verter = System.
ea90: 54 65 78 74 2e 45 6e 63 6f 64 69 6e 67 2e 55 54 Text.Encoding.UT
eaa0: 46 38 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 62 F8;.. b
eab0: 72 65 61 6b 3b 0d 0a 20 20 20 20 20 20 20 20 63 reak;.. c
eac0: 61 73 65 20 43 6f 6c 6c 61 74 69 6f 6e 45 6e 63 ase CollationEnc
ead0: 6f 64 69 6e 67 45 6e 75 6d 2e 55 54 46 31 36 4c odingEnum.UTF16L
eae0: 45 3a 0d 0a 20 20 20 20 20 20 20 20 20 20 63 6f E:.. co
eaf0: 6e 76 65 72 74 65 72 20 3d 20 53 79 73 74 65 6d nverter = System
eb00: 2e 54 65 78 74 2e 45 6e 63 6f 64 69 6e 67 2e 55 .Text.Encoding.U
eb10: 6e 69 63 6f 64 65 3b 0d 0a 20 20 20 20 20 20 20 nicode;..
eb20: 20 20 20 62 72 65 61 6b 3b 0d 0a 20 20 20 20 20 break;..
eb30: 20 20 20 63 61 73 65 20 43 6f 6c 6c 61 74 69 6f case Collatio
eb40: 6e 45 6e 63 6f 64 69 6e 67 45 6e 75 6d 2e 55 54 nEncodingEnum.UT
eb50: 46 31 36 42 45 3a 0d 0a 20 20 20 20 20 20 20 20 F16BE:..
eb60: 20 20 63 6f 6e 76 65 72 74 65 72 20 3d 20 53 79 converter = Sy
eb70: 73 74 65 6d 2e 54 65 78 74 2e 45 6e 63 6f 64 69 stem.Text.Encodi
eb80: 6e 67 2e 42 69 67 45 6e 64 69 61 6e 55 6e 69 63 ng.BigEndianUnic
eb90: 6f 64 65 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 ode;..
eba0: 62 72 65 61 6b 3b 0d 0a 20 20 20 20 20 20 7d 0d break;.. }.
ebb0: 0a 0d 0a 20 20 20 20 20 20 62 31 20 3d 20 63 6f ... b1 = co
ebc0: 6e 76 65 72 74 65 72 2e 47 65 74 42 79 74 65 73 nverter.GetBytes
ebd0: 28 63 31 29 3b 0d 0a 20 20 20 20 20 20 62 32 20 (c1);.. b2
ebe0: 3d 20 63 6f 6e 76 65 72 74 65 72 2e 47 65 74 42 = converter.GetB
ebf0: 79 74 65 73 28 63 32 29 3b 0d 0a 0d 0a 20 20 20 ytes(c2);....
ec00: 20 20 20 72 65 74 75 72 6e 20 55 6e 73 61 66 65 return Unsafe
ec10: 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 NativeMethods.sq
ec20: 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 5f 63 6f lite3_context_co
ec30: 6c 6c 63 6f 6d 70 61 72 65 5f 69 6e 74 65 72 6f llcompare_intero
ec40: 70 28 63 6f 6e 74 65 78 74 2c 20 62 31 2c 20 62 p(context, b1, b
ec50: 31 2e 4c 65 6e 67 74 68 2c 20 62 32 2c 20 62 32 1.Length, b2, b2
ec60: 2e 4c 65 6e 67 74 68 29 3b 0d 0a 23 65 6c 73 65 .Length);..#else
ec70: 0d 0a 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 .. throw ne
ec80: 77 20 4e 6f 74 49 6d 70 6c 65 6d 65 6e 74 65 64 w NotImplemented
ec90: 45 78 63 65 70 74 69 6f 6e 28 29 3b 0d 0a 23 65 Exception();..#e
eca0: 6e 64 69 66 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 ndif.. }....
ecb0: 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 internal over
ecc0: 72 69 64 65 20 43 6f 6c 6c 61 74 69 6f 6e 53 65 ride CollationSe
ecd0: 71 75 65 6e 63 65 20 47 65 74 43 6f 6c 6c 61 74 quence GetCollat
ece0: 69 6f 6e 53 65 71 75 65 6e 63 65 28 53 51 4c 69 ionSequence(SQLi
ecf0: 74 65 46 75 6e 63 74 69 6f 6e 20 66 75 6e 63 2c teFunction func,
ed00: 20 49 6e 74 50 74 72 20 63 6f 6e 74 65 78 74 29 IntPtr context)
ed10: 0d 0a 20 20 20 20 7b 0d 0a 23 69 66 20 21 53 51 .. {..#if !SQ
ed20: 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a 20 LITE_STANDARD..
ed30: 20 20 20 20 20 43 6f 6c 6c 61 74 69 6f 6e 53 65 CollationSe
ed40: 71 75 65 6e 63 65 20 73 65 71 20 3d 20 6e 65 77 quence seq = new
ed50: 20 43 6f 6c 6c 61 74 69 6f 6e 53 65 71 75 65 6e CollationSequen
ed60: 63 65 28 29 3b 0d 0a 20 20 20 20 20 20 69 6e 74 ce();.. int
ed70: 20 6c 65 6e 3b 0d 0a 20 20 20 20 20 20 69 6e 74 len;.. int
ed80: 20 74 79 70 65 3b 0d 0a 20 20 20 20 20 20 69 6e type;.. in
ed90: 74 20 65 6e 63 3b 0d 0a 20 20 20 20 20 20 49 6e t enc;.. In
eda0: 74 50 74 72 20 70 20 3d 20 55 6e 73 61 66 65 4e tPtr p = UnsafeN
edb0: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
edc0: 69 74 65 33 5f 63 6f 6e 74 65 78 74 5f 63 6f 6c ite3_context_col
edd0: 6c 73 65 71 5f 69 6e 74 65 72 6f 70 28 63 6f 6e lseq_interop(con
ede0: 74 65 78 74 2c 20 6f 75 74 20 74 79 70 65 2c 20 text, out type,
edf0: 6f 75 74 20 65 6e 63 2c 20 6f 75 74 20 6c 65 6e out enc, out len
ee00: 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 69 66 20 28 );.... if (
ee10: 70 20 21 3d 20 6e 75 6c 6c 29 20 73 65 71 2e 4e p != null) seq.N
ee20: 61 6d 65 20 3d 20 55 54 46 38 54 6f 53 74 72 69 ame = UTF8ToStri
ee30: 6e 67 28 70 2c 20 6c 65 6e 29 3b 0d 0a 20 20 20 ng(p, len);..
ee40: 20 20 20 73 65 71 2e 54 79 70 65 20 3d 20 28 43 seq.Type = (C
ee50: 6f 6c 6c 61 74 69 6f 6e 54 79 70 65 45 6e 75 6d ollationTypeEnum
ee60: 29 74 79 70 65 3b 0d 0a 20 20 20 20 20 20 73 65 )type;.. se
ee70: 71 2e 5f 66 75 6e 63 20 3d 20 66 75 6e 63 3b 0d q._func = func;.
ee80: 0a 20 20 20 20 20 20 73 65 71 2e 45 6e 63 6f 64 . seq.Encod
ee90: 69 6e 67 20 3d 20 28 43 6f 6c 6c 61 74 69 6f 6e ing = (Collation
eea0: 45 6e 63 6f 64 69 6e 67 45 6e 75 6d 29 65 6e 63 EncodingEnum)enc
eeb0: 3b 0d 0a 0d 0a 20 20 20 20 20 20 72 65 74 75 72 ;.... retur
eec0: 6e 20 73 65 71 3b 0d 0a 23 65 6c 73 65 0d 0a 20 n seq;..#else..
eed0: 20 20 20 20 20 74 68 72 6f 77 20 6e 65 77 20 4e throw new N
eee0: 6f 74 49 6d 70 6c 65 6d 65 6e 74 65 64 45 78 63 otImplementedExc
eef0: 65 70 74 69 6f 6e 28 29 3b 0d 0a 23 65 6e 64 69 eption();..#endi
ef00: 66 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 f.. }....
ef10: 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 internal overrid
ef20: 65 20 6c 6f 6e 67 20 47 65 74 50 61 72 61 6d 56 e long GetParamV
ef30: 61 6c 75 65 42 79 74 65 73 28 49 6e 74 50 74 72 alueBytes(IntPtr
ef40: 20 70 2c 20 69 6e 74 20 6e 44 61 74 61 4f 66 66 p, int nDataOff
ef50: 73 65 74 2c 20 62 79 74 65 5b 5d 20 62 44 65 73 set, byte[] bDes
ef60: 74 2c 20 69 6e 74 20 6e 53 74 61 72 74 2c 20 69 t, int nStart, i
ef70: 6e 74 20 6e 4c 65 6e 67 74 68 29 0d 0a 20 20 20 nt nLength)..
ef80: 20 7b 0d 0a 20 20 20 20 20 20 69 6e 74 20 6e 6c {.. int nl
ef90: 65 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 en = UnsafeNativ
efa0: 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
efb0: 5f 76 61 6c 75 65 5f 62 79 74 65 73 28 70 29 3b _value_bytes(p);
efc0: 0d 0a 0d 0a 20 20 20 20 20 20 2f 2f 20 49 66 20 .... // If
efd0: 6e 6f 20 64 65 73 74 69 6e 61 74 69 6f 6e 20 62 no destination b
efe0: 75 66 66 65 72 2c 20 72 65 74 75 72 6e 20 74 68 uffer, return th
eff0: 65 20 73 69 7a 65 20 6e 65 65 64 65 64 2e 0d 0a e size needed...
f000: 20 20 20 20 20 20 69 66 20 28 62 44 65 73 74 20 if (bDest
f010: 3d 3d 20 6e 75 6c 6c 29 20 72 65 74 75 72 6e 20 == null) return
f020: 6e 6c 65 6e 3b 0d 0a 0d 0a 20 20 20 20 20 20 69 nlen;.... i
f030: 6e 74 20 6e 43 6f 70 69 65 64 20 3d 20 6e 4c 65 nt nCopied = nLe
f040: 6e 67 74 68 3b 0d 0a 0d 0a 20 20 20 20 20 20 69 ngth;.... i
f050: 66 20 28 6e 43 6f 70 69 65 64 20 2b 20 6e 53 74 f (nCopied + nSt
f060: 61 72 74 20 3e 20 62 44 65 73 74 2e 4c 65 6e 67 art > bDest.Leng
f070: 74 68 29 20 6e 43 6f 70 69 65 64 20 3d 20 62 44 th) nCopied = bD
f080: 65 73 74 2e 4c 65 6e 67 74 68 20 2d 20 6e 53 74 est.Length - nSt
f090: 61 72 74 3b 0d 0a 20 20 20 20 20 20 69 66 20 28 art;.. if (
f0a0: 6e 43 6f 70 69 65 64 20 2b 20 6e 44 61 74 61 4f nCopied + nDataO
f0b0: 66 66 73 65 74 20 3e 20 6e 6c 65 6e 29 20 6e 43 ffset > nlen) nC
f0c0: 6f 70 69 65 64 20 3d 20 6e 6c 65 6e 20 2d 20 6e opied = nlen - n
f0d0: 44 61 74 61 4f 66 66 73 65 74 3b 0d 0a 0d 0a 20 DataOffset;....
f0e0: 20 20 20 20 20 69 66 20 28 6e 43 6f 70 69 65 64 if (nCopied
f0f0: 20 3e 20 30 29 0d 0a 20 20 20 20 20 20 7b 0d 0a > 0).. {..
f100: 20 20 20 20 20 20 20 20 49 6e 74 50 74 72 20 70 IntPtr p
f110: 74 72 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 tr = UnsafeNativ
f120: 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
f130: 5f 76 61 6c 75 65 5f 62 6c 6f 62 28 70 29 3b 0d _value_blob(p);.
f140: 0a 0d 0a 20 20 20 20 20 20 20 20 4d 61 72 73 68 ... Marsh
f150: 61 6c 2e 43 6f 70 79 28 28 49 6e 74 50 74 72 29 al.Copy((IntPtr)
f160: 28 70 74 72 2e 54 6f 49 6e 74 36 34 28 29 20 2b (ptr.ToInt64() +
f170: 20 6e 44 61 74 61 4f 66 66 73 65 74 29 2c 20 62 nDataOffset), b
f180: 44 65 73 74 2c 20 6e 53 74 61 72 74 2c 20 6e 43 Dest, nStart, nC
f190: 6f 70 69 65 64 29 3b 0d 0a 20 20 20 20 20 20 7d opied);.. }
f1a0: 0d 0a 20 20 20 20 20 20 65 6c 73 65 0d 0a 20 20 .. else..
f1b0: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 6e {.. n
f1c0: 43 6f 70 69 65 64 20 3d 20 30 3b 0d 0a 20 20 20 Copied = 0;..
f1d0: 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 72 65 }.... re
f1e0: 74 75 72 6e 20 6e 43 6f 70 69 65 64 3b 0d 0a 20 turn nCopied;..
f1f0: 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 }.... inte
f200: 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 64 6f rnal override do
f210: 75 62 6c 65 20 47 65 74 50 61 72 61 6d 56 61 6c uble GetParamVal
f220: 75 65 44 6f 75 62 6c 65 28 49 6e 74 50 74 72 20 ueDouble(IntPtr
f230: 70 74 72 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 ptr).. {..
f240: 20 20 20 64 6f 75 62 6c 65 20 76 61 6c 75 65 3b double value;
f250: 0d 0a 23 69 66 20 21 50 4c 41 54 46 4f 52 4d 5f ..#if !PLATFORM_
f260: 43 4f 4d 50 41 43 54 46 52 41 4d 45 57 4f 52 4b COMPACTFRAMEWORK
f270: 0d 0a 20 20 20 20 20 20 76 61 6c 75 65 20 3d 20 .. value =
f280: 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 UnsafeNativeMeth
f290: 6f 64 73 2e 73 71 6c 69 74 65 33 5f 76 61 6c 75 ods.sqlite3_valu
f2a0: 65 5f 64 6f 75 62 6c 65 28 70 74 72 29 3b 0d 0a e_double(ptr);..
f2b0: 23 65 6c 69 66 20 21 53 51 4c 49 54 45 5f 53 54 #elif !SQLITE_ST
f2c0: 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 20 55 6e ANDARD.. Un
f2d0: 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 safeNativeMethod
f2e0: 73 2e 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 5f s.sqlite3_value_
f2f0: 64 6f 75 62 6c 65 5f 69 6e 74 65 72 6f 70 28 70 double_interop(p
f300: 74 72 2c 20 6f 75 74 20 76 61 6c 75 65 29 3b 0d tr, out value);.
f310: 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 74 68 .#else.. th
f320: 72 6f 77 20 6e 65 77 20 4e 6f 74 49 6d 70 6c 65 row new NotImple
f330: 6d 65 6e 74 65 64 45 78 63 65 70 74 69 6f 6e 28 mentedException(
f340: 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 );..#endif..
f350: 20 20 72 65 74 75 72 6e 20 76 61 6c 75 65 3b 0d return value;.
f360: 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e . }.... in
f370: 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 ternal override
f380: 69 6e 74 20 47 65 74 50 61 72 61 6d 56 61 6c 75 int GetParamValu
f390: 65 49 6e 74 33 32 28 49 6e 74 50 74 72 20 70 74 eInt32(IntPtr pt
f3a0: 72 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 r).. {..
f3b0: 20 72 65 74 75 72 6e 20 55 6e 73 61 66 65 4e 61 return UnsafeNa
f3c0: 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 tiveMethods.sqli
f3d0: 74 65 33 5f 76 61 6c 75 65 5f 69 6e 74 28 70 74 te3_value_int(pt
f3e0: 72 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 r);.. }....
f3f0: 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
f400: 69 64 65 20 6c 6f 6e 67 20 47 65 74 50 61 72 61 ide long GetPara
f410: 6d 56 61 6c 75 65 49 6e 74 36 34 28 49 6e 74 50 mValueInt64(IntP
f420: 74 72 20 70 74 72 29 0d 0a 20 20 20 20 7b 0d 0a tr ptr).. {..
f430: 20 20 20 20 20 20 49 6e 74 36 34 20 76 61 6c 75 Int64 valu
f440: 65 3b 0d 0a 23 69 66 20 21 50 4c 41 54 46 4f 52 e;..#if !PLATFOR
f450: 4d 5f 43 4f 4d 50 41 43 54 46 52 41 4d 45 57 4f M_COMPACTFRAMEWO
f460: 52 4b 0d 0a 20 20 20 20 20 20 76 61 6c 75 65 20 RK.. value
f470: 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 = UnsafeNativeMe
f480: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 76 61 thods.sqlite3_va
f490: 6c 75 65 5f 69 6e 74 36 34 28 70 74 72 29 3b 0d lue_int64(ptr);.
f4a0: 0a 23 65 6c 69 66 20 21 53 51 4c 49 54 45 5f 53 .#elif !SQLITE_S
f4b0: 54 41 4e 44 41 52 44 0d 0a 20 20 20 20 20 20 55 TANDARD.. U
f4c0: 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
f4d0: 64 73 2e 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 ds.sqlite3_value
f4e0: 5f 69 6e 74 36 34 5f 69 6e 74 65 72 6f 70 28 70 _int64_interop(p
f4f0: 74 72 2c 20 6f 75 74 20 76 61 6c 75 65 29 3b 0d tr, out value);.
f500: 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 74 68 .#else.. th
f510: 72 6f 77 20 6e 65 77 20 4e 6f 74 49 6d 70 6c 65 row new NotImple
f520: 6d 65 6e 74 65 64 45 78 63 65 70 74 69 6f 6e 28 mentedException(
f530: 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 );..#endif..
f540: 20 20 72 65 74 75 72 6e 20 76 61 6c 75 65 3b 0d return value;.
f550: 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e . }.... in
f560: 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 ternal override
f570: 73 74 72 69 6e 67 20 47 65 74 50 61 72 61 6d 56 string GetParamV
f580: 61 6c 75 65 54 65 78 74 28 49 6e 74 50 74 72 20 alueText(IntPtr
f590: 70 74 72 29 0d 0a 20 20 20 20 7b 0d 0a 23 69 66 ptr).. {..#if
f5a0: 20 21 53 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 !SQLITE_STANDAR
f5b0: 44 0d 0a 20 20 20 20 20 20 69 6e 74 20 6c 65 6e D.. int len
f5c0: 3b 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 ;.. return
f5d0: 55 54 46 38 54 6f 53 74 72 69 6e 67 28 55 6e 73 UTF8ToString(Uns
f5e0: 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 afeNativeMethods
f5f0: 2e 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 5f 74 .sqlite3_value_t
f600: 65 78 74 5f 69 6e 74 65 72 6f 70 28 70 74 72 2c ext_interop(ptr,
f610: 20 6f 75 74 20 6c 65 6e 29 2c 20 6c 65 6e 29 3b out len), len);
f620: 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 72 ..#else.. r
f630: 65 74 75 72 6e 20 55 54 46 38 54 6f 53 74 72 69 eturn UTF8ToStri
f640: 6e 67 28 55 6e 73 61 66 65 4e 61 74 69 76 65 4d ng(UnsafeNativeM
f650: 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 76 ethods.sqlite3_v
f660: 61 6c 75 65 5f 74 65 78 74 28 70 74 72 29 2c 0d alue_text(ptr),.
f670: 0a 20 20 20 20 20 20 20 20 55 6e 73 61 66 65 4e . UnsafeN
f680: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
f690: 69 74 65 33 5f 76 61 6c 75 65 5f 62 79 74 65 73 ite3_value_bytes
f6a0: 28 70 74 72 29 29 3b 0d 0a 23 65 6e 64 69 66 0d (ptr));..#endif.
f6b0: 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e . }.... in
f6c0: 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 ternal override
f6d0: 54 79 70 65 41 66 66 69 6e 69 74 79 20 47 65 74 TypeAffinity Get
f6e0: 50 61 72 61 6d 56 61 6c 75 65 54 79 70 65 28 49 ParamValueType(I
f6f0: 6e 74 50 74 72 20 70 74 72 29 0d 0a 20 20 20 20 ntPtr ptr)..
f700: 7b 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 {.. return
f710: 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 UnsafeNativeMeth
f720: 6f 64 73 2e 73 71 6c 69 74 65 33 5f 76 61 6c 75 ods.sqlite3_valu
f730: 65 5f 74 79 70 65 28 70 74 72 29 3b 0d 0a 20 20 e_type(ptr);..
f740: 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 }.... inter
f750: 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 76 6f 69 nal override voi
f760: 64 20 52 65 74 75 72 6e 42 6c 6f 62 28 49 6e 74 d ReturnBlob(Int
f770: 50 74 72 20 63 6f 6e 74 65 78 74 2c 20 62 79 74 Ptr context, byt
f780: 65 5b 5d 20 76 61 6c 75 65 29 0d 0a 20 20 20 20 e[] value)..
f790: 7b 0d 0a 20 20 20 20 20 20 55 6e 73 61 66 65 4e {.. UnsafeN
f7a0: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
f7b0: 69 74 65 33 5f 72 65 73 75 6c 74 5f 62 6c 6f 62 ite3_result_blob
f7c0: 28 63 6f 6e 74 65 78 74 2c 20 76 61 6c 75 65 2c (context, value,
f7d0: 20 76 61 6c 75 65 2e 4c 65 6e 67 74 68 2c 20 28 value.Length, (
f7e0: 49 6e 74 50 74 72 29 28 2d 31 29 29 3b 0d 0a 20 IntPtr)(-1));..
f7f0: 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 }.... inte
f800: 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 76 6f rnal override vo
f810: 69 64 20 52 65 74 75 72 6e 44 6f 75 62 6c 65 28 id ReturnDouble(
f820: 49 6e 74 50 74 72 20 63 6f 6e 74 65 78 74 2c 20 IntPtr context,
f830: 64 6f 75 62 6c 65 20 76 61 6c 75 65 29 0d 0a 20 double value)..
f840: 20 20 20 7b 0d 0a 23 69 66 20 21 50 4c 41 54 46 {..#if !PLATF
f850: 4f 52 4d 5f 43 4f 4d 50 41 43 54 46 52 41 4d 45 ORM_COMPACTFRAME
f860: 57 4f 52 4b 0d 0a 20 20 20 20 20 20 55 6e 73 61 WORK.. Unsa
f870: 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
f880: 73 71 6c 69 74 65 33 5f 72 65 73 75 6c 74 5f 64 sqlite3_result_d
f890: 6f 75 62 6c 65 28 63 6f 6e 74 65 78 74 2c 20 76 ouble(context, v
f8a0: 61 6c 75 65 29 3b 0d 0a 23 65 6c 69 66 20 21 53 alue);..#elif !S
f8b0: 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a QLITE_STANDARD..
f8c0: 20 20 20 20 20 20 55 6e 73 61 66 65 4e 61 74 69 UnsafeNati
f8d0: 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 veMethods.sqlite
f8e0: 33 5f 72 65 73 75 6c 74 5f 64 6f 75 62 6c 65 5f 3_result_double_
f8f0: 69 6e 74 65 72 6f 70 28 63 6f 6e 74 65 78 74 2c interop(context,
f900: 20 72 65 66 20 76 61 6c 75 65 29 3b 0d 0a 23 65 ref value);..#e
f910: 6c 73 65 0d 0a 20 20 20 20 20 20 74 68 72 6f 77 lse.. throw
f920: 20 6e 65 77 20 4e 6f 74 49 6d 70 6c 65 6d 65 6e new NotImplemen
f930: 74 65 64 45 78 63 65 70 74 69 6f 6e 28 29 3b 0d tedException();.
f940: 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 7d 0d 0a .#endif.. }..
f950: 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
f960: 76 65 72 72 69 64 65 20 76 6f 69 64 20 52 65 74 verride void Ret
f970: 75 72 6e 45 72 72 6f 72 28 49 6e 74 50 74 72 20 urnError(IntPtr
f980: 63 6f 6e 74 65 78 74 2c 20 73 74 72 69 6e 67 20 context, string
f990: 76 61 6c 75 65 29 0d 0a 20 20 20 20 7b 0d 0a 20 value).. {..
f9a0: 20 20 20 20 20 55 6e 73 61 66 65 4e 61 74 69 76 UnsafeNativ
f9b0: 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
f9c0: 5f 72 65 73 75 6c 74 5f 65 72 72 6f 72 28 63 6f _result_error(co
f9d0: 6e 74 65 78 74 2c 20 54 6f 55 54 46 38 28 76 61 ntext, ToUTF8(va
f9e0: 6c 75 65 29 2c 20 76 61 6c 75 65 2e 4c 65 6e 67 lue), value.Leng
f9f0: 74 68 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 th);.. }....
fa00: 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 internal over
fa10: 72 69 64 65 20 76 6f 69 64 20 52 65 74 75 72 6e ride void Return
fa20: 49 6e 74 33 32 28 49 6e 74 50 74 72 20 63 6f 6e Int32(IntPtr con
fa30: 74 65 78 74 2c 20 69 6e 74 20 76 61 6c 75 65 29 text, int value)
fa40: 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 55 .. {.. U
fa50: 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
fa60: 64 73 2e 73 71 6c 69 74 65 33 5f 72 65 73 75 6c ds.sqlite3_resul
fa70: 74 5f 69 6e 74 28 63 6f 6e 74 65 78 74 2c 20 76 t_int(context, v
fa80: 61 6c 75 65 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d alue);.. }...
fa90: 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 . internal ov
faa0: 65 72 72 69 64 65 20 76 6f 69 64 20 52 65 74 75 erride void Retu
fab0: 72 6e 49 6e 74 36 34 28 49 6e 74 50 74 72 20 63 rnInt64(IntPtr c
fac0: 6f 6e 74 65 78 74 2c 20 6c 6f 6e 67 20 76 61 6c ontext, long val
fad0: 75 65 29 0d 0a 20 20 20 20 7b 0d 0a 23 69 66 20 ue).. {..#if
fae0: 21 50 4c 41 54 46 4f 52 4d 5f 43 4f 4d 50 41 43 !PLATFORM_COMPAC
faf0: 54 46 52 41 4d 45 57 4f 52 4b 0d 0a 20 20 20 20 TFRAMEWORK..
fb00: 20 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 UnsafeNativeMe
fb10: 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 72 65 thods.sqlite3_re
fb20: 73 75 6c 74 5f 69 6e 74 36 34 28 63 6f 6e 74 65 sult_int64(conte
fb30: 78 74 2c 20 76 61 6c 75 65 29 3b 0d 0a 23 65 6c xt, value);..#el
fb40: 69 66 20 21 53 51 4c 49 54 45 5f 53 54 41 4e 44 if !SQLITE_STAND
fb50: 41 52 44 0d 0a 20 20 20 20 20 20 55 6e 73 61 66 ARD.. Unsaf
fb60: 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
fb70: 71 6c 69 74 65 33 5f 72 65 73 75 6c 74 5f 69 6e qlite3_result_in
fb80: 74 36 34 5f 69 6e 74 65 72 6f 70 28 63 6f 6e 74 t64_interop(cont
fb90: 65 78 74 2c 20 72 65 66 20 76 61 6c 75 65 29 3b ext, ref value);
fba0: 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 20 20 74 ..#else.. t
fbb0: 68 72 6f 77 20 6e 65 77 20 4e 6f 74 49 6d 70 6c hrow new NotImpl
fbc0: 65 6d 65 6e 74 65 64 45 78 63 65 70 74 69 6f 6e ementedException
fbd0: 28 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 ();..#endif..
fbe0: 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e }.... intern
fbf0: 61 6c 20 6f 76 65 72 72 69 64 65 20 76 6f 69 64 al override void
fc00: 20 52 65 74 75 72 6e 4e 75 6c 6c 28 49 6e 74 50 ReturnNull(IntP
fc10: 74 72 20 63 6f 6e 74 65 78 74 29 0d 0a 20 20 20 tr context)..
fc20: 20 7b 0d 0a 20 20 20 20 20 20 55 6e 73 61 66 65 {.. Unsafe
fc30: 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 NativeMethods.sq
fc40: 6c 69 74 65 33 5f 72 65 73 75 6c 74 5f 6e 75 6c lite3_result_nul
fc50: 6c 28 63 6f 6e 74 65 78 74 29 3b 0d 0a 20 20 20 l(context);..
fc60: 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e }.... intern
fc70: 61 6c 20 6f 76 65 72 72 69 64 65 20 76 6f 69 64 al override void
fc80: 20 52 65 74 75 72 6e 54 65 78 74 28 49 6e 74 50 ReturnText(IntP
fc90: 74 72 20 63 6f 6e 74 65 78 74 2c 20 73 74 72 69 tr context, stri
fca0: 6e 67 20 76 61 6c 75 65 29 0d 0a 20 20 20 20 7b ng value).. {
fcb0: 0d 0a 20 20 20 20 20 20 62 79 74 65 5b 5d 20 62 .. byte[] b
fcc0: 20 3d 20 54 6f 55 54 46 38 28 76 61 6c 75 65 29 = ToUTF8(value)
fcd0: 3b 0d 0a 20 20 20 20 20 20 55 6e 73 61 66 65 4e ;.. UnsafeN
fce0: 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
fcf0: 69 74 65 33 5f 72 65 73 75 6c 74 5f 74 65 78 74 ite3_result_text
fd00: 28 63 6f 6e 74 65 78 74 2c 20 54 6f 55 54 46 38 (context, ToUTF8
fd10: 28 76 61 6c 75 65 29 2c 20 62 2e 4c 65 6e 67 74 (value), b.Lengt
fd20: 68 20 2d 20 31 2c 20 28 49 6e 74 50 74 72 29 28 h - 1, (IntPtr)(
fd30: 2d 31 29 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a -1));.. }....
fd40: 23 69 66 20 49 4e 54 45 52 4f 50 5f 56 49 52 54 #if INTEROP_VIRT
fd50: 55 41 4c 5f 54 41 42 4c 45 0d 0a 20 20 20 20 2f UAL_TABLE.. /
fd60: 2f 2f 20 3c 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 // <summary>..
fd70: 20 20 2f 2f 2f 20 43 61 6c 6c 73 20 74 68 65 20 /// Calls the
fd80: 6e 61 74 69 76 65 20 53 51 4c 69 74 65 20 63 6f native SQLite co
fd90: 72 65 20 6c 69 62 72 61 72 79 20 69 6e 20 6f 72 re library in or
fda0: 64 65 72 20 74 6f 20 63 72 65 61 74 65 20 61 20 der to create a
fdb0: 64 69 73 70 6f 73 61 62 6c 65 0d 0a 20 20 20 20 disposable..
fdc0: 2f 2f 2f 20 6d 6f 64 75 6c 65 20 63 6f 6e 74 61 /// module conta
fdd0: 69 6e 69 6e 67 20 74 68 65 20 69 6d 70 6c 65 6d ining the implem
fde0: 65 6e 74 61 74 69 6f 6e 20 6f 66 20 61 20 76 69 entation of a vi
fdf0: 72 74 75 61 6c 20 74 61 62 6c 65 2e 0d 0a 20 20 rtual table...
fe00: 20 20 2f 2f 2f 20 3c 2f 73 75 6d 6d 61 72 79 3e /// </summary>
fe10: 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 72 61 6d .. /// <param
fe20: 20 6e 61 6d 65 3d 22 6d 6f 64 75 6c 65 22 3e 0d name="module">.
fe30: 0a 20 20 20 20 2f 2f 2f 20 54 68 65 20 6d 6f 64 . /// The mod
fe40: 75 6c 65 20 6f 62 6a 65 63 74 20 74 6f 20 62 65 ule object to be
fe50: 20 75 73 65 64 20 77 68 65 6e 20 63 72 65 61 74 used when creat
fe60: 69 6e 67 20 74 68 65 20 6e 61 74 69 76 65 20 64 ing the native d
fe70: 69 73 70 6f 73 61 62 6c 65 20 6d 6f 64 75 6c 65 isposable module
fe80: 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 70 61 72 ... /// </par
fe90: 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 am>.. /// <pa
fea0: 72 61 6d 20 6e 61 6d 65 3d 22 66 6c 61 67 73 22 ram name="flags"
feb0: 3e 0d 0a 20 20 20 20 2f 2f 2f 20 54 68 65 20 66 >.. /// The f
fec0: 6c 61 67 73 20 66 6f 72 20 74 68 65 20 61 73 73 lags for the ass
fed0: 6f 63 69 61 74 65 64 20 3c 73 65 65 20 63 72 65 ociated <see cre
fee0: 66 3d 22 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 f="SQLiteConnect
fef0: 69 6f 6e 22 20 2f 3e 20 6f 62 6a 65 63 74 20 69 ion" /> object i
ff00: 6e 73 74 61 6e 63 65 2e 0d 0a 20 20 20 20 2f 2f nstance... //
ff10: 2f 20 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 20 20 / </param>..
ff20: 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 internal overrid
ff30: 65 20 76 6f 69 64 20 43 72 65 61 74 65 4d 6f 64 e void CreateMod
ff40: 75 6c 65 28 53 51 4c 69 74 65 4d 6f 64 75 6c 65 ule(SQLiteModule
ff50: 20 6d 6f 64 75 6c 65 2c 20 53 51 4c 69 74 65 43 module, SQLiteC
ff60: 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 20 66 onnectionFlags f
ff70: 6c 61 67 73 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 lags).. {..
ff80: 20 20 20 20 20 20 69 66 20 28 6d 6f 64 75 6c 65 if (module
ff90: 20 3d 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 == null)..
ffa0: 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 77 throw new
ffb0: 20 41 72 67 75 6d 65 6e 74 4e 75 6c 6c 45 78 63 ArgumentNullExc
ffc0: 65 70 74 69 6f 6e 28 22 6d 6f 64 75 6c 65 22 29 eption("module")
ffd0: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 66 20 ;.... if
ffe0: 28 28 66 6c 61 67 73 20 26 20 53 51 4c 69 74 65 ((flags & SQLite
fff0: 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2e ConnectionFlags.
10000 4e 6f 4c 6f 67 4d 6f 64 75 6c 65 29 20 21 3d 20 NoLogModule) !=
10010 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e SQLiteConnection
10020 46 6c 61 67 73 2e 4e 6f 4c 6f 67 4d 6f 64 75 6c Flags.NoLogModul
10030 65 29 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 e).. {..
10040 20 20 20 20 20 20 20 20 20 20 20 6d 6f 64 75 6c modul
10050 65 2e 4c 6f 67 45 72 72 6f 72 73 20 3d 20 28 28 e.LogErrors = ((
10060 66 6c 61 67 73 20 26 20 53 51 4c 69 74 65 43 6f flags & SQLiteCo
10070 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f nnectionFlags.Lo
10080 67 4d 6f 64 75 6c 65 45 72 72 6f 72 29 20 3d 3d gModuleError) ==
10090 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f SQLiteConnectio
100a0 6e 46 6c 61 67 73 2e 4c 6f 67 4d 6f 64 75 6c 65 nFlags.LogModule
100b0 45 72 72 6f 72 29 3b 0d 0a 20 20 20 20 20 20 20 Error);..
100c0 20 20 20 20 20 6d 6f 64 75 6c 65 2e 4c 6f 67 45 module.LogE
100d0 78 63 65 70 74 69 6f 6e 73 20 3d 20 28 28 66 6c xceptions = ((fl
100e0 61 67 73 20 26 20 53 51 4c 69 74 65 43 6f 6e 6e ags & SQLiteConn
100f0 65 63 74 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 4d ectionFlags.LogM
10100 6f 64 75 6c 65 45 78 63 65 70 74 69 6f 6e 29 20 oduleException)
10110 3d 3d 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 == SQLiteConnect
10120 69 6f 6e 46 6c 61 67 73 2e 4c 6f 67 4d 6f 64 75 ionFlags.LogModu
10130 6c 65 45 78 63 65 70 74 69 6f 6e 29 3b 0d 0a 20 leException);..
10140 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 }....
10150 20 20 20 20 69 66 20 28 5f 73 71 6c 20 3d 3d 20 if (_sql ==
10160 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 null)..
10170 20 20 20 74 68 72 6f 77 20 6e 65 77 20 53 51 4c throw new SQL
10180 69 74 65 45 78 63 65 70 74 69 6f 6e 28 22 63 6f iteException("co
10190 6e 6e 65 63 74 69 6f 6e 20 68 61 73 20 61 6e 20 nnection has an
101a0 69 6e 76 61 6c 69 64 20 68 61 6e 64 6c 65 22 29 invalid handle")
101b0 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 53 65 74 ;.... Set
101c0 4c 6f 61 64 45 78 74 65 6e 73 69 6f 6e 28 74 72 LoadExtension(tr
101d0 75 65 29 3b 0d 0a 20 20 20 20 20 20 20 20 4c 6f ue);.. Lo
101e0 61 64 45 78 74 65 6e 73 69 6f 6e 28 55 6e 73 61 adExtension(Unsa
101f0 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
10200 53 51 4c 49 54 45 5f 44 4c 4c 2c 20 22 73 71 6c SQLITE_DLL, "sql
10210 69 74 65 33 5f 76 74 73 68 69 6d 5f 69 6e 69 74 ite3_vtshim_init
10220 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 ");.... i
10230 66 20 28 6d 6f 64 75 6c 65 2e 43 72 65 61 74 65 f (module.Create
10240 44 69 73 70 6f 73 61 62 6c 65 4d 6f 64 75 6c 65 DisposableModule
10250 28 5f 73 71 6c 29 29 0d 0a 20 20 20 20 20 20 20 (_sql))..
10260 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
10270 69 66 20 28 5f 6d 6f 64 75 6c 65 73 20 3d 3d 20 if (_modules ==
10280 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 null)..
10290 20 20 20 20 20 20 20 5f 6d 6f 64 75 6c 65 73 20 _modules
102a0 3d 20 6e 65 77 20 44 69 63 74 69 6f 6e 61 72 79 = new Dictionary
102b0 3c 73 74 72 69 6e 67 2c 20 53 51 4c 69 74 65 4d <string, SQLiteM
102c0 6f 64 75 6c 65 3e 28 29 3b 0d 0a 0d 0a 20 20 20 odule>();....
102d0 20 20 20 20 20 20 20 20 20 5f 6d 6f 64 75 6c 65 _module
102e0 73 2e 41 64 64 28 6d 6f 64 75 6c 65 2e 4e 61 6d s.Add(module.Nam
102f0 65 2c 20 6d 6f 64 75 6c 65 29 3b 0d 0a 0d 0a 20 e, module);....
10300 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 5f if (_
10310 75 73 65 50 6f 6f 6c 29 0d 0a 20 20 20 20 20 20 usePool)..
10320 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
10330 20 20 20 20 20 20 20 20 20 5f 75 73 65 50 6f 6f _usePoo
10340 6c 20 3d 20 66 61 6c 73 65 3b 0d 0a 0d 0a 23 69 l = false;....#i
10350 66 20 21 4e 45 54 5f 43 4f 4d 50 41 43 54 5f 32 f !NET_COMPACT_2
10360 30 20 26 26 20 54 52 41 43 45 5f 43 4f 4e 4e 45 0 && TRACE_CONNE
10370 43 54 49 4f 4e 0d 0a 20 20 20 20 20 20 20 20 20 CTION..
10380 20 20 20 20 20 20 20 54 72 61 63 65 2e 57 72 69 Trace.Wri
10390 74 65 4c 69 6e 65 28 53 74 72 69 6e 67 2e 46 6f teLine(String.Fo
103a0 72 6d 61 74 28 22 43 72 65 61 74 65 4d 6f 64 75 rmat("CreateModu
103b0 6c 65 20 28 50 6f 6f 6c 29 20 44 69 73 61 62 6c le (Pool) Disabl
103c0 65 64 3a 20 7b 30 7d 22 2c 20 5f 73 71 6c 29 29 ed: {0}", _sql))
103d0 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 20 ;..#endif..
103e0 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 }..
103f0 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 65 6c 73 }.. els
10400 65 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 e.. {..
10410 20 20 20 20 20 20 20 20 20 20 74 68 72 6f 77 20 throw
10420 6e 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 74 new SQLiteExcept
10430 69 6f 6e 28 47 65 74 4c 61 73 74 45 72 72 6f 72 ion(GetLastError
10440 28 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d ());.. }.
10450 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 2f 2f . }.... //
10460 2f 20 3c 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 / <summary>..
10470 20 2f 2f 2f 20 43 61 6c 6c 73 20 74 68 65 20 6e /// Calls the n
10480 61 74 69 76 65 20 53 51 4c 69 74 65 20 63 6f 72 ative SQLite cor
10490 65 20 6c 69 62 72 61 72 79 20 69 6e 20 6f 72 64 e library in ord
104a0 65 72 20 74 6f 20 63 6c 65 61 6e 75 70 20 74 68 er to cleanup th
104b0 65 20 72 65 73 6f 75 72 63 65 73 0d 0a 20 20 20 e resources..
104c0 20 2f 2f 2f 20 61 73 73 6f 63 69 61 74 65 64 20 /// associated
104d0 77 69 74 68 20 61 20 6d 6f 64 75 6c 65 20 63 6f with a module co
104e0 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 69 6d 70 ntaining the imp
104f0 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 6f 66 20 61 lementation of a
10500 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 2e 0d virtual table..
10510 0a 20 20 20 20 2f 2f 2f 20 3c 2f 73 75 6d 6d 61 . /// </summa
10520 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 ry>.. /// <pa
10530 72 61 6d 20 6e 61 6d 65 3d 22 6d 6f 64 75 6c 65 ram name="module
10540 22 3e 0d 0a 20 20 20 20 2f 2f 2f 20 54 68 65 20 ">.. /// The
10550 6d 6f 64 75 6c 65 20 6f 62 6a 65 63 74 20 70 72 module object pr
10560 65 76 69 6f 75 73 6c 79 20 70 61 73 73 65 64 20 eviously passed
10570 74 6f 20 74 68 65 20 3c 73 65 65 20 63 72 65 66 to the <see cref
10580 3d 22 43 72 65 61 74 65 4d 6f 64 75 6c 65 22 20 ="CreateModule"
10590 2f 3e 0d 0a 20 20 20 20 2f 2f 2f 20 6d 65 74 68 />.. /// meth
105a0 6f 64 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 70 od... /// </p
105b0 61 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c aram>.. /// <
105c0 70 61 72 61 6d 20 6e 61 6d 65 3d 22 66 6c 61 67 param name="flag
105d0 73 22 3e 0d 0a 20 20 20 20 2f 2f 2f 20 54 68 65 s">.. /// The
105e0 20 66 6c 61 67 73 20 66 6f 72 20 74 68 65 20 61 flags for the a
105f0 73 73 6f 63 69 61 74 65 64 20 3c 73 65 65 20 63 ssociated <see c
10600 72 65 66 3d 22 53 51 4c 69 74 65 43 6f 6e 6e 65 ref="SQLiteConne
10610 63 74 69 6f 6e 22 20 2f 3e 20 6f 62 6a 65 63 74 ction" /> object
10620 20 69 6e 73 74 61 6e 63 65 2e 0d 0a 20 20 20 20 instance...
10630 2f 2f 2f 20 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 /// </param>..
10640 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
10650 69 64 65 20 76 6f 69 64 20 44 69 73 70 6f 73 65 ide void Dispose
10660 4d 6f 64 75 6c 65 28 53 51 4c 69 74 65 4d 6f 64 Module(SQLiteMod
10670 75 6c 65 20 6d 6f 64 75 6c 65 2c 20 53 51 4c 69 ule module, SQLi
10680 74 65 43 6f 6e 6e 65 63 74 69 6f 6e 46 6c 61 67 teConnectionFlag
10690 73 20 66 6c 61 67 73 29 0d 0a 20 20 20 20 7b 0d s flags).. {.
106a0 0a 20 20 20 20 20 20 20 20 69 66 20 28 6d 6f 64 . if (mod
106b0 75 6c 65 20 3d 3d 20 6e 75 6c 6c 29 0d 0a 20 20 ule == null)..
106c0 20 20 20 20 20 20 20 20 20 20 74 68 72 6f 77 20 throw
106d0 6e 65 77 20 41 72 67 75 6d 65 6e 74 4e 75 6c 6c new ArgumentNull
106e0 45 78 63 65 70 74 69 6f 6e 28 22 6d 6f 64 75 6c Exception("modul
106f0 65 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 e");....
10700 6d 6f 64 75 6c 65 2e 44 69 73 70 6f 73 65 28 29 module.Dispose()
10710 3b 0d 0a 20 20 20 20 7d 0d 0a 23 65 6e 64 69 66 ;.. }..#endif
10720 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c .... internal
10730 20 6f 76 65 72 72 69 64 65 20 49 6e 74 50 74 72 override IntPtr
10740 20 41 67 67 72 65 67 61 74 65 43 6f 6e 74 65 78 AggregateContex
10750 74 28 49 6e 74 50 74 72 20 63 6f 6e 74 65 78 74 t(IntPtr context
10760 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 ).. {..
10770 72 65 74 75 72 6e 20 55 6e 73 61 66 65 4e 61 74 return UnsafeNat
10780 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 iveMethods.sqlit
10790 65 33 5f 61 67 67 72 65 67 61 74 65 5f 63 6f 6e e3_aggregate_con
107a0 74 65 78 74 28 63 6f 6e 74 65 78 74 2c 20 31 29 text(context, 1)
107b0 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 23 69 66 20 ;.. }....#if
107c0 49 4e 54 45 52 4f 50 5f 56 49 52 54 55 41 4c 5f INTEROP_VIRTUAL_
107d0 54 41 42 4c 45 0d 0a 20 20 20 20 2f 2f 2f 20 3c TABLE.. /// <
107e0 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f summary>.. //
107f0 2f 20 43 61 6c 6c 73 20 74 68 65 20 6e 61 74 69 / Calls the nati
10800 76 65 20 53 51 4c 69 74 65 20 63 6f 72 65 20 6c ve SQLite core l
10810 69 62 72 61 72 79 20 69 6e 20 6f 72 64 65 72 20 ibrary in order
10820 74 6f 20 64 65 63 6c 61 72 65 20 61 20 76 69 72 to declare a vir
10830 74 75 61 6c 20 74 61 62 6c 65 0d 0a 20 20 20 20 tual table..
10840 2f 2f 2f 20 69 6e 20 72 65 73 70 6f 6e 73 65 20 /// in response
10850 74 6f 20 61 20 63 61 6c 6c 20 69 6e 74 6f 20 74 to a call into t
10860 68 65 20 3c 73 65 65 20 63 72 65 66 3d 22 49 53 he <see cref="IS
10870 51 4c 69 74 65 4e 61 74 69 76 65 4d 6f 64 75 6c QLiteNativeModul
10880 65 2e 78 43 72 65 61 74 65 22 20 2f 3e 0d 0a 20 e.xCreate" />..
10890 20 20 20 2f 2f 2f 20 6f 72 20 3c 73 65 65 20 63 /// or <see c
108a0 72 65 66 3d 22 49 53 51 4c 69 74 65 4e 61 74 69 ref="ISQLiteNati
108b0 76 65 4d 6f 64 75 6c 65 2e 78 43 6f 6e 6e 65 63 veModule.xConnec
108c0 74 22 20 2f 3e 20 76 69 72 74 75 61 6c 20 74 61 t" /> virtual ta
108d0 62 6c 65 20 6d 65 74 68 6f 64 73 2e 0d 0a 20 20 ble methods...
108e0 20 20 2f 2f 2f 20 3c 2f 73 75 6d 6d 61 72 79 3e /// </summary>
108f0 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 72 61 6d .. /// <param
10900 20 6e 61 6d 65 3d 22 6d 6f 64 75 6c 65 22 3e 0d name="module">.
10910 0a 20 20 20 20 2f 2f 2f 20 54 68 65 20 76 69 72 . /// The vir
10920 74 75 61 6c 20 74 61 62 6c 65 20 6d 6f 64 75 6c tual table modul
10930 65 20 74 68 61 74 20 69 73 20 74 6f 20 62 65 20 e that is to be
10940 72 65 73 70 6f 6e 73 69 62 6c 65 20 66 6f 72 20 responsible for
10950 74 68 65 20 76 69 72 74 75 61 6c 20 74 61 62 6c the virtual tabl
10960 65 0d 0a 20 20 20 20 2f 2f 2f 20 62 65 69 6e 67 e.. /// being
10970 20 64 65 63 6c 61 72 65 64 2e 0d 0a 20 20 20 20 declared...
10980 2f 2f 2f 20 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 /// </param>..
10990 20 20 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 6d /// <param nam
109a0 65 3d 22 73 74 72 53 71 6c 22 3e 0d 0a 20 20 20 e="strSql">..
109b0 20 2f 2f 2f 20 54 68 65 20 73 74 72 69 6e 67 20 /// The string
109c0 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 53 containing the S
109d0 51 4c 20 73 74 61 74 65 6d 65 6e 74 20 64 65 73 QL statement des
109e0 63 72 69 62 69 6e 67 20 74 68 65 20 76 69 72 74 cribing the virt
109f0 75 61 6c 20 74 61 62 6c 65 20 74 6f 0d 0a 20 20 ual table to..
10a00 20 20 2f 2f 2f 20 62 65 20 64 65 63 6c 61 72 65 /// be declare
10a10 64 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 70 61 d... /// </pa
10a20 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 ram>.. /// <p
10a30 61 72 61 6d 20 6e 61 6d 65 3d 22 65 72 72 6f 72 aram name="error
10a40 22 3e 0d 0a 20 20 20 20 2f 2f 2f 20 55 70 6f 6e ">.. /// Upon
10a50 20 73 75 63 63 65 73 73 2c 20 74 68 65 20 63 6f success, the co
10a60 6e 74 65 6e 74 73 20 6f 66 20 74 68 69 73 20 70 ntents of this p
10a70 61 72 61 6d 65 74 65 72 20 61 72 65 20 75 6e 64 arameter are und
10a80 65 66 69 6e 65 64 2e 20 20 55 70 6f 6e 20 66 61 efined. Upon fa
10a90 69 6c 75 72 65 2c 0d 0a 20 20 20 20 2f 2f 2f 20 ilure,.. ///
10aa0 69 74 20 73 68 6f 75 6c 64 20 63 6f 6e 74 61 69 it should contai
10ab0 6e 20 61 6e 20 61 70 70 72 6f 70 72 69 61 74 65 n an appropriate
10ac0 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 2e 0d error message..
10ad0 0a 20 20 20 20 2f 2f 2f 20 3c 2f 70 61 72 61 6d . /// </param
10ae0 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 72 65 74 75 >.. /// <retu
10af0 72 6e 73 3e 0d 0a 20 20 20 20 2f 2f 2f 20 41 20 rns>.. /// A
10b00 73 74 61 6e 64 61 72 64 20 53 51 4c 69 74 65 20 standard SQLite
10b10 72 65 74 75 72 6e 20 63 6f 64 65 2e 0d 0a 20 20 return code...
10b20 20 20 2f 2f 2f 20 3c 2f 72 65 74 75 72 6e 73 3e /// </returns>
10b30 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
10b40 76 65 72 72 69 64 65 20 53 51 4c 69 74 65 45 72 verride SQLiteEr
10b50 72 6f 72 43 6f 64 65 20 44 65 63 6c 61 72 65 56 rorCode DeclareV
10b60 69 72 74 75 61 6c 54 61 62 6c 65 28 0d 0a 20 20 irtualTable(..
10b70 20 20 20 20 20 20 53 51 4c 69 74 65 4d 6f 64 75 SQLiteModu
10b80 6c 65 20 6d 6f 64 75 6c 65 2c 0d 0a 20 20 20 20 le module,..
10b90 20 20 20 20 73 74 72 69 6e 67 20 73 74 72 53 71 string strSq
10ba0 6c 2c 0d 0a 20 20 20 20 20 20 20 20 72 65 66 20 l,.. ref
10bb0 73 74 72 69 6e 67 20 65 72 72 6f 72 0d 0a 20 20 string error..
10bc0 20 20 20 20 20 20 29 0d 0a 20 20 20 20 7b 0d 0a ).. {..
10bd0 20 20 20 20 20 20 20 20 69 66 20 28 5f 73 71 6c if (_sql
10be0 20 3d 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 == null)..
10bf0 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 {..
10c00 20 20 65 72 72 6f 72 20 3d 20 22 63 6f 6e 6e 65 error = "conne
10c10 63 74 69 6f 6e 20 68 61 73 20 61 6e 20 69 6e 76 ction has an inv
10c20 61 6c 69 64 20 68 61 6e 64 6c 65 22 3b 0d 0a 20 alid handle";..
10c30 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 retur
10c40 6e 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 n SQLiteErrorCod
10c50 65 2e 45 72 72 6f 72 3b 0d 0a 20 20 20 20 20 20 e.Error;..
10c60 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 49 }.... I
10c70 6e 74 50 74 72 20 70 53 71 6c 20 3d 20 49 6e 74 ntPtr pSql = Int
10c80 50 74 72 2e 5a 65 72 6f 3b 0d 0a 0d 0a 20 20 20 Ptr.Zero;....
10c90 20 20 20 20 20 74 72 79 0d 0a 20 20 20 20 20 20 try..
10ca0 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 {..
10cb0 20 70 53 71 6c 20 3d 20 53 51 4c 69 74 65 53 74 pSql = SQLiteSt
10cc0 72 69 6e 67 2e 55 74 66 38 49 6e 74 50 74 72 46 ring.Utf8IntPtrF
10cd0 72 6f 6d 53 74 72 69 6e 67 28 73 74 72 53 71 6c romString(strSql
10ce0 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 );....
10cf0 20 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 SQLiteErrorCod
10d00 65 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 e n = UnsafeNati
10d10 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 veMethods.sqlite
10d20 33 5f 64 65 63 6c 61 72 65 5f 76 74 61 62 28 0d 3_declare_vtab(.
10d30 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
10d40 20 5f 73 71 6c 2c 20 70 53 71 6c 29 3b 0d 0a 0d _sql, pSql);...
10d50 0a 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 . if
10d60 28 28 6e 20 3d 3d 20 53 51 4c 69 74 65 45 72 72 ((n == SQLiteErr
10d70 6f 72 43 6f 64 65 2e 4f 6b 29 20 26 26 20 28 6d orCode.Ok) && (m
10d80 6f 64 75 6c 65 20 21 3d 20 6e 75 6c 6c 29 29 0d odule != null)).
10d90 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
10da0 20 6d 6f 64 75 6c 65 2e 44 65 63 6c 61 72 65 64 module.Declared
10db0 20 3d 20 74 72 75 65 3b 0d 0a 0d 0a 20 20 20 20 = true;....
10dc0 20 20 20 20 20 20 20 20 69 66 20 28 6e 20 21 3d if (n !=
10dd0 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 SQLiteErrorCode
10de0 2e 4f 6b 29 20 65 72 72 6f 72 20 3d 20 47 65 74 .Ok) error = Get
10df0 4c 61 73 74 45 72 72 6f 72 28 29 3b 0d 0a 0d 0a LastError();....
10e00 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 retu
10e10 72 6e 20 6e 3b 0d 0a 20 20 20 20 20 20 20 20 7d rn n;.. }
10e20 0d 0a 20 20 20 20 20 20 20 20 66 69 6e 61 6c 6c .. finall
10e30 79 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 y.. {..
10e40 20 20 20 20 20 20 20 20 20 20 69 66 20 28 70 53 if (pS
10e50 71 6c 20 21 3d 20 49 6e 74 50 74 72 2e 5a 65 72 ql != IntPtr.Zer
10e60 6f 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 o)..
10e70 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 {..
10e80 20 20 20 53 51 4c 69 74 65 4d 65 6d 6f 72 79 2e SQLiteMemory.
10e90 46 72 65 65 28 70 53 71 6c 29 3b 0d 0a 20 20 20 Free(pSql);..
10ea0 20 20 20 20 20 20 20 20 20 20 20 20 20 70 53 71 pSq
10eb0 6c 20 3d 20 49 6e 74 50 74 72 2e 5a 65 72 6f 3b l = IntPtr.Zero;
10ec0 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d .. }.
10ed0 0a 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 . }..
10ee0 7d 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 }.... /// <su
10ef0 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 mmary>.. ///
10f00 43 61 6c 6c 73 20 74 68 65 20 6e 61 74 69 76 65 Calls the native
10f10 20 53 51 4c 69 74 65 20 63 6f 72 65 20 6c 69 62 SQLite core lib
10f20 72 61 72 79 20 69 6e 20 6f 72 64 65 72 20 74 6f rary in order to
10f30 20 64 65 63 6c 61 72 65 20 61 20 76 69 72 74 75 declare a virtu
10f40 61 6c 20 74 61 62 6c 65 0d 0a 20 20 20 20 2f 2f al table.. //
10f50 2f 20 66 75 6e 63 74 69 6f 6e 20 69 6e 20 72 65 / function in re
10f60 73 70 6f 6e 73 65 20 74 6f 20 61 20 63 61 6c 6c sponse to a call
10f70 20 69 6e 74 6f 20 74 68 65 20 3c 73 65 65 20 63 into the <see c
10f80 72 65 66 3d 22 49 53 51 4c 69 74 65 4e 61 74 69 ref="ISQLiteNati
10f90 76 65 4d 6f 64 75 6c 65 2e 78 43 72 65 61 74 65 veModule.xCreate
10fa0 22 20 2f 3e 0d 0a 20 20 20 20 2f 2f 2f 20 6f 72 " />.. /// or
10fb0 20 3c 73 65 65 20 63 72 65 66 3d 22 49 53 51 4c <see cref="ISQL
10fc0 69 74 65 4e 61 74 69 76 65 4d 6f 64 75 6c 65 2e iteNativeModule.
10fd0 78 43 6f 6e 6e 65 63 74 22 20 2f 3e 20 76 69 72 xConnect" /> vir
10fe0 74 75 61 6c 20 74 61 62 6c 65 20 6d 65 74 68 6f tual table metho
10ff0 64 73 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 73 ds... /// </s
11000 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f ummary>.. ///
11010 20 3c 70 61 72 61 6d 20 6e 61 6d 65 3d 22 6d 6f <param name="mo
11020 64 75 6c 65 22 3e 0d 0a 20 20 20 20 2f 2f 2f 20 dule">.. ///
11030 54 68 65 20 76 69 72 74 75 61 6c 20 74 61 62 6c The virtual tabl
11040 65 20 6d 6f 64 75 6c 65 20 74 68 61 74 20 69 73 e module that is
11050 20 74 6f 20 62 65 20 72 65 73 70 6f 6e 73 69 62 to be responsib
11060 6c 65 20 66 6f 72 20 74 68 65 20 76 69 72 74 75 le for the virtu
11070 61 6c 20 74 61 62 6c 65 0d 0a 20 20 20 20 2f 2f al table.. //
11080 2f 20 66 75 6e 63 74 69 6f 6e 20 62 65 69 6e 67 / function being
11090 20 64 65 63 6c 61 72 65 64 2e 0d 0a 20 20 20 20 declared...
110a0 2f 2f 2f 20 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 /// </param>..
110b0 20 20 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 6d /// <param nam
110c0 65 3d 22 61 72 67 75 6d 65 6e 74 43 6f 75 6e 74 e="argumentCount
110d0 22 3e 0d 0a 20 20 20 20 2f 2f 2f 20 54 68 65 20 ">.. /// The
110e0 6e 75 6d 62 65 72 20 6f 66 20 61 72 67 75 6d 65 number of argume
110f0 6e 74 73 20 74 6f 20 74 68 65 20 66 75 6e 63 74 nts to the funct
11100 69 6f 6e 20 62 65 69 6e 67 20 64 65 63 6c 61 72 ion being declar
11110 65 64 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 70 ed... /// </p
11120 61 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c aram>.. /// <
11130 70 61 72 61 6d 20 6e 61 6d 65 3d 22 6e 61 6d 65 param name="name
11140 22 3e 0d 0a 20 20 20 20 2f 2f 2f 20 54 68 65 20 ">.. /// The
11150 6e 61 6d 65 20 6f 66 20 74 68 65 20 66 75 6e 63 name of the func
11160 74 69 6f 6e 20 62 65 69 6e 67 20 64 65 63 6c 61 tion being decla
11170 72 65 64 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f red... /// </
11180 70 61 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 param>.. ///
11190 3c 70 61 72 61 6d 20 6e 61 6d 65 3d 22 65 72 72 <param name="err
111a0 6f 72 22 3e 0d 0a 20 20 20 20 2f 2f 2f 20 55 70 or">.. /// Up
111b0 6f 6e 20 73 75 63 63 65 73 73 2c 20 74 68 65 20 on success, the
111c0 63 6f 6e 74 65 6e 74 73 20 6f 66 20 74 68 69 73 contents of this
111d0 20 70 61 72 61 6d 65 74 65 72 20 61 72 65 20 75 parameter are u
111e0 6e 64 65 66 69 6e 65 64 2e 20 20 55 70 6f 6e 20 ndefined. Upon
111f0 66 61 69 6c 75 72 65 2c 0d 0a 20 20 20 20 2f 2f failure,.. //
11200 2f 20 69 74 20 73 68 6f 75 6c 64 20 63 6f 6e 74 / it should cont
11210 61 69 6e 20 61 6e 20 61 70 70 72 6f 70 72 69 61 ain an appropria
11220 74 65 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 te error message
11230 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 70 61 72 ... /// </par
11240 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 72 65 am>.. /// <re
11250 74 75 72 6e 73 3e 0d 0a 20 20 20 20 2f 2f 2f 20 turns>.. ///
11260 41 20 73 74 61 6e 64 61 72 64 20 53 51 4c 69 74 A standard SQLit
11270 65 20 72 65 74 75 72 6e 20 63 6f 64 65 2e 0d 0a e return code...
11280 20 20 20 20 2f 2f 2f 20 3c 2f 72 65 74 75 72 6e /// </return
11290 73 3e 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c s>.. internal
112a0 20 6f 76 65 72 72 69 64 65 20 53 51 4c 69 74 65 override SQLite
112b0 45 72 72 6f 72 43 6f 64 65 20 44 65 63 6c 61 72 ErrorCode Declar
112c0 65 56 69 72 74 75 61 6c 46 75 6e 63 74 69 6f 6e eVirtualFunction
112d0 28 0d 0a 20 20 20 20 20 20 20 20 53 51 4c 69 74 (.. SQLit
112e0 65 4d 6f 64 75 6c 65 20 6d 6f 64 75 6c 65 2c 0d eModule module,.
112f0 0a 20 20 20 20 20 20 20 20 69 6e 74 20 61 72 67 . int arg
11300 75 6d 65 6e 74 43 6f 75 6e 74 2c 0d 0a 20 20 20 umentCount,..
11310 20 20 20 20 20 73 74 72 69 6e 67 20 6e 61 6d 65 string name
11320 2c 0d 0a 20 20 20 20 20 20 20 20 72 65 66 20 73 ,.. ref s
11330 74 72 69 6e 67 20 65 72 72 6f 72 0d 0a 20 20 20 tring error..
11340 20 20 20 20 20 29 0d 0a 20 20 20 20 7b 0d 0a 20 ).. {..
11350 20 20 20 20 20 20 20 69 66 20 28 5f 73 71 6c 20 if (_sql
11360 3d 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 == null)..
11370 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 {..
11380 20 65 72 72 6f 72 20 3d 20 22 63 6f 6e 6e 65 63 error = "connec
11390 74 69 6f 6e 20 68 61 73 20 61 6e 20 69 6e 76 61 tion has an inva
113a0 6c 69 64 20 68 61 6e 64 6c 65 22 3b 0d 0a 20 20 lid handle";..
113b0 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e return
113c0 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 SQLiteErrorCode
113d0 2e 45 72 72 6f 72 3b 0d 0a 20 20 20 20 20 20 20 .Error;..
113e0 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 49 6e }.... In
113f0 74 50 74 72 20 70 4e 61 6d 65 20 3d 20 49 6e 74 tPtr pName = Int
11400 50 74 72 2e 5a 65 72 6f 3b 0d 0a 0d 0a 20 20 20 Ptr.Zero;....
11410 20 20 20 20 20 74 72 79 0d 0a 20 20 20 20 20 20 try..
11420 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 {..
11430 20 70 4e 61 6d 65 20 3d 20 53 51 4c 69 74 65 53 pName = SQLiteS
11440 74 72 69 6e 67 2e 55 74 66 38 49 6e 74 50 74 72 tring.Utf8IntPtr
11450 46 72 6f 6d 53 74 72 69 6e 67 28 6e 61 6d 65 29 FromString(name)
11460 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ;....
11470 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 SQLiteErrorCode
11480 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 n = UnsafeNativ
11490 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
114a0 5f 6f 76 65 72 6c 6f 61 64 5f 66 75 6e 63 74 69 _overload_functi
114b0 6f 6e 28 0d 0a 20 20 20 20 20 20 20 20 20 20 20 on(..
114c0 20 20 20 20 20 5f 73 71 6c 2c 20 70 4e 61 6d 65 _sql, pName
114d0 2c 20 61 72 67 75 6d 65 6e 74 43 6f 75 6e 74 29 , argumentCount)
114e0 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ;....
114f0 20 69 66 20 28 6e 20 21 3d 20 53 51 4c 69 74 65 if (n != SQLite
11500 45 72 72 6f 72 43 6f 64 65 2e 4f 6b 29 20 65 72 ErrorCode.Ok) er
11510 72 6f 72 20 3d 20 47 65 74 4c 61 73 74 45 72 72 ror = GetLastErr
11520 6f 72 28 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 or();....
11530 20 20 20 20 20 72 65 74 75 72 6e 20 6e 3b 0d 0a return n;..
11540 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 }..
11550 20 20 20 66 69 6e 61 6c 6c 79 0d 0a 20 20 20 20 finally..
11560 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 {..
11570 20 20 20 69 66 20 28 70 4e 61 6d 65 20 21 3d 20 if (pName !=
11580 49 6e 74 50 74 72 2e 5a 65 72 6f 29 0d 0a 20 20 IntPtr.Zero)..
11590 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 {..
115a0 20 20 20 20 20 20 20 20 20 20 20 20 20 53 51 4c SQL
115b0 69 74 65 4d 65 6d 6f 72 79 2e 46 72 65 65 28 70 iteMemory.Free(p
115c0 4e 61 6d 65 29 3b 0d 0a 20 20 20 20 20 20 20 20 Name);..
115d0 20 20 20 20 20 20 20 20 70 4e 61 6d 65 20 3d 20 pName =
115e0 49 6e 74 50 74 72 2e 5a 65 72 6f 3b 0d 0a 20 20 IntPtr.Zero;..
115f0 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 }..
11600 20 20 20 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a 23 }.. }..#
11610 65 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 2f 2f 2f endif.... ///
11620 20 3c 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 <summary>..
11630 2f 2f 2f 20 45 6e 61 62 6c 65 73 20 6f 72 20 64 /// Enables or d
11640 69 73 61 62 6c 65 64 20 65 78 74 65 6e 73 69 6f isabled extensio
11650 6e 20 6c 6f 61 64 69 6e 67 20 62 79 20 53 51 4c n loading by SQL
11660 69 74 65 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f ite... /// </
11670 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f summary>.. //
11680 2f 20 3c 70 61 72 61 6d 20 6e 61 6d 65 3d 22 62 / <param name="b
11690 4f 6e 4f 66 66 22 3e 0d 0a 20 20 20 20 2f 2f 2f OnOff">.. ///
116a0 20 54 72 75 65 20 74 6f 20 65 6e 61 62 6c 65 20 True to enable
116b0 6c 6f 61 64 69 6e 67 20 6f 66 20 65 78 74 65 6e loading of exten
116c0 73 69 6f 6e 73 2c 20 66 61 6c 73 65 20 74 6f 20 sions, false to
116d0 64 69 73 61 62 6c 65 2e 0d 0a 20 20 20 20 2f 2f disable... //
116e0 2f 20 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 20 20 / </param>..
116f0 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 internal overrid
11700 65 20 76 6f 69 64 20 53 65 74 4c 6f 61 64 45 78 e void SetLoadEx
11710 74 65 6e 73 69 6f 6e 28 62 6f 6f 6c 20 62 4f 6e tension(bool bOn
11720 4f 66 66 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 Off).. {..
11730 20 20 20 20 20 53 51 4c 69 74 65 45 72 72 6f 72 SQLiteError
11740 43 6f 64 65 20 6e 20 3d 20 55 6e 73 61 66 65 4e Code n = UnsafeN
11750 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
11760 69 74 65 33 5f 65 6e 61 62 6c 65 5f 6c 6f 61 64 ite3_enable_load
11770 5f 65 78 74 65 6e 73 69 6f 6e 28 0d 0a 20 20 20 _extension(..
11780 20 20 20 20 20 20 20 20 20 5f 73 71 6c 2c 20 28 _sql, (
11790 62 4f 6e 4f 66 66 20 3f 20 2d 31 20 3a 20 30 29 bOnOff ? -1 : 0)
117a0 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 66 );.... if
117b0 20 28 6e 20 21 3d 20 53 51 4c 69 74 65 45 72 72 (n != SQLiteErr
117c0 6f 72 43 6f 64 65 2e 4f 6b 29 20 74 68 72 6f 77 orCode.Ok) throw
117d0 20 6e 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 new SQLiteExcep
117e0 74 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 tion(n, GetLastE
117f0 72 72 6f 72 28 29 29 3b 0d 0a 20 20 20 20 7d 0d rror());.. }.
11800 0a 0d 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 6d 6d ... /// <summ
11810 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 4c 6f ary>.. /// Lo
11820 61 64 73 20 61 20 53 51 4c 69 74 65 20 65 78 74 ads a SQLite ext
11830 65 6e 73 69 6f 6e 20 6c 69 62 72 61 72 79 20 66 ension library f
11840 72 6f 6d 20 74 68 65 20 6e 61 6d 65 64 20 66 69 rom the named fi
11850 6c 65 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 73 le... /// </s
11860 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f ummary>.. ///
11870 20 3c 70 61 72 61 6d 20 6e 61 6d 65 3d 22 66 69 <param name="fi
11880 6c 65 4e 61 6d 65 22 3e 0d 0a 20 20 20 20 2f 2f leName">.. //
11890 2f 20 54 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 / The name of th
118a0 65 20 64 79 6e 61 6d 69 63 20 6c 69 6e 6b 20 6c e dynamic link l
118b0 69 62 72 61 72 79 20 66 69 6c 65 20 63 6f 6e 74 ibrary file cont
118c0 61 69 6e 69 6e 67 20 74 68 65 20 65 78 74 65 6e aining the exten
118d0 73 69 6f 6e 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c sion... /// <
118e0 2f 70 61 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f /param>.. ///
118f0 20 3c 70 61 72 61 6d 20 6e 61 6d 65 3d 22 70 72 <param name="pr
11900 6f 63 4e 61 6d 65 22 3e 0d 0a 20 20 20 20 2f 2f ocName">.. //
11910 2f 20 54 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 / The name of th
11920 65 20 65 78 70 6f 72 74 65 64 20 66 75 6e 63 74 e exported funct
11930 69 6f 6e 20 75 73 65 64 20 74 6f 20 69 6e 69 74 ion used to init
11940 69 61 6c 69 7a 65 20 74 68 65 20 65 78 74 65 6e ialize the exten
11950 73 69 6f 6e 2e 0d 0a 20 20 20 20 2f 2f 2f 20 49 sion... /// I
11960 66 20 6e 75 6c 6c 2c 20 74 68 65 20 64 65 66 61 f null, the defa
11970 75 6c 74 20 22 73 71 6c 69 74 65 33 5f 65 78 74 ult "sqlite3_ext
11980 65 6e 73 69 6f 6e 5f 69 6e 69 74 22 20 77 69 6c ension_init" wil
11990 6c 20 62 65 20 75 73 65 64 2e 0d 0a 20 20 20 20 l be used...
119a0 2f 2f 2f 20 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 /// </param>..
119b0 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
119c0 69 64 65 20 76 6f 69 64 20 4c 6f 61 64 45 78 74 ide void LoadExt
119d0 65 6e 73 69 6f 6e 28 73 74 72 69 6e 67 20 66 69 ension(string fi
119e0 6c 65 4e 61 6d 65 2c 20 73 74 72 69 6e 67 20 70 leName, string p
119f0 72 6f 63 4e 61 6d 65 29 0d 0a 20 20 20 20 7b 0d rocName).. {.
11a00 0a 20 20 20 20 20 20 20 20 69 66 20 28 66 69 6c . if (fil
11a10 65 4e 61 6d 65 20 3d 3d 20 6e 75 6c 6c 29 0d 0a eName == null)..
11a20 20 20 20 20 20 20 20 20 20 20 20 20 74 68 72 6f thro
11a30 77 20 6e 65 77 20 41 72 67 75 6d 65 6e 74 4e 75 w new ArgumentNu
11a40 6c 6c 45 78 63 65 70 74 69 6f 6e 28 22 66 69 6c llException("fil
11a50 65 4e 61 6d 65 22 29 3b 0d 0a 0d 0a 20 20 20 20 eName");....
11a60 20 20 20 20 49 6e 74 50 74 72 20 70 45 72 72 6f IntPtr pErro
11a70 72 20 3d 20 49 6e 74 50 74 72 2e 5a 65 72 6f 3b r = IntPtr.Zero;
11a80 0d 0a 0d 0a 20 20 20 20 20 20 20 20 74 72 79 0d .... try.
11a90 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 . {..
11aa0 20 20 20 20 20 20 20 20 62 79 74 65 5b 5d 20 75 byte[] u
11ab0 74 66 38 46 69 6c 65 4e 61 6d 65 20 3d 20 55 54 tf8FileName = UT
11ac0 46 38 45 6e 63 6f 64 69 6e 67 2e 55 54 46 38 2e F8Encoding.UTF8.
11ad0 47 65 74 42 79 74 65 73 28 66 69 6c 65 4e 61 6d GetBytes(fileNam
11ae0 65 20 2b 20 27 5c 30 27 29 3b 0d 0a 20 20 20 20 e + '\0');..
11af0 20 20 20 20 20 20 20 20 62 79 74 65 5b 5d 20 75 byte[] u
11b00 74 66 38 50 72 6f 63 4e 61 6d 65 20 3d 20 6e 75 tf8ProcName = nu
11b10 6c 6c 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 ll;....
11b20 20 20 20 69 66 20 28 70 72 6f 63 4e 61 6d 65 20 if (procName
11b30 21 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 != null)..
11b40 20 20 20 20 20 20 20 20 20 20 75 74 66 38 50 72 utf8Pr
11b50 6f 63 4e 61 6d 65 20 3d 20 55 54 46 38 45 6e 63 ocName = UTF8Enc
11b60 6f 64 69 6e 67 2e 55 54 46 38 2e 47 65 74 42 79 oding.UTF8.GetBy
11b70 74 65 73 28 70 72 6f 63 4e 61 6d 65 20 2b 20 27 tes(procName + '
11b80 5c 30 27 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 \0');....
11b90 20 20 20 20 20 53 51 4c 69 74 65 45 72 72 6f 72 SQLiteError
11ba0 43 6f 64 65 20 6e 20 3d 20 55 6e 73 61 66 65 4e Code n = UnsafeN
11bb0 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
11bc0 69 74 65 33 5f 6c 6f 61 64 5f 65 78 74 65 6e 73 ite3_load_extens
11bd0 69 6f 6e 28 0d 0a 20 20 20 20 20 20 20 20 20 20 ion(..
11be0 20 20 20 20 20 20 5f 73 71 6c 2c 20 75 74 66 38 _sql, utf8
11bf0 46 69 6c 65 4e 61 6d 65 2c 20 75 74 66 38 50 72 FileName, utf8Pr
11c00 6f 63 4e 61 6d 65 2c 20 72 65 66 20 70 45 72 72 ocName, ref pErr
11c10 6f 72 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 or);....
11c20 20 20 20 20 69 66 20 28 6e 20 21 3d 20 53 51 4c if (n != SQL
11c30 69 74 65 45 72 72 6f 72 43 6f 64 65 2e 4f 6b 29 iteErrorCode.Ok)
11c40 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
11c50 20 20 74 68 72 6f 77 20 6e 65 77 20 53 51 4c 69 throw new SQLi
11c60 74 65 45 78 63 65 70 74 69 6f 6e 28 6e 2c 20 55 teException(n, U
11c70 54 46 38 54 6f 53 74 72 69 6e 67 28 70 45 72 72 TF8ToString(pErr
11c80 6f 72 2c 20 2d 31 29 29 3b 0d 0a 20 20 20 20 20 or, -1));..
11c90 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 66 69 }.. fi
11ca0 6e 61 6c 6c 79 0d 0a 20 20 20 20 20 20 20 20 7b nally.. {
11cb0 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 69 66 .. if
11cc0 20 28 70 45 72 72 6f 72 20 21 3d 20 49 6e 74 50 (pError != IntP
11cd0 74 72 2e 5a 65 72 6f 29 0d 0a 20 20 20 20 20 20 tr.Zero)..
11ce0 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
11cf0 20 20 20 20 20 20 20 20 20 55 6e 73 61 66 65 4e UnsafeN
11d00 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
11d10 69 74 65 33 5f 66 72 65 65 28 70 45 72 72 6f 72 ite3_free(pError
11d20 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 );..
11d30 20 20 20 20 70 45 72 72 6f 72 20 3d 20 49 6e 74 pError = Int
11d40 50 74 72 2e 5a 65 72 6f 3b 0d 0a 20 20 20 20 20 Ptr.Zero;..
11d50 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 }..
11d60 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 }.. }....
11d70 20 20 2f 2f 2f 20 45 6e 61 62 6c 65 73 20 6f 72 /// Enables or
11d80 20 64 69 73 61 62 6c 65 64 20 65 78 74 65 6e 64 disabled extend
11d90 65 64 20 72 65 73 75 6c 74 20 63 6f 64 65 73 20 ed result codes
11da0 72 65 74 75 72 6e 65 64 20 62 79 20 53 51 4c 69 returned by SQLi
11db0 74 65 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c te.. internal
11dc0 20 6f 76 65 72 72 69 64 65 20 76 6f 69 64 20 53 override void S
11dd0 65 74 45 78 74 65 6e 64 65 64 52 65 73 75 6c 74 etExtendedResult
11de0 43 6f 64 65 73 28 62 6f 6f 6c 20 62 4f 6e 4f 66 Codes(bool bOnOf
11df0 66 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 f).. {..
11e00 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 SQLiteErrorCode
11e10 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 n = UnsafeNativ
11e20 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
11e30 5f 65 78 74 65 6e 64 65 64 5f 72 65 73 75 6c 74 _extended_result
11e40 5f 63 6f 64 65 73 28 0d 0a 20 20 20 20 20 20 20 _codes(..
11e50 20 20 20 5f 73 71 6c 2c 20 28 62 4f 6e 4f 66 66 _sql, (bOnOff
11e60 20 3f 20 2d 31 20 3a 20 30 29 29 3b 0d 0a 0d 0a ? -1 : 0));....
11e70 20 20 20 20 20 20 69 66 20 28 6e 20 21 3d 20 53 if (n != S
11e80 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 2e 4f QLiteErrorCode.O
11e90 6b 29 20 74 68 72 6f 77 20 6e 65 77 20 53 51 4c k) throw new SQL
11ea0 69 74 65 45 78 63 65 70 74 69 6f 6e 28 6e 2c 20 iteException(n,
11eb0 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 29 3b GetLastError());
11ec0 0d 0a 20 20 20 20 7d 0d 0a 20 20 20 20 2f 2f 2f .. }.. ///
11ed0 20 47 65 74 73 20 74 68 65 20 6c 61 73 74 20 53 Gets the last S
11ee0 51 4c 69 74 65 20 65 72 72 6f 72 20 63 6f 64 65 QLite error code
11ef0 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
11f00 76 65 72 72 69 64 65 20 53 51 4c 69 74 65 45 72 verride SQLiteEr
11f10 72 6f 72 43 6f 64 65 20 52 65 73 75 6c 74 43 6f rorCode ResultCo
11f20 64 65 28 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 de().. {..
11f30 20 20 20 72 65 74 75 72 6e 20 55 6e 73 61 66 65 return Unsafe
11f40 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 NativeMethods.sq
11f50 6c 69 74 65 33 5f 65 72 72 63 6f 64 65 28 5f 73 lite3_errcode(_s
11f60 71 6c 29 3b 0d 0a 20 20 20 20 7d 0d 0a 20 20 20 ql);.. }..
11f70 20 2f 2f 2f 20 47 65 74 73 20 74 68 65 20 6c 61 /// Gets the la
11f80 73 74 20 53 51 4c 69 74 65 20 65 78 74 65 6e 64 st SQLite extend
11f90 65 64 20 65 72 72 6f 72 20 63 6f 64 65 0d 0a 20 ed error code..
11fa0 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 internal over
11fb0 72 69 64 65 20 53 51 4c 69 74 65 45 72 72 6f 72 ride SQLiteError
11fc0 43 6f 64 65 20 45 78 74 65 6e 64 65 64 52 65 73 Code ExtendedRes
11fd0 75 6c 74 43 6f 64 65 28 29 0d 0a 20 20 20 20 7b ultCode().. {
11fe0 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 55 .. return U
11ff0 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f nsafeNativeMetho
12000 64 73 2e 73 71 6c 69 74 65 33 5f 65 78 74 65 6e ds.sqlite3_exten
12010 64 65 64 5f 65 72 72 63 6f 64 65 28 5f 73 71 6c ded_errcode(_sql
12020 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 );.. }....
12030 20 2f 2f 2f 20 41 64 64 20 61 20 6c 6f 67 20 6d /// Add a log m
12040 65 73 73 61 67 65 20 76 69 61 20 74 68 65 20 53 essage via the S
12050 51 4c 69 74 65 20 73 71 6c 69 74 65 33 5f 6c 6f QLite sqlite3_lo
12060 67 20 69 6e 74 65 72 66 61 63 65 2e 0d 0a 20 20 g interface...
12070 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
12080 69 64 65 20 76 6f 69 64 20 4c 6f 67 4d 65 73 73 ide void LogMess
12090 61 67 65 28 53 51 4c 69 74 65 45 72 72 6f 72 43 age(SQLiteErrorC
120a0 6f 64 65 20 69 45 72 72 43 6f 64 65 2c 20 73 74 ode iErrCode, st
120b0 72 69 6e 67 20 7a 4d 65 73 73 61 67 65 29 0d 0a ring zMessage)..
120c0 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 53 74 61 {.. Sta
120d0 74 69 63 4c 6f 67 4d 65 73 73 61 67 65 28 69 45 ticLogMessage(iE
120e0 72 72 43 6f 64 65 2c 20 7a 4d 65 73 73 61 67 65 rrCode, zMessage
120f0 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 );.. }....
12100 20 2f 2f 2f 20 41 64 64 20 61 20 6c 6f 67 20 6d /// Add a log m
12110 65 73 73 61 67 65 20 76 69 61 20 74 68 65 20 53 essage via the S
12120 51 4c 69 74 65 20 73 71 6c 69 74 65 33 5f 6c 6f QLite sqlite3_lo
12130 67 20 69 6e 74 65 72 66 61 63 65 2e 0d 0a 20 20 g interface...
12140 20 20 69 6e 74 65 72 6e 61 6c 20 73 74 61 74 69 internal stati
12150 63 20 76 6f 69 64 20 53 74 61 74 69 63 4c 6f 67 c void StaticLog
12160 4d 65 73 73 61 67 65 28 53 51 4c 69 74 65 45 72 Message(SQLiteEr
12170 72 6f 72 43 6f 64 65 20 69 45 72 72 43 6f 64 65 rorCode iErrCode
12180 2c 20 73 74 72 69 6e 67 20 7a 4d 65 73 73 61 67 , string zMessag
12190 65 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 e).. {..
121a0 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 UnsafeNativeMet
121b0 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 6c 6f 67 hods.sqlite3_log
121c0 28 69 45 72 72 43 6f 64 65 2c 20 54 6f 55 54 46 (iErrCode, ToUTF
121d0 38 28 7a 4d 65 73 73 61 67 65 29 29 3b 0d 0a 20 8(zMessage));..
121e0 20 20 20 7d 0d 0a 0d 0a 23 69 66 20 49 4e 54 45 }....#if INTE
121f0 52 4f 50 5f 43 4f 44 45 43 0d 0a 20 20 20 20 69 ROP_CODEC.. i
12200 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 nternal override
12210 20 76 6f 69 64 20 53 65 74 50 61 73 73 77 6f 72 void SetPasswor
12220 64 28 62 79 74 65 5b 5d 20 70 61 73 73 77 6f 72 d(byte[] passwor
12230 64 42 79 74 65 73 29 0d 0a 20 20 20 20 7b 0d 0a dBytes).. {..
12240 20 20 20 20 20 20 53 51 4c 69 74 65 45 72 72 6f SQLiteErro
12250 72 43 6f 64 65 20 6e 20 3d 20 55 6e 73 61 66 65 rCode n = Unsafe
12260 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 NativeMethods.sq
12270 6c 69 74 65 33 5f 6b 65 79 28 5f 73 71 6c 2c 20 lite3_key(_sql,
12280 70 61 73 73 77 6f 72 64 42 79 74 65 73 2c 20 70 passwordBytes, p
12290 61 73 73 77 6f 72 64 42 79 74 65 73 2e 4c 65 6e asswordBytes.Len
122a0 67 74 68 29 3b 0d 0a 20 20 20 20 20 20 69 66 20 gth);.. if
122b0 28 6e 20 21 3d 20 53 51 4c 69 74 65 45 72 72 6f (n != SQLiteErro
122c0 72 43 6f 64 65 2e 4f 6b 29 20 74 68 72 6f 77 20 rCode.Ok) throw
122d0 6e 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 74 new SQLiteExcept
122e0 69 6f 6e 28 6e 2c 20 47 65 74 4c 61 73 74 45 72 ion(n, GetLastEr
122f0 72 6f 72 28 29 29 3b 0d 0a 20 20 20 20 7d 0d 0a ror());.. }..
12300 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
12310 76 65 72 72 69 64 65 20 76 6f 69 64 20 43 68 61 verride void Cha
12320 6e 67 65 50 61 73 73 77 6f 72 64 28 62 79 74 65 ngePassword(byte
12330 5b 5d 20 6e 65 77 50 61 73 73 77 6f 72 64 42 79 [] newPasswordBy
12340 74 65 73 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 tes).. {..
12350 20 20 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f SQLiteErrorCo
12360 64 65 20 6e 20 3d 20 55 6e 73 61 66 65 4e 61 74 de n = UnsafeNat
12370 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 iveMethods.sqlit
12380 65 33 5f 72 65 6b 65 79 28 5f 73 71 6c 2c 20 6e e3_rekey(_sql, n
12390 65 77 50 61 73 73 77 6f 72 64 42 79 74 65 73 2c ewPasswordBytes,
123a0 20 28 6e 65 77 50 61 73 73 77 6f 72 64 42 79 74 (newPasswordByt
123b0 65 73 20 3d 3d 20 6e 75 6c 6c 29 20 3f 20 30 20 es == null) ? 0
123c0 3a 20 6e 65 77 50 61 73 73 77 6f 72 64 42 79 74 : newPasswordByt
123d0 65 73 2e 4c 65 6e 67 74 68 29 3b 0d 0a 20 20 20 es.Length);..
123e0 20 20 20 69 66 20 28 6e 20 21 3d 20 53 51 4c 69 if (n != SQLi
123f0 74 65 45 72 72 6f 72 43 6f 64 65 2e 4f 6b 29 20 teErrorCode.Ok)
12400 74 68 72 6f 77 20 6e 65 77 20 53 51 4c 69 74 65 throw new SQLite
12410 45 78 63 65 70 74 69 6f 6e 28 6e 2c 20 47 65 74 Exception(n, Get
12420 4c 61 73 74 45 72 72 6f 72 28 29 29 3b 0d 0a 20 LastError());..
12430 20 20 20 7d 0d 0a 23 65 6e 64 69 66 0d 0a 0d 0a }..#endif....
12440 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 internal ove
12450 72 72 69 64 65 20 76 6f 69 64 20 53 65 74 41 75 rride void SetAu
12460 74 68 6f 72 69 7a 65 72 48 6f 6f 6b 28 53 51 4c thorizerHook(SQL
12470 69 74 65 41 75 74 68 6f 72 69 7a 65 72 43 61 6c iteAuthorizerCal
12480 6c 62 61 63 6b 20 66 75 6e 63 29 0d 0a 20 20 20 lback func)..
12490 20 7b 0d 0a 20 20 20 20 20 20 55 6e 73 61 66 65 {.. Unsafe
124a0 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 NativeMethods.sq
124b0 6c 69 74 65 33 5f 73 65 74 5f 61 75 74 68 6f 72 lite3_set_author
124c0 69 7a 65 72 28 5f 73 71 6c 2c 20 66 75 6e 63 2c izer(_sql, func,
124d0 20 49 6e 74 50 74 72 2e 5a 65 72 6f 29 3b 0d 0a IntPtr.Zero);..
124e0 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 }.... int
124f0 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 76 ernal override v
12500 6f 69 64 20 53 65 74 55 70 64 61 74 65 48 6f 6f oid SetUpdateHoo
12510 6b 28 53 51 4c 69 74 65 55 70 64 61 74 65 43 61 k(SQLiteUpdateCa
12520 6c 6c 62 61 63 6b 20 66 75 6e 63 29 0d 0a 20 20 llback func)..
12530 20 20 7b 0d 0a 20 20 20 20 20 20 55 6e 73 61 66 {.. Unsaf
12540 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
12550 71 6c 69 74 65 33 5f 75 70 64 61 74 65 5f 68 6f qlite3_update_ho
12560 6f 6b 28 5f 73 71 6c 2c 20 66 75 6e 63 2c 20 49 ok(_sql, func, I
12570 6e 74 50 74 72 2e 5a 65 72 6f 29 3b 0d 0a 20 20 ntPtr.Zero);..
12580 20 20 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 }.... inter
12590 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 76 6f 69 nal override voi
125a0 64 20 53 65 74 43 6f 6d 6d 69 74 48 6f 6f 6b 28 d SetCommitHook(
125b0 53 51 4c 69 74 65 43 6f 6d 6d 69 74 43 61 6c 6c SQLiteCommitCall
125c0 62 61 63 6b 20 66 75 6e 63 29 0d 0a 20 20 20 20 back func)..
125d0 7b 0d 0a 20 20 20 20 20 20 55 6e 73 61 66 65 4e {.. UnsafeN
125e0 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
125f0 69 74 65 33 5f 63 6f 6d 6d 69 74 5f 68 6f 6f 6b ite3_commit_hook
12600 28 5f 73 71 6c 2c 20 66 75 6e 63 2c 20 49 6e 74 (_sql, func, Int
12610 50 74 72 2e 5a 65 72 6f 29 3b 0d 0a 20 20 20 20 Ptr.Zero);..
12620 7d 0d 0a 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 }.... interna
12630 6c 20 6f 76 65 72 72 69 64 65 20 76 6f 69 64 20 l override void
12640 53 65 74 54 72 61 63 65 43 61 6c 6c 62 61 63 6b SetTraceCallback
12650 28 53 51 4c 69 74 65 54 72 61 63 65 43 61 6c 6c (SQLiteTraceCall
12660 62 61 63 6b 20 66 75 6e 63 29 0d 0a 20 20 20 20 back func)..
12670 7b 0d 0a 20 20 20 20 20 20 55 6e 73 61 66 65 4e {.. UnsafeN
12680 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c ativeMethods.sql
12690 69 74 65 33 5f 74 72 61 63 65 28 5f 73 71 6c 2c ite3_trace(_sql,
126a0 20 66 75 6e 63 2c 20 49 6e 74 50 74 72 2e 5a 65 func, IntPtr.Ze
126b0 72 6f 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 ro);.. }....
126c0 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 internal over
126d0 72 69 64 65 20 76 6f 69 64 20 53 65 74 52 6f 6c ride void SetRol
126e0 6c 62 61 63 6b 48 6f 6f 6b 28 53 51 4c 69 74 65 lbackHook(SQLite
126f0 52 6f 6c 6c 62 61 63 6b 43 61 6c 6c 62 61 63 6b RollbackCallback
12700 20 66 75 6e 63 29 0d 0a 20 20 20 20 7b 0d 0a 20 func).. {..
12710 20 20 20 20 20 55 6e 73 61 66 65 4e 61 74 69 76 UnsafeNativ
12720 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
12730 5f 72 6f 6c 6c 62 61 63 6b 5f 68 6f 6f 6b 28 5f _rollback_hook(_
12740 73 71 6c 2c 20 66 75 6e 63 2c 20 49 6e 74 50 74 sql, func, IntPt
12750 72 2e 5a 65 72 6f 29 3b 0d 0a 20 20 20 20 7d 0d r.Zero);.. }.
12760 0a 0d 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 6d 6d ... /// <summ
12770 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 41 6c ary>.. /// Al
12780 6c 6f 77 73 20 74 68 65 20 73 65 74 74 69 6e 67 lows the setting
12790 20 6f 66 20 61 20 6c 6f 67 67 69 6e 67 20 63 61 of a logging ca
127a0 6c 6c 62 61 63 6b 20 69 6e 76 6f 6b 65 64 20 62 llback invoked b
127b0 79 20 53 51 4c 69 74 65 20 77 68 65 6e 20 61 0d y SQLite when a.
127c0 0a 20 20 20 20 2f 2f 2f 20 6c 6f 67 20 65 76 65 . /// log eve
127d0 6e 74 20 6f 63 63 75 72 73 2e 20 20 4f 6e 6c 79 nt occurs. Only
127e0 20 6f 6e 65 20 63 61 6c 6c 62 61 63 6b 20 6d 61 one callback ma
127f0 79 20 62 65 20 73 65 74 2e 20 20 49 66 20 4e 55 y be set. If NU
12800 4c 4c 20 69 73 20 70 61 73 73 65 64 2c 0d 0a 20 LL is passed,..
12810 20 20 20 2f 2f 2f 20 74 68 65 20 6c 6f 67 67 69 /// the loggi
12820 6e 67 20 63 61 6c 6c 62 61 63 6b 20 69 73 20 75 ng callback is u
12830 6e 72 65 67 69 73 74 65 72 65 64 2e 0d 0a 20 20 nregistered...
12840 20 20 2f 2f 2f 20 3c 2f 73 75 6d 6d 61 72 79 3e /// </summary>
12850 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 72 61 6d .. /// <param
12860 20 6e 61 6d 65 3d 22 66 75 6e 63 22 3e 54 68 65 name="func">The
12870 20 63 61 6c 6c 62 61 63 6b 20 66 75 6e 63 74 69 callback functi
12880 6f 6e 20 74 6f 20 69 6e 76 6f 6b 65 2e 3c 2f 70 on to invoke.</p
12890 61 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c aram>.. /// <
128a0 72 65 74 75 72 6e 73 3e 52 65 74 75 72 6e 73 20 returns>Returns
128b0 61 20 72 65 73 75 6c 74 20 63 6f 64 65 3c 2f 72 a result code</r
128c0 65 74 75 72 6e 73 3e 0d 0a 20 20 20 20 69 6e 74 eturns>.. int
128d0 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 53 ernal override S
128e0 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 20 53 QLiteErrorCode S
128f0 65 74 4c 6f 67 43 61 6c 6c 62 61 63 6b 28 53 51 etLogCallback(SQ
12900 4c 69 74 65 4c 6f 67 43 61 6c 6c 62 61 63 6b 20 LiteLogCallback
12910 66 75 6e 63 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 func).. {..
12920 20 20 20 20 20 20 53 51 4c 69 74 65 45 72 72 6f SQLiteErro
12930 72 43 6f 64 65 20 72 63 20 3d 20 55 6e 73 61 66 rCode rc = Unsaf
12940 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 eNativeMethods.s
12950 71 6c 69 74 65 33 5f 63 6f 6e 66 69 67 5f 6c 6f qlite3_config_lo
12960 67 28 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 g(..
12970 53 51 4c 69 74 65 43 6f 6e 66 69 67 4f 70 73 45 SQLiteConfigOpsE
12980 6e 75 6d 2e 53 51 4c 49 54 45 5f 43 4f 4e 46 49 num.SQLITE_CONFI
12990 47 5f 4c 4f 47 2c 20 66 75 6e 63 2c 20 49 6e 74 G_LOG, func, Int
129a0 50 74 72 2e 5a 65 72 6f 29 3b 0d 0a 0d 0a 20 20 Ptr.Zero);....
129b0 20 20 20 20 20 20 72 65 74 75 72 6e 20 72 63 3b return rc;
129c0 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 2f .. }.... /
129d0 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
129e0 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
129f0 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
12a00 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
12a10 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
12a20 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0d 0a //////////////..
12a30 0d 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 .. /// <summa
12a40 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 43 72 65 ry>.. /// Cre
12a50 61 74 65 73 20 61 20 6e 65 77 20 53 51 4c 69 74 ates a new SQLit
12a60 65 20 62 61 63 6b 75 70 20 6f 62 6a 65 63 74 20 e backup object
12a70 62 61 73 65 64 20 6f 6e 20 74 68 65 20 70 72 6f based on the pro
12a80 76 69 64 65 64 20 64 65 73 74 69 6e 61 74 69 6f vided destinatio
12a90 6e 0d 0a 20 20 20 20 2f 2f 2f 20 64 61 74 61 62 n.. /// datab
12aa0 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e 20 ase connection.
12ab0 20 54 68 65 20 73 6f 75 72 63 65 20 64 61 74 61 The source data
12ac0 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 base connection
12ad0 69 73 20 74 68 65 20 6f 6e 65 0d 0a 20 20 20 20 is the one..
12ae0 2f 2f 2f 20 61 73 73 6f 63 69 61 74 65 64 20 77 /// associated w
12af0 69 74 68 20 74 68 69 73 20 6f 62 6a 65 63 74 2e ith this object.
12b00 20 20 54 68 65 20 73 6f 75 72 63 65 20 61 6e 64 The source and
12b10 20 64 65 73 74 69 6e 61 74 69 6f 6e 20 64 61 74 destination dat
12b20 61 62 61 73 65 0d 0a 20 20 20 20 2f 2f 2f 20 63 abase.. /// c
12b30 6f 6e 6e 65 63 74 69 6f 6e 73 20 63 61 6e 6e 6f onnections canno
12b40 74 20 62 65 20 74 68 65 20 73 61 6d 65 2e 0d 0a t be the same...
12b50 20 20 20 20 2f 2f 2f 20 3c 2f 73 75 6d 6d 61 72 /// </summar
12b60 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 72 y>.. /// <par
12b70 61 6d 20 6e 61 6d 65 3d 22 64 65 73 74 43 6e 6e am name="destCnn
12b80 22 3e 54 68 65 20 64 65 73 74 69 6e 61 74 69 6f ">The destinatio
12b90 6e 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 n database conne
12ba0 63 74 69 6f 6e 2e 3c 2f 70 61 72 61 6d 3e 0d 0a ction.</param>..
12bb0 20 20 20 20 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e /// <param n
12bc0 61 6d 65 3d 22 64 65 73 74 4e 61 6d 65 22 3e 54 ame="destName">T
12bd0 68 65 20 64 65 73 74 69 6e 61 74 69 6f 6e 20 64 he destination d
12be0 61 74 61 62 61 73 65 20 6e 61 6d 65 2e 3c 2f 70 atabase name.</p
12bf0 61 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c aram>.. /// <
12c00 70 61 72 61 6d 20 6e 61 6d 65 3d 22 73 6f 75 72 param name="sour
12c10 63 65 4e 61 6d 65 22 3e 54 68 65 20 73 6f 75 72 ceName">The sour
12c20 63 65 20 64 61 74 61 62 61 73 65 20 6e 61 6d 65 ce database name
12c30 2e 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 20 20 2f .</param>.. /
12c40 2f 2f 20 3c 72 65 74 75 72 6e 73 3e 54 68 65 20 // <returns>The
12c50 6e 65 77 6c 79 20 63 72 65 61 74 65 64 20 62 61 newly created ba
12c60 63 6b 75 70 20 6f 62 6a 65 63 74 2e 3c 2f 72 65 ckup object.</re
12c70 74 75 72 6e 73 3e 0d 0a 20 20 20 20 69 6e 74 65 turns>.. inte
12c80 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 53 51 rnal override SQ
12c90 4c 69 74 65 42 61 63 6b 75 70 20 49 6e 69 74 69 LiteBackup Initi
12ca0 61 6c 69 7a 65 42 61 63 6b 75 70 28 0d 0a 20 20 alizeBackup(..
12cb0 20 20 20 20 20 20 53 51 4c 69 74 65 43 6f 6e 6e SQLiteConn
12cc0 65 63 74 69 6f 6e 20 64 65 73 74 43 6e 6e 2c 0d ection destCnn,.
12cd0 0a 20 20 20 20 20 20 20 20 73 74 72 69 6e 67 20 . string
12ce0 64 65 73 74 4e 61 6d 65 2c 0d 0a 20 20 20 20 20 destName,..
12cf0 20 20 20 73 74 72 69 6e 67 20 73 6f 75 72 63 65 string source
12d00 4e 61 6d 65 0d 0a 20 20 20 20 20 20 20 20 29 0d Name.. ).
12d10 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 . {..
12d20 69 66 20 28 64 65 73 74 43 6e 6e 20 3d 3d 20 6e if (destCnn == n
12d30 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 20 ull)..
12d40 20 20 74 68 72 6f 77 20 6e 65 77 20 41 72 67 75 throw new Argu
12d50 6d 65 6e 74 4e 75 6c 6c 45 78 63 65 70 74 69 6f mentNullExceptio
12d60 6e 28 22 64 65 73 74 43 6e 6e 22 29 3b 0d 0a 0d n("destCnn");...
12d70 0a 20 20 20 20 20 20 20 20 69 66 20 28 64 65 73 . if (des
12d80 74 4e 61 6d 65 20 3d 3d 20 6e 75 6c 6c 29 0d 0a tName == null)..
12d90 20 20 20 20 20 20 20 20 20 20 20 20 74 68 72 6f thro
12da0 77 20 6e 65 77 20 41 72 67 75 6d 65 6e 74 4e 75 w new ArgumentNu
12db0 6c 6c 45 78 63 65 70 74 69 6f 6e 28 22 64 65 73 llException("des
12dc0 74 4e 61 6d 65 22 29 3b 0d 0a 0d 0a 20 20 20 20 tName");....
12dd0 20 20 20 20 69 66 20 28 73 6f 75 72 63 65 4e 61 if (sourceNa
12de0 6d 65 20 3d 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 me == null)..
12df0 20 20 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e throw n
12e00 65 77 20 41 72 67 75 6d 65 6e 74 4e 75 6c 6c 45 ew ArgumentNullE
12e10 78 63 65 70 74 69 6f 6e 28 22 73 6f 75 72 63 65 xception("source
12e20 4e 61 6d 65 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 Name");....
12e30 20 20 20 53 51 4c 69 74 65 33 20 64 65 73 74 53 SQLite3 destS
12e40 71 6c 69 74 65 33 20 3d 20 64 65 73 74 43 6e 6e qlite3 = destCnn
12e50 2e 5f 73 71 6c 20 61 73 20 53 51 4c 69 74 65 33 ._sql as SQLite3
12e60 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 66 20 ;.... if
12e70 28 64 65 73 74 53 71 6c 69 74 65 33 20 3d 3d 20 (destSqlite3 ==
12e80 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 null)..
12e90 20 20 20 74 68 72 6f 77 20 6e 65 77 20 41 72 67 throw new Arg
12ea0 75 6d 65 6e 74 45 78 63 65 70 74 69 6f 6e 28 0d umentException(.
12eb0 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
12ec0 20 22 44 65 73 74 69 6e 61 74 69 6f 6e 20 63 6f "Destination co
12ed0 6e 6e 65 63 74 69 6f 6e 20 68 61 73 20 6e 6f 20 nnection has no
12ee0 77 72 61 70 70 65 72 2e 22 2c 0d 0a 20 20 20 20 wrapper.",..
12ef0 20 20 20 20 20 20 20 20 20 20 20 20 22 64 65 73 "des
12f00 74 43 6e 6e 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 tCnn");....
12f10 20 20 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 SQLiteConnect
12f20 69 6f 6e 48 61 6e 64 6c 65 20 64 65 73 74 48 61 ionHandle destHa
12f30 6e 64 6c 65 20 3d 20 64 65 73 74 53 71 6c 69 74 ndle = destSqlit
12f40 65 33 2e 5f 73 71 6c 3b 0d 0a 0d 0a 20 20 20 20 e3._sql;....
12f50 20 20 20 20 69 66 20 28 64 65 73 74 48 61 6e 64 if (destHand
12f60 6c 65 20 3d 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 le == null)..
12f70 20 20 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e throw n
12f80 65 77 20 41 72 67 75 6d 65 6e 74 45 78 63 65 70 ew ArgumentExcep
12f90 74 69 6f 6e 28 0d 0a 20 20 20 20 20 20 20 20 20 tion(..
12fa0 20 20 20 20 20 20 20 22 44 65 73 74 69 6e 61 74 "Destinat
12fb0 69 6f 6e 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 68 ion connection h
12fc0 61 73 20 61 6e 20 69 6e 76 61 6c 69 64 20 68 61 as an invalid ha
12fd0 6e 64 6c 65 2e 22 2c 0d 0a 20 20 20 20 20 20 20 ndle.",..
12fe0 20 20 20 20 20 20 20 20 20 22 64 65 73 74 43 6e "destCn
12ff0 6e 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 n");....
13000 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e SQLiteConnection
13010 48 61 6e 64 6c 65 20 73 6f 75 72 63 65 48 61 6e Handle sourceHan
13020 64 6c 65 20 3d 20 5f 73 71 6c 3b 0d 0a 0d 0a 20 dle = _sql;....
13030 20 20 20 20 20 20 20 69 66 20 28 73 6f 75 72 63 if (sourc
13040 65 48 61 6e 64 6c 65 20 3d 3d 20 6e 75 6c 6c 29 eHandle == null)
13050 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 74 68 .. th
13060 72 6f 77 20 6e 65 77 20 49 6e 76 61 6c 69 64 4f row new InvalidO
13070 70 65 72 61 74 69 6f 6e 45 78 63 65 70 74 69 6f perationExceptio
13080 6e 28 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 n(..
13090 20 20 20 20 22 53 6f 75 72 63 65 20 63 6f 6e 6e "Source conn
130a0 65 63 74 69 6f 6e 20 68 61 73 20 61 6e 20 69 6e ection has an in
130b0 76 61 6c 69 64 20 68 61 6e 64 6c 65 2e 22 29 3b valid handle.");
130c0 0d 0a 0d 0a 20 20 20 20 20 20 20 20 62 79 74 65 .... byte
130d0 5b 5d 20 7a 44 65 73 74 4e 61 6d 65 20 3d 20 54 [] zDestName = T
130e0 6f 55 54 46 38 28 64 65 73 74 4e 61 6d 65 29 3b oUTF8(destName);
130f0 0d 0a 20 20 20 20 20 20 20 20 62 79 74 65 5b 5d .. byte[]
13100 20 7a 53 6f 75 72 63 65 4e 61 6d 65 20 3d 20 54 zSourceName = T
13110 6f 55 54 46 38 28 73 6f 75 72 63 65 4e 61 6d 65 oUTF8(sourceName
13120 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 53 51 );.... SQ
13130 4c 69 74 65 42 61 63 6b 75 70 48 61 6e 64 6c 65 LiteBackupHandle
13140 20 62 61 63 6b 75 70 48 61 6e 64 6c 65 20 3d 20 backupHandle =
13150 6e 75 6c 6c 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 null;....
13160 20 74 72 79 0d 0a 20 20 20 20 20 20 20 20 7b 0d try.. {.
13170 0a 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 . //
13180 64 6f 20 6e 6f 74 68 69 6e 67 2e 0d 0a 20 20 20 do nothing...
13190 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 }..
131a0 66 69 6e 61 6c 6c 79 20 2f 2a 20 4e 4f 54 45 3a finally /* NOTE:
131b0 20 54 68 72 65 61 64 2e 41 62 6f 72 74 28 29 20 Thread.Abort()
131c0 70 72 6f 74 65 63 74 69 6f 6e 2e 20 2a 2f 0d 0a protection. */..
131d0 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 {..
131e0 20 20 20 20 20 20 20 49 6e 74 50 74 72 20 62 61 IntPtr ba
131f0 63 6b 75 70 20 3d 20 55 6e 73 61 66 65 4e 61 74 ckup = UnsafeNat
13200 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 iveMethods.sqlit
13210 65 33 5f 62 61 63 6b 75 70 5f 69 6e 69 74 28 0d e3_backup_init(.
13220 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
13230 20 64 65 73 74 48 61 6e 64 6c 65 2c 20 7a 44 65 destHandle, zDe
13240 73 74 4e 61 6d 65 2c 20 73 6f 75 72 63 65 48 61 stName, sourceHa
13250 6e 64 6c 65 2c 20 7a 53 6f 75 72 63 65 4e 61 6d ndle, zSourceNam
13260 65 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 e);....
13270 20 20 20 69 66 20 28 62 61 63 6b 75 70 20 3d 3d if (backup ==
13280 20 49 6e 74 50 74 72 2e 5a 65 72 6f 29 0d 0a 20 IntPtr.Zero)..
13290 20 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 {..
132a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 53 51 SQ
132b0 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 20 72 65 LiteErrorCode re
132c0 73 75 6c 74 43 6f 64 65 20 3d 20 52 65 73 75 6c sultCode = Resul
132d0 74 43 6f 64 65 28 29 3b 0d 0a 0d 0a 20 20 20 20 tCode();....
132e0 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 if (
132f0 72 65 73 75 6c 74 43 6f 64 65 20 21 3d 20 53 51 resultCode != SQ
13300 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 2e 4f 6b LiteErrorCode.Ok
13310 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 )..
13320 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 77 throw new
13330 20 53 51 4c 69 74 65 45 78 63 65 70 74 69 6f 6e SQLiteException
13340 28 72 65 73 75 6c 74 43 6f 64 65 2c 20 47 65 74 (resultCode, Get
13350 4c 61 73 74 45 72 72 6f 72 28 29 29 3b 0d 0a 20 LastError());..
13360 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 65 e
13370 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 20 20 20 lse..
13380 20 20 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e throw n
13390 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 74 69 ew SQLiteExcepti
133a0 6f 6e 28 22 66 61 69 6c 65 64 20 74 6f 20 69 6e on("failed to in
133b0 69 74 69 61 6c 69 7a 65 20 62 61 63 6b 75 70 22 itialize backup"
133c0 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 );..
133d0 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 }....
133e0 20 62 61 63 6b 75 70 48 61 6e 64 6c 65 20 3d 20 backupHandle =
133f0 6e 65 77 20 53 51 4c 69 74 65 42 61 63 6b 75 70 new SQLiteBackup
13400 48 61 6e 64 6c 65 28 64 65 73 74 48 61 6e 64 6c Handle(destHandl
13410 65 2c 20 62 61 63 6b 75 70 29 3b 0d 0a 20 20 20 e, backup);..
13420 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 }....
13430 20 20 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 SQLiteConnecti
13440 6f 6e 2e 4f 6e 43 68 61 6e 67 65 64 28 6e 75 6c on.OnChanged(nul
13450 6c 2c 20 6e 65 77 20 43 6f 6e 6e 65 63 74 69 6f l, new Connectio
13460 6e 45 76 65 6e 74 41 72 67 73 28 0d 0a 20 20 20 nEventArgs(..
13470 20 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 43 SQLiteC
13480 6f 6e 6e 65 63 74 69 6f 6e 45 76 65 6e 74 54 79 onnectionEventTy
13490 70 65 2e 4e 65 77 43 72 69 74 69 63 61 6c 48 61 pe.NewCriticalHa
134a0 6e 64 6c 65 2c 20 6e 75 6c 6c 2c 20 6e 75 6c 6c ndle, null, null
134b0 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 6e ,.. n
134c0 75 6c 6c 2c 20 6e 75 6c 6c 2c 20 62 61 63 6b 75 ull, null, backu
134d0 70 48 61 6e 64 6c 65 2c 20 6e 75 6c 6c 2c 20 6e pHandle, null, n
134e0 65 77 20 6f 62 6a 65 63 74 5b 5d 20 7b 20 64 65 ew object[] { de
134f0 73 74 43 6e 6e 2c 0d 0a 20 20 20 20 20 20 20 20 stCnn,..
13500 20 20 20 20 64 65 73 74 4e 61 6d 65 2c 20 73 6f destName, so
13510 75 72 63 65 4e 61 6d 65 20 7d 29 29 3b 0d 0a 0d urceName }));...
13520 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 . return
13530 6e 65 77 20 53 51 4c 69 74 65 42 61 63 6b 75 70 new SQLiteBackup
13540 28 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 74 (.. t
13550 68 69 73 2c 20 62 61 63 6b 75 70 48 61 6e 64 6c his, backupHandl
13560 65 2c 20 64 65 73 74 48 61 6e 64 6c 65 2c 20 7a e, destHandle, z
13570 44 65 73 74 4e 61 6d 65 2c 20 73 6f 75 72 63 65 DestName, source
13580 48 61 6e 64 6c 65 2c 0d 0a 20 20 20 20 20 20 20 Handle,..
13590 20 20 20 20 20 7a 53 6f 75 72 63 65 4e 61 6d 65 zSourceName
135a0 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 );.. }....
135b0 20 2f 2f 2f 20 3c 73 75 6d 6d 61 72 79 3e 0d 0a /// <summary>..
135c0 20 20 20 20 2f 2f 2f 20 43 6f 70 69 65 73 20 75 /// Copies u
135d0 70 20 74 6f 20 4e 20 70 61 67 65 73 20 66 72 6f p to N pages fro
135e0 6d 20 74 68 65 20 73 6f 75 72 63 65 20 64 61 74 m the source dat
135f0 61 62 61 73 65 20 74 6f 20 74 68 65 20 64 65 73 abase to the des
13600 74 69 6e 61 74 69 6f 6e 0d 0a 20 20 20 20 2f 2f tination.. //
13610 2f 20 64 61 74 61 62 61 73 65 20 61 73 73 6f 63 / database assoc
13620 69 61 74 65 64 20 77 69 74 68 20 74 68 65 20 73 iated with the s
13630 70 65 63 69 66 69 65 64 20 62 61 63 6b 75 70 20 pecified backup
13640 6f 62 6a 65 63 74 2e 0d 0a 20 20 20 20 2f 2f 2f object... ///
13650 20 3c 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 </summary>..
13660 20 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 6d 65 /// <param name
13670 3d 22 62 61 63 6b 75 70 22 3e 54 68 65 20 62 61 ="backup">The ba
13680 63 6b 75 70 20 6f 62 6a 65 63 74 20 74 6f 20 75 ckup object to u
13690 73 65 2e 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 20 se.</param>..
136a0 20 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 6d 65 /// <param name
136b0 3d 22 6e 50 61 67 65 22 3e 0d 0a 20 20 20 20 2f ="nPage">.. /
136c0 2f 2f 20 54 68 65 20 6e 75 6d 62 65 72 20 6f 66 // The number of
136d0 20 70 61 67 65 73 20 74 6f 20 63 6f 70 79 2c 20 pages to copy,
136e0 6e 65 67 61 74 69 76 65 20 74 6f 20 63 6f 70 79 negative to copy
136f0 20 61 6c 6c 20 72 65 6d 61 69 6e 69 6e 67 20 70 all remaining p
13700 61 67 65 73 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c ages... /// <
13710 2f 70 61 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f /param>.. ///
13720 20 3c 70 61 72 61 6d 20 6e 61 6d 65 3d 22 72 65 <param name="re
13730 74 72 79 22 3e 0d 0a 20 20 20 20 2f 2f 2f 20 53 try">.. /// S
13740 65 74 20 74 6f 20 74 72 75 65 20 69 66 20 74 68 et to true if th
13750 65 20 6f 70 65 72 61 74 69 6f 6e 20 6e 65 65 64 e operation need
13760 73 20 74 6f 20 62 65 20 72 65 74 72 69 65 64 20 s to be retried
13770 64 75 65 20 74 6f 20 64 61 74 61 62 61 73 65 0d due to database.
13780 0a 20 20 20 20 2f 2f 2f 20 6c 6f 63 6b 69 6e 67 . /// locking
13790 20 69 73 73 75 65 73 3b 20 6f 74 68 65 72 77 69 issues; otherwi
137a0 73 65 2c 20 73 65 74 20 74 6f 20 66 61 6c 73 65 se, set to false
137b0 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f 70 61 72 ... /// </par
137c0 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 72 65 am>.. /// <re
137d0 74 75 72 6e 73 3e 0d 0a 20 20 20 20 2f 2f 2f 20 turns>.. ///
137e0 54 72 75 65 20 69 66 20 74 68 65 72 65 20 61 72 True if there ar
137f0 65 20 6d 6f 72 65 20 70 61 67 65 73 20 74 6f 20 e more pages to
13800 62 65 20 63 6f 70 69 65 64 2c 20 66 61 6c 73 65 be copied, false
13810 20 6f 74 68 65 72 77 69 73 65 2e 0d 0a 20 20 20 otherwise...
13820 20 2f 2f 2f 20 3c 2f 72 65 74 75 72 6e 73 3e 0d /// </returns>.
13830 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 . internal ov
13840 65 72 72 69 64 65 20 62 6f 6f 6c 20 53 74 65 70 erride bool Step
13850 42 61 63 6b 75 70 28 0d 0a 20 20 20 20 20 20 20 Backup(..
13860 20 53 51 4c 69 74 65 42 61 63 6b 75 70 20 62 61 SQLiteBackup ba
13870 63 6b 75 70 2c 0d 0a 20 20 20 20 20 20 20 20 69 ckup,.. i
13880 6e 74 20 6e 50 61 67 65 2c 0d 0a 20 20 20 20 20 nt nPage,..
13890 20 20 20 6f 75 74 20 62 6f 6f 6c 20 72 65 74 72 out bool retr
138a0 79 0d 0a 20 20 20 20 20 20 20 20 29 0d 0a 20 20 y.. )..
138b0 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 72 65 74 {.. ret
138c0 72 79 20 3d 20 66 61 6c 73 65 3b 0d 0a 0d 0a 20 ry = false;....
138d0 20 20 20 20 20 20 20 69 66 20 28 62 61 63 6b 75 if (backu
138e0 70 20 3d 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 p == null)..
138f0 20 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 throw ne
13900 77 20 41 72 67 75 6d 65 6e 74 4e 75 6c 6c 45 78 w ArgumentNullEx
13910 63 65 70 74 69 6f 6e 28 22 62 61 63 6b 75 70 22 ception("backup"
13920 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 53 51 );.... SQ
13930 4c 69 74 65 42 61 63 6b 75 70 48 61 6e 64 6c 65 LiteBackupHandle
13940 20 68 61 6e 64 6c 65 20 3d 20 62 61 63 6b 75 70 handle = backup
13950 2e 5f 73 71 6c 69 74 65 5f 62 61 63 6b 75 70 3b ._sqlite_backup;
13960 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 .... if (
13970 68 61 6e 64 6c 65 20 3d 3d 20 6e 75 6c 6c 29 0d handle == null).
13980 0a 20 20 20 20 20 20 20 20 20 20 20 20 74 68 72 . thr
13990 6f 77 20 6e 65 77 20 49 6e 76 61 6c 69 64 4f 70 ow new InvalidOp
139a0 65 72 61 74 69 6f 6e 45 78 63 65 70 74 69 6f 6e erationException
139b0 28 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 (..
139c0 20 20 20 22 42 61 63 6b 75 70 20 6f 62 6a 65 63 "Backup objec
139d0 74 20 68 61 73 20 61 6e 20 69 6e 76 61 6c 69 64 t has an invalid
139e0 20 68 61 6e 64 6c 65 2e 22 29 3b 0d 0a 0d 0a 20 handle.");....
139f0 20 20 20 20 20 20 20 49 6e 74 50 74 72 20 68 61 IntPtr ha
13a00 6e 64 6c 65 50 74 72 20 3d 20 68 61 6e 64 6c 65 ndlePtr = handle
13a10 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 66 20 ;.... if
13a20 28 68 61 6e 64 6c 65 50 74 72 20 3d 3d 20 49 6e (handlePtr == In
13a30 74 50 74 72 2e 5a 65 72 6f 29 0d 0a 20 20 20 20 tPtr.Zero)..
13a40 20 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e 65 throw ne
13a50 77 20 49 6e 76 61 6c 69 64 4f 70 65 72 61 74 69 w InvalidOperati
13a60 6f 6e 45 78 63 65 70 74 69 6f 6e 28 0d 0a 20 20 onException(..
13a70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 42 "B
13a80 61 63 6b 75 70 20 6f 62 6a 65 63 74 20 68 61 73 ackup object has
13a90 20 61 6e 20 69 6e 76 61 6c 69 64 20 68 61 6e 64 an invalid hand
13aa0 6c 65 20 70 6f 69 6e 74 65 72 2e 22 29 3b 0d 0a le pointer.");..
13ab0 0d 0a 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 .. SQLite
13ac0 45 72 72 6f 72 43 6f 64 65 20 6e 20 3d 20 55 6e ErrorCode n = Un
13ad0 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 safeNativeMethod
13ae0 73 2e 73 71 6c 69 74 65 33 5f 62 61 63 6b 75 70 s.sqlite3_backup
13af0 5f 73 74 65 70 28 68 61 6e 64 6c 65 50 74 72 2c _step(handlePtr,
13b00 20 6e 50 61 67 65 29 3b 0d 0a 20 20 20 20 20 20 nPage);..
13b10 20 20 62 61 63 6b 75 70 2e 5f 73 74 65 70 52 65 backup._stepRe
13b20 73 75 6c 74 20 3d 20 6e 3b 20 2f 2a 20 4e 4f 54 sult = n; /* NOT
13b30 45 3a 20 53 61 76 65 20 66 6f 72 20 75 73 65 20 E: Save for use
13b40 62 79 20 46 69 6e 69 73 68 42 61 63 6b 75 70 2e by FinishBackup.
13b50 20 2a 2f 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 */.... i
13b60 66 20 28 6e 20 3d 3d 20 53 51 4c 69 74 65 45 72 f (n == SQLiteEr
13b70 72 6f 72 43 6f 64 65 2e 4f 6b 29 0d 0a 20 20 20 rorCode.Ok)..
13b80 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
13b90 20 20 20 20 72 65 74 75 72 6e 20 74 72 75 65 3b return true;
13ba0 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 .. }..
13bb0 20 20 20 20 20 65 6c 73 65 20 69 66 20 28 6e 20 else if (n
13bc0 3d 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f == SQLiteErrorCo
13bd0 64 65 2e 42 75 73 79 29 0d 0a 20 20 20 20 20 20 de.Busy)..
13be0 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 {..
13bf0 20 72 65 74 72 79 20 3d 20 74 72 75 65 3b 0d 0a retry = true;..
13c00 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 retu
13c10 72 6e 20 74 72 75 65 3b 0d 0a 20 20 20 20 20 20 rn true;..
13c20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 65 6c 73 }.. els
13c30 65 20 69 66 20 28 6e 20 3d 3d 20 53 51 4c 69 74 e if (n == SQLit
13c40 65 45 72 72 6f 72 43 6f 64 65 2e 4c 6f 63 6b 65 eErrorCode.Locke
13c50 64 29 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 d).. {..
13c60 20 20 20 20 20 20 20 20 20 20 20 72 65 74 72 79 retry
13c70 20 3d 20 74 72 75 65 3b 0d 0a 20 20 20 20 20 20 = true;..
13c80 20 20 20 20 20 20 72 65 74 75 72 6e 20 74 72 75 return tru
13c90 65 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a 20 e;.. }..
13ca0 20 20 20 20 20 20 20 65 6c 73 65 20 69 66 20 28 else if (
13cb0 6e 20 3d 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 n == SQLiteError
13cc0 43 6f 64 65 2e 44 6f 6e 65 29 0d 0a 20 20 20 20 Code.Done)..
13cd0 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 {..
13ce0 20 20 20 72 65 74 75 72 6e 20 66 61 6c 73 65 3b return false;
13cf0 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 .. }..
13d00 20 20 20 20 20 65 6c 73 65 0d 0a 20 20 20 20 20 else..
13d10 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 {..
13d20 20 20 74 68 72 6f 77 20 6e 65 77 20 53 51 4c 69 throw new SQLi
13d30 74 65 45 78 63 65 70 74 69 6f 6e 28 6e 2c 20 47 teException(n, G
13d40 65 74 4c 61 73 74 45 72 72 6f 72 28 29 29 3b 0d etLastError());.
13d50 0a 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 . }..
13d60 7d 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 }.... /// <su
13d70 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 mmary>.. ///
13d80 52 65 74 75 72 6e 73 20 74 68 65 20 6e 75 6d 62 Returns the numb
13d90 65 72 20 6f 66 20 70 61 67 65 73 20 72 65 6d 61 er of pages rema
13da0 69 6e 69 6e 67 20 74 6f 20 62 65 20 63 6f 70 69 ining to be copi
13db0 65 64 20 66 72 6f 6d 20 74 68 65 20 73 6f 75 72 ed from the sour
13dc0 63 65 0d 0a 20 20 20 20 2f 2f 2f 20 64 61 74 61 ce.. /// data
13dd0 62 61 73 65 20 74 6f 20 74 68 65 20 64 65 73 74 base to the dest
13de0 69 6e 61 74 69 6f 6e 20 64 61 74 61 62 61 73 65 ination database
13df0 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 associated with
13e00 20 74 68 65 20 73 70 65 63 69 66 69 65 64 0d 0a the specified..
13e10 20 20 20 20 2f 2f 2f 20 62 61 63 6b 75 70 20 6f /// backup o
13e20 62 6a 65 63 74 2e 0d 0a 20 20 20 20 2f 2f 2f 20 bject... ///
13e30 3c 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 </summary>..
13e40 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 6d 65 3d /// <param name=
13e50 22 62 61 63 6b 75 70 22 3e 54 68 65 20 62 61 63 "backup">The bac
13e60 6b 75 70 20 6f 62 6a 65 63 74 20 74 6f 20 63 68 kup object to ch
13e70 65 63 6b 2e 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 eck.</param>..
13e80 20 20 2f 2f 2f 20 3c 72 65 74 75 72 6e 73 3e 54 /// <returns>T
13e90 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 70 61 67 he number of pag
13ea0 65 73 20 72 65 6d 61 69 6e 69 6e 67 20 74 6f 20 es remaining to
13eb0 62 65 20 63 6f 70 69 65 64 2e 3c 2f 72 65 74 75 be copied.</retu
13ec0 72 6e 73 3e 0d 0a 20 20 20 20 69 6e 74 65 72 6e rns>.. intern
13ed0 61 6c 20 6f 76 65 72 72 69 64 65 20 69 6e 74 20 al override int
13ee0 52 65 6d 61 69 6e 69 6e 67 42 61 63 6b 75 70 28 RemainingBackup(
13ef0 0d 0a 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 .. SQLite
13f00 42 61 63 6b 75 70 20 62 61 63 6b 75 70 0d 0a 20 Backup backup..
13f10 20 20 20 20 20 20 20 29 0d 0a 20 20 20 20 7b 0d ).. {.
13f20 0a 20 20 20 20 20 20 20 20 69 66 20 28 62 61 63 . if (bac
13f30 6b 75 70 20 3d 3d 20 6e 75 6c 6c 29 0d 0a 20 20 kup == null)..
13f40 20 20 20 20 20 20 20 20 20 20 74 68 72 6f 77 20 throw
13f50 6e 65 77 20 41 72 67 75 6d 65 6e 74 4e 75 6c 6c new ArgumentNull
13f60 45 78 63 65 70 74 69 6f 6e 28 22 62 61 63 6b 75 Exception("backu
13f70 70 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 p");....
13f80 53 51 4c 69 74 65 42 61 63 6b 75 70 48 61 6e 64 SQLiteBackupHand
13f90 6c 65 20 68 61 6e 64 6c 65 20 3d 20 62 61 63 6b le handle = back
13fa0 75 70 2e 5f 73 71 6c 69 74 65 5f 62 61 63 6b 75 up._sqlite_backu
13fb0 70 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 66 p;.... if
13fc0 20 28 68 61 6e 64 6c 65 20 3d 3d 20 6e 75 6c 6c (handle == null
13fd0 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 74 ).. t
13fe0 68 72 6f 77 20 6e 65 77 20 49 6e 76 61 6c 69 64 hrow new Invalid
13ff0 4f 70 65 72 61 74 69 6f 6e 45 78 63 65 70 74 69 OperationExcepti
14000 6f 6e 28 0d 0a 20 20 20 20 20 20 20 20 20 20 20 on(..
14010 20 20 20 20 20 22 42 61 63 6b 75 70 20 6f 62 6a "Backup obj
14020 65 63 74 20 68 61 73 20 61 6e 20 69 6e 76 61 6c ect has an inval
14030 69 64 20 68 61 6e 64 6c 65 2e 22 29 3b 0d 0a 0d id handle.");...
14040 0a 20 20 20 20 20 20 20 20 49 6e 74 50 74 72 20 . IntPtr
14050 68 61 6e 64 6c 65 50 74 72 20 3d 20 68 61 6e 64 handlePtr = hand
14060 6c 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 le;.... i
14070 66 20 28 68 61 6e 64 6c 65 50 74 72 20 3d 3d 20 f (handlePtr ==
14080 49 6e 74 50 74 72 2e 5a 65 72 6f 29 0d 0a 20 20 IntPtr.Zero)..
14090 20 20 20 20 20 20 20 20 20 20 74 68 72 6f 77 20 throw
140a0 6e 65 77 20 49 6e 76 61 6c 69 64 4f 70 65 72 61 new InvalidOpera
140b0 74 69 6f 6e 45 78 63 65 70 74 69 6f 6e 28 0d 0a tionException(..
140c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
140d0 22 42 61 63 6b 75 70 20 6f 62 6a 65 63 74 20 68 "Backup object h
140e0 61 73 20 61 6e 20 69 6e 76 61 6c 69 64 20 68 61 as an invalid ha
140f0 6e 64 6c 65 20 70 6f 69 6e 74 65 72 2e 22 29 3b ndle pointer.");
14100 0d 0a 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75 .... retu
14110 72 6e 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d rn UnsafeNativeM
14120 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 62 ethods.sqlite3_b
14130 61 63 6b 75 70 5f 72 65 6d 61 69 6e 69 6e 67 28 ackup_remaining(
14140 68 61 6e 64 6c 65 50 74 72 29 3b 0d 0a 20 20 20 handlePtr);..
14150 20 7d 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 20 3c 73 }.... /// <s
14160 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f ummary>.. ///
14170 20 52 65 74 75 72 6e 73 20 74 68 65 20 74 6f 74 Returns the tot
14180 61 6c 20 6e 75 6d 62 65 72 20 6f 66 20 70 61 67 al number of pag
14190 65 73 20 69 6e 20 74 68 65 20 73 6f 75 72 63 65 es in the source
141a0 20 64 61 74 61 62 61 73 65 20 61 73 73 6f 63 69 database associ
141b0 61 74 65 64 0d 0a 20 20 20 20 2f 2f 2f 20 77 69 ated.. /// wi
141c0 74 68 20 74 68 65 20 73 70 65 63 69 66 69 65 64 th the specified
141d0 20 62 61 63 6b 75 70 20 6f 62 6a 65 63 74 2e 0d backup object..
141e0 0a 20 20 20 20 2f 2f 2f 20 3c 2f 73 75 6d 6d 61 . /// </summa
141f0 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 61 ry>.. /// <pa
14200 72 61 6d 20 6e 61 6d 65 3d 22 62 61 63 6b 75 70 ram name="backup
14210 22 3e 54 68 65 20 62 61 63 6b 75 70 20 6f 62 6a ">The backup obj
14220 65 63 74 20 74 6f 20 63 68 65 63 6b 2e 3c 2f 70 ect to check.</p
14230 61 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c aram>.. /// <
14240 72 65 74 75 72 6e 73 3e 54 68 65 20 74 6f 74 61 returns>The tota
14250 6c 20 6e 75 6d 62 65 72 20 6f 66 20 70 61 67 65 l number of page
14260 73 20 69 6e 20 74 68 65 20 73 6f 75 72 63 65 20 s in the source
14270 64 61 74 61 62 61 73 65 2e 3c 2f 72 65 74 75 72 database.</retur
14280 6e 73 3e 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 ns>.. interna
14290 6c 20 6f 76 65 72 72 69 64 65 20 69 6e 74 20 50 l override int P
142a0 61 67 65 43 6f 75 6e 74 42 61 63 6b 75 70 28 0d ageCountBackup(.
142b0 0a 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 42 . SQLiteB
142c0 61 63 6b 75 70 20 62 61 63 6b 75 70 0d 0a 20 20 ackup backup..
142d0 20 20 20 20 20 20 29 0d 0a 20 20 20 20 7b 0d 0a ).. {..
142e0 20 20 20 20 20 20 20 20 69 66 20 28 62 61 63 6b if (back
142f0 75 70 20 3d 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 up == null)..
14300 20 20 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e throw n
14310 65 77 20 41 72 67 75 6d 65 6e 74 4e 75 6c 6c 45 ew ArgumentNullE
14320 78 63 65 70 74 69 6f 6e 28 22 62 61 63 6b 75 70 xception("backup
14330 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 53 ");.... S
14340 51 4c 69 74 65 42 61 63 6b 75 70 48 61 6e 64 6c QLiteBackupHandl
14350 65 20 68 61 6e 64 6c 65 20 3d 20 62 61 63 6b 75 e handle = backu
14360 70 2e 5f 73 71 6c 69 74 65 5f 62 61 63 6b 75 70 p._sqlite_backup
14370 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 66 20 ;.... if
14380 28 68 61 6e 64 6c 65 20 3d 3d 20 6e 75 6c 6c 29 (handle == null)
14390 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 74 68 .. th
143a0 72 6f 77 20 6e 65 77 20 49 6e 76 61 6c 69 64 4f row new InvalidO
143b0 70 65 72 61 74 69 6f 6e 45 78 63 65 70 74 69 6f perationExceptio
143c0 6e 28 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 n(..
143d0 20 20 20 20 22 42 61 63 6b 75 70 20 6f 62 6a 65 "Backup obje
143e0 63 74 20 68 61 73 20 61 6e 20 69 6e 76 61 6c 69 ct has an invali
143f0 64 20 68 61 6e 64 6c 65 2e 22 29 3b 0d 0a 0d 0a d handle.");....
14400 20 20 20 20 20 20 20 20 49 6e 74 50 74 72 20 68 IntPtr h
14410 61 6e 64 6c 65 50 74 72 20 3d 20 68 61 6e 64 6c andlePtr = handl
14420 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 69 66 e;.... if
14430 20 28 68 61 6e 64 6c 65 50 74 72 20 3d 3d 20 49 (handlePtr == I
14440 6e 74 50 74 72 2e 5a 65 72 6f 29 0d 0a 20 20 20 ntPtr.Zero)..
14450 20 20 20 20 20 20 20 20 20 74 68 72 6f 77 20 6e throw n
14460 65 77 20 49 6e 76 61 6c 69 64 4f 70 65 72 61 74 ew InvalidOperat
14470 69 6f 6e 45 78 63 65 70 74 69 6f 6e 28 0d 0a 20 ionException(..
14480 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 "
14490 42 61 63 6b 75 70 20 6f 62 6a 65 63 74 20 68 61 Backup object ha
144a0 73 20 61 6e 20 69 6e 76 61 6c 69 64 20 68 61 6e s an invalid han
144b0 64 6c 65 20 70 6f 69 6e 74 65 72 2e 22 29 3b 0d dle pointer.");.
144c0 0a 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 ... retur
144d0 6e 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 n UnsafeNativeMe
144e0 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 62 61 thods.sqlite3_ba
144f0 63 6b 75 70 5f 70 61 67 65 63 6f 75 6e 74 28 68 ckup_pagecount(h
14500 61 6e 64 6c 65 50 74 72 29 3b 0d 0a 20 20 20 20 andlePtr);..
14510 7d 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 }.... /// <su
14520 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 mmary>.. ///
14530 44 65 73 74 72 6f 79 73 20 74 68 65 20 62 61 63 Destroys the bac
14540 6b 75 70 20 6f 62 6a 65 63 74 2c 20 72 6f 6c 6c kup object, roll
14550 69 6e 67 20 62 61 63 6b 20 61 6e 79 20 62 61 63 ing back any bac
14560 6b 75 70 20 74 68 61 74 20 6d 61 79 20 62 65 20 kup that may be
14570 69 6e 0d 0a 20 20 20 20 2f 2f 2f 20 70 72 6f 67 in.. /// prog
14580 65 73 73 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 2f ess... /// </
14590 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f summary>.. //
145a0 2f 20 3c 70 61 72 61 6d 20 6e 61 6d 65 3d 22 62 / <param name="b
145b0 61 63 6b 75 70 22 3e 54 68 65 20 62 61 63 6b 75 ackup">The backu
145c0 70 20 6f 62 6a 65 63 74 20 74 6f 20 64 65 73 74 p object to dest
145d0 72 6f 79 2e 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 roy.</param>..
145e0 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
145f0 69 64 65 20 76 6f 69 64 20 46 69 6e 69 73 68 42 ide void FinishB
14600 61 63 6b 75 70 28 0d 0a 20 20 20 20 20 20 20 20 ackup(..
14610 53 51 4c 69 74 65 42 61 63 6b 75 70 20 62 61 63 SQLiteBackup bac
14620 6b 75 70 0d 0a 20 20 20 20 20 20 20 20 29 0d 0a kup.. )..
14630 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 69 {.. i
14640 66 20 28 62 61 63 6b 75 70 20 3d 3d 20 6e 75 6c f (backup == nul
14650 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 l)..
14660 74 68 72 6f 77 20 6e 65 77 20 41 72 67 75 6d 65 throw new Argume
14670 6e 74 4e 75 6c 6c 45 78 63 65 70 74 69 6f 6e 28 ntNullException(
14680 22 62 61 63 6b 75 70 22 29 3b 0d 0a 0d 0a 20 20 "backup");....
14690 20 20 20 20 20 20 53 51 4c 69 74 65 42 61 63 6b SQLiteBack
146a0 75 70 48 61 6e 64 6c 65 20 68 61 6e 64 6c 65 20 upHandle handle
146b0 3d 20 62 61 63 6b 75 70 2e 5f 73 71 6c 69 74 65 = backup._sqlite
146c0 5f 62 61 63 6b 75 70 3b 0d 0a 0d 0a 20 20 20 20 _backup;....
146d0 20 20 20 20 69 66 20 28 68 61 6e 64 6c 65 20 3d if (handle =
146e0 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 = null)..
146f0 20 20 20 20 20 74 68 72 6f 77 20 6e 65 77 20 49 throw new I
14700 6e 76 61 6c 69 64 4f 70 65 72 61 74 69 6f 6e 45 nvalidOperationE
14710 78 63 65 70 74 69 6f 6e 28 0d 0a 20 20 20 20 20 xception(..
14720 20 20 20 20 20 20 20 20 20 20 20 22 42 61 63 6b "Back
14730 75 70 20 6f 62 6a 65 63 74 20 68 61 73 20 61 6e up object has an
14740 20 69 6e 76 61 6c 69 64 20 68 61 6e 64 6c 65 2e invalid handle.
14750 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 49 ");.... I
14760 6e 74 50 74 72 20 68 61 6e 64 6c 65 50 74 72 20 ntPtr handlePtr
14770 3d 20 68 61 6e 64 6c 65 3b 0d 0a 0d 0a 20 20 20 = handle;....
14780 20 20 20 20 20 69 66 20 28 68 61 6e 64 6c 65 50 if (handleP
14790 74 72 20 3d 3d 20 49 6e 74 50 74 72 2e 5a 65 72 tr == IntPtr.Zer
147a0 6f 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 o)..
147b0 74 68 72 6f 77 20 6e 65 77 20 49 6e 76 61 6c 69 throw new Invali
147c0 64 4f 70 65 72 61 74 69 6f 6e 45 78 63 65 70 74 dOperationExcept
147d0 69 6f 6e 28 0d 0a 20 20 20 20 20 20 20 20 20 20 ion(..
147e0 20 20 20 20 20 20 22 42 61 63 6b 75 70 20 6f 62 "Backup ob
147f0 6a 65 63 74 20 68 61 73 20 61 6e 20 69 6e 76 61 ject has an inva
14800 6c 69 64 20 68 61 6e 64 6c 65 20 70 6f 69 6e 74 lid handle point
14810 65 72 2e 22 29 3b 0d 0a 0d 0a 23 69 66 20 21 53 er.");....#if !S
14820 51 4c 49 54 45 5f 53 54 41 4e 44 41 52 44 0d 0a QLITE_STANDARD..
14830 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 45 72 SQLiteEr
14840 72 6f 72 43 6f 64 65 20 6e 20 3d 20 55 6e 73 61 rorCode n = Unsa
14850 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
14860 73 71 6c 69 74 65 33 5f 62 61 63 6b 75 70 5f 66 sqlite3_backup_f
14870 69 6e 69 73 68 5f 69 6e 74 65 72 6f 70 28 68 61 inish_interop(ha
14880 6e 64 6c 65 50 74 72 29 3b 0d 0a 23 65 6c 73 65 ndlePtr);..#else
14890 0d 0a 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 .. SQLite
148a0 45 72 72 6f 72 43 6f 64 65 20 6e 20 3d 20 55 6e ErrorCode n = Un
148b0 73 61 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 safeNativeMethod
148c0 73 2e 73 71 6c 69 74 65 33 5f 62 61 63 6b 75 70 s.sqlite3_backup
148d0 5f 66 69 6e 69 73 68 28 68 61 6e 64 6c 65 50 74 _finish(handlePt
148e0 72 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 r);..#endif..
148f0 20 20 20 20 20 68 61 6e 64 6c 65 2e 53 65 74 48 handle.SetH
14900 61 6e 64 6c 65 41 73 49 6e 76 61 6c 69 64 28 29 andleAsInvalid()
14910 3b 0d 0a 0d 0a 23 69 66 20 43 4f 55 4e 54 5f 48 ;....#if COUNT_H
14920 41 4e 44 4c 45 0d 0a 20 20 20 20 20 20 20 20 69 ANDLE.. i
14930 66 20 28 28 6e 20 3d 3d 20 53 51 4c 69 74 65 45 f ((n == SQLiteE
14940 72 72 6f 72 43 6f 64 65 2e 4f 6b 29 20 7c 7c 20 rrorCode.Ok) ||
14950 28 6e 20 3d 3d 20 62 61 63 6b 75 70 2e 5f 73 74 (n == backup._st
14960 65 70 52 65 73 75 6c 74 29 29 20 68 61 6e 64 6c epResult)) handl
14970 65 2e 57 61 73 52 65 6c 65 61 73 65 64 4f 6b 28 e.WasReleasedOk(
14980 29 3b 0d 0a 23 65 6e 64 69 66 0d 0a 0d 0a 20 20 );..#endif....
14990 20 20 20 20 20 20 69 66 20 28 28 6e 20 21 3d 20 if ((n !=
149a0 53 51 4c 69 74 65 45 72 72 6f 72 43 6f 64 65 2e SQLiteErrorCode.
149b0 4f 6b 29 20 26 26 20 28 6e 20 21 3d 20 62 61 63 Ok) && (n != bac
149c0 6b 75 70 2e 5f 73 74 65 70 52 65 73 75 6c 74 29 kup._stepResult)
149d0 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 74 ).. t
149e0 68 72 6f 77 20 6e 65 77 20 53 51 4c 69 74 65 45 hrow new SQLiteE
149f0 78 63 65 70 74 69 6f 6e 28 6e 2c 20 47 65 74 4c xception(n, GetL
14a00 61 73 74 45 72 72 6f 72 28 29 29 3b 0d 0a 20 20 astError());..
14a10 20 20 7d 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 2f 2f }.... /////
14a20 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
14a30 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
14a40 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
14a50 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
14a60 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
14a70 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0d 0a 0d 0a 20 20 //////////....
14a80 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 72 79 3e 0d /// <summary>.
14a90 0a 20 20 20 20 2f 2f 2f 20 44 65 74 65 72 6d 69 . /// Determi
14aa0 6e 65 73 20 69 66 20 74 68 65 20 53 51 4c 69 74 nes if the SQLit
14ab0 65 20 63 6f 72 65 20 6c 69 62 72 61 72 79 20 68 e core library h
14ac0 61 73 20 62 65 65 6e 20 69 6e 69 74 69 61 6c 69 as been initiali
14ad0 7a 65 64 20 66 6f 72 20 74 68 65 0d 0a 20 20 20 zed for the..
14ae0 20 2f 2f 2f 20 63 75 72 72 65 6e 74 20 70 72 6f /// current pro
14af0 63 65 73 73 2e 0d 0a 20 20 20 20 2f 2f 2f 20 3c cess... /// <
14b00 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f /summary>.. /
14b10 2f 2f 20 3c 72 65 74 75 72 6e 73 3e 0d 0a 20 20 // <returns>..
14b20 20 20 2f 2f 2f 20 41 20 62 6f 6f 6c 65 61 6e 20 /// A boolean
14b30 69 6e 64 69 63 61 74 69 6e 67 20 77 68 65 74 68 indicating wheth
14b40 65 72 20 6f 72 20 6e 6f 74 20 74 68 65 20 53 51 er or not the SQ
14b50 4c 69 74 65 20 63 6f 72 65 20 6c 69 62 72 61 72 Lite core librar
14b60 79 20 68 61 73 20 62 65 65 6e 0d 0a 20 20 20 20 y has been..
14b70 2f 2f 2f 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 /// initialized
14b80 66 6f 72 20 74 68 65 20 63 75 72 72 65 6e 74 20 for the current
14b90 70 72 6f 63 65 73 73 2e 0d 0a 20 20 20 20 2f 2f process... //
14ba0 2f 20 3c 2f 72 65 74 75 72 6e 73 3e 0d 0a 20 20 / </returns>..
14bb0 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
14bc0 69 64 65 20 62 6f 6f 6c 20 49 73 49 6e 69 74 69 ide bool IsIniti
14bd0 61 6c 69 7a 65 64 28 29 0d 0a 20 20 20 20 7b 0d alized().. {.
14be0 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 . return
14bf0 53 74 61 74 69 63 49 73 49 6e 69 74 69 61 6c 69 StaticIsInitiali
14c00 7a 65 64 28 29 3b 0d 0a 20 20 20 20 7d 0d 0a 0d zed();.. }...
14c10 0a 20 20 20 20 2f 2f 2f 20 3c 73 75 6d 6d 61 72 . /// <summar
14c20 79 3e 0d 0a 20 20 20 20 2f 2f 2f 20 44 65 74 65 y>.. /// Dete
14c30 72 6d 69 6e 65 73 20 69 66 20 74 68 65 20 53 51 rmines if the SQ
14c40 4c 69 74 65 20 63 6f 72 65 20 6c 69 62 72 61 72 Lite core librar
14c50 79 20 68 61 73 20 62 65 65 6e 20 69 6e 69 74 69 y has been initi
14c60 61 6c 69 7a 65 64 20 66 6f 72 20 74 68 65 0d 0a alized for the..
14c70 20 20 20 20 2f 2f 2f 20 63 75 72 72 65 6e 74 20 /// current
14c80 70 72 6f 63 65 73 73 2e 0d 0a 20 20 20 20 2f 2f process... //
14c90 2f 20 3c 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 / </summary>..
14ca0 20 20 2f 2f 2f 20 3c 72 65 74 75 72 6e 73 3e 0d /// <returns>.
14cb0 0a 20 20 20 20 2f 2f 2f 20 41 20 62 6f 6f 6c 65 . /// A boole
14cc0 61 6e 20 69 6e 64 69 63 61 74 69 6e 67 20 77 68 an indicating wh
14cd0 65 74 68 65 72 20 6f 72 20 6e 6f 74 20 74 68 65 ether or not the
14ce0 20 53 51 4c 69 74 65 20 63 6f 72 65 20 6c 69 62 SQLite core lib
14cf0 72 61 72 79 20 68 61 73 20 62 65 65 6e 0d 0a 20 rary has been..
14d00 20 20 20 2f 2f 2f 20 69 6e 69 74 69 61 6c 69 7a /// initializ
14d10 65 64 20 66 6f 72 20 74 68 65 20 63 75 72 72 65 ed for the curre
14d20 6e 74 20 70 72 6f 63 65 73 73 2e 0d 0a 20 20 20 nt process...
14d30 20 2f 2f 2f 20 3c 2f 72 65 74 75 72 6e 73 3e 0d /// </returns>.
14d40 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 73 74 . internal st
14d50 61 74 69 63 20 62 6f 6f 6c 20 53 74 61 74 69 63 atic bool Static
14d60 49 73 49 6e 69 74 69 61 6c 69 7a 65 64 28 29 0d IsInitialized().
14d70 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 . {..
14d80 2f 2f 0d 0a 20 20 20 20 20 20 20 20 2f 2f 20 42 //.. // B
14d90 55 47 46 49 58 3a 20 50 72 65 76 65 6e 74 20 72 UGFIX: Prevent r
14da0 61 63 65 73 20 77 69 74 68 20 6f 74 68 65 72 20 aces with other
14db0 74 68 72 65 61 64 73 20 66 6f 72 20 74 68 69 73 threads for this
14dc0 20 65 6e 74 69 72 65 20 62 6c 6f 63 6b 2c 20 64 entire block, d
14dd0 75 65 0d 0a 20 20 20 20 20 20 20 20 2f 2f 20 20 ue.. //
14de0 20 20 20 20 20 20 20 74 6f 20 74 68 65 20 74 72 to the tr
14df0 79 2f 66 69 6e 61 6c 6c 79 20 73 65 6d 61 6e 74 y/finally semant
14e00 69 63 73 2e 20 20 53 65 65 20 74 69 63 6b 65 74 ics. See ticket
14e10 20 5b 37 32 39 30 35 63 39 61 37 37 5d 2e 0d 0a [72905c9a77]...
14e20 20 20 20 20 20 20 20 20 2f 2f 0d 0a 20 20 20 20 //..
14e30 20 20 20 20 6c 6f 63 6b 20 28 73 79 6e 63 52 6f lock (syncRo
14e40 6f 74 29 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a ot).. {..
14e50 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 0d 0a //..
14e60 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 4e // N
14e70 4f 54 45 3a 20 53 61 76 65 20 74 68 65 20 73 74 OTE: Save the st
14e80 61 74 65 20 6f 66 20 74 68 65 20 6c 6f 67 67 69 ate of the loggi
14e90 6e 67 20 63 6c 61 73 73 20 61 6e 64 20 74 68 65 ng class and the
14ea0 6e 20 72 65 73 74 6f 72 65 20 69 74 0d 0a 20 20 n restore it..
14eb0 20 20 20 20 20 20 20 20 20 20 2f 2f 20 20 20 20 //
14ec0 20 20 20 61 66 74 65 72 20 77 65 20 61 72 65 20 after we are
14ed0 64 6f 6e 65 20 74 6f 20 61 76 6f 69 64 20 6c 6f done to avoid lo
14ee0 67 67 69 6e 67 20 74 6f 6f 20 6d 61 6e 79 20 66 gging too many f
14ef0 61 6c 73 65 20 65 72 72 6f 72 73 2e 0d 0a 20 20 alse errors...
14f00 20 20 20 20 20 20 20 20 20 20 2f 2f 0d 0a 20 20 //..
14f10 20 20 20 20 20 20 20 20 20 20 62 6f 6f 6c 20 73 bool s
14f20 61 76 65 64 45 6e 61 62 6c 65 64 20 3d 20 53 51 avedEnabled = SQ
14f30 4c 69 74 65 4c 6f 67 2e 45 6e 61 62 6c 65 64 3b LiteLog.Enabled;
14f40 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 53 51 .. SQ
14f50 4c 69 74 65 4c 6f 67 2e 45 6e 61 62 6c 65 64 20 LiteLog.Enabled
14f60 3d 20 66 61 6c 73 65 3b 0d 0a 0d 0a 20 20 20 20 = false;....
14f70 20 20 20 20 20 20 20 20 74 72 79 0d 0a 20 20 20 try..
14f80 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 {..
14f90 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 0d 0a //..
14fa0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
14fb0 2f 2f 20 4e 4f 54 45 3a 20 54 68 69 73 20 6d 65 // NOTE: This me
14fc0 74 68 6f 64 20 5b 61 62 5d 75 73 65 73 20 74 68 thod [ab]uses th
14fd0 65 20 66 61 63 74 20 74 68 61 74 20 53 51 4c 69 e fact that SQLi
14fe0 74 65 20 77 69 6c 6c 20 61 6c 77 61 79 73 0d 0a te will always..
14ff0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15000 2f 2f 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 // return
15010 53 51 4c 49 54 45 5f 45 52 52 4f 52 20 66 6f 72 SQLITE_ERROR for
15020 20 61 6e 79 20 75 6e 6b 6e 6f 77 6e 20 63 6f 6e any unknown con
15030 66 69 67 75 72 61 74 69 6f 6e 20 6f 70 74 69 6f figuration optio
15040 6e 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 n..
15050 20 20 20 2f 2f 20 20 20 20 20 20 20 2a 75 6e 6c // *unl
15060 65 73 73 2a 20 74 68 65 20 53 51 4c 69 74 65 20 ess* the SQLite
15070 6c 69 62 72 61 72 79 20 68 61 73 20 61 6c 72 65 library has alre
15080 61 64 79 20 62 65 65 6e 20 69 6e 69 74 69 61 6c ady been initial
15090 69 7a 65 64 2e 0d 0a 20 20 20 20 20 20 20 20 20 ized...
150a0 20 20 20 20 20 20 20 2f 2f 20 20 20 20 20 20 20 //
150b0 49 6e 20 74 68 61 74 20 63 61 73 65 20 69 74 20 In that case it
150c0 77 69 6c 6c 20 61 6c 77 61 79 73 20 72 65 74 75 will always retu
150d0 72 6e 20 53 51 4c 49 54 45 5f 4d 49 53 55 53 45 rn SQLITE_MISUSE
150e0 2e 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ...
150f0 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 20 20 20 //..
15100 20 20 20 20 20 20 20 53 51 4c 69 74 65 45 72 72 SQLiteErr
15110 6f 72 43 6f 64 65 20 72 63 20 3d 20 55 6e 73 61 orCode rc = Unsa
15120 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
15130 73 71 6c 69 74 65 33 5f 63 6f 6e 66 69 67 5f 6e sqlite3_config_n
15140 6f 6e 65 28 0d 0a 20 20 20 20 20 20 20 20 20 20 one(..
15150 20 20 20 20 20 20 20 20 20 20 53 51 4c 69 74 65 SQLite
15160 43 6f 6e 66 69 67 4f 70 73 45 6e 75 6d 2e 53 51 ConfigOpsEnum.SQ
15170 4c 49 54 45 5f 43 4f 4e 46 49 47 5f 4e 4f 4e 45 LITE_CONFIG_NONE
15180 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 );....
15190 20 20 20 20 20 20 72 65 74 75 72 6e 20 28 72 63 return (rc
151a0 20 3d 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 43 == SQLiteErrorC
151b0 6f 64 65 2e 4d 69 73 75 73 65 29 3b 0d 0a 20 20 ode.Misuse);..
151c0 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 }..
151d0 20 20 20 20 20 20 20 20 20 66 69 6e 61 6c 6c 79 finally
151e0 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d .. {.
151f0 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
15200 20 53 51 4c 69 74 65 4c 6f 67 2e 45 6e 61 62 6c SQLiteLog.Enabl
15210 65 64 20 3d 20 73 61 76 65 64 45 6e 61 62 6c 65 ed = savedEnable
15220 64 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 d;..
15230 7d 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 }.. }..
15240 20 20 7d 0d 0a 0d 0a 20 20 20 20 2f 2f 2f 20 3c }.... /// <
15250 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 2f 2f summary>.. //
15260 2f 20 48 65 6c 70 65 72 20 66 75 6e 63 74 69 6f / Helper functio
15270 6e 20 74 6f 20 72 65 74 72 69 65 76 65 20 61 20 n to retrieve a
15280 63 6f 6c 75 6d 6e 20 6f 66 20 64 61 74 61 20 66 column of data f
15290 72 6f 6d 20 61 6e 20 61 63 74 69 76 65 20 73 74 rom an active st
152a0 61 74 65 6d 65 6e 74 2e 0d 0a 20 20 20 20 2f 2f atement... //
152b0 2f 20 3c 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 / </summary>..
152c0 20 20 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 6d /// <param nam
152d0 65 3d 22 73 74 6d 74 22 3e 54 68 65 20 73 74 61 e="stmt">The sta
152e0 74 65 6d 65 6e 74 20 62 65 69 6e 67 20 73 74 65 tement being ste
152f0 70 28 29 27 64 20 74 68 72 6f 75 67 68 3c 2f 70 p()'d through</p
15300 61 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c aram>.. /// <
15310 70 61 72 61 6d 20 6e 61 6d 65 3d 22 66 6c 61 67 param name="flag
15320 73 22 3e 54 68 65 20 66 6c 61 67 73 20 61 73 73 s">The flags ass
15330 6f 63 69 61 74 65 64 20 77 69 74 68 20 74 68 65 ociated with the
15340 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e 3c 2f 70 61 connection.</pa
15350 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 3c 70 ram>.. /// <p
15360 61 72 61 6d 20 6e 61 6d 65 3d 22 69 6e 64 65 78 aram name="index
15370 22 3e 54 68 65 20 63 6f 6c 75 6d 6e 20 69 6e 64 ">The column ind
15380 65 78 20 74 6f 20 72 65 74 72 69 65 76 65 3c 2f ex to retrieve</
15390 70 61 72 61 6d 3e 0d 0a 20 20 20 20 2f 2f 2f 20 param>.. ///
153a0 3c 70 61 72 61 6d 20 6e 61 6d 65 3d 22 74 79 70 <param name="typ
153b0 22 3e 54 68 65 20 74 79 70 65 20 6f 66 20 64 61 ">The type of da
153c0 74 61 20 63 6f 6e 74 61 69 6e 65 64 20 69 6e 20 ta contained in
153d0 74 68 65 20 63 6f 6c 75 6d 6e 2e 20 20 49 66 20 the column. If
153e0 55 6e 69 6e 69 74 69 61 6c 69 7a 65 64 2c 20 74 Uninitialized, t
153f0 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 77 69 6c his function wil
15400 6c 20 72 65 74 72 69 65 76 65 20 74 68 65 20 64 l retrieve the d
15410 61 74 61 74 79 70 65 20 69 6e 66 6f 72 6d 61 74 atatype informat
15420 69 6f 6e 2e 3c 2f 70 61 72 61 6d 3e 0d 0a 20 20 ion.</param>..
15430 20 20 2f 2f 2f 20 3c 72 65 74 75 72 6e 73 3e 52 /// <returns>R
15440 65 74 75 72 6e 73 20 74 68 65 20 64 61 74 61 20 eturns the data
15450 69 6e 20 74 68 65 20 63 6f 6c 75 6d 6e 3c 2f 72 in the column</r
15460 65 74 75 72 6e 73 3e 0d 0a 20 20 20 20 69 6e 74 eturns>.. int
15470 65 72 6e 61 6c 20 6f 76 65 72 72 69 64 65 20 6f ernal override o
15480 62 6a 65 63 74 20 47 65 74 56 61 6c 75 65 28 53 bject GetValue(S
15490 51 4c 69 74 65 53 74 61 74 65 6d 65 6e 74 20 73 QLiteStatement s
154a0 74 6d 74 2c 20 53 51 4c 69 74 65 43 6f 6e 6e 65 tmt, SQLiteConne
154b0 63 74 69 6f 6e 46 6c 61 67 73 20 66 6c 61 67 73 ctionFlags flags
154c0 2c 20 69 6e 74 20 69 6e 64 65 78 2c 20 53 51 4c , int index, SQL
154d0 69 74 65 54 79 70 65 20 74 79 70 29 0d 0a 20 20 iteType typ)..
154e0 20 20 7b 0d 0a 20 20 20 20 20 20 54 79 70 65 41 {.. TypeA
154f0 66 66 69 6e 69 74 79 20 61 66 66 20 3d 20 74 79 ffinity aff = ty
15500 70 2e 41 66 66 69 6e 69 74 79 3b 0d 0a 20 20 20 p.Affinity;..
15510 20 20 20 69 66 20 28 61 66 66 20 3d 3d 20 54 79 if (aff == Ty
15520 70 65 41 66 66 69 6e 69 74 79 2e 4e 75 6c 6c 29 peAffinity.Null)
15530 20 72 65 74 75 72 6e 20 44 42 4e 75 6c 6c 2e 56 return DBNull.V
15540 61 6c 75 65 3b 0d 0a 20 20 20 20 20 20 54 79 70 alue;.. Typ
15550 65 20 74 20 3d 20 6e 75 6c 6c 3b 0d 0a 0d 0a 20 e t = null;....
15560 20 20 20 20 20 69 66 20 28 74 79 70 2e 54 79 70 if (typ.Typ
15570 65 20 21 3d 20 44 62 54 79 70 65 2e 4f 62 6a 65 e != DbType.Obje
15580 63 74 29 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 20 ct).. {..
15590 20 20 20 20 20 20 74 20 3d 20 53 51 4c 69 74 65 t = SQLite
155a0 43 6f 6e 76 65 72 74 2e 53 51 4c 69 74 65 54 79 Convert.SQLiteTy
155b0 70 65 54 6f 54 79 70 65 28 74 79 70 29 3b 0d 0a peToType(typ);..
155c0 20 20 20 20 20 20 20 20 61 66 66 20 3d 20 54 79 aff = Ty
155d0 70 65 54 6f 41 66 66 69 6e 69 74 79 28 74 29 3b peToAffinity(t);
155e0 0d 0a 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 .. }....
155f0 20 20 20 69 66 20 28 28 66 6c 61 67 73 20 26 20 if ((flags &
15600 53 51 4c 69 74 65 43 6f 6e 6e 65 63 74 69 6f 6e SQLiteConnection
15610 46 6c 61 67 73 2e 47 65 74 41 6c 6c 41 73 54 65 Flags.GetAllAsTe
15620 78 74 29 20 3d 3d 20 53 51 4c 69 74 65 43 6f 6e xt) == SQLiteCon
15630 6e 65 63 74 69 6f 6e 46 6c 61 67 73 2e 47 65 74 nectionFlags.Get
15640 41 6c 6c 41 73 54 65 78 74 29 0d 0a 20 20 20 20 AllAsText)..
15650 20 20 20 20 20 20 72 65 74 75 72 6e 20 47 65 74 return Get
15660 54 65 78 74 28 73 74 6d 74 2c 20 69 6e 64 65 78 Text(stmt, index
15670 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 73 77 69 74 );.... swit
15680 63 68 20 28 61 66 66 29 0d 0a 20 20 20 20 20 20 ch (aff)..
15690 7b 0d 0a 20 20 20 20 20 20 20 20 63 61 73 65 20 {.. case
156a0 54 79 70 65 41 66 66 69 6e 69 74 79 2e 42 6c 6f TypeAffinity.Blo
156b0 62 3a 0d 0a 20 20 20 20 20 20 20 20 20 20 69 66 b:.. if
156c0 20 28 74 79 70 2e 54 79 70 65 20 3d 3d 20 44 62 (typ.Type == Db
156d0 54 79 70 65 2e 47 75 69 64 20 26 26 20 74 79 70 Type.Guid && typ
156e0 2e 41 66 66 69 6e 69 74 79 20 3d 3d 20 54 79 70 .Affinity == Typ
156f0 65 41 66 66 69 6e 69 74 79 2e 54 65 78 74 29 0d eAffinity.Text).
15700 0a 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 . ret
15710 75 72 6e 20 6e 65 77 20 47 75 69 64 28 47 65 74 urn new Guid(Get
15720 54 65 78 74 28 73 74 6d 74 2c 20 69 6e 64 65 78 Text(stmt, index
15730 29 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 ));....
15740 20 69 6e 74 20 6e 20 3d 20 28 69 6e 74 29 47 65 int n = (int)Ge
15750 74 42 79 74 65 73 28 73 74 6d 74 2c 20 69 6e 64 tBytes(stmt, ind
15760 65 78 2c 20 30 2c 20 6e 75 6c 6c 2c 20 30 2c 20 ex, 0, null, 0,
15770 30 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 62 0);.. b
15780 79 74 65 5b 5d 20 62 20 3d 20 6e 65 77 20 62 79 yte[] b = new by
15790 74 65 5b 6e 5d 3b 0d 0a 20 20 20 20 20 20 20 20 te[n];..
157a0 20 20 47 65 74 42 79 74 65 73 28 73 74 6d 74 2c GetBytes(stmt,
157b0 20 69 6e 64 65 78 2c 20 30 2c 20 62 2c 20 30 2c index, 0, b, 0,
157c0 20 6e 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 n);....
157d0 20 20 69 66 20 28 74 79 70 2e 54 79 70 65 20 3d if (typ.Type =
157e0 3d 20 44 62 54 79 70 65 2e 47 75 69 64 20 26 26 = DbType.Guid &&
157f0 20 6e 20 3d 3d 20 31 36 29 0d 0a 20 20 20 20 20 n == 16)..
15800 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 6e 65 return ne
15810 77 20 47 75 69 64 28 62 29 3b 0d 0a 0d 0a 20 20 w Guid(b);....
15820 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 62 return b
15830 3b 0d 0a 20 20 20 20 20 20 20 20 63 61 73 65 20 ;.. case
15840 54 79 70 65 41 66 66 69 6e 69 74 79 2e 44 61 74 TypeAffinity.Dat
15850 65 54 69 6d 65 3a 0d 0a 20 20 20 20 20 20 20 20 eTime:..
15860 20 20 72 65 74 75 72 6e 20 47 65 74 44 61 74 65 return GetDate
15870 54 69 6d 65 28 73 74 6d 74 2c 20 69 6e 64 65 78 Time(stmt, index
15880 29 3b 0d 0a 20 20 20 20 20 20 20 20 63 61 73 65 );.. case
15890 20 54 79 70 65 41 66 66 69 6e 69 74 79 2e 44 6f TypeAffinity.Do
158a0 75 62 6c 65 3a 0d 0a 20 20 20 20 20 20 20 20 20 uble:..
158b0 20 69 66 20 28 74 20 3d 3d 20 6e 75 6c 6c 29 20 if (t == null)
158c0 72 65 74 75 72 6e 20 47 65 74 44 6f 75 62 6c 65 return GetDouble
158d0 28 73 74 6d 74 2c 20 69 6e 64 65 78 29 3b 0d 0a (stmt, index);..
158e0 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e return
158f0 20 43 6f 6e 76 65 72 74 2e 43 68 61 6e 67 65 54 Convert.ChangeT
15900 79 70 65 28 47 65 74 44 6f 75 62 6c 65 28 73 74 ype(GetDouble(st
15910 6d 74 2c 20 69 6e 64 65 78 29 2c 20 74 2c 20 6e mt, index), t, n
15920 75 6c 6c 29 3b 0d 0a 20 20 20 20 20 20 20 20 63 ull);.. c
15930 61 73 65 20 54 79 70 65 41 66 66 69 6e 69 74 79 ase TypeAffinity
15940 2e 49 6e 74 36 34 3a 0d 0a 20 20 20 20 20 20 20 .Int64:..
15950 20 20 20 69 66 20 28 74 20 3d 3d 20 6e 75 6c 6c if (t == null
15960 29 20 72 65 74 75 72 6e 20 47 65 74 49 6e 74 36 ) return GetInt6
15970 34 28 73 74 6d 74 2c 20 69 6e 64 65 78 29 3b 0d 4(stmt, index);.
15980 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 28 74 . if (t
15990 20 3d 3d 20 74 79 70 65 6f 66 28 53 42 79 74 65 == typeof(SByte
159a0 29 29 20 72 65 74 75 72 6e 20 47 65 74 53 42 79 )) return GetSBy
159b0 74 65 28 73 74 6d 74 2c 20 69 6e 64 65 78 29 3b te(stmt, index);
159c0 0d 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 28 .. if (
159d0 74 20 3d 3d 20 74 79 70 65 6f 66 28 42 79 74 65 t == typeof(Byte
159e0 29 29 20 72 65 74 75 72 6e 20 47 65 74 42 79 74 )) return GetByt
159f0 65 28 73 74 6d 74 2c 20 69 6e 64 65 78 29 3b 0d e(stmt, index);.
15a00 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 28 74 . if (t
15a10 20 3d 3d 20 74 79 70 65 6f 66 28 49 6e 74 31 36 == typeof(Int16
15a20 29 29 20 72 65 74 75 72 6e 20 47 65 74 49 6e 74 )) return GetInt
15a30 31 36 28 73 74 6d 74 2c 20 69 6e 64 65 78 29 3b 16(stmt, index);
15a40 0d 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 28 .. if (
15a50 74 20 3d 3d 20 74 79 70 65 6f 66 28 55 49 6e 74 t == typeof(UInt
15a60 31 36 29 29 20 72 65 74 75 72 6e 20 47 65 74 55 16)) return GetU
15a70 49 6e 74 31 36 28 73 74 6d 74 2c 20 69 6e 64 65 Int16(stmt, inde
15a80 78 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 69 x);.. i
15a90 66 20 28 74 20 3d 3d 20 74 79 70 65 6f 66 28 49 f (t == typeof(I
15aa0 6e 74 33 32 29 29 20 72 65 74 75 72 6e 20 47 65 nt32)) return Ge
15ab0 74 49 6e 74 33 32 28 73 74 6d 74 2c 20 69 6e 64 tInt32(stmt, ind
15ac0 65 78 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 ex);..
15ad0 69 66 20 28 74 20 3d 3d 20 74 79 70 65 6f 66 28 if (t == typeof(
15ae0 55 49 6e 74 33 32 29 29 20 72 65 74 75 72 6e 20 UInt32)) return
15af0 47 65 74 55 49 6e 74 33 32 28 73 74 6d 74 2c 20 GetUInt32(stmt,
15b00 69 6e 64 65 78 29 3b 0d 0a 20 20 20 20 20 20 20 index);..
15b10 20 20 20 69 66 20 28 74 20 3d 3d 20 74 79 70 65 if (t == type
15b20 6f 66 28 55 49 6e 74 36 34 29 29 20 72 65 74 75 of(UInt64)) retu
15b30 72 6e 20 47 65 74 55 49 6e 74 36 34 28 73 74 6d rn GetUInt64(stm
15b40 74 2c 20 69 6e 64 65 78 29 3b 0d 0a 20 20 20 20 t, index);..
15b50 20 20 20 20 20 20 72 65 74 75 72 6e 20 43 6f 6e return Con
15b60 76 65 72 74 2e 43 68 61 6e 67 65 54 79 70 65 28 vert.ChangeType(
15b70 47 65 74 49 6e 74 36 34 28 73 74 6d 74 2c 20 69 GetInt64(stmt, i
15b80 6e 64 65 78 29 2c 20 74 2c 20 6e 75 6c 6c 29 3b ndex), t, null);
15b90 0d 0a 20 20 20 20 20 20 20 20 64 65 66 61 75 6c .. defaul
15ba0 74 3a 0d 0a 20 20 20 20 20 20 20 20 20 20 72 65 t:.. re
15bb0 74 75 72 6e 20 47 65 74 54 65 78 74 28 73 74 6d turn GetText(stm
15bc0 74 2c 20 69 6e 64 65 78 29 3b 0d 0a 20 20 20 20 t, index);..
15bd0 20 20 7d 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 20 }.. }....
15be0 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 72 internal overr
15bf0 69 64 65 20 69 6e 74 20 47 65 74 43 75 72 73 6f ide int GetCurso
15c00 72 46 6f 72 54 61 62 6c 65 28 53 51 4c 69 74 65 rForTable(SQLite
15c10 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 2c 20 Statement stmt,
15c20 69 6e 74 20 64 62 2c 20 69 6e 74 20 72 6f 6f 74 int db, int root
15c30 50 61 67 65 29 0d 0a 20 20 20 20 7b 0d 0a 23 69 Page).. {..#i
15c40 66 20 21 53 51 4c 49 54 45 5f 53 54 41 4e 44 41 f !SQLITE_STANDA
15c50 52 44 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e RD.. return
15c60 20 55 6e 73 61 66 65 4e 61 74 69 76 65 4d 65 74 UnsafeNativeMet
15c70 68 6f 64 73 2e 73 71 6c 69 74 65 33 5f 74 61 62 hods.sqlite3_tab
15c80 6c 65 5f 63 75 72 73 6f 72 5f 69 6e 74 65 72 6f le_cursor_intero
15c90 70 28 73 74 6d 74 2e 5f 73 71 6c 69 74 65 5f 73 p(stmt._sqlite_s
15ca0 74 6d 74 2c 20 64 62 2c 20 72 6f 6f 74 50 61 67 tmt, db, rootPag
15cb0 65 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 e);..#else..
15cc0 20 20 72 65 74 75 72 6e 20 2d 31 3b 0d 0a 23 65 return -1;..#e
15cd0 6e 64 69 66 0d 0a 20 20 20 20 7d 0d 0a 0d 0a 20 ndif.. }....
15ce0 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 72 internal over
15cf0 72 69 64 65 20 6c 6f 6e 67 20 47 65 74 52 6f 77 ride long GetRow
15d00 49 64 46 6f 72 43 75 72 73 6f 72 28 53 51 4c 69 IdForCursor(SQLi
15d10 74 65 53 74 61 74 65 6d 65 6e 74 20 73 74 6d 74 teStatement stmt
15d20 2c 20 69 6e 74 20 63 75 72 73 6f 72 29 0d 0a 20 , int cursor)..
15d30 20 20 20 7b 0d 0a 23 69 66 20 21 53 51 4c 49 54 {..#if !SQLIT
15d40 45 5f 53 54 41 4e 44 41 52 44 0d 0a 20 20 20 20 E_STANDARD..
15d50 20 20 6c 6f 6e 67 20 72 6f 77 69 64 3b 0d 0a 20 long rowid;..
15d60 20 20 20 20 20 53 51 4c 69 74 65 45 72 72 6f 72 SQLiteError
15d70 43 6f 64 65 20 72 63 20 3d 20 55 6e 73 61 66 65 Code rc = Unsafe
15d80 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e 73 71 NativeMethods.sq
15d90 6c 69 74 65 33 5f 63 75 72 73 6f 72 5f 72 6f 77 lite3_cursor_row
15da0 69 64 5f 69 6e 74 65 72 6f 70 28 73 74 6d 74 2e id_interop(stmt.
15db0 5f 73 71 6c 69 74 65 5f 73 74 6d 74 2c 20 63 75 _sqlite_stmt, cu
15dc0 72 73 6f 72 2c 20 6f 75 74 20 72 6f 77 69 64 29 rsor, out rowid)
15dd0 3b 0d 0a 20 20 20 20 20 20 69 66 20 28 72 63 20 ;.. if (rc
15de0 3d 3d 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f == SQLiteErrorCo
15df0 64 65 2e 4f 6b 29 20 72 65 74 75 72 6e 20 72 6f de.Ok) return ro
15e00 77 69 64 3b 0d 0a 0d 0a 20 20 20 20 20 20 72 65 wid;.... re
15e10 74 75 72 6e 20 30 3b 0d 0a 23 65 6c 73 65 0d 0a turn 0;..#else..
15e20 20 20 20 20 20 20 72 65 74 75 72 6e 20 30 3b 0d return 0;.
15e30 0a 23 65 6e 64 69 66 0d 0a 20 20 20 20 7d 0d 0a .#endif.. }..
15e40 0d 0a 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f .. internal o
15e50 76 65 72 72 69 64 65 20 76 6f 69 64 20 47 65 74 verride void Get
15e60 49 6e 64 65 78 43 6f 6c 75 6d 6e 45 78 74 65 6e IndexColumnExten
15e70 64 65 64 49 6e 66 6f 28 73 74 72 69 6e 67 20 64 dedInfo(string d
15e80 61 74 61 62 61 73 65 2c 20 73 74 72 69 6e 67 20 atabase, string
15e90 69 6e 64 65 78 2c 20 73 74 72 69 6e 67 20 63 6f index, string co
15ea0 6c 75 6d 6e 2c 20 6f 75 74 20 69 6e 74 20 73 6f lumn, out int so
15eb0 72 74 4d 6f 64 65 2c 20 6f 75 74 20 69 6e 74 20 rtMode, out int
15ec0 6f 6e 45 72 72 6f 72 2c 20 6f 75 74 20 73 74 72 onError, out str
15ed0 69 6e 67 20 63 6f 6c 6c 61 74 69 6f 6e 53 65 71 ing collationSeq
15ee0 75 65 6e 63 65 29 0d 0a 20 20 20 20 7b 0d 0a 23 uence).. {..#
15ef0 69 66 20 21 53 51 4c 49 54 45 5f 53 54 41 4e 44 if !SQLITE_STAND
15f00 41 52 44 0d 0a 20 20 20 20 20 20 49 6e 74 50 74 ARD.. IntPt
15f10 72 20 63 6f 6c 6c 3b 0d 0a 20 20 20 20 20 20 69 r coll;.. i
15f20 6e 74 20 63 6f 6c 6c 6c 65 6e 3b 0d 0a 20 20 20 nt colllen;..
15f30 20 20 20 53 51 4c 69 74 65 45 72 72 6f 72 43 6f SQLiteErrorCo
15f40 64 65 20 72 63 3b 0d 0a 0d 0a 20 20 20 20 20 20 de rc;....
15f50 72 63 20 3d 20 55 6e 73 61 66 65 4e 61 74 69 76 rc = UnsafeNativ
15f60 65 4d 65 74 68 6f 64 73 2e 73 71 6c 69 74 65 33 eMethods.sqlite3
15f70 5f 69 6e 64 65 78 5f 63 6f 6c 75 6d 6e 5f 69 6e _index_column_in
15f80 66 6f 5f 69 6e 74 65 72 6f 70 28 5f 73 71 6c 2c fo_interop(_sql,
15f90 20 54 6f 55 54 46 38 28 64 61 74 61 62 61 73 65 ToUTF8(database
15fa0 29 2c 20 54 6f 55 54 46 38 28 69 6e 64 65 78 29 ), ToUTF8(index)
15fb0 2c 20 54 6f 55 54 46 38 28 63 6f 6c 75 6d 6e 29 , ToUTF8(column)
15fc0 2c 20 6f 75 74 20 73 6f 72 74 4d 6f 64 65 2c 20 , out sortMode,
15fd0 6f 75 74 20 6f 6e 45 72 72 6f 72 2c 20 6f 75 74 out onError, out
15fe0 20 63 6f 6c 6c 2c 20 6f 75 74 20 63 6f 6c 6c 6c coll, out colll
15ff0 65 6e 29 3b 0d 0a 20 20 20 20 20 20 69 66 20 28 en);.. if (
16000 72 63 20 21 3d 20 53 51 4c 69 74 65 45 72 72 6f rc != SQLiteErro
16010 72 43 6f 64 65 2e 4f 6b 29 20 74 68 72 6f 77 20 rCode.Ok) throw
16020 6e 65 77 20 53 51 4c 69 74 65 45 78 63 65 70 74 new SQLiteExcept
16030 69 6f 6e 28 72 63 2c 20 6e 75 6c 6c 29 3b 0d 0a ion(rc, null);..
16040 0d 0a 20 20 20 20 20 20 63 6f 6c 6c 61 74 69 6f .. collatio
16050 6e 53 65 71 75 65 6e 63 65 20 3d 20 55 54 46 38 nSequence = UTF8
16060 54 6f 53 74 72 69 6e 67 28 63 6f 6c 6c 2c 20 63 ToString(coll, c
16070 6f 6c 6c 6c 65 6e 29 3b 0d 0a 23 65 6c 73 65 0d olllen);..#else.
16080 0a 20 20 20 20 20 20 73 6f 72 74 4d 6f 64 65 20 . sortMode
16090 3d 20 30 3b 0d 0a 20 20 20 20 20 20 6f 6e 45 72 = 0;.. onEr
160a0 72 6f 72 20 3d 20 32 3b 0d 0a 20 20 20 20 20 20 ror = 2;..
160b0 63 6f 6c 6c 61 74 69 6f 6e 53 65 71 75 65 6e 63 collationSequenc
160c0 65 20 3d 20 22 42 49 4e 41 52 59 22 3b 0d 0a 23 e = "BINARY";..#
160d0 65 6e 64 69 66 0d 0a 20 20 20 20 7d 0d 0a 0d 0a endif.. }....
160e0 20 20 20 20 69 6e 74 65 72 6e 61 6c 20 6f 76 65 internal ove
160f0 72 72 69 64 65 20 53 51 4c 69 74 65 45 72 72 6f rride SQLiteErro
16100 72 43 6f 64 65 20 46 69 6c 65 43 6f 6e 74 72 6f rCode FileContro
16110 6c 28 73 74 72 69 6e 67 20 7a 44 62 4e 61 6d 65 l(string zDbName
16120 2c 20 69 6e 74 20 6f 70 2c 20 49 6e 74 50 74 72 , int op, IntPtr
16130 20 70 41 72 67 29 0d 0a 20 20 20 20 7b 0d 0a 20 pArg).. {..
16140 20 20 20 20 20 72 65 74 75 72 6e 20 55 6e 73 61 return Unsa
16150 66 65 4e 61 74 69 76 65 4d 65 74 68 6f 64 73 2e feNativeMethods.
16160 73 71 6c 69 74 65 33 5f 66 69 6c 65 5f 63 6f 6e sqlite3_file_con
16170 74 72 6f 6c 28 5f 73 71 6c 2c 20 28 7a 44 62 4e trol(_sql, (zDbN
16180 61 6d 65 20 21 3d 20 6e 75 6c 6c 29 20 3f 20 54 ame != null) ? T
16190 6f 55 54 46 38 28 7a 44 62 4e 61 6d 65 29 20 3a oUTF8(zDbName) :
161a0 20 6e 75 6c 6c 2c 20 6f 70 2c 20 70 41 72 67 29 null, op, pArg)
161b0 3b 0d 0a 20 20 20 20 7d 0d 0a 20 20 7d 0d 0a 7d ;.. }.. }..}
161c0 0d 0a ..