summaryrefslogtreecommitdiff
path: root/tests/test_cursor.py
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-02-17 23:18:05 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-02-18 02:33:42 +0000
commit99b3c7231207693e677c77afc03ce25ef83b7fb8 (patch)
treecc06e9051e654d8b8452bde197dd46c601598567 /tests/test_cursor.py
parentb6d6fbbe8ccfd38fb9d0fab876802def9255930b (diff)
downloadpsycopg2-99b3c7231207693e677c77afc03ce25ef83b7fb8.tar.gz
Some cleanup in mogrify
- Raise an exception on incomplete placeholders. - Minor speedups. - Don't change the string in place (??!!) if the placeholder is not s and the value is null. The latter point can be done because downstream we don't accept anything different from s anyway (in the Bytes_Format function). Notice that now the format string is constant whatever the arguments. This means that executemany is still more inefficient than it should be as mogrify may work only on the parameters. However this is an implementation only worthwhile if we start supporting real parameters. Let's talk about that for the next release.
Diffstat (limited to 'tests/test_cursor.py')
-rwxr-xr-xtests/test_cursor.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/test_cursor.py b/tests/test_cursor.py
index 65050c8..b8a8b66 100755
--- a/tests/test_cursor.py
+++ b/tests/test_cursor.py
@@ -91,6 +91,17 @@ class CursorTests(unittest.TestCase):
self.assertEqual(b('SELECT 10.3;'),
cur.mogrify("SELECT %s;", (Decimal("10.3"),)))
+ def test_bad_placeholder(self):
+ cur = self.conn.cursor()
+ self.assertRaises(psycopg2.ProgrammingError,
+ cur.mogrify, "select %(foo", {})
+ self.assertRaises(psycopg2.ProgrammingError,
+ cur.mogrify, "select %(foo", {'foo': 1})
+ self.assertRaises(psycopg2.ProgrammingError,
+ cur.mogrify, "select %(foo, %(bar)", {'foo': 1})
+ self.assertRaises(psycopg2.ProgrammingError,
+ cur.mogrify, "select %(foo, %(bar)", {'foo': 1, 'bar': 2})
+
def test_cast(self):
curs = self.conn.cursor()