Hey all,
I'm trying to enter some data into a database and I keep getting this error:
Traceback (most recent call last):
File "./ais_file_parser.py", line 77, in <module>
cursor.execute(sql)
File "/usr/lib/pymodules/python2.7/MySQLdb/cursors.py", line 166, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "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 '('366978440', '46.500150', '-84.338107', CURRENT_TIMESTAMP)' at line 3")
The mysql command that I'm running is this:
#add the location entry to the database
sql = "INSERT INTO `ship_location`\n \
VALUES (`userid`, `latitude`, `longitude`, `date_time`) \n \
('%d', '%f', '%f', CURRENT_TIMESTAMP);" % (msg.userid, DMToDec(lat_dd, lat_min), DMToDec(long_ddd, long_min))
I set up the database so the date_time field has a default of the CURRENT_TIMESTAMP. From the error message, you can see that the userid is being sent an integer, and the latitude and longitude are both getting floats and when I set up their fields in MySQL I set them as FLOAT(10,6). So it might then be a problem with the sql syntax, but I can't see it. I've tried tried multiple ways of doing it, so I'm kind of at my wits end with it.
Any help would be appreciated.
[edit] Also thought I should add that I tried entering 366978440, 46.500150, -84.338107 into the user_id, longitude and latitude fields respectfully, and it works.