pNew->pHashNext = pGlobal->aHash[iHash % pGlobal->nHash];
pGlobal->aHash[iHash % pGlobal->nHash] = pNew;
+ pGlobal->nEntry++;
}
return SQLITE_OK;
zSql = sqlite3_vmprintf(zFmt, ap);
*ppStmt = 0;
if( zSql ){
- rc = sqlite3_prepare(db, zSql, -1, ppStmt, 0);
+ rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
if( rc!=SQLITE_OK ){
*pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
}
if( zErr ){
sqlite3_result_error(pCtx, zErr, -1);
sqlite3_free(zErr);
+ }else if( rc ){
+ sqlite3_result_error_code(pCtx, rc);
}else{
if( p->encryptionKey==0 ){
p->encryptionType = 0;
sParam.encryptionType, (u8*)sParam.encryptionKey, n, &pCodec, &zErr
);
if( rc!=SQLITE_OK ){
- sqlite3_result_error(pCtx, zErr, -1);
+ if( zErr ){
+ sqlite3_result_error(pCtx, zErr, -1);
+ }else{
+ sqlite3_result_error_code(pCtx, rc);
+ }
sqlite3_free(zErr);
goto zone_write_out;
}
zonefileBufferFree(&sSample);
sqlite3_free(aSample);
sqlite3_free(sParam.encryptionKey);
+ if( rc==SQLITE_NOMEM ){
+ sqlite3_result_error_nomem(pCtx);
+ }
}
typedef struct ZonefileFilesTab ZonefileFilesTab;
}
/* Find the encryption method and key. */
- if( hdr.encryptionType ){
+ if( rc==SQLITE_OK && hdr.encryptionType ){
const char *z = 0;
int n = zonefileKeyFind(pTab->pGlobal, pTab->zDb, pTab->zName, iFile, &z);
if( n==0 ){
}
set COMPRESSION_METHODS [list]
foreach cmp {
- none zlib zstd zstd_global_dict lz4 lz4hc brotli
+ none zlib zstd zstd_global_dict lz4 lz4hc brotli nosuchcmp
} {
set res [catchsql {
WITH p(n,v) AS (
SELECT count(*) FROM rr JOIN gg USING(k) WHERE rr.v==gg.v;
} {300}
+forcedelete test.db2
+do_execsql_test 1.9.1 {
+ ATTACH 'test.db2' AS maing;
+ CREATE VIRTUAL TABLE maing.g USING zonefile;
+ INSERT INTO g_files(filename) SELECT filename FROM gg_files;
+}
+do_catchsql_test 1.9.2 {
+ SELECT count(*) FROM rr JOIN g USING(k) WHERE rr.v!=g.v;
+} {1 {missing encryption key for file "test0.zonefile"}}
+do_execsql_test 1.9.3 {
+ UPDATE g_files SET ekey = k(rowid-1);
+ SELECT count(*) FROM rr JOIN g USING(k) WHERE rr.v==g.v;
+} {300}
+
+do_execsql_test 1.10 {
+ SELECT count(*) FROM rr JOIN gg USING(k) WHERE rr.v==gg.v;
+} {300}
+#-------------------------------------------------------------------------
+
+reset_db
+load_static_extension db zonefile
+
+do_execsql_test 2.0 {
+ CREATE TABLE zz(k INTEGER PRIMARY KEY, frame INTEGER, idx INTEGER, v BLOB);
+}
+foreach {tn alg id} {
+ 1 aes_128_ctr 1
+ 2 aes_128_cbc 2
+ 3 AES_256_CTR 3
+ 4 Aes_256_CBC 4
+} {
+ do_catchsql_test 2.$tn {
+ WITH p(n,v) AS (
+ VALUES('encryptionType', $alg) UNION ALL
+ VALUES('encryptionKey', 'secret')
+ )
+ SELECT zonefile_write('test' || $i || '.zonefile', 'zz',
+ json_group_object(n, v)
+ ) FROM p;
+ } "1 {unsupported encryption method: $id}"
+}
finish_test
--- /dev/null
+# 2018 Feb 11
+#
+# 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.
+#
+#***********************************************************************
+#
+# The focus of this file is testing the zonefile extension.
+#
+
+if {![info exists testdir]} {
+ set testdir [file join [file dirname [info script]] .. .. test]
+}
+source [file join $testdir tester.tcl]
+source [file join $testdir malloc_common.tcl]
+set testprefix zonefilefault
+load_static_extension db zonefile
+
+do_execsql_test 1.0 {
+ CREATE TABLE tt(k INTEGER PRIMARY KEY, frame INTEGER, idx INTEGER, v BLOB);
+ INSERT INTO tt VALUES(1, -1, -1, randomblob(100));
+ INSERT INTO tt VALUES(2, -1, -1, randomblob(200));
+ INSERT INTO tt VALUES(3, 1, -1, randomblob(300));
+ INSERT INTO tt VALUES(4, 2, -1, randomblob(400));
+}
+
+do_faultsim_test 1.1 -faults oom* -prep {
+ sqlite3 db test.db
+ load_static_extension db zonefile
+} -body {
+ execsql {
+ SELECT zonefile_write('test.zonefile', 'tt',
+ '{"encryptionType":"xor", "encryptionKey":"secret"}'
+ );
+ }
+} -test {
+ faultsim_test_result {0 {{}}}
+}
+
+do_faultsim_test 1.2 -faults oom* -prep {
+ sqlite3 db test.db
+ load_static_extension db zonefile
+} -body {
+ execsql {
+ SELECT zonefile_write('test.zonefile', 'tt',
+ '{"compressionTypeContent":"zstd_global_dict"}'
+ );
+ }
+} -test {
+ faultsim_test_result {0 {{}}}
+}
+
+do_execsql_test 2.0 {
+ SELECT zonefile_write('test.zonefile', 'tt',
+ '{"encryptionType":"xor", "encryptionKey":"secret"}'
+ );
+ CREATE VIRTUAL TABLE zz USING zonefile;
+} {{}}
+
+faultsim_save_and_close
+do_faultsim_test 2 -faults oom* -prep {
+ faultsim_restore_and_reopen
+ load_static_extension db zonefile
+} -body {
+ execsql {
+ INSERT INTO zz_files(filename, ekey) VALUES('test.zonefile', 'secret')
+ }
+} -test {
+ faultsim_test_result {0 {}}
+}
+
+finish_test
+
-C Add\san\sLRU\scache\sof\suncompressed\sframe\scontent\sto\sthe\szonefile\svirtual\stable\nimplementation.
-D 2018-02-22T16:46:42.652
+C Add\stests\scases\sand\sfix\ssome\sminor\szonefile\sproblems.
+D 2018-02-22T21:06:08.522
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in 7a3f714b4fcf793108042b7b0a5c720b0b310ec84314d61ba7f3f49f27e550ea
F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04
F ext/userauth/userauth.c 3410be31283abba70255d71fd24734e017a4497f
F ext/zonefile/README.md df86ef5b4f9aa8b07e1c8124b3f2dcea616927385aad59d525b784f0a06d446c
-F ext/zonefile/zonefile.c ce2963a584f6e98f9238e84a5f7336d52750f669b4dc2d308842f78204189872
-F ext/zonefile/zonefile1.test 51ba36bd254026b86ceecb358a3f33837c7d086b75d3b45db85d0aee3fd0a9a0
-F ext/zonefile/zonefileenc.test 5cc89a1e716b127a5220f03162ced3bd9d7df8819fe04a87f2d962315e8ebdc1
+F ext/zonefile/zonefile.c f43dd41bd121ce8ab4f46ba3c8136e674df88ec2eb7ccc1c974e8e8b5aaa6e99
+F ext/zonefile/zonefile1.test d80e8fd9db0b4b942628d00136ee448ce5b1b5e09f4b85a25aef500b888d62e9
+F ext/zonefile/zonefileenc.test f23e16fc8810c95588dfd528af8e4332f0d1d13370fdd7163226ec886715058e
+F ext/zonefile/zonefilefault.test 5a76456541a7779d4869e0803dbc2d5453f941080a68ed1e3f3d1783d79548f6
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P d9d5cc62f11058f9ba560381367ff4765dbbde08184e55abdb50ae1b6bf4a016
-R fb3194c43333fefa4c70a2354320310d
+P 883e7e75d65622e8d06c46e48b7cc756cc0e3345b8124a8038cab0a8d51d0458
+R da39cc270268ef3a63a8351195aef15c
U dan
-Z 7246c4cd1ede6422af161378c0967b5a
+Z b265d0dff2f8716ab6f08f5f692e71fc
-883e7e75d65622e8d06c46e48b7cc756cc0e3345b8124a8038cab0a8d51d0458
\ No newline at end of file
+f4d42162fa2196078cea4db9c2247a08f5439d29e49f5e8dc23db317b8101865
\ No newline at end of file