Explicit locking mechanism in SQLite

后端 未结 2 1120
盖世英雄少女心
盖世英雄少女心 2020-12-31 14:05

I did not find explicit sqlite locking commands before inserting or updating rows into the table. Does sqlite handle the locking mechanism on it own? The pager module descr

2条回答
  •  青春惊慌失措
    2020-12-31 14:50

    As far as I know there are no dedicated sqlite commands to control locking. However you can get sqlite to lock the database using create transaction. For instance:

    BEGIN IMMEDIATE TRANSACTION;
    ...
    COMMIT TRANSACTION;
    
    BEGIN EXCLUSIVE TRANSACTION;
    ...
    COMMIT TRANSACTION;
    

    If you read the documentation I linked you should get a better idea on the difference between IMMEDIATE & EXCLUSIVE transactions.

    It might be worth noting that the locks in sqlite apply to the whole database and not just individual tables, unlike the LOCK TABLE statement in other sql databases.

提交回复
热议问题