]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- usage of the CHAR type results in cx_oracle's
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 3 Oct 2009 19:58:19 +0000 (19:58 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 3 Oct 2009 19:58:19 +0000 (19:58 +0000)
FIXED_CHAR dbapi type being bound to statements.

CHANGES
lib/sqlalchemy/dialects/oracle/cx_oracle.py
test/dialect/test_oracle.py

diff --git a/CHANGES b/CHANGES
index c3380c0741da40efa00e5b687d780b812c779c01..372496f0a40b639fafc33de8fa7f7d7fce35c0b0 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -288,7 +288,10 @@ CHANGES
       later of cx_oracle.
 
     - an NCLOB type is added to the base types.
-
+    
+    - usage of the CHAR type results in cx_oracle's 
+      FIXED_CHAR dbapi type being bound to statements.
+      
     - the Oracle dialect now features NUMBER which intends
       to act justlike Oracle's NUMBER type.  It is the primary
       numeric type returned by table reflection and attempts
index f4092359142f30d47d41735b90a9d3b2fc88c4e0..721c455884ae7a915709438493468dc5cfff9b41 100644 (file)
@@ -139,6 +139,10 @@ class _LOBMixin(object):
                 else:
                     return value
         return process
+
+class _OracleChar(sqltypes.CHAR):
+    def get_dbapi_type(self, dbapi):
+        return dbapi.FIXED_CHAR
     
 class _OracleText(_LOBMixin, sqltypes.Text):
     def get_dbapi_type(self, dbapi):
@@ -176,10 +180,12 @@ colspecs = {
     sqltypes.Text : _OracleText,
     sqltypes.UnicodeText : _OracleUnicodeText,
     sqltypes.TIMESTAMP : _OracleTimestamp,
+    sqltypes.CHAR : _OracleChar,
     sqltypes.Integer : _OracleInteger,  # this is only needed for OUT parameters.
                                         # it would be nice if we could not use it otherwise.
     oracle.NUMBER : oracle.NUMBER, # don't let this get converted
     oracle.RAW: _OracleRaw,
+    
 }
 
 class Oracle_cx_oracleCompiler(OracleCompiler):
index 1701c72807efda1b72502472cb99ffe3e51fddcc..3296f47fce66dbff5dd84bd4a20dd74e73651a84 100644 (file)
@@ -346,7 +346,36 @@ class TypesTest(TestBase, AssertsCompiledSQL):
 
         b = bindparam("foo", u"hello world!")
         assert b.type.dialect_impl(dialect).get_dbapi_type(dbapi) == 'STRING'
+    
+    def test_fixed_char(self):
+        m = MetaData(testing.db)
+        t = Table('t1', m, 
+            Column('id', Integer, primary_key=True),
+            Column('data', CHAR(30), nullable=False)
+        )
+        
+        t.create()
+        try:
+            t.insert().execute(
+                dict(id=1, data="value 1"),
+                dict(id=2, data="value 2"),
+                dict(id=3, data="value 3")
+            )
 
+            eq_(t.select().where(t.c.data=='value 2').execute().fetchall(), 
+                [(2, 'value 2                       ')]
+                )
+                
+            m2 = MetaData(testing.db)
+            t2 = Table('t1', m2, autoload=True)
+            assert type(t2.c.data.type) is CHAR
+            eq_(t2.select().where(t2.c.data=='value 2').execute().fetchall(), 
+                [(2, 'value 2                       ')]
+                )
+            
+        finally:
+            t.drop()
+        
     def test_type_adapt(self):
         dialect = cx_oracle.dialect()