/ Check-in [05f6c1ae]
Login

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

Overview
Comment:Further test coverage improvements for rtree.c.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 05f6c1aebbe757dd3b54fd027057b9db7ae3a990
User & Date: dan 2010-08-25 19:04:38
Context
2010-08-25
19:39
Disable the legacy "sqlite" command in the TCL interface. Provide only the "sqlite3" command. check-in: 909b3d88 user: drh tags: trunk
19:04
Further test coverage improvements for rtree.c. check-in: 05f6c1ae user: dan tags: trunk
17:53
Test cases to improve coverage of rtree module. Fixes associated with the same. check-in: 865cec04 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/rtree/rtree.c.

  1994   1994     memset(pRight->zData, 0, pRtree->iNodeSize);
  1995   1995   
  1996   1996     rc = AssignCells(pRtree, aCell, nCell, pLeft, pRight, &leftbbox, &rightbbox);
  1997   1997     if( rc!=SQLITE_OK ){
  1998   1998       goto splitnode_out;
  1999   1999     }
  2000   2000   
  2001         -  /* Ensure both child nodes have node numbers assigned to them. */
  2002         -  if( (0==pRight->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pRight)))
         2001  +  /* Ensure both child nodes have node numbers assigned to them by calling
         2002  +  ** nodeWrite(). Node pRight always needs a node number, as it was created
         2003  +  ** by nodeNew() above. But node pLeft sometimes already has a node number.
         2004  +  ** In this case avoid the all to nodeWrite().
         2005  +  */
         2006  +  if( SQLITE_OK!=(rc = nodeWrite(pRtree, pRight))
  2003   2007      || (0==pLeft->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pLeft)))
  2004   2008     ){
  2005   2009       goto splitnode_out;
  2006   2010     }
  2007   2011   
  2008   2012     rightbbox.iRowid = pRight->iNode;
  2009   2013     leftbbox.iRowid = pLeft->iNode;
................................................................................
  2060   2064     sqlite3_free(aCell);
  2061   2065     return rc;
  2062   2066   }
  2063   2067   
  2064   2068   static int fixLeafParent(Rtree *pRtree, RtreeNode *pLeaf){
  2065   2069     int rc = SQLITE_OK;
  2066   2070     if( pLeaf->iNode!=1 && pLeaf->pParent==0 ){
         2071  +    int rc2;                      /* sqlite3_reset() return code */
  2067   2072       sqlite3_bind_int64(pRtree->pReadParent, 1, pLeaf->iNode);
  2068         -    if( sqlite3_step(pRtree->pReadParent)==SQLITE_ROW ){
         2073  +    rc = sqlite3_step(pRtree->pReadParent);
         2074  +    if( rc==SQLITE_ROW ){
  2069   2075         i64 iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
  2070   2076         rc = nodeAcquire(pRtree, iNode, 0, &pLeaf->pParent);
  2071         -    }else{
  2072         -      rc = SQLITE_ERROR;
         2077  +    }else if( rc==SQLITE_DONE ){
         2078  +      rc = SQLITE_CORRUPT;
  2073   2079       }
  2074         -    sqlite3_reset(pRtree->pReadParent);
         2080  +    rc2 = sqlite3_reset(pRtree->pReadParent);
         2081  +    if( rc==SQLITE_OK ){
         2082  +      rc = rc2;
         2083  +    }
  2075   2084       if( rc==SQLITE_OK ){
  2076   2085         rc = fixLeafParent(pRtree, pLeaf->pParent);
  2077   2086       }
  2078   2087     }
  2079   2088     return rc;
  2080   2089   }
  2081   2090   
................................................................................
  2877   2886   
  2878   2887   /*
  2879   2888   ** Register the r-tree module with database handle db. This creates the
  2880   2889   ** virtual table module "rtree" and the debugging/analysis scalar 
  2881   2890   ** function "rtreenode".
  2882   2891   */
  2883   2892   int sqlite3RtreeInit(sqlite3 *db){
  2884         -  int rc = SQLITE_OK;
         2893  +  const int utf8 = SQLITE_UTF8;
         2894  +  int rc;
  2885   2895   
  2886         -  if( rc==SQLITE_OK ){
  2887         -    int utf8 = SQLITE_UTF8;
  2888         -    rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
  2889         -  }
         2896  +  rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
  2890   2897     if( rc==SQLITE_OK ){
  2891   2898       int utf8 = SQLITE_UTF8;
  2892   2899       rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
  2893   2900     }
  2894   2901     if( rc==SQLITE_OK ){
  2895   2902       void *c = (void *)RTREE_COORD_REAL32;
  2896   2903       rc = sqlite3_create_module_v2(db, "rtree", &rtreeModule, c, 0);

Changes to ext/rtree/rtree3.test.

    29     29   source $testdir/malloc_common.tcl
    30     30   if {!$MEMDEBUG} {
    31     31      puts "Skipping malloc tests: not compiled with -DSQLITE_MEMDEBUG..."
    32     32      finish_test
    33     33      return
    34     34   }
    35     35   
    36         -if 1 {
    37         -
    38     36   do_faultsim_test rtree3-1 -faults oom* -prep {
    39     37     faultsim_delete_and_reopen
    40     38   } -body {
    41     39     execsql {
    42     40       BEGIN TRANSACTION;
    43     41       CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
    44     42       INSERT INTO rt VALUES(NULL, 3, 5, 7, 9);
................................................................................
    92     90     for {set ii 0} {$ii < 100} {incr ii} {
    93     91       set f [expr rand()]
    94     92       db eval { DELETE FROM rt WHERE x1<($f*10.0) AND x1>($f*10.5) }
    95     93     }
    96     94     db eval COMMIT
    97     95   } 
    98     96   
    99         -}
   100         -
   101     97   do_test rtree3-4.prep {
   102     98     faultsim_delete_and_reopen
   103     99     execsql {
   104    100       BEGIN;
   105    101       PRAGMA page_size = 512;
   106    102       CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
   107    103     }
................................................................................
   108    104     for {set i 0} {$i < 1500} {incr i} {
   109    105       execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
   110    106     }
   111    107     execsql { COMMIT }
   112    108     faultsim_save_and_close
   113    109   } {}
   114    110   
   115         -do_faultsim_test rtree3-4 -faults oom-transient -prep {
          111  +do_faultsim_test rtree3-4a -faults oom-transient -prep {
   116    112     faultsim_restore_and_reopen
   117    113   } -body {
   118    114     db eval { SELECT count(*) FROM rt }
   119    115   } -test {
   120    116     faultsim_test_result {0 1500}
          117  +}
          118  +do_faultsim_test rtree3-4b -faults oom-transient -prep {
          119  +  faultsim_restore_and_reopen
          120  +} -body {
          121  +  db eval { DELETE FROM rt WHERE ii BETWEEN 880 AND 920 }
          122  +} -test {
          123  +  faultsim_test_result {0 {}}
   121    124   }
   122    125   
   123    126   finish_test

Changes to ext/rtree/rtree8.test.

   100    100     SELECT * FROM t1
   101    101   } {1 {database disk image is malformed}}
   102    102   do_catchsql_test rtree8-2.1.5 { 
   103    103     DELETE FROM t1
   104    104   } {1 {database disk image is malformed}}
   105    105   
   106    106   do_execsql_test rtree8-2.1.6 { 
   107         -  DELETE FROM t1_node;
   108         -  DELETE FROM t1_parent;
   109         -  DELETE FROM t1_rowid;
          107  +  DROP TABLE t1;
          108  +  CREATE VIRTUAL TABLE t1 USING rtree_i32(id, x1, x2);
          109  +} {}
          110  +
          111  +
          112  +populate_t1 50
          113  +do_execsql_test rtree8-2.2.1 {
          114  +  DELETE FROM t1_parent
          115  +} {}
          116  +do_catchsql_test rtree8-2.2.2 {
          117  +  DELETE FROM t1 WHERE id=25
          118  +} {1 {database disk image is malformed}}
          119  +do_execsql_test rtree8-2.2.3 { 
   110    120     DROP TABLE t1;
   111    121     CREATE VIRTUAL TABLE t1 USING rtree_i32(id, x1, x2);
   112    122   } {}
          123  +
   113    124   
   114    125   #-------------------------------------------------------------------------
   115    126   # Test that trying to use the MATCH operator with the r-tree module does
   116    127   # not confuse it.
   117    128   #
   118    129   breakpoint
   119    130   populate_t1 10
   120    131   do_catchsql_test rtree8-3.1 { 
   121    132     SELECT * FROM t1 WHERE x1 MATCH '1234'
   122         -} {1 {}}
          133  +} {1 {unable to use function MATCH in the requested context}}
   123    134   
   124    135   
   125    136   finish_test
   126    137