changeset 65:7a60c4574baf MySQLdb

figleaf revealed that the INSERT_VALUES regex never matched. Added a test for this, and fixed the regex (forgot to add group anchors)
author adustman
date Sun, 29 Mar 2009 00:52:14 +0000
parents 2d6a35051f64
children 5a7c30cd9de2
files MySQLdb/cursors.py tests/test_MySQLdb_capabilities.py
diffstat 2 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MySQLdb/cursors.py	Sat Mar 28 13:37:58 2009 +0000
+++ b/MySQLdb/cursors.py	Sun Mar 29 00:52:14 2009 +0000
@@ -14,11 +14,9 @@
 import sys
 import weakref
 
-INSERT_VALUES = re.compile(r"\svalues\s*"
-                           r"(\(((?<!\\)'[^\)]*?\)[^\)]*(?<!\\)?'"
-                           r"|[^\(\)]|"
-                           r"(?:\([^\)]*\))"
-                           r")+\))")
+INSERT_VALUES = re.compile(r"(?P<start>.+values\s*)"
+                           r"(?P<values>\(((?<!\\)'[^\)]*?\)[^\)]*(?<!\\)?'|[^\(\)]|(?:\([^\)]*\)))+\))"
+                           r"(?P<end>.*)", re.I)
 
 
 class Cursor(object):
--- a/tests/test_MySQLdb_capabilities.py	Sat Mar 28 13:37:58 2009 +0000
+++ b/tests/test_MySQLdb_capabilities.py	Sun Mar 29 00:52:14 2009 +0000
@@ -81,6 +81,18 @@
         except self.connection.ProgrammingError, msg:
             self.failUnless(msg[0] == ER.NO_SUCH_TABLE)
     
+    def test_INSERT_VALUES(self):
+        from MySQLdb.cursors import INSERT_VALUES
+        query = """INSERT FOO (a, b, c) VALUES (%s, %s, %s)"""
+        matched = INSERT_VALUES.match(query)
+        self.failUnless(matched)
+        start = matched.group('start')
+        end = matched.group('end')
+        values = matched.group('values')
+        self.failUnless(start == """INSERT FOO (a, b, c) VALUES """)
+        self.failUnless(values == "(%s, %s, %s)")
+        self.failUnless(end == "")
+        
     def test_ping(self):
         self.connection.ping()