Mike Bayer avatar Mike Bayer committed 255b24e

fix up oracle handling of LOB/string [ticket:902], slight fixes to defaults.py but we
will need to fix up result-type handling some more

Comments (0)

Files changed (4)

    - oracle
       - added disconnect detection support for Oracle
+      - some cleanup to binary/raw types so that cx_oracle.LOB is detected
+        on an ad-hoc basis [ticket:902]
    - MSSQL
       - PyODBC no longer has a global "set nocount on".


     def result_processor(self, dialect):
         super_process = super(OracleText, self).result_processor(dialect)
+        lob = dialect.dbapi.LOB
         def process(value):
-            if value is None:
-                return None
-            elif hasattr(value, 'read'):
-                # cx_oracle doesnt seem to be consistent with CLOB returning LOB or str
+            if isinstance(value, lob):
                 if super_process:
                     return super_process(value.read())
         return None
     def result_processor(self, dialect):
+        lob = dialect.dbapi.LOB
         def process(value):
-            if value is None:
-                return None
+            if isinstance(value, lob):
+                return value.read()
-                return value.read()
+                return value
         return process
 class OracleBoolean(sqltypes.Boolean):


         b = bindparam("foo", u"hello world!")
         assert b.type.dialect_impl(dialect).get_dbapi_type(dbapi) == 'STRING'
+    def test_reflect_raw(self):
+        types_table = Table(
+        'all_types', MetaData(testbase.db),
+            Column('owner', String(30), primary_key=True),
+            Column('type_name', String(30), primary_key=True),
+            autoload=True,
+            )
+        [[row[k] for k in row.keys()] for row in types_table.select().execute().fetchall()]
     def test_longstring(self):
         metadata = MetaData(testbase.db)


         currenttime = func.current_date(type_=Date, bind=db)
         if is_oracle:
-            ts = db.func.trunc(func.sysdate(), literal_column("'DAY'")).scalar()
+            ts = db.scalar(select([func.trunc(func.sysdate(), literal_column("'DAY'"), type_=Date).label('today')]))
+            assert isinstance(ts, datetime.date) and not isinstance(ts, datetime.datetime)
             f = select([func.length('abcdef')], bind=db).scalar()
             f2 = select([func.length('abcdefghijk')], bind=db).scalar()
             # TODO: engine propigation across nested functions not working
-            currenttime = func.trunc(currenttime, literal_column("'DAY'"), bind=db)
+            currenttime = func.trunc(currenttime, literal_column("'DAY'"), bind=db, type_=Date)
             def1 = currenttime
-            def2 = func.trunc(text("sysdate"), literal_column("'DAY'"))
+            def2 = func.trunc(text("sysdate"), literal_column("'DAY'"), type_=Date)
             deftype = Date
         elif use_function_defaults:
             f = select([func.length('abcdef')], bind=db).scalar()
-        ctexec = currenttime.scalar()
+        ctexec = select([currenttime.label('now')], bind=testbase.db).scalar()
         l = t.select().execute()
         today = datetime.date.today()
-        self.assert_(l.fetchall() == [
+        self.assertEquals(l.fetchall(), [
             (51, 'imthedefault', f, ts, ts, ctexec, True, False, 12, today),
             (52, 'imthedefault', f, ts, ts, ctexec, True, False, 12, today),
             (53, 'imthedefault', f, ts, ts, ctexec, True, False, 12, today),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.