With SQlite, how do you show current PRAGMA settings?
And when setting them, are they persistent, or do they need to be set with every query?
Chris
The PRAGMA statement is an SQL extension specific to SQLite and used to modify the operation of the SQLite library or to query the SQLite library for internal (non-table) data.
If you are running the sqlite3 command-line access program you can type ". tables" to get a list of all tables. Or you can type ". schema" to see the complete database schema including all tables and indices.
The table_info pragma is used to query information about a specific table. The result set will contain one row for each column in the table.
Description. The integrity_check pragma runs a self-check on the database structure. The check runs through a battery of tests that verify the integrity of the database file, its structure, and its contents. Errors are returned as text descriptions in a single-column table.
In the simplest form, current pragma settings can be obtained by simply executing an sql statement with the syntax PRAGMA <command>
. For example, when debugging in PHP using PDO, you could do something like this:
$db = new PDO("sqlite: myDb.sqlite");
$synchronous = $db->query("PRAGMA synchronous")->fetchColumn();
To set the values, use PRAGMA <command> = <value>
. There will be no return value, however (so don't bother with fetch
ing anything).
$db->query("PRAGMA synchronous = OFF");
As to the second question of whether the commands are persistent, as turlando said, there is no general answer as it is depends on which PRAGMA statement is being issued. Just check the sqlite pragma docs to be sure. And if you are uncertain, simply use the above code to check whether your settings have persisted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With