Skip to content

Commit

Permalink
Various bug fixes for the new LSM1 virtual table design.
Browse files Browse the repository at this point in the history
  • Loading branch information
D. Richard Hipp committed Aug 9, 2017
1 parent 2c22742 commit 353bbae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
40 changes: 20 additions & 20 deletions ext/lsm1/lsm_vtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@
** values, the content is the blob data or the UTF-8 text data. For
** non-negative integers X, the content is a variable-length integer X*2.
** For negative integers Y, the content is varaible-length integer (1-Y)*2+1.
** For FLOAT values, the content is the variable length encoding of the
** integer with the same bit pattern as the IEEE754 floating point value.
** For FLOAT values, the content is the IEEE754 floating point value in
** native byte-order. This means that FLOAT values will be corrupted when
** database file is moved between big-endian and little-endian machines.
*/
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
Expand Down Expand Up @@ -529,7 +530,7 @@ static int lsm1PutSignedVarint64(u8 *z, sqlite3_int64 v){
u = (sqlite3_uint64)v;
return lsm1PutVarint64(z, u*2);
}else{
u = (sqlite3_uint64)(1-v);
u = (sqlite3_uint64)(-1-v);
return lsm1PutVarint64(z, u*2+1);
}
}
Expand Down Expand Up @@ -645,18 +646,20 @@ static int lsm1Column(
break;
}
case SQLITE_FLOAT: {
sqlite3_uint64 v1 = 0;
double v;
lsm1GetVarint64(zData, nData, &v1);
memcpy(&v, &v1, sizeof(v));
sqlite3_result_double(ctx, v);
if( nData==sizeof(v) ){
memcpy(&v, zData, sizeof(v));
sqlite3_result_double(ctx, v);
}
break;
}
case SQLITE_TEXT: {
sqlite3_result_text(ctx, (const char*)zData, nData, SQLITE_TRANSIENT);
break;
}
case SQLITE_BLOB: {
sqlite3_result_blob(ctx, zData, nData, SQLITE_TRANSIENT);
break;
}
default: {
/* A NULL. Do nothing */
Expand Down Expand Up @@ -908,14 +911,15 @@ int lsm1Update(
}
memset(&val, 0, sizeof(val));
for(i=0; i<p->nVal; i++){
u8 eType = sqlite3_value_type(argv[3+i]);
sqlite3_value *pArg = argv[3+i];
u8 eType = sqlite3_value_type(pArg);
switch( eType ){
case SQLITE_NULL: {
lsm1VblobAppendVarint(&val, SQLITE_NULL);
break;
}
case SQLITE_INTEGER: {
sqlite3_int64 v = sqlite3_value_int64(argv[3+i]);
sqlite3_int64 v = sqlite3_value_int64(pArg);
if( v>=0 && v<=240/6 ){
lsm1VblobAppendVarint(&val, v*6);
}else{
Expand All @@ -926,25 +930,21 @@ int lsm1Update(
break;
}
case SQLITE_FLOAT: {
double r = sqlite3_value_double(argv[3+i]);
sqlite3_uint64 u;
int n;
memcpy(&u, &r, 8);
n = lsm1PutSignedVarint64(pSpace, u);
lsm1VblobAppendVarint(&val, SQLITE_FLOAT + n*6);
lsm1VblobAppend(&val, pSpace, n);
double r = sqlite3_value_double(pArg);
lsm1VblobAppendVarint(&val, SQLITE_FLOAT + 8*6);
lsm1VblobAppend(&val, (u8*)&r, sizeof(r));
break;
}
case SQLITE_BLOB: {
int n = sqlite3_value_bytes(argv[3+i]);
int n = sqlite3_value_bytes(pArg);
lsm1VblobAppendVarint(&val, n*6 + SQLITE_BLOB);
lsm1VblobAppend(&val, sqlite3_value_blob(argv[2+i]), n);
lsm1VblobAppend(&val, sqlite3_value_blob(pArg), n);
break;
}
case SQLITE_TEXT: {
int n = sqlite3_value_bytes(argv[3+i]);
int n = sqlite3_value_bytes(pArg);
lsm1VblobAppendVarint(&val, n*6 + SQLITE_TEXT);
lsm1VblobAppend(&val, sqlite3_value_text(argv[2+i]), n);
lsm1VblobAppend(&val, sqlite3_value_text(pArg), n);
break;
}
}
Expand Down
7 changes: 4 additions & 3 deletions ext/lsm1/test/lsm1_simple.test
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ do_execsql_test 1.0 {
}

do_execsql_test 1.1 {
INSERT INTO x1(a,b,c,d) VALUES(15, 11, 22, 33);
SELECT * FROM x1;
} {15 11 22 33}
INSERT INTO x1(a,b,c,d) VALUES(15, 11, 22, 33),(8,'banjo',x'333231',NULL),
(12,NULL,3.25,-559281390);
SELECT a, quote(b), quote(c), quote(d) FROM x1;
} {8 'banjo' X'333231' NULL 12 NULL 3.25 -559281390 15 11 22 33}

do_catchsql_test 1.2 {
UPDATE x1 SET d = d+1.0 WHERE a=15;
Expand Down

0 comments on commit 353bbae

Please sign in to comment.