0000: 2f 2a 0a 2a 2a 20 32 30 30 37 20 4d 61 72 63 68 /*.** 2007 March
0010: 20 32 39 0a 2a 2a 0a 2a 2a 20 54 68 65 20 61 75 29.**.** The au
0020: 74 68 6f 72 20 64 69 73 63 6c 61 69 6d 73 20 63 thor disclaims c
0030: 6f 70 79 72 69 67 68 74 20 74 6f 20 74 68 69 73 opyright to this
0040: 20 73 6f 75 72 63 65 20 63 6f 64 65 2e 20 20 49 source code. I
0050: 6e 20 70 6c 61 63 65 20 6f 66 0a 2a 2a 20 61 20 n place of.** a
0060: 6c 65 67 61 6c 20 6e 6f 74 69 63 65 2c 20 68 65 legal notice, he
0070: 72 65 20 69 73 20 61 20 62 6c 65 73 73 69 6e 67 re is a blessing
0080: 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 4d 61 79 20 79 :.**.** May y
0090: 6f 75 20 64 6f 20 67 6f 6f 64 20 61 6e 64 20 6e ou do good and n
00a0: 6f 74 20 65 76 69 6c 2e 0a 2a 2a 20 20 20 20 4d ot evil..** M
00b0: 61 79 20 79 6f 75 20 66 69 6e 64 20 66 6f 72 67 ay you find forg
00c0: 69 76 65 6e 65 73 73 20 66 6f 72 20 79 6f 75 72 iveness for your
00d0: 73 65 6c 66 20 61 6e 64 20 66 6f 72 67 69 76 65 self and forgive
00e0: 20 6f 74 68 65 72 73 2e 0a 2a 2a 20 20 20 20 4d others..** M
00f0: 61 79 20 79 6f 75 20 73 68 61 72 65 20 66 72 65 ay you share fre
0100: 65 6c 79 2c 20 6e 65 76 65 72 20 74 61 6b 69 6e ely, never takin
0110: 67 20 6d 6f 72 65 20 74 68 61 6e 20 79 6f 75 20 g more than you
0120: 67 69 76 65 2e 0a 2a 2a 0a 2a 2a 2a 2a 2a 2a 2a give..**.*******
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0160: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0170: 2a 2a 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 66 69 **.**.** This fi
0180: 6c 65 20 63 6f 6e 74 61 69 6e 73 20 6f 62 73 63 le contains obsc
0190: 75 72 65 20 74 65 73 74 73 20 6f 66 20 74 68 65 ure tests of the
01a0: 20 43 2d 69 6e 74 65 72 66 61 63 65 20 72 65 71 C-interface req
01b0: 75 69 72 65 64 0a 2a 2a 20 66 6f 72 20 63 6f 6d uired.** for com
01c0: 70 6c 65 74 65 6e 65 73 73 2e 20 54 65 73 74 20 pleteness. Test
01d0: 63 6f 64 65 20 69 73 20 77 72 69 74 74 65 6e 20 code is written
01e0: 69 6e 20 43 20 66 6f 72 20 74 68 65 73 65 20 63 in C for these c
01f0: 61 73 65 73 0a 2a 2a 20 61 73 20 74 68 65 72 65 ases.** as there
0200: 20 69 73 20 6e 6f 74 20 6d 75 63 68 20 70 6f 69 is not much poi
0210: 6e 74 20 69 6e 20 62 69 6e 64 69 6e 67 20 74 6f nt in binding to
0220: 20 54 63 6c 2e 0a 2a 2f 0a 23 69 6e 63 6c 75 64 Tcl..*/.#includ
0230: 65 20 22 73 71 6c 69 74 65 49 6e 74 2e 68 22 0a e "sqliteInt.h".
0240: 23 69 66 20 64 65 66 69 6e 65 64 28 49 4e 43 4c #if defined(INCL
0250: 55 44 45 5f 53 51 4c 49 54 45 5f 54 43 4c 5f 48 UDE_SQLITE_TCL_H
0260: 29 0a 23 20 20 69 6e 63 6c 75 64 65 20 22 73 71 ).# include "sq
0270: 6c 69 74 65 5f 74 63 6c 2e 68 22 0a 23 65 6c 73 lite_tcl.h".#els
0280: 65 0a 23 20 20 69 6e 63 6c 75 64 65 20 22 74 63 e.# include "tc
0290: 6c 2e 68 22 0a 23 65 6e 64 69 66 0a 23 69 6e 63 l.h".#endif.#inc
02a0: 6c 75 64 65 20 3c 73 74 64 6c 69 62 2e 68 3e 0a lude <stdlib.h>.
02b0: 23 69 6e 63 6c 75 64 65 20 3c 73 74 72 69 6e 67 #include <string
02c0: 2e 68 3e 0a 0a 2f 2a 0a 2a 2a 20 63 5f 63 6f 6c .h>../*.** c_col
02d0: 6c 61 74 69 6f 6e 5f 74 65 73 74 0a 2a 2f 0a 73 lation_test.*/.s
02e0: 74 61 74 69 63 20 69 6e 74 20 53 51 4c 49 54 45 tatic int SQLITE
02f0: 5f 54 43 4c 41 50 49 20 63 5f 63 6f 6c 6c 61 74 _TCLAPI c_collat
0300: 69 6f 6e 5f 74 65 73 74 28 0a 20 20 43 6c 69 65 ion_test(. Clie
0310: 6e 74 44 61 74 61 20 63 6c 69 65 6e 74 44 61 74 ntData clientDat
0320: 61 2c 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f a, /* Pointer to
0330: 20 73 71 6c 69 74 65 33 5f 65 6e 61 62 6c 65 5f sqlite3_enable_
0340: 58 58 58 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a XXX function */.
0350: 20 20 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e Tcl_Interp *in
0360: 74 65 72 70 2c 20 20 20 20 2f 2a 20 54 68 65 20 terp, /* The
0370: 54 43 4c 20 69 6e 74 65 72 70 72 65 74 65 72 20 TCL interpreter
0380: 74 68 61 74 20 69 6e 76 6f 6b 65 64 20 74 68 69 that invoked thi
0390: 73 20 63 6f 6d 6d 61 6e 64 20 2a 2f 0a 20 20 69 s command */. i
03a0: 6e 74 20 6f 62 6a 63 2c 20 20 20 20 20 20 20 20 nt objc,
03b0: 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
03c0: 6f 66 20 61 72 67 75 6d 65 6e 74 73 20 2a 2f 0a of arguments */.
03d0: 20 20 54 63 6c 5f 4f 62 6a 20 2a 43 4f 4e 53 54 Tcl_Obj *CONST
03e0: 20 6f 62 6a 76 5b 5d 20 20 2f 2a 20 43 6f 6d 6d objv[] /* Comm
03f0: 61 6e 64 20 61 72 67 75 6d 65 6e 74 73 20 2a 2f and arguments */
0400: 0a 29 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 .){. const char
0410: 20 2a 7a 45 72 72 46 75 6e 63 74 69 6f 6e 20 3d *zErrFunction =
0420: 20 22 4e 2f 41 22 3b 0a 20 20 73 71 6c 69 74 65 "N/A";. sqlite
0430: 33 20 2a 64 62 3b 0a 0a 20 20 69 6e 74 20 72 63 3 *db;.. int rc
0440: 3b 0a 20 20 69 66 28 20 6f 62 6a 63 21 3d 31 20 ;. if( objc!=1
0450: 29 7b 0a 20 20 20 20 54 63 6c 5f 57 72 6f 6e 67 ){. Tcl_Wrong
0460: 4e 75 6d 41 72 67 73 28 69 6e 74 65 72 70 2c 20 NumArgs(interp,
0470: 31 2c 20 6f 62 6a 76 2c 20 22 22 29 3b 0a 20 20 1, objv, "");.
0480: 20 20 72 65 74 75 72 6e 20 54 43 4c 5f 45 52 52 return TCL_ERR
0490: 4f 52 3b 0a 20 20 7d 0a 0a 20 20 2f 2a 20 4f 70 OR;. }.. /* Op
04a0: 65 6e 20 61 20 64 61 74 61 62 61 73 65 2e 20 2a en a database. *
04b0: 2f 0a 20 20 72 63 20 3d 20 73 71 6c 69 74 65 33 /. rc = sqlite3
04c0: 5f 6f 70 65 6e 28 22 3a 6d 65 6d 6f 72 79 3a 22 _open(":memory:"
04d0: 2c 20 26 64 62 29 3b 0a 20 20 69 66 28 20 72 63 , &db);. if( rc
04e0: 21 3d 53 51 4c 49 54 45 5f 4f 4b 20 29 7b 0a 20 !=SQLITE_OK ){.
04f0: 20 20 20 7a 45 72 72 46 75 6e 63 74 69 6f 6e 20 zErrFunction
0500: 3d 20 22 73 71 6c 69 74 65 33 5f 6f 70 65 6e 22 = "sqlite3_open"
0510: 3b 0a 20 20 20 20 67 6f 74 6f 20 65 72 72 6f 72 ;. goto error
0520: 5f 6f 75 74 3b 0a 20 20 7d 0a 0a 20 20 72 63 20 _out;. }.. rc
0530: 3d 20 73 71 6c 69 74 65 33 5f 63 72 65 61 74 65 = sqlite3_create
0540: 5f 63 6f 6c 6c 61 74 69 6f 6e 28 64 62 2c 20 22 _collation(db, "
0550: 63 6f 6c 6c 61 74 65 22 2c 20 34 35 36 2c 20 30 collate", 456, 0
0560: 2c 20 30 29 3b 0a 20 20 69 66 28 20 72 63 21 3d , 0);. if( rc!=
0570: 53 51 4c 49 54 45 5f 4d 49 53 55 53 45 20 29 7b SQLITE_MISUSE ){
0580: 0a 20 20 20 20 73 71 6c 69 74 65 33 5f 63 6c 6f . sqlite3_clo
0590: 73 65 28 64 62 29 3b 0a 20 20 20 20 7a 45 72 72 se(db);. zErr
05a0: 46 75 6e 63 74 69 6f 6e 20 3d 20 22 73 71 6c 69 Function = "sqli
05b0: 74 65 33 5f 63 72 65 61 74 65 5f 63 6f 6c 6c 61 te3_create_colla
05c0: 74 69 6f 6e 22 3b 0a 20 20 20 20 67 6f 74 6f 20 tion";. goto
05d0: 65 72 72 6f 72 5f 6f 75 74 3b 0a 20 20 7d 0a 0a error_out;. }..
05e0: 20 20 73 71 6c 69 74 65 33 5f 63 6c 6f 73 65 28 sqlite3_close(
05f0: 64 62 29 3b 0a 20 20 72 65 74 75 72 6e 20 54 43 db);. return TC
0600: 4c 5f 4f 4b 3b 0a 0a 65 72 72 6f 72 5f 6f 75 74 L_OK;..error_out
0610: 3a 0a 20 20 54 63 6c 5f 52 65 73 65 74 52 65 73 :. Tcl_ResetRes
0620: 75 6c 74 28 69 6e 74 65 72 70 29 3b 0a 20 20 54 ult(interp);. T
0630: 63 6c 5f 41 70 70 65 6e 64 52 65 73 75 6c 74 28 cl_AppendResult(
0640: 69 6e 74 65 72 70 2c 20 22 45 72 72 6f 72 20 74 interp, "Error t
0650: 65 73 74 69 6e 67 20 66 75 6e 63 74 69 6f 6e 3a esting function:
0660: 20 22 2c 20 7a 45 72 72 46 75 6e 63 74 69 6f 6e ", zErrFunction
0670: 2c 20 30 29 3b 0a 20 20 72 65 74 75 72 6e 20 54 , 0);. return T
0680: 43 4c 5f 45 52 52 4f 52 3b 0a 7d 0a 0a 2f 2a 0a CL_ERROR;.}../*.
0690: 2a 2a 20 63 5f 72 65 61 6c 6c 6f 63 5f 74 65 73 ** c_realloc_tes
06a0: 74 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 t.*/.static int
06b0: 53 51 4c 49 54 45 5f 54 43 4c 41 50 49 20 63 5f SQLITE_TCLAPI c_
06c0: 72 65 61 6c 6c 6f 63 5f 74 65 73 74 28 0a 20 20 realloc_test(.
06d0: 43 6c 69 65 6e 74 44 61 74 61 20 63 6c 69 65 6e ClientData clien
06e0: 74 44 61 74 61 2c 20 2f 2a 20 50 6f 69 6e 74 65 tData, /* Pointe
06f0: 72 20 74 6f 20 73 71 6c 69 74 65 33 5f 65 6e 61 r to sqlite3_ena
0700: 62 6c 65 5f 58 58 58 20 66 75 6e 63 74 69 6f 6e ble_XXX function
0710: 20 2a 2f 0a 20 20 54 63 6c 5f 49 6e 74 65 72 70 */. Tcl_Interp
0720: 20 2a 69 6e 74 65 72 70 2c 20 20 20 20 2f 2a 20 *interp, /*
0730: 54 68 65 20 54 43 4c 20 69 6e 74 65 72 70 72 65 The TCL interpre
0740: 74 65 72 20 74 68 61 74 20 69 6e 76 6f 6b 65 64 ter that invoked
0750: 20 74 68 69 73 20 63 6f 6d 6d 61 6e 64 20 2a 2f this command */
0760: 0a 20 20 69 6e 74 20 6f 62 6a 63 2c 20 20 20 20 . int objc,
0770: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
0780: 62 65 72 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 ber of arguments
0790: 20 2a 2f 0a 20 20 54 63 6c 5f 4f 62 6a 20 2a 43 */. Tcl_Obj *C
07a0: 4f 4e 53 54 20 6f 62 6a 76 5b 5d 20 20 2f 2a 20 ONST objv[] /*
07b0: 43 6f 6d 6d 61 6e 64 20 61 72 67 75 6d 65 6e 74 Command argument
07c0: 73 20 2a 2f 0a 29 7b 0a 20 20 76 6f 69 64 20 2a s */.){. void *
07d0: 70 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 p;. const char
07e0: 2a 7a 45 72 72 46 75 6e 63 74 69 6f 6e 20 3d 20 *zErrFunction =
07f0: 22 4e 2f 41 22 3b 0a 0a 20 20 69 66 28 20 6f 62 "N/A";.. if( ob
0800: 6a 63 21 3d 31 20 29 7b 0a 20 20 20 20 54 63 6c jc!=1 ){. Tcl
0810: 5f 57 72 6f 6e 67 4e 75 6d 41 72 67 73 28 69 6e _WrongNumArgs(in
0820: 74 65 72 70 2c 20 31 2c 20 6f 62 6a 76 2c 20 22 terp, 1, objv, "
0830: 22 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 54 ");. return T
0840: 43 4c 5f 45 52 52 4f 52 3b 0a 20 20 7d 0a 0a 20 CL_ERROR;. }..
0850: 20 70 20 3d 20 73 71 6c 69 74 65 33 5f 6d 61 6c p = sqlite3_mal
0860: 6c 6f 63 28 35 29 3b 0a 20 20 69 66 28 20 21 70 loc(5);. if( !p
0870: 20 29 7b 0a 20 20 20 20 7a 45 72 72 46 75 6e 63 ){. zErrFunc
0880: 74 69 6f 6e 20 3d 20 22 73 71 6c 69 74 65 33 5f tion = "sqlite3_
0890: 6d 61 6c 6c 6f 63 22 3b 0a 20 20 20 20 67 6f 74 malloc";. got
08a0: 6f 20 65 72 72 6f 72 5f 6f 75 74 3b 0a 20 20 7d o error_out;. }
08b0: 0a 0a 20 20 2f 2a 20 54 65 73 74 20 74 68 61 74 .. /* Test that
08c0: 20 72 65 61 6c 6c 6f 63 28 29 69 6e 67 20 61 20 realloc()ing a
08d0: 62 6c 6f 63 6b 20 6f 66 20 6d 65 6d 6f 72 79 20 block of memory
08e0: 74 6f 20 61 20 6e 65 67 61 74 69 76 65 20 73 69 to a negative si
08f0: 7a 65 20 69 73 0a 20 20 2a 2a 20 74 68 65 20 73 ze is. ** the s
0900: 61 6d 65 20 61 73 20 66 72 65 65 28 29 69 6e 67 ame as free()ing
0910: 20 74 68 61 74 20 6d 65 6d 6f 72 79 2e 0a 20 20 that memory..
0920: 2a 2f 0a 20 20 70 20 3d 20 73 71 6c 69 74 65 33 */. p = sqlite3
0930: 5f 72 65 61 6c 6c 6f 63 28 70 2c 20 2d 31 29 3b _realloc(p, -1);
0940: 0a 20 20 69 66 28 20 70 20 29 7b 0a 20 20 20 20 . if( p ){.
0950: 7a 45 72 72 46 75 6e 63 74 69 6f 6e 20 3d 20 22 zErrFunction = "
0960: 73 71 6c 69 74 65 33 5f 72 65 61 6c 6c 6f 63 22 sqlite3_realloc"
0970: 3b 0a 20 20 20 20 67 6f 74 6f 20 65 72 72 6f 72 ;. goto error
0980: 5f 6f 75 74 3b 0a 20 20 7d 0a 0a 20 20 72 65 74 _out;. }.. ret
0990: 75 72 6e 20 54 43 4c 5f 4f 4b 3b 0a 0a 65 72 72 urn TCL_OK;..err
09a0: 6f 72 5f 6f 75 74 3a 0a 20 20 54 63 6c 5f 52 65 or_out:. Tcl_Re
09b0: 73 65 74 52 65 73 75 6c 74 28 69 6e 74 65 72 70 setResult(interp
09c0: 29 3b 0a 20 20 54 63 6c 5f 41 70 70 65 6e 64 52 );. Tcl_AppendR
09d0: 65 73 75 6c 74 28 69 6e 74 65 72 70 2c 20 22 45 esult(interp, "E
09e0: 72 72 6f 72 20 74 65 73 74 69 6e 67 20 66 75 6e rror testing fun
09f0: 63 74 69 6f 6e 3a 20 22 2c 20 7a 45 72 72 46 75 ction: ", zErrFu
0a00: 6e 63 74 69 6f 6e 2c 20 30 29 3b 0a 20 20 72 65 nction, 0);. re
0a10: 74 75 72 6e 20 54 43 4c 5f 45 52 52 4f 52 3b 0a turn TCL_ERROR;.
0a20: 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 63 5f 6d 69 73 75 }.../*.** c_misu
0a30: 73 65 5f 74 65 73 74 0a 2a 2f 0a 73 74 61 74 69 se_test.*/.stati
0a40: 63 20 69 6e 74 20 53 51 4c 49 54 45 5f 54 43 4c c int SQLITE_TCL
0a50: 41 50 49 20 63 5f 6d 69 73 75 73 65 5f 74 65 73 API c_misuse_tes
0a60: 74 28 0a 20 20 43 6c 69 65 6e 74 44 61 74 61 20 t(. ClientData
0a70: 63 6c 69 65 6e 74 44 61 74 61 2c 20 2f 2a 20 50 clientData, /* P
0a80: 6f 69 6e 74 65 72 20 74 6f 20 73 71 6c 69 74 65 ointer to sqlite
0a90: 33 5f 65 6e 61 62 6c 65 5f 58 58 58 20 66 75 6e 3_enable_XXX fun
0aa0: 63 74 69 6f 6e 20 2a 2f 0a 20 20 54 63 6c 5f 49 ction */. Tcl_I
0ab0: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 20 nterp *interp,
0ac0: 20 20 2f 2a 20 54 68 65 20 54 43 4c 20 69 6e 74 /* The TCL int
0ad0: 65 72 70 72 65 74 65 72 20 74 68 61 74 20 69 6e erpreter that in
0ae0: 76 6f 6b 65 64 20 74 68 69 73 20 63 6f 6d 6d 61 voked this comma
0af0: 6e 64 20 2a 2f 0a 20 20 69 6e 74 20 6f 62 6a 63 nd */. int objc
0b00: 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f , /
0b10: 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 72 67 75 * Number of argu
0b20: 6d 65 6e 74 73 20 2a 2f 0a 20 20 54 63 6c 5f 4f ments */. Tcl_O
0b30: 62 6a 20 2a 43 4f 4e 53 54 20 6f 62 6a 76 5b 5d bj *CONST objv[]
0b40: 20 20 2f 2a 20 43 6f 6d 6d 61 6e 64 20 61 72 67 /* Command arg
0b50: 75 6d 65 6e 74 73 20 2a 2f 0a 29 7b 0a 20 20 63 uments */.){. c
0b60: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 45 72 72 46 onst char *zErrF
0b70: 75 6e 63 74 69 6f 6e 20 3d 20 22 4e 2f 41 22 3b unction = "N/A";
0b80: 0a 20 20 73 71 6c 69 74 65 33 20 2a 64 62 20 3d . sqlite3 *db =
0b90: 20 30 3b 0a 20 20 73 71 6c 69 74 65 33 5f 73 74 0;. sqlite3_st
0ba0: 6d 74 20 2a 70 53 74 6d 74 3b 0a 20 20 69 6e 74 mt *pStmt;. int
0bb0: 20 72 63 3b 0a 0a 20 20 69 66 28 20 6f 62 6a 63 rc;.. if( objc
0bc0: 21 3d 31 20 29 7b 0a 20 20 20 20 54 63 6c 5f 57 !=1 ){. Tcl_W
0bd0: 72 6f 6e 67 4e 75 6d 41 72 67 73 28 69 6e 74 65 rongNumArgs(inte
0be0: 72 70 2c 20 31 2c 20 6f 62 6a 76 2c 20 22 22 29 rp, 1, objv, "")
0bf0: 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 54 43 4c ;. return TCL
0c00: 5f 45 52 52 4f 52 3b 0a 20 20 7d 0a 0a 20 20 2f _ERROR;. }.. /
0c10: 2a 20 4f 70 65 6e 20 61 20 64 61 74 61 62 61 73 * Open a databas
0c20: 65 2e 20 54 68 65 6e 20 63 6c 6f 73 65 20 69 74 e. Then close it
0c30: 20 61 67 61 69 6e 2e 20 57 65 20 6e 65 65 64 20 again. We need
0c40: 74 6f 20 64 6f 20 74 68 69 73 20 73 6f 20 74 68 to do this so th
0c50: 61 74 0a 20 20 2a 2a 20 77 65 20 68 61 76 65 20 at. ** we have
0c60: 61 20 22 63 6c 6f 73 65 64 20 64 61 74 61 62 61 a "closed databa
0c70: 73 65 20 68 61 6e 64 6c 65 22 20 74 6f 20 70 61 se handle" to pa
0c80: 73 73 20 74 6f 20 76 61 72 69 6f 75 73 20 41 50 ss to various AP
0c90: 49 20 66 75 6e 63 74 69 6f 6e 73 2e 0a 20 20 2a I functions.. *
0ca0: 2f 0a 20 20 72 63 20 3d 20 73 71 6c 69 74 65 33 /. rc = sqlite3
0cb0: 5f 6f 70 65 6e 28 22 3a 6d 65 6d 6f 72 79 3a 22 _open(":memory:"
0cc0: 2c 20 26 64 62 29 3b 0a 20 20 69 66 28 20 72 63 , &db);. if( rc
0cd0: 21 3d 53 51 4c 49 54 45 5f 4f 4b 20 29 7b 0a 20 !=SQLITE_OK ){.
0ce0: 20 20 20 7a 45 72 72 46 75 6e 63 74 69 6f 6e 20 zErrFunction
0cf0: 3d 20 22 73 71 6c 69 74 65 33 5f 6f 70 65 6e 22 = "sqlite3_open"
0d00: 3b 0a 20 20 20 20 67 6f 74 6f 20 65 72 72 6f 72 ;. goto error
0d10: 5f 6f 75 74 3b 0a 20 20 7d 0a 20 20 73 71 6c 69 _out;. }. sqli
0d20: 74 65 33 5f 63 6c 6f 73 65 28 64 62 29 3b 0a 0a te3_close(db);..
0d30: 0a 20 20 72 63 20 3d 20 73 71 6c 69 74 65 33 5f . rc = sqlite3_
0d40: 65 72 72 63 6f 64 65 28 64 62 29 3b 0a 20 20 69 errcode(db);. i
0d50: 66 28 20 72 63 21 3d 53 51 4c 49 54 45 5f 4d 49 f( rc!=SQLITE_MI
0d60: 53 55 53 45 20 29 7b 0a 20 20 20 20 7a 45 72 72 SUSE ){. zErr
0d70: 46 75 6e 63 74 69 6f 6e 20 3d 20 22 73 71 6c 69 Function = "sqli
0d80: 74 65 33 5f 65 72 72 63 6f 64 65 22 3b 0a 20 20 te3_errcode";.
0d90: 20 20 67 6f 74 6f 20 65 72 72 6f 72 5f 6f 75 74 goto error_out
0da0: 3b 0a 20 20 7d 0a 0a 20 20 70 53 74 6d 74 20 3d ;. }.. pStmt =
0db0: 20 28 73 71 6c 69 74 65 33 5f 73 74 6d 74 2a 29 (sqlite3_stmt*)
0dc0: 31 32 33 34 3b 0a 20 20 72 63 20 3d 20 73 71 6c 1234;. rc = sql
0dd0: 69 74 65 33 5f 70 72 65 70 61 72 65 28 64 62 2c ite3_prepare(db,
0de0: 20 30 2c 20 30 2c 20 26 70 53 74 6d 74 2c 20 30 0, 0, &pStmt, 0
0df0: 29 3b 0a 20 20 69 66 28 20 72 63 21 3d 53 51 4c );. if( rc!=SQL
0e00: 49 54 45 5f 4d 49 53 55 53 45 20 29 7b 0a 20 20 ITE_MISUSE ){.
0e10: 20 20 7a 45 72 72 46 75 6e 63 74 69 6f 6e 20 3d zErrFunction =
0e20: 20 22 73 71 6c 69 74 65 33 5f 70 72 65 70 61 72 "sqlite3_prepar
0e30: 65 22 3b 0a 20 20 20 20 67 6f 74 6f 20 65 72 72 e";. goto err
0e40: 6f 72 5f 6f 75 74 3b 0a 20 20 7d 0a 20 20 61 73 or_out;. }. as
0e50: 73 65 72 74 28 20 70 53 74 6d 74 3d 3d 30 20 29 sert( pStmt==0 )
0e60: 3b 20 2f 2a 20 56 65 72 69 66 79 20 74 68 61 74 ; /* Verify that
0e70: 20 70 53 74 6d 74 20 69 73 20 7a 65 72 6f 65 64 pStmt is zeroed
0e80: 20 65 76 65 6e 20 6f 6e 20 61 20 4d 49 53 55 53 even on a MISUS
0e90: 45 20 65 72 72 6f 72 20 2a 2f 0a 0a 20 20 70 53 E error */.. pS
0ea0: 74 6d 74 20 3d 20 28 73 71 6c 69 74 65 33 5f 73 tmt = (sqlite3_s
0eb0: 74 6d 74 2a 29 31 32 33 34 3b 0a 20 20 72 63 20 tmt*)1234;. rc
0ec0: 3d 20 73 71 6c 69 74 65 33 5f 70 72 65 70 61 72 = sqlite3_prepar
0ed0: 65 5f 76 32 28 64 62 2c 20 30 2c 20 30 2c 20 26 e_v2(db, 0, 0, &
0ee0: 70 53 74 6d 74 2c 20 30 29 3b 0a 20 20 69 66 28 pStmt, 0);. if(
0ef0: 20 72 63 21 3d 53 51 4c 49 54 45 5f 4d 49 53 55 rc!=SQLITE_MISU
0f00: 53 45 20 29 7b 0a 20 20 20 20 7a 45 72 72 46 75 SE ){. zErrFu
0f10: 6e 63 74 69 6f 6e 20 3d 20 22 73 71 6c 69 74 65 nction = "sqlite
0f20: 33 5f 70 72 65 70 61 72 65 5f 76 32 22 3b 0a 20 3_prepare_v2";.
0f30: 20 20 20 67 6f 74 6f 20 65 72 72 6f 72 5f 6f 75 goto error_ou
0f40: 74 3b 0a 20 20 7d 0a 20 20 61 73 73 65 72 74 28 t;. }. assert(
0f50: 20 70 53 74 6d 74 3d 3d 30 20 29 3b 0a 0a 23 69 pStmt==0 );..#i
0f60: 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
0f70: 54 5f 55 54 46 31 36 0a 20 20 70 53 74 6d 74 20 T_UTF16. pStmt
0f80: 3d 20 28 73 71 6c 69 74 65 33 5f 73 74 6d 74 2a = (sqlite3_stmt*
0f90: 29 31 32 33 34 3b 0a 20 20 72 63 20 3d 20 73 71 )1234;. rc = sq
0fa0: 6c 69 74 65 33 5f 70 72 65 70 61 72 65 31 36 28 lite3_prepare16(
0fb0: 64 62 2c 20 30 2c 20 30 2c 20 26 70 53 74 6d 74 db, 0, 0, &pStmt
0fc0: 2c 20 30 29 3b 0a 20 20 69 66 28 20 72 63 21 3d , 0);. if( rc!=
0fd0: 53 51 4c 49 54 45 5f 4d 49 53 55 53 45 20 29 7b SQLITE_MISUSE ){
0fe0: 0a 20 20 20 20 7a 45 72 72 46 75 6e 63 74 69 6f . zErrFunctio
0ff0: 6e 20 3d 20 22 73 71 6c 69 74 65 33 5f 70 72 65 n = "sqlite3_pre
1000: 70 61 72 65 31 36 22 3b 0a 20 20 20 20 67 6f 74 pare16";. got
1010: 6f 20 65 72 72 6f 72 5f 6f 75 74 3b 0a 20 20 7d o error_out;. }
1020: 0a 20 20 61 73 73 65 72 74 28 20 70 53 74 6d 74 . assert( pStmt
1030: 3d 3d 30 20 29 3b 0a 20 20 70 53 74 6d 74 20 3d ==0 );. pStmt =
1040: 20 28 73 71 6c 69 74 65 33 5f 73 74 6d 74 2a 29 (sqlite3_stmt*)
1050: 31 32 33 34 3b 0a 20 20 72 63 20 3d 20 73 71 6c 1234;. rc = sql
1060: 69 74 65 33 5f 70 72 65 70 61 72 65 31 36 5f 76 ite3_prepare16_v
1070: 32 28 64 62 2c 20 30 2c 20 30 2c 20 26 70 53 74 2(db, 0, 0, &pSt
1080: 6d 74 2c 20 30 29 3b 0a 20 20 69 66 28 20 72 63 mt, 0);. if( rc
1090: 21 3d 53 51 4c 49 54 45 5f 4d 49 53 55 53 45 20 !=SQLITE_MISUSE
10a0: 29 7b 0a 20 20 20 20 7a 45 72 72 46 75 6e 63 74 ){. zErrFunct
10b0: 69 6f 6e 20 3d 20 22 73 71 6c 69 74 65 33 5f 70 ion = "sqlite3_p
10c0: 72 65 70 61 72 65 31 36 5f 76 32 22 3b 0a 20 20 repare16_v2";.
10d0: 20 20 67 6f 74 6f 20 65 72 72 6f 72 5f 6f 75 74 goto error_out
10e0: 3b 0a 20 20 7d 0a 20 20 61 73 73 65 72 74 28 20 ;. }. assert(
10f0: 70 53 74 6d 74 3d 3d 30 20 29 3b 0a 23 65 6e 64 pStmt==0 );.#end
1100: 69 66 0a 0a 20 20 72 65 74 75 72 6e 20 54 43 4c if.. return TCL
1110: 5f 4f 4b 3b 0a 0a 65 72 72 6f 72 5f 6f 75 74 3a _OK;..error_out:
1120: 0a 20 20 54 63 6c 5f 52 65 73 65 74 52 65 73 75 . Tcl_ResetResu
1130: 6c 74 28 69 6e 74 65 72 70 29 3b 0a 20 20 54 63 lt(interp);. Tc
1140: 6c 5f 41 70 70 65 6e 64 52 65 73 75 6c 74 28 69 l_AppendResult(i
1150: 6e 74 65 72 70 2c 20 22 45 72 72 6f 72 20 74 65 nterp, "Error te
1160: 73 74 69 6e 67 20 66 75 6e 63 74 69 6f 6e 3a 20 sting function:
1170: 22 2c 20 7a 45 72 72 46 75 6e 63 74 69 6f 6e 2c ", zErrFunction,
1180: 20 30 29 3b 0a 20 20 72 65 74 75 72 6e 20 54 43 0);. return TC
1190: 4c 5f 45 52 52 4f 52 3b 0a 7d 0a 0a 2f 2a 0a 2a L_ERROR;.}../*.*
11a0: 2a 20 52 65 67 69 73 74 65 72 20 63 6f 6d 6d 61 * Register comma
11b0: 6e 64 73 20 77 69 74 68 20 74 68 65 20 54 43 4c nds with the TCL
11c0: 20 69 6e 74 65 72 70 72 65 74 65 72 2e 0a 2a 2f interpreter..*/
11d0: 0a 69 6e 74 20 53 71 6c 69 74 65 74 65 73 74 39 .int Sqlitetest9
11e0: 5f 49 6e 69 74 28 54 63 6c 5f 49 6e 74 65 72 70 _Init(Tcl_Interp
11f0: 20 2a 69 6e 74 65 72 70 29 7b 0a 20 20 73 74 61 *interp){. sta
1200: 74 69 63 20 73 74 72 75 63 74 20 7b 0a 20 20 20 tic struct {.
1210: 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 0a 20 char *zName;.
1220: 20 20 20 20 54 63 6c 5f 4f 62 6a 43 6d 64 50 72 Tcl_ObjCmdPr
1230: 6f 63 20 2a 78 50 72 6f 63 3b 0a 20 20 20 20 20 oc *xProc;.
1240: 76 6f 69 64 20 2a 63 6c 69 65 6e 74 44 61 74 61 void *clientData
1250: 3b 0a 20 20 7d 20 61 4f 62 6a 43 6d 64 5b 5d 20 ;. } aObjCmd[]
1260: 3d 20 7b 0a 20 20 20 20 20 7b 20 22 63 5f 6d 69 = {. { "c_mi
1270: 73 75 73 65 5f 74 65 73 74 22 2c 20 20 20 20 63 suse_test", c
1280: 5f 6d 69 73 75 73 65 5f 74 65 73 74 2c 20 30 20 _misuse_test, 0
1290: 7d 2c 0a 20 20 20 20 20 7b 20 22 63 5f 72 65 61 },. { "c_rea
12a0: 6c 6c 6f 63 5f 74 65 73 74 22 2c 20 20 20 63 5f lloc_test", c_
12b0: 72 65 61 6c 6c 6f 63 5f 74 65 73 74 2c 20 30 20 realloc_test, 0
12c0: 7d 2c 0a 20 20 20 20 20 7b 20 22 63 5f 63 6f 6c },. { "c_col
12d0: 6c 61 74 69 6f 6e 5f 74 65 73 74 22 2c 20 63 5f lation_test", c_
12e0: 63 6f 6c 6c 61 74 69 6f 6e 5f 74 65 73 74 2c 20 collation_test,
12f0: 30 20 7d 2c 0a 20 20 7d 3b 0a 20 20 69 6e 74 20 0 },. };. int
1300: 69 3b 0a 20 20 66 6f 72 28 69 3d 30 3b 20 69 3c i;. for(i=0; i<
1310: 73 69 7a 65 6f 66 28 61 4f 62 6a 43 6d 64 29 2f sizeof(aObjCmd)/
1320: 73 69 7a 65 6f 66 28 61 4f 62 6a 43 6d 64 5b 30 sizeof(aObjCmd[0
1330: 5d 29 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 54 63 ]); i++){. Tc
1340: 6c 5f 43 72 65 61 74 65 4f 62 6a 43 6f 6d 6d 61 l_CreateObjComma
1350: 6e 64 28 69 6e 74 65 72 70 2c 20 61 4f 62 6a 43 nd(interp, aObjC
1360: 6d 64 5b 69 5d 2e 7a 4e 61 6d 65 2c 20 0a 20 20 md[i].zName, .
1370: 20 20 20 20 20 20 61 4f 62 6a 43 6d 64 5b 69 5d aObjCmd[i]
1380: 2e 78 50 72 6f 63 2c 20 61 4f 62 6a 43 6d 64 5b .xProc, aObjCmd[
1390: 69 5d 2e 63 6c 69 65 6e 74 44 61 74 61 2c 20 30 i].clientData, 0
13a0: 29 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 );. }. return
13b0: 54 43 4c 5f 4f 4b 3b 0a 7d 0a TCL_OK;.}.