self->statement_cache->decref_factory = 0;
Py_DECREF(self);
- self->inTransaction = 0;
self->detect_types = detect_types;
self->timeout = timeout;
(void)sqlite3_busy_timeout(self->db, (int)(timeout*1000));
}
rc = pysqlite_step(statement, self);
- if (rc == SQLITE_DONE) {
- self->inTransaction = 1;
- } else {
+ if (rc != SQLITE_DONE) {
_pysqlite_seterror(self->db, statement);
}
return NULL;
}
- if (self->inTransaction) {
+ if (!sqlite3_get_autocommit(self->db)) {
Py_BEGIN_ALLOW_THREADS
rc = sqlite3_prepare(self->db, "COMMIT", -1, &statement, &tail);
}
rc = pysqlite_step(statement, self);
- if (rc == SQLITE_DONE) {
- self->inTransaction = 0;
- } else {
+ if (rc != SQLITE_DONE) {
_pysqlite_seterror(self->db, statement);
}
return NULL;
}
- if (self->inTransaction) {
+ if (!sqlite3_get_autocommit(self->db)) {
pysqlite_do_all_statements(self, ACTION_RESET, 1);
Py_BEGIN_ALLOW_THREADS
}
rc = pysqlite_step(statement, self);
- if (rc == SQLITE_DONE) {
- self->inTransaction = 0;
- } else {
+ if (rc != SQLITE_DONE) {
_pysqlite_seterror(self->db, statement);
}
}
}
+static PyObject* pysqlite_connection_get_in_transaction(pysqlite_Connection* self, void* unused)
+{
+ if (!pysqlite_check_connection(self)) {
+ return NULL;
+ }
+ if (!sqlite3_get_autocommit(self->db)) {
+ Py_RETURN_TRUE;
+ }
+ Py_RETURN_FALSE;
+}
+
static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level)
{
if (isolation_level == Py_None) {
Py_DECREF(res);
self->begin_statement = NULL;
- self->inTransaction = 0;
} else {
const char * const *candidate;
PyObject *uppercase_level;
static PyGetSetDef connection_getset[] = {
{"isolation_level", (getter)pysqlite_connection_get_isolation_level, (setter)pysqlite_connection_set_isolation_level},
{"total_changes", (getter)pysqlite_connection_get_total_changes, (setter)0},
+ {"in_transaction", (getter)pysqlite_connection_get_in_transaction, (setter)0},
{NULL}
};
{"NotSupportedError", T_OBJECT, offsetof(pysqlite_Connection, NotSupportedError), READONLY},
{"row_factory", T_OBJECT, offsetof(pysqlite_Connection, row_factory)},
{"text_factory", T_OBJECT, offsetof(pysqlite_Connection, text_factory)},
- {"in_transaction", T_BOOL, offsetof(pysqlite_Connection, inTransaction), READONLY},
{NULL}
};