/ Check-in [a192d04f]
Login

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

Overview
Comment:Fix session module problems with real (floating point) values.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sessions
Files: files | file ages | folders
SHA1:a192d04f4e3a9e4960a4d96d1d3ee8635bc1034d
User & Date: dan 2011-03-21 11:03:25
Context
2011-03-21
11:55
Clarify handling of NULL values in PK columns in sqlite3session.h. Add tests and fixes for the same. check-in: aed42730 user: dan tags: sessions
11:03
Fix session module problems with real (floating point) values. check-in: a192d04f user: dan tags: sessions
07:23
Fix some typos in sqlite3session.h. check-in: 0853e530 user: dan tags: sessions
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/session/session2.test.

101
102
103
104
105
106
107





108
109
110
111
112
113
114
...
198
199
200
201
202
203
204


205

206
207
208
209
210
211
212
...
251
252
253
254
255
256
257






258
259
260
261
262
263
264
265
266
267
do_iterator_test 1.1 t1 {
  DELETE FROM t1 WHERE a = 'i';
  INSERT INTO t1 VALUES('ii', 'two');
} {
  {DELETE t1 {t i t one} {}} 
  {INSERT t1 {} {t ii t two}}
}






test_reset
do_common_sql {
  CREATE TABLE t1(a PRIMARY KEY, b);
  CREATE TABLE t2(a, b INTEGER PRIMARY KEY);
  CREATE TABLE t3(a, b, c, PRIMARY KEY(a, b));
}
................................................................................
  execsql {
    CREATE TABLE t1(a PRIMARY KEY, b);
    CREATE TABLE t2(a, b INTEGER PRIMARY KEY);
    CREATE TABLE t3(a, b, c, PRIMARY KEY(a, b));
  } db2
} {}



foreach {tn sql} {

  1 { INSERT INTO aux.t1 VALUES(1, 2) } 

  2 {
    INSERT INTO aux.t2 VALUES(1, NULL);
    INSERT INTO aux.t2 VALUES(2, NULL);
    INSERT INTO aux.t2 VALUES(3, NULL);
    DELETE FROM aux.t2 WHERE a = 2;
................................................................................
    ROLLBACK;
  }
  10 {
    BEGIN;
      DELETE FROM aux.t1 WHERE 1;
    ROLLBACK;
  }






} {
  do_then_apply_sql $sql aux
  do_test 2.$tn { compare_db db3 db2 } {}
}


catch {db3 close}

finish_test








>
>
>
>
>







 







>
>

>







 







>
>
>
>
>
>










101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
...
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
...
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
do_iterator_test 1.1 t1 {
  DELETE FROM t1 WHERE a = 'i';
  INSERT INTO t1 VALUES('ii', 'two');
} {
  {DELETE t1 {t i t one} {}} 
  {INSERT t1 {} {t ii t two}}
}
do_iterator_test 1.1 t1 {
  INSERT INTO t1 VALUES(1.5, 99.9)
} {
  {INSERT t1 {} {f 1.5 f 99.9}}
}

test_reset
do_common_sql {
  CREATE TABLE t1(a PRIMARY KEY, b);
  CREATE TABLE t2(a, b INTEGER PRIMARY KEY);
  CREATE TABLE t3(a, b, c, PRIMARY KEY(a, b));
}
................................................................................
  execsql {
    CREATE TABLE t1(a PRIMARY KEY, b);
    CREATE TABLE t2(a, b INTEGER PRIMARY KEY);
    CREATE TABLE t3(a, b, c, PRIMARY KEY(a, b));
  } db2
} {}

proc xTrace {args} { puts $args }

foreach {tn sql} {

  1 { INSERT INTO aux.t1 VALUES(1, 2) } 

  2 {
    INSERT INTO aux.t2 VALUES(1, NULL);
    INSERT INTO aux.t2 VALUES(2, NULL);
    INSERT INTO aux.t2 VALUES(3, NULL);
    DELETE FROM aux.t2 WHERE a = 2;
................................................................................
    ROLLBACK;
  }
  10 {
    BEGIN;
      DELETE FROM aux.t1 WHERE 1;
    ROLLBACK;
  }
  11 {
    INSERT INTO aux.t1 VALUES(randomblob(21000), randomblob(0));
    INSERT INTO aux.t1 VALUES(1.5, 1.5);
    INSERT INTO aux.t1 VALUES(4.56, -99.999999999999999999999);
  }

} {
  do_then_apply_sql $sql aux
  do_test 2.$tn { compare_db db3 db2 } {}
}


catch {db3 close}

finish_test

Changes to ext/session/sqlite3session.c.

241
242
243
244
245
246
247
248
249
250
251

252
253
254
255
256
257
258
....
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
....
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
          memcpy(&i, &r, 8);
        }
        sessionPutI64(&aBuf[1], i);
      }
      nByte = 9; 
      break;

    case SQLITE_TEXT: 
    case SQLITE_BLOB: {
      int n = sqlite3_value_bytes(pValue);
      int nVarint = sessionVarintLen(n);

      if( aBuf ){
        sessionVarintPut(&aBuf[1], n);
        memcpy(&aBuf[nVarint + 1], eType==SQLITE_TEXT ? 
            sqlite3_value_text(pValue) : sqlite3_value_blob(pValue), n
        );
      }

................................................................................
      }

      case SQLITE_FLOAT: {
        if( abPK[i] ){
          double rVal;
          i64 iVal = sessionGetI64(a);
          memcpy(&rVal, &iVal, 8);
          rc = sqlite3_bind_int64(pSelect, i+1, rVal);
        }
        a += 8;
        break;
      }

      case SQLITE_TEXT: {
        int n;
................................................................................
      if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
        if( apOut ){
          sqlite3_int64 v = sessionGetI64(aRec);
          if( eType==SQLITE_INTEGER ){
            sqlite3VdbeMemSetInt64(apOut[i], v);
          }else{
            double d;
            memcpy(&d, &i, 8);
            sqlite3VdbeMemSetDouble(apOut[i], d);
          }
        }
        aRec += 8;
      }
    }
  }







|
<


>







 







|







 







|







241
242
243
244
245
246
247
248

249
250
251
252
253
254
255
256
257
258
....
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
....
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
          memcpy(&i, &r, 8);
        }
        sessionPutI64(&aBuf[1], i);
      }
      nByte = 9; 
      break;

    default: {

      int n = sqlite3_value_bytes(pValue);
      int nVarint = sessionVarintLen(n);
      assert( eType==SQLITE_TEXT || eType==SQLITE_BLOB );
      if( aBuf ){
        sessionVarintPut(&aBuf[1], n);
        memcpy(&aBuf[nVarint + 1], eType==SQLITE_TEXT ? 
            sqlite3_value_text(pValue) : sqlite3_value_blob(pValue), n
        );
      }

................................................................................
      }

      case SQLITE_FLOAT: {
        if( abPK[i] ){
          double rVal;
          i64 iVal = sessionGetI64(a);
          memcpy(&rVal, &iVal, 8);
          rc = sqlite3_bind_double(pSelect, i+1, rVal);
        }
        a += 8;
        break;
      }

      case SQLITE_TEXT: {
        int n;
................................................................................
      if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
        if( apOut ){
          sqlite3_int64 v = sessionGetI64(aRec);
          if( eType==SQLITE_INTEGER ){
            sqlite3VdbeMemSetInt64(apOut[i], v);
          }else{
            double d;
            memcpy(&d, &v, 8);
            sqlite3VdbeMemSetDouble(apOut[i], d);
          }
        }
        aRec += 8;
      }
    }
  }