Changeset 900


Ignore:
Timestamp:
Dec 31, 2016, 3:40:24 AM (3 years ago)
Author:
cito
Message:

Allow query_formatted() to be used without parameters

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/docs/contents/changelog.rst

    r896 r900  
    11ChangeLog
    22=========
     3
     4Version 5.0.4 (to be released)
     5------------------------------
     6- query_formatted() can now be used without parameters.
    37
    48Version 5.0.3 (2016-12-10)
  • trunk/docs/contents/pg/db_wrapper.rst

    r895 r900  
    467467---------------------------------------------------------
    468468
    469 .. method:: DB.query_formatted(command, parameters, [types], [inline])
     469.. method:: DB.query_formatted(command, [parameters], [types], [inline])
    470470
    471471    Execute a formatted SQL command string
  • trunk/pg.py

    r894 r900  
    678678        return params
    679679
    680     def format_query(self, command, values, types=None, inline=False):
     680    def format_query(self, command, values=None, types=None, inline=False):
    681681        """Format a database query using the given values and types."""
     682        if not values:
     683            return command, []
    682684        if inline and types:
    683685            raise ValueError('Typed parameters must be sent separately')
     
    18481850        return self.db.query(command)
    18491851
    1850     def query_formatted(self, command, parameters, types=None, inline=False):
     1852    def query_formatted(self, command,
     1853            parameters=None, types=None, inline=False):
    18511854        """Execute a formatted SQL command string.
    18521855
  • trunk/tests/test_classic_dbwrapper.py

    r886 r900  
    954954        r = f(q, [[None]]).getresult()[0][0]
    955955        self.assertIsNone(r)
     956
     957    def testQueryFormattedWithoutParams(self):
     958        f = self.db.query_formatted
     959        q = "select 42"
     960        r = f(q).getresult()[0][0]
     961        self.assertEqual(r, 42)
     962        r = f(q, None).getresult()[0][0]
     963        self.assertEqual(r, 42)
     964        r = f(q, []).getresult()[0][0]
     965        self.assertEqual(r, 42)
     966        r = f(q, {}).getresult()[0][0]
     967        self.assertEqual(r, 42)
    956968
    957969    def testPkey(self):
Note: See TracChangeset for help on using the changeset viewer.