/ Check-in [82a2ae71]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Use SQLITE_PREPARE_NO_VTAB in rtree as well.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | prepare-no-vtab
Files: files | file ages | folders
SHA3-256: 82a2ae7132964eab0dfad9a8314a399ffd3b72366b35e1767df6452125dd1d80
User & Date: dan 2018-12-21 19:55:20
Context
2018-12-21
20:18
Add new sqlite3_prepare_v3() flag SQLITE_PREPARE_NO_VTAB, for preparing statements that are not allowed to use any virtual tables. Use this to prevent circular references in triggers on virtual table shadow tables from causing resource leaks. check-in: da587d18 user: dan tags: trunk
19:55
Use SQLITE_PREPARE_NO_VTAB in rtree as well. Closed-Leaf check-in: 82a2ae71 user: dan tags: prepare-no-vtab
19:30
Add tests for the use of SQLITE_PREPARE_NO_VTAB in fts5. check-in: 19996120 user: dan tags: prepare-no-vtab
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/rtree/rtree.c.

  3419   3419       /* Read and write the xxx_parent table */
  3420   3420       "SELECT parentnode FROM '%q'.'%q_parent' WHERE nodeno = ?1",
  3421   3421       "INSERT OR REPLACE INTO '%q'.'%q_parent' VALUES(?1, ?2)",
  3422   3422       "DELETE FROM '%q'.'%q_parent' WHERE nodeno = ?1"
  3423   3423     };
  3424   3424     sqlite3_stmt **appStmt[N_STATEMENT];
  3425   3425     int i;
         3426  +  const int f = SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_NO_VTAB;
  3426   3427   
  3427   3428     pRtree->db = db;
  3428   3429   
  3429   3430     if( isCreate ){
  3430   3431       char *zCreate;
  3431   3432       sqlite3_str *p = sqlite3_str_new(db);
  3432   3433       int ii;
................................................................................
  3475   3476          /* An UPSERT is very slightly slower than REPLACE, but it is needed
  3476   3477          ** if there are auxiliary columns */
  3477   3478          zFormat = "INSERT INTO\"%w\".\"%w_rowid\"(rowid,nodeno)VALUES(?1,?2)"
  3478   3479                     "ON CONFLICT(rowid)DO UPDATE SET nodeno=excluded.nodeno";
  3479   3480       }
  3480   3481       zSql = sqlite3_mprintf(zFormat, zDb, zPrefix);
  3481   3482       if( zSql ){
  3482         -      rc = sqlite3_prepare_v3(db, zSql, -1, SQLITE_PREPARE_PERSISTENT,
  3483         -                              appStmt[i], 0); 
         3483  +      rc = sqlite3_prepare_v3(db, zSql, -1, f, appStmt[i], 0); 
  3484   3484       }else{
  3485   3485         rc = SQLITE_NOMEM;
  3486   3486       }
  3487   3487       sqlite3_free(zSql);
  3488   3488     }
  3489   3489     if( pRtree->nAux ){
  3490   3490       pRtree->zReadAuxSql = sqlite3_mprintf(
................................................................................
  3506   3506           }
  3507   3507         }
  3508   3508         sqlite3_str_appendf(p, " WHERE rowid=?1");
  3509   3509         zSql = sqlite3_str_finish(p);
  3510   3510         if( zSql==0 ){
  3511   3511           rc = SQLITE_NOMEM;
  3512   3512         }else{
  3513         -        rc = sqlite3_prepare_v3(db, zSql, -1, SQLITE_PREPARE_PERSISTENT,
  3514         -                                &pRtree->pWriteAux, 0); 
         3513  +        rc = sqlite3_prepare_v3(db, zSql, -1, f, &pRtree->pWriteAux, 0); 
  3515   3514           sqlite3_free(zSql);
  3516   3515         }
  3517   3516       }
  3518   3517     }
  3519   3518   
  3520   3519     return rc;
  3521   3520   }

Added ext/rtree/rtreecirc.test.

            1  +# 2018 Dec 22
            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 script is testing the FTS5 module.
           13  +#
           14  +
           15  +if {![info exists testdir]} {
           16  +  set testdir [file join [file dirname [info script]] .. .. test]
           17  +}
           18  +source [file join [file dirname [info script]] rtree_util.tcl]
           19  +source $testdir/tester.tcl
           20  +set testprefix rtreecirc
           21  +
           22  +ifcapable !rtree {
           23  +  finish_test
           24  +  return
           25  +}
           26  +
           27  +do_execsql_test 1.0 {
           28  +  CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2, y1, y2);
           29  +  SELECT name FROM sqlite_master ORDER BY 1;
           30  +} {
           31  +  rt rt_node rt_parent rt_rowid
           32  +}
           33  +db_save_and_close
           34  +
           35  +foreach {tn schema sql} {
           36  +  1 {
           37  +    CREATE TRIGGER tr1 AFTER INSERT ON rt_node BEGIN
           38  +      SELECT * FROM rt;
           39  +    END;
           40  +  } {
           41  +    INSERT INTO rt VALUES(1, 2, 3, 4, 5);
           42  +  }
           43  +  2 {
           44  +    CREATE TRIGGER tr1 AFTER INSERT ON rt_parent BEGIN
           45  +      SELECT * FROM rt;
           46  +    END;
           47  +  } {
           48  +    INSERT INTO rt VALUES(1, 2, 3, 4, 5);
           49  +  }
           50  +  3 {
           51  +    CREATE TRIGGER tr1 AFTER INSERT ON rt_rowid BEGIN
           52  +      SELECT * FROM rt;
           53  +    END;
           54  +  } {
           55  +    INSERT INTO rt VALUES(1, 2, 3, 4, 5);
           56  +  }
           57  +} {
           58  +  db_restore_and_reopen
           59  +  do_execsql_test  1.1.$tn.1 $schema
           60  +  do_catchsql_test 1.1.$tn.2 $sql {1 {no such table: main.rt}}
           61  +  db close
           62  +}
           63  +
           64  +
           65  +finish_test
           66  +