/ Check-in [6ce8b7ca]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix a segfault in swarmvtab that could occur if there was an error in the SQL statement passed to the constructor. Add other test cases.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6ce8b7ca62fcf97875395fc1a989179309e0abb48d4465658ef0d871434ea057
User & Date: dan 2017-08-05 16:15:33
Context
2017-08-07
17:14
Add new test file "bigmmap.test". For testing builds with -DSQLITE_MAX_MMAP_SIZE > 2GB. check-in: 17447062 user: dan tags: trunk
14:15
Update this branch with latest trunk changes. check-in: 17bc7ded user: dan tags: server-process-edition
2017-08-05
16:15
Fix a segfault in swarmvtab that could occur if there was an error in the SQL statement passed to the constructor. Add other test cases. check-in: 6ce8b7ca user: dan tags: trunk
15:49
Microoptimization in pcache1.c makes the code slightly smaller and faster. check-in: 422cd9f3 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/misc/unionvtab.c.

   717    717           }
   718    718         }
   719    719       }
   720    720       unionFinalize(&rc, pStmt, pzErr);
   721    721       pStmt = 0;
   722    722   
   723    723       /* Capture the not-found callback UDF name */
   724         -    if( argc>=5 ){
          724  +    if( rc==SQLITE_OK && argc>=5 ){
   725    725         pTab->zNotFoundCallback = unionStrdup(&rc, argv[4]);
   726    726         unionDequote(pTab->zNotFoundCallback);
   727    727       }
   728    728   
   729    729       /* It is an error if the SELECT statement returned zero rows. If only
   730    730       ** because there is no way to determine the schema of the virtual 
   731    731       ** table in this case.  */

Changes to test/swarmvtab.test.

   126    126   
   127    127   #-------------------------------------------------------------------------
   128    128   # Test some error conditions:
   129    129   #
   130    130   #   2.1: Database file does not exist.
   131    131   #   2.2: Table does not exist.
   132    132   #   2.3: Table schema does not match.
          133  +#   2.4: Syntax error in SELECT statement.
   133    134   #
   134    135   reset_db
   135    136   load_static_extension db unionvtab
   136    137   do_test 2.0.1 {
   137    138     db eval {
   138    139       CREATE TABLE t0(a INTEGER PRIMARY KEY, b TEXT);
   139    140       WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<400) 
................................................................................
   179    180   } {1 {unable to open database file}}
   180    181   do_catchsql_test 2.2 {
   181    182     SELECT * FROM s1 WHERE rowid BETWEEN 101 AND 200;
   182    183   } {1 {no such rowid table: t15}}
   183    184   do_catchsql_test 2.3 {
   184    185     SELECT * FROM s1 WHERE rowid BETWEEN 201 AND 300;
   185    186   } {1 {source table schema mismatch}}
          187  +
          188  +do_catchsql_test 2.4 {
          189  +  CREATE VIRTUAL TABLE temp.x1 USING swarmvtab('SELECT * FROMdir');
          190  +} {1 {sql error: near "FROMdir": syntax error}}
          191  +do_catchsql_test 2.5 {
          192  +  CREATE VIRTUAL TABLE temp.x1 USING swarmvtab('SELECT * FROMdir', 'fetchdb');
          193  +} {1 {sql error: near "FROMdir": syntax error}}
          194  +
          195  +for {set i 0} {$i < 40} {incr i} {
          196  +  forcedelete "test.db$i"
          197  +}
          198  +
          199  +#-------------------------------------------------------------------------
          200  +# Test the outcome of the fetch function throwing an exception.
          201  +#
          202  +proc fetch_db {file} {
          203  +  error "fetch_db error!"
          204  +}
          205  +
          206  +db func fetch_db fetch_db
          207  +
          208  +do_catchsql_test 3.1 {
          209  +  CREATE VIRTUAL TABLE temp.xyz USING swarmvtab(
          210  +    'VALUES
          211  +        ("test.db1", "t1", 1, 10),
          212  +        ("test.db2", "t1", 11, 20)
          213  +    ', 'fetch_db_no_such_function'
          214  +  );
          215  +} {1 {no such function: fetch_db_no_such_function}}
          216  +
          217  +do_catchsql_test 3.2 {
          218  +  CREATE VIRTUAL TABLE temp.xyz USING swarmvtab(
          219  +    'VALUES
          220  +        ("test.db1", "t1", 1, 10),
          221  +        ("test.db2", "t1", 11, 20)
          222  +    ', 'fetch_db'
          223  +  );
          224  +} {1 {fetch_db error!}}
          225  +
          226  +do_execsql_test 3.3.1 {
          227  +  ATTACH 'test.db1' AS aux;
          228  +  CREATE TABLE aux.t1(a INTEGER PRIMARY KEY, b);
          229  +  INSERT INTO aux.t1 VALUES(1, NULL);
          230  +  INSERT INTO aux.t1 VALUES(2, NULL);
          231  +  INSERT INTO aux.t1 VALUES(9, NULL);
          232  +  DETACH aux;
          233  +  CREATE VIRTUAL TABLE temp.xyz USING swarmvtab(
          234  +    'VALUES
          235  +        ("test.db1", "t1", 1, 10),
          236  +        ("test.db2", "t1", 11, 20)
          237  +    ', 'fetch_db'
          238  +  );
          239  +} {}
          240  +
          241  +do_catchsql_test 3.3 { SELECT * FROM xyz } {1 {fetch_db error!}}
          242  +
          243  +
   186    244   
   187    245   finish_test
   188    246   

Added test/swarmvtabfault.test.

            1  +# 2017-07-15
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this file is error handling in the swarmvtab extension.
           13  +#
           14  +
           15  +set testdir [file dirname $argv0]
           16  +source $testdir/tester.tcl
           17  +set testprefix swarmvtabfault
           18  +
           19  +ifcapable !vtab {
           20  +  finish_test
           21  +  return
           22  +}
           23  +
           24  +proc fetch_db {file} {
           25  +  forcedelete $file
           26  +  sqlite3 dbX $file
           27  +  dbX eval { CREATE TABLE t1(a INTEGER PRIMARY KEY, b) }
           28  +  dbX close
           29  +}
           30  +
           31  +forcedelete test.db1
           32  +do_execsql_test 1.0 {
           33  +  ATTACH 'test.db1' AS aux;
           34  +  CREATE TABLE aux.t1(a INTEGER PRIMARY KEY, b);
           35  +  INSERT INTO aux.t1 VALUES(1, NULL);
           36  +  INSERT INTO aux.t1 VALUES(2, NULL);
           37  +  INSERT INTO aux.t1 VALUES(9, NULL);
           38  +  DETACH aux;
           39  +} {}
           40  +
           41  +faultsim_save_and_close
           42  +do_faultsim_test 1.1 -faults oom* -prep {
           43  +  faultsim_restore_and_reopen
           44  +  db func fetch_db fetch_db
           45  +  load_static_extension db unionvtab
           46  +  db eval {
           47  +    CREATE VIRTUAL TABLE temp.xyz USING swarmvtab(
           48  +        'VALUES
           49  +        ("test.db1", "t1", 1, 10),
           50  +        ("test.db2", "t1", 11, 20)
           51  +        ', 'fetch_db'
           52  +    );
           53  +  }
           54  +} -body {
           55  +  execsql { SELECT a FROM xyz }
           56  +} -test {
           57  +  faultsim_test_result {0 {1 2 9}} {1 {sql error: out of memory}}
           58  +}
           59  +
           60  +finish_test
           61  +