Fossil SCM

Added query_col_int and query_col_double. Renamed query_column_xxx to query_col_xxx.

stephan 2012-07-14 00:56 th1-query-api
Commit b01eb58bcaadfd79ba6e1732c7f7003b674dc406
2 files changed +86 -17 +19 -11
+86 -17
--- src/th_main.c
+++ src/th_main.c
@@ -517,10 +517,43 @@
517517
518518
static void queryReportDbErr( Th_Interp * interp, int rc ){
519519
char const * msg = sqlite3_errmsg( g.db );
520520
Th_ErrorMessage(interp, "db error:", msg, -1);
521521
}
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
+}
522555
523556
static int queryStepCmd(
524557
Th_Interp *interp,
525558
void *p,
526559
int argc,
@@ -530,12 +563,11 @@
530563
sqlite3_stmt * pStmt = NULL;
531564
int rc = 0;
532565
if( argc!=2 ){
533566
return Th_WrongNumArgs(interp, "query_step StmtHandle");
534567
}
535
- pStmt = queryStmtHandle(interp, argv[1], argl[1], &rc);
536
- if( rc < 1 ){
568
+ if(0 != queryStmtIndexArgs(interp, argc, argv, argl, &pStmt, NULL)){
537569
return TH_ERROR;
538570
}
539571
rc = sqlite3_step( pStmt );
540572
switch(rc){
541573
case SQLITE_ROW:
@@ -560,27 +592,62 @@
560592
int *argl
561593
){
562594
sqlite3_stmt * pStmt = NULL;
563595
char const * val;
564596
int index;
565
- int rc = 0;
566597
int valLen;
567598
if( argc!=3 ){
568
- return Th_WrongNumArgs(interp, "query_column_string StmtHandle Index");
599
+ return Th_WrongNumArgs(interp, "query_col_string StmtHandle Index");
569600
}
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)){
575602
return TH_ERROR;
576603
}
577604
val = sqlite3_column_text( pStmt, index );
578605
valLen = val ? sqlite3_column_bytes( pStmt, index ) : 0;
579606
Th_SetResult( interp, val, valLen );
580607
return TH_OK;
581608
}
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
+}
582649
583650
584651
static int queryColCountCmd(
585652
Th_Interp *interp,
586653
void *p,
@@ -589,11 +656,11 @@
589656
int *argl
590657
){
591658
int rc;
592659
sqlite3_stmt * pStmt = NULL;
593660
if( argc!=2 ){
594
- return Th_WrongNumArgs(interp, "query_column_count StmtHandle");
661
+ return Th_WrongNumArgs(interp, "query_col_count StmtHandle");
595662
}
596663
pStmt = queryStmtHandle(interp, argv[1], argl[1], NULL);
597664
if( NULL == pStmt ){
598665
return TH_ERROR;
599666
}
@@ -613,11 +680,11 @@
613680
char const * val;
614681
int index;
615682
int rc = 0;
616683
int valLen;
617684
if( argc!=3 ){
618
- return Th_WrongNumArgs(interp, "query_column_name StmtHandle Index");
685
+ return Th_WrongNumArgs(interp, "query_col_name StmtHandle Index");
619686
}
620687
pStmt = queryStmtHandle(interp, argv[1], argl[1], &rc);
621688
if( rc < 1 ){
622689
return TH_ERROR;
623690
}
@@ -662,16 +729,18 @@
662729
{"date", dateCmd, 0},
663730
{"html", putsCmd, &puts_Html},
664731
{"puts", putsCmd, &puts_Normal},
665732
{"putsl", putsCmd, &puts_Ext},
666733
#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},
673742
#endif
674743
{"wiki", wikiCmd, 0},
675744
{"repository", repositoryCmd, 0},
676745
{0, 0, 0}
677746
};
678747
--- 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
--- 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".
13
<th1>
24
proc bar {} {
35
puts "json ?= [hasfeature json]\n"
46
puts "tcl ?= [hasfeature tcl]\n"
57
puts "ssl ?= [hasfeature ssl]\n"
@@ -21,16 +23,16 @@
2123
}
2224
set a [xyz]
2325
puts "a=${a}" ! \n
2426
2527
set stmt [query_prepare {SELECT login, cap FROM user}]
26
-set colCount [query_column_count $stmt]
28
+set colCount [query_col_count $stmt]
2729
puts "query column count: ${colCount}\n"
2830
#set stmt2 [query_prepare {SELECT cap, login FROM user}]
2931
#puts "stmt=${stmt} stmt2=${stmt2}\n"
3032
#putsl "step =" [query_step $stmt]
31
-#putsl "val =" [query_column_string $stmt 1]
33
+#putsl "val =" [query_col_string $stmt 1]
3234
3335
proc noop {} {}
3436
proc incr {name {step 1}} {
3537
upvar $name x
3638
set x [expr $x+$step]
@@ -39,21 +41,21 @@
3941
4042
set sep " "
4143
set i 0
4244
set colNames(0) 0
4345
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]
4547
}
4648
4749
for {set row 0} {0 < [query_step $stmt]} {incr row} {
4850
for {set i 0} {$i < $colCount} {incr i} {
4951
if {$i > 0} {
5052
puts $sep
5153
} else {
5254
puts "#$row: $sep"
5355
}
54
- puts $colNames($i) = [query_column_string $stmt $i]
56
+ puts $colNames($i) = [query_col_string $stmt $i]
5557
}
5658
puts "\n"
5759
}
5860
unset row
5961
@@ -61,34 +63,40 @@
6163
#query_finalize $stmt2
6264
6365
6466
proc query_step_each {{stmt} {callback}} {
6567
set colNames(0) 0
66
- set colCount [query_column_count $stmt]
68
+ set colCount [query_col_count $stmt]
6769
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]
6971
}
7072
upvar cb $callback
7173
for {set row 0} {0 < [query_step $stmt]} {incr row} {
7274
#puts "Calling callback: $stmt $colCount colNames\n"
7375
$callback $stmt $colCount
7476
}
7577
}
7678
7779
78
-set stmt [query_prepare {SELECT login FROM user}]
80
+set stmt [query_prepare {SELECT uid, login FROM user}]
7981
set rc 0
8082
catch {
8183
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
+# }
8691
puts "\n"
8792
# error "hi!"
8893
}
8994
query_step_each $stmt my_each
95
+# query_step_each $stmt {
96
+# proc each {stmt cc} { puts hi "\n" }
97
+# }
9098
} rc
9199
query_finalize $stmt
92100
puts rc = $rc
93101
94102
</th1>
95103
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button