Subject Re: [Firebird-devel] Dump blobs from GDB file
Author Pierre Y.
Ann Harrison wrote:
> Pierre Y. wrote:
>> I've a hardly corrupted database. In this database I have a table
>> with a blob field. It's the only one blob field of the database. In
>> this blob field I store XML "packets". This is the only important
>> information I need to rebuild the database from scratch. How can I
>> develop an application to dump the contents of the whole blob pages
>> into a text file ?
> First, this is not a support list, so we probably should move to
> firebird-support. Second, if you're writting a C/C++ program,

Sorry Ann, thanks for your answer. I think it was about firebird development.
I won't develop in C/C++ but in Delphi, I don't think thatw would be a problem.

I'm anxious on the way to get the blob pages in the "right" order. ie. Record by record and not blob page by blob page. Do you have a tip to help me beginning that kind of development ?



[To others who reads that thread...]

> you'll, need to read the database page by page (e.g page size 4096,
> read 4096 bytes in a hunk. Look at the header file ods.h .
> The struct pag is the first thing on every page and the first byte in
> the page header is the type.
> typedef struct pag {
> SCHAR pag_type;
> SCHAR pag_flags;
> USHORT pag_checksum;
> ULONG pag_generation;
> ULONG pag_seqno; /* WAL seqno of last update */
> ULONG pag_offset; /* WAL offset of last update */
> } *PAG;
> Blob pages are type 8. The next definition in the header is the blp -
> blob page header. As you see, it includes the page header. You'll
> need
> to use the blp_lead_page and blp_sequence to identify which blob a
> page
> belongs to and where the page fits in the blob. The field blp_length
> tells you how many significant bytes the page contains. Those bytes
> start at blp_page.
> /* Blob page */
> typedef struct blp {
> struct pag blp_header;
> SLONG blp_lead_page; /* First page of blob (for redundancy
> only) */
> SLONG blp_sequence; /* Sequence within blob */
> USHORT blp_length; /* Bytes on page */
> USHORT blp_pad; /* Unused */
> SLONG blp_page[1]; /* Page number if level 1 */
> } *BLP;
> But that's not all. Since you almost certainly used segmented blobs,
> the data is stored in hunks that start with a two-byte hunk length.
> After you've got the significant bytes of a blob extracted, you need
> to
> find and eliminate the length bytes.
> Regards,
> Ann