====== pears.DBCleanupOrphanBlobstore ====== Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace. ===== Original SQL ===== create function "pears"."DBCleanupOrphanBlobstore"( /* Application Maintained Function / Procedure - DO NOT EDIT*/ in "countordo" char(1) ) returns integer begin declare @RC integer; set @RC = 0; if "countordo" = 'C' then select "count"() into @RC from "Blobstore" where(((("class" = 'V') or("class" = 'J')) and not exists(select * from "person" where "personid" = "Blobstore"."id")) or(("class" = 'O') and not exists(select * from "OLEDocument" where "OLEDocumentid" = "Blobstore"."id")) or(("class" = 'L') and not exists(select * from "Contactevent" where "Contacteventid" = "Blobstore"."id")) or(("class" = 'M') and not exists(select * from "MailMerge" where "MailMergeid" = "Blobstore"."id")) or(("class" = 'T') and not exists(select * from "TemplateStore" where "Templateid" = "Blobstore"."id"))); return @RC end if; delete from "Blobstore" where(("class" = 'V') or("class" = 'J')) and not exists(select * from "person" where "personid" = "Blobstore"."id"); set @RC = @RC+(select @@rowcount); delete from "Blobstore" where("class" = 'O') and not exists(select * from "OLEDocument" where "OLEDocumentid" = "Blobstore"."id"); set @RC = @RC+(select @@rowcount); delete from "Blobstore" where("class" = 'L') and not exists(select * from "ContactEvent" where "Contacteventid" = "Blobstore"."id"); set @RC = @RC+(select @@rowcount); delete from "Blobstore" where("class" = 'M') and not exists(select * from "MailMerge" where "MailMergeid" = "Blobstore"."id"); set @RC = @RC+(select @@rowcount); delete from "Blobstore" where("class" = 'T') and not exists(select * from "TemplateStore" where "Templateid" = "Blobstore"."id"); set @RC = @RC+(select @@rowcount); call "AuditLog"('CLEANUP',null,"string"(@RC,' Unattached Blobstore Records deleted '),null,null); return @RC end