SQLite PRAGMA
SQLite's PRAGMA command is a special command that can be used to control various environment variables and status flags within the SQLite environment. A PRAGMA value can be read and set as required.
Syntax
To query the current PRAGMA value, you only need to provide the name of the pragma:
To set a new value for PRAGMA, the syntax is as follows:
Set the mode, which can be a name or an equivalent integer, but The returned value will always be an integer.
auto_vacuum Pragma
auto_vacuum Pragma Gets or sets the auto-vacuum mode. The syntax is as follows:
PRAGMA [database.]auto_vacuum = mode;
Among them, mode can Is any of the following:
Pragma Value | Description |
---|---|
0 or NONE | Disable Auto-vacuum. This is the default mode, which means that the database file size will not be reduced unless the VACUUM command is used manually. |
1 or FULL | Enable Auto-vacuum, which is fully automatic. In this mode, the database file is allowed to shrink as data is removed from the database. |
2 or INCREMENTAL | Enable Auto-vacuum, but must be activated manually. In this mode, citation data is maintained and free pages are only placed in the free list. These pages can be overwritten at any time using the incremental_vacuum pragma. |
cache_size Pragma
cache_size Pragma gets or temporarily sets the maximum size of the page cache in memory. The syntax is as follows:
PRAGMA [database.]cache_size = pages;
pages The value is expressed in The number of pages in the cache. The built-in page cache has a default size of 2,000 pages and a minimum size of 10 pages.
case_sensitive_like Pragma
case_sensitive_like Pragma controls the case sensitivity of the built-in LIKE expression. By default, this Pragma is false, which means that the built-in LIKE operator ignores letter case. The syntax is as follows:
There is currently no way to query the current status of this Pragma.
count_changes Pragma
count_changes Pragma gets or sets the return value of data manipulation statements, such as INSERT, UPDATE, and DELETE. The syntax is as follows:
PRAGMA count_changes = [true|false];
By default, this Pragma is false, and these statements do not return anything thing. If set to true, each mentioned statement will return a single-row, single-column table consisting of a single integer value representing the row affected by the operation.
database_list Pragma
database_list Pragma will be used to list all database connections. The syntax is as follows:
This Pragma will return a table with a single row and three columns. Whenever the database is opened or attached, the sequence in the database will be given. number, its name and associated files.
encoding Pragma
encoding Pragma controls how strings are encoded and stored in the database file. The syntax is as follows:
PRAGMA encoding = format;
The format value can be one of UTF-8, UTF-16le or UTF-16be.
freelist_count Pragma
freelist_count Pragma returns an integer representing the number of database pages currently marked as free and available. The syntax is as follows:
The format value can be one of UTF-8, UTF-16le or UTF-16be.
index_info Pragma
index_info Pragma returns information about the database index. The syntax is as follows:
The result set will be every column contained in the index and table of the given column sequence. The columns of index and column names show a row.
index_list Pragma
index_list Pragma lists all indexes associated with the table. The syntax is as follows:
The result set will display one row for each index for a given column sequence, the index name, and an identifier indicating whether the index is unique.
journal_mode Pragma
journal_mode Pragma Gets or sets the log mode that controls how log files are stored and processed. The syntax is as follows::
PRAGMA database.journal_mode;
PRAGMA database.journal_mode = mode;
Description | |
---|---|
Default mode. In this mode, at the end of the transaction, the log file is deleted. | |
The log file is staged to zero byte length. | |
The log file is left in place, but the header is overwritten, indicating that the log is no longer valid. | |
Log records are kept in memory, not on disk. | |
No logging is maintained. |
Pragma Value | Description |
---|---|
0 or OFF | No synchronization. |
1 or NORMAL | Synchronize after each sequence of critical disk operations. |
2 or FULL | Synchronize after each critical disk operation. |
temp_store Pragma
temp_store Pragma Gets or sets the storage mode used by temporary database files. The syntax is as follows:
Description | |
---|---|
Default to use the compile-time mode. Usually FILE. | |
uses file-based storage. | |
Use memory-based storage. |