Fossil SCM

Refactored th1 query API to use (query foo) instead of query_foo. Added th1_query.wiki doc page.

stephan 2012-07-14 20:45 th1-query-api
Commit bd98f0f4304fd49a0d0bf2c0f0d8055073d3892f
+5 -1
--- src/th.h
+++ src/th.h
@@ -223,11 +223,15 @@
223223
int Th_WrongNumArgs2(Th_Interp *interp, const char *zCmdName,
224224
int zCmdLen, const char *zMsg);
225225
226226
typedef struct Th_SubCommand {char *zName; Th_CommandProc xProc;} Th_SubCommand;
227227
int Th_CallSubCommand(Th_Interp*,void*,int,const char**,int*,Th_SubCommand*);
228
-
228
+/*
229
+** Works similarly to Th_CallSubCommand() but adjusts argc/argv/argl
230
+** by 1 before passing on the call to the subcommand.
231
+*/
232
+int Th_CallSubCommand2(Th_Interp *interp, void *ctx, int argc, const char **argv, int *argl, Th_SubCommand *aSub);
229233
/*
230234
** Sends the given data through vTab->out.f() if vTab->out.enabled is
231235
** true, otherwise this is a no-op. Returns 0 or higher on success, *
232236
** a negative value if vTab->out.f is NULL.
233237
*/
234238
--- src/th.h
+++ src/th.h
@@ -223,11 +223,15 @@
223 int Th_WrongNumArgs2(Th_Interp *interp, const char *zCmdName,
224 int zCmdLen, const char *zMsg);
225
226 typedef struct Th_SubCommand {char *zName; Th_CommandProc xProc;} Th_SubCommand;
227 int Th_CallSubCommand(Th_Interp*,void*,int,const char**,int*,Th_SubCommand*);
228
 
 
 
 
229 /*
230 ** Sends the given data through vTab->out.f() if vTab->out.enabled is
231 ** true, otherwise this is a no-op. Returns 0 or higher on success, *
232 ** a negative value if vTab->out.f is NULL.
233 */
234
--- src/th.h
+++ src/th.h
@@ -223,11 +223,15 @@
223 int Th_WrongNumArgs2(Th_Interp *interp, const char *zCmdName,
224 int zCmdLen, const char *zMsg);
225
226 typedef struct Th_SubCommand {char *zName; Th_CommandProc xProc;} Th_SubCommand;
227 int Th_CallSubCommand(Th_Interp*,void*,int,const char**,int*,Th_SubCommand*);
228 /*
229 ** Works similarly to Th_CallSubCommand() but adjusts argc/argv/argl
230 ** by 1 before passing on the call to the subcommand.
231 */
232 int Th_CallSubCommand2(Th_Interp *interp, void *ctx, int argc, const char **argv, int *argl, Th_SubCommand *aSub);
233 /*
234 ** Sends the given data through vTab->out.f() if vTab->out.enabled is
235 ** true, otherwise this is a no-op. Returns 0 or higher on success, *
236 ** a negative value if vTab->out.f is NULL.
237 */
238
--- src/th_lang.c
+++ src/th_lang.c
@@ -881,10 +881,30 @@
881881
}
882882
883883
Th_ErrorMessage(interp, "Expected sub-command, got:", argv[1], argl[1]);
884884
return TH_ERROR;
885885
}
886
+
887
+int Th_CallSubCommand2(
888
+ Th_Interp *interp,
889
+ void *ctx,
890
+ int argc,
891
+ const char **argv,
892
+ int *argl,
893
+ Th_SubCommand *aSub
894
+){
895
+ int i;
896
+ for(i=0; aSub[i].zName; i++){
897
+ char const *zName = aSub[i].zName;
898
+ if( th_strlen(zName)==argl[1] && 0==memcmp(zName, argv[1], argl[1]) ){
899
+ return aSub[i].xProc(interp, ctx, argc-1, argv+1, argl+1);
900
+ }
901
+ }
902
+ Th_ErrorMessage(interp, "Expected sub-command, got:", argv[1], argl[1]);
903
+ return TH_ERROR;
904
+}
905
+
886906
887907
/*
888908
** TH Syntax:
889909
**
890910
** string compare STR1 STR2
891911
--- src/th_lang.c
+++ src/th_lang.c
@@ -881,10 +881,30 @@
881 }
882
883 Th_ErrorMessage(interp, "Expected sub-command, got:", argv[1], argl[1]);
884 return TH_ERROR;
885 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
886
887 /*
888 ** TH Syntax:
889 **
890 ** string compare STR1 STR2
891
--- src/th_lang.c
+++ src/th_lang.c
@@ -881,10 +881,30 @@
881 }
882
883 Th_ErrorMessage(interp, "Expected sub-command, got:", argv[1], argl[1]);
884 return TH_ERROR;
885 }
886
887 int Th_CallSubCommand2(
888 Th_Interp *interp,
889 void *ctx,
890 int argc,
891 const char **argv,
892 int *argl,
893 Th_SubCommand *aSub
894 ){
895 int i;
896 for(i=0; aSub[i].zName; i++){
897 char const *zName = aSub[i].zName;
898 if( th_strlen(zName)==argl[1] && 0==memcmp(zName, argv[1], argl[1]) ){
899 return aSub[i].xProc(interp, ctx, argc-1, argv+1, argl+1);
900 }
901 }
902 Th_ErrorMessage(interp, "Expected sub-command, got:", argv[1], argl[1]);
903 return TH_ERROR;
904 }
905
906
907 /*
908 ** TH Syntax:
909 **
910 ** string compare STR1 STR2
911
--- src/th_main.c
+++ src/th_main.c
@@ -1324,10 +1324,37 @@
13241324
return queryReportDbErr( interp );
13251325
}
13261326
Th_SetResultInt( interp, 0 );
13271327
return TH_OK;
13281328
}
1329
+
1330
+static int queryTopLevelCmd(
1331
+ Th_Interp *interp,
1332
+ void *ctx,
1333
+ int argc,
1334
+ const char **argv,
1335
+ int *argl
1336
+){
1337
+ static Th_SubCommand aSub[] = {
1338
+ {"bind_int", queryBindIntCmd},
1339
+ {"bind_double", queryBindDoubleCmd},
1340
+ {"bind_null", queryBindNullCmd},
1341
+ {"bind_string", queryBindStringCmd},
1342
+ {"col_count", queryColCountCmd},
1343
+ {"col_double", queryColDoubleCmd},
1344
+ {"col_int", queryColIntCmd},
1345
+ {"col_is_null", queryColIsNullCmd},
1346
+ {"col_name", queryColNameCmd},
1347
+ {"col_string", queryColStringCmd},
1348
+ {"col_type", queryColTypeCmd},
1349
+ {"step", queryStepCmd},
1350
+ {"finalize", queryFinalizeCmd},
1351
+ {"prepare", queryPrepareCmd},
1352
+ {0, 0}
1353
+ };
1354
+ Th_CallSubCommand2( interp, ctx, argc, argv, argl, aSub );
1355
+}
13291356
13301357
int th_register_sqlite(Th_Interp *interp){
13311358
enum { BufLen = 100 };
13321359
char buf[BufLen];
13331360
int i, l;
@@ -1342,10 +1369,12 @@
13421369
SET(SQLITE_OK);
13431370
SET(SQLITE_ROW);
13441371
SET(SQLITE_TEXT);
13451372
#undef SET
13461373
static Th_Command_Reg aCommand[] = {
1374
+ {"query", queryTopLevelCmd, 0},
1375
+#if 0
13471376
{"query_bind_int", queryBindIntCmd, 0},
13481377
{"query_bind_double", queryBindDoubleCmd,0},
13491378
{"query_bind_null", queryBindNullCmd, 0},
13501379
{"query_bind_string", queryBindStringCmd,0},
13511380
{"query_col_count", queryColCountCmd, 0},
@@ -1356,10 +1385,11 @@
13561385
{"query_col_string", queryColStringCmd, 0},
13571386
{"query_col_type", queryColTypeCmd, 0},
13581387
{"query_finalize", queryFinalizeCmd, 0},
13591388
{"query_prepare", queryPrepareCmd, 0},
13601389
{"query_step", queryStepCmd, 0},
1390
+#endif
13611391
{0, 0, 0}
13621392
};
13631393
Th_register_commands( interp, aCommand );
13641394
}
13651395
13661396
--- src/th_main.c
+++ src/th_main.c
@@ -1324,10 +1324,37 @@
1324 return queryReportDbErr( interp );
1325 }
1326 Th_SetResultInt( interp, 0 );
1327 return TH_OK;
1328 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1329
1330 int th_register_sqlite(Th_Interp *interp){
1331 enum { BufLen = 100 };
1332 char buf[BufLen];
1333 int i, l;
@@ -1342,10 +1369,12 @@
1342 SET(SQLITE_OK);
1343 SET(SQLITE_ROW);
1344 SET(SQLITE_TEXT);
1345 #undef SET
1346 static Th_Command_Reg aCommand[] = {
 
 
1347 {"query_bind_int", queryBindIntCmd, 0},
1348 {"query_bind_double", queryBindDoubleCmd,0},
1349 {"query_bind_null", queryBindNullCmd, 0},
1350 {"query_bind_string", queryBindStringCmd,0},
1351 {"query_col_count", queryColCountCmd, 0},
@@ -1356,10 +1385,11 @@
1356 {"query_col_string", queryColStringCmd, 0},
1357 {"query_col_type", queryColTypeCmd, 0},
1358 {"query_finalize", queryFinalizeCmd, 0},
1359 {"query_prepare", queryPrepareCmd, 0},
1360 {"query_step", queryStepCmd, 0},
 
1361 {0, 0, 0}
1362 };
1363 Th_register_commands( interp, aCommand );
1364 }
1365
1366
--- src/th_main.c
+++ src/th_main.c
@@ -1324,10 +1324,37 @@
1324 return queryReportDbErr( interp );
1325 }
1326 Th_SetResultInt( interp, 0 );
1327 return TH_OK;
1328 }
1329
1330 static int queryTopLevelCmd(
1331 Th_Interp *interp,
1332 void *ctx,
1333 int argc,
1334 const char **argv,
1335 int *argl
1336 ){
1337 static Th_SubCommand aSub[] = {
1338 {"bind_int", queryBindIntCmd},
1339 {"bind_double", queryBindDoubleCmd},
1340 {"bind_null", queryBindNullCmd},
1341 {"bind_string", queryBindStringCmd},
1342 {"col_count", queryColCountCmd},
1343 {"col_double", queryColDoubleCmd},
1344 {"col_int", queryColIntCmd},
1345 {"col_is_null", queryColIsNullCmd},
1346 {"col_name", queryColNameCmd},
1347 {"col_string", queryColStringCmd},
1348 {"col_type", queryColTypeCmd},
1349 {"step", queryStepCmd},
1350 {"finalize", queryFinalizeCmd},
1351 {"prepare", queryPrepareCmd},
1352 {0, 0}
1353 };
1354 Th_CallSubCommand2( interp, ctx, argc, argv, argl, aSub );
1355 }
1356
1357 int th_register_sqlite(Th_Interp *interp){
1358 enum { BufLen = 100 };
1359 char buf[BufLen];
1360 int i, l;
@@ -1342,10 +1369,12 @@
1369 SET(SQLITE_OK);
1370 SET(SQLITE_ROW);
1371 SET(SQLITE_TEXT);
1372 #undef SET
1373 static Th_Command_Reg aCommand[] = {
1374 {"query", queryTopLevelCmd, 0},
1375 #if 0
1376 {"query_bind_int", queryBindIntCmd, 0},
1377 {"query_bind_double", queryBindDoubleCmd,0},
1378 {"query_bind_null", queryBindNullCmd, 0},
1379 {"query_bind_string", queryBindStringCmd,0},
1380 {"query_col_count", queryColCountCmd, 0},
@@ -1356,10 +1385,11 @@
1385 {"query_col_string", queryColStringCmd, 0},
1386 {"query_col_type", queryColTypeCmd, 0},
1387 {"query_finalize", queryFinalizeCmd, 0},
1388 {"query_prepare", queryPrepareCmd, 0},
1389 {"query_step", queryStepCmd, 0},
1390 #endif
1391 {0, 0, 0}
1392 };
1393 Th_register_commands( interp, aCommand );
1394 }
1395
1396
--- test/th1-query-api-1.th1
+++ test/th1-query-api-1.th1
@@ -22,12 +22,12 @@
2222
return 42
2323
}
2424
set a [xyz]
2525
puts "a=${a}" ! \n
2626
27
-set stmt [query_prepare {SELECT login, cap FROM user}]
28
-set colCount [query_col_count $stmt]
27
+set stmt [query prepare {SELECT login, cap FROM user}]
28
+set colCount [query col_count $stmt]
2929
puts "query column count: ${colCount}\n"
3030
puts "stmt id=${stmt}\n"
3131
3232
proc noop {} {}
3333
proc incr {name {step 1}} {
@@ -38,75 +38,75 @@
3838
3939
set sep " "
4040
set i 0
4141
set colNames(0) 0
4242
for {set i 0} {$i < $colCount} {incr i} {
43
- set colNames($i) [query_col_name $stmt $i]
43
+ set colNames($i) [query col_name $stmt $i]
4444
puts "colNames($i)=" $colNames($i) "\n"
4545
}
4646
47
-for {set row 0} {0 < [query_step $stmt]} {incr row} {
47
+for {set row 0} {0 < [query step $stmt]} {incr row} {
4848
for {set i 0} {$i < $colCount} {incr i} {
4949
if {$i > 0} {
5050
puts $sep
5151
} else {
5252
puts "#$row: $sep"
5353
}
54
- puts $colNames($i) = [query_col_string $stmt $i]
54
+ puts $colNames($i) = [query col_string $stmt $i]
5555
}
5656
puts "\n"
5757
}
5858
unset row
5959
60
-query_finalize $stmt
60
+query finalize $stmt
6161
6262
6363
proc query_step_each {{stmt} {callback}} {
6464
set colNames(0) 0
65
- set colCount [query_col_count $stmt]
65
+ set colCount [query col_count $stmt]
6666
for {set i 0} {$i < $colCount} {incr i} {
67
- set colNames($i) [query_col_name $stmt $i]
67
+ set colNames($i) [query col_name $stmt $i]
6868
}
6969
upvar cb $callback
70
- for {set row 0} {0 < [query_step $stmt]} {incr row} {
70
+ for {set row 0} {0 < [query step $stmt]} {incr row} {
7171
#puts "Calling callback: $stmt $colCount colNames\n"
7272
$callback $stmt $colCount
7373
}
7474
}
7575
7676
set sql {SELECT uid, login FROM user WHERE uid!=?}
7777
#set sql {SELECT uid, login FROM user WHERE login=?}
7878
#set sql {SELECT tagid, value, null FROM tagxref WHERE value IS ? LIMIT 3}
79
-set stmt [query_prepare $sql]
79
+set stmt [query prepare $sql]
8080
puts "stmt ID=" $stmt "\n"
81
-query_bind_int $stmt 1 3
82
-#set stmt [query_prepare $sql]
83
-#query_bind_string $stmt 1 stephan
84
-#set stmt [query_prepare $sql]
85
-#query_bind_null $stmt 1
81
+query bind_int $stmt 1 3
82
+#set stmt [query prepare $sql]
83
+#query bind_string $stmt 1 stephan
84
+#set stmt [query prepare $sql]
85
+#query bind_null $stmt 1
8686
set rc 0
8787
puts "USER LIST:\n"
8888
catch {
8989
proc my_each {stmt colCount} {
9090
upvar 2 sep sep
91
- puts [query_col_int $stmt 0] " (type=" [query_col_type $stmt 0] ")" $sep
92
- puts [query_col_double $stmt 0] $sep
93
- puts [query_col_string $stmt 1] " (type=" [query_col_type $stmt 1] ")" $sep
94
- puts "isnull 0 ?= " [query_col_is_null $stmt 0] $sep
95
- puts "isnull 2 ?= " [query_col_is_null $stmt 2]
91
+ puts [query col_int $stmt 0] " (type=" [query col_type $stmt 0] ")" $sep
92
+ puts [query col_double $stmt 0] $sep
93
+ puts [query col_string $stmt 1] " (type=" [query col_type $stmt 1] ")" $sep
94
+ puts "isnull 0 ?= " [query col_is_null $stmt 0] $sep
95
+ puts "isnull 2 ?= " [query col_is_null $stmt 2]
9696
# for {set i 0} {$i < $colCount} {incr i} {
9797
# if {$i > 0} { puts $sep }
9898
# }
9999
puts "\n"
100100
# error "hi!"
101101
}
102
- query_step_each $stmt my_each
103
-# query_step_each $stmt {
102
+ query step_each $stmt my_each
103
+# query step_each $stmt {
104104
# proc each {stmt cc} { puts hi "\n" }
105105
# }
106106
} rc
107
-query_finalize $stmt
107
+query finalize $stmt
108108
puts rc = $rc "\n"
109109
110110
set consts [list SQLITE_BLOB SQLITE_DONE SQLITE_ERROR SQLITE_FLOAT SQLITE_INTEGER SQLITE_NULL SQLITE_OK SQLITE_ROW SQLITE_TEXT]
111111
#set consts $SQLITE_CONSTANTS
112112
puts consts = $consts "\n"
@@ -139,37 +139,37 @@
139139
proc multiStmt {} {
140140
set max 5
141141
set i 0
142142
set s(0) 0
143143
for {set i 0} {$i < $max} {incr i} {
144
- set s($i) [query_prepare "SELECT $i"]
144
+ set s($i) [query prepare "SELECT $i"]
145145
puts "s($i) = $s($i)\n"
146146
}
147147
for {set i 0} {$i < $max} {incr i} {
148
- query_step $s($i)
148
+ query step $s($i)
149149
}
150150
for {set i 0} {$i < $max} {incr i} {
151151
puts "closing stmt $s($i)\n"
152
- query_finalize $s($i)
152
+ query finalize $s($i)
153153
}
154154
155155
puts "Preparing again\n"
156156
157157
for {set i 0} {$i < $max} {incr i} {
158
- set s($i) [query_prepare "SELECT $i"]
158
+ set s($i) [query prepare "SELECT $i"]
159159
puts "s($i) = $s($i)\n"
160160
}
161161
for {set i 0} {$i < $max} {incr i} {
162
- query_step $s($i)
162
+ query step $s($i)
163163
}
164164
puts "Closing again\n"
165165
166166
for {set i 0} {$i < $max} {incr i} {
167167
puts "closing stmt $s($i)\n"
168
- query_finalize $s($i)
168
+ query finalize $s($i)
169169
}
170170
}
171171
multiStmt
172172
173173
enable_output 1
174174
puts "If you got this far, you win!\n"
175175
</th1>
176176
177177
ADDED www/th1_query.wiki
--- test/th1-query-api-1.th1
+++ test/th1-query-api-1.th1
@@ -22,12 +22,12 @@
22 return 42
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 puts "stmt id=${stmt}\n"
31
32 proc noop {} {}
33 proc incr {name {step 1}} {
@@ -38,75 +38,75 @@
38
39 set sep " "
40 set i 0
41 set colNames(0) 0
42 for {set i 0} {$i < $colCount} {incr i} {
43 set colNames($i) [query_col_name $stmt $i]
44 puts "colNames($i)=" $colNames($i) "\n"
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_col_string $stmt $i]
55 }
56 puts "\n"
57 }
58 unset row
59
60 query_finalize $stmt
61
62
63 proc query_step_each {{stmt} {callback}} {
64 set colNames(0) 0
65 set colCount [query_col_count $stmt]
66 for {set i 0} {$i < $colCount} {incr i} {
67 set colNames($i) [query_col_name $stmt $i]
68 }
69 upvar cb $callback
70 for {set row 0} {0 < [query_step $stmt]} {incr row} {
71 #puts "Calling callback: $stmt $colCount colNames\n"
72 $callback $stmt $colCount
73 }
74 }
75
76 set sql {SELECT uid, login FROM user WHERE uid!=?}
77 #set sql {SELECT uid, login FROM user WHERE login=?}
78 #set sql {SELECT tagid, value, null FROM tagxref WHERE value IS ? LIMIT 3}
79 set stmt [query_prepare $sql]
80 puts "stmt ID=" $stmt "\n"
81 query_bind_int $stmt 1 3
82 #set stmt [query_prepare $sql]
83 #query_bind_string $stmt 1 stephan
84 #set stmt [query_prepare $sql]
85 #query_bind_null $stmt 1
86 set rc 0
87 puts "USER LIST:\n"
88 catch {
89 proc my_each {stmt colCount} {
90 upvar 2 sep sep
91 puts [query_col_int $stmt 0] " (type=" [query_col_type $stmt 0] ")" $sep
92 puts [query_col_double $stmt 0] $sep
93 puts [query_col_string $stmt 1] " (type=" [query_col_type $stmt 1] ")" $sep
94 puts "isnull 0 ?= " [query_col_is_null $stmt 0] $sep
95 puts "isnull 2 ?= " [query_col_is_null $stmt 2]
96 # for {set i 0} {$i < $colCount} {incr i} {
97 # if {$i > 0} { puts $sep }
98 # }
99 puts "\n"
100 # error "hi!"
101 }
102 query_step_each $stmt my_each
103 # query_step_each $stmt {
104 # proc each {stmt cc} { puts hi "\n" }
105 # }
106 } rc
107 query_finalize $stmt
108 puts rc = $rc "\n"
109
110 set consts [list SQLITE_BLOB SQLITE_DONE SQLITE_ERROR SQLITE_FLOAT SQLITE_INTEGER SQLITE_NULL SQLITE_OK SQLITE_ROW SQLITE_TEXT]
111 #set consts $SQLITE_CONSTANTS
112 puts consts = $consts "\n"
@@ -139,37 +139,37 @@
139 proc multiStmt {} {
140 set max 5
141 set i 0
142 set s(0) 0
143 for {set i 0} {$i < $max} {incr i} {
144 set s($i) [query_prepare "SELECT $i"]
145 puts "s($i) = $s($i)\n"
146 }
147 for {set i 0} {$i < $max} {incr i} {
148 query_step $s($i)
149 }
150 for {set i 0} {$i < $max} {incr i} {
151 puts "closing stmt $s($i)\n"
152 query_finalize $s($i)
153 }
154
155 puts "Preparing again\n"
156
157 for {set i 0} {$i < $max} {incr i} {
158 set s($i) [query_prepare "SELECT $i"]
159 puts "s($i) = $s($i)\n"
160 }
161 for {set i 0} {$i < $max} {incr i} {
162 query_step $s($i)
163 }
164 puts "Closing again\n"
165
166 for {set i 0} {$i < $max} {incr i} {
167 puts "closing stmt $s($i)\n"
168 query_finalize $s($i)
169 }
170 }
171 multiStmt
172
173 enable_output 1
174 puts "If you got this far, you win!\n"
175 </th1>
176
177 DDED www/th1_query.wiki
--- test/th1-query-api-1.th1
+++ test/th1-query-api-1.th1
@@ -22,12 +22,12 @@
22 return 42
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 puts "stmt id=${stmt}\n"
31
32 proc noop {} {}
33 proc incr {name {step 1}} {
@@ -38,75 +38,75 @@
38
39 set sep " "
40 set i 0
41 set colNames(0) 0
42 for {set i 0} {$i < $colCount} {incr i} {
43 set colNames($i) [query col_name $stmt $i]
44 puts "colNames($i)=" $colNames($i) "\n"
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 col_string $stmt $i]
55 }
56 puts "\n"
57 }
58 unset row
59
60 query finalize $stmt
61
62
63 proc query_step_each {{stmt} {callback}} {
64 set colNames(0) 0
65 set colCount [query col_count $stmt]
66 for {set i 0} {$i < $colCount} {incr i} {
67 set colNames($i) [query col_name $stmt $i]
68 }
69 upvar cb $callback
70 for {set row 0} {0 < [query step $stmt]} {incr row} {
71 #puts "Calling callback: $stmt $colCount colNames\n"
72 $callback $stmt $colCount
73 }
74 }
75
76 set sql {SELECT uid, login FROM user WHERE uid!=?}
77 #set sql {SELECT uid, login FROM user WHERE login=?}
78 #set sql {SELECT tagid, value, null FROM tagxref WHERE value IS ? LIMIT 3}
79 set stmt [query prepare $sql]
80 puts "stmt ID=" $stmt "\n"
81 query bind_int $stmt 1 3
82 #set stmt [query prepare $sql]
83 #query bind_string $stmt 1 stephan
84 #set stmt [query prepare $sql]
85 #query bind_null $stmt 1
86 set rc 0
87 puts "USER LIST:\n"
88 catch {
89 proc my_each {stmt colCount} {
90 upvar 2 sep sep
91 puts [query col_int $stmt 0] " (type=" [query col_type $stmt 0] ")" $sep
92 puts [query col_double $stmt 0] $sep
93 puts [query col_string $stmt 1] " (type=" [query col_type $stmt 1] ")" $sep
94 puts "isnull 0 ?= " [query col_is_null $stmt 0] $sep
95 puts "isnull 2 ?= " [query col_is_null $stmt 2]
96 # for {set i 0} {$i < $colCount} {incr i} {
97 # if {$i > 0} { puts $sep }
98 # }
99 puts "\n"
100 # error "hi!"
101 }
102 query step_each $stmt my_each
103 # query step_each $stmt {
104 # proc each {stmt cc} { puts hi "\n" }
105 # }
106 } rc
107 query finalize $stmt
108 puts rc = $rc "\n"
109
110 set consts [list SQLITE_BLOB SQLITE_DONE SQLITE_ERROR SQLITE_FLOAT SQLITE_INTEGER SQLITE_NULL SQLITE_OK SQLITE_ROW SQLITE_TEXT]
111 #set consts $SQLITE_CONSTANTS
112 puts consts = $consts "\n"
@@ -139,37 +139,37 @@
139 proc multiStmt {} {
140 set max 5
141 set i 0
142 set s(0) 0
143 for {set i 0} {$i < $max} {incr i} {
144 set s($i) [query prepare "SELECT $i"]
145 puts "s($i) = $s($i)\n"
146 }
147 for {set i 0} {$i < $max} {incr i} {
148 query step $s($i)
149 }
150 for {set i 0} {$i < $max} {incr i} {
151 puts "closing stmt $s($i)\n"
152 query finalize $s($i)
153 }
154
155 puts "Preparing again\n"
156
157 for {set i 0} {$i < $max} {incr i} {
158 set s($i) [query prepare "SELECT $i"]
159 puts "s($i) = $s($i)\n"
160 }
161 for {set i 0} {$i < $max} {incr i} {
162 query step $s($i)
163 }
164 puts "Closing again\n"
165
166 for {set i 0} {$i < $max} {incr i} {
167 puts "closing stmt $s($i)\n"
168 query finalize $s($i)
169 }
170 }
171 multiStmt
172
173 enable_output 1
174 puts "If you got this far, you win!\n"
175 </th1>
176
177 DDED www/th1_query.wiki
--- a/www/th1_query.wiki
+++ b/www/th1_query.wiki
@@ -0,0 +1,18 @@
1
+"]
2
+ puts "stmt Itypetmt
3
+
4
+query col string $sti><pre>
5
+set stmt [qquery $stmt finalize
6
+</pre></nowiki>
7
+
8
+
9
+<h2>step</h2>
10
+
11
+This subcommand steps the result set by one row. It returns 0
12
+at the e____bind__"]
13
+ puts "stmpetmt
14
+
15
+query col string $s_double * <tt>bind_null"]
16
+ puts "stmt Itypetmt
17
+
18
+qmt It split bind_xxx into "bind xxx"2I@Rs,1:_15@UA,1:_L@VG,1:_1a@Vb,1:_1M@XC,8:_is_nullP@a~,15@Z3,1:_b@_9,1:_Z@_l,7:_stringW@_F,1:_1i@aw,Y:TODO: split col_xxx into "col xxx"12@ca,30FoId;
--- a/www/th1_query.wiki
+++ b/www/th1_query.wiki
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/www/th1_query.wiki
+++ b/www/th1_query.wiki
@@ -0,0 +1,18 @@
1 "]
2 puts "stmt Itypetmt
3
4 query col string $sti><pre>
5 set stmt [qquery $stmt finalize
6 </pre></nowiki>
7
8
9 <h2>step</h2>
10
11 This subcommand steps the result set by one row. It returns 0
12 at the e____bind__"]
13 puts "stmpetmt
14
15 query col string $s_double * <tt>bind_null"]
16 puts "stmt Itypetmt
17
18 qmt It split bind_xxx into "bind xxx"2I@Rs,1:_15@UA,1:_L@VG,1:_1a@Vb,1:_1M@XC,8:_is_nullP@a~,15@Z3,1:_b@_9,1:_Z@_l,7:_stringW@_F,1:_1i@aw,Y:TODO: split col_xxx into "col xxx"12@ca,30FoId;

Keyboard Shortcuts

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