Ensure the PostgreSQL driver raises a `sql_base.SQLError` when a cursor executes a query which has unbound variables.
This makes the behaviour of the PostgreSQL driver consistent with the Oracle one. --- backend/server/rhnSQL/driver_postgresql.py | 4 ++++ backend/test/non-unit/server/rhnSQL/dbtests.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/server/rhnSQL/driver_postgresql.py b/backend/server/rhnSQL/driver_postgresql.py index 88273e0..9470ac4 100644 --- a/backend/server/rhnSQL/driver_postgresql.py +++ b/backend/server/rhnSQL/driver_postgresql.py @@ -18,6 +18,7 @@ # import sys +import string import re import psycopg2 @@ -279,6 +280,9 @@ class Cursor(sql_base.Cursor): raise sql_base.SQLSchemaError(error_code, e.pgerror, e) except psycopg2.ProgrammingError, e: raise sql_base.SQLStatementPrepareError(self.dbh, e.pgerror, self.sql) + except KeyError, e: + raise sql_base.SQLError("Unable to bound the following variable(s): %s" + % (string.join(e.args, " "))) return retval def _execute_(self, args, kwargs): diff --git a/backend/test/non-unit/server/rhnSQL/dbtests.py b/backend/test/non-unit/server/rhnSQL/dbtests.py index 0fa703a..fd7fa93 100644 --- a/backend/test/non-unit/server/rhnSQL/dbtests.py +++ b/backend/test/non-unit/server/rhnSQL/dbtests.py @@ -66,7 +66,7 @@ class RhnSQLDatabaseTests(unittest.TestCase): query = "INSERT INTO %s(id, name) VALUES(:id, :name)" % \ self.temp_table cursor = rhnSQL.prepare(query) - self.assertRaises(KeyError, cursor.execute, name="Blah") + self.assertRaises(sql_base.SQLError, cursor.execute, name="Blah") def test_statement_prepare_error(self): rhnSQL.transaction("test_statement_prepare_error") -- 1.8.1.4 _______________________________________________ Spacewalk-devel mailing list Spacewalk-devel@redhat.com https://www.redhat.com/mailman/listinfo/spacewalk-devel