Ticket #22769: code sample.txt

File code sample.txt, 1.1 KB (added by manish_kumar9@…, 7 years ago)

Code sample

Line 
1@transaction.atomic
2def fun():
3        insertSQL = """insert into my_blob (id, date_created, date_updated, filename, blob_data,blob_size) \
4                                                            values (appstore_blob_sq.nextval, :1, :2, :3, :blobd,:5)"""
5    self.cursor.execute(insertSQL,{'3':filename, '5' : filesize, 'blobd':blobd, '1' : dctime, '2' : dctime})
6    #retrieve blob_data from the row so that we can add chunks to the LOB
7        self.cursor.execute("select blob_data from appstore_blob where filename = :file_name for update of blob_data", file_name=filename)
8    for row in self.cursor:
9        offset = 0
10        lob = row[0]
11        writechunk_sz = lob.getchunksize()
12        #compute the read chunk size
13        factor = int(blob_writechunk_sz/writechunk_sz)
14        if factor > 0:
15            writechunk_sz *=  factor
16        lob.open()
17        while True:
18                chunk = filehandle.read(writechunk_sz)
19            chk_len = len(chunk)
20            #print "write chunk of sz: %s" % chk_len
21            if chunk is None or chunk == "":
22                break
23            lob.write(chunk, offset+1)
24            offset += chk_len
25         lob.close()
26         break
Back to Top