Need help on wxsqlite3.4.2.0 Topic is solved

In this forum you can discuss database related issues which can be wxWidgets related, but also generic in nature.
Post Reply
kjteng
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Oct 31, 2018 1:57 am

Need help on wxsqlite3.4.2.0

Post by kjteng »

I have downloaded wxsqlite3.4.2.0 and is facing the following problems:

1. I am unable to access database created in the earlier version (3.3.5.0) even if the database is not encrypted (i.e. password = '').
My code (lazarus freepascal, with zeolib database component) is as follows:

ZConnection1.Disconnect;
ZConnection1.Database := FileNameEdit1.FileName;
ZConnection1.Password := '';
// ZConnection1.ExecuteDirect(SELECT wxsqlite3_config("cipher", "aes256cbc"); //commented for non encryted db
ZConnection1.Connect;
Error message:
error1.png
error1.png (23.49 KiB) Viewed 17397 times
2. I can change the password of a database (created with wxsqlite3.4.2.0) with the following code:-

ZConnection1.Disconnect;
ZConnection1.Password := tx1Pass.Text; //existing password
ZConnection1.Connect;
if ZConnection1.Connected then
begin
zConnection1.ExecuteDirect('PRAGMA rekey =' + QuotedStr(tx2Pass.Text) + ';'); //only works if tx2pass.text is not blank
ZConnection1.Commit;
Showmessage('Password changed to: ' + #13 + tx2Pass.Text);
end
else
Showmessage('Unable to change key because database is not connected');

However, if I changed the password to '' (blank) then I won't be able to open tables in the database. The following error message will be displayed:
error2.png
error2.png (17.46 KiB) Viewed 17397 times
All the above codes work fine when I use wxsqlite3.3.5.0. Also, there are no problem the database is created with password using wxsqlite3.4.2.0.

Please help. Thank you.
kjteng
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Oct 31, 2018 1:57 am

Re: Need help on wxsqlite3.4.2.0

Post by kjteng »

After numerous time of try and error, I think I have found the solution: I have to set the encrypted property of the zConnection to true for version 3.4.2.0 as follows:
ZConnection1.Disconnect;
ZConnection1.Database := FileNameEdit1.FileName;
ZConnection1.Password := edit1.Text';

// change the encrypted parameter -- required for wxsqlite3.4.2.0
if ZConnection1.Password > '' then
ZConnection1.Properties.Values['encrypted']:= 'True'
else
ZConnection1.Properties.Values['encrypted']:= '' ;

ZConnection1.Connect;

The same is applicable to my 2nd question on changing of password rekey
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Need help on wxsqlite3.4.2.0

Post by utelle »

kjteng wrote:I have downloaded wxsqlite3.4.2.0 and is facing the following problems:

1. I am unable to access database created in the earlier version (3.3.5.0) even if the database is not encrypted (i.e. password = '').
My code (lazarus freepascal, with zeolib database component) is as follows:

ZConnection1.Disconnect;
ZConnection1.Database := FileNameEdit1.FileName;
ZConnection1.Password := '';
// ZConnection1.ExecuteDirect(SELECT wxsqlite3_config("cipher", "aes256cbc"); //commented for non encryted db
ZConnection1.Connect;
This question has been answered in this post.
kjteng wrote: 2. I can change the password of a database (created with wxsqlite3.4.2.0) with the following code:-

ZConnection1.Disconnect;
ZConnection1.Password := tx1Pass.Text; //existing password
ZConnection1.Connect;
if ZConnection1.Connected then
begin
zConnection1.ExecuteDirect('PRAGMA rekey =' + QuotedStr(tx2Pass.Text) + ';'); //only works if tx2pass.text is not blank
ZConnection1.Commit;
Showmessage('Password changed to: ' + #13 + tx2Pass.Text);
end
else
Showmessage('Unable to change key because database is not connected');
As you found out yourself you have to set the password and the encrypted property of the connection object. Otherwise the database can't be established properly and executing the pragma fails.
kjteng wrote: However, if I changed the password to '' (blank) then I won't be able to open tables in the database. The following error message will be displayed:
Well, if the encrypted database was successfully opened, then using pragma rekey with a blank password should decrypt the database. So, the first step is to verify that the database was successfully opened and can be accessed.

Regards,

Ulrich
kjteng
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Oct 31, 2018 1:57 am

Re: Need help on wxsqlite3.4.2.0

Post by kjteng »

Thanks for you reply.
Post Reply