Gandalf
Gandalf

Reputation: 13693

sqlcipher attach database

I am following the example at the sqlcipher Api docs : http://sqlcipher.net/sqlcipher-api#attach

ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'secret'; -- create a new encrypted database
CREATE TABLE encrypted.t1(a,b); -- recreate the schema in the new database (you can inspect all objects using SELECT * FROM sqlite_master)
INSERT INTO encrypted.t1 SELECT * FROM t1; -- copy data from the existing tables to the new tables in the encrypted database
DETACH DATABASE encrypted;

The first line CREATE TABLE encrypted.t1(a,b); has (a,b) and the second

INSERT INTO encrypted.t1 SELECT * FROM t1; does not.

Why is there an(a,b) in the first line and what is it for?.

Upvotes: 2

Views: 1755

Answers (1)

Stephen Lombardo
Stephen Lombardo

Reputation: 1523

In this case a and b are the column names. The introduction to that example in the docs explains the important point "assume you have a standard SQLite database called unencrypted.db with a single table, t1(a,b)." Then:

  1. The first line attaches a new encrypted database.
  2. Next, a second table is created in the encrypted database with the same name and column specification.
  3. The third line selects all the data out of the original table and inserts it into the new table in the encrypted database.

Because the columns on the two tables are identical it is not necessary to list the table columns explicitly.

Upvotes: 3

Related Questions