[pypy-commit] pypy py3.3: sqlite: add connection.set_trace_callback

amauryfa pypy.commits at gmail.com
Mon Feb 1 03:57:39 EST 2016


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3.3
Changeset: r82024:f471a84da866
Date: 2016-02-01 01:03 +0100
http://bitbucket.org/pypy/pypy/changeset/f471a84da866/

Log:	sqlite: add connection.set_trace_callback

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -624,6 +624,22 @@
         _lib.sqlite3_progress_handler(self._db, nsteps, progress_handler,
                                       _ffi.NULL)
 
+    @_check_thread_wrap
+    @_check_closed_wrap
+    def set_trace_callback(self, callable):
+        if callable is None:
+            trace_callback = _ffi.NULL
+        else:
+            try:
+                trace_callback = self.__func_cache[callable]
+            except KeyError:
+                @_ffi.callback("void(void*, const char*)")
+                def trace_callback(userdata, statement):
+                    stmt = _ffi.string(statement).decode('utf-8')
+                    callable(stmt)
+                self.__func_cache[callable] = trace_callback
+        _lib.sqlite3_trace(self._db, trace_callback, _ffi.NULL)
+
     if sys.version_info[0] >= 3:
         def __get_in_transaction(self):
             return self._in_transaction
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
@@ -159,6 +159,7 @@
 const char *sqlite3_column_decltype(sqlite3_stmt*,int);
 
 void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
+void sqlite3_trace(sqlite3*, void(*)(void*, const char*), void*);
 int sqlite3_create_collation(
     sqlite3*,
     const char *zName,


More information about the pypy-commit mailing list