Convert the LSM1 virtual table to be WITHOUT ROWID and get UPDATE and DELETE
operations working on it. FossilOrigin-Name: 2164031b509dc6eae367ffb9d915f3e1d33d26210506b2de8b2bfca38c53465f
This commit is contained in:
parent
f41a8d3d9a
commit
037a2bacb0
@ -243,13 +243,16 @@ static int lsm1Connect(
|
||||
lsm1VblobAppendText(&sql, argv[4]);
|
||||
lsm1VblobAppendText(&sql, " ");
|
||||
lsm1VblobAppendText(&sql, argv[5]);
|
||||
lsm1VblobAppendText(&sql, " PRIMARY KEY");
|
||||
for(i=6; i<argc; i++){
|
||||
lsm1VblobAppendText(&sql, ", ");
|
||||
lsm1VblobAppendText(&sql, argv[i]);
|
||||
pNew->nVal++;
|
||||
}
|
||||
lsm1VblobAppendText(&sql,
|
||||
", lsm1_command HIDDEN, lsm1_key HIDDEN, lsm1_value HIDDEN)");
|
||||
", lsm1_command HIDDEN"
|
||||
", lsm1_key HIDDEN"
|
||||
", lsm1_value HIDDEN) WITHOUT ROWID");
|
||||
lsm1VblobAppend(&sql, (u8*)"", 1);
|
||||
if( sql.errNoMem ){
|
||||
rc = SQLITE_NOMEM;
|
||||
@ -669,6 +672,31 @@ static int lsm1Column(
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/* Parameter "pValue" contains an SQL value that is to be used as
|
||||
** a key in an LSM table. The type of the key is determined by
|
||||
** "keyType". Extract the raw bytes used for the key in LSM1.
|
||||
*/
|
||||
static void lsm1KeyFromValue(
|
||||
int keyType, /* The key type */
|
||||
sqlite3_value *pValue, /* The key value */
|
||||
u8 *pBuf, /* Storage space for a generated key */
|
||||
const u8 **ppKey, /* OUT: the bytes of the key */
|
||||
int *pnKey /* OUT: size of the key */
|
||||
){
|
||||
if( keyType==SQLITE_BLOB ){
|
||||
*ppKey = (const u8*)sqlite3_value_blob(pValue);
|
||||
*pnKey = sqlite3_value_bytes(pValue);
|
||||
}else if( keyType==SQLITE_TEXT ){
|
||||
*ppKey = (const u8*)sqlite3_value_text(pValue);
|
||||
*pnKey = sqlite3_value_bytes(pValue);
|
||||
}else{
|
||||
sqlite3_int64 v = sqlite3_value_int64(pValue);
|
||||
if( v<0 ) v = 0;
|
||||
*pnKey = lsm1PutVarint64(pBuf, v);
|
||||
*ppKey = pBuf;
|
||||
}
|
||||
}
|
||||
|
||||
/* Move to the first row to return.
|
||||
*/
|
||||
static int lsm1Filter(
|
||||
@ -680,7 +708,7 @@ static int lsm1Filter(
|
||||
lsm1_vtab *pTab = (lsm1_vtab*)(pCur->base.pVtab);
|
||||
int rc = LSM_OK;
|
||||
int seekType = -1;
|
||||
const void *pVal = 0;
|
||||
const u8 *pVal = 0;
|
||||
int nVal;
|
||||
u8 keyType = pTab->keyType;
|
||||
u8 aKey1[16];
|
||||
@ -689,18 +717,7 @@ static int lsm1Filter(
|
||||
sqlite3_free(pCur->pKey2);
|
||||
pCur->pKey2 = 0;
|
||||
if( idxNum<99 ){
|
||||
if( keyType==SQLITE_BLOB ){
|
||||
pVal = sqlite3_value_blob(argv[0]);
|
||||
nVal = sqlite3_value_bytes(argv[0]);
|
||||
}else if( keyType==SQLITE_TEXT ){
|
||||
pVal = sqlite3_value_text(argv[0]);
|
||||
nVal = sqlite3_value_bytes(argv[0]);
|
||||
}else{
|
||||
sqlite3_int64 v = sqlite3_value_int64(argv[0]);
|
||||
if( v<0 ) v = 0;
|
||||
nVal = lsm1PutVarint64(aKey1, v);
|
||||
pVal = aKey1;
|
||||
}
|
||||
lsm1KeyFromValue(keyType, argv[0], aKey1, &pVal, &nVal);
|
||||
}
|
||||
switch( idxNum ){
|
||||
case 0: { /* key==argv[0] */
|
||||
@ -870,21 +887,30 @@ int lsm1Update(
|
||||
sqlite_int64 *pRowid
|
||||
){
|
||||
lsm1_vtab *p = (lsm1_vtab*)pVTab;
|
||||
int nKey;
|
||||
int nKey, nKey2;
|
||||
int i;
|
||||
int rc = LSM_OK;
|
||||
unsigned char *pKey;
|
||||
const u8 *pKey, *pKey2;
|
||||
unsigned char aKey[16];
|
||||
unsigned char pSpace[16];
|
||||
lsm1_vblob val;
|
||||
|
||||
if( argc==1 ){
|
||||
pVTab->zErrMsg = sqlite3_mprintf("cannot DELETE");
|
||||
return SQLITE_ERROR;
|
||||
/* DELETE the record whose key is argv[0] */
|
||||
lsm1KeyFromValue(p->keyType, argv[0], aKey, &pKey, &nKey);
|
||||
lsm_delete(p->pDb, pKey, nKey);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
if( sqlite3_value_type(argv[0])!=SQLITE_NULL ){
|
||||
pVTab->zErrMsg = sqlite3_mprintf("cannot UPDATE");
|
||||
return SQLITE_ERROR;
|
||||
/* An UPDATE */
|
||||
lsm1KeyFromValue(p->keyType, argv[0], aKey, &pKey, &nKey);
|
||||
lsm1KeyFromValue(p->keyType, argv[1], pSpace, &pKey2, &nKey2);
|
||||
if( nKey!=nKey2 || memcmp(pKey, pKey2, nKey)!=0 ){
|
||||
/* The UPDATE changes the PRIMARY KEY value. DELETE the old key */
|
||||
lsm_delete(p->pDb, pKey, nKey);
|
||||
}
|
||||
/* Fall through into the INSERT case to complete the UPDATE */
|
||||
}
|
||||
|
||||
/* "INSERT INTO tab(lsm1_command) VALUES('....')" is used to implement
|
||||
@ -893,22 +919,7 @@ int lsm1Update(
|
||||
if( sqlite3_value_type(argv[3+p->nVal])!=SQLITE_NULL ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
if( p->keyType==SQLITE_BLOB ){
|
||||
pKey = (u8*)sqlite3_value_blob(argv[2]);
|
||||
nKey = sqlite3_value_bytes(argv[2]);
|
||||
}else if( p->keyType==SQLITE_TEXT ){
|
||||
pKey = (u8*)sqlite3_value_text(argv[2]);
|
||||
nKey = sqlite3_value_bytes(argv[2]);
|
||||
}else{
|
||||
sqlite3_int64 v = sqlite3_value_int64(argv[2]);
|
||||
if( v>=0 ){
|
||||
nKey = lsm1PutVarint64(aKey, (sqlite3_uint64)v);
|
||||
pKey = aKey;
|
||||
}else{
|
||||
pVTab->zErrMsg = sqlite3_mprintf("key must be non-negative");
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
}
|
||||
lsm1KeyFromValue(p->keyType, argv[2], aKey, &pKey, &nKey);
|
||||
memset(&val, 0, sizeof(val));
|
||||
for(i=0; i<p->nVal; i++){
|
||||
sqlite3_value *pArg = argv[3+i];
|
||||
|
@ -23,7 +23,7 @@ do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE x1 USING lsm1(testlsm.db,a,UINT,b,c,d);
|
||||
PRAGMA table_info(x1);
|
||||
} {
|
||||
0 a UINT 0 {} 0
|
||||
0 a UINT 1 {} 1
|
||||
1 b {} 0 {} 0
|
||||
2 c {} 0 {} 0
|
||||
3 d {} 0 {} 0
|
||||
@ -35,13 +35,15 @@ do_execsql_test 1.1 {
|
||||
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 {
|
||||
do_execsql_test 1.2 {
|
||||
UPDATE x1 SET d = d+1.0 WHERE a=15;
|
||||
} {1 {cannot UPDATE}}
|
||||
SELECT a, quote(b), quote(c), quote(d) FROM x1;
|
||||
} {8 'banjo' X'333231' NULL 12 NULL 3.25 -559281390 15 11 22 34.0}
|
||||
|
||||
do_catchsql_test 1.3 {
|
||||
do_execsql_test 1.3 {
|
||||
DELETE FROM x1 WHERE a=15;
|
||||
} {1 {cannot DELETE}}
|
||||
SELECT a, quote(b), quote(c), quote(d) FROM x1;
|
||||
} {8 'banjo' X'333231' NULL 12 NULL 3.25 -559281390}
|
||||
|
||||
do_test 1.4 {
|
||||
lsort [glob testlsm.db*]
|
||||
|
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
||||
C Simplification\sto\sthe\slike\soptimization\slogic.\s\sRemove\sunnecessary\sbranches.
|
||||
D 2017-08-11T03:47:21.399
|
||||
C Convert\sthe\sLSM1\svirtual\stable\sto\sbe\sWITHOUT\sROWID\sand\sget\sUPDATE\sand\sDELETE\noperations\sworking\son\sit.
|
||||
D 2017-08-11T12:49:59.722
|
||||
F Makefile.in d9873c9925917cca9990ee24be17eb9613a668012c85a343aef7e5536ae266e8
|
||||
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
||||
F Makefile.msc 02b469e9dcd5b7ee63fc1fb05babc174260ee4cfa4e0ef2e48c3c6801567a016
|
||||
@ -249,10 +249,10 @@ F ext/lsm1/lsm_str.c 65e361b488c87b10bf3e5c0070b14ffc602cf84f094880bece77bbf6678
|
||||
F ext/lsm1/lsm_tree.c 682679d7ef2b8b6f2fe77aeb532c8d29695bca671c220b0abac77069de5fb9fb
|
||||
F ext/lsm1/lsm_unix.c 57361bcf5b1a1a028f5d66571ee490e9064d2cfb145a2cc9e5ddade467bb551b
|
||||
F ext/lsm1/lsm_varint.c 43f954af668a66c7928b81597c14d6ad4be9fedbc276bbd80f52fa28a02fdb62
|
||||
F ext/lsm1/lsm_vtab.c 976ded75b78be59fc358cf5c06641cda01a4bd0b52374419ab36bf37f646d5df
|
||||
F ext/lsm1/lsm_vtab.c be946a9c657ee52532f332db3acd65dc96fc0b398d81cc7df6cd41bf14907b60
|
||||
F ext/lsm1/lsm_win32.c 0a4acbd7e8d136dd3a5753f0a9e7a9802263a9d96cef3278cf120bcaa724db7c
|
||||
F ext/lsm1/test/lsm1_common.tcl 5ed4bab07c93be2e4f300ebe46007ecf4b3e20bc5fbe1dedaf04a8774a6d8d82
|
||||
F ext/lsm1/test/lsm1_simple.test 0ca15907fbfe09b6606f93149416786709e0cd55a69ecf53f605fadefa64228c
|
||||
F ext/lsm1/test/lsm1_simple.test 4adc9a20586de30a4fbcaa3c38aa45e41eb6e5dad1a94d29133ab26f2d3ae0b3
|
||||
F ext/misc/README.md 8e008c8d2b02e09096b31dfba033253ac27c6c06a18aa5826e299fa7601d90b2
|
||||
F ext/misc/amatch.c 6db4607cb17c54b853a2d7c7c36046d004853f65b9b733e6f019d543d5dfae87
|
||||
F ext/misc/anycollseq.c 5ffdfde9829eeac52219136ad6aa7cd9a4edb3b15f4f2532de52f4a22525eddb
|
||||
@ -1646,7 +1646,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P c601d128ff1f1dd6d221ee9f55595a95b58ba07d043e1d530743ea913731560e
|
||||
R 7b8cc485a478f9a3a5e81fd5979a0685
|
||||
P 9466d952e169a6a60f6e575e679a61f05887b51c693505764edaf10f62cd829f
|
||||
R 62e131d09888f53496402cbcb1bebe19
|
||||
U drh
|
||||
Z d5fe3bd64a4a4e8c044c651e64077540
|
||||
Z 28be5e6440b8c6d01af98e584f712f63
|
||||
|
@ -1 +1 @@
|
||||
9466d952e169a6a60f6e575e679a61f05887b51c693505764edaf10f62cd829f
|
||||
2164031b509dc6eae367ffb9d915f3e1d33d26210506b2de8b2bfca38c53465f
|
Loading…
x
Reference in New Issue
Block a user