Title: [958] trunk: Add important note regarding unnamed prepared statements
Revision
958
Author
cito
Date
2019-01-04 11:24:55 -0500 (Fri, 04 Jan 2019)

Log Message

Add important note regarding unnamed prepared statements

Modified Paths


Diff

Modified: trunk/docs/contents/pg/db_wrapper.rst (957 => 958)


--- trunk/docs/contents/pg/db_wrapper.rst	2019-01-04 13:28:58 UTC (rev 957)
+++ trunk/docs/contents/pg/db_wrapper.rst	2019-01-04 16:24:55 UTC (rev 958)
@@ -572,6 +572,12 @@
         rows = db.query_prepared(ein, phone,
             name='update employees).getresult()[0][0]
 
+.. note::
+
+    The DB wrapper sometimes issues parameterized queries behind the scenes
+    (for instance to find unknown database types) which could replace the
+    unnamed statement. So we advice to always name prepared statements.
+
 .. versionadded:: 5.1
 
 describe_prepared -- describe a prepared statement

Modified: trunk/tests/test_classic_connection.py (957 => 958)


--- trunk/tests/test_classic_connection.py	2019-01-04 13:28:58 UTC (rev 957)
+++ trunk/tests/test_classic_connection.py	2019-01-04 16:24:55 UTC (rev 958)
@@ -958,9 +958,10 @@
         self.assertRaises(pg.OperationalError,
             self.c.query_prepared, 'does-not-exist')
 
-    def testAnonymousQueryWithoutParams(self):
+    def testUnnamedQueryWithoutParams(self):
         self.assertIsNone(self.c.prepare('', "select 'anon'"))
         self.assertEqual(self.c.query_prepared('').getresult(), [('anon',)])
+        self.assertEqual(self.c.query_prepared('').getresult(), [('anon',)])
 
     def testNamedQueryWithoutParams(self):
         self.assertIsNone(self.c.prepare('hello', "select 'world'"))
@@ -973,7 +974,7 @@
         self.assertEqual(self.c.query_prepared('query17').getresult(), [(17,)])
         self.assertEqual(self.c.query_prepared('query42').getresult(), [(42,)])
 
-    def testAnonymousQueryWithParams(self):
+    def testUnnamedQueryWithParams(self):
         self.assertIsNone(self.c.prepare('', "select $1 || ', ' || $2"))
         self.assertEqual(
             self.c.query_prepared('', ['hello', 'world']).getresult(),
@@ -994,7 +995,7 @@
         self.assertRaises(pg.OperationalError,
             self.c.describe_prepared, 'does-not-exist')
 
-    def testDescribeAnonymousQuery(self):
+    def testDescribeUnnamedQuery(self):
         self.c.prepare('', "select 1::int, 'a'::char")
         r = self.c.describe_prepared('')
         self.assertEqual(r.listfields(), ('int4', 'bpchar'))

Modified: trunk/tests/test_classic_dbwrapper.py (957 => 958)


--- trunk/tests/test_classic_dbwrapper.py	2019-01-04 13:28:58 UTC (rev 957)
+++ trunk/tests/test_classic_dbwrapper.py	2019-01-04 16:24:55 UTC (rev 958)
@@ -450,7 +450,7 @@
     def createTable(self, table, definition,
                     temporary=True, oids=None, values=None):
         query = self.db.query
-        if not '"' in table or '.' in table:
+        if '"' not in table or '.' in table:
             table = '"%s"' % table
         if not temporary:
             q = 'drop table if exists %s cascade' % table
@@ -1009,7 +1009,9 @@
         f = self.db.query_prepared
         self.assertRaises(pg.OperationalError, f)
         p = self.db.prepare
-        p("select 'no name'")
+        # make sure all types are known so that we will not
+        # generate other anonymous queries in the background
+        p("select 'no name'::varchar")
         r = f().getresult()[0][0]
         self.assertEqual(r, 'no name')
         r = f(name=None).getresult()[0][0]
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo/pygresql

Reply via email to