/ Check-in [cca376bf]
Login

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

Overview
Comment:Have the sqlite3_index_writer() VMs check that the final values of records inserted into indexes on rowid tables are integers.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ota-update
Files: files | file ages | folders
SHA1: cca376bff3510dc5e99fc5824862c3471ceced16
User & Date: dan 2014-09-15 12:18:29
Context
2014-09-15
14:54
Ensure the correct collation sequences are used when sorting data in sqlite3ota.c. check-in: 473a72d7 user: dan tags: ota-update
12:18
Have the sqlite3_index_writer() VMs check that the final values of records inserted into indexes on rowid tables are integers. check-in: cca376bf user: dan tags: ota-update
10:44
Add OP_Affinity opcodes to the VMs generated by sqlite3_index_writer(). check-in: b9b38cb8 user: dan tags: ota-update
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/ota/ota3.test.

45
46
47
48
49
50
51



52


53




















54
  run_ota test.db ota.db
} {SQLITE_DONE}

do_execsql_test 1.2 {
  PRAGMA integrity_check;
} {ok}




























finish_test







>
>
>
|
>
>

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

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
79
  run_ota test.db ota.db
} {SQLITE_DONE}

do_execsql_test 1.2 {
  PRAGMA integrity_check;
} {ok}

#--------------------------------------------------------------------
# Test that NULL values may not be inserted into INTEGER PRIMARY KEY
# columns.
#
forcedelete ota.db
reset_db

do_execsql_test 2.0 {
  CREATE TABLE x1(a INTEGER PRIMARY KEY, b TEXT, c REAL);
  CREATE INDEX i1 ON x1(b, c);
} {}

do_test 2.1 {
  sqlite3 db2 ota.db
  db2 eval {
    CREATE TABLE data_x1(a, b, c, ota_control);
    INSERT INTO data_x1 VALUES(NULL, 'a', 'b', 0);
  }
  db2 close
  list [catch { run_ota test.db ota.db } msg] $msg
} {1 {SQLITE_MISMATCH - datatype mismatch}}

do_execsql_test 2.2 {
  PRAGMA integrity_check;
} {ok}


finish_test

Changes to ext/ota/sqlite3ota.h.

94
95
96
97
98
99
100
101





102
103
104
105
106
107
108
**
** The order of the columns in the data_% table does not matter.
**
** For each row to INSERT into the target database as part of the OTA 
** update, the corresponding data_% table should contain a single record
** with the "ota_control" column set to contain integer value 0. The
** other columns should be set to the values that make up the new record 
** to insert.





**
** For each row to DELETE from the target database as part of the OTA 
** update, the corresponding data_% table should contain a single record
** with the "ota_control" column set to contain integer value 1. The
** real primary key values of the row to delete should be stored in the
** corresponding columns of the data_% table. The values stored in the
** other columns are not used.







|
>
>
>
>
>







94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
**
** The order of the columns in the data_% table does not matter.
**
** For each row to INSERT into the target database as part of the OTA 
** update, the corresponding data_% table should contain a single record
** with the "ota_control" column set to contain integer value 0. The
** other columns should be set to the values that make up the new record 
** to insert. 
**
** If the target database table has an INTEGER PRIMARY KEY and there are
** one or more auxiliary indexes, it is not possible to insert a NULL value
** into the IPK column. Attempting to do so results in an SQLITE_MISMATCH
** error.
**
** For each row to DELETE from the target database as part of the OTA 
** update, the corresponding data_% table should contain a single record
** with the "ota_control" column set to contain integer value 1. The
** real primary key values of the row to delete should be stored in the
** corresponding columns of the data_% table. The values stored in the
** other columns are not used.

Changes to src/vdbeblob.c.

544
545
546
547
548
549
550





551
552
553
554
555
556
557
  /* Create the record to insert into the index. Store it in register regRec. */
  pParse->nVar = pIdx->nColumn;
  pParse->nMem = pIdx->nColumn;
  for(i=1; i<=pIdx->nColumn; i++){
    sqlite3VdbeAddOp2(v, OP_Variable, i, i);
  }
  regRec = ++pParse->nMem;






  if( bDelete==0 ){
    sqlite3VdbeAddOp4(v, OP_MakeRecord, 1, pIdx->nColumn, regRec, zAffinity, 0);

    /* If this is a UNIQUE index, check the constraint. */
    if( pIdx->onError ){
      int addr = sqlite3VdbeAddOp4Int(v, OP_NoConflict, 0, 0, 1, pIdx->nKeyCol);







>
>
>
>
>







544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
  /* Create the record to insert into the index. Store it in register regRec. */
  pParse->nVar = pIdx->nColumn;
  pParse->nMem = pIdx->nColumn;
  for(i=1; i<=pIdx->nColumn; i++){
    sqlite3VdbeAddOp2(v, OP_Variable, i, i);
  }
  regRec = ++pParse->nMem;

  /* If this is a rowid table, check that the rowid field is an integer. */
  if( HasRowid(pTab) ){
    sqlite3VdbeAddOp2(v, OP_MustBeInt, pIdx->nColumn, 0);
  }

  if( bDelete==0 ){
    sqlite3VdbeAddOp4(v, OP_MakeRecord, 1, pIdx->nColumn, regRec, zAffinity, 0);

    /* If this is a UNIQUE index, check the constraint. */
    if( pIdx->onError ){
      int addr = sqlite3VdbeAddOp4Int(v, OP_NoConflict, 0, 0, 1, pIdx->nKeyCol);