rogerbinns / apsw

Another Python SQLite wrapper
https://rogerbinns.github.io/apsw/
Other
733 stars 97 forks source link

Enhancements to apsw.ext #493

Closed scarlock closed 10 months ago

scarlock commented 10 months ago

Please consider the following enhancements.

  1. Allow apsw.ext.format_query_table to work with either connections or cursors.
  2. Allow apsw.ext.log_sqlite to optionally specify the logger instance to use instead of the root logger.
  3. Allow apswext.print_augmented_traceback to use a logger instead of/in addition to a file.

Thanks

rogerbinns commented 10 months ago
  1. It has to work with a connection in order to get column names via a new cursor tracer. I did notice you using cursors a lot in https://github.com/rogerbinns/apsw/discussions/492 even though they aren't necessary. What is special about the cursors you want to supply?
  2. Will do.
  3. Won't do. Have a look at the implementation - it is 3 lines printing traceback.TracebackException.format and Python 3.11 has a print method making this one line. You should be able to roll your own meeting your exact needs.
scarlock commented 10 months ago
  1. Makes sense. Using cursors is an old habit from other database environments that are (thankfully) lost to the ages. I should probably break that habit.
  2. Thanks.
  3. No worries. Already rolled my own, just figured it would be a nice addition.
        traceback = io.StringIO()
        apsw.ext.print_augmented_traceback(*sys.exc_info(), file=traceback)
        logging.error(traceback.getvalue())