[英]You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near at line 1",
[英]MariaDB SQL syntax near error parenthesis ')' for python
我試圖使用python腳本將一些數據插入到我的MariaDB中。 當我在控制台中執行以下操作時,它可以完美運行
INSERT INTO `Failure` (`faillure_id`, `testrun_id`, `failed_at`, `log_path`, `node`)
VALUES (2, 1, 'STEP8:RUN:RC=1', '/var/fail_logs','NodeA')
給我看一個查詢確定。 我可以看到正在填充的表格。 沒問題。
但是,當我使用python執行相同的SQL查詢時,我收到一些錯誤。 這是我的代碼
conn = MySQLdb.connect("localhost","user","","DB")
cursor = conn.cursor()
cursor.execute("""INSERT INTO `Failure` (`testrun_id`, `failed_at`, `log_path`, `node`) VALUES (%s, %s, %s, %s)""",(testrun_id, failed_at, log_path, node))
conn.commit()
這會產生以下錯誤
檢查與您的MariaDB服務器版本對應的手冊,以便在')附近使用正確的語法,
有人可以幫我理解錯誤的來源。
作為解決方法,我正在構建這樣的查詢字符串
sql_query = "INSERT INTO `Failure` (`testrun_id`, `failed_at`, `log_path`, `node`) VALUES " + "( '" + str(testrun_id) + "', '" + str(failed_at) + "', '"+ log_path + "', '" + node + "')"
cursor.execute(sql_query)
不是很有效但是現在做的工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.