何时在 sqlite 上使用编译指示? [英] When to use pragmas on sqlite?

查看:36
本文介绍了何时在 sqlite 上使用编译指示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

何时使用编译指示?

第一次创建数据库时或每次连接数据库时?

When the database is created for first time or in each connection to database?

推荐答案

这取决于所使用的编译指示.来自 SQLite 权威指南数据库配置:

this depends on the pragma being used. from The definitive guide to SQLite, Database Configuration:

许多 pragma 有临时和永久两种形式.临时表单在其生命周期内仅影响当前会话.永久表单存储在数据库中并影响每个会话.

Many pragmas have both temporary and permanent forms. Temporary forms affect only the current session for the duration of its lifetime. The permanent forms are stored in the database and affect every session.

或者,用你的问题的话来说:每次连接数据库时都使用临时表单,第一次创建数据库时使用永久表单.

or, in the words of your question: Temporary forms are used in each connection to database, permanent forms are used when the database is created for the first time.

pragma 文档没有明确指定 pragma 是否临时em> 或 永久.但是,它通常会说类似

the pragma documentation doesn't explicitly specify if a pragma is temporary or permanent. however, it usually says something like

必须在创建任何表之前打开自动清空.创建表后无法启用或禁用自动清空.

auto-vacuuming must be turned on before any tables are created. It is not possible to enable or disable auto-vacuum after a table has been created.

意思是auto_vacuum是一个永久的pragma,或者

meaning auto_vacuum is a permanent pragma, or

当您使用 cache_size pragma 更改缓存大小时,更改仅对当前会话有效.

When you change the cache size using the cache_size pragma, the change only endures for the current session.

意味着 cache_size 是一个临时的.

meaning cache_size is a temporary one.

因此,回答您的问题的最佳选择是仔细阅读您的特定 pragma 的文档.或者,您可以研究pragma source code(搜索** PRAGMA [,区分大小写).

so your best bet to answer your question is to carefully read the documentation for your specific pragma. alternatively, you can study the pragma source code (search for ** PRAGMA [, case sensitive).

这篇关于何时在 sqlite 上使用编译指示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆