Skip to content

Commit 4b4ba4f

Browse files
author
Erlend E. Aasland
committed
Add helper to improve understanding between begin statement and isolation level
1 parent 3e924dd commit 4b4ba4f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Modules/_sqlite/connection.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,23 @@ new_statement_cache(pysqlite_Connection *self, int maxsize)
106106
return res;
107107
}
108108

109+
static inline const char *
110+
begin_stmt_to_isolation_level(const char *begin_stmt)
111+
{
112+
assert(begin_stmt != NULL);
113+
114+
// All begin statements start with "BEGIN "; add strlen("BEGIN ") to get
115+
// the isolation level.
116+
return begin_stmt + 6;
117+
}
118+
109119
static const char *
110120
get_begin_statement(const char *level)
111121
{
112122
assert(level != NULL);
113123
for (int i = 0; begin_statements[i] != NULL; i++) {
114-
const char *candidate = begin_statements[i] + 6;
124+
const char *stmt = begin_statements[i];
125+
const char *candidate = begin_stmt_to_isolation_level(stmt);
115126
if (sqlite3_stricmp(level, candidate) == 0) {
116127
return begin_statements[i];
117128
}
@@ -1322,8 +1333,9 @@ static PyObject* pysqlite_connection_get_isolation_level(pysqlite_Connection* se
13221333
return NULL;
13231334
}
13241335
if (self->begin_statement != NULL) {
1325-
// We return what's left of the statement after "BEGIN "
1326-
return PyUnicode_FromString(self->begin_statement + 6);
1336+
const char *stmt = self->begin_statement;
1337+
const char *iso_level = begin_stmt_to_isolation_level(stmt);
1338+
return PyUnicode_FromString(iso_level);
13271339
}
13281340
Py_RETURN_NONE;
13291341
}

0 commit comments

Comments
 (0)