return -1;
}
Py_BEGIN_ALLOW_THREADS
+ /* No need to use sqlite3_open_v2 as sqlite3_open(filename, db) is the
+ same as sqlite3_open_v2(filename, db, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, NULL). */
rc = sqlite3_open(database, &self->db);
#endif
Py_END_ALLOW_THREADS
/* Clean up if user has not called .close() explicitly. */
if (self->db) {
Py_BEGIN_ALLOW_THREADS
- sqlite3_close(self->db);
+ SQLITE3_CLOSE(self->db);
Py_END_ALLOW_THREADS
}
if (self->db) {
Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_close(self->db);
+ rc = SQLITE3_CLOSE(self->db);
Py_END_ALLOW_THREADS
if (rc != SQLITE_OK) {
sqlite3_stmt* statement;
Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_prepare(self->db, self->begin_statement, -1, &statement, &tail);
+ rc = SQLITE3_PREPARE(self->db, self->begin_statement, -1, &statement, &tail);
Py_END_ALLOW_THREADS
if (rc != SQLITE_OK) {
if (!sqlite3_get_autocommit(self->db)) {
Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_prepare(self->db, "COMMIT", -1, &statement, &tail);
+ rc = SQLITE3_PREPARE(self->db, "COMMIT", -1, &statement, &tail);
Py_END_ALLOW_THREADS
if (rc != SQLITE_OK) {
_pysqlite_seterror(self->db, NULL);
pysqlite_do_all_statements(self, ACTION_RESET, 1);
Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_prepare(self->db, "ROLLBACK", -1, &statement, &tail);
+ rc = SQLITE3_PREPARE(self->db, "ROLLBACK", -1, &statement, &tail);
Py_END_ALLOW_THREADS
if (rc != SQLITE_OK) {
_pysqlite_seterror(self->db, NULL);
/* If it worked, let's get out of the loop */
break;
}
+#if SQLITE_VERSION_NUMBER < 3003009
/* Something went wrong. Re-set the statement and try again. */
rc = pysqlite_statement_reset(self->statement);
+#endif
if (rc == SQLITE_SCHEMA) {
/* If this was a result of the schema changing, let's try
again. */
while (1) {
Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_prepare(self->connection->db,
+ rc = SQLITE3_PREPARE(self->connection->db,
script_cstr,
-1,
&statement,
{
int errorcode;
- /* SQLite often doesn't report anything useful, unless you reset the statement first */
+#if SQLITE_VERSION_NUMBER < 3003009
+ /* SQLite often doesn't report anything useful, unless you reset the statement first.
+ When using sqlite3_prepare_v2 this is not needed. */
if (st != NULL) {
(void)sqlite3_reset(st);
}
+#endif
errorcode = sqlite3_errcode(db);
PyObject * _pysqlite_long_from_int64(sqlite_int64 value);
sqlite_int64 _pysqlite_long_as_int64(PyObject * value);
+#if SQLITE_VERSION_NUMBER >= 3003009
+#define SQLITE3_PREPARE sqlite3_prepare_v2
+#else
+#define SQLITE3_PREPARE sqlite3_prepare
+#endif
+
+#if SQLITE_VERSION_NUMBER >= 3007014
+#define SQLITE3_CLOSE sqlite3_close_v2
+#else
+#define SQLITE3_CLOSE sqlite3_close
+#endif
+
#endif