]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Made the regexp detecting the returning token more readable and fixed a couple of...
authorAnts Aasma <ants.aasma@gmail.com>
Wed, 3 Oct 2007 01:06:07 +0000 (01:06 +0000)
committerAnts Aasma <ants.aasma@gmail.com>
Wed, 3 Oct 2007 01:06:07 +0000 (01:06 +0000)
lib/sqlalchemy/databases/postgres.py

index 03b3fd042f15048a64fd1714b3cd9c483954888c..990140c891413d643b0d00acba15b6a942296a69 100644 (file)
@@ -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):