chacham15
chacham15

Reputation: 14251

How do I lock a SQLite database?

I have a trigger on a table that I dont want to trigger during specific contexts.

In order to do this, I plan on:

  1. locking the database
  2. dropping the trigger
  3. performing my operations
  4. adding the trigger
  5. unlocking the database

Locking the database is necessary so that any operations that other threads attempt to perform will halt until the triggers are back in place. How do I do this from the C code?

Upvotes: 2

Views: 343

Answers (2)

CL.
CL.

Reputation: 180010

Use sqlite3_db_config() with SQLITE_DBCONFIG_ENABLE_TRIGGER to temporarily disable triggers.

Upvotes: 0

bdonlan
bdonlan

Reputation: 231063

Perform your work in a transaction by using the BEGIN TRANSACTION and COMMIT TRANSACTION SQL:

BEGIN TRANSACTION;
DROP TRIGGER dbname.triggername;
(do other stuff)
CREATE TRIGGER ...;
COMMIT TRANSACTION;

Upvotes: 2

Related Questions