Changeset 958 for trunk


Ignore:
Timestamp:
Jan 4, 2019, 11:24:55 AM (9 months ago)
Author:
cito
Message:

Add important note regarding unnamed prepared statements

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/docs/contents/pg/db_wrapper.rst

    r957 r958  
    572572        rows = db.query_prepared(ein, phone,
    573573            name='update employees).getresult()[0][0]
     574
     575.. note::
     576
     577    The DB wrapper sometimes issues parameterized queries behind the scenes
     578    (for instance to find unknown database types) which could replace the
     579    unnamed statement. So we advice to always name prepared statements.
    574580
    575581.. versionadded:: 5.1
  • trunk/tests/test_classic_connection.py

    r957 r958  
    959959            self.c.query_prepared, 'does-not-exist')
    960960
    961     def testAnonymousQueryWithoutParams(self):
     961    def testUnnamedQueryWithoutParams(self):
    962962        self.assertIsNone(self.c.prepare('', "select 'anon'"))
     963        self.assertEqual(self.c.query_prepared('').getresult(), [('anon',)])
    963964        self.assertEqual(self.c.query_prepared('').getresult(), [('anon',)])
    964965
     
    974975        self.assertEqual(self.c.query_prepared('query42').getresult(), [(42,)])
    975976
    976     def testAnonymousQueryWithParams(self):
     977    def testUnnamedQueryWithParams(self):
    977978        self.assertIsNone(self.c.prepare('', "select $1 || ', ' || $2"))
    978979        self.assertEqual(
     
    995996            self.c.describe_prepared, 'does-not-exist')
    996997
    997     def testDescribeAnonymousQuery(self):
     998    def testDescribeUnnamedQuery(self):
    998999        self.c.prepare('', "select 1::int, 'a'::char")
    9991000        r = self.c.describe_prepared('')
  • trunk/tests/test_classic_dbwrapper.py

    r956 r958  
    451451                    temporary=True, oids=None, values=None):
    452452        query = self.db.query
    453         if not '"' in table or '.' in table:
     453        if '"' not in table or '.' in table:
    454454            table = '"%s"' % table
    455455        if not temporary:
     
    10101010        self.assertRaises(pg.OperationalError, f)
    10111011        p = self.db.prepare
    1012         p("select 'no name'")
     1012        # make sure all types are known so that we will not
     1013        # generate other anonymous queries in the background
     1014        p("select 'no name'::varchar")
    10131015        r = f().getresult()[0][0]
    10141016        self.assertEqual(r, 'no name')
Note: See TracChangeset for help on using the changeset viewer.