You are not logged in Log in Join
You are here: Home » Members » jim » ZODB » InsertAbortedVersionAsNew » wikipage_view

Log in
Name

Password

 
 
FrontPage » RelationalStorage » RelationalStorageSQLCallsByMethod »

InsertAbortedVersionAsNew

SELECT rec.z_oid, %s, rec.z_serial, c, 0, '', '', nv.z_dataserial
FROM %s rec, %s nv
WHERE rec.z_version = %s
AND rec.z_status = c
AND rec.z_data IS NULL
AND rec.z_dataserial != ''
AND rec.z_nv = nv.z_serial
AND rec.z_oid = nv.z_oid 
Feed that sql the serial, the name of the data table, the name of the data table again, and the version name.

for each row:

INSERT INTO %(data)s (z_oid, z_serial, z_pre, z_status, z_datalen, z_version, z_nv, z_dataserial) values (?, ?, ?, ?, ?, ?, ?, ?)


then select again a different set (interbase doesn't have an "if")

 SELECT rec.z_oid, %s, rec.z_serial,c,0,'','', nv.z_serial
              FROM %s rec, %s nv
              WHERE rec.z_version = %s
              AND rec.z_status = c
              AND rec.z_data IS NOT NULL
              AND rec.z_dataserial = ''
              AND rec.z_nv = nv.z_serial
              AND rec.z_oid = nv.z_oid 

for each row returned:
 INSERT INTO %(data)s
                 (z_oid, z_serial, z_pre, z_status, z_datalen, z_version, z_nv,
                 z_dataserial) values (?, ?, ?, ?, ?, ?, ?, ?) 

Then finally insert "ghost" records for version items that were created inside the version that need to be undone to:

 SELECT z_oid, %s, z_serial,g,0,'','', ''
              FROM %s
              WHERE z_version = %s
              AND z_status = c
              AND z_nv = '' "
For each record:

INSERT INTO %(data)s
                 (z_oid, z_serial, z_pre, z_status, z_datalen, z_version, z_nv,
                 z_dataserial) values (?, ?, ?, ?, ?, ?, ?, ?) 

These should all be insert-selects and should be combined into one or two queries if possible. Python logic should not be used to do this. I just couldn't get it to work otherwise and bailed.