Wednesday 15 June 2011

python MySQLdb prepared select statement -


I'm trying to execute the following in Python with MySQLdb:

  cur .execute "(select COUNT (*) from adjacency where r =% d and c =% d)"% (currow, curCol)   

r and < Code> C integer field table has imprecise and also creates an overall primary key curRow and curCol integer in my Python program There are variables. MySQL is complaining:

  _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; manual that matches the MySQL server version for the correct syntax for your SIM Finally, I want to check whether the  r = curCow  and   

> C = curCol . If so, update a field in the table. Otherwise enter a row in the table.

  1. What is wrong with my prepared statement?

    All help is appreciated!

    It seems that you have a bracket in the wrong place.

    Change ...

      cur.execute ("Select from nearest COUNT (*) where r =% d and c =% d)"% (currow, curCol )   

    ... to ...

      cur.execute ("select COUNT (*) proximity where r =% d and c =% D "% (curRow, curCol))   

    ... though it is safe to use ...

      cur.execute (" selection Do COUNT (*) proximity where r =% s and c =% s ", (CurRow, curCol))   

    ... which will save you from potential SQL injection.

No comments:

Post a Comment