using database connection inside of python scripts or how to do a d-hoc queries
I have been searching for this answer and not finding it. Inside a python script I want to create insert queries based on the fields returned from a form. I tried creating a database connection object like : dbcon = context.Psycopg_database_connection() Then executing a query like: RS = dbcon.query('select * from customer').dictionaries() this does not work. Can any one point me in the right direction? Thanks Gene
--On Donnerstag, 17. Februar 2005 13:17 Uhr -0600 "Tuttle, Gene" <cetuttle@rottlundhomes.com> wrote:
I have been searching for this answer and not finding it.
Inside a python script I want to create insert queries based on the fields returned from a form. I tried creating a database connection object like :
dbcon = context.Psycopg_database_connection()
Then executing a query like: RS = dbcon.query('select * from customer').dictionaries()
this does not work. Can any one point me in the right direction?
Why are you using *this* approach. The recommended way is to setup a DA inside the ZMI and use ZSQL methods for performing SQL operations through the DA. Please read the Zope Book RDBMS chapter carefully to get an idea how to it it the zope-ish way. -aj
Tuttle, Gene wrote at 2005-2-17 13:17 -0600:
I have been searching for this answer and not finding it.
Inside a python script I want to create insert queries based on the fields returned from a form. I tried creating a database connection object like :
dbcon = context.Psycopg_database_connection()
Then executing a query like: RS = dbcon.query('select * from customer').dictionaries()
this does not work.
What happens? You should always tell us the precise problem! You probably get an "Unauthorized" exception, because "query" is an internal method. If you do not (because you execute in trusted code), then you get an "AttributeError" exception because "query" returns a tuple and a tuple does not have a "dictionaries" method. When you use internal methods, you should carefully look at their source to learn about arguments and return values. -- Dieter
participants (3)
-
Andreas Jung -
Dieter Maurer -
Tuttle, Gene