mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Add test cases and fix minor error-handling issues in unionvtab.c.
FossilOrigin-Name: deadaad2a0801b3c30d2a076d8eb006b62d8557cff820e0939741c078477c83f
This commit is contained in:
@@ -254,7 +254,7 @@ static void unionReset(int *pRc, sqlite3_stmt *pStmt, char **pzErr){
|
|||||||
int rc = sqlite3_reset(pStmt);
|
int rc = sqlite3_reset(pStmt);
|
||||||
if( *pRc==SQLITE_OK ){
|
if( *pRc==SQLITE_OK ){
|
||||||
*pRc = rc;
|
*pRc = rc;
|
||||||
if( rc && pzErr ){
|
if( rc ){
|
||||||
*pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(sqlite3_db_handle(pStmt)));
|
*pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(sqlite3_db_handle(pStmt)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,10 +315,12 @@ static char *unionSourceToStr(
|
|||||||
if( *pRc==SQLITE_OK ){
|
if( *pRc==SQLITE_OK ){
|
||||||
int bPk = 0;
|
int bPk = 0;
|
||||||
const char *zType = 0;
|
const char *zType = 0;
|
||||||
|
int rc;
|
||||||
|
|
||||||
int rc = sqlite3_table_column_metadata(
|
sqlite3_table_column_metadata(
|
||||||
db, pSrc->zDb, pSrc->zTab, "_rowid_", &zType, 0, 0, &bPk, 0
|
db, pSrc->zDb, pSrc->zTab, "_rowid_", &zType, 0, 0, &bPk, 0
|
||||||
);
|
);
|
||||||
|
rc = sqlite3_errcode(db);
|
||||||
if( rc==SQLITE_ERROR
|
if( rc==SQLITE_ERROR
|
||||||
|| (rc==SQLITE_OK && (!bPk || sqlite3_stricmp("integer", zType)))
|
|| (rc==SQLITE_OK && (!bPk || sqlite3_stricmp("integer", zType)))
|
||||||
){
|
){
|
||||||
@@ -475,17 +477,17 @@ static int unionConnect(
|
|||||||
if( rc==SQLITE_OK ){
|
if( rc==SQLITE_OK ){
|
||||||
pTab->db = db;
|
pTab->db = db;
|
||||||
rc = unionSourceCheck(pTab, pzErr);
|
rc = unionSourceCheck(pTab, pzErr);
|
||||||
}
|
|
||||||
|
|
||||||
/* Compose a CREATE TABLE statement and pass it to declare_vtab() */
|
/* Compose a CREATE TABLE statement and pass it to declare_vtab() */
|
||||||
pStmt = unionPreparePrintf(&rc, pzErr, db, "SELECT "
|
pStmt = unionPreparePrintf(&rc, pzErr, db, "SELECT "
|
||||||
"'CREATE TABLE xyz('"
|
"'CREATE TABLE xyz('"
|
||||||
" || group_concat(quote(name) || ' ' || type, ', ')"
|
" || group_concat(quote(name) || ' ' || type, ', ')"
|
||||||
" || ')',"
|
" || ')',"
|
||||||
"max((cid+1) * (type='INTEGER' COLLATE nocase AND pk=1))-1 "
|
"max((cid+1) * (type='INTEGER' COLLATE nocase AND pk=1))-1 "
|
||||||
"FROM pragma_table_info(%Q, ?)",
|
"FROM pragma_table_info(%Q, ?)",
|
||||||
pTab->aSrc[0].zTab, pTab->aSrc[0].zDb
|
pTab->aSrc[0].zTab, pTab->aSrc[0].zDb
|
||||||
);
|
);
|
||||||
|
}
|
||||||
if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
|
if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||||
const char *zDecl = (const char*)sqlite3_column_text(pStmt, 0);
|
const char *zDecl = (const char*)sqlite3_column_text(pStmt, 0);
|
||||||
rc = sqlite3_declare_vtab(db, zDecl);
|
rc = sqlite3_declare_vtab(db, zDecl);
|
||||||
@@ -658,29 +660,24 @@ static int unionFilter(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( zSql ){
|
if( iMin==iMax ){
|
||||||
if( iMin==iMax ){
|
zSql = sqlite3_mprintf("%z WHERE rowid=%lld", zSql, iMin);
|
||||||
zSql = sqlite3_mprintf("%z WHERE rowid=%lld", zSql, iMin);
|
}else{
|
||||||
}else{
|
const char *zWhere = "WHERE";
|
||||||
const char *zWhere = "WHERE";
|
if( iMin!=SMALLEST_INT64 && iMin>pSrc->iMin ){
|
||||||
if( iMin!=SMALLEST_INT64 && iMin>pSrc->iMin ){
|
zSql = sqlite3_mprintf("%z WHERE rowid>=%lld", zSql, iMin);
|
||||||
zSql = sqlite3_mprintf("%z WHERE rowid>=%lld", zSql, iMin);
|
zWhere = "AND";
|
||||||
zWhere = "AND";
|
}
|
||||||
}
|
if( iMax!=LARGEST_INT64 && iMax<pSrc->iMax ){
|
||||||
if( iMax!=LARGEST_INT64 && iMax<pSrc->iMax ){
|
zSql = sqlite3_mprintf("%z %s rowid<=%lld", zSql, zWhere, iMax);
|
||||||
zSql = sqlite3_mprintf("%z %s rowid<=%lld", zSql, zWhere, iMax);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( rc==SQLITE_OK ){
|
if( zSql==0 ) return rc;
|
||||||
if( zSql==0 ) return SQLITE_OK;
|
pCsr->pStmt = unionPrepare(&rc, pTab->db, zSql, &pTab->base.zErrMsg);
|
||||||
pCsr->pStmt = unionPrepare(&rc, pTab->db, zSql, &pTab->base.zErrMsg);
|
|
||||||
}
|
|
||||||
sqlite3_free(zSql);
|
sqlite3_free(zSql);
|
||||||
|
|
||||||
if( rc!=SQLITE_OK ) return rc;
|
if( rc!=SQLITE_OK ) return rc;
|
||||||
return unionNext(pVtabCursor);
|
return unionNext(pVtabCursor);
|
||||||
}
|
}
|
||||||
@@ -718,15 +715,15 @@ static int unionBestIndex(
|
|||||||
if( p->usable && (p->iColumn<0 || p->iColumn==pTab->iPK) ){
|
if( p->usable && (p->iColumn<0 || p->iColumn==pTab->iPK) ){
|
||||||
switch( p->op ){
|
switch( p->op ){
|
||||||
case SQLITE_INDEX_CONSTRAINT_EQ:
|
case SQLITE_INDEX_CONSTRAINT_EQ:
|
||||||
if( iEq<0 ) iEq = i;
|
iEq = i;
|
||||||
break;
|
break;
|
||||||
case SQLITE_INDEX_CONSTRAINT_LE:
|
case SQLITE_INDEX_CONSTRAINT_LE:
|
||||||
case SQLITE_INDEX_CONSTRAINT_LT:
|
case SQLITE_INDEX_CONSTRAINT_LT:
|
||||||
if( iLt<0 ) iLt = i;
|
iLt = i;
|
||||||
break;
|
break;
|
||||||
case SQLITE_INDEX_CONSTRAINT_GE:
|
case SQLITE_INDEX_CONSTRAINT_GE:
|
||||||
case SQLITE_INDEX_CONSTRAINT_GT:
|
case SQLITE_INDEX_CONSTRAINT_GT:
|
||||||
if( iGt<0 ) iGt = i;
|
iGt = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
manifest
15
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Fix\sduplicate\stest\sname.\s\sNo\schanges\sto\scode.
|
C Add\stest\scases\sand\sfix\sminor\serror-handling\sissues\sin\sunionvtab.c.
|
||||||
D 2017-07-18T20:30:55.470
|
D 2017-07-18T20:49:15.448
|
||||||
F Makefile.in d9873c9925917cca9990ee24be17eb9613a668012c85a343aef7e5536ae266e8
|
F Makefile.in d9873c9925917cca9990ee24be17eb9613a668012c85a343aef7e5536ae266e8
|
||||||
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
||||||
F Makefile.msc 02b469e9dcd5b7ee63fc1fb05babc174260ee4cfa4e0ef2e48c3c6801567a016
|
F Makefile.msc 02b469e9dcd5b7ee63fc1fb05babc174260ee4cfa4e0ef2e48c3c6801567a016
|
||||||
@@ -281,7 +281,7 @@ F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52
|
|||||||
F ext/misc/spellfix.c a4723b6aff748a417b5091b68a46443265c40f0d
|
F ext/misc/spellfix.c a4723b6aff748a417b5091b68a46443265c40f0d
|
||||||
F ext/misc/stmt.c 6f16443abb3551e3f5813bb13ba19a30e7032830015b0f92fe0c0453045c0a11
|
F ext/misc/stmt.c 6f16443abb3551e3f5813bb13ba19a30e7032830015b0f92fe0c0453045c0a11
|
||||||
F ext/misc/totype.c 4a167594e791abeed95e0a8db028822b5e8fe512
|
F ext/misc/totype.c 4a167594e791abeed95e0a8db028822b5e8fe512
|
||||||
F ext/misc/unionvtab.c b4d76914379f45c83783ee6120ec76ce6df64806ecee4cb127532207770c6de2
|
F ext/misc/unionvtab.c e6ed3a3a6fe244c7968620cd74b33a140610541896f69dc28f7168e9dea6326b
|
||||||
F ext/misc/vfslog.c fe40fab5c077a40477f7e5eba994309ecac6cc95
|
F ext/misc/vfslog.c fe40fab5c077a40477f7e5eba994309ecac6cc95
|
||||||
F ext/misc/vfsstat.c bf10ef0bc51e1ad6756629e1edb142f7a8db1178
|
F ext/misc/vfsstat.c bf10ef0bc51e1ad6756629e1edb142f7a8db1178
|
||||||
F ext/misc/vtshim.c 1976e6dd68dd0d64508c91a6dfab8e75f8aaf6cd
|
F ext/misc/vtshim.c 1976e6dd68dd0d64508c91a6dfab8e75f8aaf6cd
|
||||||
@@ -1433,6 +1433,7 @@ F test/types.test bf816ce73c7dfcfe26b700c19f97ef4050d194ff
|
|||||||
F test/types2.test 1aeb81976841a91eef292723649b5c4fe3bc3cac
|
F test/types2.test 1aeb81976841a91eef292723649b5c4fe3bc3cac
|
||||||
F test/types3.test 99e009491a54f4dc02c06bdbc0c5eea56ae3e25a
|
F test/types3.test 99e009491a54f4dc02c06bdbc0c5eea56ae3e25a
|
||||||
F test/unionvtab.test ba9f8146e847c2386567bc65e43079a8cd9c047ce9f76e034033731efec07989
|
F test/unionvtab.test ba9f8146e847c2386567bc65e43079a8cd9c047ce9f76e034033731efec07989
|
||||||
|
F test/unionvtabfault.test ccb87c510efd0da88d90d813cfaeebe69f2be78cdfbdc3343b04fd9fc507d887
|
||||||
F test/unique.test 93f8b2ef5ea51b9495f8d6493429b1fd0f465264
|
F test/unique.test 93f8b2ef5ea51b9495f8d6493429b1fd0f465264
|
||||||
F test/unique2.test 3674e9f2a3f1fbbfd4772ac74b7a97090d0f77d2
|
F test/unique2.test 3674e9f2a3f1fbbfd4772ac74b7a97090d0f77d2
|
||||||
F test/unixexcl.test d936ba2b06794018e136418addd59a2354eeae97
|
F test/unixexcl.test d936ba2b06794018e136418addd59a2354eeae97
|
||||||
@@ -1635,7 +1636,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
|||||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||||
P d49639c208ac366f6c675ac5671accc2a597558b62a51520194276c61f32d406
|
P 47b80ecc679e656ef865e73809d6a9aa485eceeacab86d10d405881c5d9872bd
|
||||||
R 8e7e64ef28860f8f5c2014a6618c15fa
|
R 15ffe9e1282d41d7effada7cdd9cfc02
|
||||||
U mistachkin
|
U dan
|
||||||
Z 42bd4dccb8e05d700a80262381d5f5c6
|
Z 25cb6976b03d308a83435181e64ee0cf
|
||||||
|
@@ -1 +1 @@
|
|||||||
47b80ecc679e656ef865e73809d6a9aa485eceeacab86d10d405881c5d9872bd
|
deadaad2a0801b3c30d2a076d8eb006b62d8557cff820e0939741c078477c83f
|
68
test/unionvtabfault.test
Normal file
68
test/unionvtabfault.test
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
# 2017-07-15
|
||||||
|
#
|
||||||
|
# The author disclaims copyright to this source code. In place of
|
||||||
|
# a legal notice, here is a blessing:
|
||||||
|
#
|
||||||
|
# May you do good and not evil.
|
||||||
|
# May you find forgiveness for yourself and forgive others.
|
||||||
|
# May you share freely, never taking more than you give.
|
||||||
|
#
|
||||||
|
#***********************************************************************
|
||||||
|
# This file implements regression tests for SQLite library. The
|
||||||
|
# focus of this file is percentile.c extension
|
||||||
|
#
|
||||||
|
|
||||||
|
set testdir [file dirname $argv0]
|
||||||
|
source $testdir/tester.tcl
|
||||||
|
set testprefix unionvtabfault
|
||||||
|
|
||||||
|
|
||||||
|
forcedelete test.db2
|
||||||
|
do_execsql_test 1.0 {
|
||||||
|
ATTACH 'test.db2' AS aux;
|
||||||
|
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT);
|
||||||
|
CREATE TABLE t2(a INTEGER PRIMARY KEY, b TEXT);
|
||||||
|
CREATE TABLE aux.t3(a INTEGER PRIMARY KEY, b TEXT);
|
||||||
|
|
||||||
|
INSERT INTO t1 VALUES(1, 'one'), (2, 'two'), (3, 'three');
|
||||||
|
INSERT INTO t2 VALUES(10, 'ten'), (11, 'eleven'), (12, 'twelve');
|
||||||
|
INSERT INTO t3 VALUES(20, 'twenty'), (21, 'twenty-one'), (22, 'twenty-two');
|
||||||
|
}
|
||||||
|
faultsim_save_and_close
|
||||||
|
|
||||||
|
do_faultsim_test 1.1 -faults * -prep {
|
||||||
|
faultsim_restore_and_reopen
|
||||||
|
load_static_extension db unionvtab
|
||||||
|
execsql { ATTACH 'test.db2' AS aux; }
|
||||||
|
execsql { CREATE TEMP TABLE xyz(x); }
|
||||||
|
} -body {
|
||||||
|
execsql {
|
||||||
|
CREATE VIRTUAL TABLE temp.uuu USING unionvtab(
|
||||||
|
"VALUES(NULL, 't1', 1, 9), ('main', 't2', 10, 19), ('aux', 't3', 20, 29)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} -test {
|
||||||
|
faultsim_test_result {0 {}} \
|
||||||
|
{1 {vtable constructor failed: uuu}} \
|
||||||
|
{1 {sql error: interrupted}}
|
||||||
|
}
|
||||||
|
|
||||||
|
faultsim_restore_and_reopen
|
||||||
|
load_static_extension db unionvtab
|
||||||
|
execsql { ATTACH 'test.db2' AS aux; }
|
||||||
|
execsql { CREATE TEMP TABLE xyz(x); }
|
||||||
|
execsql {
|
||||||
|
CREATE VIRTUAL TABLE temp.uuu USING unionvtab(
|
||||||
|
"VALUES(NULL, 't1', 1, 9), ('main', 't2', 10, 19), ('aux', 't3', 20, 29)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
do_faultsim_test 1.2 -faults oom* -prep {
|
||||||
|
} -body {
|
||||||
|
execsql { SELECT * FROM uuu }
|
||||||
|
} -test {
|
||||||
|
faultsim_test_result {0 {1 one 2 two 3 three 10 ten 11 eleven 12 twelve 20 twenty 21 twenty-one 22 twenty-two}}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
finish_test
|
||||||
|
|
Reference in New Issue
Block a user