/ Check-in [3dfd1d63]
Login

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

Overview
Comment:Improve coverage of session module.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sessions
Files: files | file ages | folders
SHA1:3dfd1d63bddfa9bd9018eb00bee1d496379630b5
User & Date: dan 2011-04-15 19:18:57
Context
2011-04-16
19:23
Improve test coverage of session module. check-in: f46d4b64 user: dan tags: sessions
2011-04-15
19:18
Improve coverage of session module. check-in: 3dfd1d63 user: dan tags: sessions
16:03
Add tests and fixes for OOM handling in sqlite3changeset_concat(). check-in: df0b2d21 user: dan tags: sessions
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/session/session5.test.

179
180
181
182
183
184
185







186
187
188
189
190
191
192
...
199
200
201
202
203
204
205












































206
207
208
209
210
211
212
  INSERT INTO abc VALUES('one', 'two', 'three');
} {
  SELECT indirect(1);
  UPDATE abc SET a='one point five' WHERE c = 'three';
} {
  SELECT indirect(0);
  UPDATE abc SET a='one point six' WHERE c = 'three';







}

catch {db close}
forcedelete test.db
sqlite3 db test.db
do_concat_test 2.2 {
  CREATE TABLE t1(a, b, PRIMARY KEY(b));
................................................................................
  INSERT INTO t2 VALUES(1, NULL);
  UPDATE t1 SET a = 5 WHERE a = 2;
} {
  DELETE FROM t2 WHERE a = 1;
  UPDATE t1 SET a = 4 WHERE a = 2;
  INSERT INTO t2 VALUES('x', 'y');
}













































#-------------------------------------------------------------------------
# Test that schema incompatibilities are detected correctly.
#
#   session5-3.1: Incompatible number of columns.
#   session5-3.2: Incompatible PK definition.
#







>
>
>
>
>
>
>







 







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







179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
  INSERT INTO abc VALUES('one', 'two', 'three');
} {
  SELECT indirect(1);
  UPDATE abc SET a='one point five' WHERE c = 'three';
} {
  SELECT indirect(0);
  UPDATE abc SET a='one point six' WHERE c = 'three';
} {
  CREATE TABLE x1(a, b, PRIMARY KEY(a));
  SELECT indirect(1);
  INSERT INTO x1 VALUES(1, 2);
} {
  SELECT indirect(1);
  UPDATE x1 SET b = 3 WHERE a = 1;
}

catch {db close}
forcedelete test.db
sqlite3 db test.db
do_concat_test 2.2 {
  CREATE TABLE t1(a, b, PRIMARY KEY(b));
................................................................................
  INSERT INTO t2 VALUES(1, NULL);
  UPDATE t1 SET a = 5 WHERE a = 2;
} {
  DELETE FROM t2 WHERE a = 1;
  UPDATE t1 SET a = 4 WHERE a = 2;
  INSERT INTO t2 VALUES('x', 'y');
}

do_test 2.3.0 {
  catch {db close}
  forcedelete test.db
  sqlite3 db test.db
 
  set sql1 ""
  set sql2 ""
  for {set i 1} {$i < 120} {incr i} {
    append sql1 "INSERT INTO x1 VALUES($i*4, $i);"
  }
  for {set i 1} {$i < 120} {incr i} {
    append sql2 "DELETE FROM x1 WHERE a = $i*4;"
  }

  set {} {}
} {}
do_concat_test 2.3 {
  CREATE TABLE x1(a PRIMARY KEY, b)
} $sql1 $sql2 $sql1 $sql2

do_concat_test 2.4 {
  CREATE TABLE x2(a PRIMARY KEY, b);
  CREATE TABLE x3(a PRIMARY KEY, b);

  INSERT INTO x2 VALUES('a', 'b');
  INSERT INTO x2 VALUES('x', 'y');
  INSERT INTO x3 VALUES('a', 'b');
} {
  INSERT INTO x2 VALUES('c', 'd');
  INSERT INTO x3 VALUES('e', 'f');
  INSERT INTO x3 VALUES('x', 'y');
}

do_concat_test 2.5 {
  UPDATE x3 SET b = 'Y' WHERE a = 'x'
} {
  DELETE FROM x3 WHERE a = 'x'
} {
  DELETE FROM x2 WHERE a = 'a'
} {
  INSERT INTO x2 VALUES('a', 'B');
}


#-------------------------------------------------------------------------
# Test that schema incompatibilities are detected correctly.
#
#   session5-3.1: Incompatible number of columns.
#   session5-3.2: Incompatible PK definition.
#

Changes to ext/session/sqlite3session.c.

2789
2790
2791
2792
2793
2794
2795
2796
2797

2798
2799
2800






2801

2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
....
2855
2856
2857
2858
2859
2860
2861




2862
2863
2864
2865
2866
2867
2868
        sqlite3_free(pExist);
        return SQLITE_NOMEM;
      }
      memset(pNew, 0, sizeof(SessionChange));
      pNew->bIndirect = (bIndirect && pExist->bIndirect);
      aCsr = pNew->aRecord = (u8 *)&pNew[1];

      if( op1==SQLITE_INSERT && op2==SQLITE_UPDATE ){
        u8 *a1 = aRec;

        pNew->bInsert = SQLITE_INSERT;
        sessionReadRecord(&a1, pTab->nCol, 0);
        sessionMergeRecord(&aCsr, pTab, pExist->aRecord, a1);






      }

      else if( op1==SQLITE_UPDATE && op2==SQLITE_UPDATE ){
        u8 *a1 = pExist->aRecord;
        u8 *a2 = aRec;
        sessionReadRecord(&a1, pTab->nCol, 0);
        sessionReadRecord(&a2, pTab->nCol, 0);
        pNew->bInsert = SQLITE_UPDATE;
        if( 0==sessionMergeUpdate(&aCsr, pTab, aRec, pExist->aRecord, a1, a2) ){
          sqlite3_free(pNew);
          pNew = 0;
        }
      }
      else if( op1==SQLITE_UPDATE && op2==SQLITE_DELETE ){
        pNew->bInsert = SQLITE_DELETE;
        sessionMergeRecord(&aCsr, pTab, aRec, pExist->aRecord);
      }
      else if( op1==SQLITE_DELETE && op2==SQLITE_INSERT ){
        pNew->bInsert = SQLITE_UPDATE;
        if( 0==sessionMergeUpdate(&aCsr, pTab, pExist->aRecord, 0, aRec, 0) ){
          sqlite3_free(pNew);
          pNew = 0;
        }
      }

      if( pNew ){
        pNew->nRecord = (aCsr - pNew->aRecord);
      }
      sqlite3_free(pExist);
    }
  }
................................................................................
    int bIndirect;
    SessionChange *pChange;
    SessionChange *pExist = 0;
    SessionChange **pp;

    assert( pIter->apValue==0 );
    sqlite3changeset_op(pIter, &zNew, &nCol, &op, &bIndirect);





    if( !pTab || zNew!=pTab->zName ){
      /* Search the list for a matching table */
      int nNew = strlen(zNew);
      u8 *abPK;

      sqlite3changeset_pk(pIter, &abPK, 0);







|

>



>
>
>
>
>
>
|
>
|









|
|



<
<
<
<
<
<
<







 







>
>
>
>







2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824







2825
2826
2827
2828
2829
2830
2831
....
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
        sqlite3_free(pExist);
        return SQLITE_NOMEM;
      }
      memset(pNew, 0, sizeof(SessionChange));
      pNew->bIndirect = (bIndirect && pExist->bIndirect);
      aCsr = pNew->aRecord = (u8 *)&pNew[1];

      if( op1==SQLITE_INSERT ){             /* INSERT + UPDATE */
        u8 *a1 = aRec;
        assert( op2==SQLITE_UPDATE );
        pNew->bInsert = SQLITE_INSERT;
        sessionReadRecord(&a1, pTab->nCol, 0);
        sessionMergeRecord(&aCsr, pTab, pExist->aRecord, a1);
      }else if( op1==SQLITE_DELETE ){       /* DELETE + INSERT */
        assert( op2==SQLITE_INSERT );
        pNew->bInsert = SQLITE_UPDATE;
        if( 0==sessionMergeUpdate(&aCsr, pTab, pExist->aRecord, 0, aRec, 0) ){
          sqlite3_free(pNew);
          pNew = 0;
        }
      }else if( op2==SQLITE_UPDATE ){       /* UPDATE + UPDATE */
        assert( op1==SQLITE_UPDATE );
        u8 *a1 = pExist->aRecord;
        u8 *a2 = aRec;
        sessionReadRecord(&a1, pTab->nCol, 0);
        sessionReadRecord(&a2, pTab->nCol, 0);
        pNew->bInsert = SQLITE_UPDATE;
        if( 0==sessionMergeUpdate(&aCsr, pTab, aRec, pExist->aRecord, a1, a2) ){
          sqlite3_free(pNew);
          pNew = 0;
        }
      }else{                                /* UPDATE + DELETE */
        assert( op1==SQLITE_UPDATE && op2==SQLITE_DELETE );
        pNew->bInsert = SQLITE_DELETE;
        sessionMergeRecord(&aCsr, pTab, aRec, pExist->aRecord);
      }








      if( pNew ){
        pNew->nRecord = (aCsr - pNew->aRecord);
      }
      sqlite3_free(pExist);
    }
  }
................................................................................
    int bIndirect;
    SessionChange *pChange;
    SessionChange *pExist = 0;
    SessionChange **pp;

    assert( pIter->apValue==0 );
    sqlite3changeset_op(pIter, &zNew, &nCol, &op, &bIndirect);

    assert( zNew>=(char *)pChangeset && zNew-nChangeset<((char *)pChangeset) );
    assert( !pTab || pTab->zName-nChangeset<(char *)pChangeset );
    assert( !pTab || zNew>=pTab->zName );

    if( !pTab || zNew!=pTab->zName ){
      /* Search the list for a matching table */
      int nNew = strlen(zNew);
      u8 *abPK;

      sqlite3changeset_pk(pIter, &abPK, 0);