]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- column labels in the form "tablename.columname", i.e. with a dot, are now
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 27 Nov 2007 16:57:56 +0000 (16:57 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 27 Nov 2007 16:57:56 +0000 (16:57 +0000)
supported.

CHANGES
lib/sqlalchemy/engine/base.py
test/sql/query.py

diff --git a/CHANGES b/CHANGES
index adb61906c2a52ce6d4b3055bc28cd8da55e41c85..9ff6189529bf89ce2143411f195ee8bd33027371 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -5,12 +5,15 @@ CHANGES
 -----
 - sql
     - added new flag to String and create_engine(), assert_unicode=(True|False|None).
-    When convert_unicode=True, this flag also defaults to `True`, and results in all 
-    unicode conversion operations raising an exception when a non-unicode bytestring
-    is passed as a bind parameter.  It is strongly advised that all unicode-aware
-    applications make proper use of Python unicode objects (i.e. u'hello' and 
-    not 'hello').
-    
+      When convert_unicode=True, this flag also defaults to `True`, and results in all 
+      unicode conversion operations raising an exception when a non-unicode bytestring
+      is passed as a bind parameter.  It is strongly advised that all unicode-aware
+      applications make proper use of Python unicode objects (i.e. u'hello' and 
+      not 'hello').
+
+    - column labels in the form "tablename.columname", i.e. with a dot, are now
+      supported.
+      
 - orm
 
    - fixed endless loop issue when using lazy="dynamic" on both 
index 9e30043253bc70d611f9af7277397b8721630cc5..4e6247810519df6d765e9a5f3405705d5eb6dc18 100644 (file)
@@ -1342,9 +1342,15 @@ class ResultProxy(object):
             typemap = self.dialect.dbapi_type_map
 
             for i, item in enumerate(metadata):
-                # sqlite possibly prepending table name to colnames so strip
-                colname = (item[0].split('.')[-1]).decode(self.dialect.encoding)
-
+                colname = item[0].decode(self.dialect.encoding)
+                
+                if '.' in colname:
+                    # sqlite will in some circumstances prepend table name to colnames, so strip
+                    origname = colname
+                    colname = colname.split('.')[-1]
+                else:
+                    origname = None
+                    
                 if self.context.result_map:
                     try:
                         (name, obj, type_) = self.context.result_map[colname]
@@ -1356,7 +1362,12 @@ class ResultProxy(object):
                 rec = (type_, type_.dialect_impl(self.dialect).result_processor(self.dialect), i)
 
                 if self.__props.setdefault(name.lower(), rec) is not rec:
-                    self.__props[name.lower()] = (type_, self.__ambiguous_processor(colname), 0)
+                    self.__props[name.lower()] = (type_, self.__ambiguous_processor(name), 0)
+                
+                # store the "origname" if we truncated (sqlite only)
+                if origname:
+                    if self.__props.setdefault(origname.lower(), rec) is not rec:
+                        self.__props[origname.lower()] = (type_, self.__ambiguous_processor(origname), 0)
                     
                 self.__keys.append(colname)
                 self.__props[i] = rec
index 7790b5f34a019346ad807f1a7e05355aa20ba531..fa88c5fe63cb64c5a0367b1b78fa8a5d059f1d1f 100644 (file)
@@ -361,6 +361,11 @@ class QueryTest(PersistTest):
             "UNION select query_users.user_id, query_users.user_name from query_users", bind=testbase.db).execute().fetchone()
         self.assert_(r['user_id']) == 1
         self.assert_(r['user_name']) == "john"
+
+        # test using literal tablename.colname
+        r = text('select query_users.user_id AS "query_users.user_id", query_users.user_name AS "query_users.user_name" from query_users', bind=testbase.db).execute().fetchone()
+        self.assert_(r['query_users.user_id']) == 1
+        self.assert_(r['query_users.user_name']) == "john"
         
 
     def test_ambiguous_column(self):