diff options
author | Michael Trier <mtrier@gmail.com> | 2008-10-20 15:21:00 +0000 |
---|---|---|
committer | Michael Trier <mtrier@gmail.com> | 2008-10-20 15:21:00 +0000 |
commit | c81c7ff3d59469cf6ceccbcf1593fd0563f0eaf3 (patch) | |
tree | d12139bc6c793c7190c3fb1d344a49c37080d635 /lib/sqlalchemy/sql/compiler.py | |
parent | abcb5605f91ef206dd5f0f6400302f0b28425365 (diff) | |
download | sqlalchemy-c81c7ff3d59469cf6ceccbcf1593fd0563f0eaf3.tar.gz |
Modifications to allow the backends to control the behavior of an empty insert. If supports_empty_insert is True then the backend specifically supports the 'insert into t1 () values ()' syntax. If supports_default_values is True then the backend supports the 'insert into t1 default values' syntax. If both are false then the backend has no support for empty inserts at all and an exception gets raised. Changes here are careful to not change current behavior except where the current behavior was failing to begin with.
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 0117b96ff..2072d5a27 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -570,11 +570,18 @@ class DefaultCompiler(engine.Compiled): insert = ' '.join(["INSERT"] + [self.process(x) for x in insert_stmt._prefixes]) - return (insert + " INTO %s (%s) VALUES (%s)" % + if not colparams and not self.dialect.supports_default_values and not self.dialect.supports_empty_insert: + raise exc.NotSupportedError( + "The version of %s you are using does not support empty inserts." % self.dialect.name) + elif not colparams and self.dialect.supports_default_values: + return (insert + " INTO %s DEFAULT VALUES" % ( + (preparer.format_table(insert_stmt.table),))) + else: + return (insert + " INTO %s (%s) VALUES (%s)" % (preparer.format_table(insert_stmt.table), - ', '.join(preparer.quote(c[0].name, c[0].quote) - for c in colparams), - ', '.join(c[1] for c in colparams))) + ', '.join([preparer.format_column(c[0]) + for c in colparams]), + ', '.join([c[1] for c in colparams]))) def visit_update(self, update_stmt): self.stack.append({'from': set([update_stmt.table])}) |