Index: ext/lsm1/lsm_vtab.c ================================================================== --- ext/lsm1/lsm_vtab.c +++ ext/lsm1/lsm_vtab.c @@ -593,10 +593,11 @@ sqlite3_value **argv, sqlite_int64 *pRowid ){ lsm1_vtab *p = (lsm1_vtab*)pVTab; const void *pKey; + void *pFree = 0; int nKey; int eType; int rc = LSM_OK; sqlite3_value *pValue; const unsigned char *pVal; @@ -627,10 +628,11 @@ /* Use a key encoding that sorts in lexicographical order */ rc = lsm1EncodeKey(argv[2+LSM1_COLUMN_KEY], (unsigned char**)&pKey,&nKey, pSpace,sizeof(pSpace)); if( rc ) return rc; + if( pKey!=(const void*)pSpace ) pFree = (void*)pKey; } if( sqlite3_value_type(argv[2+LSM1_COLUMN_BLOBVALUE])==SQLITE_BLOB ){ pVal = sqlite3_value_blob(argv[2+LSM1_COLUMN_BLOBVALUE]); nVal = sqlite3_value_bytes(argv[2+LSM1_COLUMN_BLOBVALUE]); rc = lsm_insert(p->pDb, pKey, nKey, pVal, nVal); @@ -681,11 +683,11 @@ rc = lsm_insert(p->pDb, pKey, nKey, &aVal[i], 9-i); break; } } } - if( pKey!=(const void*)pSpace ) sqlite3_free((void*)pKey); + sqlite3_free(pFree); return rc==LSM_OK ? SQLITE_OK : SQLITE_ERROR; } /* Begin a transaction */ ADDED ext/lsm1/test/lsm1_common.tcl Index: ext/lsm1/test/lsm1_common.tcl ================================================================== --- /dev/null +++ ext/lsm1/test/lsm1_common.tcl @@ -0,0 +1,35 @@ +# 2014 Dec 19 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +if {![info exists testdir]} { + set testdir [file join [file dirname [info script]] .. .. .. test] +} +source $testdir/tester.tcl + +# Check if the lsm1 extension has been compiled. +set lsm1 lsm1.so +if {[file exists [file join .. $lsm1]]} { + proc return_if_no_lsm1 {} {} +} else { + proc return_if_no_lsm1 {} { + finish_test + return -code return + } + return +} + +proc load_lsm1_vtab {db} { + db enable_load_extension 1 + db eval {SELECT load_extension('../lsm1')} +} + + ADDED ext/lsm1/test/lsm1_simple.test Index: ext/lsm1/test/lsm1_simple.test ================================================================== --- /dev/null +++ ext/lsm1/test/lsm1_simple.test @@ -0,0 +1,56 @@ +# 2017 July 14 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the lsm1 virtual table module. +# + +source [file join [file dirname [info script]] lsm1_common.tcl] +set testprefix lsm1_simple +return_if_no_lsm1 +load_lsm1_vtab db + +forcedelete testlsm.db + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE x1 USING lsm1(testlsm.db); + PRAGMA table_info(x1); +} { + 0 key {} 0 {} 0 + 1 blobkey {} 0 {} 0 + 2 value {} 0 {} 0 + 3 blobvalue {} 0 {} 0 +} + +do_execsql_test 1.1 { + INSERT INTO x1(blobkey, blobvalue) VALUES(x'abcd', x'1234'); + SELECT quote(blobkey), quote(blobvalue) FROM x1; +} {X'ABCD' X'1234'} + +do_catchsql_test 1.2 { + UPDATE x1 SET blobvalue = x'7890' WHERE blobkey = x'abcd'; +} {1 {cannot UPDATE}} + +do_catchsql_test 1.3 { + DELETE FROM x1 WHERE blobkey = x'abcd' +} {1 {cannot DELETE}} + +do_test 1.4 { + lsort [glob testlsm.db*] +} {testlsm.db testlsm.db-log testlsm.db-shm} + +db close +do_test 1.5 { + lsort [glob testlsm.db*] +} {testlsm.db} + +finish_test + + Index: test/permutations.test ================================================================== --- test/permutations.test +++ test/permutations.test @@ -87,11 +87,12 @@ set alltests [list] foreach f [glob $testdir/*.test] { lappend alltests [file tail $f] } foreach f [glob -nocomplain \ $testdir/../ext/rtree/*.test \ $testdir/../ext/fts5/test/*.test \ -] { + $testdir/../ext/lsm1/test/*.test \ +] { lappend alltests $f } foreach f [glob -nocomplain $testdir/../ext/session/*.test] { lappend alltests $f }