In MySQLdb 1.2.3, a query comes from string substitution using the first argument as the model string, and the second argument as a list of parameters or a single parameter passed through con.literal. con.literal takes what you put and tries to turn it into a string that is correctly processed by MySQL. He adds apostrophes to the lines. It prints numbers without quotes. Or, for example, if you give him a line with an apostrophe, it quotes an apostrophe.
In your particular case, MySQLdb seems like it will always do the wrong thing when you pass it a tuple in which there is only one element (con is any open connection):
>>> con.literal((10,)) ('10',) >>>
What Python expects will be able to create a tuple with one element in it, but it forces MySQL barf (scroll right to see barfness):
mysql> select distinct sites.SiteCode, sites.SiteName, Latitude, Longitude, County, SourceID from sites, seriescatalog where sites.SiteID = seriescatalog.SiteID and sites.SiteID in (82,); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 mysql>
This is my job to prevent Bobby Tabling:
siteinfoquery = """select distinct sites.SiteCode, sites.SiteName, Latitude, Longitude, County, SourceID from sites, seriescatalog where sites.SiteID = seriescatalog.SiteID and sites.SiteID in (%s);""" cur.execute(siteinfoquery % ",".join([str(int(i)) for i in SiteID]))
BTW, the following does not work because con.literal (called inside the MySQLdb execute () function) quotes the resulting string, turning it from a list of numbers to a string, which then becomes the only value that does not match any SiteID:
cur.execute(siteinfoquery , ",".join([str(int(i)) for i in SiteID])) >>> "(%s)" % con.literal(",".join([str(float(i)) for i in SiteID])) "('10.0,20.0')" >>>
I did not see if the error was fixed in a later version, the current problem, my error or an unknown problem.