xref: /sqlite-3.40.0/src/test_thread.c (revision 3374f8ae)
1 /*
2 ** 2007 September 9
3 **
4 ** The author disclaims copyright to this source code.  In place of
5 ** a legal notice, here is a blessing:
6 **
7 **    May you do good and not evil.
8 **    May you find forgiveness for yourself and forgive others.
9 **    May you share freely, never taking more than you give.
10 **
11 *************************************************************************
12 **
13 ** This file contains the implementation of some Tcl commands used to
14 ** test that sqlite3 database handles may be concurrently accessed by
15 ** multiple threads. Right now this only works on unix.
16 */
17 
18 #include "sqliteInt.h"
19 #include <tcl.h>
20 
21 #if SQLITE_THREADSAFE
22 
23 #include <errno.h>
24 
25 #if !defined(_MSC_VER)
26 #include <unistd.h>
27 #endif
28 
29 /*
30 ** One of these is allocated for each thread created by [sqlthread spawn].
31 */
32 typedef struct SqlThread SqlThread;
33 struct SqlThread {
34   Tcl_ThreadId parent;     /* Thread id of parent thread */
35   Tcl_Interp *interp;      /* Parent interpreter */
36   char *zScript;           /* The script to execute. */
37   char *zVarname;          /* Varname in parent script */
38 };
39 
40 /*
41 ** A custom Tcl_Event type used by this module. When the event is
42 ** handled, script zScript is evaluated in interpreter interp. If
43 ** the evaluation throws an exception (returns TCL_ERROR), then the
44 ** error is handled by Tcl_BackgroundError(). If no error occurs,
45 ** the result is simply discarded.
46 */
47 typedef struct EvalEvent EvalEvent;
48 struct EvalEvent {
49   Tcl_Event base;          /* Base class of type Tcl_Event */
50   char *zScript;           /* The script to execute. */
51   Tcl_Interp *interp;      /* The interpreter to execute it in. */
52 };
53 
54 static Tcl_ObjCmdProc sqlthread_proc;
55 static Tcl_ObjCmdProc clock_seconds_proc;
56 #if defined(SQLITE_OS_UNIX) && defined(SQLITE_ENABLE_UNLOCK_NOTIFY)
57 static Tcl_ObjCmdProc blocking_step_proc;
58 static Tcl_ObjCmdProc blocking_prepare_v2_proc;
59 #endif
60 int Sqlitetest1_Init(Tcl_Interp *);
61 int Sqlite3_Init(Tcl_Interp *);
62 
63 /* Functions from test1.c */
64 void *sqlite3TestTextToPtr(const char *);
65 const char *sqlite3TestErrorName(int);
66 int getDbPointer(Tcl_Interp *, const char *, sqlite3 **);
67 int sqlite3TestMakePointerStr(Tcl_Interp *, char *, void *);
68 int sqlite3TestErrCode(Tcl_Interp *, sqlite3 *, int);
69 
70 /*
71 ** Handler for events of type EvalEvent.
72 */
73 static int tclScriptEvent(Tcl_Event *evPtr, int flags){
74   int rc;
75   EvalEvent *p = (EvalEvent *)evPtr;
76   rc = Tcl_Eval(p->interp, p->zScript);
77   if( rc!=TCL_OK ){
78     Tcl_BackgroundError(p->interp);
79   }
80   UNUSED_PARAMETER(flags);
81   return 1;
82 }
83 
84 /*
85 ** Register an EvalEvent to evaluate the script pScript in the
86 ** parent interpreter/thread of SqlThread p.
87 */
88 static void postToParent(SqlThread *p, Tcl_Obj *pScript){
89   EvalEvent *pEvent;
90   char *zMsg;
91   int nMsg;
92 
93   zMsg = Tcl_GetStringFromObj(pScript, &nMsg);
94   pEvent = (EvalEvent *)ckalloc(sizeof(EvalEvent)+nMsg+1);
95   pEvent->base.nextPtr = 0;
96   pEvent->base.proc = tclScriptEvent;
97   pEvent->zScript = (char *)&pEvent[1];
98   memcpy(pEvent->zScript, zMsg, nMsg+1);
99   pEvent->interp = p->interp;
100 
101   Tcl_ThreadQueueEvent(p->parent, (Tcl_Event *)pEvent, TCL_QUEUE_TAIL);
102   Tcl_ThreadAlert(p->parent);
103 }
104 
105 /*
106 ** The main function for threads created with [sqlthread spawn].
107 */
108 static Tcl_ThreadCreateType tclScriptThread(ClientData pSqlThread){
109   Tcl_Interp *interp;
110   Tcl_Obj *pRes;
111   Tcl_Obj *pList;
112   int rc;
113   SqlThread *p = (SqlThread *)pSqlThread;
114   extern int Sqlitetest_mutex_Init(Tcl_Interp*);
115 
116   interp = Tcl_CreateInterp();
117   Tcl_CreateObjCommand(interp, "clock_seconds", clock_seconds_proc, 0, 0);
118   Tcl_CreateObjCommand(interp, "sqlthread", sqlthread_proc, pSqlThread, 0);
119 #if defined(SQLITE_OS_UNIX) && defined(SQLITE_ENABLE_UNLOCK_NOTIFY)
120   Tcl_CreateObjCommand(interp, "sqlite3_blocking_step", blocking_step_proc,0,0);
121   Tcl_CreateObjCommand(interp,
122       "sqlite3_blocking_prepare_v2", blocking_prepare_v2_proc, (void *)1, 0);
123   Tcl_CreateObjCommand(interp,
124       "sqlite3_nonblocking_prepare_v2", blocking_prepare_v2_proc, 0, 0);
125 #endif
126   Sqlitetest1_Init(interp);
127   Sqlitetest_mutex_Init(interp);
128   Sqlite3_Init(interp);
129 
130   rc = Tcl_Eval(interp, p->zScript);
131   pRes = Tcl_GetObjResult(interp);
132   pList = Tcl_NewObj();
133   Tcl_IncrRefCount(pList);
134   Tcl_IncrRefCount(pRes);
135 
136   if( rc!=TCL_OK ){
137     Tcl_ListObjAppendElement(interp, pList, Tcl_NewStringObj("error", -1));
138     Tcl_ListObjAppendElement(interp, pList, pRes);
139     postToParent(p, pList);
140     Tcl_DecrRefCount(pList);
141     pList = Tcl_NewObj();
142   }
143 
144   Tcl_ListObjAppendElement(interp, pList, Tcl_NewStringObj("set", -1));
145   Tcl_ListObjAppendElement(interp, pList, Tcl_NewStringObj(p->zVarname, -1));
146   Tcl_ListObjAppendElement(interp, pList, pRes);
147   postToParent(p, pList);
148 
149   ckfree((void *)p);
150   Tcl_DecrRefCount(pList);
151   Tcl_DecrRefCount(pRes);
152   Tcl_DeleteInterp(interp);
153   Tcl_ExitThread(0);
154   TCL_THREAD_CREATE_RETURN;
155 }
156 
157 /*
158 ** sqlthread spawn VARNAME SCRIPT
159 **
160 **     Spawn a new thread with its own Tcl interpreter and run the
161 **     specified SCRIPT(s) in it. The thread terminates after running
162 **     the script. The result of the script is stored in the variable
163 **     VARNAME.
164 **
165 **     The caller can wait for the script to terminate using [vwait VARNAME].
166 */
167 static int sqlthread_spawn(
168   ClientData clientData,
169   Tcl_Interp *interp,
170   int objc,
171   Tcl_Obj *CONST objv[]
172 ){
173   Tcl_ThreadId x;
174   SqlThread *pNew;
175   int rc;
176 
177   int nVarname; char *zVarname;
178   int nScript; char *zScript;
179 
180   /* Parameters for thread creation */
181   const int nStack = TCL_THREAD_STACK_DEFAULT;
182   const int flags = TCL_THREAD_NOFLAGS;
183 
184   assert(objc==4);
185   UNUSED_PARAMETER(clientData);
186   UNUSED_PARAMETER(objc);
187 
188   zVarname = Tcl_GetStringFromObj(objv[2], &nVarname);
189   zScript = Tcl_GetStringFromObj(objv[3], &nScript);
190 
191   pNew = (SqlThread *)ckalloc(sizeof(SqlThread)+nVarname+nScript+2);
192   pNew->zVarname = (char *)&pNew[1];
193   pNew->zScript = (char *)&pNew->zVarname[nVarname+1];
194   memcpy(pNew->zVarname, zVarname, nVarname+1);
195   memcpy(pNew->zScript, zScript, nScript+1);
196   pNew->parent = Tcl_GetCurrentThread();
197   pNew->interp = interp;
198 
199   rc = Tcl_CreateThread(&x, tclScriptThread, (void *)pNew, nStack, flags);
200   if( rc!=TCL_OK ){
201     Tcl_AppendResult(interp, "Error in Tcl_CreateThread()", 0);
202     ckfree((char *)pNew);
203     return TCL_ERROR;
204   }
205 
206   return TCL_OK;
207 }
208 
209 /*
210 ** sqlthread parent SCRIPT
211 **
212 **     This can be called by spawned threads only. It sends the specified
213 **     script back to the parent thread for execution. The result of
214 **     evaluating the SCRIPT is returned. The parent thread must enter
215 **     the event loop for this to work - otherwise the caller will
216 **     block indefinitely.
217 **
218 **     NOTE: At the moment, this doesn't work. FIXME.
219 */
220 static int sqlthread_parent(
221   ClientData clientData,
222   Tcl_Interp *interp,
223   int objc,
224   Tcl_Obj *CONST objv[]
225 ){
226   EvalEvent *pEvent;
227   char *zMsg;
228   int nMsg;
229   SqlThread *p = (SqlThread *)clientData;
230 
231   assert(objc==3);
232   UNUSED_PARAMETER(objc);
233 
234   if( p==0 ){
235     Tcl_AppendResult(interp, "no parent thread", 0);
236     return TCL_ERROR;
237   }
238 
239   zMsg = Tcl_GetStringFromObj(objv[2], &nMsg);
240   pEvent = (EvalEvent *)ckalloc(sizeof(EvalEvent)+nMsg+1);
241   pEvent->base.nextPtr = 0;
242   pEvent->base.proc = tclScriptEvent;
243   pEvent->zScript = (char *)&pEvent[1];
244   memcpy(pEvent->zScript, zMsg, nMsg+1);
245   pEvent->interp = p->interp;
246   Tcl_ThreadQueueEvent(p->parent, (Tcl_Event *)pEvent, TCL_QUEUE_TAIL);
247   Tcl_ThreadAlert(p->parent);
248 
249   return TCL_OK;
250 }
251 
252 static int xBusy(void *pArg, int nBusy){
253   UNUSED_PARAMETER(pArg);
254   UNUSED_PARAMETER(nBusy);
255   sqlite3_sleep(50);
256   return 1;             /* Try again... */
257 }
258 
259 /*
260 ** sqlthread open
261 **
262 **     Open a database handle and return the string representation of
263 **     the pointer value.
264 */
265 static int sqlthread_open(
266   ClientData clientData,
267   Tcl_Interp *interp,
268   int objc,
269   Tcl_Obj *CONST objv[]
270 ){
271   int sqlite3TestMakePointerStr(Tcl_Interp *interp, char *zPtr, void *p);
272 
273   const char *zFilename;
274   sqlite3 *db;
275   int rc;
276   char zBuf[100];
277   extern void Md5_Register(sqlite3*);
278 
279   UNUSED_PARAMETER(clientData);
280   UNUSED_PARAMETER(objc);
281 
282   zFilename = Tcl_GetString(objv[2]);
283   rc = sqlite3_open(zFilename, &db);
284   Md5_Register(db);
285   sqlite3_busy_handler(db, xBusy, 0);
286 
287   if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR;
288   Tcl_AppendResult(interp, zBuf, 0);
289 
290   return TCL_OK;
291 }
292 
293 
294 /*
295 ** sqlthread open
296 **
297 **     Return the current thread-id (Tcl_GetCurrentThread()) cast to
298 **     an integer.
299 */
300 static int sqlthread_id(
301   ClientData clientData,
302   Tcl_Interp *interp,
303   int objc,
304   Tcl_Obj *CONST objv[]
305 ){
306   Tcl_ThreadId id = Tcl_GetCurrentThread();
307   Tcl_SetObjResult(interp, Tcl_NewIntObj((int)id));
308   UNUSED_PARAMETER(clientData);
309   UNUSED_PARAMETER(objc);
310   UNUSED_PARAMETER(objv);
311   return TCL_OK;
312 }
313 
314 
315 /*
316 ** Dispatch routine for the sub-commands of [sqlthread].
317 */
318 static int sqlthread_proc(
319   ClientData clientData,
320   Tcl_Interp *interp,
321   int objc,
322   Tcl_Obj *CONST objv[]
323 ){
324   struct SubCommand {
325     char *zName;
326     Tcl_ObjCmdProc *xProc;
327     int nArg;
328     char *zUsage;
329   } aSub[] = {
330     {"parent", sqlthread_parent, 1, "SCRIPT"},
331     {"spawn",  sqlthread_spawn,  2, "VARNAME SCRIPT"},
332     {"open",   sqlthread_open,   1, "DBNAME"},
333     {"id",     sqlthread_id,     0, ""},
334     {0, 0, 0}
335   };
336   struct SubCommand *pSub;
337   int rc;
338   int iIndex;
339 
340   if( objc<2 ){
341     Tcl_WrongNumArgs(interp, 1, objv, "SUB-COMMAND");
342     return TCL_ERROR;
343   }
344 
345   rc = Tcl_GetIndexFromObjStruct(
346       interp, objv[1], aSub, sizeof(aSub[0]), "sub-command", 0, &iIndex
347   );
348   if( rc!=TCL_OK ) return rc;
349   pSub = &aSub[iIndex];
350 
351   if( objc!=(pSub->nArg+2) ){
352     Tcl_WrongNumArgs(interp, 2, objv, pSub->zUsage);
353     return TCL_ERROR;
354   }
355 
356   return pSub->xProc(clientData, interp, objc, objv);
357 }
358 
359 /*
360 ** The [clock_seconds] command. This is more or less the same as the
361 ** regular tcl [clock seconds], except that it is available in testfixture
362 ** when linked against both Tcl 8.4 and 8.5. Because [clock seconds] is
363 ** implemented as a script in Tcl 8.5, it is not usually available to
364 ** testfixture.
365 */
366 static int clock_seconds_proc(
367   ClientData clientData,
368   Tcl_Interp *interp,
369   int objc,
370   Tcl_Obj *CONST objv[]
371 ){
372   Tcl_Time now;
373   Tcl_GetTime(&now);
374   Tcl_SetObjResult(interp, Tcl_NewIntObj(now.sec));
375   UNUSED_PARAMETER(clientData);
376   UNUSED_PARAMETER(objc);
377   UNUSED_PARAMETER(objv);
378   return TCL_OK;
379 }
380 
381 /*************************************************************************
382 ** This block contains the implementation of the [sqlite3_blocking_step]
383 ** command available to threads created by [sqlthread spawn] commands. It
384 ** is only available on UNIX for now. This is because pthread condition
385 ** variables are used.
386 **
387 ** The source code for the C functions sqlite3_blocking_step(),
388 ** blocking_step_notify() and the structure UnlockNotification is
389 ** automatically extracted from this file and used as part of the
390 ** documentation for the sqlite3_unlock_notify() API function. This
391 ** should be considered if these functions are to be extended (i.e. to
392 ** support windows) in the future.
393 */
394 #if defined(SQLITE_OS_UNIX) && defined(SQLITE_ENABLE_UNLOCK_NOTIFY)
395 
396 /* BEGIN_SQLITE_BLOCKING_STEP */
397 /* This example uses the pthreads API */
398 #include <pthread.h>
399 
400 /*
401 ** A pointer to an instance of this structure is passed as the user-context
402 ** pointer when registering for an unlock-notify callback.
403 */
404 typedef struct UnlockNotification UnlockNotification;
405 struct UnlockNotification {
406   int fired;                           /* True after unlock event has occured */
407   pthread_cond_t cond;                 /* Condition variable to wait on */
408   pthread_mutex_t mutex;               /* Mutex to protect structure */
409 };
410 
411 /*
412 ** This function is an unlock-notify callback registered with SQLite.
413 */
414 static void unlock_notify_cb(void **apArg, int nArg){
415   int i;
416   for(i=0; i<nArg; i++){
417     UnlockNotification *p = (UnlockNotification *)apArg[i];
418     pthread_mutex_lock(&p->mutex);
419     p->fired = 1;
420     pthread_cond_signal(&p->cond);
421     pthread_mutex_unlock(&p->mutex);
422   }
423 }
424 
425 /*
426 ** This function assumes that an SQLite API call (either sqlite3_prepare_v2()
427 ** or sqlite3_step()) has just returned SQLITE_LOCKED. The argument is the
428 ** associated database connection.
429 **
430 ** This function calls sqlite3_unlock_notify() to register for an
431 ** unlock-notify callback, then blocks until that callback is delivered
432 ** and returns SQLITE_OK. The caller should then retry the failed operation.
433 **
434 ** Or, if sqlite3_unlock_notify() indicates that to block would deadlock
435 ** the system, then this function returns SQLITE_LOCKED immediately. In
436 ** this case the caller should not retry the operation and should roll
437 ** back the current transaction (if any).
438 */
439 static int wait_for_unlock_notify(sqlite3 *db){
440   int rc;
441   UnlockNotification un;
442 
443   /* Initialize the UnlockNotification structure. */
444   un.fired = 0;
445   pthread_mutex_init(&un.mutex, 0);
446   pthread_cond_init(&un.cond, 0);
447 
448   /* Register for an unlock-notify callback. */
449   rc = sqlite3_unlock_notify(db, unlock_notify_cb, (void *)&un);
450   assert( rc==SQLITE_LOCKED || rc==SQLITE_OK );
451 
452   /* The call to sqlite3_unlock_notify() always returns either SQLITE_LOCKED
453   ** or SQLITE_OK.
454   **
455   ** If SQLITE_LOCKED was returned, then the system is deadlocked. In this
456   ** case this function needs to return SQLITE_LOCKED to the caller so
457   ** that the current transaction can be rolled back. Otherwise, block
458   ** until the unlock-notify callback is invoked, then return SQLITE_OK.
459   */
460   if( rc==SQLITE_OK ){
461     pthread_mutex_lock(&un.mutex);
462     if( !un.fired ){
463       pthread_cond_wait(&un.cond, &un.mutex);
464     }
465     pthread_mutex_unlock(&un.mutex);
466   }
467 
468   /* Destroy the mutex and condition variables. */
469   pthread_cond_destroy(&un.cond);
470   pthread_mutex_destroy(&un.mutex);
471 
472   return rc;
473 }
474 
475 /*
476 ** This function is a wrapper around the SQLite function sqlite3_step().
477 ** It functions in the same way as step(), except that if a required
478 ** shared-cache lock cannot be obtained, this function may block waiting for
479 ** the lock to become available. In this scenario the normal API step()
480 ** function always returns SQLITE_LOCKED.
481 **
482 ** If this function returns SQLITE_LOCKED, the caller should rollback
483 ** the current transaction (if any) and try again later. Otherwise, the
484 ** system may become deadlocked.
485 */
486 int sqlite3_blocking_step(sqlite3_stmt *pStmt){
487   int rc;
488   while( SQLITE_LOCKED==(rc = sqlite3_step(pStmt)) ){
489     rc = wait_for_unlock_notify(sqlite3_db_handle(pStmt));
490     if( rc!=SQLITE_OK ) break;
491     sqlite3_reset(pStmt);
492   }
493   return rc;
494 }
495 
496 /*
497 ** This function is a wrapper around the SQLite function sqlite3_prepare_v2().
498 ** It functions in the same way as prepare_v2(), except that if a required
499 ** shared-cache lock cannot be obtained, this function may block waiting for
500 ** the lock to become available. In this scenario the normal API prepare_v2()
501 ** function always returns SQLITE_LOCKED.
502 **
503 ** If this function returns SQLITE_LOCKED, the caller should rollback
504 ** the current transaction (if any) and try again later. Otherwise, the
505 ** system may become deadlocked.
506 */
507 int sqlite3_blocking_prepare_v2(
508   sqlite3 *db,              /* Database handle. */
509   const char *zSql,         /* UTF-8 encoded SQL statement. */
510   int nSql,                 /* Length of zSql in bytes. */
511   sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
512   const char **pz           /* OUT: End of parsed string */
513 ){
514   int rc;
515   while( SQLITE_LOCKED==(rc = sqlite3_prepare_v2(db, zSql, nSql, ppStmt, pz)) ){
516     rc = wait_for_unlock_notify(db);
517     if( rc!=SQLITE_OK ) break;
518   }
519   return rc;
520 }
521 /* END_SQLITE_BLOCKING_STEP */
522 
523 /*
524 ** Usage: sqlite3_blocking_step STMT
525 **
526 ** Advance the statement to the next row.
527 */
528 static int blocking_step_proc(
529   void * clientData,
530   Tcl_Interp *interp,
531   int objc,
532   Tcl_Obj *CONST objv[]
533 ){
534 
535   sqlite3_stmt *pStmt;
536   int rc;
537 
538   if( objc!=2 ){
539     Tcl_WrongNumArgs(interp, 1, objv, "STMT");
540     return TCL_ERROR;
541   }
542 
543   pStmt = (sqlite3_stmt*)sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
544   rc = sqlite3_blocking_step(pStmt);
545 
546   Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), 0);
547   return TCL_OK;
548 }
549 
550 /*
551 ** Usage: sqlite3_blocking_prepare_v2 DB sql bytes ?tailvar?
552 ** Usage: sqlite3_nonblocking_prepare_v2 DB sql bytes ?tailvar?
553 */
554 static int blocking_prepare_v2_proc(
555   void * clientData,
556   Tcl_Interp *interp,
557   int objc,
558   Tcl_Obj *CONST objv[]
559 ){
560   sqlite3 *db;
561   const char *zSql;
562   int bytes;
563   const char *zTail = 0;
564   sqlite3_stmt *pStmt = 0;
565   char zBuf[50];
566   int rc;
567   int isBlocking = !(clientData==0);
568 
569   if( objc!=5 && objc!=4 ){
570     Tcl_AppendResult(interp, "wrong # args: should be \"",
571        Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0);
572     return TCL_ERROR;
573   }
574   if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
575   zSql = Tcl_GetString(objv[2]);
576   if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR;
577 
578   if( isBlocking ){
579     rc = sqlite3_blocking_prepare_v2(db, zSql, bytes, &pStmt, &zTail);
580   }else{
581     rc = sqlite3_prepare_v2(db, zSql, bytes, &pStmt, &zTail);
582   }
583 
584   assert(rc==SQLITE_OK || pStmt==0);
585   if( zTail && objc>=5 ){
586     if( bytes>=0 ){
587       bytes = bytes - (zTail-zSql);
588     }
589     Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0);
590   }
591   if( rc!=SQLITE_OK ){
592     assert( pStmt==0 );
593     sprintf(zBuf, "%s ", (char *)sqlite3TestErrorName(rc));
594     Tcl_AppendResult(interp, zBuf, sqlite3_errmsg(db), 0);
595     return TCL_ERROR;
596   }
597 
598   if( pStmt ){
599     if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
600     Tcl_AppendResult(interp, zBuf, 0);
601   }
602   return TCL_OK;
603 }
604 
605 #endif /* SQLITE_OS_UNIX && SQLITE_ENABLE_UNLOCK_NOTIFY */
606 /*
607 ** End of implementation of [sqlite3_blocking_step].
608 ************************************************************************/
609 
610 /*
611 ** Register commands with the TCL interpreter.
612 */
613 int SqlitetestThread_Init(Tcl_Interp *interp){
614   Tcl_CreateObjCommand(interp, "sqlthread", sqlthread_proc, 0, 0);
615   Tcl_CreateObjCommand(interp, "clock_seconds", clock_seconds_proc, 0, 0);
616 #if defined(SQLITE_OS_UNIX) && defined(SQLITE_ENABLE_UNLOCK_NOTIFY)
617   Tcl_CreateObjCommand(interp, "sqlite3_blocking_step", blocking_step_proc,0,0);
618   Tcl_CreateObjCommand(interp,
619       "sqlite3_blocking_prepare_v2", blocking_prepare_v2_proc, (void *)1, 0);
620   Tcl_CreateObjCommand(interp,
621       "sqlite3_nonblocking_prepare_v2", blocking_prepare_v2_proc, 0, 0);
622 #endif
623   return TCL_OK;
624 }
625 #else
626 int SqlitetestThread_Init(Tcl_Interp *interp){
627   return TCL_OK;
628 }
629 #endif
630