Skip to content

safe_psql() should always raise error on wrong input (issue #52) #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion testgres/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,8 @@ def psql(self,
filename=None,
dbname=None,
username=None,
input=None):
input=None,
**variables):
"""
Execute a query using psql.

Expand All @@ -822,9 +823,18 @@ def psql(self,
dbname: database name to connect to.
username: database user name.
input: raw input to be passed.
**variables: vars to be set before execution.

Returns:
A tuple of (code, stdout, stderr).

Examples:
>>> psql('select 1')
(0, b'1\n', b'')
>>> psql('postgres', 'select 2')
(0, b'2\n', b'')
>>> psql(query='select 3', ON_ERROR_STOP=1)
(0, b'3\n', b'')
"""

# Set default arguments
Expand All @@ -843,6 +853,10 @@ def psql(self,
dbname
] # yapf: disable

# set variables before execution
for key, value in iteritems(variables):
psql_params.extend(["--set", '{}={}'.format(key, value)])

# select query source
if query:
psql_params.extend(("-c", query))
Expand Down Expand Up @@ -874,10 +888,15 @@ def safe_psql(self, query=None, **kwargs):
username: database user name.
input: raw input to be passed.

**kwargs are passed to psql().

Returns:
psql's output as str.
"""

# force this setting
kwargs['ON_ERROR_STOP'] = 1

ret, out, err = self.psql(query=query, **kwargs)
if ret:
raise QueryException((err or b'').decode('utf-8'), query)
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy