The problem:
You're using MySQL's connector to access your MySQL DB using Python, and having read the documentation, are trying to work out why your very simple query isn't working:
You're using MySQL's connector to access your MySQL DB using Python, and having read the documentation, are trying to work out why your very simple query isn't working:
dbCursor.execute("SELECT das_description, das_pictureloc FROM dassie WHERE das_id = %s", dassieId)
The error message talks about the format parameters, with argument 2 to map() needing to support iteration.
Hmm, you had thought that because you were only passing one arg, you should pass it 'naked' and not in a tuple. Clearly that was wrong. So you write:
Hmm, you had thought that because you were only passing one arg, you should pass it 'naked' and not in a tuple. Clearly that was wrong. So you write:
dbCursor.execute("SELECT das_description, das_pictureloc FROM dassie WHERE das_id = %s", (dassieId))
and you get the same error message. OK, that can't have been it, so you faff about a bit more. And that's where you went wrong. Funnily enough, I was stuck until I found the answer here in the MySQLdb User's Guide. (And yes, I really do mean MySQLdb and not MySQL's own connector.)
Here's the version that works:
Here's the version that works:
dbCursor.execute("SELECT das_description, das_pictureloc FROM dassie WHERE das_id = %s", (dassieId,))
To sum up, you need to insert your single value in a tuple with a second empty item, to prevent Python from treating the brackets around dassieId as ordinary grouping brackets and thus mentally undressing it.
Ugly, and I'm sure there's a nicer way of writing it (perhaps by creating an instance of some tuple class), but right now all I want to do is lie down in a darkened room...
Ugly, and I'm sure there's a nicer way of writing it (perhaps by creating an instance of some tuple class), but right now all I want to do is lie down in a darkened room...