You can check which entries in user tables refer to an external media file. Use the DBxAdminIsFileReferenced API to check which entries in all or a subset of user tables in the current database refer to an external media file. Use the DBxIsFileReferenced API to check which entries in a specific user table refer to an external media file.
Using the API: The sample code in the following example returns the number of times a file is referenced and where it is referenced. It includes some error-checking code. The complete sample program is in the API.C file in the SAMPLES subdirectory.
Figure 14. Sample code that checks if a file is referenced by user tables
/*---- Query the database using DBiAdminIsFileReferenced API. ------*/ step="DBiAdminIsFileReferenced API"; rc = DBiAdminIsFileReferenced((char*) uid, filename, &count, &filelist); if (rc < 0) { printf("%s: %s FAILED!\n", program, step); printMsg(rc); DBiGetError(&sqlcode, errorMsgText); printf("sqlcode=%i, errorMsgText=%s\n", sqlcode, errorMsgText); } else if (rc > 0) { printf("%s: %s, warning detected.\n", program, step); printMsg(rc); DBiGetError(&sqlcode, errorMsgText); printf("sqlcode=%i, errorMsgText=%s\n", sqlcode, errorMsg Text); } else { if (count == 0) printf("%s: \"%s\" file is not referenced\n", program, filename); else { printf("%s: \"%s\" file is referenced %d times\n", program, filename); for (i=0; i < count; i++) { /* filename is NULL for any IsFileReferenced APIs */ printf ("filename = %s\n", filelist[i].filename); printf ("\tqualifier = %s\n", filelist[i].tqualifier); printf ("\ttable = %s\n", filelist[i].tname); printf ("\thandle = %s\n", filelist[i].handle); printf ("\tcolumn = %s\n", filelist[i].column); if (filelist[i].filename) free (filelist[i].filename); } } if (filelist) free (filelist); printf("%s: %s PASSED\n\n", argv[0], step); } |