Skip to content

Commit a6a5a51

Browse files
author
James William Pye
committed
Change DO API to reflect absence of 'default_do_language'.
Better this way.
1 parent dd3ea31 commit a6a5a51

3 files changed

Lines changed: 13 additions & 16 deletions

File tree

postgresql/api.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -919,13 +919,10 @@ def settings(self) -> Settings:
919919
"""
920920

921921
@abstractmethod
922-
def do(source, language = None) -> None:
922+
def do(language, source) -> None:
923923
"""
924-
Execute a DO statement using the given source. Always returns `None` and
925-
raise a `postgresql.exceptions.Error` subclass on error.
926-
927-
If `language` is `None`, no language will be given to the DO statement,
928-
allowing the default configured language to be used.
924+
Execute a DO statement using the given language and source.
925+
Always returns `None`.
929926
930927
Likely to be a function of Connection.execute.
931928
"""
@@ -934,7 +931,7 @@ def do(source, language = None) -> None:
934931
def execute(sql) -> None:
935932
"""
936933
Execute an arbitrary block of SQL. Always returns `None` and raise
937-
a `postgresql.exceptions.Error` subclass on error.
934+
an exception on error.
938935
"""
939936

940937
@abstractmethod

postgresql/documentation/driver.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,9 @@ The methods and properties on the connection object are ready for use:
335335
This is used in cases where the cursor was declared on the server. See
336336
`Cursors`_ for more information.
337337

338-
``db.do(source[, language = None])``
339-
Execute a DO statement on the server. If `language` is `None`, none will be
340-
specified and the `default_do_language` database setting will be used by
341-
PostgreSQL. *DO statements are available on PostgreSQL 8.5 and greater.*
338+
``db.do(language, source)``
339+
Execute a DO statement on the server using the specified language.
340+
*DO statements are available on PostgreSQL 9.0 and greater.*
342341
*Executing this method on servers that do not support DO statements will*
343342
*likely cause a SyntaxError*.
344343

postgresql/driver/pq3.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,11 +1808,12 @@ def execute(self, query : str) -> None:
18081808
self._pq_push(q, self)
18091809
self._pq_complete()
18101810

1811-
def do(self, source : str, language : str = None) -> None:
1812-
sql = "DO " + pg_str.quote_literal(source)
1813-
if language is not None:
1814-
sql = sql + " LANGUAGE " + pg_str.quote_ident(language)
1815-
self.execute(sql + ";")
1811+
def do(self, language : str, source : str,
1812+
qlit = pg_str.quote_literal,
1813+
qid = pg_str.quote_ident,
1814+
) -> None:
1815+
sql = "DO " + qlit(source) + " LANGUAGE " + qid(language) + ";"
1816+
self.execute(sql)
18161817

18171818
def xact(self, gid = None, isolation = None, mode = None):
18181819
x = Transaction(self, gid = gid, isolation = isolation, mode = mode)

0 commit comments

Comments
 (0)