The main is to set the Tfdconnection two link parameters: Password, NewPassword, very simple.
ConstDBPath = ' C:\Temp\SQLiteTest.sdb '; {The encrypted database is established, the password is mm123}procedureTform1.formcreate (Sender:tobject);Conststrtable = ' CREATE TABLE MyTable (Id integer, Name string (a), age byte) '; Id, Name, age three fieldsbegin
ifFileExists (DBPath)thenDeleteFile (DBPath);
FDCONNECTION1.PARAMS.ADD (' Driverid=sqlite ');
FDCONNECTION1.PARAMS.ADD (' database= ' + dbpath); FDCONNECTION1.PARAMS.ADD (' password=mm123 '); Same with password=aes-256:mm123; AES-256 is the default encryption algorithm; Also: aes-128,aes-192,aes-256, aes-ctr-128,aes-ctr-192,aes-ctr-256, aes-ecb-128,aes-ecb-192,aes-ecb-256/
Build the table and enter the test data fdconnection1.execsql (strtable); Fdconnection1.execsql (' INSERT into MyTable (Id, Name, age) VALUES (: 1,: 2,: 3) ', [1, ' abc ', 23]); End; {Open a database with a password}procedureTform1.button1click (Sender:tobject);beginFDConnection1.Params.Clear;
fdconnection1.connected: = False;
FDCONNECTION1.PARAMS.ADD (' Driverid=sqlite ');
FDCONNECTION1.PARAMS.ADD (' database= ' + dbpath);
FDCONNECTION1.PARAMS.ADD (' password=mm123 ');
fdconnection1.connected: = True; Fdquery1.open (' SELECT * from MyTable '); End; {Modify Password}procedureTform1.button2click (Sender:tobject);beginFDConnection1.Params.Clear;
fdconnection1.connected: = False;
FDCONNECTION1.PARAMS.ADD (' Driverid=sqlite ');
FDCONNECTION1.PARAMS.ADD (' database= ' + dbpath);
FDCONNECTION1.PARAMS.ADD (' password=mm123 '); FDCONNECTION1.PARAMS.ADD (' newpassword=mm12345 ');
New password, null password for password fdconnection1.connected: = True; fdconnection1.connected: = False; End;
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Delphi/
FIREDAC also provides a dedicated cryptographic control tfdsqlitesecurity, because the above method is convenient enough, so it is not very useful.
Fdsqlitesecurity1.driverlink: = FDPhysSQLiteDriverLink1; The other four controls in Tfdsqlitesecurity and FireDAC.Phys.SQLite specify this property before use
fdsqlitesecurity1.database: = DBPath; Specifies the database path
fdsqlitesecurity1.password: = ' mm111 '; Password
fdsqlitesecurity1.topassword: = ' mm222 ';//new password
Fdsqlitesecurity1.setpassword; Set password
fdsqlitesecurity1.changepassword; Modify password
Fdsqlitesecurity1.removepassword; Remove password
Help says: The SQLite encrypted by FIREDAC is incompatible with it.
Author:cnblogs in case