Call SQLMethods/SQL Statements directly with python
Hello! Somebody out there who can give me a hint how to call SQL directly from python and not with SQLMethods Thank you! Philipp
[Philipp Giere]
Somebody out there who can give me a hint how to call SQL directly from python and not with SQLMethods
The Python Database SIG has developed a standard database interface, and it is supported by many database modules. On Windows, I use ODBC. The package to get is mxODBC. Whether or not you use ODBC, the interface methods are the same. Here's a sketch of how to use the SIG's interface: import ODBC.Windows # Or whatever driver you use # Connect to database and get cursor conn=ODBC.Windows.Connect('nesdis_quest') cursor=conn.cursor() # Build a query statement - in this example, an INSERT statement insertStr='INSERT INTO %s(%s) values(%s)' %\ (table,cols,values) # calculated elsewhere # Execute cursor.execute(insertStr) # Number of inserted rows is in cursor.rowcount # Commit transaction and clean up cursor.close() conn.commit() conn.close() Not hard at all! Cheers, Tom P
If you still want to use a zope database adapter, you can do it like this: db = self.database_adapter_id() i,rows = db.query('...SQL Statement(s)...') for row in rows: process the rows hth, -Casey Philipp Giere wrote:
Hello! Somebody out there who can give me a hint how to call SQL directly from python and not with SQLMethods
Thank you!
Philipp
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Casey Duncan wrote:
If you still want to use a zope database adapter, you can do it like this:
db = self.database_adapter_id() i,rows = db.query('...SQL Statement(s)...')
for row in rows: process the rows
Serendipity!! That's exactly the solution to one of the questions i'm pondering myself. Thanks
Philipp Giere wrote:
Hello! Somebody out there who can give me a hint how to call SQL directly from python and not with SQLMethods
------------------------------------------------------------- Who's got only a hammer sees the world as a nail hans augustin (software developer) hans@beehive.de beehive elektronische medien GmbH http://www.beehive.de phone: +49 30 847-82 0 fax: +49 30 847-82 299
participants (4)
-
Casey Duncan -
hans -
Philipp Giere -
Thomas B. Passin