2
0

pragma.html 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html><head>
  3. <title>Pragma statements supported by SQLite</title>
  4. <style type="text/css">
  5. body {
  6. margin: auto;
  7. font-family: Verdana, sans-serif;
  8. padding: 8px 1%;
  9. }
  10. a { color: #45735f }
  11. a:visited { color: #734559 }
  12. .logo { position:absolute; margin:3px; }
  13. .tagline {
  14. float:right;
  15. text-align:right;
  16. font-style:italic;
  17. width:240px;
  18. margin:12px;
  19. margin-top:58px;
  20. }
  21. .toolbar {
  22. font-variant: small-caps;
  23. text-align: center;
  24. line-height: 1.6em;
  25. margin: 0;
  26. padding:1px 8px;
  27. }
  28. .toolbar a { color: white; text-decoration: none; padding: 6px 12px; }
  29. .toolbar a:visited { color: white; }
  30. .toolbar a:hover { color: #80a796; background: white; }
  31. .content { margin: 5%; }
  32. .content dt { font-weight:bold; }
  33. .content dd { margin-bottom: 25px; margin-left:20%; }
  34. .content ul { padding:0px; padding-left: 15px; margin:0px; }
  35. /* rounded corners */
  36. .se { background: url(images/se.png) 100% 100% no-repeat #80a796}
  37. .sw { background: url(images/sw.png) 0% 100% no-repeat }
  38. .ne { background: url(images/ne.png) 100% 0% no-repeat }
  39. .nw { background: url(images/nw.png) 0% 0% no-repeat }
  40. </style>
  41. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  42. </head>
  43. <body>
  44. <div><!-- container div to satisfy validator -->
  45. <p>The <a href="pragma.html#syntax">PRAGMA</a> statement is a special SQL statement used to
  46. modify the operation of the SQLite library or to query the library for
  47. internal (non-table) data. The <a href="pragma.html#syntax">PRAGMA</a> statement is issued using the same
  48. interface as other SQLite commands (e.g. <a href="lang_select.html">SELECT</a>, <a href="lang_insert.html">INSERT</a>) but is
  49. different in the following important respects:
  50. </p>
  51. <ul>
  52. <li>Specific pragma statements may be removed and others added in future
  53. releases of SQLite. There is no guarantee of backwards compatiblity.
  54. <li>No error messages are generated if an unknown pragma is issued.
  55. Unknown pragmas are simply ignored. This means if there is a typo in
  56. a pragma statement the library does not inform the user of the fact.
  57. <li>Some pragmas take effect during the SQL compilation stage, not the
  58. execution stage. This means if using Prepare(),
  59. NextRow(), (or similar in a wrapper
  60. interface), the pragma may run during the Prepare</a> call,
  61. not during the NextRow() call as normal SQL statements do.
  62. Or the pragma might run during NextRow() just like normal
  63. SQL statements. Whether or not the pragma runs during Prepare()
  64. or NextRow() depends on the pragma and on the specific release
  65. of SQLite.
  66. <li>The pragma command is specific to SQLite and is very unlikely
  67. to be compatible with any other SQL database engine.
  68. </ul>
  69. <p>The available pragmas fall into four basic categories:</p>
  70. <ul>
  71. <li>Pragmas used to <a href="#modify">modify the operation</a> of the
  72. SQLite library in some manner, or to query for the current mode of
  73. operation.
  74. <li>Pragmas used to <a href="#schema">query the schema</a> of the current
  75. database.
  76. <li>Pragmas used to <a href="#version">query or modify the two
  77. version counters stored in the database:</a>
  78. the schema-version and the user-version.
  79. <li>Pragmas used to <a href="#debug">debug the library</a> and verify that
  80. database files are not corrupted.
  81. </ul>
  82. <hr /><a name="syntax"></a>
  83. <h1>PRAGMA command syntax</h1>
  84. <h4><a href="syntaxdiagrams.html#pragma-stmt">pragma-stmt:</a></h4><blockquote> <img alt="syntax diagram pragma-stmt" src="images/syntax/pragma-stmt.gif"></img> </blockquote>
  85. <h4><a href="syntaxdiagrams.html#pragma-value">pragma-value:</a></h4><blockquote> <img alt="syntax diagram pragma-value" src="images/syntax/pragma-value.gif"></img> </blockquote>
  86. <p>
  87. A pragma can take either zero or one argument. The argument is may be either
  88. in parentheses or it may be separated from the pragma name by an equal sign.
  89. The two syntaxes yield identical results.
  90. In many pragmas, the argument is a boolean. The boolean can be one of:
  91. </p>
  92. <center>
  93. <b>1 yes true on<br>0 no false off</b>
  94. </center>
  95. <p>Keyword arguments can optionally appear in quotes.
  96. (Example: <tt>'yes' &#91;FALSE&#93;</tt>.) Some pragmas
  97. takes a string literal as their argument. When pragma takes a keyword
  98. argument, it will usually also take a numeric equivalent as well.
  99. For example, "0" and "no" mean the same thing, as does "1" and "yes".
  100. When querying the value of a setting, many pragmas return the number
  101. rather than the keyword.</p>
  102. <p>A pragma may have an optional database name before the pragma name.
  103. The database name is the name of an <a href="lang_attach.html">ATTACH</a>-ed database. Or it can be
  104. "main" or "temp" for the main and the TEMP databases. If the optional
  105. database name is omitted, "main" is assumed. In some pragmas, the database
  106. name is meaningless and is simply ignored.</p>
  107. <hr /><a name="modify"></a>
  108. <h1>Pragmas to modify library operation</h1>
  109. <ul>
  110. <a name="pragma_auto_vacuum"></a>
  111. <li><p><b>PRAGMA auto_vacuum;<br>
  112. PRAGMA auto_vacuum = </b>
  113. <i>0 | NONE | 1 | FULL | 2 | INCREMENTAL</i><b>;</b></p>
  114. <p>Query or set the auto-vacuum status in the database.</p>
  115. <p>The default setting for auto-vacuum is 0 or "none",
  116. unless the <a href="compile.html#default_autovacuum">SQLITE_DEFAULT_AUTOVACUUM</a> compile-time option is used.
  117. The "none" setting means that auto-vacuum is disabled.
  118. When auto-vacuum is disabled and data is deleted data from a database,
  119. the database file remains the same size. Unused database file
  120. pages are added to a "freelist" and reused for subsequent inserts. So
  121. no database file space is lost. However, the database file does not
  122. shrink. In this mode the <a href="lang_vacuum.html">VACUUM</a>
  123. command can be used to rebuild the entire database file and
  124. thus reclaim unused disk space.</p>
  125. <p>When the auto-vacuum mode is 1 or "full", the freelist pages are
  126. moved to the end of the database file and the database file is truncated
  127. to remove the freelist pages at every transaction commit.
  128. Note, however, that auto-vacuum only truncates the freelist pages
  129. from the file. Auto-vacuum does not defragment the database nor
  130. repack individual database pages the way that the
  131. <a href="lang_vacuum.html">VACUUM</a> command does. In fact, because
  132. it moves pages around within the file, auto-vacuum can actually
  133. make fragmentation worse.</p>
  134. <p>Auto-vacuuming is only possible if the database stores some
  135. additional information that allows each database page to be
  136. traced backwards to its referer. Therefore, auto-vacuuming must
  137. be turned on before any tables are created. It is not possible
  138. to enable or disable auto-vacuum after a table has been created.</p>
  139. <p>When the value of auto-vacuum is 2 or "incremental" then the additional
  140. information needed to do auto-vacuuming is stored in the database file
  141. but auto-vacuuming does not occur automatically at each commit as it
  142. does with auto_vacuum=full. In incremental mode, the separate
  143. <a href="pragma.html#pragma_incremental_vacuum">incremental_vacuum</a> pragma must
  144. be invoked to cause the auto-vacuum to occur.</p>
  145. <p>The database connection can be changed between full and incremental
  146. autovacuum mode at any time. However, the connection can only be changed
  147. "none" to "full" or "incremental" when the database is empty (no tables
  148. have yet been created) or by running the <a href="lang_vacuum.html">VACUUM</a> command. To
  149. change auto-vacuum modes, first use the auto_vacuum pragma to set
  150. the new desired mode, then invoke the <a href="lang_vacuum.html">VACUUM</a> command to
  151. reorganize the entire database file. To change from "full" or
  152. "incremental" back to "none" always requires running <a href="lang_vacuum.html">VACUUM</a> even
  153. on an empty database.
  154. </p>
  155. <p>When the auto_vacuum pragma is invoked with no arguments, it
  156. returns the current auto_vacuum mode.</p>
  157. </li>
  158. <a name="pragma_cache_size"></a>
  159. <li><p><b>PRAGMA cache_size;
  160. <br>PRAGMA cache_size = </b><i>Number-of-pages</i><b>;</b></p>
  161. <p>Query or change the suggested maximum number of database disk pages
  162. that SQLite will hold in memory at once per open database file. Whether
  163. or not this suggestion is honored is at the discretion of the
  164. Application Defined Page Cache. The default
  165. page cache implemention that is built into SQLite does honor the
  166. suggestion if it can, but alternative page caches implementations
  167. set by the application at run-time may choose to ignore this suggestion.
  168. The default suggested cache size is 2000.</p>
  169. <p>When you change the cache size using the cache_size pragma, the
  170. change only endures for the current session. The cache size reverts
  171. to the default value when the database is closed and reopened. Use
  172. the <a href="pragma.html#pragma_default_cache_size">default_cache_size</a>
  173. pragma to check the cache size permanently.</p></li>
  174. <a name="pragma_case_sensitive_like"></a>
  175. <li><p><b>PRAGMA case_sensitive_like = </b><i>boolean</i><b>;</b></p>
  176. <p>The default behavior of the <a href="lang_expr.html#like">LIKE</a> operator is to ignore case
  177. for ASCII characters. Hence, by default <b>'a' LIKE 'A'</b> is
  178. true. The case_sensitive_like pragma installs a new application-defined
  179. LIKE function that can change
  180. this behavior. When case_sensitive_like is enabled,
  181. <b>'a' LIKE 'A'</b> is false but <b>'a' LIKE 'a'</b> is still true.</p>
  182. </li>
  183. <a name="pragma_count_changes"></a>
  184. <li><p><b>PRAGMA count_changes;
  185. <br>PRAGMA count_changes = </b>boolean</i><b>;</b></p>
  186. <p>Query or change the count-changes flag. Normally, when the
  187. count-changes flag is not set, <a href="lang_insert.html">INSERT</a>, <a href="lang_update.html">UPDATE</a> and <a href="lang_delete.html">DELETE</a> statements
  188. return no data. When count-changes is set, each of these commands
  189. returns a single row of data consisting of one integer value - the
  190. number of rows inserted, modified or deleted by the command. The
  191. returned change count does not include any insertions, modifications
  192. or deletions performed by triggers, or any changes made automatically
  193. by <a href="foreignkeys.html#fk_actions">foreign key actions</a>.</p>
  194. <p>Another way to get the row change counts is to use the
  195. sqlite3_changes() or sqlite3_total_changes() interfaces.
  196. There is a subtle different, though. When an INSERT, UPDATE, or
  197. DELETE is run against a view using an <a href="lang_createtrigger.html#instead_of_trigger">INSTEAD OF trigger</a>,
  198. the count_changes pragma reports the number of rows in the view
  199. that fired the trigger, whereas sqlite3_changes() and
  200. sqlite3_total_changes() do not.</p>
  201. <a name="pragma_default_cache_size"></a>
  202. <li><p><b>PRAGMA default_cache_size;
  203. <br>PRAGMA default_cache_size = </b><i>Number-of-pages</i><b>;</b></p>
  204. <p>This pragma queries or sets the suggested maximum number of pages
  205. of disk cache that will be allocated per open database file.
  206. The difference between this pragma and <a href="pragma.html#pragma_cache_size">cache_size</a> is that the
  207. value set here persists across database connections.
  208. </p></li>
  209. <a name="pragma_empty_result_callbacks"></a>
  210. <li><p><b>PRAGMA empty_result_callbacks;
  211. <br>PRAGMA empty_result_callbacks = </b><i>boolean</i><b>;</b></p>
  212. <p>Query or change the empty-result-callbacks flag.</p>
  213. <p>The empty-result-callbacks flag affects the Execute() API only.
  214. Normally, when the empty-result-callbacks flag is cleared, the
  215. callback function supplied to the Execute() call is not invoked
  216. for commands that return zero rows of data. When empty-result-callbacks
  217. is set in this situation, the callback function is invoked exactly once,
  218. with the third parameter set to 0 (NULL). This is to enable programs
  219. that use the Execute() API to retrieve column-names even when
  220. a query returns no data.</p>
  221. <p>This pragma is legacy. It was created long ago in the early
  222. days of SQLite before the prepared statement interface was available.
  223. Do not use this pragma. It is likely to go away in a future release</p>
  224. <a name="pragma_encoding"></a>
  225. <li><p><b>PRAGMA encoding;
  226. <br>PRAGMA encoding = "UTF-8";
  227. <br>PRAGMA encoding = "UTF-16";
  228. <br>PRAGMA encoding = "UTF-16le";
  229. <br>PRAGMA encoding = "UTF-16be";</b></p>
  230. <p>In first form, if the main database has already been
  231. created, then this pragma returns the text encoding used by the
  232. main database, one of "UTF-8", "UTF-16le" (little-endian UTF-16
  233. encoding) or "UTF-16be" (big-endian UTF-16 encoding). If the main
  234. database has not already been created, then the value returned is the
  235. text encoding that will be used to create the main database, if
  236. it is created by this session.</p>
  237. <p>The second and subsequent forms of this pragma are only useful if
  238. the main database has not already been created. In this case the
  239. pragma sets the encoding that the main database will be created with if
  240. it is created by this session. The string "UTF-16" is interpreted
  241. as "UTF-16 encoding using native machine byte-ordering". If the second
  242. and subsequent forms are used after the database file has already
  243. been created, they have no effect and are silently ignored.</p>
  244. <p>Once an encoding has been set for a database, it cannot be changed.</p>
  245. <p>Databases created by the <a href="lang_attach.html">ATTACH</a> command always use the same encoding
  246. as the main database.</p>
  247. </li>
  248. <a name="pragma_foreign_keys"></a>
  249. <li><p><b>PRAGMA foreign_keys;
  250. <br>PRAGMA foreign_keys = </b><i>boolean</i><b>;</b></p>
  251. <p>Query, set, or clear the enforcement of <a href="foreignkeys.html">foreign key constraints</a>.
  252. <p>Changing this setting affects the execution of all statements prepared
  253. using the database connection, including those prepared before the
  254. setting was changed. Any existing statements prepared using the legacy
  255. Prepare() interface may fail with an SQLITE_SCHEMA error
  256. after this setting is changed.
  257. <p>As of SQLite version 3.6.19, the default setting for foreign
  258. key enforcement is OFF. However, that might change in a future
  259. release of SQLite. To minimize future problems, applications should
  260. set the foreign key enforcement flag as required by the application
  261. and not depend on the default setting.
  262. </li>
  263. <a name="pragma_full_column_names"></a>
  264. <li><p><b>PRAGMA full_column_names;
  265. <br>PRAGMA full_column_names = </b><i>boolean</i><b>;</b></p>
  266. <p>Query or change the full_column_names flag. This flag together
  267. with the <a href="pragma.html#pragma_short_column_names">short_column_names</a> flag determine
  268. the way SQLite assigns names to results returned by <a href="lang_select.html">SELECT</a> statements.
  269. Result columns are named by applying the following rules in order:
  270. <ol>
  271. <li><p>If there is an AS clause on the result, then the name of
  272. the column is the right-hand side of the AS clause.</p></li>
  273. <li><p>If the result is a general expression, not a just the name of
  274. a source table column,
  275. then the name of the result is a copy of the expression text.</p></li>
  276. <li><p>If the <a href="pragma.html#pragma_short_column_names">short_column_names</a> pragma is ON, then the name of the
  277. result is the name of the source table column without the
  278. source table name prefix: COLUMN.</p></li>
  279. <li><p>If both pragmas <a href="pragma.html#pragma_short_column_names">short_column_names</a> and <a href="pragma.html#pragma_full_column_names">full_column_names</a>
  280. are OFF then case (2) applies.
  281. </p></li>
  282. <li><p>The name of the result column is a combination of the source table
  283. and source column name: TABLE.COLUMN</p></li>
  284. </ol>
  285. </li>
  286. <a name="pragma_fullfsync"></a>
  287. <li><p><b>PRAGMA fullfsync
  288. <br>PRAGMA fullfsync = </b><i>boolean</i><b>;</b></p>
  289. <p>Query or change the fullfsync flag. This flag affects
  290. determines whether or not the F_FULLFSYNC syncing method is used
  291. on systems that support it. The default value is off. As of this
  292. writing (2006-02-10) only Mac OS X supports F_FULLFSYNC.
  293. </p>
  294. </li>
  295. <a name="pragma_incremental_vacuum"></a>
  296. <li><p><b>PRAGMA incremental_vacuum</b><i>(N)</i><b>;</b></p>
  297. <p>The incremental_vacuum pragma causes up to <i>N</i> pages to
  298. be removed from the freelist. The database file is truncated by
  299. the same amount. The incremental_vacuum pragma has no effect if
  300. the database is not in
  301. <a href="#pragma_auto_vacuum">auto_vacuum==incremental</a> mode
  302. or if there are no pages on the freelist. If there are fewer than
  303. <i>N</i> pages on the freelist, or if <i>N</i> is less than 1, or
  304. if <i>N</i> is omitted entirely, then the entire freelist is cleared.</p>
  305. <p>As of version 3.4.0 (the first version that supports
  306. incremental_vacuum) this feature is still experimental. Possible
  307. future changes include enhancing incremental vacuum to do
  308. defragmentation and node repacking just as the full-blown
  309. <a href="lang_vacuum.html">VACUUM</a> command does. And
  310. incremental vacuum may be promoted from a pragma to a separate
  311. SQL command, or perhaps some variation on the <a href="lang_vacuum.html">VACUUM</a> command.
  312. Programmers are cautioned to not become enamored with the
  313. current syntax or functionality as it is likely to change.</p>
  314. </li>
  315. <a name="pragma_journal_mode"></a>
  316. <li><p><b>PRAGMA journal_mode;
  317. <br>PRAGMA </b><i>database</i><b>.journal_mode;
  318. <br>PRAGMA journal_mode
  319. = <i>DELETE | TRUNCATE | PERSIST | MEMORY | OFF</i>
  320. <br>PRAGMA </b><i>database</i><b>.journal_mode
  321. = <i>DELETE | TRUNCATE | PERSIST | MEMORY | OFF</i></b></p>
  322. <p>This pragma queries or sets the journal mode for databases
  323. associated with the current database connection.</p>
  324. <p>The first two forms of this pragma query the current journaling
  325. mode. In the first form, the default journal_mode is returned.
  326. The default journaling mode is the mode used by databases added
  327. to the connection by subsequent <a href="lang_attach.html">ATTACH</a> statements. The second
  328. form returns the current journaling mode for a specific database.</p>
  329. <p>The last two forms change the journaling mode. The 4th form
  330. changes the journaling mode for a specific database connection.
  331. Use "main" for the main database (the database that was opened by
  332. the original sqlite3_open(), sqlite3_open16(), or
  333. sqlite3_open_v2() interface call) and use "temp" for database
  334. that holds TEMP tables. The 3rd form changes the journaling mode
  335. on all databases and it changes the default journaling mode that
  336. will be used for new databases added by subsequent <a href="lang_attach.html">ATTACH</a>
  337. commands. The new journal mode is returned. If the journal mode
  338. could not be changed, the original journal mode is returned.</p>
  339. <p>The DELETE journaling mode is the normal behavior. In the DELETE
  340. mode, the rollback journal is deleted at the conclusion of each
  341. transaction. Indeed, the delete operation is the action that causes
  342. the transaction to commit.
  343. (See the documented titled
  344. Atomic Commit In SQLite for additional detail.)</p>
  345. <p>The TRUNCATE journaling mode commits transactions by truncating
  346. the rollback journal to zero-length instead of deleting it. On many
  347. systems, truncating a file is much faster than deleting the file since
  348. the containing directory does not need to be changed.</p>
  349. <p>The PERSIST journaling mode prevents the rollback journal from
  350. being deleted at the end of each transaction. Instead, the header
  351. of the journal is overwritten with zeros. This will prevent other
  352. database connections from rolling the journal back. The PERSIST
  353. journaling mode is useful as an optimization on platforms where
  354. deleting or truncating a file is much more expensive than overwriting
  355. the first block of a file with zeros.</p>
  356. <p>The MEMORY journaling mode stores the rollback journal in
  357. volatile RAM. This saves disk I/O but that the expense of database
  358. safety and integrity. If the application using SQLite crashes in
  359. the middle of a transaction when the MEMORY journaling mode is set,
  360. then the database file will very likely go corrupt.</p>
  361. <p>The OFF journaling mode disables the rollback journal completely.
  362. No rollback journal is ever created and hence there is never a rollback
  363. journal to delete. The OFF journaling mode disables the atomic
  364. commit and rollback capabilities of SQLite. The <a href="lang_transaction.html">ROLLBACK</a> command
  365. no longer works; it behaves in an undefined way. Applications must
  366. avoid using the <a href="lang_transaction.html">ROLLBACK</a> command when the journal mode is OFF.
  367. If the application crashes
  368. in the middle of a transaction when the OFF journaling mode is
  369. set, then the database file will very likely go corrupt.</p>
  370. <p>Note that the journal_mode for an <a href="inmemorydb.html">in-memory database</a>
  371. is either MEMORY or OFF and can not be changed to a different value.
  372. An attempt to change the journal_mode of an <a href="inmemorydb.html">in-memory database</a> to
  373. any setting other than MEMORY or OFF is ignored. Note also that
  374. the journal_mode cannot be changed while a transaction is active.</p>
  375. </li>
  376. <a name="pragma_journal_size_limit"></a>
  377. <li><p><b>
  378. PRAGMA journal_size_limit<br>
  379. PRAGMA journal_size_limit = </b><i>N</i> <b>;</b>
  380. <p>If a database connection is operating in either "exclusive mode"
  381. (PRAGMA locking_mode=exclusive) or "persistent journal mode"
  382. (PRAGMA journal_mode=persist) then under certain circumstances
  383. after committing a transaction the journal file may remain in
  384. the file-system. This increases efficiency but also consumes
  385. space in the file-system. After a large transaction (e.g. a VACUUM),
  386. it may consume a very large amount of space.
  387. <p>This pragma may be used to limit the size of journal files left
  388. in the file-system after transactions are committed on a per database
  389. basis. Each time a transaction is committed, SQLite compares the
  390. size of the journal file left in the file-system to the size limit
  391. configured using this pragma. If the journal file is larger than the
  392. limit allows for, it is truncated to the limit.
  393. <p>The second form of the pragma listed above is used to set a new limit
  394. in bytes for the specified database. A negative number implies no limit.
  395. Both the first and second forms of the pragma listed above return a single
  396. result row containing a single integer column - the value of the journal
  397. size limit in bytes. The default limit value is -1 (no limit), which
  398. may be overridden by defining the preprocessor macro
  399. SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT at compile time.
  400. <p>This pragma only operates on the single database specified prior
  401. to the pragma name (or on the "main" database if no database is specified.)
  402. There is no way to operate on all attached databases using a single
  403. PRAGMA statement, nor is there a way to set the limit to use for databases
  404. that will be attached in the future.
  405. </li>
  406. <a name="pragma_legacy_file_format"></a>
  407. <li><p><b>PRAGMA legacy_file_format;
  408. <br>PRAGMA legacy_file_format = <i>boolean</i></b></p>
  409. <p>This pragma sets or queries the value of the legacy_file_format
  410. flag. When this flag is on, new SQLite databases are created in
  411. a file format that is readable and writable by all versions of
  412. SQLite going back to 3.0.0. When the flag is off, new databases
  413. are created using the latest file format which might not be
  414. readable or writable by versions of SQLite prior to 3.3.0.</p>
  415. <p>When the pragma is issued with no argument, it returns the
  416. setting of the flag. This pragma does <u>not</u> tell which
  417. file format the current database is using. It tells what format
  418. will be used by any newly created databases.</p>
  419. <p>This flag only affects newly created databases. It has no
  420. effect on databases that already exist.</p>
  421. <p>The default file format is set by the
  422. SQLITE_DEFAULT_FILE_FORMAT compile-time option.</p>
  423. </li>
  424. <a name="pragma_locking_mode"></a>
  425. <li><p><b>PRAGMA locking_mode;
  426. <br>PRAGMA locking_mode = <i>NORMAL | EXCLUSIVE</i></b></p>
  427. <p>This pragma sets or queries the database connection locking-mode.
  428. The locking-mode is either NORMAL or EXCLUSIVE.
  429. <p>In NORMAL locking-mode (the default), a database connection
  430. unlocks the database file at the conclusion of each read or
  431. write transaction. When the locking-mode is set to EXCLUSIVE, the
  432. database connection never releases file-locks. The first time the
  433. database is read in EXCLUSIVE mode, a shared lock is obtained and
  434. held. The first time the database is written, an exclusive lock is
  435. obtained and held.</p>
  436. <p>Database locks obtained by a connection in EXCLUSIVE mode may be
  437. released either by closing the database connection, or by setting the
  438. locking-mode back to NORMAL using this pragma and then accessing the
  439. database file (for read or write). Simply setting the locking-mode to
  440. NORMAL is not enough - locks are not be released until the next time
  441. the database file is accessed.</p>
  442. <p>There are two reasons to set the locking-mode to EXCLUSIVE. One
  443. is if the application actually wants to prevent other processes from
  444. accessing the database file. The other is that a small number of
  445. filesystem operations are saved by optimizations enabled in this
  446. mode. This may be significant in embedded environments.</p>
  447. <p>When the locking_mode pragma specifies a particular database,
  448. for example:</p>
  449. <blockquote>
  450. PRAGMA <b>main.</b>locking_mode=EXCLUSIVE;
  451. </blockquote>
  452. <p>Then the locking mode applies only to the named database. If no
  453. database name qualifier precedes the "locking_mode" keyword then
  454. the locking mode is applied to all databases, including any new
  455. databases added by subsequent <a href="lang_attach.html">ATTACH</a> commands.</p>
  456. <p>The "temp" database (in which TEMP tables and indices are stored)
  457. always uses exclusive locking mode. The locking mode of temp cannot
  458. be changed. All other databases use the normal locking mode by default
  459. and are affected by this pragma.</p>
  460. </li>
  461. <a name="pragma_page_size"></a>
  462. <li><p><b>PRAGMA page_size;
  463. <br>PRAGMA page_size = </b><i>bytes</i><b>;</b></p>
  464. <p>Query or set the page size of the database. The page size
  465. may only be set if the database has not yet been created. The page
  466. size must be a power of two greater than or equal to 512 and less
  467. than or equal to SQLITE_MAX_PAGE_SIZE.
  468. The maximum value for SQLITE_MAX_PAGE_SIZE is 32768.
  469. </p>
  470. <p>When a new database is created, SQLite assigned a default page size
  471. based on information received from the xSectorSize and
  472. xDeviceCharacteristics methods of the sqlite3_io_methods object
  473. of the newly created database file. The page_size pragma will only
  474. cause an immediate change in the
  475. page size if it is issued while the database is still empty, prior
  476. to the first CREATE TABLE statement. As of version 3.5.8, if
  477. the page_size pragma is used to specify a new page size just prior to
  478. running the <a href="lang_vacuum.html">VACUUM</a> command then <a href="lang_vacuum.html">VACUUM</a> will change the page
  479. size to the new value.</p>
  480. <p>If SQLite is compiled with the SQLITE_ENABLE_ATOMIC_WRITE option,
  481. then the default page size is chosen to be the largest page size
  482. less than or equal to SQLITE_MAX_DEFAULT_PAGE_SIZE for which atomic
  483. write is enabled according to the
  484. xDeviceCharacteristics method of the sqlite3_io_methods object for
  485. the database file. If the SQLITE_ENABLE_ATOMIC_WRITE option is
  486. disabled or if xDeviceCharacteristics reports no suitable atomic
  487. write page sizes, then the default page size is the larger of
  488. SQLITE_DEFALT_PAGE_SIZE
  489. and the sector size as reported by the xSectorSize method of the
  490. sqlite3_io_methods object, but not more than
  491. SQLITE_MAX_DEFAULT_PAGE_SIZE. The normal configuration for SQLite
  492. running on workstations is for atomic write to be
  493. disabled, for the maximum page size to be set to 32768, for
  494. SQLITE_DEFAULT_PAGE_SIZE to be 1024, and for the
  495. maximum default page size to be set to 8192. The default xSectorSize
  496. method on workstation implementations always reports a sector size
  497. of 512 bytes. Hence,
  498. the default page size chosen by SQLite is usually 1024 bytes.</p>
  499. </li>
  500. <a name="pragma_max_page_count"></a>
  501. <li><p><b>PRAGMA max_page_count;
  502. <br>PRAGMA max_page_count = </b><i>N</i><b>;</b></p>
  503. <p>Query or set the maximum number of pages in the database file.
  504. Both forms of the pragma return the maximum page count. The second
  505. form attempts to modify the maximum page count. The maximum page
  506. count cannot be reduced below the current database size.
  507. </p>
  508. </li>
  509. <a name="pragma_read_uncommitted"></a>
  510. <li><p><b>PRAGMA read_uncommitted;
  511. <br>PRAGMA read_uncommitted = </b><i>boolean</i><b>;</b></p>
  512. <p>Query, set, or clear READ UNCOMMITTED isolation. The default isolation
  513. level for SQLite is SERIALIZABLE. Any process or thread can select
  514. READ UNCOMMITTED isolation, but SERIALIZABLE will still be used except
  515. between connections that share a common page and schema cache.
  516. Cache sharing is enabled using the sqlite3_enable_shared_cache() API.
  517. Cache sharing is disabled by default.
  518. </p>
  519. <p>See SQLite Shared-Cache Mode for additional information.</p>
  520. </li>
  521. <a name="pragma_reverse_unordered_selects"></a>
  522. <li><p><b>PRAGMA reverse_unordered_selects;
  523. <br>PRAGMA reverse_unordered_selects = </b><i>boolean</i><b>;</b></p>
  524. <p>When enabled, this PRAGMA causes <a href="lang_select.html">SELECT</a> statements without a
  525. an ORDER BY clause to emit their results in the reverse order of what
  526. they normally would. This can help debug applications that are
  527. making invalid assumptions about the result order.<p>SQLite makes no
  528. guarantees about the order of results if a SELECT omits the ORDER BY
  529. clause. Even so, the order of results does not change from one
  530. run to the next, and so many applications mistakenly come to depend
  531. on the arbitrary output order whatever that order happens to be. However,
  532. sometimes new versions of SQLite will contain optimizer enhancements
  533. that will cause the output order of queries without ORDER BY clauses
  534. to shift. When that happens, applications that depend on a certain
  535. output order might malfunction. By running the application multiple
  536. times with this pragma both disabled and enabled, cases where the
  537. application makes faulty assumptions about output order can be
  538. identified and fixed early, reducing problems
  539. that might be caused by linking against a different version of SQLite.
  540. </p>
  541. </li>
  542. <a name="pragma_short_column_names"></a>
  543. <li><p><b>PRAGMA short_column_names;
  544. <br>PRAGMA short_column_names = </b><i>boolean</i><b>;</b></p>
  545. <p>Query or change the short-column-names flag. This flag affects
  546. the way SQLite names columns of data returned by <a href="lang_select.html">SELECT</a> statements.
  547. See the <a href="pragma.html#pragma_full_column_names">full_column_names</a> pragma for full details.
  548. </p>
  549. </li>
  550. <a name="pragma_synchronous"></a>
  551. <li><p><b>PRAGMA synchronous;
  552. <br>PRAGMA synchronous = </b>
  553. <i>0 | OFF | 1 | NORMAL | 2 | FULL</i><b>;</b></p>
  554. <p>Query or change the setting of the "synchronous" flag.
  555. The first (query) form will return the setting as an
  556. integer. When synchronous is FULL (2), the SQLite database engine will
  557. pause at critical moments to make sure that data has actually been
  558. written to the disk surface before continuing. This ensures that if
  559. the operating system crashes or if there is a power failure, the database
  560. will be uncorrupted after rebooting. FULL synchronous is very
  561. safe, but it is also slower.
  562. When synchronous is NORMAL, the SQLite database
  563. engine will still pause at the most critical moments, but less often
  564. than in FULL mode. There is a very small (though non-zero) chance that
  565. a power failure at just the wrong time could corrupt the database in
  566. NORMAL mode. But in practice, you are more likely to suffer
  567. a catastrophic disk failure or some other unrecoverable hardware
  568. fault.
  569. With synchronous OFF (0), SQLite continues without pausing
  570. as soon as it has handed data off to the operating system.
  571. If the application running SQLite crashes, the data will be safe, but
  572. the database might become corrupted if the operating system
  573. crashes or the computer loses power before that data has been written
  574. to the disk surface. On the other hand, some
  575. operations are as much as 50 or more times faster with synchronous OFF.
  576. </p>
  577. <p>The default setting is synchronous=FULL.
  578. </p>
  579. </li>
  580. <a name="pragma_temp_store"></a>
  581. <li><p><b>PRAGMA temp_store;
  582. <br>PRAGMA temp_store = </b>
  583. <i>0 | DEFAULT | 1 | FILE | 2 | MEMORY</i><b>;</b></p>
  584. <p>Query or change the setting of the "<b>temp_store</b>" parameter.
  585. When temp_store is DEFAULT (0), the compile-time C preprocessor macro
  586. SQLITE_TEMP_STORE is used to determine where temporary tables and indices
  587. are stored. When
  588. temp_store is MEMORY (2) <a href="inmemorydb.html#temp_db">temporary tables</a> and indices are kept in
  589. as if they were pure <a href="inmemorydb.html">in-memory databases</a> memory.
  590. When temp_store is FILE (1) <a href="inmemorydb.html#temp_db">temporary tables</a> and indices are stored
  591. in a file. The <a href="pragma.html#pragma_temp_store_directory">temp_store_directory</a> pragma can be used to specify
  592. the directory containing temporary files when
  593. <b>FILE</b> is specified. When the temp_store setting is changed,
  594. all existing temporary tables, indices, triggers, and views are
  595. immediately deleted.</p>
  596. <p>It is possible for the library compile-time C preprocessor symbol
  597. SQLITE_TEMP_STORE to override this pragma setting.
  598. The following table summarizes
  599. the interaction of the SQLITE_TEMP_STORE preprocessor macro and the
  600. temp_store pragma:</p>
  601. <blockquote>
  602. <table cellpadding="2" border="1">
  603. <tr><th valign="bottom"><a href="compile.html#temp_store">SQLITE_TEMP_STORE</a></th>
  604. <th valign="bottom">PRAGMA<br>temp_store</th>
  605. <th>Storage used for<br>TEMP tables and indices</th></tr>
  606. <tr><td align="center">0</td>
  607. <td align="center"><em>any</em></td>
  608. <td align="center">file</td></tr>
  609. <tr><td align="center">1</td>
  610. <td align="center">0</td>
  611. <td align="center">file</td></tr>
  612. <tr><td align="center">1</td>
  613. <td align="center">1</td>
  614. <td align="center">file</td></tr>
  615. <tr><td align="center">1</td>
  616. <td align="center">2</td>
  617. <td align="center">memory</td></tr>
  618. <tr><td align="center">2</td>
  619. <td align="center">0</td>
  620. <td align="center">memory</td></tr>
  621. <tr><td align="center">2</td>
  622. <td align="center">1</td>
  623. <td align="center">file</td></tr>
  624. <tr><td align="center">2</td>
  625. <td align="center">2</td>
  626. <td align="center">memory</td></tr>
  627. <tr><td align="center">3</td>
  628. <td align="center"><em>any</em></td>
  629. <td align="center">memory</td></tr>
  630. </table>
  631. </blockquote>
  632. </li>
  633. <br>
  634. <a name="pragma_temp_store_directory"></a>
  635. <li><p><b>PRAGMA temp_store_directory;
  636. <br>PRAGMA temp_store_directory = '</b><i>directory-name</i><b>';</b></p>
  637. <p>Query or change the setting of the "temp_store_directory" - the
  638. directory where files used for storing <a href="inmemorydb.html#temp_db">temporary tables</a> and indices
  639. are kept.</p>
  640. <p>When the temp_store_directory setting is changed, all existing temporary
  641. tables, indices, triggers, and viewers are immediately deleted. In
  642. practice, temp_store_directory should be set immediately after the
  643. database is opened.</p>
  644. <p>Changing the temp_store_directory setting is <u>not</u> threadsafe.
  645. Never change the temp_store_directory setting if another thread
  646. within the application is running any SQLite interface at the same time.
  647. Doing so results in undefined behavior. Changing the temp_store_directory
  648. setting writes to the sqlite3_temp_directory global
  649. variable and that global variable is not protected by a mutex.</p>
  650. <p>The value <i>directory-name</i> should be enclosed in single quotes.
  651. To revert the directory to the default, set the <i>directory-name</i> to
  652. an empty string, e.g., <i>PRAGMA temp_store_directory = ''</i>. An
  653. error is raised if <i>directory-name</i> is not found or is not
  654. writable. </p>
  655. <p>The default directory for temporary files depends on the OS. Some
  656. OS interfaces may choose to ignore this variable in place temporary
  657. files in some other directory different from the directory specified
  658. here. In that sense, this pragma is only advisory.</p>
  659. </li>
  660. </ul>
  661. <hr /><a name="schema"></a>
  662. <h1>Pragmas to query the database schema</h1>
  663. <ul>
  664. <a name="pragma_collation_list"></a>
  665. <li><p><b>PRAGMA collation_list;</b></p>
  666. <p>Return a list of the collating sequences defined for the current
  667. database connection.</p></li>
  668. <a name="pragma_database_list"></a>
  669. <li><p><b>PRAGMA database_list;</b></p>
  670. <p>For each open database, invoke the callback function once with
  671. information about that database. Arguments include the index and
  672. the name the database was attached with. The first row will be for
  673. the main database. The second row will be for the database used to
  674. store temporary tables.</p></li>
  675. <a name="pragma_foreign_key_list"></a>
  676. <li><p><b>PRAGMA foreign_key_list(</b><i>table-name</i><b>);</b></p>
  677. <p>For each foreign key that references a column in the argument
  678. table, invoke the callback function with information about that
  679. foreign key. The callback function will be invoked once for each
  680. column in each foreign key.</p></li>
  681. <a name="pragma_freelist_count"></a>
  682. <li><p><b>PRAGMA freelist_count;</b></p>
  683. <p>Return the number of unused pages in the database file. Running
  684. a <a href="#pragma_incremental_vacuum">"PRAGMA incremental_vaccum(N);"</a>
  685. command with a large value of N will shrink the database file by this
  686. number of pages. </p></li>
  687. <a name="pragma_index_info"></a>
  688. <li><p><b>PRAGMA index_info(</b><i>index-name</i><b>);</b></p>
  689. <p>For each column that the named index references, invoke the
  690. callback function
  691. once with information about that column, including the column name,
  692. and the column number.</p></li>
  693. <a name="pragma_index_list"></a>
  694. <li><p><b>PRAGMA index_list(</b><i>table-name</i><b>);</b></p>
  695. <p>For each index on the named table, invoke the callback function
  696. once with information about that index. Arguments include the
  697. index name and a flag to indicate whether or not the index must be
  698. unique.</p></li>
  699. <a name="pragma_page_count"></a>
  700. <li><p><b>PRAGMA page_count;</b></p>
  701. <p>Return the total number of pages in the database file.</p></li>
  702. <a name="pragma_table_info"></a>
  703. <li><p><b>PRAGMA table_info(</b><i>table-name</i><b>);</b></p>
  704. <p>For each column in the named table, invoke the callback function
  705. once with information about that column, including the column name,
  706. data type, whether or not the column can be NULL, and the default
  707. value for the column.</p></li>
  708. </ul>
  709. <hr /><a name="version"></a>
  710. <h1>Pragmas to query/modify version values</h1>
  711. <ul>
  712. <a name="pragma_schema_version"></a>
  713. <li><p><b>PRAGMA schema_version;
  714. <br>PRAGMA schema_version = </b><i>integer </i><b>;
  715. <br>PRAGMA user_version;
  716. <br>PRAGMA user_version = </b><i>integer </i><b>;</b>
  717. <p> The pragmas schema_version and user_version are used to set or get
  718. the value of the schema-version and user-version, respectively. Both
  719. the schema-version and the user-version are 32-bit signed integers
  720. stored in the database header.</p>
  721. <p> The schema-version is usually only manipulated internally by SQLite.
  722. It is incremented by SQLite whenever the database schema is modified
  723. (by creating or dropping a table or index). The schema version is
  724. used by SQLite each time a query is executed to ensure that the
  725. internal cache of the schema used when compiling the SQL query matches
  726. the schema of the database against which the compiled query is actually
  727. executed. Subverting this mechanism by using "PRAGMA schema_version"
  728. to modify the schema-version is potentially dangerous and may lead
  729. to program crashes or database corruption. Use with caution!</p>
  730. <p> The user-version is not used internally by SQLite. It may be used by
  731. applications for any purpose.</p>
  732. </li>
  733. </ul>
  734. <hr /><a name="debug"></a>
  735. <h1>Pragmas to debug the library</h1>
  736. <ul>
  737. <a name="pragma_integrity_check"></a>
  738. <li><p><b>PRAGMA integrity_check;
  739. <br>PRAGMA integrity_check(</b><i>integer</i><b>)</b></p>
  740. <p>This pragma does an integrity check of the entire database. It
  741. looks for out-of-order records, missing pages, malformed records, and
  742. corrupt indices.
  743. If any problems are found, then strings are returned (as multiple
  744. rows with a single column per row) which describe
  745. the problems. At most <i>integer</i> errors will be reported
  746. before the analysis quits. The default value for <i>integer</i>
  747. is 100. If no errors are found, a single row with the value "ok" is
  748. returned.</p></li>
  749. <a name="pragma_quick_check"></a>
  750. <li><p><b>PRAGMA quick_check;
  751. <br>PRAGMA quick_check(</b><i>integer</i><b>)</b></p>
  752. <p>The pragma is like <a href="pragma.html#pragma_integrity_check">integrity_check</a> except that it does not verify
  753. that index content matches table content. By skipping the verification
  754. of index content, quick_check is able to run much faster than
  755. integrity_check. Otherwise the two pragmas are the same.
  756. </p></li>
  757. <a name="pragma_parser_trace"></a>
  758. <li><p><b>PRAGMA parser_trace = </b><i>boolean</i><b>; </b></p>
  759. <p>Turn tracing of the SQL parser inside of the
  760. SQLite library on and off. This is used for debugging.
  761. This only works if the library is compiled with the SQLITE_DEBUG
  762. compile-time option.
  763. </p></li>
  764. <a name="pragma_vdbe_trace"></a>
  765. <li><p><b>PRAGMA vdbe_trace = </b><i>boolean</i><b>;</b></p>
  766. <p>Turn tracing of the virtual database engine inside of the
  767. SQLite library on and off. This is used for debugging. See the
  768. VDBE documentation for more
  769. information.</p></li>
  770. <a name="pragma_vdbe_listing"></a>
  771. <li><p><b>PRAGMA vdbe_listing = </b><i>boolean</i><b>;</b></p>
  772. <p>Turn listings of virtual machine programs on and off.
  773. With listing is on, the entire content of a program is printed
  774. just prior to beginning execution. The statement
  775. executes normally after the listing is printed.
  776. This is used for debugging. See the
  777. VDBE documentation for more
  778. information.</p></li>
  779. </ul>