Adjust the implementation of the ".selftest" feature of the shell to avoid
using the deprecated sqlite3_get_table() interface. FossilOrigin-Name: 3168e2c92ad0a0dafc78a27ee1d87ac89f426585f506f418a0182141335dc68b
This commit is contained in:
parent
d96cc6fbcb
commit
c5d353fb33
12
manifest
12
manifest
@ -1,5 +1,5 @@
|
||||
C Add\sa\stestcase()\sto\sconfirm\sthat\san\sOOM\son\ssqlite3DbStrNDup()\sis\shandled\ncorrectly\sin\strigger.c.
|
||||
D 2017-06-08T14:35:21.062
|
||||
C Adjust\sthe\simplementation\sof\sthe\s".selftest"\sfeature\sof\sthe\sshell\sto\savoid\nusing\sthe\sdeprecated\ssqlite3_get_table()\sinterface.
|
||||
D 2017-06-09T02:27:49.833
|
||||
F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb
|
||||
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
||||
F Makefile.msc 8eeb80162074004e906b53d7340a12a14c471a83743aab975947e95ce061efcc
|
||||
@ -406,7 +406,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
|
||||
F src/resolve.c adf3ef9843135b1383321ad751f16f5a40c3f37925154555a3e61653d2a954e8
|
||||
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
|
||||
F src/select.c d93205e43af302d9eb147fddecc956509ee9d0dde6297ee3f93c591f60f0e295
|
||||
F src/shell.c eca7e7fe8dae859aa56e462c5b35c735976fa1e5e1d7a90fd5a32aa4615c1825
|
||||
F src/shell.c a43292634af8e3528fec5c6e3360f122fc807a0af619d566ea44fdb98dcfca78
|
||||
F src/sqlite.h.in ad7f4101e3613b1134d1ad6c61ff385424ffac0d542627fd31f26667fdd91c94
|
||||
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
|
||||
F src/sqlite3ext.h 58fd0676d3111d02e62e5a35992a7d3da5d3f88753acc174f2d37b774fbbdd28
|
||||
@ -1582,7 +1582,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P b30dfba811cb531b09ff2e71a1a18ed53c816cb39155dd52ca3e2701425fe17b
|
||||
R 8b6275f7a74215887d823a2acf4a12c1
|
||||
P 343e55992f503efa662e49bb0f3c0d798defd0a11f2ee1c36968902fa7e06823
|
||||
R 05d16117faed3625799198482db32d3f
|
||||
U drh
|
||||
Z afbd99381bc167bd1f1d6007c35f0942
|
||||
Z 9b8c30c557442a6e6787e2734b5f737b
|
||||
|
@ -1 +1 @@
|
||||
343e55992f503efa662e49bb0f3c0d798defd0a11f2ee1c36968902fa7e06823
|
||||
3168e2c92ad0a0dafc78a27ee1d87ac89f426585f506f418a0182141335dc68b
|
121
src/shell.c
121
src/shell.c
@ -6000,19 +6000,11 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
int bIsInit = 0; /* True to initialize the SELFTEST table */
|
||||
int bVerbose = 0; /* Verbose output */
|
||||
int bSelftestExists; /* True if SELFTEST already exists */
|
||||
char **azTest = 0; /* Content of the SELFTEST table */
|
||||
int nRow = 0; /* Number of rows in the SELFTEST table */
|
||||
int nCol = 4; /* Number of columns in the SELFTEST table */
|
||||
int i; /* Loop counter */
|
||||
int i, k; /* Loop counters */
|
||||
int nTest = 0; /* Number of tests runs */
|
||||
int nErr = 0; /* Number of errors seen */
|
||||
ShellText str; /* Answer for a query */
|
||||
static char *azDefaultTest[] = {
|
||||
0, 0, 0, 0,
|
||||
"0", "memo", "Missing SELFTEST table - default checks only", "",
|
||||
"1", "run", "PRAGMA integrity_check", "ok"
|
||||
};
|
||||
static const int nDefaultRow = 2;
|
||||
sqlite3_stmt *pStmt = 0; /* Query against the SELFTEST table */
|
||||
|
||||
open_db(p,0);
|
||||
for(i=1; i<nArg; i++){
|
||||
@ -6042,70 +6034,71 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
createSelftestTable(p);
|
||||
bSelftestExists = 1;
|
||||
}
|
||||
if( bSelftestExists ){
|
||||
rc = sqlite3_get_table(p->db,
|
||||
"SELECT tno,op,cmd,ans FROM selftest ORDER BY tno",
|
||||
&azTest, &nRow, &nCol, 0);
|
||||
initText(&str);
|
||||
appendText(&str, "x", 0);
|
||||
for(k=bSelftestExists; k>=0; k--){
|
||||
if( k==1 ){
|
||||
rc = sqlite3_prepare_v2(p->db,
|
||||
"SELECT tno,op,cmd,ans FROM selftest ORDER BY tno",
|
||||
-1, &pStmt, 0);
|
||||
}else{
|
||||
rc = sqlite3_prepare_v2(p->db,
|
||||
"VALUES(0,'memo','Missing SELFTEST table - default checks only',''),"
|
||||
" (1,'run','PRAGMA integrity_check','ok')",
|
||||
-1, &pStmt, 0);
|
||||
}
|
||||
if( rc ){
|
||||
raw_printf(stderr, "Error querying the selftest table\n");
|
||||
rc = 1;
|
||||
sqlite3_free_table(azTest);
|
||||
sqlite3_finalize(pStmt);
|
||||
goto meta_command_exit;
|
||||
}else if( nRow==0 ){
|
||||
sqlite3_free_table(azTest);
|
||||
azTest = azDefaultTest;
|
||||
nRow = nDefaultRow;
|
||||
}
|
||||
}else{
|
||||
azTest = azDefaultTest;
|
||||
nRow = nDefaultRow;
|
||||
}
|
||||
initText(&str);
|
||||
appendText(&str, "x", 0);
|
||||
for(i=1; i<=nRow; i++){
|
||||
int tno = atoi(azTest[i*nCol]);
|
||||
const char *zOp = azTest[i*nCol+1];
|
||||
const char *zSql = azTest[i*nCol+2];
|
||||
const char *zAns = azTest[i*nCol+3];
|
||||
for(i=1; sqlite3_step(pStmt)==SQLITE_ROW; i++){
|
||||
int tno = sqlite3_column_int(pStmt, 0);
|
||||
const char *zOp = (const char*)sqlite3_column_text(pStmt, 1);
|
||||
const char *zSql = (const char*)sqlite3_column_text(pStmt, 2);
|
||||
const char *zAns = (const char*)sqlite3_column_text(pStmt, 3);
|
||||
|
||||
if( bVerbose>0 ){
|
||||
char *zQuote = sqlite3_mprintf("%q", zSql);
|
||||
printf("%d: %s %s\n", tno, zOp, zSql);
|
||||
sqlite3_free(zQuote);
|
||||
}
|
||||
if( strcmp(zOp,"memo")==0 ){
|
||||
utf8_printf(p->out, "%s\n", zSql);
|
||||
}else
|
||||
if( strcmp(zOp,"run")==0 ){
|
||||
char *zErrMsg = 0;
|
||||
str.n = 0;
|
||||
str.z[0] = 0;
|
||||
rc = sqlite3_exec(p->db, zSql, captureOutputCallback, &str, &zErrMsg);
|
||||
nTest++;
|
||||
if( bVerbose ){
|
||||
utf8_printf(p->out, "Result: %s\n", str.z);
|
||||
k = 0;
|
||||
if( bVerbose>0 ){
|
||||
char *zQuote = sqlite3_mprintf("%q", zSql);
|
||||
printf("%d: %s %s\n", tno, zOp, zSql);
|
||||
sqlite3_free(zQuote);
|
||||
}
|
||||
if( rc || zErrMsg ){
|
||||
nErr++;
|
||||
if( strcmp(zOp,"memo")==0 ){
|
||||
utf8_printf(p->out, "%s\n", zSql);
|
||||
}else
|
||||
if( strcmp(zOp,"run")==0 ){
|
||||
char *zErrMsg = 0;
|
||||
str.n = 0;
|
||||
str.z[0] = 0;
|
||||
rc = sqlite3_exec(p->db, zSql, captureOutputCallback, &str, &zErrMsg);
|
||||
nTest++;
|
||||
if( bVerbose ){
|
||||
utf8_printf(p->out, "Result: %s\n", str.z);
|
||||
}
|
||||
if( rc || zErrMsg ){
|
||||
nErr++;
|
||||
rc = 1;
|
||||
utf8_printf(p->out, "%d: error-code-%d: %s\n", tno, rc, zErrMsg);
|
||||
sqlite3_free(zErrMsg);
|
||||
}else if( strcmp(zAns,str.z)!=0 ){
|
||||
nErr++;
|
||||
rc = 1;
|
||||
utf8_printf(p->out, "%d: Expected: [%s]\n", tno, zAns);
|
||||
utf8_printf(p->out, "%d: Got: [%s]\n", tno, str.z);
|
||||
}
|
||||
}else
|
||||
{
|
||||
utf8_printf(stderr,
|
||||
"Unknown operation \"%s\" on selftest line %d\n", zOp, tno);
|
||||
rc = 1;
|
||||
utf8_printf(p->out, "%d: error-code-%d: %s\n", tno, rc, zErrMsg);
|
||||
sqlite3_free(zErrMsg);
|
||||
}else if( strcmp(zAns,str.z)!=0 ){
|
||||
nErr++;
|
||||
rc = 1;
|
||||
utf8_printf(p->out, "%d: Expected: [%s]\n", tno, zAns);
|
||||
utf8_printf(p->out, "%d: Got: [%s]\n", tno, str.z);
|
||||
break;
|
||||
}
|
||||
}else
|
||||
{
|
||||
utf8_printf(stderr,
|
||||
"Unknown operation \"%s\" on selftest line %d\n", zOp, tno);
|
||||
rc = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} /* End loop over rows of content from SELFTEST */
|
||||
sqlite3_finalize(pStmt);
|
||||
} /* End loop over k */
|
||||
freeText(&str);
|
||||
if( azTest!=azDefaultTest ) sqlite3_free_table(azTest);
|
||||
utf8_printf(p->out, "%d errors out of %d tests\n", nErr, nTest);
|
||||
}else
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user