How to provide password to sqlite3.exe? - sqlite

I have a sqlite database that I want to open using sqlite3.exe. Now I get an error when I try to make queries, saying "file is encrypted or is not a database". This may seem stupid but I've been looking around on internet and I just don't find how to supply a password (or key) to sqlite3.exe to decrypt the database. The -help option or .help command of sqlite3.exe don't show anything to do that... Is it possible to do that, and if so how can I do it?

It is unlikely that the database would be encrypted, unless you have a reason to believe it is. Are you able to open the database at all, or are you getting this error once you issue some SQL query? If it's the former, your file is probably either not an sqlite db to begin with, or it is corrupted; if it's the latter, please check the integrity of your db with:
pragma integrity_check;
See http://www.sqlite.org/pragma.html#pragma_integrity_check for more info about this pragma.
In any case, unless your db is really encrypted (which sqlite does not support natively), your db is probably unusable.

SQLite reports that error when you pass it a file which is either not actually a SQLite database, or alternatively has been corrupted. There are several SQLite addons to support encryption, but other than that SQLite doesn't have encryption.
It can also happen when you try and open a SQLite v3 database with SQLite v2 (and possibly for other version mismatches).
Assuming you have experienced corruption (and not just passing the wrong file, or using the wrong version of SQLite), you may want to check the PRAGMA synchronous settings you're using, and also review the list of fixed data-corrupting bugs.

Checkout this this forum here. The guy had the same question as you. The thing is that there is not any form of protection offered as a standard package in sqlite3 API, but you can try System.Data.SQLite. These are the codes posted on the forum:
#include <SQLite.au3> don't include sqlite.dll.au3 !!!
_SQLite_Startup ("System.Data.SQLite.dll")
ConsoleWrite(_SQLite_LibVersion() & #LF)
_SQLite_Open("testcrypt.db")
_SQLite_Exec(-1, "pragma key = 'Radu is happy!';create table if not exists test (id integer, val text);" & _
"insert into test values (1, 'abc');")
Local $row
_SQLite_QuerySingleRow(-1, "select * from test;", $row)
ConsoleWrite($row[1] & #LF)
_SQLite_Close()
_SQLite_Shutdown()
hope that helps.

Related

Decrypt database using FMDB with SQLCipher, setkey with a wrong password always return YES

FMDB version (2.6.2)
Problem:
I am testing FMDB and SQLCipher, and find a tricky problem.
I encrypt a db with password 'test001' successfully, and I export it and open the db with DB Brower, with 'test001' I open it without any problem. Then in Xcode I try to open the DB with password 'test002'(I do this to test if FMDB will tell me that I use a wrong password), however the setkey() return YES. I check db.lastErrorMessage, it returns nil, which means FMDB thinks I give the right key.Then I try to read data from the DB using executeQuery(), the function returns NO, and the NSLog shows 'file is encrypted or is not a database'.
Anyone has the same problem? Is it a bug of sqlite or I use it in a wrong way?
setkey() return YES
executeQuery() return NO due to decrypt error
The call to setKey(…)does not verify the password provided is valid for current database, rather it just causes the database to attach a codec context within SQLCipher. The next SQL command that you issue following the keying of the database will cause key derivation to occur (so long as you are not using a raw hex key), and will generally validate whether SQLCipher is able to use the key to access your database. We generally recommend you attempt to execute the following query to validate the password is valid as the sqlite_master table will always be present, regardless of your schema.
SELECT count(*) FROM sqlite_master;

'file is encrypted or is not a database' error while opening the sqlite db

I have a sqlite database in my UWP app. On the very first launch of my app, I create the database and set it up with all the tables and stuff. I play around with the app and generate some data just fine. But when I close and relaunch the app, it starts giving me 'file is encrypted or is not a database' error while trying to execute any query.
I am using sqlite3.dll v3.12.0 and here is my pragma key statement (with an example encryption key):
"PRAGMA key='aes256:66zk4rsKBIfSJ4vhF1XkzFxzrznOhjjnotuHRdKADIg='"
I verified, on second launch, the encryption key is being used to run the pragma key statement.
Edit: It looks like the encryption went just fine. Because, when I use a tool like SQLite Manager and provide the same key, it opens the db just fine.
I think what might be happening to you Is that you use to have a previous library of SQLite working with encryption working properly like I did.
<SDKReference Include="SQLite.UAP.2015, Version=3.10.2">
<Name>SQLite for Universal App Platform</Name>
</SDKReference>
And since you updated the library to v3.12.0 the PRAGMA key in this version did not work hence not being able to enter to the previous encrypted DB.
I'm trying to rebuild the link to that version but is hard: "SQLite.UAP.2015, Version=3.10.2"

sqlite database schema version incrementing on disconnect/connect from sqlitestudio

I use the sqlite database schema version.
PRAGMA schema_version;
It helps me control upgrades and prevents user from modifying the schema and then reporting a flood of irreproducible bugs.
However, I find the version increments far more often that I expect.
" It is incremented by SQLite whenever the database schema is modified (by creating or dropping a table or index). " http://www.sqlite.org/pragma.html#pragma_schema_version
In particular when I simply connect and disconnect from sqlitestudio, even though I do not change the schema in any way.
Is there any way of preventing this happening ( or at least understanding what is going on ) ?

Qt - How to list all existing databases on PostgreSQL server using Qt interface

Could someone please explain how to obtain a list of all existing databases on a PostgreSQL server, to which the user already has access, using Qt? PostgreSQL documentation suggests the following query:
SELECT datname FROM pg_database WHERE datistemplate = false;
What are the correct parameters to the following functions:
QSqlDatabase::setDatabaseName(const QString & name) //"postgres" or "pg_database"?
QSqlDatabase::setUserName(const QString & name) //actual user name?
QSqlDatabase::setPassword(const QString & password) //no password? or user password?
Much appreciated. Thank you in advance.
You appear to have already answered the first part of your question. Connect to the postgres or template1 database and issue the query you've quoted above to get a list of databases. I'm guessing - reading between the lines - that you don't know how to connect to PostgreSQL to send that query, and that's what the second part of your question is about. Right?
If so, the QSqlDatabase accessor functions you've mentioned are used to set connection parameters, so the "correct" values depend on your environment.
If you want to issue the query above - to list databases - then you would probably want to connect to the postgres database as it always exists and isn't generally used for anything specific, it's there just to be connected to. That means you'd call setDatabaseName("postgres");. Passing pg_database to setDatabaseName would be nonsensical, since pg_database is the pg_catalog.pg_database table, it isn't a database you can connect to. pg_database is one of those odd tables that exists in every database, which might be what confused you.
With the other two accessors specify the appropriate username and password for your environment, same as you'd use for psql; there's no possible way I could tell you which ones to use.
Note that if you set a password but one isn't required because authentication is done over unix socket ident, trust, or other non-password scheme the password will be ignored.
If this doesn't cover your question, consider editing it and explaining your problem in more detail. What've you tried? What didn't work how you expected? Error messages? Qt version?

Issuing PRAGMA statement in AIR app

When I use the flash.data routines to issue a SQLite "PRAGMA encoding" statement, I get an error suggesting that this isn't supported:
'Error #3115: SQL Error.', details:'PRAGMA is not allowed in SQL.', operation:'execute', detailID:'2005
Is there a workaround?
In a word no. See for supported and unsupported features.
http://help.adobe.com/en_US/as3/dev/WSd47bd22bdd97276f1365b8c112629d7c47c-8000.html#WSd47bd22bdd97276f-5741a41a1262b2de46b-8000.
However on that page however you will see...
System table access is not available
The system tables including sqlite_master and other tables with the "sqlite_" prefix are not available in SQL statements. The runtime includes a schema API that provides an object-oriented way to access schema data. For more information see the SQLConnection.loadSchema() method.
For a more detailed help in using loadSchema have a look at,
http://gmarius.posterous.com/a-test-33
and consider using,
http://sqlitebrowser.sourceforge.net/ In fact

Resources