2
* Program type: API Interface
5
* This program selects a blob data type.
6
* A set of project descriptions is printed.
7
* The contents of this file are subject to the Interbase Public
8
* License Version 1.0 (the "License"); you may not use this file
9
* except in compliance with the License. You may obtain a copy
10
* of the License at http://www.Inprise.com/IPL.html
12
* Software distributed under the License is distributed on an
13
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
14
* or implied. See the License for the specific language governing
15
* rights and limitations under the License.
17
* The Original Code was created by Inprise Corporation
18
* and its predecessors. Portions created by Inprise Corporation are
19
* Copyright (C) Inprise Corporation.
21
* All Rights Reserved.
22
* Contributor(s): ______________________________________.
36
/* This macro is used to declare structures representing SQL VARCHAR types */
37
#define SQL_VARCHAR(len) struct {short vary_length; char vary_string[(len)+1];}
39
int main (int argc, char** argv)
41
SQL_VARCHAR(PROJLEN + 2) proj_name;
42
char prod_type[TYPELEN + 2];
43
char sel_str[BUFLEN + 1];
45
isc_blob_handle blob_handle = NULL;
47
char blob_segment[11];
48
isc_db_handle DB = NULL; /* database handle */
49
isc_tr_handle trans = NULL; /* transaction handle */
50
ISC_STATUS_ARRAY status; /* status vector */
51
isc_stmt_handle stmt = NULL; /* statement handle */
53
long fetch_stat, blob_stat;
60
strcpy(empdb, argv[1]);
62
strcpy(empdb, "employee.fdb");
65
strcpy(sel_str, "SELECT proj_name, proj_desc, product FROM project WHERE \
66
product IN ('software', 'hardware', 'other') ORDER BY proj_name");
68
if (isc_attach_database(status, 0, empdb, &DB, 0, NULL))
73
if (isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
79
* Allocate and prepare the select statement.
82
if (isc_dsql_allocate_statement(status, &DB, &stmt))
87
sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(3));
91
if (isc_dsql_prepare(status, &trans, &stmt, 0, sel_str, 1, sqlda))
96
sqlda->sqlvar[0].sqldata = (char *)&proj_name;
97
sqlda->sqlvar[0].sqltype = SQL_VARYING + 1;
98
sqlda->sqlvar[0].sqlind = &flag0;
100
sqlda->sqlvar[1].sqldata = (char *) &blob_id;
101
sqlda->sqlvar[1].sqltype = SQL_BLOB + 1;
102
sqlda->sqlvar[1].sqlind = &flag1;
104
sqlda->sqlvar[2].sqldata = prod_type;
105
sqlda->sqlvar[2].sqltype = SQL_TEXT + 1;
106
sqlda->sqlvar[2].sqlind = &flag2;
108
if (isc_dsql_execute(status, &trans, &stmt, 1, NULL))
114
* For each project in the select statement, get and display
115
* project descriptions.
118
while ((fetch_stat = isc_dsql_fetch(status, &stmt, 1, sqlda)) == 0)
120
prod_type[TYPELEN] = '\0';
121
printf("\nPROJECT: %-20.*s TYPE: %-15s\n\n",
122
proj_name.vary_length, proj_name.vary_string, prod_type);
124
/* Open the blob with the fetched blob_id. Notice that the
125
* segment length is shorter than the average segment fetched.
126
* Each partial fetch should return isc_segment.
128
if (isc_open_blob(status, &DB, &trans, &blob_handle, &blob_id))
133
/* Get blob segments and their lengths and print each segment. */
134
blob_stat = isc_get_segment(status, &blob_handle,
135
(unsigned short *) &blob_seg_len,
136
sizeof(blob_segment), blob_segment);
137
while (blob_stat == 0 || status[1] == isc_segment)
139
printf("%*.*s", blob_seg_len, blob_seg_len, blob_segment);
140
blob_stat = isc_get_segment(status, &blob_handle,
141
(unsigned short *)&blob_seg_len,
142
sizeof(blob_segment), blob_segment);
144
/* Close the blob. Should be blob_stat to check */
145
if (status[1] == isc_segstr_eof)
147
if (isc_close_blob(status, &blob_handle))
153
isc_print_status(status);
158
if (fetch_stat != 100L)
163
if (isc_dsql_free_statement(status, &stmt, DSQL_close))
168
if (isc_commit_transaction (status, &trans))
173
if (isc_detach_database(status, &DB))