| | @@ -1296,15 +1296,64 @@ |
| 1296 | 1296 | return queryReportDbErr( interp ); |
| 1297 | 1297 | } |
| 1298 | 1298 | Th_SetResultInt( interp, 0 ); |
| 1299 | 1299 | return TH_OK; |
| 1300 | 1300 | } |
| 1301 | + |
| 1302 | +int th_register_sqlite(Th_Interp *interp){ |
| 1303 | + enum { BufLen = 100 }; |
| 1304 | + char buf[BufLen]; |
| 1305 | + int i, l; |
| 1306 | +#define SET(K) l = snprintf(buf, BufLen, "%d", K); \ |
| 1307 | + Th_SetVar( interp, #K, strlen(#K), buf, l ); |
| 1308 | + SET(SQLITE_BLOB); |
| 1309 | + SET(SQLITE_DONE); |
| 1310 | + SET(SQLITE_ERROR); |
| 1311 | + SET(SQLITE_FLOAT); |
| 1312 | + SET(SQLITE_INTEGER); |
| 1313 | + SET(SQLITE_NULL); |
| 1314 | + SET(SQLITE_OK); |
| 1315 | + SET(SQLITE_ROW); |
| 1316 | + SET(SQLITE_TEXT); |
| 1317 | +#undef SET |
| 1318 | + static Th_Command_Reg aCommand[] = { |
| 1319 | + {"query_bind_int", queryBindIntCmd, 0}, |
| 1320 | + {"query_bind_double", queryBindDoubleCmd,0}, |
| 1321 | + {"query_bind_null", queryBindNullCmd, 0}, |
| 1322 | + {"query_bind_string", queryBindStringCmd,0}, |
| 1323 | + {"query_col_count", queryColCountCmd, 0}, |
| 1324 | + {"query_col_double", queryColDoubleCmd, 0}, |
| 1325 | + {"query_col_int", queryColIntCmd, 0}, |
| 1326 | + {"query_col_is_null", queryColIsNullCmd, 0}, |
| 1327 | + {"query_col_name", queryColNameCmd, 0}, |
| 1328 | + {"query_col_string", queryColStringCmd, 0}, |
| 1329 | + {"query_col_type", queryColTypeCmd, 0}, |
| 1330 | + {"query_finalize", queryFinalizeCmd, 0}, |
| 1331 | + {"query_prepare", queryPrepareCmd, 0}, |
| 1332 | + {"query_step", queryStepCmd, 0}, |
| 1333 | + {0, 0, 0} |
| 1334 | + }; |
| 1335 | + Th_register_commands( interp, aCommand ); |
| 1336 | +} |
| 1301 | 1337 | |
| 1302 | 1338 | #endif |
| 1303 | 1339 | /* end TH_USE_SQLITE */ |
| 1304 | 1340 | |
| 1305 | | - |
| 1341 | +int Th_register_commands( Th_Interp * interp, |
| 1342 | + Th_Command_Reg const * aCommand ){ |
| 1343 | + int i; |
| 1344 | + int rc = TH_OK; |
| 1345 | + for(i=0; (TH_OK==rc) && aCommand[i].zName; ++i){ |
| 1346 | + if ( !aCommand[i].zName ) break; |
| 1347 | + else if( !aCommand[i].xProc ) continue; |
| 1348 | + else{ |
| 1349 | + rc = Th_CreateCommand(interp, aCommand[i].zName, aCommand[i].xProc, |
| 1350 | + aCommand[i].pContext, 0); |
| 1351 | + } |
| 1352 | + } |
| 1353 | + return rc; |
| 1354 | +} |
| 1306 | 1355 | |
| 1307 | 1356 | /* |
| 1308 | 1357 | ** Make sure the interpreter has been initialized. Initialize it if |
| 1309 | 1358 | ** it has not been already. |
| 1310 | 1359 | ** |
| | @@ -1311,15 +1360,11 @@ |
| 1311 | 1360 | ** The interpreter is stored in the g.interp global variable. |
| 1312 | 1361 | */ |
| 1313 | 1362 | void Th_FossilInit(void){ |
| 1314 | 1363 | static PutsCmdData puts_Html = {0, 0, 0}; |
| 1315 | 1364 | static PutsCmdData puts_Normal = {1, 0, 0}; |
| 1316 | | - static struct _Command { |
| 1317 | | - const char *zName; |
| 1318 | | - Th_CommandProc xProc; |
| 1319 | | - void *pContext; |
| 1320 | | - } aCommand[] = { |
| 1365 | + static Th_Command_Reg aCommand[] = { |
| 1321 | 1366 | {"anycap", anycapCmd, 0}, |
| 1322 | 1367 | {"combobox", comboboxCmd, 0}, |
| 1323 | 1368 | {"enable_output", enableOutputCmd, 0}, |
| 1324 | 1369 | {"linecount", linecntCmd, 0}, |
| 1325 | 1370 | {"hascap", hascapCmd, 0}, |
| | @@ -1337,27 +1382,10 @@ |
| 1337 | 1382 | {"argv_getstr", argvFindOptionStringCmd, 0}, |
| 1338 | 1383 | {"argv_getbool", argvFindOptionBoolCmd, 0}, |
| 1339 | 1384 | {"argv_getint", argvFindOptionIntCmd, 0}, |
| 1340 | 1385 | #endif |
| 1341 | 1386 | |
| 1342 | | -#ifdef TH_USE_SQLITE |
| 1343 | | - {"query_bind_int", queryBindIntCmd, 0}, |
| 1344 | | - {"query_bind_double", queryBindDoubleCmd,0}, |
| 1345 | | - {"query_bind_null", queryBindNullCmd, 0}, |
| 1346 | | - {"query_bind_string", queryBindStringCmd,0}, |
| 1347 | | - {"query_col_count", queryColCountCmd, 0}, |
| 1348 | | - {"query_col_double", queryColDoubleCmd, 0}, |
| 1349 | | - {"query_col_int", queryColIntCmd, 0}, |
| 1350 | | - {"query_col_is_null", queryColIsNullCmd, 0}, |
| 1351 | | - {"query_col_name", queryColNameCmd, 0}, |
| 1352 | | - {"query_col_string", queryColStringCmd, 0}, |
| 1353 | | - {"query_col_type", queryColTypeCmd, 0}, |
| 1354 | | - {"query_finalize", queryFinalizeCmd, 0}, |
| 1355 | | - {"query_prepare", queryPrepareCmd, 0}, |
| 1356 | | - {"query_step", queryStepCmd, 0}, |
| 1357 | | -#endif |
| 1358 | | - |
| 1359 | 1387 | {0, 0, 0} |
| 1360 | 1388 | }; |
| 1361 | 1389 | if( g.interp==0 ){ |
| 1362 | 1390 | int i; |
| 1363 | 1391 | if(g.cgiOutput){ |
| | @@ -1372,34 +1400,14 @@ |
| 1372 | 1400 | #ifdef FOSSIL_ENABLE_TCL |
| 1373 | 1401 | if( getenv("TH1_ENABLE_TCL")!=0 || db_get_boolean("tcl", 0) ){ |
| 1374 | 1402 | th_register_tcl(g.interp, &g.tcl); /* Tcl integration commands. */ |
| 1375 | 1403 | } |
| 1376 | 1404 | #endif |
| 1377 | | - for(i=0; i<sizeof(aCommand)/sizeof(aCommand[0]); i++){ |
| 1378 | | - if ( !aCommand[i].zName || !aCommand[i].xProc ) continue; |
| 1379 | | - Th_CreateCommand(g.interp, aCommand[i].zName, aCommand[i].xProc, |
| 1380 | | - aCommand[i].pContext, 0); |
| 1381 | | - } |
| 1382 | 1405 | #ifdef TH_USE_SQLITE |
| 1383 | | - { |
| 1384 | | - enum { BufLen = 100 }; |
| 1385 | | - char buf[BufLen]; |
| 1386 | | - int i, l; |
| 1387 | | -#define SET(K) l = snprintf(buf, BufLen, "%d", K); \ |
| 1388 | | - Th_SetVar( g.interp, #K, strlen(#K), buf, l ); |
| 1389 | | - SET(SQLITE_BLOB); |
| 1390 | | - SET(SQLITE_DONE); |
| 1391 | | - SET(SQLITE_ERROR); |
| 1392 | | - SET(SQLITE_FLOAT); |
| 1393 | | - SET(SQLITE_INTEGER); |
| 1394 | | - SET(SQLITE_NULL); |
| 1395 | | - SET(SQLITE_OK); |
| 1396 | | - SET(SQLITE_ROW); |
| 1397 | | - SET(SQLITE_TEXT); |
| 1398 | | -#undef SET |
| 1399 | | - } |
| 1406 | + th_register_sqlite(g.interp); |
| 1400 | 1407 | #endif |
| 1408 | + Th_register_commands( g.interp, aCommand ); |
| 1401 | 1409 | } |
| 1402 | 1410 | } |
| 1403 | 1411 | |
| 1404 | 1412 | /* |
| 1405 | 1413 | ** Store a string value in a variable in the interpreter. |
| 1406 | 1414 | |