The exact supported parameter formats are documented per database adapter, so check that too. See the Python DB API 2.0 spec for (some) more details on parametrized SQL. Sql_input = "INSERT INTO 963168MBV17A(Rev, Part, SN, Iterations, Date, Time, Upstream, Downstream, ResultList, Result, Report) VALUES('503', '100-120970-0031', '1594539', ?, ?, ?, ?, ?, 0, P, 0"Ĭur.execute(sql_input, (export_date, export_time, export_numtests, export_upstream, export_downstream)) You need to let the MySQL library do the parameter handling for you this has the added benefit of letting MySQL prepare your statement, making repeated inserts faster too: cur = con.cursor() Still, though, I get the same error.Īny ideas? If not, any better way to store Python array/list data into a single MySQL cell? When I did the json.dumps(json.dumps(upstream_data)), the inside quotations become double quotes "" and preceded by \ characters. I see that the JSON object is appearing as a long string with lots of single quotes all over the place (for the list, and on the outside to represent a string). Moreover, when I do a print "about to execute(%s)" % sql_input 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 '' at line 1") Referencing an answer by Mordi (), I even tried: export_upstream = json.dumps(json.dumps(upstream_data))Įxport_downstream = json.dumps(json.dumps(downstream_data))īut regardless I end up with the error: Traceback (most recent call last):įile "P:\Projects\testing database\scrap\test.py", line 83, in įile "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 174, in executeįile "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler ![]() Then I execute the SQL commands: cur = con.cursor() I take my list of lists called upstream_data and downstream_data and do: export_upstream = json.dumps(upstream_data)Įxport_downstream = json.dumps(downstream_data) So after connecting to my database: (I've tried LONGTEXT and LONGBLOB datatypes for Upstream and Downstream cur = con.cursor()Ĭur.execute("CREATE TABLE IF NOT EXISTS 963168MBV17A(Id INT AUTO_INCREMENT PRIMARY KEY, Rev INT, Part VARCHAR(15), SN INT(7), Date DATE, Time TIME, Iterations INT(3), Upstream LONGBLOB, Downstream LONGBLOB, ResultList LONGTEXT, Result CHAR(1), Report LONGBLOB)") I've attempted to use JSON to serialize my data, but perhaps I do not understand how JSON works. ![]() I'm trying to store this array into a single cell in a MySQL database. ![]() So I have a bunch of array data in Python.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |