[ANN] istring 1.0.1 released; announce list created

Duncan Booth duncan at NOSPAMrcp.co.uk
Wed Mar 6 09:33:07 EST 2002


Artur Skura <arturs at iidea.pl> wrote in 
news:slrna8c26g.eug.arturs at aph.waw.pdi.net:

>       Ask yourself which query is clearer:
> 
>       (1) db.query("""SELECT    foo, bar
>                       FROM      %s
>                       WHERE     rsrc_id = %s
>                       AND       name = '%s'" % (table, rsrc_id, name))
> 
>       Or:
> 
>       (2) qry = istring("""SELECT   foo, bar
>                            FROM     $table
>                            WHERE    rsrc_id = $rsrc_id
>                            AND      name = $.name""")
>           db.query(qry)
> 
I vote for (3):
  db.query("""SELECT    foo, bar
              FROM      %(table)s
              WHERE     rsrc_id = %(rsrc_id)s
              AND       name = '%(name)s'" % vars())

You have the names for interpolation, AND control over the formatting. 
Someone should dust down the time machine and implement it. Oops, they did.

Although, I sure hope there aren't any funny characters embedded in any of 
those variables that might turn the query into a DELETE...

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list