Пример #1
0
    def encode_bytes_param(value, use_base64):
        if isinstance(value, str):
            value = value.encode('ascii')
        if use_base64:
            value = encodestring(value)

        return value
Пример #2
0
 def postgresql_store_temp(self, cursor, batcher, oid, prev_tid, data):
     """Store an object in the temporary table."""
     if self.keep_history:
         md5sum = compute_md5sum(data)
     else:
         md5sum = None
     batcher.delete_from('temp_store', zoid=oid)
     batcher.insert_into(
         "temp_store (zoid, prev_tid, md5, state)",
         "%s, %s, %s, decode(%s, 'base64')",
         (oid, prev_tid, md5sum, encodestring(data)),
         rowkey=oid,
         size=len(data),
     )
Пример #3
0
 def postgresql_store_temp(self, cursor, batcher, oid, prev_tid, data):
     """Store an object in the temporary table."""
     if self.keep_history:
         md5sum = compute_md5sum(data)
     else:
         md5sum = None
     batcher.delete_from('temp_store', zoid=oid)
     batcher.insert_into(
         "temp_store (zoid, prev_tid, md5, state)",
         "%s, %s, %s, decode(%s, 'base64')",
         (oid, prev_tid, md5sum, encodestring(data)),
         rowkey=oid,
         size=len(data),
     )
Пример #4
0
    def postgresql_replace_temp(self, cursor, oid, prev_tid, data):
        """Replace an object in the temporary table.

        This happens after conflict resolution.
        """
        if self.keep_history:
            md5sum = compute_md5sum(data)
        else:
            md5sum = None
        stmt = """
        UPDATE temp_store SET
            prev_tid = %s,
            md5 = %s,
            state = decode(%s, 'base64')
        WHERE zoid = %s
        """
        cursor.execute(stmt, (prev_tid, md5sum, encodestring(data), oid))
Пример #5
0
    def postgresql_replace_temp(self, cursor, oid, prev_tid, data):
        """Replace an object in the temporary table.

        This happens after conflict resolution.
        """
        if self.keep_history:
            md5sum = compute_md5sum(data)
        else:
            md5sum = None
        stmt = """
        UPDATE temp_store SET
            prev_tid = %s,
            md5 = %s,
            state = decode(%s, 'base64')
        WHERE zoid = %s
        """
        cursor.execute(stmt, (prev_tid, md5sum, encodestring(data), oid))
Пример #6
0
    def postgresql_restore(self, cursor, batcher, oid, tid, data):
        """Store an object directly, without conflict detection.

        Used for copying transactions into this database.
        """
        if self.keep_history:
            md5sum = compute_md5sum(data)
        else:
            md5sum = None

        if data is not None:
            encoded = encodestring(data)
            size = len(data)
        else:
            encoded = None
            size = 0

        if self.keep_history:
            batcher.delete_from("object_state", zoid=oid, tid=tid)
            row_schema = """
                %s, %s,
                COALESCE((SELECT tid FROM current_object WHERE zoid = %s), 0),
                %s, %s, decode(%s, 'base64')
            """
            batcher.insert_into(
                "object_state (zoid, tid, prev_tid, md5, state_size, state)",
                row_schema,
                (oid, tid, oid, md5sum, size, encoded),
                rowkey=(oid, tid),
                size=size,
            )
        else:
            batcher.delete_from('object_state', zoid=oid)
            if data:
                batcher.insert_into(
                    "object_state (zoid, tid, state_size, state)",
                    "%s, %s, %s, decode(%s, 'base64')",
                    (oid, tid, size, encoded),
                    rowkey=oid,
                    size=size,
                )
Пример #7
0
    def postgresql_restore(self, cursor, batcher, oid, tid, data):
        """Store an object directly, without conflict detection.

        Used for copying transactions into this database.
        """
        if self.keep_history:
            md5sum = compute_md5sum(data)
        else:
            md5sum = None

        if data is not None:
            encoded = encodestring(data)
            size = len(data)
        else:
            encoded = None
            size = 0

        if self.keep_history:
            batcher.delete_from("object_state", zoid=oid, tid=tid)
            row_schema = """
                %s, %s,
                COALESCE((SELECT tid FROM current_object WHERE zoid = %s), 0),
                %s, %s, decode(%s, 'base64')
            """
            batcher.insert_into(
                "object_state (zoid, tid, prev_tid, md5, state_size, state)",
                row_schema,
                (oid, tid, oid, md5sum, size, encoded),
                rowkey=(oid, tid),
                size=size,
            )
        else:
            batcher.delete_from('object_state', zoid=oid)
            if data:
                batcher.insert_into(
                    "object_state (zoid, tid, state_size, state)",
                    "%s, %s, %s, decode(%s, 'base64')",
                    (oid, tid, size, encoded),
                    rowkey=oid,
                    size=size,
                )
Пример #8
0
    def encode_bytes_param(value, use_base64):
        if use_base64:
            value = encodestring(value)

        return value