55
55
Jump ahead for the :ref:`orm-tutorial`.
56
56
57
57
58
+ .. _bind-parameters:
59
+
58
60
Bind Parameters
59
61
+++++++++++++++
60
62
@@ -350,12 +352,14 @@ def run(self, sql, parameters=None, *a, **kw):
350
352
"""Execute a query and discard any results.
351
353
352
354
:param string sql: the SQL statement to execute
353
- :param parameters: the bind parameters for the SQL statement
355
+ :param parameters: the ` bind parameters`_ for the SQL statement
354
356
:type parameters: dict or tuple
355
357
:param a: passed through to :py:meth:`~postgres.Postgres.get_cursor`
356
358
:param kw: passed through to :py:meth:`~postgres.Postgres.get_cursor`
357
359
:returns: :py:const:`None`
358
360
361
+ .. _bind parameters: #bind-parameters
362
+
359
363
>>> db.run("DROP TABLE IF EXISTS foo CASCADE")
360
364
>>> db.run("CREATE TABLE foo (bar text, baz int)")
361
365
>>> db.run("INSERT INTO foo VALUES ('buz', 42)")
@@ -370,7 +374,7 @@ def one(self, sql, parameters=None, back_as=None, default=None, *a, **kw):
370
374
"""Execute a query and return a single result or a default value.
371
375
372
376
:param string sql: the SQL statement to execute
373
- :param parameters: the bind parameters for the SQL statement
377
+ :param parameters: the ` bind parameters`_ for the SQL statement
374
378
:type parameters: dict or tuple
375
379
:param back_as: the type of record to return
376
380
:type back_as: type or string
@@ -383,6 +387,8 @@ def one(self, sql, parameters=None, back_as=None, default=None, *a, **kw):
383
387
:py:attr:`default` argument
384
388
:raises: :py:exc:`~postgres.TooFew` or :py:exc:`~postgres.TooMany`
385
389
390
+ .. _bind parameters: #bind-parameters
391
+
386
392
Use this for the common case where there should only be one record, but
387
393
it may not exist yet.
388
394
@@ -474,7 +480,7 @@ def all(self, sql, parameters=None, back_as=None, *a, **kw):
474
480
"""Execute a query and return all results.
475
481
476
482
:param string sql: the SQL statement to execute
477
- :param parameters: the bind parameters for the SQL statement
483
+ :param parameters: the ` bind parameters`_ for the SQL statement
478
484
:type parameters: dict or tuple
479
485
:param back_as: the type of record to return
480
486
:type back_as: type or string
@@ -485,6 +491,8 @@ def all(self, sql, parameters=None, back_as=None, *a, **kw):
485
491
:returns: :py:class:`list` of records or :py:class:`list` of single
486
492
values
487
493
494
+ .. _bind parameters: #bind-parameters
495
+
488
496
>>> db.all("SELECT * FROM foo ORDER BY bar")
489
497
[Record(bar='bit', baz=537), Record(bar='buz', baz=42)]
490
498
0 commit comments