INSERT IGNORE INTO standard_group (group_name, subject, grade, country, state) VALUES (%(group_name), %(subject), %(grade), %(country), %(state));
隨着
('Arizona Social Studies Standards', 'Social Studies', '1', 'United States', 'AZ')
如:
print group_columns
print group_sql
print group
cur.execute(group_sql, dict(zip(group_columns, group)))
但我總是得到:
['group_name', 'subject', 'standard_category', 'standard_sub_category', 'standard_name', 'standard_description', 'grade', 'country', 'state', 'is_common_core', 'is_state_standard']
INSERT IGNORE INTO standard_group (group_name, subject, grade, country, state) VALUES (%(group_name), %(subject), %(grade), %(country), %(state));
('Arizona Social Studies Standards', 'Social Studies', '1', 'United States', 'AZ')
Traceback (most recent call last):
File "standards-import/simport.py", line 167, in <module>
cur.execute(group_sql, dict(zip(group_columns, group)))
File "/Library/Python/2.7/site-packages/mysql/connector/cursor.py", line 507, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "/Library/Python/2.7/site-packages/mysql/connector/connection.py", line 722, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "/Library/Python/2.7/site-packages/mysql/connector/connection.py", line 640, in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 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 '%(group_name), %(subject), %(grade), %(country), %(state))' at line 1
我曾與一個名爲PARAMS試過,?
和%s
,並獲得
- 並非所有的參數使用
- 的參數錯誤號碼命名的參數
- SQL語法
這是怎麼回事?我錯過了什麼?
當你用'%(組名)'應該不是替換是在字典而不是列表中? – Barmar
'dict(zip(group_columns,group))'將它們變成一個字典(用正確的鍵名稱)。還有其他的東西也是問題,因爲我不能做list +'%s'或'''格式。 –
你可以粘貼你的Python腳本,以便我們可以查看縮進等? – FirebladeDan