From: Mike Bayer Date: Tue, 23 Jan 2007 20:25:48 +0000 (+0000) Subject: - *slight* support for binary, but still need to figure out how to insert reasonably... X-Git-Tag: rel_0_3_4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8662333bbd20194ca3117835e7e1ca0bb4d3c0b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - *slight* support for binary, but still need to figure out how to insert reasonably large values (over 4K). requires auto_setinputsizes=True sent to create_engine(), rows must be fully fetched individually, etc. --- diff --git a/CHANGES b/CHANGES index 9ea810c6de..e279b85e94 100644 --- a/CHANGES +++ b/CHANGES @@ -52,6 +52,10 @@ required for firebird, not a bad idea for others [ticket:408] - Firebird fix to autoload multifield foreign keys [ticket:409] - Firebird NUMERIC type properly handles a type without precision [ticket:409] +- oracle: + - *slight* support for binary, but still need to figure out how to insert reasonably large + values (over 4K). requires auto_setinputsizes=True sent to create_engine(), rows must + be fully fetched individually, etc. - orm: - poked the first hole in the can of worms: saying query.select_by(somerelationname=someinstance) will create the join of the primary key columns represented by "somerelationname"'s mapper to the diff --git a/lib/sqlalchemy/databases/oracle.py b/lib/sqlalchemy/databases/oracle.py index 3f257a4608..6008ae61c9 100644 --- a/lib/sqlalchemy/databases/oracle.py +++ b/lib/sqlalchemy/databases/oracle.py @@ -62,11 +62,15 @@ class OracleBinary(sqltypes.Binary): return dbapi.BINARY def get_col_spec(self): return "BLOB" -class OracleLongBinary(sqltypes.Binary): - def get_dbapi_type(self, dbapi): - return dbapi.LONG_BINARY - def get_col_spec(self): - return "LONGBLOB" + def convert_bind_param(self, value, dialect): + # this is RAWTOHEX + return ''.join(["%.2X" % ord(c) for c in value]) + def convert_result_value(self, value, dialect): + if value is None: + return None + else: + return value.read() + class OracleBoolean(sqltypes.Boolean): def get_col_spec(self): return "SMALLINT" diff --git a/test/sql/testtypes.py b/test/sql/testtypes.py index 8889b7b34c..8606f1b74c 100644 --- a/test/sql/testtypes.py +++ b/test/sql/testtypes.py @@ -186,7 +186,7 @@ class BinaryTest(AssertMixin): def setUpAll(self): global binary_table binary_table = Table('binary_table', db, - Column('primary_id', Integer, primary_key=True), + Column('primary_id', Integer, Sequence('binary_id_seq', optional=True), primary_key=True), Column('data', Binary), Column('data_slice', Binary(100)), Column('misc', String(30)), @@ -199,16 +199,27 @@ class BinaryTest(AssertMixin): def tearDownAll(self): binary_table.drop() - @testbase.unsupported('oracle') def testbinary(self): testobj1 = pickleable.Foo('im foo 1') testobj2 = pickleable.Foo('im foo 2') - stream1 =self.load_stream('binary_data_one.dat') - stream2 =self.load_stream('binary_data_two.dat') + if db.name == 'oracle': + stream1 =self.load_stream('binary_data_one.dat', len=2000) + stream2 =self.load_stream('binary_data_two.dat', len=2000) + else: + stream1 =self.load_stream('binary_data_one.dat') + stream2 =self.load_stream('binary_data_two.dat') binary_table.insert().execute(primary_id=1, misc='binary_data_one.dat', data=stream1, data_slice=stream1[0:100], pickled=testobj1) binary_table.insert().execute(primary_id=2, misc='binary_data_two.dat', data=stream2, data_slice=stream2[0:99], pickled=testobj2) - l = binary_table.select().execute().fetchall() + if db.name == 'oracle': + res = binary_table.select().execute() + l = [] + row = res.fetchone() + l.append(dict([(k, row[k]) for k in row.keys()])) + row = res.fetchone() + l.append(dict([(k, row[k]) for k in row.keys()])) + else: + l = binary_table.select().execute().fetchall() print len(stream1), len(l[0]['data']), len(l[0]['data_slice']) self.assert_(list(stream1) == list(l[0]['data'])) self.assert_(list(stream1[0:100]) == list(l[0]['data_slice'])) @@ -216,10 +227,10 @@ class BinaryTest(AssertMixin): self.assert_(testobj1 == l[0]['pickled']) self.assert_(testobj2 == l[1]['pickled']) - def load_stream(self, name): + def load_stream(self, name, len=12579): f = os.path.join(os.path.dirname(testbase.__file__), name) # put a number less than the typical MySQL default BLOB size - return file(f).read(12579) + return file(f).read(len) class DateTest(AssertMixin): def setUpAll(self): diff --git a/test/testbase.py b/test/testbase.py index ed68efd4d2..360a02b320 100644 --- a/test/testbase.py +++ b/test/testbase.py @@ -73,7 +73,7 @@ def parse_argv(): db_uri = 'oracle://scott:tiger@127.0.0.1:1521' elif DBTYPE == 'oracle8': db_uri = 'oracle://scott:tiger@127.0.0.1:1521' - opts = {'use_ansi':False} + opts = {'use_ansi':False, 'auto_setinputsizes':True} elif DBTYPE == 'mssql': db_uri = 'mssql://scott:tiger@SQUAWK\\SQLEXPRESS/test' elif DBTYPE == 'firebird':