[Checkins] SVN: relstorage/branches/postgres_blob_oid/relstorage/adapters/mover.py We'll create postgresql-specific versions of the up- and download blob methods.
Martijn Pieters
mj at zopatista.com
Sun Jun 12 09:30:48 EDT 2011
Log message for revision 121923:
We'll create postgresql-specific versions of the up- and download blob methods.
Changed:
U relstorage/branches/postgres_blob_oid/relstorage/adapters/mover.py
-=-
Modified: relstorage/branches/postgres_blob_oid/relstorage/adapters/mover.py
===================================================================
--- relstorage/branches/postgres_blob_oid/relstorage/adapters/mover.py 2011-06-12 13:18:54 UTC (rev 121922)
+++ relstorage/branches/postgres_blob_oid/relstorage/adapters/mover.py 2011-06-12 13:30:48 UTC (rev 121923)
@@ -992,8 +992,11 @@
- def generic_download_blob(self, cursor, oid, tid, filename):
+ def postgresql_download_blob(self, cursor, oid, tid, filename):
"""Download a blob into a file."""
+
+ def mysql_download_blob(self, cursor, oid, tid, filename):
+ """Download a blob into a file."""
stmt = """
SELECT chunk
FROM blob_chunk
@@ -1002,12 +1005,6 @@
AND chunk_num = %s
"""
- use_base64 = False
- if self.database_name == 'postgresql':
- use_base64 = True
- stmt = stmt.replace(
- "SELECT chunk", "SELECT encode(chunk, 'base64')")
-
f = None
bytes = 0
try:
@@ -1023,8 +1020,6 @@
# all, then this method should not write a file.
break
- if use_base64:
- chunk = decodestring(chunk)
if f is None:
f = open(filename, 'wb')
f.write(chunk)
@@ -1040,9 +1035,6 @@
f.close()
return bytes
- mysql_download_blob = generic_download_blob
- postgresql_download_blob = generic_download_blob
-
def oracle_download_blob(self, cursor, oid, tid, filename):
"""Download a blob into a file."""
stmt = """
@@ -1104,11 +1096,17 @@
- def generic_upload_blob(self, cursor, oid, tid, filename):
+ def postgresql_upload_blob(self, cursor, oid, tid, filename):
"""Upload a blob from a file.
If serial is None, upload to the temporary table.
"""
+
+ def mysql_upload_blob(self, cursor, oid, tid, filename):
+ """Upload a blob from a file.
+
+ If serial is None, upload to the temporary table.
+ """
if tid is not None:
if self.keep_history:
delete_stmt = """
@@ -1123,7 +1121,7 @@
use_tid = True
insert_stmt = """
INSERT INTO blob_chunk (zoid, tid, chunk_num, chunk)
- VALUES (%s, %s, %s, CHUNK)
+ VALUES (%s, %s, %s, %s)
"""
else:
use_tid = False
@@ -1132,17 +1130,9 @@
insert_stmt = """
INSERT INTO temp_blob_chunk (zoid, chunk_num, chunk)
- VALUES (%s, %s, CHUNK)
+ VALUES (%s, %s, %s)
"""
- use_base64 = False
- if self.database_name == 'postgresql':
- use_base64 = True
- insert_stmt = insert_stmt.replace(
- "CHUNK", "decode(%s, 'base64')", 1)
- else:
- insert_stmt = insert_stmt.replace("CHUNK", "%s")
-
f = open(filename, 'rb')
try:
chunk_num = 0
@@ -1152,8 +1142,6 @@
# EOF. Note that we always write at least one
# chunk, even if the blob file is empty.
break
- if use_base64:
- chunk = encodestring(chunk)
if use_tid:
params = (oid, tid, chunk_num, chunk)
else:
@@ -1163,9 +1151,6 @@
finally:
f.close()
- mysql_upload_blob = generic_upload_blob
- postgresql_upload_blob = generic_upload_blob
-
def oracle_upload_blob(self, cursor, oid, tid, filename):
"""Upload a blob from a file.
More information about the checkins
mailing list