Ruby - SQLite3 - 从代码中设置pragma

时间:2017-08-18 07:52:39

标签: ruby sqlite

我在macos上使用Ruby SQLite3(1.13.11)(Ruby 2.0.0-p247)为我的应用程序创建了一些数据库。我需要设置一些pragma,但我不确定我做的是正确的。这就是我设置PRAGMA synchronous = OFF

的方法
db = SQLite3::Database.new("test.db")
db.synchronous
2
db.synchronous = 0
db.synchronous
0

这似乎有效,但当我使用test.db打开DB Browser for SQLite时,synchronous仍然设置为Full

我也试过

db.execute("PRAGMA synchronous = OFF")

具有相同的结果。

synchronous是否与连接相关联?这是所有PRAGMAS的情况吗?

1 个答案:

答案 0 :(得分:0)

某些 PRAGMA 与当前数据库连接相关联,因此它们不会在会话之间持久化。例如:journal_mode

有关所有 PRAGMAS 的列表,请参阅 this 链接