summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-01-01 00:43:24 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-01-01 00:43:24 +0000
commit65c618534ff5c6401d1e6f6318e3e4c6b1516204 (patch)
tree3ecfd57636e6ebec648b9d397200cb2537f773a7
parent85ab0501f46b473e4283dd2df9f9b74a89ad9021 (diff)
downloadsqlalchemy-65c618534ff5c6401d1e6f6318e3e4c6b1516204.tar.gz
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
-rw-r--r--CHANGES2
-rw-r--r--lib/sqlalchemy/databases/oracle.py13
-rw-r--r--test/dialect/oracle.py9
-rw-r--r--test/sql/defaults.py12
4 files changed, 24 insertions, 12 deletions
diff --git a/CHANGES b/CHANGES
index 402ef6e6e..b552745ab 100644
--- a/CHANGES
+++ b/CHANGES
@@ -273,6 +273,8 @@ CHANGES
- 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".
diff --git a/lib/sqlalchemy/databases/oracle.py b/lib/sqlalchemy/databases/oracle.py
index c57ed006c..99cfbbb3a 100644
--- a/lib/sqlalchemy/databases/oracle.py
+++ b/lib/sqlalchemy/databases/oracle.py
@@ -95,11 +95,9 @@ class OracleText(sqltypes.TEXT):
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())
else:
@@ -130,11 +128,12 @@ class OracleBinary(sqltypes.Binary):
return None
def result_processor(self, dialect):
+ lob = dialect.dbapi.LOB
def process(value):
- if value is None:
- return None
- else:
+ if isinstance(value, lob):
return value.read()
+ else:
+ return value
return process
class OracleBoolean(sqltypes.Boolean):
diff --git a/test/dialect/oracle.py b/test/dialect/oracle.py
index c9c19f045..64f86329e 100644
--- a/test/dialect/oracle.py
+++ b/test/dialect/oracle.py
@@ -147,6 +147,15 @@ class TypesTest(SQLCompileTest):
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)
testbase.db.execute("""
diff --git a/test/sql/defaults.py b/test/sql/defaults.py
index bce499686..a67eea894 100644
--- a/test/sql/defaults.py
+++ b/test/sql/defaults.py
@@ -40,13 +40,15 @@ class DefaultTest(PersistTest):
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()
@@ -146,10 +148,10 @@ class DefaultTest(PersistTest):
t.insert().execute()
t.insert().execute()
- 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),