Writing Data to a Blob

From InterBase

Go Up to Blob Data Operations

Before you can create a new Blob and write data to it, you must do at least one of the ­following:

  • Include Blob data in a row to be inserted into a table.
  • Replace the data referenced by a Blob column of a row.
  • Update the data referenced by a Blob column of a row.

The entry in a Blob column of a row does not actually contain Blob data. Rather, it has a Blob ID referring to the data, which is stored elsewhere. So, to set or modify a Blob column, you need to set (or reset) the Blob ID stored in it. If a Blob column contains a Blob ID, and you modify the column to refer to a different Blob (or to contain NULL), the Blob referenced by the previously stored Blob ID will be deleted during the next garbage collection.

These operations all require the following steps:

  1. Prepare an appropriate DSQL statement. This will be an INSERT statement if you are inserting a new row into a table, or an UPDATE statement for modifying a row. Each of these statements will need a corresponding input XSQLDA structure for supplying parameter values to the statement at run time. The Blob ID of a new Blob will be one of the values passed.
  2. Create a new Blob, and write data into it.
  3. Associate the Blob ID of the new Blob with the Blob column of the table row by executing the UPDATE or INSERT statement.

Note that you cannot update Blob data directly. If you want to modify Blob data, you must:

  1. Create a new Blob.
  2. Read the old Blob data into a buffer where you can edit or modify it.
  3. Write the modified data to the new Blob.
  4. Prepare and execute an UPDATE statement that will modify the Blob column to contain the Blob ID of the new Blob, replacing the old Blob’s Blob ID.

The sections below describe the steps required to insert, replace, or update Blob data.


Advance To: