if (!sqlite3_get_autocommit(self->db)) {
Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_prepare_v2(self->db, "COMMIT", -1, &statement, NULL);
+ rc = sqlite3_prepare_v2(self->db, "COMMIT", 7, &statement, NULL);
Py_END_ALLOW_THREADS
if (rc != SQLITE_OK) {
_pysqlite_seterror(self->db);
pysqlite_do_all_statements(self, ACTION_RESET, 1);
Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_prepare_v2(self->db, "ROLLBACK", -1, &statement, NULL);
+ rc = sqlite3_prepare_v2(self->db, "ROLLBACK", 9, &statement, NULL);
Py_END_ALLOW_THREADS
if (rc != SQLITE_OK) {
_pysqlite_seterror(self->db);
const char* script_cstr;
sqlite3_stmt* statement;
int rc;
+ Py_ssize_t sql_len;
PyObject* result;
if (!check_cursor(self)) {
self->reset = 0;
if (PyUnicode_Check(script_obj)) {
- script_cstr = PyUnicode_AsUTF8(script_obj);
+ script_cstr = PyUnicode_AsUTF8AndSize(script_obj, &sql_len);
if (!script_cstr) {
return NULL;
}
+
+ int max_length = sqlite3_limit(self->connection->db,
+ SQLITE_LIMIT_LENGTH, -1);
+ if (sql_len >= max_length) {
+ PyErr_SetString(pysqlite_DataError, "query string is too large");
+ return NULL;
+ }
} else {
PyErr_SetString(PyExc_ValueError, "script argument must be unicode.");
return NULL;
Py_DECREF(result);
while (1) {
+ const char *tail;
+
Py_BEGIN_ALLOW_THREADS
rc = sqlite3_prepare_v2(self->connection->db,
script_cstr,
- -1,
+ (int)sql_len + 1,
&statement,
- &script_cstr);
+ &tail);
Py_END_ALLOW_THREADS
if (rc != SQLITE_OK) {
_pysqlite_seterror(self->connection->db);
goto error;
}
- if (*script_cstr == (char)0) {
+ if (*tail == (char)0) {
break;
}
+ sql_len -= (tail - script_cstr);
+ script_cstr = tail;
}
error:
Py_TYPE(sql)->tp_name);
return NULL;
}
+
+ int max_length = sqlite3_limit(connection->db, SQLITE_LIMIT_LENGTH, -1);
+ if (sql_cstr_len >= max_length) {
+ PyErr_SetString(pysqlite_DataError, "query string is too large");
+ return PYSQLITE_TOO_MUCH_SQL;
+ }
if (strlen(sql_cstr) != (size_t)sql_cstr_len) {
PyErr_SetString(PyExc_ValueError,
"the query contains a null character");
Py_BEGIN_ALLOW_THREADS
rc = sqlite3_prepare_v2(self->db,
sql_cstr,
- -1,
+ (int)sql_cstr_len + 1,
&self->st,
&tail);
Py_END_ALLOW_THREADS