[Checkins] SVN: relstorage/trunk/relstorage/adapters/ The tests pass. Oracle can now store blobs in the database.

Shane Hathaway shane at hathawaymix.org
Wed Oct 20 05:06:42 EDT 2010


Log message for revision 117794:
  The tests pass.  Oracle can now store blobs in the database.
  

Changed:
  U   relstorage/trunk/relstorage/adapters/mover.py
  U   relstorage/trunk/relstorage/adapters/oracle.py

-=-
Modified: relstorage/trunk/relstorage/adapters/mover.py
===================================================================
--- relstorage/trunk/relstorage/adapters/mover.py	2010-10-20 08:13:31 UTC (rev 117793)
+++ relstorage/trunk/relstorage/adapters/mover.py	2010-10-20 09:06:41 UTC (rev 117794)
@@ -21,6 +21,7 @@
 from relstorage.adapters.batch import OracleRowBatcher
 from relstorage.adapters.batch import PostgreSQLRowBatcher
 from zope.interface import implements
+import os
 
 try:
     from hashlib import md5
@@ -994,18 +995,26 @@
             chunk_num = 0
             while True:
                 if self.database_name == 'oracle':
-                    chunk = self.runner.run_lob_stmt(
+                    row = self.runner.run_lob_stmt(
                         cursor, stmt, (oid, tid, chunk_num))
+                    if row is not None:
+                        chunk = row[0] or ''
+                    else:
+                        chunk = None
                 else:
                     cursor.execute(stmt, (oid, tid, chunk_num))
                     rows = list(cursor)
-                    if not rows:
-                        # No more chunks.  Note: if there are no chunks at
-                        # all, then this method should not write a file.
-                        break
-                    assert len(rows) == 1
-                    chunk = rows[0][0]
+                    if rows:
+                        assert len(rows) == 1
+                        chunk = rows[0][0]
+                    else:
+                        chunk = None
 
+                if chunk is None:
+                    # No more chunks.  Note: if there are no chunks at
+                    # all, then this method should not write a file.
+                    break
+
                 if use_base64:
                     chunk = decodestring(chunk)
                 if f is None:
@@ -1036,26 +1045,21 @@
         If serial is None, upload to the temporary table.
         """
         if tid is not None:
-            use_tid = True
             if self.keep_history:
                 delete_stmt = """
                 DELETE FROM blob_chunk
                 WHERE zoid = %s AND tid = %s
                 """
                 cursor.execute(delete_stmt, (oid, tid))
-
-                insert_stmt = """
-                INSERT INTO blob_chunk (zoid, tid, chunk_num, chunk)
-                VALUES (%s, %s, %s, CHUNK)
-                """
             else:
                 delete_stmt = "DELETE FROM blob_chunk WHERE zoid = %s"
                 cursor.execute(delete_stmt, (oid,))
 
-                insert_stmt = """
-                INSERT INTO blob_chunk (zoid, tid, chunk_num, chunk)
-                VALUES (%s, %s, %s, CHUNK)
-                """
+            use_tid = True
+            insert_stmt = """
+            INSERT INTO blob_chunk (zoid, tid, chunk_num, chunk)
+            VALUES (%s, %s, %s, CHUNK)
+            """
         else:
             use_tid = False
             delete_stmt = "DELETE FROM temp_blob_chunk WHERE zoid = %s"
@@ -1103,30 +1107,26 @@
         If serial is None, upload to the temporary table.
         """
         if tid is not None:
-            use_tid = True
             if self.keep_history:
                 delete_stmt = """
                 DELETE FROM blob_chunk
                 WHERE zoid = :1 AND tid = :2
                 """
                 cursor.execute(delete_stmt, (oid, tid))
-
-                insert_stmt = """
-                INSERT INTO blob_chunk (zoid, tid, chunk_num, chunk)
-                VALUES (:oid, :tid, :chunk_num, :blobdata)
-                """
             else:
                 delete_stmt = "DELETE FROM blob_chunk WHERE zoid = :1"
                 cursor.execute(delete_stmt, (oid,))
 
-                insert_stmt = """
-                INSERT INTO blob_chunk (zoid, tid, chunk_num, chunk)
-                VALUES (:oid, :tid, :chunk_num, :blobdata)
-                """
+            use_tid = True
+            insert_stmt = """
+            INSERT INTO blob_chunk (zoid, tid, chunk_num, chunk)
+            VALUES (:oid, :tid, :chunk_num, :blobdata)
+            """
+
         else:
             use_tid = False
             delete_stmt = "DELETE FROM temp_blob_chunk WHERE zoid = :1"
-            delete_args = (oid,)
+            cursor.execute(delete_stmt, (oid,))
 
             insert_stmt = """
             INSERT INTO temp_blob_chunk (zoid, chunk_num, chunk)
@@ -1149,7 +1149,8 @@
                 }
                 if use_tid:
                     params['tid'] = tid
-                cursor.execute(stmt, params)
+                cursor.setinputsizes(blobdata=self.inputsizes['blobdata'])
+                cursor.execute(insert_stmt, params)
                 chunk_num += 1
         finally:
             f.close()

Modified: relstorage/trunk/relstorage/adapters/oracle.py
===================================================================
--- relstorage/trunk/relstorage/adapters/oracle.py	2010-10-20 08:13:31 UTC (rev 117793)
+++ relstorage/trunk/relstorage/adapters/oracle.py	2010-10-20 09:06:41 UTC (rev 117794)
@@ -102,6 +102,7 @@
                 'oid': cx_Oracle.NUMBER,
                 'tid': cx_Oracle.NUMBER,
                 'prev_tid': cx_Oracle.NUMBER,
+                'chunk_num': cx_Oracle.NUMBER,
                 'md5sum': cx_Oracle.STRING,
                 },
             )



More information about the checkins mailing list