From: Ants Aasma Date: Wed, 3 Oct 2007 01:06:07 +0000 (+0000) Subject: Made the regexp detecting the returning token more readable and fixed a couple of... X-Git-Tag: rel_0_4_0~77 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c25fa30febb2fc7ac21fe1379ee03595c7c6a8b6;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Made the regexp detecting the returning token more readable and fixed a couple of corner cases --- diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index 03b3fd042f..990140c891 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[^$]*)\\$.*?\\$(?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[^$]*)\$.*?\$(?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):