Creating a New Blob and Storing Data
From InterBase
Go Up to Writing Data to a Blob
To create a new Blob containing the data to be written:
- Declare and initialize a Blob handle:
isc_blob_handle blob_handle; /* Declare a Blob handle. */ blob_handle = NULL; /* Set handle to NULL before using it */
- Declare and initialize a Blob ID:
ISC_QUAD blob_id; /* Declare a Blob ID. */ blob_id = NULL; /* Set handle to NULL before using it */
- Create a new Blob by calling
isc_create_blob2()
:isc_create_blob2( status_vector, &db_handle, &trans, &blob_handle, /* set by this function to refer to the new Blob */ &blob_id, /* Blob ID set by this function */ 0, /* Blob Parameter Buffer length = 0; no filter will be used */ NULL); /* NULL Blob Parameter Buffer, since no filter will be used */
This function creates a new Blob, opens it for write access, and sets
blob_handle
to point to the new Blob.isc_create_blob2()
also assigns the Blob a Blob ID, and setsblob_id
to point to the Blob ID. Note thatblob_id
is the variable pointed to by thesqldata
field of theUPDATE
statement input parameter that specifies the Blob column to be updated. Thus, when theUPDATE
statement is executed, this new Blob will be used to update the Blob column. - Write all the data to be written to the Blob by making a series of calls to
isc_put_segment()
. The following example reads lines of data, and concatenates each to the Blob referenced byblob_handle
. (get_line()
reads the next line of data to be written.)char *line; unsigned short len; . . . line = get_line(); while (line) { len = strlen(line); isc_put_segment( status_vector, &blob_handle, /* set by previous isc_create_blob2() */ len, /* length of buffer containing data to write */ line ); /* buffer containing data to write into Blob */ if (status_vector[0] == 1 && status_vector[1]) { isc_print_status(status_vector); return(1); }; line = get_line(); };
- Close the Blob:
isc_close_blob(status_vector, &blob_handle);