在SQLite中获得排他锁的功能 [英] Function to get exclusive lock in SQLite

查看:37
本文介绍了在SQLite中获得排他锁的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取SQLite数据库的排他锁.
我使用了 sqlite3_db_mutex(db); sqlite3_mutex_try(mutexObj)函数来获取锁定,但是,当我尝试从其他外壳程序向同一数据库执行查询时,我能够在表中插入行,从表中读取数据

我想要的是将LOCK锁定到数据库,以便在这段时间内,没有人可以对数据库进行任何更改,而我已经获得了该锁.Sqlite中有可能吗?

I was trying to get the exclusive lock for the SQLite database.
I used sqlite3_db_mutex(db); and sqlite3_mutex_try(mutexObj) function to acquire lock, but when I tried to execute query from other shell to the same database, I was able insert row in the table,read the data from table

I want is to get the LOCK to the database, so that during that time, no-one can make any change to the database, while I've acquired the lock. It is possible in Sqlite ????

推荐答案

sqlite3_db_mutex 锁定该连接,旨在用于使用同一连接的多个线程.

sqlite3_db_mutex locks that connection, and is intended to be used for multiple threads using the same connection.

要锁定数据库,请执行 BEGIN独家.

To lock the database, execute BEGIN EXCLUSIVE.

这篇关于在SQLite中获得排他锁的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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