Changeset 961 for trunk/pg.py


Ignore:
Timestamp:
Jan 4, 2019, 2:43:23 PM (10 months ago)
Author:
cito
Message:

Revert to name of prepared query as positional arg

Unnamed prepared queries are not really useful due to their limited
lifetime. To discourage usage of unnamed statements and have a more
consistent API, we switched back from keyword-only to positional arg.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pg.py

    r960 r961  
    18701870            command, parameters, types, inline))
    18711871
    1872     def query_prepared(self, *args, **kwargs):
     1872    def query_prepared(self, name, *args):
    18731873        """Execute a prepared SQL statement.
    18741874
    18751875        This works like the query() method, except that instead of passing
    1876         the SQL command, you pass the name of a prepared statement via
    1877         the keyword-only argument `name`.  If you don't pass a name, the
    1878         unnamed statement will be executed, if you created one before.
     1876        the SQL command, you pass the name of a prepared statement.  If you
     1877        pass an empty name, the unnamed statement will be executed.
    18791878        """
    18801879        if not self.db:
    18811880            raise _int_error('Connection is not valid')
    1882         # use kwargs because Python 2 does not support keyword-only arguments
    1883         name = kwargs.get('name')
    18841881        if name is None:
    18851882            name = ''
     
    18901887        return self.db.query_prepared(name)
    18911888
    1892     def prepare(self, command, name=None):
     1889    def prepare(self, name, command):
    18931890        """Create a prepared SQL statement.
    18941891
    18951892        This creates a prepared statement for the given command with the
    18961893        the given name for later execution with the query_prepared() method.
    1897         The name can be empty or left out to create an unnamed statement,
    1898         in which case any pre-existing unnamed statement is automatically
    1899         replaced; otherwise it is an error if the statement name is already
    1900         defined in the current database session.
    1901 
    1902         If any parameters are used, they can be referred to in the query as
    1903         numbered parameters of the form $1.
     1894
     1895        The name can be empty to create an unnamed statement, in which case
     1896        any pre-existing unnamed statement is automatically replaced;
     1897        otherwise it is an error if the statement name is already
     1898        defined in the current database session. We recommend always using
     1899        named queries, since unnamed queries have a limited lifetime and
     1900        can be automatically replaced or destroyed by various operations.
    19041901        """
    19051902        if not self.db:
Note: See TracChangeset for help on using the changeset viewer.