如何锁定sqlite数据库? [英] How can I lock a sqlite database?

查看:60
本文介绍了如何锁定sqlite数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们过去曾遇到过流氓进程锁定 sqlite 数据库的问题.如果发生这种情况,我已经编写了一些代码来通知我们,但需要对其进行测试.

We've had issues in the past where a rogue process was keeping a sqlite db locked. I've written some code to notify us if this is happening, but need to test it.

我怎样才能故意锁定一个sqlite数据库,以便我可以检查它是否被锁定?

How can I deliberately lock up a sqlite database, so that I can check if it's locked?

推荐答案

执行这些语句:

PRAGMA locking_mode = EXCLUSIVE;
BEGIN EXCLUSIVE;

这将锁定整个数据库,直到您执行:

This will lock whole database until you execute:

COMMIT;

为简单起见,您可以使用 sqlite3 命令行实用程序执行此操作.

For simplicity, you can do this using sqlite3 command line utility.

有关详细信息,请参阅文档.

For more info, see documentation.

这篇关于如何锁定sqlite数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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