[DB-SIG] spec: named parameters: clarification needed

Marcos Sánchez Provencio msanchez@grupoburke.com
15 Feb 2003 13:54:23 +0100


Maybe we should have explicit different methods for each type of
parameter passing (explicit is better than implicit). Some drivers just
would raise NotImplemented if they were misused. One possible option
would be to have the user choose not to let the driver modify the string
whatsoever. And drivers should implement as many modes as they could,
having one minimum standard at least (to be truly universal, as is the
objective of the DB API, I suppose). I guess the parameterStyle setting
would be a list, then.

El vie, 14-02-2003 a las 21:18, Matthew T. Kromer escribió:
> Marcos Sánchez Provencio wrote:
> 
> >I believe DCOracle2 does. I wish it would understand ?s too.
> >
> >  
> >
> The Oracle OCI API doesn't support question mark parameter binding.  It 
> is nominally possible to use a regular expression to convert '?' 
> notation to numeric parameter binds, but I find the notion of the driver 
> munging the command string to be a frightening thing and something to be 
> avoided.
> 
> Arguably, you really want a helper method to construct parameterized SQL 
> for you, e.g.
> 
>     sql = "SELECT * FROM TEST WHERE"
>     args = DB.NewBindingArgs()
>     text, arg = DB.BindParameter("FOO", foo, type="string")
>     sql + = text
>     args = DB.MergeArgs(args, arg)
> 
> which might yield sql = "SELECT * FROM TEST WHERE FOO = :1" and args =
= 
> [foo,] for one driver which does numeric binding, and sql = "SELECT * 
> FROM TEST WHERE FOO = 'foo value'" and args = None for a driver which=
 
> doesn't do parameter binding, and sql = "SELECT * FROM TEST WHERE FOO =
= 
> :foo" and args = { 'foo': foo , } for a driver that does named binding.
> 
> Unfortunately, its awfully crufty to generate things this way -- not 
> that there aren't cases where this would be helpful.
> 
> You could probably collapse some of this down to a
> 
>     command, args = DB.ConstructBinding(oldcmd, oldargs, argname, 
> argvalue, type=type)
> 
> but...  :)
> 
> Well, I'll leave that for other people to argue.
>