-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOutPut.pc
More file actions
102 lines (91 loc) · 2.73 KB
/
Copy pathOutPut.pc
File metadata and controls
102 lines (91 loc) · 2.73 KB
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
/**
* OutPut.pc - Output the result of SQL sentence of "SELECT".
*
* Copyright (C) 1995 Batayan. (kawabata@personal.email.ne.jp)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* 1999/3/11 Update: For ARRAY FETCH. by Batayan.
* 1999/3/28 Update: Change the way to write from fputs to "write".
*
**/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define _SQLEXTERN_
#include "extern.h"
#include "sqlhead.h"
#define SQLCA_STORAGE_CLASS extern
EXEC SQL INCLUDE sqlca.h;
EXEC SQL INCLUDE sqlda.h;
EXEC SQL INCLUDE chcsv.h;
int
OutPut(SQLDA *dp, int numOfFetch)
{
int h; /* Loop for rows */
int i; /* Loop for columns */
int j; /* Loop for charctors */
int prec,scale;
strcpy(FUNCTION, "OutPut");
#ifdef DEBUG
fprintf(debug,"OutPut:numOfFetch=%d\n",numOfFetch );
#endif
for( h = 0; h < numOfFetch; h++ ){
for( i = 0; i < dp->N; i++ ){
#ifdef DEBUG2
printda(dp, i, "NVL", h);
#endif
/* Output enclosure */
if( *( numflg + i ) != 2 && ENCLOSE != (char)NULL ){
OUTBUF[OUTBYTE++] = ENCLOSE;
}
/* Output columns */
j = 0;
while( *( dp->V[i] + ( dp->L[i] * h ) + j ) != (char)NULL ){
OUTBUF[OUTBYTE++] = *( dp->V[i] + ( dp->L[i] * h ) + j++ );
}
/* Output enclosure */
if( *( numflg + i ) != 2 && ENCLOSE != (char)NULL ){
OUTBUF[OUTBYTE++] = ENCLOSE;
}
/* Output terminator except the last column */
if( i != dp->N - 1 ){
OUTBUF[OUTBYTE++] = TERMINATE;
}
}
/* Output line terminator */
OUTBUF[OUTBYTE++] = '\n';
TOTALRECORDS++;
BUFFERED++;
/* When to reach maximun records of buffer */
if( BUFFERED = OUTRECORDS ){
#ifdef DEBUG
fprintf(debug, "TOTALRECORDS=%d OUTRECORDS=%d h=%d OUTBYTE=%d\n", TOTALRECORDS, OUTRECORDS, h, OUTBYTE);
#endif
FlashBuffer();
}
}
return 0;
}
int
FlashBuffer()
{
OUTBUF[OUTBYTE] = (char)NULL;
if( write(fdout, OUTBUF, OUTBYTE ) != OUTBYTE ){
SysOraErr("write");
}
OUTBYTE = 0;
BUFFERED = 0;
}