Author: Richard Plangger <[email protected]>
Branch: py3.5-ssl
Changeset: r88946:c42c8db1576c
Date: 2016-12-07 16:26 +0100
http://bitbucket.org/pypy/pypy/changeset/c42c8db1576c/
Log: fix sqlite3 error, additional argument (uri) passed down to
sqlite3_open_v2
diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -149,10 +149,11 @@
def connect(database, timeout=5.0, detect_types=0, isolation_level="",
- check_same_thread=True, factory=None, cached_statements=100):
+ check_same_thread=True, factory=None, cached_statements=100,
+ uri=0):
factory = Connection if not factory else factory
return factory(database, timeout, detect_types, isolation_level,
- check_same_thread, factory, cached_statements)
+ check_same_thread, factory, cached_statements, uri)
def _unicode_text_factory(x):
@@ -195,14 +196,23 @@
_db = None
def __init__(self, database, timeout=5.0, detect_types=0,
isolation_level="",
- check_same_thread=True, factory=None, cached_statements=100):
+ check_same_thread=True, factory=None, cached_statements=100,
uri=0):
self.__initialized = True
db_star = _ffi.new('sqlite3 **')
if isinstance(database, unicode):
database = database.encode('utf-8')
- if _lib.sqlite3_open(database, db_star) != _lib.SQLITE_OK:
- raise OperationalError("Could not open database")
+ if _lib.SQLITE_OPEN_URI != 0:
+ if uri and _lib.SQLITE_OPEN_URI == 0:
+ raise NotSupportedError("URIs not supported")
+ flags = _lib.SQLITE_OPEN_READWRITE | _lib.SQLITE_OPEN_CREATE
+ if uri:
+ flags |= _lib.SQLITE_OPEN_URI
+ if _lib.sqlite3_open_v2(database, db_star, flags, _ffi.NULL) !=
_lib.SQLITE_OK:
+ raise OperationalError("Could not open database")
+ else:
+ if _lib.sqlite3_open(database, db_star) != _lib.SQLITE_OK:
+ raise OperationalError("Could not open database")
self._db = db_star[0]
if timeout is not None:
timeout = int(timeout * 1000) # pysqlite2 uses timeout in seconds
diff --git a/lib_pypy/_sqlite3_build.py b/lib_pypy/_sqlite3_build.py
--- a/lib_pypy/_sqlite3_build.py
+++ b/lib_pypy/_sqlite3_build.py
@@ -103,6 +103,10 @@
#define SQLITE_DROP_VTABLE ...
#define SQLITE_FUNCTION ...
+static const long SQLITE_OPEN_URI;
+static const long SQLITE_OPEN_READWRITE;
+static const long SQLITE_OPEN_CREATE;
+
const char *sqlite3_libversion(void);
typedef ... sqlite3;
@@ -117,6 +121,13 @@
sqlite3 **ppDb /* OUT: SQLite db handle */
);
+int sqlite3_open_v2(
+ const char *filename, /* Database filename (UTF-8) */
+ sqlite3 **ppDb, /* OUT: SQLite db handle */
+ int flags, /* Flags */
+ const char *zVfs /* Name of VFS module to use */
+);
+
int sqlite3_close(sqlite3 *);
int sqlite3_busy_timeout(sqlite3*, int ms);
@@ -259,7 +270,21 @@
libraries=['sqlite3']
)
-_ffi.set_source("_sqlite3_cffi", "#include <sqlite3.h>", **extra_args)
+SOURCE = """
+#include <sqlite3.h>
+
+#ifndef SQLITE_OPEN_URI
+static const long SQLITE_OPEN_URI = 0;
+#endif
+#ifndef SQLITE_OPEN_READWRITE
+static const long SQLITE_OPEN_READWRITE = 0;
+#endif
+#ifndef SQLITE_OPEN_CREATE
+static const long SQLITE_OPEN_CREATE = 0;
+#endif
+"""
+
+_ffi.set_source("_sqlite3_cffi", SOURCE, **extra_args)
if __name__ == "__main__":
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit