Re: need some database API design advice
Chris Clark <[email protected]>
| Newsgroups | gmane.comp.python.db |
|---|---|
| Message-ID | <[email protected]> |
On Wednesday 2012-04-11 12:44 (-0700), Peter Eisentraut <[email protected]> wrote: > .... > So, in terms of code, which one of these is "better"? > > 1a. > > rv = plpy.execute("some SQL command") > try: > output(rv.colnames()) > except SomeException: > output("it's a utility command") > > 1b. > > rv = plpy.execute("some SQL command") > if rv.has_rows(): # some currently nonexisting function to be added > output(rv.colnames()) > else: > output("it's a utility command") > > 2. > > rv = plpy.execute("some SQL command") > if rv.colnames() is not None: > output(rv.colnames()) > else: > output("it's a utility command") My 2 cents, I don't like any of them :-p I prefer the last one modified slightly: rv = plpy.execute("some SQL command") if rv.colnames(): output(rv.colnames()) else: output("it's a utility command") I.e. loose the None check. I'm not sure I like making an explicit function call for the colnames. I.e. I think sticking with the pep249 description attribute is a better solution, the API already exist so clone that (when possible) in your new api. ....Of course a lot of this is is down to style preferences. Chris _______________________________________________ DB-SIG maillist - [email protected] http://mail.python.org/mailman/listinfo/db-sig