Menu

problem with place holder within a loop

Help
Anonymous
2002-09-26
2012-09-19
  • Anonymous

    Anonymous - 2002-09-26

    Hi,
    I'm trying this:

    def getall(sdate, list):
    ...
        e = Con.cursor()
        for x in list:
            e.execute("""select plz from bericht where sdatum=%s and paket=%s order by plz""", (sdate, x))
            sam = e.fetchone()
            erg.append(sam)
        return erg

    And the result is:

    Traceback (most recent call last):
      File "einoalsp.py", line 65, in ?
        ergebnis('2002-04-02')
      File "einoalsp.py", line 61, in ergebnis
        getall(sdate, rest)
      File "einoalsp.py", line 49, in getall
        e.execute("""select plz from bericht where sdatum=%s and paket=%s order by plz""", (sdate, x))
      File "C:\Python21\MySQLdb\cursors.py", line 66, in execute
        r = self._query(query % self.__conn.literal(args))
      File "C:\Python21\MySQLdb\cursors.py", line 168, in _query
        rowcount = self._BaseCursor__do_query(q)
      File "C:\Python21\MySQLdb\cursors.py", line 112, in __do_query
        db.query(q)
    _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax near ') order by plz' at line 1")

    (sdate ) without loop and (x) without (sdate) is working, so I think the loop is the problem.
    Can anyone help me solving this?

    Thomas

     
    • Andy Dustman

      Andy Dustman - 2002-10-02

      Are you sure x isn't a tuple?

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.