]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- The IdentifierPreprarer's _requires_quotes test is now regex based.
authorJason Kirtland <jek@discorporate.us>
Thu, 27 Sep 2007 17:23:41 +0000 (17:23 +0000)
committerJason Kirtland <jek@discorporate.us>
Thu, 27 Sep 2007 17:23:41 +0000 (17:23 +0000)
  Any out-of-tree dialects that provide custom sets of legal_characters
  or illegal_initial_characters will need to move to regexes or override
  _requires_quotes.

CHANGES
lib/sqlalchemy/sql/compiler.py
test/profiling/zoomark.py

diff --git a/CHANGES b/CHANGES
index 35baf8da678d607490993a8957eb5e6151e66c3d..81f98617b5d7629ff7069cbac6edd8fc085d7268 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,14 @@
 CHANGES
 =======
 
+0.4.0beta7
+----------
+
+- The IdentifierPreprarer's _requires_quotes test is now regex based.  Any
+  out-of-tree dialects that provide custom sets of legal_characters or
+  illegal_initial_characters will need to move to regexes or override
+  _requires_quotes.
+
 0.4.0beta6
 ----------
 
index 4fca6b2eccb55650b5d6ef7358be37d940d7ea3d..6d22da1dedde6056da3684eeba973d6739463bb3 100644 (file)
@@ -36,10 +36,8 @@ RESERVED_WORDS = util.Set([
     'then', 'to', 'trailing', 'true', 'union', 'unique', 'user',
     'using', 'verbose', 'when', 'where'])
 
-LEGAL_CHARACTERS = util.Set(string.ascii_lowercase +
-                            string.ascii_uppercase +
-                            string.digits + '_$')
-ILLEGAL_INITIAL_CHARACTERS = util.Set(string.digits + '$')
+LEGAL_CHARACTERS = re.compile(r'^[A-Z0-9_$]+$', re.I)
+ILLEGAL_INITIAL_CHARACTERS = re.compile(r'[0-9$]')
 
 BIND_PARAMS = re.compile(r'(?<![:\w\$\x5c]):([\w\$]+)(?![:\w\$])', re.UNICODE)
 BIND_PARAMS_ESC = re.compile(r'\x5c(:[\w\$]+)(?![:\w\$])', re.UNICODE)
@@ -979,11 +977,11 @@ class IdentifierPreparer(object):
 
     def _requires_quotes(self, value):
         """Return True if the given identifier requires quoting."""
-        return \
-            value in self.reserved_words \
-            or (value[0] in self.illegal_initial_characters) \
-            or bool(len([x for x in unicode(value) if x not in self.legal_characters])) \
-            or (value.lower() != value)
+        lc_value = value.lower()
+        return (lc_value in self.reserved_words
+                or self.illegal_initial_characters.match(value[0])
+                or not self.legal_characters.match(unicode(value))
+                or (lc_value != value))
 
     def __generic_obj_format(self, obj, ident):
         if getattr(obj, 'quote', False):
index 305e2a3d99ff03cc4cfff8e54d7e5f9e6f908ee5..410c7756f56add3cd872100020fddf4d285620d0 100644 (file)
@@ -143,7 +143,7 @@ class ZooMarkTest(testing.AssertMixin):
             ticks = fullobject(Animal.select(Animal.c.Species=='Tick'))
     
     @testing.supported('postgres')
-    @profiling.profiled('expressions', call_range=(13210, 13230), always=True)        
+    @profiling.profiled('expressions', call_range=(12595, 12605), always=True)        
     def test_4_expressions(self):
         Zoo = metadata.tables['Zoo']
         Animal = metadata.tables['Animal']
@@ -197,7 +197,7 @@ class ZooMarkTest(testing.AssertMixin):
             assert len(fulltable(Animal.select(func.date_part('day', Animal.c.LastEscape) == 21))) == 1
     
     @testing.supported('postgres')
-    @profiling.profiled('aggregates', call_range=(1260, 1270), always=True)        
+    @profiling.profiled('aggregates', call_range=(1220, 1230), always=True)        
     def test_5_aggregates(self):
         Animal = metadata.tables['Animal']
         Zoo = metadata.tables['Zoo']
@@ -268,7 +268,7 @@ class ZooMarkTest(testing.AssertMixin):
             assert SDZ['Founded'] == datetime.date(1935, 9, 13)
     
     @testing.supported('postgres')
-    @profiling.profiled('multiview', call_range=(3150, 3160), always=True)        
+    @profiling.profiled('multiview', call_range=(3090, 3100), always=True)        
     def test_7_multiview(self):
         Zoo = metadata.tables['Zoo']
         Animal = metadata.tables['Animal']