OLD | NEW |
1 /* | 1 /* |
2 ** 2006 January 09 | 2 ** 2006 January 09 |
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 ** |
11 ************************************************************************* | 11 ************************************************************************* |
12 ** Code for testing the client/server version of the SQLite library. | 12 ** Code for testing the client/server version of the SQLite library. |
13 ** Derived from test4.c. | 13 ** Derived from test4.c. |
14 */ | 14 */ |
15 #include "sqliteInt.h" | 15 #include "sqliteInt.h" |
16 #include "tcl.h" | 16 #if defined(INCLUDE_SQLITE_TCL_H) |
| 17 # include "sqlite_tcl.h" |
| 18 #else |
| 19 # include "tcl.h" |
| 20 #endif |
17 | 21 |
18 /* | 22 /* |
19 ** This test only works on UNIX with a SQLITE_THREADSAFE build that includes | 23 ** This test only works on UNIX with a SQLITE_THREADSAFE build that includes |
20 ** the SQLITE_SERVER option. | 24 ** the SQLITE_SERVER option. |
21 */ | 25 */ |
22 #if defined(SQLITE_SERVER) && !defined(SQLITE_OMIT_SHARED_CACHE) && \ | 26 #if defined(SQLITE_SERVER) && !defined(SQLITE_OMIT_SHARED_CACHE) && \ |
23 SQLITE_OS_UNIX && SQLITE_THREADSAFE | 27 SQLITE_OS_UNIX && SQLITE_THREADSAFE |
24 | 28 |
25 #include <stdlib.h> | 29 #include <stdlib.h> |
26 #include <string.h> | 30 #include <string.h> |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } | 146 } |
143 return zArg[0] - 'A'; | 147 return zArg[0] - 'A'; |
144 } | 148 } |
145 | 149 |
146 /* | 150 /* |
147 ** Usage: client_create NAME FILENAME | 151 ** Usage: client_create NAME FILENAME |
148 ** | 152 ** |
149 ** NAME should be an upper case letter. Start the thread running with | 153 ** NAME should be an upper case letter. Start the thread running with |
150 ** an open connection to the given database. | 154 ** an open connection to the given database. |
151 */ | 155 */ |
152 static int tcl_client_create( | 156 static int SQLITE_TCLAPI tcl_client_create( |
153 void *NotUsed, | 157 void *NotUsed, |
154 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ | 158 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
155 int argc, /* Number of arguments */ | 159 int argc, /* Number of arguments */ |
156 const char **argv /* Text of each argument */ | 160 const char **argv /* Text of each argument */ |
157 ){ | 161 ){ |
158 int i; | 162 int i; |
159 pthread_t x; | 163 pthread_t x; |
160 int rc; | 164 int rc; |
161 | 165 |
162 if( argc!=3 ){ | 166 if( argc!=3 ){ |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 */ | 199 */ |
196 static void client_wait(Thread *p){ | 200 static void client_wait(Thread *p){ |
197 while( p->opnum>p->completed ) sched_yield(); | 201 while( p->opnum>p->completed ) sched_yield(); |
198 } | 202 } |
199 | 203 |
200 /* | 204 /* |
201 ** Usage: client_wait ID | 205 ** Usage: client_wait ID |
202 ** | 206 ** |
203 ** Wait on thread ID to reach its idle state. | 207 ** Wait on thread ID to reach its idle state. |
204 */ | 208 */ |
205 static int tcl_client_wait( | 209 static int SQLITE_TCLAPI tcl_client_wait( |
206 void *NotUsed, | 210 void *NotUsed, |
207 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ | 211 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
208 int argc, /* Number of arguments */ | 212 int argc, /* Number of arguments */ |
209 const char **argv /* Text of each argument */ | 213 const char **argv /* Text of each argument */ |
210 ){ | 214 ){ |
211 int i; | 215 int i; |
212 | 216 |
213 if( argc!=2 ){ | 217 if( argc!=2 ){ |
214 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], | 218 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
215 " ID", 0); | 219 " ID", 0); |
(...skipping 23 matching lines...) Expand all Loading... |
239 p->zFilename = 0; | 243 p->zFilename = 0; |
240 p->busy = 0; | 244 p->busy = 0; |
241 } | 245 } |
242 | 246 |
243 /* | 247 /* |
244 ** Usage: client_halt ID | 248 ** Usage: client_halt ID |
245 ** | 249 ** |
246 ** Cause a client thread to shut itself down. Wait for the shutdown to be | 250 ** Cause a client thread to shut itself down. Wait for the shutdown to be |
247 ** completed. If ID is "*" then stop all client threads. | 251 ** completed. If ID is "*" then stop all client threads. |
248 */ | 252 */ |
249 static int tcl_client_halt( | 253 static int SQLITE_TCLAPI tcl_client_halt( |
250 void *NotUsed, | 254 void *NotUsed, |
251 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ | 255 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
252 int argc, /* Number of arguments */ | 256 int argc, /* Number of arguments */ |
253 const char **argv /* Text of each argument */ | 257 const char **argv /* Text of each argument */ |
254 ){ | 258 ){ |
255 int i; | 259 int i; |
256 | 260 |
257 if( argc!=2 ){ | 261 if( argc!=2 ){ |
258 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], | 262 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
259 " ID", 0); | 263 " ID", 0); |
(...skipping 27 matching lines...) Expand all Loading... |
287 } | 291 } |
288 return TCL_OK; | 292 return TCL_OK; |
289 } | 293 } |
290 | 294 |
291 /* | 295 /* |
292 ** Usage: client_argc ID | 296 ** Usage: client_argc ID |
293 ** | 297 ** |
294 ** Wait on the most recent client_step to complete, then return the | 298 ** Wait on the most recent client_step to complete, then return the |
295 ** number of columns in the result set. | 299 ** number of columns in the result set. |
296 */ | 300 */ |
297 static int tcl_client_argc( | 301 static int SQLITE_TCLAPI tcl_client_argc( |
298 void *NotUsed, | 302 void *NotUsed, |
299 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ | 303 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
300 int argc, /* Number of arguments */ | 304 int argc, /* Number of arguments */ |
301 const char **argv /* Text of each argument */ | 305 const char **argv /* Text of each argument */ |
302 ){ | 306 ){ |
303 int i; | 307 int i; |
304 char zBuf[100]; | 308 char zBuf[100]; |
305 | 309 |
306 if( argc!=2 ){ | 310 if( argc!=2 ){ |
307 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], | 311 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
(...skipping 11 matching lines...) Expand all Loading... |
319 Tcl_AppendResult(interp, zBuf, 0); | 323 Tcl_AppendResult(interp, zBuf, 0); |
320 return TCL_OK; | 324 return TCL_OK; |
321 } | 325 } |
322 | 326 |
323 /* | 327 /* |
324 ** Usage: client_argv ID N | 328 ** Usage: client_argv ID N |
325 ** | 329 ** |
326 ** Wait on the most recent client_step to complete, then return the | 330 ** Wait on the most recent client_step to complete, then return the |
327 ** value of the N-th columns in the result set. | 331 ** value of the N-th columns in the result set. |
328 */ | 332 */ |
329 static int tcl_client_argv( | 333 static int SQLITE_TCLAPI tcl_client_argv( |
330 void *NotUsed, | 334 void *NotUsed, |
331 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ | 335 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
332 int argc, /* Number of arguments */ | 336 int argc, /* Number of arguments */ |
333 const char **argv /* Text of each argument */ | 337 const char **argv /* Text of each argument */ |
334 ){ | 338 ){ |
335 int i; | 339 int i; |
336 int n; | 340 int n; |
337 | 341 |
338 if( argc!=3 ){ | 342 if( argc!=3 ){ |
339 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], | 343 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
(...skipping 15 matching lines...) Expand all Loading... |
355 Tcl_AppendResult(interp, threadset[i].argv[n], 0); | 359 Tcl_AppendResult(interp, threadset[i].argv[n], 0); |
356 return TCL_OK; | 360 return TCL_OK; |
357 } | 361 } |
358 | 362 |
359 /* | 363 /* |
360 ** Usage: client_colname ID N | 364 ** Usage: client_colname ID N |
361 ** | 365 ** |
362 ** Wait on the most recent client_step to complete, then return the | 366 ** Wait on the most recent client_step to complete, then return the |
363 ** name of the N-th columns in the result set. | 367 ** name of the N-th columns in the result set. |
364 */ | 368 */ |
365 static int tcl_client_colname( | 369 static int SQLITE_TCLAPI tcl_client_colname( |
366 void *NotUsed, | 370 void *NotUsed, |
367 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ | 371 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
368 int argc, /* Number of arguments */ | 372 int argc, /* Number of arguments */ |
369 const char **argv /* Text of each argument */ | 373 const char **argv /* Text of each argument */ |
370 ){ | 374 ){ |
371 int i; | 375 int i; |
372 int n; | 376 int n; |
373 | 377 |
374 if( argc!=3 ){ | 378 if( argc!=3 ){ |
375 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], | 379 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
(...skipping 17 matching lines...) Expand all Loading... |
393 } | 397 } |
394 | 398 |
395 extern const char *sqlite3ErrName(int); | 399 extern const char *sqlite3ErrName(int); |
396 | 400 |
397 /* | 401 /* |
398 ** Usage: client_result ID | 402 ** Usage: client_result ID |
399 ** | 403 ** |
400 ** Wait on the most recent operation to complete, then return the | 404 ** Wait on the most recent operation to complete, then return the |
401 ** result code from that operation. | 405 ** result code from that operation. |
402 */ | 406 */ |
403 static int tcl_client_result( | 407 static int SQLITE_TCLAPI tcl_client_result( |
404 void *NotUsed, | 408 void *NotUsed, |
405 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ | 409 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
406 int argc, /* Number of arguments */ | 410 int argc, /* Number of arguments */ |
407 const char **argv /* Text of each argument */ | 411 const char **argv /* Text of each argument */ |
408 ){ | 412 ){ |
409 int i; | 413 int i; |
410 const char *zName; | 414 const char *zName; |
411 | 415 |
412 if( argc!=2 ){ | 416 if( argc!=2 ){ |
413 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], | 417 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
(...skipping 11 matching lines...) Expand all Loading... |
425 Tcl_AppendResult(interp, zName, 0); | 429 Tcl_AppendResult(interp, zName, 0); |
426 return TCL_OK; | 430 return TCL_OK; |
427 } | 431 } |
428 | 432 |
429 /* | 433 /* |
430 ** Usage: client_error ID | 434 ** Usage: client_error ID |
431 ** | 435 ** |
432 ** Wait on the most recent operation to complete, then return the | 436 ** Wait on the most recent operation to complete, then return the |
433 ** error string. | 437 ** error string. |
434 */ | 438 */ |
435 static int tcl_client_error( | 439 static int SQLITE_TCLAPI tcl_client_error( |
436 void *NotUsed, | 440 void *NotUsed, |
437 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ | 441 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
438 int argc, /* Number of arguments */ | 442 int argc, /* Number of arguments */ |
439 const char **argv /* Text of each argument */ | 443 const char **argv /* Text of each argument */ |
440 ){ | 444 ){ |
441 int i; | 445 int i; |
442 | 446 |
443 if( argc!=2 ){ | 447 if( argc!=2 ){ |
444 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], | 448 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
445 " ID", 0); | 449 " ID", 0); |
(...skipping 24 matching lines...) Expand all Loading... |
470 p->pStmt = 0; | 474 p->pStmt = 0; |
471 } | 475 } |
472 p->rc = sqlite3_client_prepare(p->db, p->zArg, -1, &p->pStmt, 0); | 476 p->rc = sqlite3_client_prepare(p->db, p->zArg, -1, &p->pStmt, 0); |
473 } | 477 } |
474 | 478 |
475 /* | 479 /* |
476 ** Usage: client_compile ID SQL | 480 ** Usage: client_compile ID SQL |
477 ** | 481 ** |
478 ** Compile a new virtual machine. | 482 ** Compile a new virtual machine. |
479 */ | 483 */ |
480 static int tcl_client_compile( | 484 static int SQLITE_TCLAPI tcl_client_compile( |
481 void *NotUsed, | 485 void *NotUsed, |
482 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ | 486 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
483 int argc, /* Number of arguments */ | 487 int argc, /* Number of arguments */ |
484 const char **argv /* Text of each argument */ | 488 const char **argv /* Text of each argument */ |
485 ){ | 489 ){ |
486 int i; | 490 int i; |
487 if( argc!=3 ){ | 491 if( argc!=3 ){ |
488 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], | 492 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
489 " ID SQL", 0); | 493 " ID SQL", 0); |
490 return TCL_ERROR; | 494 return TCL_ERROR; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 p->colv[i] = sqlite3_column_name(p->pStmt, i); | 527 p->colv[i] = sqlite3_column_name(p->pStmt, i); |
524 } | 528 } |
525 } | 529 } |
526 } | 530 } |
527 | 531 |
528 /* | 532 /* |
529 ** Usage: client_step ID | 533 ** Usage: client_step ID |
530 ** | 534 ** |
531 ** Advance the virtual machine by one step | 535 ** Advance the virtual machine by one step |
532 */ | 536 */ |
533 static int tcl_client_step( | 537 static int SQLITE_TCLAPI tcl_client_step( |
534 void *NotUsed, | 538 void *NotUsed, |
535 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ | 539 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
536 int argc, /* Number of arguments */ | 540 int argc, /* Number of arguments */ |
537 const char **argv /* Text of each argument */ | 541 const char **argv /* Text of each argument */ |
538 ){ | 542 ){ |
539 int i; | 543 int i; |
540 if( argc!=2 ){ | 544 if( argc!=2 ){ |
541 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], | 545 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
542 " IDL", 0); | 546 " IDL", 0); |
543 return TCL_ERROR; | 547 return TCL_ERROR; |
(...skipping 21 matching lines...) Expand all Loading... |
565 } | 569 } |
566 p->rc = sqlite3_client_finalize(p->pStmt); | 570 p->rc = sqlite3_client_finalize(p->pStmt); |
567 p->pStmt = 0; | 571 p->pStmt = 0; |
568 } | 572 } |
569 | 573 |
570 /* | 574 /* |
571 ** Usage: client_finalize ID | 575 ** Usage: client_finalize ID |
572 ** | 576 ** |
573 ** Finalize the virtual machine. | 577 ** Finalize the virtual machine. |
574 */ | 578 */ |
575 static int tcl_client_finalize( | 579 static int SQLITE_TCLAPI tcl_client_finalize( |
576 void *NotUsed, | 580 void *NotUsed, |
577 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ | 581 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
578 int argc, /* Number of arguments */ | 582 int argc, /* Number of arguments */ |
579 const char **argv /* Text of each argument */ | 583 const char **argv /* Text of each argument */ |
580 ){ | 584 ){ |
581 int i; | 585 int i; |
582 if( argc!=2 ){ | 586 if( argc!=2 ){ |
583 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], | 587 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
584 " IDL", 0); | 588 " IDL", 0); |
585 return TCL_ERROR; | 589 return TCL_ERROR; |
(...skipping 23 matching lines...) Expand all Loading... |
609 } | 613 } |
610 p->rc = sqlite3_client_reset(p->pStmt); | 614 p->rc = sqlite3_client_reset(p->pStmt); |
611 p->pStmt = 0; | 615 p->pStmt = 0; |
612 } | 616 } |
613 | 617 |
614 /* | 618 /* |
615 ** Usage: client_reset ID | 619 ** Usage: client_reset ID |
616 ** | 620 ** |
617 ** Finalize the virtual machine. | 621 ** Finalize the virtual machine. |
618 */ | 622 */ |
619 static int tcl_client_reset( | 623 static int SQLITE_TCLAPI tcl_client_reset( |
620 void *NotUsed, | 624 void *NotUsed, |
621 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ | 625 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
622 int argc, /* Number of arguments */ | 626 int argc, /* Number of arguments */ |
623 const char **argv /* Text of each argument */ | 627 const char **argv /* Text of each argument */ |
624 ){ | 628 ){ |
625 int i; | 629 int i; |
626 if( argc!=2 ){ | 630 if( argc!=2 ){ |
627 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], | 631 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
628 " IDL", 0); | 632 " IDL", 0); |
629 return TCL_ERROR; | 633 return TCL_ERROR; |
(...skipping 10 matching lines...) Expand all Loading... |
640 threadset[i].zArg = 0; | 644 threadset[i].zArg = 0; |
641 threadset[i].opnum++; | 645 threadset[i].opnum++; |
642 return TCL_OK; | 646 return TCL_OK; |
643 } | 647 } |
644 | 648 |
645 /* | 649 /* |
646 ** Usage: client_swap ID ID | 650 ** Usage: client_swap ID ID |
647 ** | 651 ** |
648 ** Interchange the sqlite* pointer between two threads. | 652 ** Interchange the sqlite* pointer between two threads. |
649 */ | 653 */ |
650 static int tcl_client_swap( | 654 static int SQLITE_TCLAPI tcl_client_swap( |
651 void *NotUsed, | 655 void *NotUsed, |
652 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ | 656 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
653 int argc, /* Number of arguments */ | 657 int argc, /* Number of arguments */ |
654 const char **argv /* Text of each argument */ | 658 const char **argv /* Text of each argument */ |
655 ){ | 659 ){ |
656 int i, j; | 660 int i, j; |
657 sqlite3 *temp; | 661 sqlite3 *temp; |
658 if( argc!=3 ){ | 662 if( argc!=3 ){ |
659 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], | 663 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
660 " ID1 ID2", 0); | 664 " ID1 ID2", 0); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 int i; | 709 int i; |
706 | 710 |
707 for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ | 711 for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ |
708 Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0); | 712 Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0); |
709 } | 713 } |
710 return TCL_OK; | 714 return TCL_OK; |
711 } | 715 } |
712 #else | 716 #else |
713 int Sqlitetest7_Init(Tcl_Interp *interp){ return TCL_OK; } | 717 int Sqlitetest7_Init(Tcl_Interp *interp){ return TCL_OK; } |
714 #endif /* SQLITE_OS_UNIX */ | 718 #endif /* SQLITE_OS_UNIX */ |
OLD | NEW |