Anonymous avatar Anonymous committed 43acd24

- *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.

Comments (0)

Files changed (4)

   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

lib/sqlalchemy/databases/oracle.py

         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"

test/sql/testtypes.py

     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)),
     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']))
         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):
             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':
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.