master
ygl 7 years ago
parent fb1f4098cb
commit 94da9bfd2a
  1. 25
      src/_sqlite3.py
  2. 12
      src/_sqlite3_build.py

@ -31,10 +31,11 @@ import sys
import weakref
import threading
try:
from __pypy__ import newlist_hint
from __pypy__ import newlist_hint, add_memory_pressure
except ImportError:
assert '__pypy__' not in sys.builtin_module_names
newlist_hint = lambda sizehint: []
add_memory_pressure = lambda size: None
if sys.version_info[0] >= 3:
StandardError = Exception
@ -150,10 +151,13 @@ class NotSupportedError(DatabaseError):
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)
add_memory_pressure(100 * 1024)
return res
def _unicode_text_factory(x):
@ -197,14 +201,23 @@ class Connection(object):
_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

@ -105,7 +105,12 @@ static void *const SQLITE_TRANSIENT;
#define SQLITE_DETERMINISTIC ...
#define SQLITE_PREPARE_PERSISTENT ...
static const long SQLITE_OPEN_URI;
static const long SQLITE_OPEN_READWRITE;
static const long SQLITE_OPEN_CREATE;
const char *sqlite3_libversion(void);
int sqlite3_libversion_number(void);
typedef ... sqlite3;
typedef ... sqlite3_stmt;
@ -120,6 +125,13 @@ int sqlite3_open(
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);

Loading…
Cancel
Save