summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases/postgres.py
diff options
context:
space:
mode:
authorAnts Aasma <ants.aasma@gmail.com>2007-10-03 01:06:07 +0000
committerAnts Aasma <ants.aasma@gmail.com>2007-10-03 01:06:07 +0000
commitc25fa30febb2fc7ac21fe1379ee03595c7c6a8b6 (patch)
tree01c59ea75c219a0c02bbf533cca774b9f97d8f5f /lib/sqlalchemy/databases/postgres.py
parente82ca71cc5c4175f071cdd72207ec04e58a6498c (diff)
downloadsqlalchemy-c25fa30febb2fc7ac21fe1379ee03595c7c6a8b6.tar.gz
Made the regexp detecting the returning token more readable and fixed a couple of corner cases
Diffstat (limited to 'lib/sqlalchemy/databases/postgres.py')
-rw-r--r--lib/sqlalchemy/databases/postgres.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py
index 03b3fd042..990140c89 100644
--- a/lib/sqlalchemy/databases/postgres.py
+++ b/lib/sqlalchemy/databases/postgres.py
@@ -217,8 +217,19 @@ RETURNING_RE = re.compile(
# handle correctly nested C style quotes, lets hope no one does the following:
# UPDATE tbl SET x=y /* foo /* bar */ RETURNING */
RETURNING_QUOTED_RE = re.compile(
- '\\s*(?:UPDATE|INSERT)\\s(?:[^\'"$/-]|-(?!-)|/(?!\\*)|"(?:[^"]|"")*"|\'(?:[^\']|\'\')*\'|\\$(?P<dquote>[^$]*)\\$.*?\\$(?P=dquote)\\$|--[^\n]*\n|/\\*([^*]|\\*(?!/))*\\*/)*\\sRETURNING',
- re.I | re.UNICODE)
+ """\s*(?:UPDATE|INSERT)\s
+ (?: # handle quoted and commented tokens separately
+ [^'"$/-] # non quote/comment character
+ | -(?!-) # a dash that does not begin a comment
+ | /(?!\*) # a slash that does not begin a comment
+ | "(?:[^"]|"")*" # quoted literal
+ | '(?:[^']|'')*' # quoted string
+ | \$(?P<dquote>[^$]*)\$.*?\$(?P=dquote)\$ # dollar quotes
+ | --[^\\n]*(?=\\n) # SQL comment, leave out line ending as that counts as whitespace
+ # for the returning token
+ | /\*([^*]|\*(?!/))*\*/ # C style comment, doesn't handle nesting
+ )*
+ \sRETURNING\s""", re.I | re.UNICODE | re.VERBOSE)
class PGExecutionContext(default.DefaultExecutionContext):