[DB-SIG] Some obscurity with paramstyle

Federico Di Gregorio federico.digregorio at dndg.it
Tue Jul 19 14:42:37 CEST 2011

On 19/07/11 14:18, M.-A. Lemburg wrote:
> Daniele Varrazzo wrote:
> While this is a nice system, it's also very slow. It uses function
> calls and string parsing/conversion for adapting each value. This
> works if you only have to insert/fetch a few rows, but won't be
> feasible for larger volumes.

It depends on the backend, too. Sincerely when I need to load hudreds of
thousands of rows I just avoid INSERT and go directly for mechanisms
like PostgreSQL COPY. INSERT is (usually) so slooow that the drivers
doesn't add that much overhead.

> I think we need something more low-level, which tries to
> avoid (Python) function calls if possible, e.g. it should be
> possible to write adapters in C and only point to them using
> a symbol (sketching here):
> cursor.setinputconverter(BINARY, module.BINARY_INPUT_CONVERTER)
> cursor.setoutputconverter(BINARY, module.BINARY_OUTPUT_CONVERTER)
> For mxODBC we'd then use something like this:
> # Convert Python unicode object data to SQLWCHAR data
> cursor.setinputconverter(unicode, module.SQLWCHAR_INPUT_CONVERTER)
> # Convert SQL_WCHAR type code data to Python unicode
> cursor.setoutputconverter(SQL.WCHAR, module.SQLCHAR_OUTPUT_CONVERTER_UNICODE)
> The advantage here is that the database module could work
> directly on the internal data structure to implement
> the conversion rather than having to round-trip to Python.

But the disavantage is that you can't easily work with composite types
where you need to convert the primitive types and pack them into the
composite (arrays, geographic data, ...) while adapt() is perfect for
nested types.

Anyway, happy that the discussion started :)


Federico Di Gregorio                         federico.digregorio at dndg.it
Studio Associato Di Nunzio e Di Gregorio                  http://dndg.it
 I porcellini di terra sono davvero Crostacei! Non lo sapevo!
  Certo che sono crostacei, hanno la crosta!
  Allora la pizza è un crostaceo?!               -- discorso all'ESC2k07

More information about the DB-SIG mailing list