Commits

jason kirtland  committed 485ef67

auto-commit after LOAD DATA INFILE for mysql
caught a couple more uncompiled regexps

  • Participants
  • Parent commits c89ad5d

Comments (0)

Files changed (3)

File lib/sqlalchemy/databases/mysql.py

      'read_only', 'read_write', # 5.1
      ])
 
+AUTOCOMMIT_RE = re.compile(
+    r'\s*(?:UPDATE|INSERT|CREATE|DELETE|DROP|ALTER|LOAD +DATA)',
+    re.I | re.UNICODE)
+SELECT_RE = re.compile(
+    r'\s*(?:SELECT|SHOW|DESCRIBE|XA RECOVER)',
+    re.I | re.UNICODE)
 
 class _NumericType(object):
     """Base for MySQL numeric types."""
 
 
 class MySQLExecutionContext(default.DefaultExecutionContext):
-    _my_is_select = re.compile(r'\s*(?:SELECT|SHOW|DESCRIBE|XA RECOVER)',
+    _my_is_select = re.compile(r'\s*(?:SELECT|SHOW|DESCRIBE|XA +RECOVER)',
                                re.I | re.UNICODE)
 
     def post_exec(self):
                                            self._last_inserted_ids[1:])
             
     def is_select(self):
-        return self._my_is_select.match(self.statement) is not None
+        return SELECT_RE.match(self.statement)
+
+    def should_autocommit(self):
+        return AUTOCOMMIT_RE.match(self.statement)
 
 
 class MySQLDialect(ansisql.ANSIDialect):

File lib/sqlalchemy/databases/sqlite.py

 import datetime,time, warnings
 import sqlalchemy.util as util
 
+
+SELECT_REGEXP = re.compile(r'\s*(?:SELECT|PRAGMA)', re.I | re.UNICODE)
     
 class SLNumeric(sqltypes.Numeric):
     def get_col_spec(self):
                 self._last_inserted_ids = [self.cursor.lastrowid] + self._last_inserted_ids[1:]
 
     def is_select(self):
-        return re.match(r'SELECT|PRAGMA', self.statement.lstrip(), re.I) is not None
+        return SELECT_REGEXP.match(self.statement)
         
 class SQLiteDialect(ansisql.ANSIDialect):
     

File lib/sqlalchemy/engine/default.py

 from sqlalchemy.engine import base
 
 
-AUTOCOMMIT_REGEXP = re.compile(r'UPDATE|INSERT|CREATE|DELETE|DROP|ALTER', re.I)
+AUTOCOMMIT_REGEXP = re.compile(r'\s*(?:UPDATE|INSERT|CREATE|DELETE|DROP|ALTER)',
+                               re.I | re.UNICODE)
+SELECT_REGEXP = re.compile(r'\s*SELECT', re.I | re.UNICODE)
 
 class DefaultDialect(base.Dialect):
     """Default implementation of Dialect"""
     def is_select(self):
         """return TRUE if the statement is expected to have result rows."""
         
-        return re.match(r'SELECT', self.statement.lstrip(), re.I) is not None
+        return SELECT_REGEXP.match(self.statement)
 
     def create_cursor(self):
         return self._connection.connection.cursor()
         return self.get_result_proxy()
 
     def should_autocommit(self):
-        return AUTOCOMMIT_REGEXP.match(self.statement.lstrip())
+        return AUTOCOMMIT_REGEXP.match(self.statement)
             
     def pre_exec(self):
         self._process_defaults()