[Top] [Prev] [Next] [Bottom] [Contents]

SaGetBlob

Retrieves Blob data from a database table. (Sybase Only)

Synopsis

#include "WorkingDialog.h"
int SaGetBlob(int vendor,
					char *sv, 
					char *db,
					char *tab,
					char *col,
					int coltype,
					char *where,
					int chunksize,
					void **chunk);

Arguments

vendor
SGESYBASE is the only valid value.
sv
pointer to a string containing the destination server name
db
pointer to a string containing the destination database name
tab
pointer to a string containing the destination table name
col
pointer to a string containing the destination column name
coltype
SA_TEXT for text blobs or SA_BINARY for binary (image) blobs
where
pointer to a string containing a where clause that is guaranteed to return a unique row in a table when used with a select statement.
chunksize
number of bytes to read in one trip to the database. -1 signifies to use the default size.
chunk
the address of a pointer which will be set to point to the returned data. This data must be freed by the developer.

Return Values

Are the size, in bytes, of the chunk returned 0 if there is no more data; or a value less than 0, if an error occurs.

Description

SaGetBlob will retrieve the data for a single column of a given row in a table. It must be called until a 0 is returned, which signifies there is no more data. It must be terminated before all results are retrieved; the function SaGetBlobDone can be called.

Data returned by SaGetBlob must be free'd to avoid memory leaks.

If the column type specified is SA_TEXT, the data will be in character form. If the column type specified is SA_BINARY, the data returned will be in binary form.

Data returned by SaGetBlob is not NULL terminated, regardless of the column type that was specified.

If a call to SaGetBlob is made before a previous one was completed, the request will fail, and the original call to SaGetBlob will be aborted. When a failure occurs at any time while calling SaGetBlob, the blob retrieval mechanism is automatically reset. A subsequent call would work because the blob retrieval mechanism has reset.

Note: To avoid an abort, it is a good practice to call SaGetBlobDone before calling SaGetBlob.

Example

#include "WorkingDialog.h"
...
void *data;
int size;
SaGetBlobDone(SGESYBASE);
while((size = SaGetBlob(SGESYBASE, "CEZANNE",
							"pubs2", "au_pix",
							"pic",						
							SA_BINARY,
							"where au_id = `192-748-2293'",
							-1,
							&data)) > 0) 
{
	write(file_descriptor, (char *)data, size);
	free(data);
}
if(size < 0)
	printf("Error reading blob.\n");
else
	printf("Blob successfully read!\n");
...

See Also



[Top] [Prev] [Next] [Bottom] [Contents]

info@bluestone.com
Copyright © 1997, Bluestone. All rights reserved.