File: stat7.e

package info (click to toggle)
firebird3.0 3.0.13.ds7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 42,632 kB
  • sloc: ansic: 374,403; cpp: 319,973; sql: 14,691; pascal: 14,532; yacc: 7,557; fortran: 5,645; sh: 5,336; makefile: 1,041; perl: 194; sed: 83; awk: 76; xml: 19; csh: 15
file content (114 lines) | stat: -rw-r--r-- 2,535 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 *  Program type:   Embedded Static SQL
 *
 *  Description:
 *		This program selects a blob data type.
 *		A set of project descriptions is printed.
 * The contents of this file are subject to the Interbase Public
 * License Version 1.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy
 * of the License at http://www.Inprise.com/IPL.html
 *
 * Software distributed under the License is distributed on an
 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
 * or implied. See the License for the specific language governing
 * rights and limitations under the License.
 *
 * The Original Code was created by Inprise Corporation
 * and its predecessors. Portions created by Inprise Corporation are
 * Copyright (C) Inprise Corporation.
 *
 * All Rights Reserved.
 * Contributor(s): ______________________________________.
 */

#include "example.h"
#include <stdlib.h>
#include <stdio.h>

EXEC SQL
	BEGIN DECLARE SECTION;

BASED ON project.proj_name			proj_name;
BASED ON project.product			prod_type;

BASED ON project.proj_desc			blob_id;
BASED ON project.proj_desc.SEGMENT		blob_segment;
unsigned short					blob_seg_len;

EXEC SQL
	END DECLARE SECTION;


int main (void)
{
	EXEC SQL
		WHENEVER SQLERROR GO TO Error;

	/* Declare a table read cursor. */
	EXEC SQL
		DECLARE proj_cur CURSOR FOR
		SELECT proj_name, proj_desc, product
		FROM project
		WHERE product IN ('software', 'hardware', 'other')
		ORDER BY proj_name;

	/* Declare a blob read cursor. */
	EXEC SQL
		DECLARE blob_cur CURSOR FOR
		READ BLOB proj_desc
		FROM project;

	/* Open the table cursor. */
	EXEC SQL
		OPEN proj_cur;

	/*
	 *  For each project get and display project description.
	 */

	while (SQLCODE == 0)
	{
		/* Fetch the blob id along with some other columns. */
		EXEC SQL
			FETCH proj_cur INTO :proj_name, :blob_id, :prod_type;

		if (SQLCODE == 100)
			break;

		printf("\nPROJECT:  %-30s   TYPE:  %-15s\n\n", proj_name, prod_type);

		/* Open the blob cursor. */
		EXEC SQL
			OPEN blob_cur USING :blob_id;

		while (SQLCODE == 0)
		{
			/* Fetch a blob segment and a blob segment length. */
			EXEC SQL FETCH blob_cur INTO :blob_segment :blob_seg_len;

			if (SQLCODE == 100)
				break;

			printf("  %*.*s\n", blob_seg_len, blob_seg_len, blob_segment);
		}
		printf("\n");

		/* Close the blob cursor. */
		EXEC SQL
			CLOSE blob_cur;
	}

	EXEC SQL
		CLOSE proj_cur;

	EXEC SQL
		COMMIT;

	return 0;

Error:
	isc_print_sqlerror((short) SQLCODE, gds__status);
	return 1;
}