OLD | NEW |
1 /* | 1 /* |
2 ** 2007 September 9 | 2 ** 2007 September 9 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 static Tcl_ObjCmdProc sqlthread_proc; | 54 static Tcl_ObjCmdProc sqlthread_proc; |
55 static Tcl_ObjCmdProc clock_seconds_proc; | 55 static Tcl_ObjCmdProc clock_seconds_proc; |
56 #if SQLITE_OS_UNIX && defined(SQLITE_ENABLE_UNLOCK_NOTIFY) | 56 #if SQLITE_OS_UNIX && defined(SQLITE_ENABLE_UNLOCK_NOTIFY) |
57 static Tcl_ObjCmdProc blocking_step_proc; | 57 static Tcl_ObjCmdProc blocking_step_proc; |
58 static Tcl_ObjCmdProc blocking_prepare_v2_proc; | 58 static Tcl_ObjCmdProc blocking_prepare_v2_proc; |
59 #endif | 59 #endif |
60 int Sqlitetest1_Init(Tcl_Interp *); | 60 int Sqlitetest1_Init(Tcl_Interp *); |
61 int Sqlite3_Init(Tcl_Interp *); | 61 int Sqlite3_Init(Tcl_Interp *); |
62 | 62 |
| 63 /* Functions from main.c */ |
| 64 extern const char *sqlite3ErrName(int); |
| 65 |
63 /* Functions from test1.c */ | 66 /* Functions from test1.c */ |
64 void *sqlite3TestTextToPtr(const char *); | 67 extern void *sqlite3TestTextToPtr(const char *); |
65 const char *sqlite3TestErrorName(int); | 68 extern int getDbPointer(Tcl_Interp *, const char *, sqlite3 **); |
66 int getDbPointer(Tcl_Interp *, const char *, sqlite3 **); | 69 extern int sqlite3TestMakePointerStr(Tcl_Interp *, char *, void *); |
67 int sqlite3TestMakePointerStr(Tcl_Interp *, char *, void *); | 70 extern int sqlite3TestErrCode(Tcl_Interp *, sqlite3 *, int); |
68 int sqlite3TestErrCode(Tcl_Interp *, sqlite3 *, int); | |
69 | 71 |
70 /* | 72 /* |
71 ** Handler for events of type EvalEvent. | 73 ** Handler for events of type EvalEvent. |
72 */ | 74 */ |
73 static int tclScriptEvent(Tcl_Event *evPtr, int flags){ | 75 static int tclScriptEvent(Tcl_Event *evPtr, int flags){ |
74 int rc; | 76 int rc; |
75 EvalEvent *p = (EvalEvent *)evPtr; | 77 EvalEvent *p = (EvalEvent *)evPtr; |
76 rc = Tcl_Eval(p->interp, p->zScript); | 78 rc = Tcl_Eval(p->interp, p->zScript); |
77 if( rc!=TCL_OK ){ | 79 if( rc!=TCL_OK ){ |
78 Tcl_BackgroundError(p->interp); | 80 Tcl_BackgroundError(p->interp); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 static int sqlthread_open( | 268 static int sqlthread_open( |
267 ClientData clientData, | 269 ClientData clientData, |
268 Tcl_Interp *interp, | 270 Tcl_Interp *interp, |
269 int objc, | 271 int objc, |
270 Tcl_Obj *CONST objv[] | 272 Tcl_Obj *CONST objv[] |
271 ){ | 273 ){ |
272 int sqlite3TestMakePointerStr(Tcl_Interp *interp, char *zPtr, void *p); | 274 int sqlite3TestMakePointerStr(Tcl_Interp *interp, char *zPtr, void *p); |
273 | 275 |
274 const char *zFilename; | 276 const char *zFilename; |
275 sqlite3 *db; | 277 sqlite3 *db; |
276 int rc; | |
277 char zBuf[100]; | 278 char zBuf[100]; |
278 extern void Md5_Register(sqlite3*); | 279 extern void Md5_Register(sqlite3*); |
279 | 280 |
280 UNUSED_PARAMETER(clientData); | 281 UNUSED_PARAMETER(clientData); |
281 UNUSED_PARAMETER(objc); | 282 UNUSED_PARAMETER(objc); |
282 | 283 |
283 zFilename = Tcl_GetString(objv[2]); | 284 zFilename = Tcl_GetString(objv[2]); |
284 rc = sqlite3_open(zFilename, &db); | 285 sqlite3_open(zFilename, &db); |
| 286 #ifdef SQLITE_HAS_CODEC |
| 287 if( db && objc>=4 ){ |
| 288 const char *zKey; |
| 289 int nKey; |
| 290 int rc; |
| 291 zKey = Tcl_GetStringFromObj(objv[3], &nKey); |
| 292 rc = sqlite3_key(db, zKey, nKey); |
| 293 if( rc!=SQLITE_OK ){ |
| 294 char *zErrMsg = sqlite3_mprintf("error %d: %s", rc, sqlite3_errmsg(db)); |
| 295 sqlite3_close(db); |
| 296 Tcl_AppendResult(interp, zErrMsg, (char*)0); |
| 297 sqlite3_free(zErrMsg); |
| 298 return TCL_ERROR; |
| 299 } |
| 300 } |
| 301 #endif |
285 Md5_Register(db); | 302 Md5_Register(db); |
286 sqlite3_busy_handler(db, xBusy, 0); | 303 sqlite3_busy_handler(db, xBusy, 0); |
287 | 304 |
288 if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR; | 305 if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR; |
289 Tcl_AppendResult(interp, zBuf, 0); | 306 Tcl_AppendResult(interp, zBuf, 0); |
290 | 307 |
291 return TCL_OK; | 308 return TCL_OK; |
292 } | 309 } |
293 | 310 |
294 | 311 |
295 /* | 312 /* |
296 ** sqlthread open | 313 ** sqlthread open |
297 ** | 314 ** |
298 ** Return the current thread-id (Tcl_GetCurrentThread()) cast to | 315 ** Return the current thread-id (Tcl_GetCurrentThread()) cast to |
299 ** an integer. | 316 ** an integer. |
300 */ | 317 */ |
301 static int sqlthread_id( | 318 static int sqlthread_id( |
302 ClientData clientData, | 319 ClientData clientData, |
303 Tcl_Interp *interp, | 320 Tcl_Interp *interp, |
304 int objc, | 321 int objc, |
305 Tcl_Obj *CONST objv[] | 322 Tcl_Obj *CONST objv[] |
306 ){ | 323 ){ |
307 Tcl_ThreadId id = Tcl_GetCurrentThread(); | 324 Tcl_ThreadId id = Tcl_GetCurrentThread(); |
308 Tcl_SetObjResult(interp, Tcl_NewIntObj((int)id)); | 325 Tcl_SetObjResult(interp, Tcl_NewIntObj(SQLITE_PTR_TO_INT(id))); |
309 UNUSED_PARAMETER(clientData); | 326 UNUSED_PARAMETER(clientData); |
310 UNUSED_PARAMETER(objc); | 327 UNUSED_PARAMETER(objc); |
311 UNUSED_PARAMETER(objv); | 328 UNUSED_PARAMETER(objv); |
312 return TCL_OK; | 329 return TCL_OK; |
313 } | 330 } |
314 | 331 |
315 | 332 |
316 /* | 333 /* |
317 ** Dispatch routine for the sub-commands of [sqlthread]. | 334 ** Dispatch routine for the sub-commands of [sqlthread]. |
318 */ | 335 */ |
(...skipping 23 matching lines...) Expand all Loading... |
342 Tcl_WrongNumArgs(interp, 1, objv, "SUB-COMMAND"); | 359 Tcl_WrongNumArgs(interp, 1, objv, "SUB-COMMAND"); |
343 return TCL_ERROR; | 360 return TCL_ERROR; |
344 } | 361 } |
345 | 362 |
346 rc = Tcl_GetIndexFromObjStruct( | 363 rc = Tcl_GetIndexFromObjStruct( |
347 interp, objv[1], aSub, sizeof(aSub[0]), "sub-command", 0, &iIndex | 364 interp, objv[1], aSub, sizeof(aSub[0]), "sub-command", 0, &iIndex |
348 ); | 365 ); |
349 if( rc!=TCL_OK ) return rc; | 366 if( rc!=TCL_OK ) return rc; |
350 pSub = &aSub[iIndex]; | 367 pSub = &aSub[iIndex]; |
351 | 368 |
352 if( objc!=(pSub->nArg+2) ){ | 369 if( objc<(pSub->nArg+2) ){ |
353 Tcl_WrongNumArgs(interp, 2, objv, pSub->zUsage); | 370 Tcl_WrongNumArgs(interp, 2, objv, pSub->zUsage); |
354 return TCL_ERROR; | 371 return TCL_ERROR; |
355 } | 372 } |
356 | 373 |
357 return pSub->xProc(clientData, interp, objc, objv); | 374 return pSub->xProc(clientData, interp, objc, objv); |
358 } | 375 } |
359 | 376 |
360 /* | 377 /* |
361 ** The [clock_seconds] command. This is more or less the same as the | 378 ** The [clock_seconds] command. This is more or less the same as the |
362 ** regular tcl [clock seconds], except that it is available in testfixture | 379 ** regular tcl [clock seconds], except that it is available in testfixture |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 /* BEGIN_SQLITE_BLOCKING_STEP */ | 414 /* BEGIN_SQLITE_BLOCKING_STEP */ |
398 /* This example uses the pthreads API */ | 415 /* This example uses the pthreads API */ |
399 #include <pthread.h> | 416 #include <pthread.h> |
400 | 417 |
401 /* | 418 /* |
402 ** A pointer to an instance of this structure is passed as the user-context | 419 ** A pointer to an instance of this structure is passed as the user-context |
403 ** pointer when registering for an unlock-notify callback. | 420 ** pointer when registering for an unlock-notify callback. |
404 */ | 421 */ |
405 typedef struct UnlockNotification UnlockNotification; | 422 typedef struct UnlockNotification UnlockNotification; |
406 struct UnlockNotification { | 423 struct UnlockNotification { |
407 int fired; /* True after unlock event has occured */ | 424 int fired; /* True after unlock event has occurred */ |
408 pthread_cond_t cond; /* Condition variable to wait on */ | 425 pthread_cond_t cond; /* Condition variable to wait on */ |
409 pthread_mutex_t mutex; /* Mutex to protect structure */ | 426 pthread_mutex_t mutex; /* Mutex to protect structure */ |
410 }; | 427 }; |
411 | 428 |
412 /* | 429 /* |
413 ** This function is an unlock-notify callback registered with SQLite. | 430 ** This function is an unlock-notify callback registered with SQLite. |
414 */ | 431 */ |
415 static void unlock_notify_cb(void **apArg, int nArg){ | 432 static void unlock_notify_cb(void **apArg, int nArg){ |
416 int i; | 433 int i; |
417 for(i=0; i<nArg; i++){ | 434 for(i=0; i<nArg; i++){ |
418 UnlockNotification *p = (UnlockNotification *)apArg[i]; | 435 UnlockNotification *p = (UnlockNotification *)apArg[i]; |
419 pthread_mutex_lock(&p->mutex); | 436 pthread_mutex_lock(&p->mutex); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 int rc; | 554 int rc; |
538 | 555 |
539 if( objc!=2 ){ | 556 if( objc!=2 ){ |
540 Tcl_WrongNumArgs(interp, 1, objv, "STMT"); | 557 Tcl_WrongNumArgs(interp, 1, objv, "STMT"); |
541 return TCL_ERROR; | 558 return TCL_ERROR; |
542 } | 559 } |
543 | 560 |
544 pStmt = (sqlite3_stmt*)sqlite3TestTextToPtr(Tcl_GetString(objv[1])); | 561 pStmt = (sqlite3_stmt*)sqlite3TestTextToPtr(Tcl_GetString(objv[1])); |
545 rc = sqlite3_blocking_step(pStmt); | 562 rc = sqlite3_blocking_step(pStmt); |
546 | 563 |
547 Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), 0); | 564 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), 0); |
548 return TCL_OK; | 565 return TCL_OK; |
549 } | 566 } |
550 | 567 |
551 /* | 568 /* |
552 ** Usage: sqlite3_blocking_prepare_v2 DB sql bytes ?tailvar? | 569 ** Usage: sqlite3_blocking_prepare_v2 DB sql bytes ?tailvar? |
553 ** Usage: sqlite3_nonblocking_prepare_v2 DB sql bytes ?tailvar? | 570 ** Usage: sqlite3_nonblocking_prepare_v2 DB sql bytes ?tailvar? |
554 */ | 571 */ |
555 static int blocking_prepare_v2_proc( | 572 static int blocking_prepare_v2_proc( |
556 void * clientData, | 573 void * clientData, |
557 Tcl_Interp *interp, | 574 Tcl_Interp *interp, |
(...skipping 26 matching lines...) Expand all Loading... |
584 | 601 |
585 assert(rc==SQLITE_OK || pStmt==0); | 602 assert(rc==SQLITE_OK || pStmt==0); |
586 if( zTail && objc>=5 ){ | 603 if( zTail && objc>=5 ){ |
587 if( bytes>=0 ){ | 604 if( bytes>=0 ){ |
588 bytes = bytes - (zTail-zSql); | 605 bytes = bytes - (zTail-zSql); |
589 } | 606 } |
590 Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0); | 607 Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0); |
591 } | 608 } |
592 if( rc!=SQLITE_OK ){ | 609 if( rc!=SQLITE_OK ){ |
593 assert( pStmt==0 ); | 610 assert( pStmt==0 ); |
594 sprintf(zBuf, "%s ", (char *)sqlite3TestErrorName(rc)); | 611 sprintf(zBuf, "%s ", (char *)sqlite3ErrName(rc)); |
595 Tcl_AppendResult(interp, zBuf, sqlite3_errmsg(db), 0); | 612 Tcl_AppendResult(interp, zBuf, sqlite3_errmsg(db), 0); |
596 return TCL_ERROR; | 613 return TCL_ERROR; |
597 } | 614 } |
598 | 615 |
599 if( pStmt ){ | 616 if( pStmt ){ |
600 if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; | 617 if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; |
601 Tcl_AppendResult(interp, zBuf, 0); | 618 Tcl_AppendResult(interp, zBuf, 0); |
602 } | 619 } |
603 return TCL_OK; | 620 return TCL_OK; |
604 } | 621 } |
(...skipping 16 matching lines...) Expand all Loading... |
621 Tcl_CreateObjCommand(interp, | 638 Tcl_CreateObjCommand(interp, |
622 "sqlite3_nonblocking_prepare_v2", blocking_prepare_v2_proc, 0, 0); | 639 "sqlite3_nonblocking_prepare_v2", blocking_prepare_v2_proc, 0, 0); |
623 #endif | 640 #endif |
624 return TCL_OK; | 641 return TCL_OK; |
625 } | 642 } |
626 #else | 643 #else |
627 int SqlitetestThread_Init(Tcl_Interp *interp){ | 644 int SqlitetestThread_Init(Tcl_Interp *interp){ |
628 return TCL_OK; | 645 return TCL_OK; |
629 } | 646 } |
630 #endif | 647 #endif |
OLD | NEW |