Skip to Content.
Sympa Menu

devel - Re: [sympa-developpers] SQLSource encoding

Subject: Developers of Sympa

List archive

Chronological Thread  
  • From: Guillaume Rousse <address@concealed>
  • To: address@concealed
  • Subject: Re: [sympa-developpers] SQLSource encoding
  • Date: Thu, 25 Jul 2013 17:50:56 +0200

Le 25/07/2013 17:21, David Verdin a écrit :

Le 25/07/13 16:49, Guillaume Rousse a écrit :


Everything related to parameter binding in do_query and
do_prepared_query can be discarded, those methods don't exist anymore,
and binding is now delegated to DBI internals.
As we speak about it: why not keeping a single function to do all the
query business?
We always do the same succession of calls to do a query to database. I
refactored all them in do_query and even planned to cover the final mile
by fetching data in this sub and sending the hashref or arrayref we
needed actually in the code.
Actually, they are different use case for queries:
- those returning results (SELECT queries), for which you need to iterate over a query handle
- those returning a simple execution status (ADD, UPDATE, DELETE, ALTER, CREATE queries), for which you don't need any handle

That's the global prepare()/execute() vs do() in DBI.

Moreover, there is caching issue. In order to cache anything, you need a query handle. But as caching also has a cost, you don't want to cache everything, and in particular queries you know beforehand they won't ever be executed again in the current process (ALTER and CREATE queries, notably).

So basically, you have 4 uses cases:
- cachable queries returning results: query handle needed
- cachable queries returning a simple status: query handle needed
- non-cachable queries returning results: query handle needed
- non-cachable queries returning a simple status: no handle needed

As I dislike the concept of functions with multiple kind of results, I prefered to use two distinct functions for this purposes:
- get_query_handle() takes a query string, and return the corresponding prepared query handle, caching it if needed
- execute_query() takes a query string, prepares it, executes it, and return the global execution status.

The only use case not covered here is the 3rd one: select queries you don't want to be cached. Maybe we should add a cache flag, active by default, to get_query_handle() method.

I've revisted all calls to do_query() and do_prepared_query() in the code already, and I also carefully pretty-printed SQL code.
--
Guillaume Rousse
INRIA, Direction des systèmes d'information
Domaine de Voluceau
Rocquencourt - BP 105
78153 Le Chesnay
Tel: 01 39 63 58 31

Attachment: smime.p7s
Description: Signature cryptographique S/MIME




Archive powered by MHonArc 2.6.19+.

Top of Page