SQLite

Check-in [05f6c1aebb]
Login

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

Overview
Comment:Further test coverage improvements for rtree.c.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 05f6c1aebbe757dd3b54fd027057b9db7ae3a990
User & Date: dan 2010-08-25 19:04:38.000
Context
2010-08-25
19:39
Disable the legacy "sqlite" command in the TCL interface. Provide only the "sqlite3" command. (check-in: 909b3d8862 user: drh tags: trunk)
19:04
Further test coverage improvements for rtree.c. (check-in: 05f6c1aebb user: dan tags: trunk)
17:53
Test cases to improve coverage of rtree module. Fixes associated with the same. (check-in: 865cec04e4 user: dan tags: trunk)
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to ext/rtree/rtree.c.
1994
1995
1996
1997
1998
1999
2000
2001
2002






2003
2004
2005
2006
2007
2008
2009
1994
1995
1996
1997
1998
1999
2000


2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013







-
-
+
+
+
+
+
+







  memset(pRight->zData, 0, pRtree->iNodeSize);

  rc = AssignCells(pRtree, aCell, nCell, pLeft, pRight, &leftbbox, &rightbbox);
  if( rc!=SQLITE_OK ){
    goto splitnode_out;
  }

  /* Ensure both child nodes have node numbers assigned to them. */
  if( (0==pRight->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pRight)))
  /* Ensure both child nodes have node numbers assigned to them by calling
  ** nodeWrite(). Node pRight always needs a node number, as it was created
  ** by nodeNew() above. But node pLeft sometimes already has a node number.
  ** In this case avoid the all to nodeWrite().
  */
  if( SQLITE_OK!=(rc = nodeWrite(pRtree, pRight))
   || (0==pLeft->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pLeft)))
  ){
    goto splitnode_out;
  }

  rightbbox.iRowid = pRight->iNode;
  leftbbox.iRowid = pLeft->iNode;
2060
2061
2062
2063
2064
2065
2066

2067
2068


2069
2070
2071
2072


2073
2074




2075
2076
2077
2078
2079
2080
2081
2064
2065
2066
2067
2068
2069
2070
2071
2072

2073
2074
2075
2076


2077
2078
2079

2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090







+

-
+
+


-
-
+
+

-
+
+
+
+







  sqlite3_free(aCell);
  return rc;
}

static int fixLeafParent(Rtree *pRtree, RtreeNode *pLeaf){
  int rc = SQLITE_OK;
  if( pLeaf->iNode!=1 && pLeaf->pParent==0 ){
    int rc2;                      /* sqlite3_reset() return code */
    sqlite3_bind_int64(pRtree->pReadParent, 1, pLeaf->iNode);
    if( sqlite3_step(pRtree->pReadParent)==SQLITE_ROW ){
    rc = sqlite3_step(pRtree->pReadParent);
    if( rc==SQLITE_ROW ){
      i64 iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
      rc = nodeAcquire(pRtree, iNode, 0, &pLeaf->pParent);
    }else{
      rc = SQLITE_ERROR;
    }else if( rc==SQLITE_DONE ){
      rc = SQLITE_CORRUPT;
    }
    sqlite3_reset(pRtree->pReadParent);
    rc2 = sqlite3_reset(pRtree->pReadParent);
    if( rc==SQLITE_OK ){
      rc = rc2;
    }
    if( rc==SQLITE_OK ){
      rc = fixLeafParent(pRtree, pLeaf->pParent);
    }
  }
  return rc;
}

2877
2878
2879
2880
2881
2882
2883

2884

2885
2886
2887
2888

2889
2890
2891
2892
2893
2894
2895
2896
2886
2887
2888
2889
2890
2891
2892
2893

2894
2895



2896

2897
2898
2899
2900
2901
2902
2903







+
-
+

-
-
-
+
-








/*
** Register the r-tree module with database handle db. This creates the
** virtual table module "rtree" and the debugging/analysis scalar 
** function "rtreenode".
*/
int sqlite3RtreeInit(sqlite3 *db){
  const int utf8 = SQLITE_UTF8;
  int rc = SQLITE_OK;
  int rc;

  if( rc==SQLITE_OK ){
    int utf8 = SQLITE_UTF8;
    rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
  rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
  }
  if( rc==SQLITE_OK ){
    int utf8 = SQLITE_UTF8;
    rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
  }
  if( rc==SQLITE_OK ){
    void *c = (void *)RTREE_COORD_REAL32;
    rc = sqlite3_create_module_v2(db, "rtree", &rtreeModule, c, 0);
Changes to ext/rtree/rtree3.test.
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
29
30
31
32
33
34
35


36
37
38
39
40
41
42







-
-







source $testdir/malloc_common.tcl
if {!$MEMDEBUG} {
   puts "Skipping malloc tests: not compiled with -DSQLITE_MEMDEBUG..."
   finish_test
   return
}

if 1 {

do_faultsim_test rtree3-1 -faults oom* -prep {
  faultsim_delete_and_reopen
} -body {
  execsql {
    BEGIN TRANSACTION;
    CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
    INSERT INTO rt VALUES(NULL, 3, 5, 7, 9);
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

116
117
118
119
120







121
122
123
90
91
92
93
94
95
96


97
98
99
100
101
102
103
104
105
106
107
108
109
110

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126







-
-














-
+





+
+
+
+
+
+
+



  for {set ii 0} {$ii < 100} {incr ii} {
    set f [expr rand()]
    db eval { DELETE FROM rt WHERE x1<($f*10.0) AND x1>($f*10.5) }
  }
  db eval COMMIT
} 

}

do_test rtree3-4.prep {
  faultsim_delete_and_reopen
  execsql {
    BEGIN;
    PRAGMA page_size = 512;
    CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
  }
  for {set i 0} {$i < 1500} {incr i} {
    execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
  }
  execsql { COMMIT }
  faultsim_save_and_close
} {}

do_faultsim_test rtree3-4 -faults oom-transient -prep {
do_faultsim_test rtree3-4a -faults oom-transient -prep {
  faultsim_restore_and_reopen
} -body {
  db eval { SELECT count(*) FROM rt }
} -test {
  faultsim_test_result {0 1500}
}
do_faultsim_test rtree3-4b -faults oom-transient -prep {
  faultsim_restore_and_reopen
} -body {
  db eval { DELETE FROM rt WHERE ii BETWEEN 880 AND 920 }
} -test {
  faultsim_test_result {0 {}}
}

finish_test
Changes to ext/rtree/rtree8.test.
100
101
102
103
104
105
106



107
108
109










110
111
112

113
114
115
116
117
118
119
120
121
122

123
124
125
126
100
101
102
103
104
105
106
107
108
109



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

133
134
135
136
137







+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+



+









-
+




  SELECT * FROM t1
} {1 {database disk image is malformed}}
do_catchsql_test rtree8-2.1.5 { 
  DELETE FROM t1
} {1 {database disk image is malformed}}

do_execsql_test rtree8-2.1.6 { 
  DROP TABLE t1;
  CREATE VIRTUAL TABLE t1 USING rtree_i32(id, x1, x2);
} {}
  DELETE FROM t1_node;
  DELETE FROM t1_parent;
  DELETE FROM t1_rowid;


populate_t1 50
do_execsql_test rtree8-2.2.1 {
  DELETE FROM t1_parent
} {}
do_catchsql_test rtree8-2.2.2 {
  DELETE FROM t1 WHERE id=25
} {1 {database disk image is malformed}}
do_execsql_test rtree8-2.2.3 { 
  DROP TABLE t1;
  CREATE VIRTUAL TABLE t1 USING rtree_i32(id, x1, x2);
} {}


#-------------------------------------------------------------------------
# Test that trying to use the MATCH operator with the r-tree module does
# not confuse it.
#
breakpoint
populate_t1 10
do_catchsql_test rtree8-3.1 { 
  SELECT * FROM t1 WHERE x1 MATCH '1234'
} {1 {}}
} {1 {unable to use function MATCH in the requested context}}


finish_test