Fossil SCM
Added query_col_int and query_col_double. Renamed query_column_xxx to query_col_xxx.
Commit
b01eb58bcaadfd79ba6e1732c7f7003b674dc406
Parent
c3b10e12a148e2d…
2 files changed
+86
-17
+19
-11
+86
-17
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -517,10 +517,43 @@ | ||
| 517 | 517 | |
| 518 | 518 | static void queryReportDbErr( Th_Interp * interp, int rc ){ |
| 519 | 519 | char const * msg = sqlite3_errmsg( g.db ); |
| 520 | 520 | Th_ErrorMessage(interp, "db error:", msg, -1); |
| 521 | 521 | } |
| 522 | + | |
| 523 | +static int queryStmtIndexArgs( | |
| 524 | + Th_Interp * interp, | |
| 525 | + int argc, | |
| 526 | + char const ** argv, | |
| 527 | + int *argl, | |
| 528 | + sqlite3_stmt ** pStmt, | |
| 529 | + int * pIndex ){ | |
| 530 | + int index = 0; | |
| 531 | + sqlite3_stmt * stmt; | |
| 532 | + if( !pIndex ){ | |
| 533 | + if(argc<2){ | |
| 534 | + return Th_WrongNumArgs(interp, "StmtHandle"); | |
| 535 | + } | |
| 536 | + }else{ | |
| 537 | + if( argc<3 ){ | |
| 538 | + return Th_WrongNumArgs(interp, "StmtHandle, Index"); | |
| 539 | + } | |
| 540 | + if( 0 != Th_ToInt( interp, argv[2], argl[2], &index ) ){ | |
| 541 | + return TH_ERROR; | |
| 542 | + } | |
| 543 | + } | |
| 544 | + stmt = queryStmtHandle(interp, argv[1], argl[1], NULL); | |
| 545 | + if( NULL == stmt ){ | |
| 546 | + return TH_ERROR; | |
| 547 | + }else{ | |
| 548 | + *pStmt = stmt; | |
| 549 | + if( pIndex ){ | |
| 550 | + *pIndex = index; | |
| 551 | + } | |
| 552 | + return 0; | |
| 553 | + } | |
| 554 | +} | |
| 522 | 555 | |
| 523 | 556 | static int queryStepCmd( |
| 524 | 557 | Th_Interp *interp, |
| 525 | 558 | void *p, |
| 526 | 559 | int argc, |
| @@ -530,12 +563,11 @@ | ||
| 530 | 563 | sqlite3_stmt * pStmt = NULL; |
| 531 | 564 | int rc = 0; |
| 532 | 565 | if( argc!=2 ){ |
| 533 | 566 | return Th_WrongNumArgs(interp, "query_step StmtHandle"); |
| 534 | 567 | } |
| 535 | - pStmt = queryStmtHandle(interp, argv[1], argl[1], &rc); | |
| 536 | - if( rc < 1 ){ | |
| 568 | + if(0 != queryStmtIndexArgs(interp, argc, argv, argl, &pStmt, NULL)){ | |
| 537 | 569 | return TH_ERROR; |
| 538 | 570 | } |
| 539 | 571 | rc = sqlite3_step( pStmt ); |
| 540 | 572 | switch(rc){ |
| 541 | 573 | case SQLITE_ROW: |
| @@ -560,27 +592,62 @@ | ||
| 560 | 592 | int *argl |
| 561 | 593 | ){ |
| 562 | 594 | sqlite3_stmt * pStmt = NULL; |
| 563 | 595 | char const * val; |
| 564 | 596 | int index; |
| 565 | - int rc = 0; | |
| 566 | 597 | int valLen; |
| 567 | 598 | if( argc!=3 ){ |
| 568 | - return Th_WrongNumArgs(interp, "query_column_string StmtHandle Index"); | |
| 599 | + return Th_WrongNumArgs(interp, "query_col_string StmtHandle Index"); | |
| 569 | 600 | } |
| 570 | - pStmt = queryStmtHandle(interp, argv[1], argl[1], &rc); | |
| 571 | - if( rc < 1 ){ | |
| 572 | - return TH_ERROR; | |
| 573 | - } | |
| 574 | - if( 0 != Th_ToInt( interp, argv[2], argl[2], &index ) ){ | |
| 601 | + if(0 != queryStmtIndexArgs(interp, argc, argv, argl, &pStmt, &index)){ | |
| 575 | 602 | return TH_ERROR; |
| 576 | 603 | } |
| 577 | 604 | val = sqlite3_column_text( pStmt, index ); |
| 578 | 605 | valLen = val ? sqlite3_column_bytes( pStmt, index ) : 0; |
| 579 | 606 | Th_SetResult( interp, val, valLen ); |
| 580 | 607 | return TH_OK; |
| 581 | 608 | } |
| 609 | + | |
| 610 | +static int queryColIntCmd( | |
| 611 | + Th_Interp *interp, | |
| 612 | + void *p, | |
| 613 | + int argc, | |
| 614 | + const char **argv, | |
| 615 | + int *argl | |
| 616 | +){ | |
| 617 | + sqlite3_stmt * pStmt = NULL; | |
| 618 | + int rc = 0; | |
| 619 | + int index = 0; | |
| 620 | + if( argc!=3 ){ | |
| 621 | + return Th_WrongNumArgs(interp, "query_col_int StmtHandle Index"); | |
| 622 | + } | |
| 623 | + if(0 != queryStmtIndexArgs(interp, argc, argv, argl, &pStmt, &index)){ | |
| 624 | + return TH_ERROR; | |
| 625 | + } | |
| 626 | + Th_SetResultInt( interp, sqlite3_column_int( pStmt, index ) ); | |
| 627 | + return TH_OK; | |
| 628 | +} | |
| 629 | + | |
| 630 | +static int queryColDoubleCmd( | |
| 631 | + Th_Interp *interp, | |
| 632 | + void *p, | |
| 633 | + int argc, | |
| 634 | + const char **argv, | |
| 635 | + int *argl | |
| 636 | +){ | |
| 637 | + sqlite3_stmt * pStmt = NULL; | |
| 638 | + double rc = 0; | |
| 639 | + int index = -1; | |
| 640 | + if( argc!=3 ){ | |
| 641 | + return Th_WrongNumArgs(interp, "query_col_double StmtHandle Index"); | |
| 642 | + } | |
| 643 | + if(0 != queryStmtIndexArgs(interp, argc, argv, argl, &pStmt, &index)){ | |
| 644 | + return TH_ERROR; | |
| 645 | + } | |
| 646 | + Th_SetResultDouble( interp, sqlite3_column_double( pStmt, index ) ); | |
| 647 | + return TH_OK; | |
| 648 | +} | |
| 582 | 649 | |
| 583 | 650 | |
| 584 | 651 | static int queryColCountCmd( |
| 585 | 652 | Th_Interp *interp, |
| 586 | 653 | void *p, |
| @@ -589,11 +656,11 @@ | ||
| 589 | 656 | int *argl |
| 590 | 657 | ){ |
| 591 | 658 | int rc; |
| 592 | 659 | sqlite3_stmt * pStmt = NULL; |
| 593 | 660 | if( argc!=2 ){ |
| 594 | - return Th_WrongNumArgs(interp, "query_column_count StmtHandle"); | |
| 661 | + return Th_WrongNumArgs(interp, "query_col_count StmtHandle"); | |
| 595 | 662 | } |
| 596 | 663 | pStmt = queryStmtHandle(interp, argv[1], argl[1], NULL); |
| 597 | 664 | if( NULL == pStmt ){ |
| 598 | 665 | return TH_ERROR; |
| 599 | 666 | } |
| @@ -613,11 +680,11 @@ | ||
| 613 | 680 | char const * val; |
| 614 | 681 | int index; |
| 615 | 682 | int rc = 0; |
| 616 | 683 | int valLen; |
| 617 | 684 | if( argc!=3 ){ |
| 618 | - return Th_WrongNumArgs(interp, "query_column_name StmtHandle Index"); | |
| 685 | + return Th_WrongNumArgs(interp, "query_col_name StmtHandle Index"); | |
| 619 | 686 | } |
| 620 | 687 | pStmt = queryStmtHandle(interp, argv[1], argl[1], &rc); |
| 621 | 688 | if( rc < 1 ){ |
| 622 | 689 | return TH_ERROR; |
| 623 | 690 | } |
| @@ -662,16 +729,18 @@ | ||
| 662 | 729 | {"date", dateCmd, 0}, |
| 663 | 730 | {"html", putsCmd, &puts_Html}, |
| 664 | 731 | {"puts", putsCmd, &puts_Normal}, |
| 665 | 732 | {"putsl", putsCmd, &puts_Ext}, |
| 666 | 733 | #ifdef TH_USE_SQLITE |
| 667 | - {"query_column_count", queryColCountCmd, 0}, | |
| 668 | - {"query_column_name", queryColNameCmd, 0}, | |
| 669 | - {"query_finalize", queryFinalizeCmd, 0}, | |
| 670 | - {"query_prepare", queryPrepareCmd, 0}, | |
| 671 | - {"query_step", queryStepCmd, 0}, | |
| 672 | - {"query_column_string", queryColStringCmd, 0}, | |
| 734 | + {"query_col_count", queryColCountCmd, 0}, | |
| 735 | + {"query_col_name", queryColNameCmd, 0}, | |
| 736 | + {"query_col_string", queryColStringCmd, 0}, | |
| 737 | + {"query_col_int", queryColIntCmd, 0}, | |
| 738 | + {"query_col_double", queryColDoubleCmd, 0}, | |
| 739 | + {"query_finalize", queryFinalizeCmd, 0}, | |
| 740 | + {"query_prepare", queryPrepareCmd, 0}, | |
| 741 | + {"query_step", queryStepCmd, 0}, | |
| 673 | 742 | #endif |
| 674 | 743 | {"wiki", wikiCmd, 0}, |
| 675 | 744 | {"repository", repositoryCmd, 0}, |
| 676 | 745 | {0, 0, 0} |
| 677 | 746 | }; |
| 678 | 747 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -517,10 +517,43 @@ | |
| 517 | |
| 518 | static void queryReportDbErr( Th_Interp * interp, int rc ){ |
| 519 | char const * msg = sqlite3_errmsg( g.db ); |
| 520 | Th_ErrorMessage(interp, "db error:", msg, -1); |
| 521 | } |
| 522 | |
| 523 | static int queryStepCmd( |
| 524 | Th_Interp *interp, |
| 525 | void *p, |
| 526 | int argc, |
| @@ -530,12 +563,11 @@ | |
| 530 | sqlite3_stmt * pStmt = NULL; |
| 531 | int rc = 0; |
| 532 | if( argc!=2 ){ |
| 533 | return Th_WrongNumArgs(interp, "query_step StmtHandle"); |
| 534 | } |
| 535 | pStmt = queryStmtHandle(interp, argv[1], argl[1], &rc); |
| 536 | if( rc < 1 ){ |
| 537 | return TH_ERROR; |
| 538 | } |
| 539 | rc = sqlite3_step( pStmt ); |
| 540 | switch(rc){ |
| 541 | case SQLITE_ROW: |
| @@ -560,27 +592,62 @@ | |
| 560 | int *argl |
| 561 | ){ |
| 562 | sqlite3_stmt * pStmt = NULL; |
| 563 | char const * val; |
| 564 | int index; |
| 565 | int rc = 0; |
| 566 | int valLen; |
| 567 | if( argc!=3 ){ |
| 568 | return Th_WrongNumArgs(interp, "query_column_string StmtHandle Index"); |
| 569 | } |
| 570 | pStmt = queryStmtHandle(interp, argv[1], argl[1], &rc); |
| 571 | if( rc < 1 ){ |
| 572 | return TH_ERROR; |
| 573 | } |
| 574 | if( 0 != Th_ToInt( interp, argv[2], argl[2], &index ) ){ |
| 575 | return TH_ERROR; |
| 576 | } |
| 577 | val = sqlite3_column_text( pStmt, index ); |
| 578 | valLen = val ? sqlite3_column_bytes( pStmt, index ) : 0; |
| 579 | Th_SetResult( interp, val, valLen ); |
| 580 | return TH_OK; |
| 581 | } |
| 582 | |
| 583 | |
| 584 | static int queryColCountCmd( |
| 585 | Th_Interp *interp, |
| 586 | void *p, |
| @@ -589,11 +656,11 @@ | |
| 589 | int *argl |
| 590 | ){ |
| 591 | int rc; |
| 592 | sqlite3_stmt * pStmt = NULL; |
| 593 | if( argc!=2 ){ |
| 594 | return Th_WrongNumArgs(interp, "query_column_count StmtHandle"); |
| 595 | } |
| 596 | pStmt = queryStmtHandle(interp, argv[1], argl[1], NULL); |
| 597 | if( NULL == pStmt ){ |
| 598 | return TH_ERROR; |
| 599 | } |
| @@ -613,11 +680,11 @@ | |
| 613 | char const * val; |
| 614 | int index; |
| 615 | int rc = 0; |
| 616 | int valLen; |
| 617 | if( argc!=3 ){ |
| 618 | return Th_WrongNumArgs(interp, "query_column_name StmtHandle Index"); |
| 619 | } |
| 620 | pStmt = queryStmtHandle(interp, argv[1], argl[1], &rc); |
| 621 | if( rc < 1 ){ |
| 622 | return TH_ERROR; |
| 623 | } |
| @@ -662,16 +729,18 @@ | |
| 662 | {"date", dateCmd, 0}, |
| 663 | {"html", putsCmd, &puts_Html}, |
| 664 | {"puts", putsCmd, &puts_Normal}, |
| 665 | {"putsl", putsCmd, &puts_Ext}, |
| 666 | #ifdef TH_USE_SQLITE |
| 667 | {"query_column_count", queryColCountCmd, 0}, |
| 668 | {"query_column_name", queryColNameCmd, 0}, |
| 669 | {"query_finalize", queryFinalizeCmd, 0}, |
| 670 | {"query_prepare", queryPrepareCmd, 0}, |
| 671 | {"query_step", queryStepCmd, 0}, |
| 672 | {"query_column_string", queryColStringCmd, 0}, |
| 673 | #endif |
| 674 | {"wiki", wikiCmd, 0}, |
| 675 | {"repository", repositoryCmd, 0}, |
| 676 | {0, 0, 0} |
| 677 | }; |
| 678 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -517,10 +517,43 @@ | |
| 517 | |
| 518 | static void queryReportDbErr( Th_Interp * interp, int rc ){ |
| 519 | char const * msg = sqlite3_errmsg( g.db ); |
| 520 | Th_ErrorMessage(interp, "db error:", msg, -1); |
| 521 | } |
| 522 | |
| 523 | static int queryStmtIndexArgs( |
| 524 | Th_Interp * interp, |
| 525 | int argc, |
| 526 | char const ** argv, |
| 527 | int *argl, |
| 528 | sqlite3_stmt ** pStmt, |
| 529 | int * pIndex ){ |
| 530 | int index = 0; |
| 531 | sqlite3_stmt * stmt; |
| 532 | if( !pIndex ){ |
| 533 | if(argc<2){ |
| 534 | return Th_WrongNumArgs(interp, "StmtHandle"); |
| 535 | } |
| 536 | }else{ |
| 537 | if( argc<3 ){ |
| 538 | return Th_WrongNumArgs(interp, "StmtHandle, Index"); |
| 539 | } |
| 540 | if( 0 != Th_ToInt( interp, argv[2], argl[2], &index ) ){ |
| 541 | return TH_ERROR; |
| 542 | } |
| 543 | } |
| 544 | stmt = queryStmtHandle(interp, argv[1], argl[1], NULL); |
| 545 | if( NULL == stmt ){ |
| 546 | return TH_ERROR; |
| 547 | }else{ |
| 548 | *pStmt = stmt; |
| 549 | if( pIndex ){ |
| 550 | *pIndex = index; |
| 551 | } |
| 552 | return 0; |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | static int queryStepCmd( |
| 557 | Th_Interp *interp, |
| 558 | void *p, |
| 559 | int argc, |
| @@ -530,12 +563,11 @@ | |
| 563 | sqlite3_stmt * pStmt = NULL; |
| 564 | int rc = 0; |
| 565 | if( argc!=2 ){ |
| 566 | return Th_WrongNumArgs(interp, "query_step StmtHandle"); |
| 567 | } |
| 568 | if(0 != queryStmtIndexArgs(interp, argc, argv, argl, &pStmt, NULL)){ |
| 569 | return TH_ERROR; |
| 570 | } |
| 571 | rc = sqlite3_step( pStmt ); |
| 572 | switch(rc){ |
| 573 | case SQLITE_ROW: |
| @@ -560,27 +592,62 @@ | |
| 592 | int *argl |
| 593 | ){ |
| 594 | sqlite3_stmt * pStmt = NULL; |
| 595 | char const * val; |
| 596 | int index; |
| 597 | int valLen; |
| 598 | if( argc!=3 ){ |
| 599 | return Th_WrongNumArgs(interp, "query_col_string StmtHandle Index"); |
| 600 | } |
| 601 | if(0 != queryStmtIndexArgs(interp, argc, argv, argl, &pStmt, &index)){ |
| 602 | return TH_ERROR; |
| 603 | } |
| 604 | val = sqlite3_column_text( pStmt, index ); |
| 605 | valLen = val ? sqlite3_column_bytes( pStmt, index ) : 0; |
| 606 | Th_SetResult( interp, val, valLen ); |
| 607 | return TH_OK; |
| 608 | } |
| 609 | |
| 610 | static int queryColIntCmd( |
| 611 | Th_Interp *interp, |
| 612 | void *p, |
| 613 | int argc, |
| 614 | const char **argv, |
| 615 | int *argl |
| 616 | ){ |
| 617 | sqlite3_stmt * pStmt = NULL; |
| 618 | int rc = 0; |
| 619 | int index = 0; |
| 620 | if( argc!=3 ){ |
| 621 | return Th_WrongNumArgs(interp, "query_col_int StmtHandle Index"); |
| 622 | } |
| 623 | if(0 != queryStmtIndexArgs(interp, argc, argv, argl, &pStmt, &index)){ |
| 624 | return TH_ERROR; |
| 625 | } |
| 626 | Th_SetResultInt( interp, sqlite3_column_int( pStmt, index ) ); |
| 627 | return TH_OK; |
| 628 | } |
| 629 | |
| 630 | static int queryColDoubleCmd( |
| 631 | Th_Interp *interp, |
| 632 | void *p, |
| 633 | int argc, |
| 634 | const char **argv, |
| 635 | int *argl |
| 636 | ){ |
| 637 | sqlite3_stmt * pStmt = NULL; |
| 638 | double rc = 0; |
| 639 | int index = -1; |
| 640 | if( argc!=3 ){ |
| 641 | return Th_WrongNumArgs(interp, "query_col_double StmtHandle Index"); |
| 642 | } |
| 643 | if(0 != queryStmtIndexArgs(interp, argc, argv, argl, &pStmt, &index)){ |
| 644 | return TH_ERROR; |
| 645 | } |
| 646 | Th_SetResultDouble( interp, sqlite3_column_double( pStmt, index ) ); |
| 647 | return TH_OK; |
| 648 | } |
| 649 | |
| 650 | |
| 651 | static int queryColCountCmd( |
| 652 | Th_Interp *interp, |
| 653 | void *p, |
| @@ -589,11 +656,11 @@ | |
| 656 | int *argl |
| 657 | ){ |
| 658 | int rc; |
| 659 | sqlite3_stmt * pStmt = NULL; |
| 660 | if( argc!=2 ){ |
| 661 | return Th_WrongNumArgs(interp, "query_col_count StmtHandle"); |
| 662 | } |
| 663 | pStmt = queryStmtHandle(interp, argv[1], argl[1], NULL); |
| 664 | if( NULL == pStmt ){ |
| 665 | return TH_ERROR; |
| 666 | } |
| @@ -613,11 +680,11 @@ | |
| 680 | char const * val; |
| 681 | int index; |
| 682 | int rc = 0; |
| 683 | int valLen; |
| 684 | if( argc!=3 ){ |
| 685 | return Th_WrongNumArgs(interp, "query_col_name StmtHandle Index"); |
| 686 | } |
| 687 | pStmt = queryStmtHandle(interp, argv[1], argl[1], &rc); |
| 688 | if( rc < 1 ){ |
| 689 | return TH_ERROR; |
| 690 | } |
| @@ -662,16 +729,18 @@ | |
| 729 | {"date", dateCmd, 0}, |
| 730 | {"html", putsCmd, &puts_Html}, |
| 731 | {"puts", putsCmd, &puts_Normal}, |
| 732 | {"putsl", putsCmd, &puts_Ext}, |
| 733 | #ifdef TH_USE_SQLITE |
| 734 | {"query_col_count", queryColCountCmd, 0}, |
| 735 | {"query_col_name", queryColNameCmd, 0}, |
| 736 | {"query_col_string", queryColStringCmd, 0}, |
| 737 | {"query_col_int", queryColIntCmd, 0}, |
| 738 | {"query_col_double", queryColDoubleCmd, 0}, |
| 739 | {"query_finalize", queryFinalizeCmd, 0}, |
| 740 | {"query_prepare", queryPrepareCmd, 0}, |
| 741 | {"query_step", queryStepCmd, 0}, |
| 742 | #endif |
| 743 | {"wiki", wikiCmd, 0}, |
| 744 | {"repository", repositoryCmd, 0}, |
| 745 | {0, 0, 0} |
| 746 | }; |
| 747 |
+19
-11
| --- test/th1-query-api-1.th1 | ||
| +++ test/th1-query-api-1.th1 | ||
| @@ -1,5 +1,7 @@ | ||
| 1 | +This is not a formal test suite, but a tinkering ground. | |
| 2 | +Run it through "fossil test-th-render THIS_FILE". | |
| 1 | 3 | <th1> |
| 2 | 4 | proc bar {} { |
| 3 | 5 | puts "json ?= [hasfeature json]\n" |
| 4 | 6 | puts "tcl ?= [hasfeature tcl]\n" |
| 5 | 7 | puts "ssl ?= [hasfeature ssl]\n" |
| @@ -21,16 +23,16 @@ | ||
| 21 | 23 | } |
| 22 | 24 | set a [xyz] |
| 23 | 25 | puts "a=${a}" ! \n |
| 24 | 26 | |
| 25 | 27 | set stmt [query_prepare {SELECT login, cap FROM user}] |
| 26 | -set colCount [query_column_count $stmt] | |
| 28 | +set colCount [query_col_count $stmt] | |
| 27 | 29 | puts "query column count: ${colCount}\n" |
| 28 | 30 | #set stmt2 [query_prepare {SELECT cap, login FROM user}] |
| 29 | 31 | #puts "stmt=${stmt} stmt2=${stmt2}\n" |
| 30 | 32 | #putsl "step =" [query_step $stmt] |
| 31 | -#putsl "val =" [query_column_string $stmt 1] | |
| 33 | +#putsl "val =" [query_col_string $stmt 1] | |
| 32 | 34 | |
| 33 | 35 | proc noop {} {} |
| 34 | 36 | proc incr {name {step 1}} { |
| 35 | 37 | upvar $name x |
| 36 | 38 | set x [expr $x+$step] |
| @@ -39,21 +41,21 @@ | ||
| 39 | 41 | |
| 40 | 42 | set sep " " |
| 41 | 43 | set i 0 |
| 42 | 44 | set colNames(0) 0 |
| 43 | 45 | for {set i 0} {$i < $colCount} {incr i} { |
| 44 | - set colNames($i) [query_column_name $stmt $i] | |
| 46 | + set colNames($i) [query_col_name $stmt $i] | |
| 45 | 47 | } |
| 46 | 48 | |
| 47 | 49 | for {set row 0} {0 < [query_step $stmt]} {incr row} { |
| 48 | 50 | for {set i 0} {$i < $colCount} {incr i} { |
| 49 | 51 | if {$i > 0} { |
| 50 | 52 | puts $sep |
| 51 | 53 | } else { |
| 52 | 54 | puts "#$row: $sep" |
| 53 | 55 | } |
| 54 | - puts $colNames($i) = [query_column_string $stmt $i] | |
| 56 | + puts $colNames($i) = [query_col_string $stmt $i] | |
| 55 | 57 | } |
| 56 | 58 | puts "\n" |
| 57 | 59 | } |
| 58 | 60 | unset row |
| 59 | 61 | |
| @@ -61,34 +63,40 @@ | ||
| 61 | 63 | #query_finalize $stmt2 |
| 62 | 64 | |
| 63 | 65 | |
| 64 | 66 | proc query_step_each {{stmt} {callback}} { |
| 65 | 67 | set colNames(0) 0 |
| 66 | - set colCount [query_column_count $stmt] | |
| 68 | + set colCount [query_col_count $stmt] | |
| 67 | 69 | for {set i 0} {$i < $colCount} {incr i} { |
| 68 | - set colNames($i) [query_column_name $stmt $i] | |
| 70 | + set colNames($i) [query_col_name $stmt $i] | |
| 69 | 71 | } |
| 70 | 72 | upvar cb $callback |
| 71 | 73 | for {set row 0} {0 < [query_step $stmt]} {incr row} { |
| 72 | 74 | #puts "Calling callback: $stmt $colCount colNames\n" |
| 73 | 75 | $callback $stmt $colCount |
| 74 | 76 | } |
| 75 | 77 | } |
| 76 | 78 | |
| 77 | 79 | |
| 78 | -set stmt [query_prepare {SELECT login FROM user}] | |
| 80 | +set stmt [query_prepare {SELECT uid, login FROM user}] | |
| 79 | 81 | set rc 0 |
| 80 | 82 | catch { |
| 81 | 83 | proc my_each {stmt colCount} { |
| 82 | - for {set i 0} {$i < $colCount} {incr i} { | |
| 83 | - if {$i > 0} { puts $sep } | |
| 84 | - puts [query_column_string $stmt $i] | |
| 85 | - } | |
| 84 | + upvar 2 sep sep | |
| 85 | + puts [query_col_int $stmt 0] $sep | |
| 86 | + puts [query_col_double $stmt 0] $sep | |
| 87 | + puts [query_col_string $stmt 1] | |
| 88 | +# for {set i 0} {$i < $colCount} {incr i} { | |
| 89 | +# if {$i > 0} { puts $sep } | |
| 90 | +# } | |
| 86 | 91 | puts "\n" |
| 87 | 92 | # error "hi!" |
| 88 | 93 | } |
| 89 | 94 | query_step_each $stmt my_each |
| 95 | +# query_step_each $stmt { | |
| 96 | +# proc each {stmt cc} { puts hi "\n" } | |
| 97 | +# } | |
| 90 | 98 | } rc |
| 91 | 99 | query_finalize $stmt |
| 92 | 100 | puts rc = $rc |
| 93 | 101 | |
| 94 | 102 | </th1> |
| 95 | 103 |
| --- test/th1-query-api-1.th1 | |
| +++ test/th1-query-api-1.th1 | |
| @@ -1,5 +1,7 @@ | |
| 1 | <th1> |
| 2 | proc bar {} { |
| 3 | puts "json ?= [hasfeature json]\n" |
| 4 | puts "tcl ?= [hasfeature tcl]\n" |
| 5 | puts "ssl ?= [hasfeature ssl]\n" |
| @@ -21,16 +23,16 @@ | |
| 21 | } |
| 22 | set a [xyz] |
| 23 | puts "a=${a}" ! \n |
| 24 | |
| 25 | set stmt [query_prepare {SELECT login, cap FROM user}] |
| 26 | set colCount [query_column_count $stmt] |
| 27 | puts "query column count: ${colCount}\n" |
| 28 | #set stmt2 [query_prepare {SELECT cap, login FROM user}] |
| 29 | #puts "stmt=${stmt} stmt2=${stmt2}\n" |
| 30 | #putsl "step =" [query_step $stmt] |
| 31 | #putsl "val =" [query_column_string $stmt 1] |
| 32 | |
| 33 | proc noop {} {} |
| 34 | proc incr {name {step 1}} { |
| 35 | upvar $name x |
| 36 | set x [expr $x+$step] |
| @@ -39,21 +41,21 @@ | |
| 39 | |
| 40 | set sep " " |
| 41 | set i 0 |
| 42 | set colNames(0) 0 |
| 43 | for {set i 0} {$i < $colCount} {incr i} { |
| 44 | set colNames($i) [query_column_name $stmt $i] |
| 45 | } |
| 46 | |
| 47 | for {set row 0} {0 < [query_step $stmt]} {incr row} { |
| 48 | for {set i 0} {$i < $colCount} {incr i} { |
| 49 | if {$i > 0} { |
| 50 | puts $sep |
| 51 | } else { |
| 52 | puts "#$row: $sep" |
| 53 | } |
| 54 | puts $colNames($i) = [query_column_string $stmt $i] |
| 55 | } |
| 56 | puts "\n" |
| 57 | } |
| 58 | unset row |
| 59 | |
| @@ -61,34 +63,40 @@ | |
| 61 | #query_finalize $stmt2 |
| 62 | |
| 63 | |
| 64 | proc query_step_each {{stmt} {callback}} { |
| 65 | set colNames(0) 0 |
| 66 | set colCount [query_column_count $stmt] |
| 67 | for {set i 0} {$i < $colCount} {incr i} { |
| 68 | set colNames($i) [query_column_name $stmt $i] |
| 69 | } |
| 70 | upvar cb $callback |
| 71 | for {set row 0} {0 < [query_step $stmt]} {incr row} { |
| 72 | #puts "Calling callback: $stmt $colCount colNames\n" |
| 73 | $callback $stmt $colCount |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | |
| 78 | set stmt [query_prepare {SELECT login FROM user}] |
| 79 | set rc 0 |
| 80 | catch { |
| 81 | proc my_each {stmt colCount} { |
| 82 | for {set i 0} {$i < $colCount} {incr i} { |
| 83 | if {$i > 0} { puts $sep } |
| 84 | puts [query_column_string $stmt $i] |
| 85 | } |
| 86 | puts "\n" |
| 87 | # error "hi!" |
| 88 | } |
| 89 | query_step_each $stmt my_each |
| 90 | } rc |
| 91 | query_finalize $stmt |
| 92 | puts rc = $rc |
| 93 | |
| 94 | </th1> |
| 95 |
| --- test/th1-query-api-1.th1 | |
| +++ test/th1-query-api-1.th1 | |
| @@ -1,5 +1,7 @@ | |
| 1 | This is not a formal test suite, but a tinkering ground. |
| 2 | Run it through "fossil test-th-render THIS_FILE". |
| 3 | <th1> |
| 4 | proc bar {} { |
| 5 | puts "json ?= [hasfeature json]\n" |
| 6 | puts "tcl ?= [hasfeature tcl]\n" |
| 7 | puts "ssl ?= [hasfeature ssl]\n" |
| @@ -21,16 +23,16 @@ | |
| 23 | } |
| 24 | set a [xyz] |
| 25 | puts "a=${a}" ! \n |
| 26 | |
| 27 | set stmt [query_prepare {SELECT login, cap FROM user}] |
| 28 | set colCount [query_col_count $stmt] |
| 29 | puts "query column count: ${colCount}\n" |
| 30 | #set stmt2 [query_prepare {SELECT cap, login FROM user}] |
| 31 | #puts "stmt=${stmt} stmt2=${stmt2}\n" |
| 32 | #putsl "step =" [query_step $stmt] |
| 33 | #putsl "val =" [query_col_string $stmt 1] |
| 34 | |
| 35 | proc noop {} {} |
| 36 | proc incr {name {step 1}} { |
| 37 | upvar $name x |
| 38 | set x [expr $x+$step] |
| @@ -39,21 +41,21 @@ | |
| 41 | |
| 42 | set sep " " |
| 43 | set i 0 |
| 44 | set colNames(0) 0 |
| 45 | for {set i 0} {$i < $colCount} {incr i} { |
| 46 | set colNames($i) [query_col_name $stmt $i] |
| 47 | } |
| 48 | |
| 49 | for {set row 0} {0 < [query_step $stmt]} {incr row} { |
| 50 | for {set i 0} {$i < $colCount} {incr i} { |
| 51 | if {$i > 0} { |
| 52 | puts $sep |
| 53 | } else { |
| 54 | puts "#$row: $sep" |
| 55 | } |
| 56 | puts $colNames($i) = [query_col_string $stmt $i] |
| 57 | } |
| 58 | puts "\n" |
| 59 | } |
| 60 | unset row |
| 61 | |
| @@ -61,34 +63,40 @@ | |
| 63 | #query_finalize $stmt2 |
| 64 | |
| 65 | |
| 66 | proc query_step_each {{stmt} {callback}} { |
| 67 | set colNames(0) 0 |
| 68 | set colCount [query_col_count $stmt] |
| 69 | for {set i 0} {$i < $colCount} {incr i} { |
| 70 | set colNames($i) [query_col_name $stmt $i] |
| 71 | } |
| 72 | upvar cb $callback |
| 73 | for {set row 0} {0 < [query_step $stmt]} {incr row} { |
| 74 | #puts "Calling callback: $stmt $colCount colNames\n" |
| 75 | $callback $stmt $colCount |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | |
| 80 | set stmt [query_prepare {SELECT uid, login FROM user}] |
| 81 | set rc 0 |
| 82 | catch { |
| 83 | proc my_each {stmt colCount} { |
| 84 | upvar 2 sep sep |
| 85 | puts [query_col_int $stmt 0] $sep |
| 86 | puts [query_col_double $stmt 0] $sep |
| 87 | puts [query_col_string $stmt 1] |
| 88 | # for {set i 0} {$i < $colCount} {incr i} { |
| 89 | # if {$i > 0} { puts $sep } |
| 90 | # } |
| 91 | puts "\n" |
| 92 | # error "hi!" |
| 93 | } |
| 94 | query_step_each $stmt my_each |
| 95 | # query_step_each $stmt { |
| 96 | # proc each {stmt cc} { puts hi "\n" } |
| 97 | # } |
| 98 | } rc |
| 99 | query_finalize $stmt |
| 100 | puts rc = $rc |
| 101 | |
| 102 | </th1> |
| 103 |