diff options
author | 2011-02-09 16:41:32 +0100 | |
---|---|---|
committer | 2011-02-09 16:41:32 +0100 | |
commit | a563b3be7eb218b0b601232a3dbadd86360e2efb (patch) | |
tree | a2ebdaef5f602cfb038105d5cbc797747698cc72 /lib_pypy | |
parent | Implement collation functions in sqlite (diff) | |
download | pypy-a563b3be7eb218b0b601232a3dbadd86360e2efb.tar.gz pypy-a563b3be7eb218b0b601232a3dbadd86360e2efb.tar.bz2 pypy-a563b3be7eb218b0b601232a3dbadd86360e2efb.zip |
Implement sqlite progress handlers
Diffstat (limited to 'lib_pypy')
-rw-r--r-- | lib_pypy/_sqlite3.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py index 018b34fb34..69997c38d4 100644 --- a/lib_pypy/_sqlite3.py +++ b/lib_pypy/_sqlite3.py @@ -468,9 +468,33 @@ class Connection(object): SQLITE_UTF8, None, c_collation_callback) + if ret != SQLITE_OK: + raise self._get_exception(ret) def set_progress_handler(self, callable, nsteps): - raise NotImplementedError + self._check_thread() + self._check_closed() + if callable is None: + c_progress_handler = cast(None, PROGRESS) + else: + try: + c_progress_handler, _ = self.func_cache[callable] + except KeyError: + def progress_handler(userdata): + try: + ret = callable() + return bool(ret) + except Exception: + # abort query if error occurred + return 1 + c_progress_handler = PROGRESS(progress_handler) + + self.func_cache[callable] = c_progress_handler, progress_handler + ret = sqlite.sqlite3_progress_handler(self.db, nsteps, + c_progress_handler, + None) + if ret != SQLITE_OK: + raise self._get_exception(ret) def set_authorizer(self, callback): raise NotImplementedError @@ -1052,6 +1076,10 @@ COLLATION = CFUNCTYPE(c_int, c_void_p, c_int, c_void_p, c_int, c_void_p) sqlite.sqlite3_create_collation.argtypes = [c_void_p, c_char_p, c_int, c_void_p, COLLATION] sqlite.sqlite3_create_collation.restype = c_int +PROGRESS = CFUNCTYPE(c_int, c_void_p) +sqlite.sqlite3_progress_handler.argtypes = [c_void_p, c_int, PROGRESS, c_void_p] +sqlite.sqlite3_progress_handler.restype = c_int + converters = {} adapters = {} |