@@ -225,6 +225,68 @@ db2 close
225225file delete -force test.db
226226file delete -force test2.db
227227
228+ # attach an empty encrypted database as the first op
229+ # on a keyed database and verify different
230+ # salts but same keys (because derivation of the key spec
231+ # has not occured yet)
232+ setup test.db "'testkey'"
233+ do_test attach-empty-database-with-default-key-first-op {
234+ sqlite_orig db test.db
235+ set rc {}
236+
237+ execsql {
238+ PRAGMA key='testkey';
239+ ATTACH DATABASE 'test2.db' AS test;
240+ CREATE TABLE test.t1(a,b);
241+ INSERT INTO test.t1 SELECT * FROM t1;
242+ DETACH DATABASE test;
243+ }
244+
245+ sqlite_orig db2 test2.db
246+
247+ lappend rc [execsql {
248+ PRAGMA key='testkey';
249+ SELECT count(*) FROM t1;
250+ } db2]
251+
252+ lappend rc [string equal [hexio_read test.db 0 16] [hexio_read test2.db 0 16]]
253+ } {1 0}
254+ db close
255+ db2 close
256+ file delete -force test.db
257+ file delete -force test2.db
258+
259+ # attach an empty encrypted database
260+ # on a keyed database when PRAGMA cipher_store_pass = 1
261+ # and verify different salts
262+ setup test.db "'testkey'"
263+ do_test attach-empty-database-with-cipher-store-pass {
264+ sqlite_orig db test.db
265+ set rc {}
266+
267+ execsql {
268+ PRAGMA key='testkey';
269+ PRAGMA cipher_store_pass = 1;
270+ INSERT INTO t1(a,b) VALUES (1,2);
271+ ATTACH DATABASE 'test2.db' AS test;
272+ CREATE TABLE test.t1(a,b);
273+ INSERT INTO test.t1 SELECT * FROM t1;
274+ DETACH DATABASE test;
275+ }
276+
277+ sqlite_orig db2 test2.db
278+
279+ lappend rc [execsql {
280+ PRAGMA key='testkey';
281+ SELECT count(*) FROM t1;
282+ } db2]
283+ lappend rc [string equal [hexio_read test.db 0 16] [hexio_read test2.db 0 16]]
284+ } {2 0}
285+ db close
286+ db2 close
287+ file delete -force test.db
288+ file delete -force test2.db
289+
228290# attach an encrypted database
229291# without specifying key, verify it attaches
230292# correctly when PRAGMA cipher_store_pass = 1
0 commit comments