Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With SQlite, how do you show current PRAGMA settings?

Tags:

php

sqlite

pdo

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

like image 226
Chris Denman Avatar asked Dec 24 '10 12:12

Chris Denman


People also ask

What is pragma in SQLite?

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.

How do I view SQLite schema?

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.

What is pragma table info?

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.

What is pragma integrity check?

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.


1 Answers

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 fetching 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.

like image 50
uɥƃnɐʌuop Avatar answered Sep 20 '22 23:09

uɥƃnɐʌuop