7 |
7 |
8 return res != SQLITE_OK; |
8 return res != SQLITE_OK; |
9 } |
9 } |
10 |
10 |
11 static int commit(connection_t *conn) { |
11 static int commit(connection_t *conn) { |
12 conn->txn_in_progress = 0; |
|
13 return run(conn, "COMMIT TRANSACTION"); |
12 return run(conn, "COMMIT TRANSACTION"); |
14 } |
13 } |
15 |
14 |
16 |
15 |
17 static int begin(connection_t *conn) { |
16 static int begin(connection_t *conn) { |
18 int err = 0; |
17 int err = 0; |
19 |
18 |
20 if (conn->txn_in_progress) { |
19 if (sqlite3_get_autocommit(conn->sqlite)) { |
|
20 err = run(conn, "BEGIN TRANSACTION"); |
|
21 } else { |
21 err = 0; |
22 err = 0; |
22 } else { |
|
23 conn->txn_in_progress = 1; |
|
24 err = run(conn, "BEGIN TRANSACTION"); |
|
25 } |
23 } |
26 |
24 |
27 return err; |
25 return err; |
28 } |
26 } |
29 |
27 |
30 static int rollback(connection_t *conn) { |
28 static int rollback(connection_t *conn) { |
31 conn->txn_in_progress = 0; |
|
32 return run(conn, "ROLLBACK TRANSACTION"); |
29 return run(conn, "ROLLBACK TRANSACTION"); |
33 } |
30 } |
34 |
31 |
35 int try_begin_transaction(connection_t *conn) { |
32 int try_begin_transaction(connection_t *conn) { |
36 if (conn->autocommit) { |
33 if (conn->autocommit) { |
65 lua_pushfstring(L, DBI_ERR_CONNECTION_FAILED, sqlite3_errmsg(conn->sqlite)); |
62 lua_pushfstring(L, DBI_ERR_CONNECTION_FAILED, sqlite3_errmsg(conn->sqlite)); |
66 return 2; |
63 return 2; |
67 } |
64 } |
68 |
65 |
69 conn->autocommit = 0; |
66 conn->autocommit = 0; |
70 conn->txn_in_progress = 0; |
|
71 |
67 |
72 luaL_getmetatable(L, DBD_SQLITE_CONNECTION); |
68 luaL_getmetatable(L, DBD_SQLITE_CONNECTION); |
73 lua_setmetatable(L, -2); |
69 lua_setmetatable(L, -2); |
74 |
70 |
75 return 1; |
71 return 1; |