[Zope-DB] dco2 and bind variables
Matthew T. Kromer
matt at zope.com
Wed Oct 8 14:41:05 EDT 2003
Jim Abramson wrote:
>Rather than rolling my own subclass of DCO2 (sounds like fun but...), I'm inclined to start using external methods instead of sql methods, which import DCO2 and now I have direct access to the execute() method.
>
>Ideally, I'd like to pass the zope database connection object to the external method, let the method call execute/fetchall, and return the results, because sometimes the same sql is run against different connections. A few quick tests of this worked just fine, hooray. But does it introduce any risk, as far as the pooling of connections or handling of transactions that may be going on elsewhere in zope? Is there some pitfall I'm not aware of here? It almost seems, well, too easy...
>
>Thanks for advice.
>Jim
>
>
>
If you grab the connection object from Zope and call it, you get an
object back that has a query() method on it. You can look under the
covers and see that it has a "cursor" attribute, which is a DCOracle2
cursor. If you grab a cursor in this way, the cursor will be registered
with the transaction environment in Zope, and you don't need to worry
about explicitly committing or rolling back your SQL.
Note that in my opinion, it would be advantageous to expand Zope's
notion of what methods a database adapter provides to include providing
a DBAPI wrapper object. Right now the DA connection object's callable
result only provides "query()" and a few other methods like __str__.
--
Matt Kromer
Zope Corporation http://www.zope.com/
More information about the Zope-DB
mailing list