Django

Code

Ticket #9633 (closed: wontfix)

Opened 8 months ago

Last modified 3 months ago

Using adaptor objects as query parameters with sqlite3

Reported by: mdh Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: 1.0 Keywords:
Cc: Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

And now for my final stumbling block within the Django core on the road to using GeoDjango with SQLite:

It is handy to be able to pass an adaptor object as a query parameter that will ultimately end up in the hands of cursor.execute(), which can convert the adaptor to a string to insert into the SQL. This is explicitly supported in (at least) the postgresql back-end, where it’s handled by UnicodeCursorWrapper.format_params(). GeoDjango currently takes advantage of this when it uses PostGISAdaptor to wrap, well, pretty much any geospatial entity en route to PostGIS.

The sqlite3 back-end could easily support something similar, but it doesn’t: if you try the corresponding trick with SQLite, you get to enjoy “InterfaceError: Error binding parameter 0 - probably unsupported type.” There may be a completely different way to address the underlying problem, which I’d certainly be very open to hearing about, but I’m personally inclined towards doing things in the corresponding ways for each back-end as much as possible, so this is the approach I’ve taken for now..

I’ve attached a fairly simple patch that takes what is clearly one of many possible similar approaches to achieving the corresponding thing for sqlite3, as well as quick test to see if your favorite back-end supports query parameter adaptors.

Attachments

9633-adaptor-query-params-sqlite3.diff (2.6 kB) - added by mdh on 11/19/08 02:01:33.
A first patch to support adaptor objects as query parameters with sqlite3
9633-adaptor-query-params-sqlite3-v2.diff (2.6 kB) - added by jbronn on 03/30/09 14:31:09.
clean up of initial patch

Change History

11/19/08 02:01:33 changed by mdh

  • attachment 9633-adaptor-query-params-sqlite3.diff added.

A first patch to support adaptor objects as query parameters with sqlite3

02/26/09 16:49:36 changed by jacob

  • needs_better_patch changed.
  • stage changed from Unreviewed to Design decision needed.
  • needs_tests changed.
  • needs_docs changed.

03/30/09 14:31:09 changed by jbronn

  • attachment 9633-adaptor-query-params-sqlite3-v2.diff added.

clean up of initial patch

03/30/09 17:25:23 changed by jbronn

  • status changed from new to closed.
  • resolution set to wontfix.

This patch was not necessary for SpatiaLite support. Just had to add a __conform__ method to the SpatiaLite adaptor.


Add/Change #9633 (Using adaptor objects as query parameters with sqlite3)




Change Properties
Action