Skip to content

Commit

Permalink
Disable usage of "%s"
Browse files Browse the repository at this point in the history
Users can already use parameters with "$N".  This makes it so that users
do not need to escape "%" with "%%" when using named queries.

See dbcli/pgcli#865.
  • Loading branch information
Jason Ribeiro authored and Jason Ribeiro committed May 15, 2018
1 parent 9cabc39 commit 68e6c92
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pgspecial/iocommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,13 @@ def execute_named_query(cur, pattern, **_):
query, params = subst_favorite_query_args(query, params)
if query is None:
raise Exception("Bad arguments\n" + params)
cur.execute(query, params)
cur.execute(query)
except psycopg2.ProgrammingError as e:
if e.pgcode == psycopg2.errorcodes.SYNTAX_ERROR and "%s" in query:
raise Exception('Bad arguments: '
'please use "$1", "$2", etc. for named queries instead of "%s"')
else:
raise
except (IndexError, TypeError):
raise Exception("Bad arguments")

Expand Down

0 comments on commit 68e6c92

Please sign in to comment.