1 #ifdef USE_SYSTEM_SQLITE 37 #if defined(INCLUDE_MSVC_H) 41 #if defined(INCLUDE_SQLITE_TCL_H) 42 # include "sqlite_tcl.h" 45 # ifndef SQLITE_TCLAPI 46 # define SQLITE_TCLAPI 55 #ifndef SQLITE_AMALGAMATION 60 typedef unsigned char u8;
67 # define GETPID getpid 68 #elif !defined(_WIN32_WCE) 69 # ifndef SQLITE_AMALGAMATION 70 # define WIN32_LEAN_AND_MEAN 73 # define GETPID (int)GetCurrentProcessId 81 #undef TCL_STORAGE_CLASS 82 #define TCL_STORAGE_CLASS DLLEXPORT 85 #define NUM_PREPARED_STMTS 10 86 #define MAX_PREPARED_STMTS 100 191 while( *z2 ){ z2++; }
192 return 0x3fffffff & (int)(z2 - z);
196 #ifndef SQLITE_OMIT_INCRBLOB 220 ClientData instanceData,
252 ClientData instanceData,
263 if( (p->
iSeek+nRead)>nBlob ){
264 nRead = nBlob-p->
iSeek;
284 ClientData instanceData,
290 int nWrite = toWrite;
295 if( (p->
iSeek+nWrite)>nBlob ){
296 *errorCodePtr = EINVAL;
317 ClientData instanceData,
335 default: assert(!
"Bad seekMode");
343 ClientData instanceData,
349 ClientData instanceData,
358 TCL_CHANNEL_VERSION_2,
390 int flags = TCL_READABLE|(isReadonly ? 0 : TCL_WRITABLE);
393 static int count = 0;
408 Tcl_RegisterChannel(interp, p->
channel);
419 Tcl_SetResult(interp, (
char *)Tcl_GetChannelName(p->
channel), TCL_VOLATILE);
423 #define closeIncrblobChannels(pDb) 445 z = Tcl_GetStringFromObj(pCmd, &n);
448 if( c==
'$' || c==
'[' || c==
';' )
return 0;
461 pNew = (
SqlFunc*)Tcl_Alloc(
sizeof(*pNew) + nName + 1 );
462 pNew->
zName = (
char*)&pNew[1];
463 memcpy(pNew->
zName, zName, nName+1);
466 Tcl_Free((
char*)pNew);
484 Tcl_Free((
char *)pStmt->
zSql);
488 Tcl_Free((
char *)pStmt);
498 for(pPreStmt = pDb->
stmtList; pPreStmt; pPreStmt=pNext){
499 pNext = pPreStmt->
pNext;
519 assert( pFunc->
pDb==pDb );
520 Tcl_DecrRefCount(pFunc->
pScript);
521 Tcl_Free((
char*)pFunc);
526 Tcl_Free((
char*)pCollate);
529 Tcl_Free(pDb->
zBusy);
541 Tcl_Free(pDb->
zAuth);
544 Tcl_Free(pDb->
zNull);
561 Tcl_Free((
char*)pDb);
574 rc = Tcl_VarEval(pDb->
interp, pDb->
zBusy,
" ", zVal, (
char*)0);
575 if( rc!=TCL_OK || atoi(Tcl_GetStringResult(pDb->
interp)) ){
581 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK 591 if( rc!=TCL_OK || atoi(Tcl_GetStringResult(pDb->
interp)) ){
598 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT) && \ 599 !defined(SQLITE_OMIT_DEPRECATED) 608 Tcl_DStringInit(&str);
609 Tcl_DStringAppend(&str, pDb->
zTrace, -1);
610 Tcl_DStringAppendElement(&str, zSql);
611 Tcl_Eval(pDb->
interp, Tcl_DStringValue(&str));
612 Tcl_DStringFree(&str);
613 Tcl_ResetResult(pDb->
interp);
617 #ifndef SQLITE_OMIT_TRACE 636 char *zSql = (
char *)xd;
638 pCmd = Tcl_NewStringObj(pDb->
zTraceV2, -1);
639 Tcl_IncrRefCount(pCmd);
640 Tcl_ListObjAppendElement(pDb->
interp, pCmd,
641 Tcl_NewWideIntObj((Tcl_WideInt)pStmt));
642 Tcl_ListObjAppendElement(pDb->
interp, pCmd,
643 Tcl_NewStringObj(zSql, -1));
644 Tcl_EvalObjEx(pDb->
interp, pCmd, TCL_EVAL_DIRECT);
645 Tcl_DecrRefCount(pCmd);
646 Tcl_ResetResult(pDb->
interp);
653 pCmd = Tcl_NewStringObj(pDb->
zTraceV2, -1);
654 Tcl_IncrRefCount(pCmd);
655 Tcl_ListObjAppendElement(pDb->
interp, pCmd,
656 Tcl_NewWideIntObj((Tcl_WideInt)pStmt));
657 Tcl_ListObjAppendElement(pDb->
interp, pCmd,
658 Tcl_NewWideIntObj((Tcl_WideInt)ns));
659 Tcl_EvalObjEx(pDb->
interp, pCmd, TCL_EVAL_DIRECT);
660 Tcl_DecrRefCount(pCmd);
661 Tcl_ResetResult(pDb->
interp);
667 pCmd = Tcl_NewStringObj(pDb->
zTraceV2, -1);
668 Tcl_IncrRefCount(pCmd);
669 Tcl_ListObjAppendElement(pDb->
interp, pCmd,
670 Tcl_NewWideIntObj((Tcl_WideInt)pStmt));
671 Tcl_EvalObjEx(pDb->
interp, pCmd, TCL_EVAL_DIRECT);
672 Tcl_DecrRefCount(pCmd);
673 Tcl_ResetResult(pDb->
interp);
679 pCmd = Tcl_NewStringObj(pDb->
zTraceV2, -1);
680 Tcl_IncrRefCount(pCmd);
681 Tcl_ListObjAppendElement(pDb->
interp, pCmd,
682 Tcl_NewWideIntObj((Tcl_WideInt)db));
683 Tcl_EvalObjEx(pDb->
interp, pCmd, TCL_EVAL_DIRECT);
684 Tcl_DecrRefCount(pCmd);
685 Tcl_ResetResult(pDb->
interp);
693 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT) && \ 694 !defined(SQLITE_OMIT_DEPRECATED) 705 Tcl_DStringInit(&str);
706 Tcl_DStringAppend(&str, pDb->
zProfile, -1);
707 Tcl_DStringAppendElement(&str, zSql);
708 Tcl_DStringAppendElement(&str, zTm);
709 Tcl_Eval(pDb->
interp, Tcl_DStringValue(&str));
710 Tcl_DStringFree(&str);
711 Tcl_ResetResult(pDb->
interp);
726 if( rc!=TCL_OK || atoi(Tcl_GetStringResult(pDb->
interp)) ){
736 Tcl_BackgroundError(pDb->
interp);
755 assert( db==pDb->
db );
756 p = Tcl_DuplicateObj(pDb->
pWalHook);
758 Tcl_ListObjAppendElement(interp, p, Tcl_NewStringObj(zDb, -1));
759 Tcl_ListObjAppendElement(interp, p, Tcl_NewIntObj(nEntry));
760 if( TCL_OK!=Tcl_EvalObjEx(interp, p, 0)
761 || TCL_OK!=Tcl_GetIntFromObj(interp, Tcl_GetObjResult(interp), &ret)
763 Tcl_BackgroundError(interp);
770 #if defined(SQLITE_TEST) && defined(SQLITE_ENABLE_UNLOCK_NOTIFY) 774 Tcl_SetVar(
interp,
"sqlite_unlock_notify_arg", zBuf, TCL_GLOBAL_ONLY);
776 Tcl_SetVar(
interp,
"sqlite_unlock_notify_argcount", zBuf, TCL_GLOBAL_ONLY);
779 # define setTestUnlockNotifyVars(x,y,z) 782 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY 783 static void DbUnlockNotify(
void **apArg,
int nArg){
785 for(i=0; i<nArg; i++){
786 const int flags = (TCL_EVAL_GLOBAL|TCL_EVAL_DIRECT);
797 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK 801 static void DbPreUpdateHandler(
812 static const char *azStr[] = {
"DELETE",
"INSERT",
"UPDATE"};
818 assert( db==pDb->
db );
822 Tcl_IncrRefCount(pCmd);
823 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(azStr[(op-1)/9], -1));
824 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(zDb, -1));
825 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(zTbl, -1));
826 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewWideIntObj(iKey1));
827 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewWideIntObj(iKey2));
828 Tcl_EvalObjEx(pDb->
interp, pCmd, TCL_EVAL_DIRECT);
829 Tcl_DecrRefCount(pCmd);
842 static const char *azStr[] = {
"DELETE",
"INSERT",
"UPDATE"};
852 Tcl_IncrRefCount(pCmd);
853 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(azStr[(op-1)/9], -1));
854 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(zDb, -1));
855 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(zTbl, -1));
856 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewWideIntObj(rowid));
857 Tcl_EvalObjEx(pDb->
interp, pCmd, TCL_EVAL_DIRECT);
858 Tcl_DecrRefCount(pCmd);
869 Tcl_IncrRefCount(pScript);
870 Tcl_ListObjAppendElement(0, pScript, Tcl_NewStringObj(zName, -1));
871 Tcl_EvalObjEx(pDb->
interp, pScript, 0);
872 Tcl_DecrRefCount(pScript);
889 pCmd = Tcl_NewStringObj(p->
zScript, -1);
890 Tcl_IncrRefCount(pCmd);
891 Tcl_ListObjAppendElement(p->
interp, pCmd, Tcl_NewStringObj(zA, nA));
892 Tcl_ListObjAppendElement(p->
interp, pCmd, Tcl_NewStringObj(zB, nB));
893 Tcl_EvalObjEx(p->
interp, pCmd, TCL_EVAL_DIRECT);
894 Tcl_DecrRefCount(pCmd);
895 return (atoi(Tcl_GetStringResult(p->
interp)));
914 Tcl_IncrRefCount(pCmd);
915 rc = Tcl_EvalObjEx(p->
interp, pCmd, 0);
916 Tcl_DecrRefCount(pCmd);
929 if( Tcl_ListObjGetElements(p->
interp, p->
pScript, &nArg, &aArg) ){
933 pCmd = Tcl_NewListObj(nArg, aArg);
934 Tcl_IncrRefCount(pCmd);
935 for(i=0; i<argc; i++){
948 if( v>=-2147483647 && v<=2147483647 ){
949 pVal = Tcl_NewIntObj((
int)v);
951 pVal = Tcl_NewWideIntObj(v);
957 pVal = Tcl_NewDoubleObj(r);
961 pVal = Tcl_NewStringObj(p->
pDb->
zNull, -1);
970 rc = Tcl_ListObjAppendElement(p->
interp, pCmd, pVal);
972 Tcl_DecrRefCount(pCmd);
983 rc = Tcl_EvalObjEx(p->
interp, pCmd, TCL_EVAL_DIRECT);
984 Tcl_DecrRefCount(pCmd);
987 if( rc && rc!=TCL_RETURN ){
990 Tcl_Obj *pVar = Tcl_GetObjResult(p->
interp);
993 const char *zType = (pVar->typePtr ? pVar->typePtr->name :
"");
995 if( c==
'b' && strcmp(zType,
"bytearray")==0 && pVar->bytes==0 ){
998 data = Tcl_GetByteArrayFromObj(pVar, &n);
1000 }
else if( c==
'b' && strcmp(zType,
"boolean")==0 ){
1001 Tcl_GetIntFromObj(0, pVar, &n);
1003 }
else if( c==
'd' && strcmp(zType,
"double")==0 ){
1005 Tcl_GetDoubleFromObj(0, pVar, &r);
1007 }
else if( (c==
'w' && strcmp(zType,
"wideInt")==0) ||
1008 (c==
'i' && strcmp(zType,
"int")==0) ){
1010 Tcl_GetWideIntFromObj(0, pVar, &v);
1013 data = (
unsigned char *)Tcl_GetStringFromObj(pVar, &n);
1019 #ifndef SQLITE_OMIT_AUTHORIZATION 1033 #ifdef SQLITE_USER_AUTHENTICATION
1079 default : zCode=
"????";
break;
1081 Tcl_DStringInit(&str);
1082 Tcl_DStringAppend(&str, pDb->
zAuth, -1);
1083 Tcl_DStringAppendElement(&str, zCode);
1084 Tcl_DStringAppendElement(&str, zArg1 ? zArg1 :
"");
1085 Tcl_DStringAppendElement(&str, zArg2 ? zArg2 :
"");
1086 Tcl_DStringAppendElement(&str, zArg3 ? zArg3 :
"");
1087 Tcl_DStringAppendElement(&str, zArg4 ? zArg4 :
"");
1088 #ifdef SQLITE_USER_AUTHENTICATION 1089 Tcl_DStringAppendElement(&str, zArg5 ? zArg5 :
"");
1091 rc = Tcl_GlobalEval(pDb->
interp, Tcl_DStringValue(&str));
1092 Tcl_DStringFree(&str);
1093 zReply = rc==TCL_OK ? Tcl_GetStringResult(pDb->
interp) :
"SQLITE_DENY";
1094 if( strcmp(zReply,
"SQLITE_OK")==0 ){
1096 }
else if( strcmp(zReply,
"SQLITE_DENY")==0 ){
1098 }
else if( strcmp(zReply,
"SQLITE_IGNORE")==0 ){
1124 zLine = malloc( nLine );
1125 if( zLine==0 )
return 0;
1129 nLine = nLine*2 + 100;
1130 zLine = realloc(zLine, nLine);
1131 if( zLine==0 )
return 0;
1133 if( fgets(&zLine[n], nLine - n, in)==0 ){
1141 while( zLine[n] ){ n++; }
1142 if( n>0 && zLine[n-1]==
'\n' ){
1148 zLine = realloc( zLine, n+1 );
1166 static const char *
const azEnd[] = {
1167 "RELEASE _tcl_transaction",
1169 "ROLLBACK TO _tcl_transaction ; RELEASE _tcl_transaction",
1177 zEnd = azEnd[(rc==TCL_ERROR)*2 + (pDb->
nTransaction==0)];
1191 if( rc!=TCL_ERROR ){
1216 if( pDb->bLegacyPrepare ){
1244 const char *zSql = zIn;
1257 while( (c = zSql[0])==
' ' || c==
'\t' || c==
'\r' || c==
'\n' ){ zSql++; }
1260 for(pPreStmt = pDb->
stmtList; pPreStmt; pPreStmt=pPreStmt->
pNext){
1261 int n = pPreStmt->
nSql;
1263 && memcmp(pPreStmt->
zSql, zSql, n)==0
1264 && (zSql[n]==0 || zSql[n-1]==
';')
1266 pStmt = pPreStmt->
pStmt;
1267 *pzOut = &zSql[pPreStmt->
nSql];
1273 if( pPreStmt->
pPrev ){
1278 if( pPreStmt->
pNext ){
1311 assert( pPreStmt==0 );
1315 memset(pPreStmt, 0, nByte);
1317 pPreStmt->
pStmt = pStmt;
1318 pPreStmt->
nSql = (int)(*pzOut - zSql);
1320 pPreStmt->
apParm = (Tcl_Obj **)&pPreStmt[1];
1322 if( pPreStmt->
zSql==0 ){
1323 char *zCopy = Tcl_Alloc(pPreStmt->
nSql + 1);
1324 memcpy(zCopy, zSql, pPreStmt->
nSql);
1325 zCopy[pPreStmt->
nSql] =
'\0';
1326 pPreStmt->
zSql = zCopy;
1332 assert( 0==memcmp(pPreStmt->
zSql, zSql, pPreStmt->
nSql) );
1335 for(i=1; i<=nVar; i++){
1337 if( zVar!=0 && (zVar[0]==
'$' || zVar[0]==
':' || zVar[0]==
'@') ){
1338 Tcl_Obj *pVar = Tcl_GetVar2Ex(interp, &zVar[1], 0, 0);
1342 const char *zType = (pVar->typePtr ? pVar->typePtr->name :
"");
1345 (c==
'b' && strcmp(zType,
"bytearray")==0 && pVar->bytes==0) ){
1349 data = Tcl_GetByteArrayFromObj(pVar, &n);
1351 Tcl_IncrRefCount(pVar);
1352 pPreStmt->
apParm[iParm++] = pVar;
1353 }
else if( c==
'b' && strcmp(zType,
"boolean")==0 ){
1354 Tcl_GetIntFromObj(interp, pVar, &n);
1356 }
else if( c==
'd' && strcmp(zType,
"double")==0 ){
1358 Tcl_GetDoubleFromObj(interp, pVar, &r);
1360 }
else if( (c==
'w' && strcmp(zType,
"wideInt")==0) ||
1361 (c==
'i' && strcmp(zType,
"int")==0) ){
1363 Tcl_GetWideIntFromObj(interp, pVar, &v);
1366 data = (
unsigned char *)Tcl_GetStringFromObj(pVar, &n);
1368 Tcl_IncrRefCount(pVar);
1369 pPreStmt->
apParm[iParm++] = pVar;
1376 pPreStmt->
nParm = iParm;
1377 *ppPreStmt = pPreStmt;
1399 for(i=0; i<pPreStmt->
nParm; i++){
1400 Tcl_DecrRefCount(pPreStmt->
apParm[i]);
1402 pPreStmt->
nParm = 0;
1404 if( pDb->
maxStmt<=0 || discard ){
1410 pPreStmt->
pPrev = 0;
1416 assert( pDb->
nStmt==0 );
1419 assert( pDb->
nStmt>0 );
1462 for(i=0; i<p->
nCol; i++){
1491 p->
zSql = Tcl_GetString(pSql);
1493 Tcl_IncrRefCount(pSql);
1496 Tcl_IncrRefCount(pArray);
1507 Tcl_Obj ***papColName
1514 Tcl_Obj **apColName = 0;
1517 if( nCol>0 && (papColName || p->
pArray) ){
1518 apColName = (Tcl_Obj**)Tcl_Alloc(
sizeof(Tcl_Obj*)*nCol );
1519 for(i=0; i<nCol; i++){
1521 Tcl_IncrRefCount(apColName[i]);
1531 Tcl_Obj *pColList = Tcl_NewObj();
1532 Tcl_Obj *pStar = Tcl_NewStringObj(
"*", -1);
1534 for(i=0; i<nCol; i++){
1535 Tcl_ListObjAppendElement(interp, pColList, apColName[i]);
1537 Tcl_IncrRefCount(pStar);
1538 Tcl_ObjSetVar2(interp, p->
pArray, pStar, pColList, 0);
1539 Tcl_DecrRefCount(pStar);
1563 const char *zPrevSql = 0;
1568 zPrevSql = (p->
zSql==zPrevSql ? 0 : p->
zSql);
1570 if( rc!=TCL_OK )
return rc;
1607 Tcl_SetObjResult(pDb->
interp,
1632 Tcl_DecrRefCount(p->
pArray);
1635 Tcl_DecrRefCount(p->
pSql);
1650 if( !zBlob ) bytes = 0;
1651 return Tcl_NewByteArrayObj((
u8*)zBlob, bytes);
1655 if( v>=-2147483647 && v<=2147483647 ){
1656 return Tcl_NewIntObj((
int)v);
1658 return Tcl_NewWideIntObj(v);
1665 return Tcl_NewStringObj(p->
pDb->
zNull, -1);
1679 #if TCL_MAJOR_VERSION>8 || (TCL_MAJOR_VERSION==8 && TCL_MINOR_VERSION>=6) 1680 # define SQLITE_TCL_NRE 1 1683 Tcl_GetVersion(&major, &minor, 0, 0);
1684 return( (major==8 && minor>=6) || major>8 );
1696 # define SQLITE_TCL_NRE 0 1697 # define DbUseNre() 0 1698 # define Tcl_NRAddCallback(a,b,c,d,e,f) (void)0 1699 # define Tcl_NREvalObj(a,b,c) 0 1700 # define Tcl_NRCreateCommand(a,b,c,d,e,f) (void)0 1720 Tcl_Obj *
pScript = (Tcl_Obj *)data[1];
1721 Tcl_Obj *pArray = p->
pArray;
1723 while( (rc==TCL_OK || rc==TCL_CONTINUE) && TCL_OK==(rc =
dbEvalStep(p)) ){
1726 Tcl_Obj **apColName;
1728 for(i=0; i<nCol; i++){
1731 Tcl_ObjSetVar2(interp, apColName[i], 0, pVal, 0);
1733 Tcl_ObjSetVar2(interp, pArray, apColName[i], pVal, 0);
1750 rc = Tcl_EvalObjEx(interp, pScript, 0);
1754 Tcl_DecrRefCount(pScript);
1756 Tcl_Free((
char *)p);
1758 if( rc==TCL_OK || rc==TCL_BREAK ){
1759 Tcl_ResetResult(interp);
1783 Tcl_SetObjResult(interp, *ppHook);
1785 Tcl_DecrRefCount(*ppHook);
1790 assert( !(*ppHook) );
1791 if( Tcl_GetCharLength(pArg)>0 ){
1793 Tcl_IncrRefCount(*ppHook);
1797 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK 1827 static const char *DB_strs[] = {
1828 "authorizer",
"backup",
"busy",
1829 "cache",
"changes",
"close",
1830 "collate",
"collation_needed",
"commit_hook",
1831 "complete",
"copy",
"enable_load_extension",
1832 "errorcode",
"eval",
"exists",
1833 "function",
"incrblob",
"interrupt",
1834 "last_insert_rowid",
"nullvalue",
"onecolumn",
1835 "preupdate",
"profile",
"progress",
1836 "rekey",
"restore",
"rollback_hook",
1837 "status",
"timeout",
"total_changes",
1838 "trace",
"trace_v2",
"transaction",
1839 "unlock_notify",
"update_hook",
"version",
1844 DB_AUTHORIZER, DB_BACKUP, DB_BUSY,
1845 DB_CACHE, DB_CHANGES, DB_CLOSE,
1846 DB_COLLATE, DB_COLLATION_NEEDED, DB_COMMIT_HOOK,
1847 DB_COMPLETE, DB_COPY, DB_ENABLE_LOAD_EXTENSION,
1848 DB_ERRORCODE, DB_EVAL, DB_EXISTS,
1849 DB_FUNCTION, DB_INCRBLOB, DB_INTERRUPT,
1850 DB_LAST_INSERT_ROWID, DB_NULLVALUE, DB_ONECOLUMN,
1851 DB_PREUPDATE, DB_PROFILE, DB_PROGRESS,
1852 DB_REKEY, DB_RESTORE, DB_ROLLBACK_HOOK,
1853 DB_STATUS, DB_TIMEOUT, DB_TOTAL_CHANGES,
1854 DB_TRACE, DB_TRACE_V2, DB_TRANSACTION,
1855 DB_UNLOCK_NOTIFY, DB_UPDATE_HOOK, DB_VERSION,
1861 Tcl_WrongNumArgs(interp, 1, objv,
"SUBCOMMAND ...");
1864 if( Tcl_GetIndexFromObj(interp, objv[1], DB_strs,
"option", 0, &choice) ){
1868 switch( (
enum DB_enum)choice ){
1888 case DB_AUTHORIZER: {
1889 #ifdef SQLITE_OMIT_AUTHORIZATION 1890 Tcl_AppendResult(interp,
"authorization not available in this build",
1895 Tcl_WrongNumArgs(interp, 2, objv,
"?CALLBACK?");
1897 }
else if( objc==2 ){
1899 Tcl_AppendResult(interp, pDb->
zAuth, (
char*)0);
1905 Tcl_Free(pDb->
zAuth);
1907 zAuth = Tcl_GetStringFromObj(objv[2], &len);
1908 if( zAuth && len>0 ){
1909 pDb->
zAuth = Tcl_Alloc( len + 1 );
1910 memcpy(pDb->
zAuth, zAuth, len+1);
1915 typedef int (*sqlite3_auth_cb)(
1916 void*,int,
const char*,
const char*,
1917 const char*,
const char*);
1935 const char *zDestFile;
1942 zDestFile = Tcl_GetString(objv[2]);
1943 }
else if( objc==4 ){
1944 zSrcDb = Tcl_GetString(objv[2]);
1945 zDestFile = Tcl_GetString(objv[3]);
1947 Tcl_WrongNumArgs(interp, 2, objv,
"?DATABASE? FILENAME");
1953 Tcl_AppendResult(interp,
"cannot open target database: ",
1960 Tcl_AppendResult(interp,
"backup failed: ",
1970 Tcl_AppendResult(interp,
"backup failed: ",
1985 Tcl_WrongNumArgs(interp, 2, objv,
"CALLBACK");
1987 }
else if( objc==2 ){
1989 Tcl_AppendResult(interp, pDb->
zBusy, (
char*)0);
1995 Tcl_Free(pDb->
zBusy);
1997 zBusy = Tcl_GetStringFromObj(objv[2], &len);
1998 if( zBusy && len>0 ){
1999 pDb->
zBusy = Tcl_Alloc( len + 1 );
2000 memcpy(pDb->
zBusy, zBusy, len+1);
2025 Tcl_WrongNumArgs(interp, 1, objv,
"cache option ?arg?");
2028 subCmd = Tcl_GetStringFromObj( objv[2], 0 );
2029 if( *subCmd==
'f' && strcmp(subCmd,
"flush")==0 ){
2031 Tcl_WrongNumArgs(interp, 2, objv,
"flush");
2036 }
else if( *subCmd==
's' && strcmp(subCmd,
"size")==0 ){
2038 Tcl_WrongNumArgs(interp, 2, objv,
"size n");
2041 if( TCL_ERROR==Tcl_GetIntFromObj(interp, objv[3], &n) ){
2042 Tcl_AppendResult( interp,
"cannot convert \"",
2043 Tcl_GetStringFromObj(objv[3],0),
"\" to integer", (
char*)0);
2056 Tcl_AppendResult( interp,
"bad option \"",
2057 Tcl_GetStringFromObj(objv[2],0),
"\": must be flush or size",
2073 Tcl_WrongNumArgs(interp, 2, objv,
"");
2076 pResult = Tcl_GetObjResult(interp);
2086 Tcl_DeleteCommand(interp, Tcl_GetStringFromObj(objv[0], 0));
2102 Tcl_WrongNumArgs(interp, 2, objv,
"NAME SCRIPT");
2105 zName = Tcl_GetStringFromObj(objv[2], 0);
2106 zScript = Tcl_GetStringFromObj(objv[3], &nScript);
2107 pCollate = (
SqlCollate*)Tcl_Alloc(
sizeof(*pCollate) + nScript + 1 );
2108 if( pCollate==0 )
return TCL_ERROR;
2111 pCollate->
zScript = (
char*)&pCollate[1];
2113 memcpy(pCollate->
zScript, zScript, nScript+1);
2128 case DB_COLLATION_NEEDED: {
2130 Tcl_WrongNumArgs(interp, 2, objv,
"SCRIPT");
2149 case DB_COMMIT_HOOK: {
2151 Tcl_WrongNumArgs(interp, 2, objv,
"?CALLBACK?");
2153 }
else if( objc==2 ){
2155 Tcl_AppendResult(interp, pDb->
zCommit, (
char*)0);
2158 const char *zCommit;
2163 zCommit = Tcl_GetStringFromObj(objv[2], &len);
2164 if( zCommit && len>0 ){
2165 pDb->
zCommit = Tcl_Alloc( len + 1 );
2166 memcpy(pDb->
zCommit, zCommit, len+1);
2187 #ifndef SQLITE_OMIT_COMPLETE 2191 Tcl_WrongNumArgs(interp, 2, objv,
"SQL");
2195 pResult = Tcl_GetObjResult(interp);
2196 Tcl_SetBooleanObj(pResult, isComplete);
2231 const char *zCommit;
2239 if( objc<5 || objc>7 ){
2240 Tcl_WrongNumArgs(interp, 2, objv,
2241 "CONFLICT-ALGORITHM TABLE FILENAME ?SEPARATOR? ?NULLINDICATOR?");
2245 zSep = Tcl_GetStringFromObj(objv[5], 0);
2250 zNull = Tcl_GetStringFromObj(objv[6], 0);
2254 zConflict = Tcl_GetStringFromObj(objv[2], 0);
2255 zTable = Tcl_GetStringFromObj(objv[3], 0);
2256 zFile = Tcl_GetStringFromObj(objv[4], 0);
2260 Tcl_AppendResult(interp,
"Error: non-null separator required for copy",
2264 if(strcmp(zConflict,
"rollback") != 0 &&
2265 strcmp(zConflict,
"abort" ) != 0 &&
2266 strcmp(zConflict,
"fail" ) != 0 &&
2267 strcmp(zConflict,
"ignore" ) != 0 &&
2268 strcmp(zConflict,
"replace" ) != 0 ) {
2269 Tcl_AppendResult(interp,
"Error: \"", zConflict,
2270 "\", conflict-algorithm must be one of: rollback, " 2271 "abort, fail, ignore, or replace", (
char*)0);
2276 Tcl_AppendResult(interp,
"Error: no such table: ", zTable, (
char*)0);
2292 zSql = malloc( nByte + 50 + nCol*2 );
2294 Tcl_AppendResult(interp,
"Error: can't malloc()", (
char*)0);
2300 for(i=1; i<nCol; i++){
2313 in = fopen(zFile,
"rb");
2315 Tcl_AppendResult(interp,
"Error: cannot open file: ", zFile, NULL);
2319 azCol = malloc(
sizeof(azCol[0])*(nCol+1) );
2321 Tcl_AppendResult(interp,
"Error: can't malloc()", (
char*)0);
2331 for(i=0, z=zLine; *z; z++){
2332 if( *z==zSep[0] && strncmp(z, zSep, nSep)==0 ){
2336 azCol[i] = &z[nSep];
2344 zErr = malloc(nErr);
2347 "Error: %s line %d: expected %d columns of data but found %d",
2348 zFile, lineno, nCol, i+1);
2349 Tcl_AppendResult(interp, zErr, (
char*)0);
2352 zCommit =
"ROLLBACK";
2355 for(i=0; i<nCol; i++){
2357 if( (nNull>0 && strcmp(azCol[i], zNull)==0)
2370 zCommit =
"ROLLBACK";
2379 if( zCommit[0] ==
'C' ){
2381 pResult = Tcl_GetObjResult(interp);
2382 Tcl_SetIntObj(pResult, lineno);
2387 Tcl_AppendResult(interp,
", failed while processing line: ",zLineNum,
2400 case DB_ENABLE_LOAD_EXTENSION: {
2401 #ifndef SQLITE_OMIT_LOAD_EXTENSION 2404 Tcl_WrongNumArgs(interp, 2, objv,
"BOOLEAN");
2407 if( Tcl_GetBooleanFromObj(interp, objv[2], &onoff) ){
2413 Tcl_AppendResult(interp,
"extension loading is turned off at compile-time",
2425 case DB_ERRORCODE: {
2438 case DB_ONECOLUMN: {
2439 Tcl_Obj *pResult = 0;
2442 Tcl_WrongNumArgs(interp, 2, objv,
"SQL");
2448 if( choice==DB_ONECOLUMN ){
2451 }
else if( rc==TCL_BREAK ){
2452 Tcl_ResetResult(interp);
2454 }
else if( rc==TCL_BREAK || rc==TCL_OK ){
2455 pResult = Tcl_NewBooleanObj(rc==TCL_OK);
2458 if( pResult ) Tcl_SetObjResult(interp, pResult);
2460 if( rc==TCL_BREAK ){
2476 if( objc<3 || objc>5 ){
2477 Tcl_WrongNumArgs(interp, 2, objv,
"SQL ?ARRAY-NAME? ?SCRIPT?");
2483 Tcl_Obj *pRet = Tcl_NewObj();
2484 Tcl_IncrRefCount(pRet);
2490 for(i=0; i<nCol; i++){
2495 if( rc==TCL_BREAK ){
2496 Tcl_SetObjResult(interp, pRet);
2499 Tcl_DecrRefCount(pRet);
2503 Tcl_Obj *pArray = 0;
2506 if( objc==5 && *(
char *)Tcl_GetString(objv[3]) ){
2509 pScript = objv[objc-1];
2510 Tcl_IncrRefCount(pScript);
2516 cd2[1] = (
void *)pScript;
2536 Tcl_WrongNumArgs(interp, 2, objv,
"NAME ?SWITCHES? SCRIPT");
2539 for(i=3; i<(objc-1); i++){
2540 const char *
z = Tcl_GetString(objv[i]);
2542 if( n>2 && strncmp(z,
"-argcount",n)==0 ){
2544 Tcl_AppendResult(interp,
"option requires an argument: ", z, 0);
2547 if( Tcl_GetIntFromObj(interp, objv[i+1], &nArg) )
return TCL_ERROR;
2549 Tcl_AppendResult(interp,
"number of arguments must be non-negative",
2555 if( n>2 && strncmp(z,
"-deterministic",n)==0 ){
2558 Tcl_AppendResult(interp,
"bad option \"", z,
2559 "\": must be -argcount or -deterministic", 0
2565 pScript = objv[objc-1];
2566 zName = Tcl_GetStringFromObj(objv[2], 0);
2568 if( pFunc==0 )
return TCL_ERROR;
2570 Tcl_DecrRefCount(pFunc->
pScript);
2573 Tcl_IncrRefCount(pScript);
2588 #ifdef SQLITE_OMIT_INCRBLOB 2589 Tcl_AppendResult(interp,
"incrblob not available in this build", (
char*)0);
2593 const char *zDb =
"main";
2595 const char *zColumn;
2599 if( objc>3 && strcmp(Tcl_GetString(objv[2]),
"-readonly")==0 ){
2603 if( objc!=(5+isReadonly) && objc!=(6+isReadonly) ){
2604 Tcl_WrongNumArgs(interp, 2, objv,
"?-readonly? ?DB? TABLE COLUMN ROWID");
2608 if( objc==(6+isReadonly) ){
2609 zDb = Tcl_GetString(objv[2]);
2611 zTable = Tcl_GetString(objv[objc-3]);
2612 zColumn = Tcl_GetString(objv[objc-2]);
2613 rc = Tcl_GetWideIntFromObj(interp, objv[objc-1], &iRow);
2617 interp, pDb, zDb, zTable, zColumn, (
sqlite3_int64)iRow, isReadonly
2630 case DB_INTERRUPT: {
2643 case DB_NULLVALUE: {
2644 if( objc!=2 && objc!=3 ){
2645 Tcl_WrongNumArgs(interp, 2, objv,
"NULLVALUE");
2650 char *zNull = Tcl_GetStringFromObj(objv[2], &len);
2652 Tcl_Free(pDb->
zNull);
2654 if( zNull && len>0 ){
2655 pDb->
zNull = Tcl_Alloc( len + 1 );
2656 memcpy(pDb->
zNull, zNull, len);
2657 pDb->
zNull[len] =
'\0';
2662 Tcl_SetObjResult(interp, Tcl_NewStringObj(pDb->
zNull, -1));
2671 case DB_LAST_INSERT_ROWID: {
2675 Tcl_WrongNumArgs(interp, 2, objv,
"");
2679 pResult = Tcl_GetObjResult(interp);
2680 Tcl_SetWideIntObj(pResult, rowid);
2696 Tcl_AppendResult(interp, pDb->
zProgress, (
char*)0);
2698 }
else if( objc==4 ){
2702 if( TCL_OK!=Tcl_GetIntFromObj(interp, objv[2], &N) ){
2708 zProgress = Tcl_GetStringFromObj(objv[3], &len);
2709 if( zProgress && len>0 ){
2711 memcpy(pDb->
zProgress, zProgress, len+1);
2715 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK 2724 Tcl_WrongNumArgs(interp, 2, objv,
"N CALLBACK");
2738 Tcl_WrongNumArgs(interp, 2, objv,
"?CALLBACK?");
2740 }
else if( objc==2 ){
2742 Tcl_AppendResult(interp, pDb->
zProfile, (
char*)0);
2750 zProfile = Tcl_GetStringFromObj(objv[2], &len);
2751 if( zProfile && len>0 ){
2752 pDb->
zProfile = Tcl_Alloc( len + 1 );
2753 memcpy(pDb->
zProfile, zProfile, len+1);
2757 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT) && \ 2758 !defined(SQLITE_OMIT_DEPRECATED) 2776 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) 2781 Tcl_WrongNumArgs(interp, 2, objv,
"KEY");
2784 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) 2785 pKey = Tcl_GetByteArrayFromObj(objv[2], &nKey);
2786 rc = sqlite3_rekey(pDb->
db, pKey, nKey);
2801 const char *zSrcFile;
2802 const char *zDestDb;
2809 zSrcFile = Tcl_GetString(objv[2]);
2810 }
else if( objc==4 ){
2811 zDestDb = Tcl_GetString(objv[2]);
2812 zSrcFile = Tcl_GetString(objv[3]);
2814 Tcl_WrongNumArgs(interp, 2, objv,
"?DATABASE? FILENAME");
2820 Tcl_AppendResult(interp,
"cannot open source database: ",
2827 Tcl_AppendResult(interp,
"restore failed: ",
2835 if( nTimeout++ >= 3 )
break;
2843 Tcl_AppendResult(interp,
"restore failed: source database busy",
2847 Tcl_AppendResult(interp,
"restore failed: ",
2865 Tcl_WrongNumArgs(interp, 2, objv,
"(step|sort|autoindex)");
2868 zOp = Tcl_GetString(objv[2]);
2869 if( strcmp(zOp,
"step")==0 ){
2871 }
else if( strcmp(zOp,
"sort")==0 ){
2873 }
else if( strcmp(zOp,
"autoindex")==0 ){
2876 Tcl_AppendResult(interp,
2877 "bad argument: should be autoindex, step, or sort",
2881 Tcl_SetObjResult(interp, Tcl_NewIntObj(v));
2893 Tcl_WrongNumArgs(interp, 2, objv,
"MILLISECONDS");
2896 if( Tcl_GetIntFromObj(interp, objv[2], &ms) )
return TCL_ERROR;
2907 case DB_TOTAL_CHANGES: {
2910 Tcl_WrongNumArgs(interp, 2, objv,
"");
2913 pResult = Tcl_GetObjResult(interp);
2926 Tcl_WrongNumArgs(interp, 2, objv,
"?CALLBACK?");
2928 }
else if( objc==2 ){
2930 Tcl_AppendResult(interp, pDb->
zTrace, (
char*)0);
2938 zTrace = Tcl_GetStringFromObj(objv[2], &len);
2939 if( zTrace && len>0 ){
2940 pDb->
zTrace = Tcl_Alloc( len + 1 );
2941 memcpy(pDb->
zTrace, zTrace, len+1);
2945 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT) && \ 2946 !defined(SQLITE_OMIT_DEPRECATED) 2966 Tcl_WrongNumArgs(interp, 2, objv,
"?CALLBACK? ?MASK?");
2968 }
else if( objc==2 ){
2970 Tcl_AppendResult(interp, pDb->
zTraceV2, (
char*)0);
2975 Tcl_WideInt wMask = 0;
2977 static const char *TTYPE_strs[] = {
2978 "statement",
"profile",
"row",
"close", 0
2981 TTYPE_STMT, TTYPE_PROFILE, TTYPE_ROW, TTYPE_CLOSE
2984 if( TCL_OK!=Tcl_ListObjLength(interp, objv[3], &len) ){
2987 for(i=0; i<len; i++){
2990 if( TCL_OK!=Tcl_ListObjIndex(interp, objv[3], i, &pObj) ){
2993 if( Tcl_GetIndexFromObj(interp, pObj, TTYPE_strs,
"trace type",
2994 0, &ttype)!=TCL_OK ){
2996 Tcl_Obj *pError = Tcl_DuplicateObj(Tcl_GetObjResult(interp));
2997 Tcl_IncrRefCount(pError);
2998 if( TCL_OK==Tcl_GetWideIntFromObj(interp, pObj, &wType) ){
2999 Tcl_DecrRefCount(pError);
3002 Tcl_SetObjResult(interp, pError);
3003 Tcl_DecrRefCount(pError);
3007 switch( (
enum TTYPE_enum)ttype ){
3021 zTraceV2 = Tcl_GetStringFromObj(objv[2], &len);
3022 if( zTraceV2 && len>0 ){
3023 pDb->
zTraceV2 = Tcl_Alloc( len + 1 );
3024 memcpy(pDb->
zTraceV2, zTraceV2, len+1);
3028 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT) 3051 case DB_TRANSACTION: {
3053 const char *zBegin =
"SAVEPOINT _tcl_transaction";
3054 if( objc!=3 && objc!=4 ){
3055 Tcl_WrongNumArgs(interp, 2, objv,
"[TYPE] SCRIPT");
3060 static const char *TTYPE_strs[] = {
3061 "deferred",
"exclusive",
"immediate", 0
3064 TTYPE_DEFERRED, TTYPE_EXCLUSIVE, TTYPE_IMMEDIATE
3067 if( Tcl_GetIndexFromObj(interp, objv[2], TTYPE_strs,
"transaction type",
3071 switch( (
enum TTYPE_enum)ttype ){
3072 case TTYPE_DEFERRED: ;
break;
3073 case TTYPE_EXCLUSIVE: zBegin =
"BEGIN EXCLUSIVE";
break;
3074 case TTYPE_IMMEDIATE: zBegin =
"BEGIN IMMEDIATE";
break;
3077 pScript = objv[objc-1];
3098 rc =
DbTransPostCmd(&cd, interp, Tcl_EvalObjEx(interp, pScript, 0));
3106 case DB_UNLOCK_NOTIFY: {
3107 #ifndef SQLITE_ENABLE_UNLOCK_NOTIFY 3108 Tcl_AppendResult(interp,
"unlock_notify not available in this build",
3112 if( objc!=2 && objc!=3 ){
3113 Tcl_WrongNumArgs(interp, 2, objv,
"?SCRIPT?");
3116 void (*xNotify)(
void **, int) = 0;
3117 void *pNotifyArg = 0;
3125 xNotify = DbUnlockNotify;
3126 pNotifyArg = (
void *)pDb;
3146 case DB_PREUPDATE: {
3147 #ifndef SQLITE_ENABLE_PREUPDATE_HOOK 3148 Tcl_AppendResult(interp,
"preupdate_hook was omitted at compile-time");
3151 static const char *azSub[] = {
"count",
"depth",
"hook",
"new",
"old", 0};
3152 enum DbPreupdateSubCmd {
3153 PRE_COUNT, PRE_DEPTH, PRE_HOOK, PRE_NEW, PRE_OLD
3158 Tcl_WrongNumArgs(interp, 2, objv,
"SUB-COMMAND ?ARGS?");
3160 if( Tcl_GetIndexFromObj(interp, objv[2], azSub,
"sub-command", 0, &iSub) ){
3164 switch( (
enum DbPreupdateSubCmd)iSub ){
3167 Tcl_SetObjResult(interp, Tcl_NewIntObj(nCol));
3173 Tcl_WrongNumArgs(interp, 2, objv,
"hook ?SCRIPT?");
3183 Tcl_WrongNumArgs(interp, 3, objv,
"");
3187 Tcl_SetObjResult(interp, pRet);
3196 Tcl_WrongNumArgs(interp, 3, objv,
"INDEX");
3199 if( Tcl_GetIntFromObj(interp, objv[3], &iIdx) ){
3203 if( iSub==PRE_OLD ){
3206 assert( iSub==PRE_NEW );
3213 Tcl_SetObjResult(interp, pObj);
3230 case DB_UPDATE_HOOK:
3231 case DB_ROLLBACK_HOOK: {
3235 Tcl_Obj **ppHook = 0;
3236 if( choice==DB_WAL_HOOK ) ppHook = &pDb->
pWalHook;
3237 if( choice==DB_UPDATE_HOOK ) ppHook = &pDb->
pUpdateHook;
3238 if( choice==DB_ROLLBACK_HOOK ) ppHook = &pDb->
pRollbackHook;
3240 Tcl_WrongNumArgs(interp, 2, objv,
"?SCRIPT?");
3244 DbHookCmd(interp, pDb, (objc==3 ? objv[2] : 0), ppHook);
3303 const char *zVfs = 0;
3305 Tcl_DString translatedFilename;
3306 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) 3318 #ifdef SQLITE_TCL_DEFAULT_FULLMUTEX 3325 zArg = Tcl_GetStringFromObj(objv[1], 0);
3326 if( strcmp(zArg,
"-version")==0 ){
3330 if( strcmp(zArg,
"-sourceid")==0 ){
3334 if( strcmp(zArg,
"-has-codec")==0 ){
3335 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) 3336 Tcl_AppendResult(interp,
"1",(
char*)0);
3338 Tcl_AppendResult(interp,
"0",(
char*)0);
3343 for(i=3; i+1<objc; i+=2){
3344 zArg = Tcl_GetString(objv[i]);
3345 if( strcmp(zArg,
"-key")==0 ){
3346 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) 3347 pKey = Tcl_GetByteArrayFromObj(objv[i+1], &nKey);
3349 }
else if( strcmp(zArg,
"-vfs")==0 ){
3350 zVfs = Tcl_GetString(objv[i+1]);
3351 }
else if( strcmp(zArg,
"-readonly")==0 ){
3353 if( Tcl_GetBooleanFromObj(interp, objv[i+1], &b) )
return TCL_ERROR;
3361 }
else if( strcmp(zArg,
"-create")==0 ){
3363 if( Tcl_GetBooleanFromObj(interp, objv[i+1], &b) )
return TCL_ERROR;
3369 }
else if( strcmp(zArg,
"-nomutex")==0 ){
3371 if( Tcl_GetBooleanFromObj(interp, objv[i+1], &b) )
return TCL_ERROR;
3378 }
else if( strcmp(zArg,
"-fullmutex")==0 ){
3380 if( Tcl_GetBooleanFromObj(interp, objv[i+1], &b) )
return TCL_ERROR;
3387 }
else if( strcmp(zArg,
"-uri")==0 ){
3389 if( Tcl_GetBooleanFromObj(interp, objv[i+1], &b) )
return TCL_ERROR;
3396 Tcl_AppendResult(interp,
"unknown option: ", zArg, (
char*)0);
3400 if( objc<3 || (objc&1)!=1 ){
3401 Tcl_WrongNumArgs(interp, 1, objv,
3402 "HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN?" 3403 " ?-nomutex BOOLEAN? ?-fullmutex BOOLEAN? ?-uri BOOLEAN?" 3404 #
if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
3411 p = (
SqliteDb*)Tcl_Alloc(
sizeof(*p) );
3413 Tcl_SetResult(interp, (
char *)
"malloc failed", TCL_STATIC);
3416 memset(p, 0,
sizeof(*p));
3417 zFile = Tcl_GetStringFromObj(objv[2], 0);
3418 zFile = Tcl_TranslateFileName(interp, zFile, &translatedFilename);
3420 Tcl_DStringFree(&translatedFilename);
3430 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) 3432 sqlite3_key(p->
db, pKey, nKey);
3436 Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE);
3444 zArg = Tcl_GetStringFromObj(objv[1], 0);
3458 #ifndef USE_TCL_STUBS 3459 # undef Tcl_InitStubs 3460 # define Tcl_InitStubs(a,b,c) TCL_VERSION 3468 #ifndef PACKAGE_VERSION 3469 # define PACKAGE_VERSION SQLITE_VERSION 3484 int rc =
Tcl_InitStubs(interp,
"8.4", 0) ? TCL_OK : TCL_ERROR;
3486 Tcl_CreateObjCommand(interp,
"sqlite3", (Tcl_ObjCmdProc*)
DbMain, 0, 0);
3487 #ifndef SQLITE_3_SUFFIX_ONLY 3491 Tcl_CreateObjCommand(interp,
"sqlite", (Tcl_ObjCmdProc*)
DbMain, 0, 0);
3510 #ifndef SQLITE_3_SUFFIX_ONLY 3526 #if defined(SQLITE_TEST) || defined(SQLITE_TCLMD5) 3553 # define uint32 unsigned int 3560 unsigned char in[64];
3562 typedef struct MD5Context MD5Context;
3567 static void byteReverse (
unsigned char *buf,
unsigned longs){
3570 t = (uint32)((
unsigned)buf[3]<<8 | buf[2]) << 16 |
3571 ((
unsigned)buf[1]<<8 | buf[0]);
3579 #define F1(x, y, z) (z ^ (x & (y ^ z))) 3580 #define F2(x, y, z) F1(z, x, y) 3581 #define F3(x, y, z) (x ^ y ^ z) 3582 #define F4(x, y, z) (y ^ (x | ~z)) 3585 #define MD5STEP(f, w, x, y, z, data, s) \ 3586 ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x ) 3593 static void MD5Transform(uint32 buf[4],
const uint32 in[16]){
3594 register uint32 a, b, c,
d;
3601 MD5STEP(F1, a, b, c, d, in[ 0]+0xd76aa478, 7);
3602 MD5STEP(F1, d, a, b, c, in[ 1]+0xe8c7b756, 12);
3603 MD5STEP(F1, c, d, a, b, in[ 2]+0x242070db, 17);
3604 MD5STEP(F1, b, c, d, a, in[ 3]+0xc1bdceee, 22);
3605 MD5STEP(F1, a, b, c, d, in[ 4]+0xf57c0faf, 7);
3606 MD5STEP(F1, d, a, b, c, in[ 5]+0x4787c62a, 12);
3607 MD5STEP(F1, c, d, a, b, in[ 6]+0xa8304613, 17);
3608 MD5STEP(F1, b, c, d, a, in[ 7]+0xfd469501, 22);
3609 MD5STEP(F1, a, b, c, d, in[ 8]+0x698098d8, 7);
3610 MD5STEP(F1, d, a, b, c, in[ 9]+0x8b44f7af, 12);
3611 MD5STEP(F1, c, d, a, b, in[10]+0xffff5bb1, 17);
3612 MD5STEP(F1, b, c, d, a, in[11]+0x895cd7be, 22);
3613 MD5STEP(F1, a, b, c, d, in[12]+0x6b901122, 7);
3614 MD5STEP(F1, d, a, b, c, in[13]+0xfd987193, 12);
3615 MD5STEP(F1, c, d, a, b, in[14]+0xa679438e, 17);
3616 MD5STEP(F1, b, c, d, a, in[15]+0x49b40821, 22);
3618 MD5STEP(F2, a, b, c, d, in[ 1]+0xf61e2562, 5);
3619 MD5STEP(F2, d, a, b, c, in[ 6]+0xc040b340, 9);
3620 MD5STEP(F2, c, d, a, b, in[11]+0x265e5a51, 14);
3621 MD5STEP(F2, b, c, d, a, in[ 0]+0xe9b6c7aa, 20);
3622 MD5STEP(F2, a, b, c, d, in[ 5]+0xd62f105d, 5);
3623 MD5STEP(F2, d, a, b, c, in[10]+0x02441453, 9);
3624 MD5STEP(F2, c, d, a, b, in[15]+0xd8a1e681, 14);
3625 MD5STEP(F2, b, c, d, a, in[ 4]+0xe7d3fbc8, 20);
3626 MD5STEP(F2, a, b, c, d, in[ 9]+0x21e1cde6, 5);
3627 MD5STEP(F2, d, a, b, c, in[14]+0xc33707d6, 9);
3628 MD5STEP(F2, c, d, a, b, in[ 3]+0xf4d50d87, 14);
3629 MD5STEP(F2, b, c, d, a, in[ 8]+0x455a14ed, 20);
3630 MD5STEP(F2, a, b, c, d, in[13]+0xa9e3e905, 5);
3631 MD5STEP(F2, d, a, b, c, in[ 2]+0xfcefa3f8, 9);
3632 MD5STEP(F2, c, d, a, b, in[ 7]+0x676f02d9, 14);
3633 MD5STEP(F2, b, c, d, a, in[12]+0x8d2a4c8a, 20);
3635 MD5STEP(F3, a, b, c, d, in[ 5]+0xfffa3942, 4);
3636 MD5STEP(F3, d, a, b, c, in[ 8]+0x8771f681, 11);
3637 MD5STEP(F3, c, d, a, b, in[11]+0x6d9d6122, 16);
3638 MD5STEP(F3, b, c, d, a, in[14]+0xfde5380c, 23);
3639 MD5STEP(F3, a, b, c, d, in[ 1]+0xa4beea44, 4);
3640 MD5STEP(F3, d, a, b, c, in[ 4]+0x4bdecfa9, 11);
3641 MD5STEP(F3, c, d, a, b, in[ 7]+0xf6bb4b60, 16);
3642 MD5STEP(F3, b, c, d, a, in[10]+0xbebfbc70, 23);
3643 MD5STEP(F3, a, b, c, d, in[13]+0x289b7ec6, 4);
3644 MD5STEP(F3, d, a, b, c, in[ 0]+0xeaa127fa, 11);
3645 MD5STEP(F3, c, d, a, b, in[ 3]+0xd4ef3085, 16);
3646 MD5STEP(F3, b, c, d, a, in[ 6]+0x04881d05, 23);
3647 MD5STEP(F3, a, b, c, d, in[ 9]+0xd9d4d039, 4);
3648 MD5STEP(F3, d, a, b, c, in[12]+0xe6db99e5, 11);
3649 MD5STEP(F3, c, d, a, b, in[15]+0x1fa27cf8, 16);
3650 MD5STEP(F3, b, c, d, a, in[ 2]+0xc4ac5665, 23);
3652 MD5STEP(F4, a, b, c, d, in[ 0]+0xf4292244, 6);
3653 MD5STEP(F4, d, a, b, c, in[ 7]+0x432aff97, 10);
3654 MD5STEP(F4, c, d, a, b, in[14]+0xab9423a7, 15);
3655 MD5STEP(F4, b, c, d, a, in[ 5]+0xfc93a039, 21);
3656 MD5STEP(F4, a, b, c, d, in[12]+0x655b59c3, 6);
3657 MD5STEP(F4, d, a, b, c, in[ 3]+0x8f0ccc92, 10);
3658 MD5STEP(F4, c, d, a, b, in[10]+0xffeff47d, 15);
3659 MD5STEP(F4, b, c, d, a, in[ 1]+0x85845dd1, 21);
3660 MD5STEP(F4, a, b, c, d, in[ 8]+0x6fa87e4f, 6);
3661 MD5STEP(F4, d, a, b, c, in[15]+0xfe2ce6e0, 10);
3662 MD5STEP(F4, c, d, a, b, in[ 6]+0xa3014314, 15);
3663 MD5STEP(F4, b, c, d, a, in[13]+0x4e0811a1, 21);
3664 MD5STEP(F4, a, b, c, d, in[ 4]+0xf7537e82, 6);
3665 MD5STEP(F4, d, a, b, c, in[11]+0xbd3af235, 10);
3666 MD5STEP(F4, c, d, a, b, in[ 2]+0x2ad7d2bb, 15);
3667 MD5STEP(F4, b, c, d, a, in[ 9]+0xeb86d391, 21);
3679 static void MD5Init(MD5Context *ctx){
3681 ctx->buf[0] = 0x67452301;
3682 ctx->buf[1] = 0xefcdab89;
3683 ctx->buf[2] = 0x98badcfe;
3684 ctx->buf[3] = 0x10325476;
3694 void MD5Update(MD5Context *ctx,
const unsigned char *buf,
unsigned int len){
3700 if ((ctx->bits[0] = t + ((uint32)len << 3)) < t)
3702 ctx->bits[1] += len >> 29;
3704 t = (t >> 3) & 0x3f;
3709 unsigned char *p = (
unsigned char *)ctx->in + t;
3713 memcpy(p, buf, len);
3717 byteReverse(ctx->in, 16);
3718 MD5Transform(ctx->buf, (uint32 *)ctx->in);
3726 memcpy(ctx->in, buf, 64);
3727 byteReverse(ctx->in, 16);
3728 MD5Transform(ctx->buf, (uint32 *)ctx->in);
3735 memcpy(ctx->in, buf, len);
3742 static void MD5Final(
unsigned char digest[16], MD5Context *ctx){
3747 count = (ctx->bits[0] >> 3) & 0x3F;
3751 p = ctx->in + count;
3755 count = 64 - 1 - count;
3760 memset(p, 0, count);
3761 byteReverse(ctx->in, 16);
3762 MD5Transform(ctx->buf, (uint32 *)ctx->in);
3765 memset(ctx->in, 0, 56);
3768 memset(p, 0, count-8);
3770 byteReverse(ctx->in, 14);
3773 memcpy(ctx->in + 14*4, ctx->bits, 8);
3775 MD5Transform(ctx->buf, (uint32 *)ctx->in);
3776 byteReverse((
unsigned char *)ctx->buf, 4);
3777 memcpy(digest, ctx->buf, 16);
3783 static void MD5DigestToBase16(
unsigned char *digest,
char *zBuf){
3784 static char const zEncode[] =
"0123456789abcdef";
3787 for(j=i=0; i<16; i++){
3789 zBuf[j++] = zEncode[(a>>4)&0xf];
3790 zBuf[j++] = zEncode[a & 0xf];
3801 static void MD5DigestToBase10x8(
unsigned char digest[16],
char zDigest[50]){
3804 for(i=j=0; i<16; i+=2){
3805 x = digest[i]*256 + digest[i+1];
3806 if( i>0 ) zDigest[j++] =
'-';
3824 unsigned char digest[16];
3826 void (*converter)(
unsigned char*,
char*);
3829 Tcl_AppendResult(
interp,
"wrong # args: should be \"", argv[0],
3830 " TEXT\"", (
char*)0);
3834 MD5Update(&ctx, (
unsigned char*)argv[1], (
unsigned)strlen(argv[1]));
3835 MD5Final(digest, &ctx);
3836 converter = (void(*)(
unsigned char*,
char*))cd;
3837 converter(digest, zBuf);
3838 Tcl_AppendResult(
interp, zBuf, (
char*)0);
3854 void (*converter)(
unsigned char*,
char*);
3855 unsigned char digest[16];
3859 Tcl_AppendResult(
interp,
"wrong # args: should be \"", argv[0],
3860 " FILENAME\"", (
char*)0);
3863 in = fopen(argv[1],
"rb");
3865 Tcl_AppendResult(
interp,
"unable to open file \"", argv[1],
3866 "\" for reading", (
char*)0);
3872 n = (int)fread(zBuf, 1,
sizeof(zBuf), in);
3874 MD5Update(&ctx, (
unsigned char*)zBuf, (
unsigned)n);
3877 MD5Final(digest, &ctx);
3878 converter = (void(*)(
unsigned char*,
char*))cd;
3879 converter(digest, zBuf);
3880 Tcl_AppendResult(
interp, zBuf, (
char*)0);
3888 int Md5_Init(Tcl_Interp *
interp){
3889 Tcl_CreateCommand(interp,
"md5", (Tcl_CmdProc*)md5_cmd,
3890 MD5DigestToBase16, 0);
3891 Tcl_CreateCommand(interp,
"md5-10x8", (Tcl_CmdProc*)md5_cmd,
3892 MD5DigestToBase10x8, 0);
3893 Tcl_CreateCommand(interp,
"md5file", (Tcl_CmdProc*)md5file_cmd,
3894 MD5DigestToBase16, 0);
3895 Tcl_CreateCommand(interp,
"md5file-10x8", (Tcl_CmdProc*)md5file_cmd,
3896 MD5DigestToBase10x8, 0);
3901 #if defined(SQLITE_TEST) 3909 if( argc<1 )
return;
3915 for(i=0; i<argc; i++){
3918 MD5Update(p, (
unsigned char*)zData, (
int)strlen(zData));
3924 unsigned char digest[16];
3928 MD5DigestToBase16(digest, zBuf);
3937 md5step, md5finalize);
3951 static const char *tclsh_main_loop(
void){
3952 static const char zMainloop[] =
3954 "while {![eof stdin]} {\n" 3955 "if {$line!=\"\"} {\n" 3956 "puts -nonewline \"> \"\n" 3958 "puts -nonewline \"% \"\n" 3961 "append line [gets stdin]\n" 3962 "if {[info complete $line]} {\n" 3963 "if {[catch {uplevel #0 $line} result]} {\n" 3964 "puts stderr \"Error: $result\"\n" 3965 "} elseif {$result!=\"\"} {\n" 3978 static const char *tclsh_main_loop(
void);
3982 static void init_all(Tcl_Interp *);
3987 Tcl_Obj *CONST objv[]
3992 Tcl_WrongNumArgs(
interp, 1, objv,
"SLAVE");
3996 slave = Tcl_GetSlave(
interp, Tcl_GetString(objv[1]));
4017 Tcl_Obj *CONST objv[]
4019 Tcl_CmdInfo cmdInfo;
4024 Tcl_WrongNumArgs(
interp, 1, objv,
"DB BOOLEAN");
4028 if( !Tcl_GetCommandInfo(
interp, Tcl_GetString(objv[1]), &cmdInfo) ){
4029 Tcl_AppendResult(
interp,
"no such db: ", Tcl_GetString(objv[1]), (
char*)0);
4032 pDb = (
SqliteDb*)cmdInfo.objClientData;
4033 if( Tcl_GetBooleanFromObj(
interp, objv[2], &bPrepare) ){
4037 pDb->bLegacyPrepare = bPrepare;
4054 Tcl_Obj *CONST objv[]
4056 extern int sqlite3TestMakePointerStr(Tcl_Interp*,
char*,
void*);
4057 Tcl_CmdInfo cmdInfo;
4063 Tcl_WrongNumArgs(
interp, 1, objv,
"DB");
4067 if( !Tcl_GetCommandInfo(
interp, Tcl_GetString(objv[1]), &cmdInfo) ){
4068 Tcl_AppendResult(
interp,
"no such db: ", Tcl_GetString(objv[1]), (
char*)0);
4071 pDb = (
SqliteDb*)cmdInfo.objClientData;
4074 if( sqlite3TestMakePointerStr(
interp, zBuf, pStmt) ){
4077 Tcl_SetResult(
interp, zBuf, TCL_VOLATILE);
4094 static void init_all(Tcl_Interp *
interp){
4097 #if defined(SQLITE_TEST) || defined(SQLITE_TCLMD5) 4103 extern int Sqliteconfig_Init(Tcl_Interp*);
4104 extern int Sqlitetest1_Init(Tcl_Interp*);
4105 extern int Sqlitetest2_Init(Tcl_Interp*);
4106 extern int Sqlitetest3_Init(Tcl_Interp*);
4107 extern int Sqlitetest4_Init(Tcl_Interp*);
4108 extern int Sqlitetest5_Init(Tcl_Interp*);
4109 extern int Sqlitetest6_Init(Tcl_Interp*);
4110 extern int Sqlitetest7_Init(Tcl_Interp*);
4111 extern int Sqlitetest8_Init(Tcl_Interp*);
4112 extern int Sqlitetest9_Init(Tcl_Interp*);
4113 extern int Sqlitetestasync_Init(Tcl_Interp*);
4114 extern int Sqlitetest_autoext_Init(Tcl_Interp*);
4115 extern int Sqlitetest_blob_Init(Tcl_Interp*);
4116 extern int Sqlitetest_demovfs_Init(Tcl_Interp *);
4117 extern int Sqlitetest_func_Init(Tcl_Interp*);
4118 extern int Sqlitetest_hexio_Init(Tcl_Interp*);
4119 extern int Sqlitetest_init_Init(Tcl_Interp*);
4120 extern int Sqlitetest_malloc_Init(Tcl_Interp*);
4121 extern int Sqlitetest_mutex_Init(Tcl_Interp*);
4122 extern int Sqlitetestschema_Init(Tcl_Interp*);
4123 extern int Sqlitetestsse_Init(Tcl_Interp*);
4124 extern int Sqlitetesttclvar_Init(Tcl_Interp*);
4125 extern int Sqlitetestfs_Init(Tcl_Interp*);
4126 extern int SqlitetestThread_Init(Tcl_Interp*);
4127 extern int SqlitetestOnefile_Init();
4128 extern int SqlitetestOsinst_Init(Tcl_Interp*);
4129 extern int Sqlitetestbackup_Init(Tcl_Interp*);
4130 extern int Sqlitetestintarray_Init(Tcl_Interp*);
4131 extern int Sqlitetestvfs_Init(Tcl_Interp *);
4132 extern int Sqlitetestrtree_Init(Tcl_Interp*);
4133 extern int Sqlitequota_Init(Tcl_Interp*);
4134 extern int Sqlitemultiplex_Init(Tcl_Interp*);
4135 extern int SqliteSuperlock_Init(Tcl_Interp*);
4136 extern int SqlitetestSyscall_Init(Tcl_Interp*);
4137 #if defined(SQLITE_ENABLE_SESSION) && defined(SQLITE_ENABLE_PREUPDATE_HOOK) 4138 extern int TestSession_Init(Tcl_Interp*);
4140 extern int Fts5tcl_Init(Tcl_Interp *);
4141 extern int SqliteRbu_Init(Tcl_Interp*);
4142 extern int Sqlitetesttcl_Init(Tcl_Interp*);
4143 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) 4144 extern int Sqlitetestfts3_Init(Tcl_Interp *interp);
4147 #ifdef SQLITE_ENABLE_ZIPVFS 4148 extern int Zipvfs_Init(Tcl_Interp*);
4149 Zipvfs_Init(interp);
4152 Sqliteconfig_Init(interp);
4153 Sqlitetest1_Init(interp);
4154 Sqlitetest2_Init(interp);
4155 Sqlitetest3_Init(interp);
4156 Sqlitetest4_Init(interp);
4157 Sqlitetest5_Init(interp);
4158 Sqlitetest6_Init(interp);
4159 Sqlitetest7_Init(interp);
4160 Sqlitetest8_Init(interp);
4161 Sqlitetest9_Init(interp);
4162 Sqlitetestasync_Init(interp);
4163 Sqlitetest_autoext_Init(interp);
4164 Sqlitetest_blob_Init(interp);
4165 Sqlitetest_demovfs_Init(interp);
4166 Sqlitetest_func_Init(interp);
4167 Sqlitetest_hexio_Init(interp);
4168 Sqlitetest_init_Init(interp);
4169 Sqlitetest_malloc_Init(interp);
4170 Sqlitetest_mutex_Init(interp);
4171 Sqlitetestschema_Init(interp);
4172 Sqlitetesttclvar_Init(interp);
4173 Sqlitetestfs_Init(interp);
4174 SqlitetestThread_Init(interp);
4175 SqlitetestOnefile_Init();
4176 SqlitetestOsinst_Init(interp);
4177 Sqlitetestbackup_Init(interp);
4178 Sqlitetestintarray_Init(interp);
4179 Sqlitetestvfs_Init(interp);
4180 Sqlitetestrtree_Init(interp);
4181 Sqlitequota_Init(interp);
4182 Sqlitemultiplex_Init(interp);
4183 SqliteSuperlock_Init(interp);
4184 SqlitetestSyscall_Init(interp);
4185 #if defined(SQLITE_ENABLE_SESSION) && defined(SQLITE_ENABLE_PREUPDATE_HOOK) 4186 TestSession_Init(interp);
4188 Fts5tcl_Init(interp);
4189 SqliteRbu_Init(interp);
4190 Sqlitetesttcl_Init(interp);
4192 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) 4193 Sqlitetestfts3_Init(interp);
4196 Tcl_CreateObjCommand(
4197 interp,
"load_testfixture_extensions", init_all_cmd, 0, 0
4199 Tcl_CreateObjCommand(
4200 interp,
"db_use_legacy_prepare", db_use_legacy_prepare_cmd, 0, 0
4202 Tcl_CreateObjCommand(
4203 interp,
"db_last_stmt_ptr", db_last_stmt_ptr, 0, 0
4207 Sqlitetestsse_Init(interp);
4215 #include <sys/resource.h> 4218 #define TCLSH_MAIN main 4222 #if !defined(_WIN32_WCE) 4223 if( getenv(
"BREAK") ){
4225 "attach debugger to process %d and press any key to continue.\n",
4233 #if defined(SQLITE_TEST) && defined(unix) 4235 getrlimit(RLIMIT_CORE, &x);
4236 x.rlim_cur = x.rlim_max;
4237 setrlimit(RLIMIT_CORE, &x);
4247 Tcl_FindExecutable(argv[0]);
4248 Tcl_SetSystemEncoding(NULL,
"utf-8");
4249 interp = Tcl_CreateInterp();
4260 Tcl_SetVar(interp,
"argc", zArgc, TCL_GLOBAL_ONLY);
4261 Tcl_SetVar(interp,
"argv0",argv[1],TCL_GLOBAL_ONLY);
4262 Tcl_SetVar(interp,
"argv",
"", TCL_GLOBAL_ONLY);
4263 for(i=3-TCLSH; i<argc; i++){
4264 Tcl_SetVar(interp,
"argv", argv[i],
4265 TCL_GLOBAL_ONLY | TCL_LIST_ELEMENT | TCL_APPEND_VALUE);
4267 if( TCLSH==1 && Tcl_EvalFile(interp, argv[1])!=TCL_OK ){
4268 const char *zInfo = Tcl_GetVar(interp,
"errorInfo", TCL_GLOBAL_ONLY);
4269 if( zInfo==0 ) zInfo = Tcl_GetStringResult(interp);
4270 fprintf(stderr,
"%s: %s\n", *argv, zInfo);
4274 if( TCLSH==2 || argc<=1 ){
4275 Tcl_GlobalEval(interp, tclsh_main_loop());
#define sqlite3_aggregate_context
#define sqlite3_total_changes
#define Tcl_InitStubs(a, b, c)
#define SQLITE_DROP_VTABLE
#define sqlite3_blob_write
#define SQLITE_STMTSTATUS_AUTOINDEX
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_count(sqlite3 *)
static void tclCollateNeeded(void *pCtx, sqlite3 *db, int enc, const char *zName)
#define Tcl_NREvalObj(a, b, c)
#define sqlite3_set_authorizer
#define SQLITE_DROP_INDEX
#define SQLITE_CREATE_TRIGGER
#define sqlite3_unlock_notify
#define SQLITE_TRACE_PROFILE
static int DbWalHandler(void *clientData, sqlite3 *db, const char *zDb, int nEntry)
#define SQLITE_CREATE_VTABLE
#define SQLITE_STMTSTATUS_SORT
#define SQLITE_OPEN_NOMUTEX
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_depth(sqlite3 *)
#define sqlite3_value_double
#define sqlite3_backup_finish
#define setTestUnlockNotifyVars(x, y, z)
#define sqlite3_value_text
static void flushStmtCache(SqliteDb *pDb)
EXTERN int Tclsqlite3_Init(Tcl_Interp *interp)
static int dbEvalStep(DbEvalContext *p)
#define SQLITE_DROP_TEMP_INDEX
static int SQLITE_TCLAPI DbObjCmd(void *cd, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
#define sqlite3_backup_init
#define SQLITE_OPEN_READONLY
#define sqlite3_column_name
SQLITE_API int sqlite3_config(int,...)
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **)
#define sqlite3_update_hook
#define sqlite3_progress_handler
static int DbCommitHandler(void *cd)
#define SQLITE_CREATE_TABLE
#define sqlite3_result_int64
#define SQLITE_CREATE_TEMP_TRIGGER
int Sqlite_Unload(Tcl_Interp *interp, int flags)
static SqlFunc * findSqlFunc(SqliteDb *pDb, const char *zName)
SqlPreparedStmt * stmtList
SQLITE_API int sqlite3_shutdown(void)
static int dbPrepare(SqliteDb *pDb, const char *zSql, sqlite3_stmt **ppStmt, const char **pzOut)
static void SQLITE_TCLAPI incrblobWatch(ClientData instanceData, int mode)
static void dbReleaseStmt(SqliteDb *pDb, SqlPreparedStmt *pPreStmt, int discard)
#define sqlite3_create_function
int Tclsqlite_Init(Tcl_Interp *interp)
#define SQLITE_CREATE_VIEW
static void DbRollbackHandler(void *clientData)
#define sqlite3_column_int64
static int SQLITE_TCLAPI incrblobInput(ClientData instanceData, char *buf, int bufSize, int *errorCodePtr)
#define SQLITE_DETERMINISTIC
#define sqlite3_busy_handler
static void tclSqlFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
static int SQLITE_TCLAPI incrblobOutput(ClientData instanceData, CONST char *buf, int toWrite, int *errorCodePtr)
#define sqlite3_blob_bytes
static void DbUpdateHandler(void *p, int op, const char *zDb, const char *zTbl, sqlite_int64 rowid)
SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff)
static int strlen30(const char *z)
static int DbTraceV2Handler(unsigned type, void *cd, void *pd, void *xd)
#define sqlite3_value_type
#define sqlite3_column_text
static int createIncrblobChannel(Tcl_Interp *interp, SqliteDb *pDb, const char *zDb, const char *zTable, const char *zColumn, sqlite_int64 iRow, int isReadonly)
int Sqlite_Init(Tcl_Interp *interp)
#define sqlite3_blob_read
#define sqlite3_result_error
static int DbBusyHandler(void *cd, int nTries)
#define sqlite3_rollback_hook
#define SQLITE_OPEN_CREATE
IncrblobChannel * pIncrblob
static int auth_callback(void *pArg, int code, const char *zArg1, const char *zArg2, const char *zArg3, const char *zArg4)
struct sqlite3_stmt sqlite3_stmt
#define sqlite3_result_int
EXTERN int Sqlite3_Unload(Tcl_Interp *interp, int flags)
#define sqlite3_bind_int64
#define SQLITE_OPEN_READWRITE
static int tclSqlCollate(void *pCtx, int nA, const void *zA, int nB, const void *zB)
sqlite_int64 sqlite3_int64
#define sqlite3_bind_double
#define sqlite3_user_data
#define sqlite3_blob_open
#define sqlite3_libversion
#define sqlite3_commit_hook
#define sqlite3_value_blob
int Tclsqlite_Unload(Tcl_Interp *interp, int flags)
#define sqlite3_last_insert_rowid
static void dbEvalFinalize(DbEvalContext *p)
#define sqlite3_bind_null
#define sqlite3_result_text
#define sqlite3_value_int64
#define MAX_PREPARED_STMTS
EXTERN int Tclsqlite3_Unload(Tcl_Interp *interp, int flags)
#define SQLITE_TRACE_CLOSE
TFSIMD_FORCE_INLINE const tfScalar & x() const
#define sqlite3_column_count
SqlPreparedStmt * stmtLast
static int DbProgressHandler(void *cd)
#define sqlite3_bind_parameter_count
static Tcl_Obj * dbEvalColumnValue(DbEvalContext *p, int iCol)
static void DbTraceHandler(void *cd, const char *zSql)
#define sqlite3_interrupt
EXTERN int Sqlite3_SafeUnload(Tcl_Interp *interp, int flags)
#define sqlite3_column_type
#define sqlite3_bind_blob
#define sqlite3_column_double
static int SQLITE_TCLAPI incrblobClose(ClientData instanceData, Tcl_Interp *interp)
static int SQLITE_TCLAPI DbEvalNextCmd(ClientData data[], Tcl_Interp *interp, int result)
TFSIMD_FORCE_INLINE const tfScalar & z() const
static void dbEvalInit(DbEvalContext *p, SqliteDb *pDb, Tcl_Obj *pSql, Tcl_Obj *pArray)
#define SQLITE_OPEN_FULLMUTEX
#define sqlite3_overload_function
static void closeIncrblobChannels(SqliteDb *pDb)
SQLITE_API SQLITE_EXPERIMENTAL void * sqlite3_preupdate_hook(sqlite3 *db, void(*xPreUpdate)(void *pCtx, sqlite3 *db, int op, char const *zDb, char const *zName, sqlite3_int64 iKey1, sqlite3_int64 iKey2), void *)
static int dbPrepareAndBind(SqliteDb *pDb, char const *zIn, char const **pzOut, SqlPreparedStmt **ppPreStmt)
#define sqlite3_result_double
#define sqlite3_prepare_v2
#define SQLITE_DROP_TEMP_VIEW
long long int sqlite_int64
#define SQLITE_TRACE_STMT
static int SQLITE_TCLAPI incrblobHandle(ClientData instanceData, int dir, ClientData *hPtr)
static int SQLITE_TCLAPI incrblobSeek(ClientData instanceData, long offset, int seekMode, int *errorCodePtr)
#define SQLITE_CONFIG_SINGLETHREAD
static int SQLITE_TCLAPI DbMain(void *cd, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
static Tcl_ChannelType IncrblobChannelType
#define Tcl_NRCreateCommand(a, b, c, d, e, f)
#define SQLITE_CREATE_TEMP_VIEW
#define Tcl_NRAddCallback(a, b, c, d, e, f)
static void dbReleaseColumnNames(DbEvalContext *p)
#define sqlite3_result_blob
static void SQLITE_TCLAPI DbDeleteCmd(void *db)
static int safeToUseEvalObjv(Tcl_Interp *interp, Tcl_Obj *pCmd)
#define sqlite3_blob_close
EXTERN int Sqlite3_Init(Tcl_Interp *interp)
#define SQLITE_DROP_TABLE
#define sqlite3_create_collation
#define sqlite3_busy_timeout
#define NUM_PREPARED_STMTS
#define SQLITE_CREATE_INDEX
struct SqlPreparedStmt SqlPreparedStmt
#define sqlite3_stmt_status
#define SQLITE_ALTER_TABLE
EXTERN int Sqlite3_SafeInit(Tcl_Interp *interp)
#define SQLITE_CREATE_TEMP_INDEX
struct sqlite3_blob sqlite3_blob
#define sqlite3_column_bytes
static void dbFreeStmt(SqlPreparedStmt *pStmt)
#define SQLITE_DROP_TEMP_TABLE
#define sqlite3_backup_step
#define SQLITE_DROP_TRIGGER
static void dbEvalRowInfo(DbEvalContext *p, int *pnCol, Tcl_Obj ***papColName)
#define SQLITE_CREATE_TEMP_TABLE
#define SQLITE_STMTSTATUS_FULLSCAN_STEP
#define sqlite3_bind_text
#define SQLITE_DROP_TEMP_TRIGGER
#define sqlite3_bind_parameter_name
static void DbProfileHandler(void *cd, const char *zSql, sqlite_uint64 tm)
SqlPreparedStmt * pPreStmt
static char * local_getline(char *zPrompt, FILE *in)
#define SQLITE_TRANSACTION
unsigned long long int sqlite_uint64
#define sqlite3_value_bytes
#define sqlite3_column_blob
#define sqlite3_collation_needed
static int SQLITE_TCLAPI DbTransPostCmd(ClientData data[], Tcl_Interp *interp, int result)
static void DbHookCmd(Tcl_Interp *interp, SqliteDb *pDb, Tcl_Obj *pArg, Tcl_Obj **ppHook)
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **)