correct syntax for db api..

Stefan Schwarzer sschwarzer at sschwarzer.net
Mon Jul 22 13:41:23 EDT 2002


Hi Eugene Kim

eugene kim wrote:
> import pgdb
> 
> db=pgdb.connect(user='postgres',database='test')
> cursor=db.cursor()
> 
> -----------------
> cursor.execute('select url, visits from history where url= %s', (self.url))     
> -------------

As a side note, (self.url) is an expression, not a tuple. Both should work.

> or
> -----------------
> sqlselect = 'select url, visits from history where url = %s '
> cursor.execute(sqlselect % self.url)
> ----------------

Perhaps you have to use quotes:

sqlselect = "select url, visits from history where url='%s'"
cursor.execute(sqlselect % self.url)

Stefan




More information about the Python-list mailing list