web.web.db.SQLQuery

Package web :: Package web :: Module db :: Class SQLQuery |
[hide private]
[frames] | no frames]

# Class SQLQuery

source code

You can pass this sort of thing as a clause in any db function. Otherwise, you can pass a dictionary to the keyword argument `vars` and the function will call reparam for you.

Internally, consists of `items`, which is a list of strings and SQLParams, which get concatenated to produce the actual query.

Instance Methods | [hide private]
__init__(self, items=`[``]`) Creates a new SQLQuery. | source code
__add__(self, other) | source code
__radd__(self, other) | source code
__iadd__(self, other) | source code
__len__(self) | source code
query(self, paramstyle=None) Returns the query part of the sql query. | source code
values(self) Returns the values of the parameters used in the sql query. | source code
_str(self) | source code
__str__(self) | source code
__unicode__(self) | source code
__repr__(self) | source code

Static Methods | [hide private]
join(items, sep=`'``` `'`) Joins multiple queries. | source code

Method Details | [hide private]

### __init__(self, items=`[``]`) (Constructor) | source code
Creates a new SQLQuery.
    >>> SQLQuery("x")
    <sql: 'x'>
    >>> q = SQLQuery(['SELECT * FROM ', 'test', ' WHERE x=', SQLParam(1)])
    >>> q
    <sql: 'SELECT * FROM test WHERE x=1'>
    >>> q.query(), q.values()
    ('SELECT * FROM test WHERE x=%s', [1])
    >>> SQLQuery(SQLParam(1))
    <sql: '1'>

### query(self, paramstyle=None) | source code
Returns the query part of the sql query.
    >>> q = SQLQuery(["SELECT * FROM test WHERE name=", SQLParam('joe')])
    >>> q.query()
    'SELECT * FROM test WHERE name=%s'
    >>> q.query(paramstyle='qmark')
    'SELECT * FROM test WHERE name=?'

### values(self) | source code
Returns the values of the parameters used in the sql query.
    >>> q = SQLQuery(["SELECT * FROM test WHERE name=", SQLParam('joe')])
    >>> q.values()
    ['joe']

### join(items, sep=`'``` `'`) Static Method | source code
Joins multiple queries.
    >>> SQLQuery.join(['a', 'b'], ', ')
    <sql: 'a, b'>