[BangPypers] Python database interface

Anirudh Asokan anirudh.asokan at gmail.com
Thu Jan 21 19:47:40 CET 2010


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


More information about the BangPypers mailing list