GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
DB insert with no values doesn't work with mysql, even though it works with sqlite.
ERR: INSERT INTO mytable DEFAULT VALUES
The correct syntax for MySQL is:
INSERT INTO mytable () VALUES();
(Originally reported by Ole Trenner in the mailing list.)
Found a workaround when there is an auto-incrementing column in the table. Instead of just insert('table') you do:
my_id = db.insert('table', id=web.db.SQLLiteral('NULL'))
This works in MySQL and SQLite.
What SQL does that result in?
In : db.insert('table', id=web.db.SQLLiteral('NULL'), _test=True)
Out: <sql: 'INSERT INTO table (id) VALUES (NULL)'>
Obviously this will only work if the id column has been set to something like id integer primary key auto_increment (mysql) or id integer primary key (sqlite).
id integer primary key auto_increment
id integer primary key
Yeah, don't think we want to count on that. I think just crashing is safer if the SQL engine doesn't support default values.
Uhm. MySQL does support default values, it just uses a different syntax:
INSERT INTO tbl_name () VALUES();
I was just searching for a solution that would work for both Sqlite and MySQL. Maybe the MySQL specific subclass in web.py could honor the MySQL syntax.