How to close SQLite Connection?
Moderator: Rathinagiri
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
How to close SQLite Connection?
Hi,
I am using HBSQLite for an application.
At the end of the application, I wish to encrypt the database and delete the original database file. I could not delete the file from inside the application because, the file is in use.
Actually when the application exits the database file is also closed automatically.
How to close this file either automatically or forcefully? Or, can I run a module just after the closure of the database and before closure of the application? (SQLite3_close() wrapper function is called via HB_Garbage function.)
Can anybody help me?
I am using HBSQLite for an application.
At the end of the application, I wish to encrypt the database and delete the original database file. I could not delete the file from inside the application because, the file is in use.
Actually when the application exits the database file is also closed automatically.
How to close this file either automatically or forcefully? Or, can I run a module just after the closure of the database and before closure of the application? (SQLite3_close() wrapper function is called via HB_Garbage function.)
Can anybody help me?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
Re: How to close SQLite Connection?
An EXIT PROCEDURE would fullfill ???
Angel Pais
Web Apps consultant/architect/developer.
Web Apps consultant/architect/developer.
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: How to close SQLite Connection?
Thanks for the reply. I tried very eagerly and got the following: Actually I have called the deleting porting at 'on release of main window' only.
- Attachments
-
- Clipboard01.jpg (11.94 KiB) Viewed 7292 times
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: How to close SQLite Connection?
Hi Rathi
Does this function not served to your purpose ?
http://www.php.net/manual/en/function.sqlite-close.php
Regards
--
Esgici
Does this function not served to your purpose ?
http://www.php.net/manual/en/function.sqlite-close.php
Regards
--
Esgici
Viva INTERNATIONAL HMG
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: How to close SQLite Connection?
Thanks for the reference Esgici. It is for php.
However, the respective wrapper function in harbour is sqlite3_close(). It can't be called directly. (On seeing the source code, I have found this). It is called automatically by Harbour in Garbage Collection procedure.
Francesco had thrown light on calling hb_gcall( .t. ), which simulates garbage collection (like cleaning up the unneeded things in the memory). Just now I have checked this and it works just as I expected.
hb_gcall( .t. )
frease( cDB )
This worked. Thanks to all. This helped me in creating an encrypted database with password protection.
This is my way of encryption/decryption of a SQLite database kept in secret. If there is any flaw in this please guide me.
1. We have an AES encrypted database.
2. When the password is given the encrypted database is decrypted inside a random directory which is created at the runtime.
3. All operations are done to this decrypted database.
4. Once the application is closed, the database is encrypted again to the original location.
5. Now, the decrypted database is deleted and the random directory is removed from the system.
However, the respective wrapper function in harbour is sqlite3_close(). It can't be called directly. (On seeing the source code, I have found this). It is called automatically by Harbour in Garbage Collection procedure.
Francesco had thrown light on calling hb_gcall( .t. ), which simulates garbage collection (like cleaning up the unneeded things in the memory). Just now I have checked this and it works just as I expected.
hb_gcall( .t. )
frease( cDB )
This worked. Thanks to all. This helped me in creating an encrypted database with password protection.
This is my way of encryption/decryption of a SQLite database kept in secret. If there is any flaw in this please guide me.
1. We have an AES encrypted database.
2. When the password is given the encrypted database is decrypted inside a random directory which is created at the runtime.
3. All operations are done to this decrypted database.
4. Once the application is closed, the database is encrypted again to the original location.
5. Now, the decrypted database is deleted and the random directory is removed from the system.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
Re: How to close SQLite Connection?
Dear Rathinagiri,
Working example, please
Working example, please
BPD
Convert Dream into Reality through HMG
Convert Dream into Reality through HMG
Re: How to close SQLite Connection?
But... When you reset computer or close your program by task manager, your database will stay decrypted
You must detect if it's encrypted or decrypted.
You must detect if it's encrypted or decrypted.
Re: How to close SQLite Connection?
Hi Rathinagiri,
I think your methods is really dangerous but I need more infos on the data in the database.
If the database is "readonly", I mean just SELECTs and no INSERT or UPDATE, you just need to keep track of where the temporary db is stored so if the program/computer crashed, at the next run you go and delete the temporary archive.
Mol already told you that when decripted, everyone can read it...
If it is updated the situation is worse: what about I add record for 3 hours and then the program crashes ? So you need to keep track of where the temporary db is stored and at next run recover from it (not delete it).
I don't remember why you need to encript the db, perhaps you can encript single fields...
I think your methods is really dangerous but I need more infos on the data in the database.
If the database is "readonly", I mean just SELECTs and no INSERT or UPDATE, you just need to keep track of where the temporary db is stored so if the program/computer crashed, at the next run you go and delete the temporary archive.
Mol already told you that when decripted, everyone can read it...
If it is updated the situation is worse: what about I add record for 3 hours and then the program crashes ? So you need to keep track of where the temporary db is stored and at next run recover from it (not delete it).
I don't remember why you need to encript the db, perhaps you can encript single fields...
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: How to close SQLite Connection?
Hi Francesco,
Really interesting situations.
I update the random directory name initially inside the database. Before application closure, I update this field to empty. If the program is crashed, this field will not be empty. So, the next time when the application is started, if there is anything in that field in the database, I will remove that directory content immediately.
After every commit, I encrypt the whole db side by side (which is silly and time consuming. But I am doing it because the database is < 20 MB and it takes less than a second to encrypt the whole db!). So, even after working for 3 hours you will not miss anything other than the last transaction.
Really interesting situations.
I update the random directory name initially inside the database. Before application closure, I update this field to empty. If the program is crashed, this field will not be empty. So, the next time when the application is started, if there is anything in that field in the database, I will remove that directory content immediately.
After every commit, I encrypt the whole db side by side (which is silly and time consuming. But I am doing it because the database is < 20 MB and it takes less than a second to encrypt the whole db!). So, even after working for 3 hours you will not miss anything other than the last transaction.
Yes, only if they know about the name and location of the random directory created elsewhere.Mol already told you that when decripted, everyone can read it...
I want to keep the whole db secretly and I wish to keep the index on some of these fields too. We can't make a primary key field to be encrypted. Isn't it?I don't remember why you need to encript the db, perhaps you can encript single fields...
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
Re: How to close SQLite Connection?
Did you know there is an encrypted version of Sqlite for under U$S 100 ?
You pay once deploy forever. The license is PER DEVELOPPER.
It is made by the same author than sqlite.
Later will try to find the link
You pay once deploy forever. The license is PER DEVELOPPER.
It is made by the same author than sqlite.
Later will try to find the link
Angel Pais
Web Apps consultant/architect/developer.
Web Apps consultant/architect/developer.