SQLite

Check-in [d43e0efb]
Login

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

Overview
Comment:Be strict about type enforcement on rowid look-ups in the RTREE extension. Ticket [30e2c183b6b356e4]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d43e0efb9642037dd751cfed13438e71cfceb50e14a0ec603880c6c3be2e93b1
User & Date: drh 2019-12-05 13:34:13
Context
2019-12-05
14:31
Fix a problem in ALTER TABLE that could occur if an index, view or trigger in the schema features an expression of the form ((SELECT ...) IN ()) where the SELECT statement uses a CTE. (check-in: 7e5ad8e0 user: dan tags: trunk)
13:34
Be strict about type enforcement on rowid look-ups in the RTREE extension. Ticket [30e2c183b6b356e4] (check-in: d43e0efb user: drh tags: trunk)
00:44
Enhance the RTREE extension so that it give correct query results even if the query uses non-numeric constraints. Ticket [a55ab6d97d01ecbc] (check-in: f898d04c user: drh tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/rtree/rtree.c.

1813
1814
1815
1816
1817
1818
1819




1820




1821
1822
1823
1824
1825
1826
1827
  pCsr->iStrategy = idxNum;
  if( idxNum==1 ){
    /* Special case - lookup by rowid. */
    RtreeNode *pLeaf;        /* Leaf on which the required cell resides */
    RtreeSearchPoint *p;     /* Search point for the leaf */
    i64 iRowid = sqlite3_value_int64(argv[0]);
    i64 iNode = 0;




    rc = findLeafNode(pRtree, iRowid, &pLeaf, &iNode);




    if( rc==SQLITE_OK && pLeaf!=0 ){
      p = rtreeSearchPointNew(pCsr, RTREE_ZERO, 0);
      assert( p!=0 );  /* Always returns pCsr->sPoint */
      pCsr->aNode[0] = pLeaf;
      p->id = iNode;
      p->eWithin = PARTLY_WITHIN;
      rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &iCell);







>
>
>
>
|
>
>
>
>







1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
  pCsr->iStrategy = idxNum;
  if( idxNum==1 ){
    /* Special case - lookup by rowid. */
    RtreeNode *pLeaf;        /* Leaf on which the required cell resides */
    RtreeSearchPoint *p;     /* Search point for the leaf */
    i64 iRowid = sqlite3_value_int64(argv[0]);
    i64 iNode = 0;
    int eType = sqlite3_value_numeric_type(argv[0]);
    if( eType==SQLITE_INTEGER
     || (eType==SQLITE_FLOAT && sqlite3_value_double(argv[0])==iRowid)
    ){
      rc = findLeafNode(pRtree, iRowid, &pLeaf, &iNode);
    }else{
      rc = SQLITE_OK;
      pLeaf = 0;
    }
    if( rc==SQLITE_OK && pLeaf!=0 ){
      p = rtreeSearchPointNew(pCsr, RTREE_ZERO, 0);
      assert( p!=0 );  /* Always returns pCsr->sPoint */
      pCsr->aNode[0] = pLeaf;
      p->id = iNode;
      p->eWithin = PARTLY_WITHIN;
      rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &iCell);

Changes to ext/rtree/rtree1.test.

597
598
599
600
601
602
603













604

605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
}
do_execsql_test 14.5 {
  SELECT * FROM t10;
} {
  1 0.0 0.0
  2 52.0 81.0
}















do_execsql_test 14.4 {
  DROP TABLE t10;
  CREATE VIRTUAL TABLE t10 USING rtree_i32(ii, x1, x2);
  INSERT INTO t10 VALUES(1, 'one', 'two');
  INSERT INTO t10 VALUES(2, '52xyz', '81...');
  INSERT INTO t10 VALUES(3, 42.3, 49.9);
}
do_execsql_test 14.5 {
  SELECT * FROM t10;
} {
  1 0 0
  2 52 81
  3 42 49
}








>
>
>
>
>
>
>
>
>
>
>
>
>

>
|






|







597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
}
do_execsql_test 14.5 {
  SELECT * FROM t10;
} {
  1 0.0 0.0
  2 52.0 81.0
}
do_execsql_test 14.6 {
  INSERT INTO t10 VALUES(0,10,20);
  SELECT * FROM t10 WHERE ii=NULL;
} {}
do_execsql_test 14.7 {
  SELECT * FROM t10 WHERE ii='xyz';
} {}
do_execsql_test 14.8 {
  SELECT * FROM t10 WHERE ii='0.0';
} {0 10.0 20.0}
do_execsql_test 14.9 {
  SELECT * FROM t10 WHERE ii=0.0;
} {0 10.0 20.0}


do_execsql_test 14.104 {
  DROP TABLE t10;
  CREATE VIRTUAL TABLE t10 USING rtree_i32(ii, x1, x2);
  INSERT INTO t10 VALUES(1, 'one', 'two');
  INSERT INTO t10 VALUES(2, '52xyz', '81...');
  INSERT INTO t10 VALUES(3, 42.3, 49.9);
}
do_execsql_test 14.105 {
  SELECT * FROM t10;
} {
  1 0 0
  2 52 81
  3 42 49
}

Changes to ext/rtree/rtreeH.test.

39
40
41
42
43
44
45












46
47
48











49
50
51
52
53
54
55
do_execsql_test rtreeH-101 {
  SELECT * FROM t1_rowid ORDER BY rowid
} {1 1 {lower-left corner} {} 2 1 {upper-left corner} {} 3 1 {lower-right corner} {} 4 1 {upper-right corner} {} 5 1 center {} 6 1 {left edge} {} 7 1 {right edge} {} 8 1 {bottom edge} {} 9 1 {top edge} {} 10 1 {the whole thing} {} 11 1 {left half} {} 12 1 {right half} {} 13 1 {bottom half} {} 14 1 {top half} {}}

do_execsql_test rtreeH-102 {
  SELECT * FROM t1 WHERE rowid=5;
} {5 40.0 60.0 40.0 60.0 center {}}












do_execsql_test rtreeH-103 {
  SELECT * FROM t1 WHERE label='center';
} {5 40.0 60.0 40.0 60.0 center {}}












do_rtree_integrity_test rtreeH-110 t1

do_execsql_test rtreeH-120 {
  SELECT label FROM t1 WHERE x1<=50 ORDER BY id
} {{lower-left corner} {upper-left corner} {left edge} {left half}}
do_execsql_test rtreeH-121 {







>
>
>
>
>
>
>
>
>
>
>
>



>
>
>
>
>
>
>
>
>
>
>







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
do_execsql_test rtreeH-101 {
  SELECT * FROM t1_rowid ORDER BY rowid
} {1 1 {lower-left corner} {} 2 1 {upper-left corner} {} 3 1 {lower-right corner} {} 4 1 {upper-right corner} {} 5 1 center {} 6 1 {left edge} {} 7 1 {right edge} {} 8 1 {bottom edge} {} 9 1 {top edge} {} 10 1 {the whole thing} {} 11 1 {left half} {} 12 1 {right half} {} 13 1 {bottom half} {} 14 1 {top half} {}}

do_execsql_test rtreeH-102 {
  SELECT * FROM t1 WHERE rowid=5;
} {5 40.0 60.0 40.0 60.0 center {}}
do_execsql_test rtreeH-102b {
  SELECT * FROM t1 WHERE rowid=5.0;
} {5 40.0 60.0 40.0 60.0 center {}}
do_execsql_test rtreeH-102c {
  SELECT * FROM t1 WHERE rowid='5';
} {5 40.0 60.0 40.0 60.0 center {}}
do_execsql_test rtreeH-102d {
  SELECT * FROM t1 WHERE rowid='0005';
} {5 40.0 60.0 40.0 60.0 center {}}
do_execsql_test rtreeH-102e {
  SELECT * FROM t1 WHERE rowid='+5.0e+0';
} {5 40.0 60.0 40.0 60.0 center {}}
do_execsql_test rtreeH-103 {
  SELECT * FROM t1 WHERE label='center';
} {5 40.0 60.0 40.0 60.0 center {}}

do_execsql_test rtreeH-104 {
  SELECT * FROM t1 WHERE rowid='+5.0e+0x';
} {}
do_execsql_test rtreeH-105 {
  SELECT * FROM t1 WHERE rowid=x'35';
} {}
do_execsql_test rtreeH-106 {
  SELECT * FROM t1 WHERE rowid=null;
} {}


do_rtree_integrity_test rtreeH-110 t1

do_execsql_test rtreeH-120 {
  SELECT label FROM t1 WHERE x1<=50 ORDER BY id
} {{lower-left corner} {upper-left corner} {left edge} {left half}}
do_execsql_test rtreeH-121 {