2

Calling:

INSERT IGNORE INTO standard_group (group_name, subject, grade, country, state) VALUES (%(group_name), %(subject), %(grade), %(country), %(state));

With

('Arizona Social Studies Standards', 'Social Studies', '1', 'United States', 'AZ')

eg:

    print group_columns
    print group_sql
    print group
    cur.execute(group_sql, dict(zip(group_columns, group)))

But I always get:

['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

I've tried with named params, ? and %s, and get

  • Not all arguments used
  • Wrong number of arguments for named parameter
  • SQL syntax

What's going on?? What am I missing???

Jordan Warbelow-Feldstein
  • 10,510
  • 12
  • 48
  • 79

1 Answers1

2

It looks like a small typo. You forgot to add s to the params

INSERT IGNORE INTO standard_group (group_name, subject, grade, country, state) VALUES (%(group_name)s, %(subject)s, %(grade)s, %(country)s, %(state)s);

The relevant code is here:

twil
  • 6,032
  • 1
  • 30
  • 28