简体   繁体   English

如何确保SqLite中的只读事务?

[英]How can I ensure a read-only transaction in SqLite?

I have public interface which allows people to interact with the database by typing in sql commands. 我有一个公共接口,该接口允许人们通过输入sql命令与数据库进行交互。 However, I do not want them to change the database in any way (and if possible, not access certain tables). 但是,我不希望他们以任何方式更改数据库(如果可能,不要访问某些表)。 As I understand though, SQLite has no concept of users, so how do I accomplish this? 据我了解,SQLite没有用户概念,那么如何实现呢?

如果查询中没有应用程序定义的sql函数,这些函数会间接修改数据库(例如: SELECT eval('DELETE FROM t1') FROM t2; ),则使用sqlite3_stmt_readonly来确定准备好的sql语句是否写入数据库,否则您将可以尝试打开其他read_only ,数据库连接handler(SQLITE_OPEN_READONLY)将被用于read_only访问。

Copy the "master" database file first and open that :-) No, really, this is a serious suggestion. 首先复制“ master”数据库文件,然后打开该文件:-)不,确实,这是一个严重的建议。

Otherwise, depending on how SQLite is accessed, the SQLITE_OPEN_READONLY flag that can be passed to sqlite3_open_v2 . 否则,根据访问SQLite的方式,可以将SQLITE_OPEN_READONLY标志传递给sqlite3_open_v2 This applies to the entire connection -- and all transactions on that connection. 这适用于整个连接-以及该连接上的所有事务。

Another option is to limit the SQL entry, but this is very very hard to do correctly and thus I don't recommend this route. 另一个选择是限制SQL条目,但这很难正确完成,因此我不建议您使用此路由。

Happy coding. 快乐的编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM