Writing Data to a Blob
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:
- Prepare an appropriate DSQL statement. This will be an
INSERTstatement if you are inserting a new row into a table, or an
UPDATEstatement for modifying a row. Each of these statements will need a corresponding input
XSQLDAstructure for supplying parameter values to the statement at run time. The Blob ID of a new Blob will be one of the values passed.
- Create a new Blob, and write data into it.
- Associate the Blob ID of the new Blob with the Blob column of the table row by executing the
Note that you cannot update Blob data directly. If you want to modify Blob data, you must:
- Create a new Blob.
- Read the old Blob data into a buffer where you can edit or modify it.
- Write the modified data to the new Blob.
- Prepare and execute an
UPDATEstatement 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.
- Preparing the UPDATE or INSERT Statement for a Blob
- Creating a New Blob and Storing Data
- Associating the New Blob with the Blob Column