.. currentmodule:: apsw.ext Various interesting and useful bits of functionality ==================================================== You need to import `apsw.ext` to use this module. Pretty printing --------------- :meth:`format_query_table` makes nicely formatted query output - see the :ref:`the example `. Logging and tracebacks ---------------------- You can use :meth:`log_sqlite` to forward SQLite log messages to the :mod:`logging` module. :meth:`print_augmented_traceback` prints an exception the usual way but also includes local variables, which :ref:`APSW includes ` to make debugging quicker and easier. Virtual Tables -------------- Use :meth:`index_info_to_dict` to get :class:`apsw.IndexInfo` in an easier to print and work with format. Use :meth:`make_virtual_module` to easily turn a Python function into a virtual table source. :meth:`generate_series` and :meth:`generate_series_sqlite` provide `generate_series `__. Accessing result rows by column name ------------------------------------ See :ref:`the example `. Use :class:`apsw.ext.DataClassRowFactory` as a :attr:`apsw.Connection.row_trace` for an entire connection, or :attr:`apsw.Cursor.row_trace` for a specific cursor. Converting types into and out of SQLite --------------------------------------- SQLite only stores and returns 5 types: * None * int * float * str * bytes Use :class:`TypesConverterCursorFactory` as :attr:`apsw.Connection.cursor_factory` to adapt values going into SQLite, and convert them coming out. See :ref:`the example `. To convert values going into SQLite, do either of: * Inherit from :class:`apsw.ext.SQLiteTypeAdapter` and define a *to_sqlite_value* method on the class * Call :meth:`TypesConverterCursorFactory.register_adapter` with the type and a adapter function To adapt values coming out of SQLite: * Call :meth:`TypesConverterCursorFactory.register_converter` with the exact type string in the table and a converter function Detailed Query Information -------------------------- SQLite can provide lots of information about queries. The :meth:`~apsw.ext.query_info` function can gather them up for you. This includes: * **readonly** if the query makes no direct changes * **first_query** if multiple queries are provided * **actions** which databases, tables, columns, functions, views etc are referenced - see `actions `__ * **query_plan** which indices, tables scans etc are used to find the query results - see `query plans `__ * **explain** for the low level steps taken inside SQLite - see `SQLite bytecode `__ See :ref:`the example `. API Reference ------------- .. automodule:: apsw.ext :synopsis: Various interesting and useful bits of functionality :members: :undoc-members: :member-order: bysource :special-members: __call__