[BangPypers] Python database interface

Praveen Kumar praveen.python.plone at gmail.com
Thu Jan 21 20:43:00 CET 2010


>>> curs.execute('SELECT * FROM ani')
>>> curs.execute('CREATE TABLE anizilla(name char(20))')
------------------------------
>
> -------------- Same query but some porb.
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File "build/bdist.linux-i686/egg/pgdb.py", line 259, in execute
>  File "build/bdist.linux-i686/egg/pgdb.py", line 289, in executemany
> pg.DatabaseError: error 'ERROR:  current transaction is aborted, commands
> ignored until end of transaction block
> ' in 'CREATE TABLE  anizilla(name char(20))'


  mySQL does not invalidate the current transaction when it encounters an
error where postgres throws the error and do not run other query until the
current transaction is not aborted. In this case you have to kill the
transaction.

>>i already tried installing MySQLdb... but been highly
unsuccessful.... says requires installin 'setuptools'...!?*

you need to install setuptools

Cheers,
Praveen


On Fri, Jan 22, 2010 at 12:17 AM, Anirudh Asokan
<anirudh.asokan at gmail.com>wrote:

> hey ter ppl... im bak wid more exotic newbie questions.....
>
>  My question is pretty simple - How do i interact with a database within
> python? For this i installed postgres sql and its python's DB-API
> (py-postgresl)... somehow i managed to install in it. I could import pgdb
> module in python but when i run some code, for eg:
>
> anirudh at Kat:~$ python
> Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15)
> [GCC 4.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import pgdb
> >>> conn = pgdb.connect(host='localhost', user='postgres', password='xyz')
> >>> curs = conn.cursor()
> >>> curs.execute('CREATE TABLE ani(name char(20))')
> ---------------------------------------------------- it worked fine here!
> >>> curs.execute('INSERT ani VALUES (%s)', ('Lemur'))
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File "build/bdist.linux-i686/egg/pgdb.py", line 259, in execute
>  File "build/bdist.linux-i686/egg/pgdb.py", line 291, in executemany
> pg.OperationalError: internal error in 'BEGIN': not all arguments converted
> during string formatting
> >>> curs.execute('SELECT * FROM ani')
> >>> curs.execute('CREATE TABLE anizilla(name char(20))')
> -------------------------------------------- Same query but some porb.
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File "build/bdist.linux-i686/egg/pgdb.py", line 259, in execute
>  File "build/bdist.linux-i686/egg/pgdb.py", line 289, in executemany
> pg.DatabaseError: error 'ERROR:  current transaction is aborted, commands
> ignored until end of transaction block
> ' in 'CREATE TABLE  anizilla(name char(20))'
> >>>
>
>
>
> WHAT IS IT ALL ABOUT MANN!!!!?????? and bother to advice me on using
> mysql.... i already tried installing MySQLdb... but been highly
> unsuccessful.... says requires installin 'setuptools'...!?*
>
> PLS HELP ME!!!
> *
> --
> Cheers,
> Anirudh Asokan
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>



-- 
Praveen Kumar
+91 9620621342
http://praveensunsetpoint.wordpress.com
Bangalore


More information about the BangPypers mailing list