Maybe I am just doing something wrong, but I have been fighting with this
for a while to no avail.
Here's my code:
query = '''INSERT INTO users_roles (user_id, role_id) VALUES (:user_id,
:perm0), (:user_id, :perm1)'''
t = text(query).execution_options(autocommit=True)
self.conn.execute(t, user_id=1, perm0=1, perm1=2)
Here is the log:
2012-11-15 11:22:12,450 INFO sqlalchemy.engine.base.Engine INSERT INTO
users_roles (user_id, role_id) VALUES (?, ?), (?, ?)
2012-11-15 11:22:12,451 INFO sqlalchemy.engine.base.Engine (1, 1, 1, 2)
Here is the error:
File "/.../site-packages/sqlalchemy/engine/default.py", line 331, in
do_execute
cursor.execute(statement, parameters)
OperationalError: (OperationalError) near ",": syntax error u'INSERT INTO
users_roles (user_id, role_id) VALUES (?, ?), (?, ?)' (1, 1, 1, 2)
If I evaluate this manually, my insert statement is:
INSERT INTO users_roles (user_id, role_id) VALUES (1, 1), (1, 2)
When I run this manually in my sql client (using sqlite for the DB right
now) it succeeds. If I run it through sqlalchemy, it get the error
outlined. Is this potentially a driver issue or am I just missing something?
Tried it with the stdlib sqlite3 driver as well, it fails there too:
import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()
c.execute("INSERT INTO users_roles (user_id, role_id) VALUES (1, 1), (1,
2)")
Table def:
CREATE TABLE "users_roles" (
id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
role_id INTEGER NOT NULL,
PRIMARY KEY (id),
)
Anyone else encounter this?
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/fRQ9vBlKMzIJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.