Eric Day wrote:
> Hi!
>
> We've decided to add the prepared statement API sooner than later,
> and I've been looking into various ways of mapping variables in. There
> are simple '?' with order of appearance determining order into the
> array of vars, there are '$1', '$2', ... which would allow you to
> repeat or do things out of order. Or the SQLite method of '?nnn' or
> ':aaa' and also allow identifies.
Python's DB API supports 5 different variations, mainly because of the
different styles people are used to in their underlying database. I'm
listing them here for reference. They are:
'qmark' Question mark style,
e.g. '...WHERE name=?'
'numeric' Numeric, positional style,
e.g. '...WHERE name=:1'
'named' Named style,
e.g. '...WHERE name=:name'
'format' ANSI C printf format codes,
e.g. '...WHERE name=%s'
'pyformat' Python extended format codes,
e.g. '...WHERE name=%(name)s'
Personally, I like pyformat, but then I'm a python guy, so I'm guessing
that shoudn't be surprising.
> What are folks thoughts on PS APIs? Anything they really love or hate?
I do not like ?. I like the forms that let me name the parameters...
but it depends on what the rest of the api looks like. If it's this:
drizzle_statement_st my_stmt= drizzle->prepare("select * from foo where
bar=:bar");
drizzle_statement_bind_value(my_stmt, ":bar","bar-value");
Then I love it named params- they allow more programmatic construction
in higher-level things like ORMs (you build the form of the query and
then iteratively figure out what goes where)
If it's more of a var-args approach though:
drizzle_statement_st my_stmt= drizzle->prepare("select * from foo where
bar=:1","bar-value");
Then I think that positional are fine. The varargs approach is quicker
and dirtier, but I think it scales much less well and is much more
difficult to build incrementally.
> We're also thinking of restricting vars to strings for now, but
> possibly simple INT types. Other types could still be given as vars,
> but they'd just be passed in as strings.
I think that's fine. Higher level conversion than that is likely going
to be done at the language level anyway. (I'm going to be more likely to
just grab a string representation of something like a date in the python
driver and pass that to libdrizzle than I am in trying to fill in a date
struct or something)
Monty
_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help : https://help.launchpad.net/ListHelp