Skip to content

Commit 991b974

Browse files
author
Michael Meskes
committed
*** empty log message ***
1 parent 62f0645 commit 991b974

File tree

21 files changed

+623
-333
lines changed

21 files changed

+623
-333
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,5 +819,10 @@ Thu Feb 17 19:37:44 CET 2000
819819

820820
- Synced preproc.y with gram.y.
821821
- Started to clean up preproc.y.
822+
823+
Tue Feb 22 13:48:18 CET 2000
824+
825+
- Synced preproc.y with gram.y.
826+
- Much more clean ups.
822827
- Set library version to 3.1.0.
823828
- Set ecpg version to 2.7.0.

src/interfaces/ecpg/TODO

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ instead of libpq so we can write backend functions using ecpg.
2828

2929
make ECPGnumeric_lvalue more accurate by using something like ECPGdump_a_*
3030

31+
remove space_or_nl and line_end from pgc.l
32+
3133
Missing statements:
3234
- exec sql ifdef
3335
- SQLSTATE

src/interfaces/ecpg/include/ecpgerrno.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
/* dynamic SQL related */
3333
#define ECPG_UNKNOWN_DESCRIPTOR -240
3434
#define ECPG_INVALID_DESCRIPTOR_INDEX -241
35+
#define ECPG_UNKNOWN_DESCRIPTOR_ITEM -242
36+
#define ECPG_VAR_NOT_NUMERIC -243
3537

3638
/* finally the backend error messages, they start at 400 */
3739
#define ECPG_PGSQL -400

src/interfaces/ecpg/include/ecpglib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ extern "C"
6161
bool ECPGallocate_desc(int line,const char *name);
6262
void ECPGraise(int line, int code, const char *str);
6363
bool ECPGget_desc_header(int, char *, int *);
64+
bool ECPGget_desc(int, char *, int, ...);
6465

6566

6667
#ifdef __cplusplus

src/interfaces/ecpg/include/ecpgtype.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@ extern "C"
4949
ECPGt_EORT, /* End of result types. */
5050
ECPGt_NO_INDICATOR /* no indicator */
5151
};
52+
53+
enum ECPGdtype
54+
{
55+
ECPGd_count,
56+
ECPGd_data,
57+
ECPGd_di_code,
58+
ECPGd_di_precision,
59+
ECPGd_indicator,
60+
ECPGd_key_member,
61+
ECPGd_length,
62+
ECPGd_name,
63+
ECPGd_nullable,
64+
ECPGd_octet,
65+
ECPGd_precision,
66+
ECPGd_ret_length,
67+
ECPGd_ret_octet,
68+
ECPGd_scale,
69+
ECPGd_type,
70+
ECPGd_EODT, /* End of descriptor types. */
71+
};
5272

5373
#define IS_SIMPLE_TYPE(type) ((type) >= ECPGt_char && (type) <= ECPGt_varchar2)
5474

src/interfaces/ecpg/lib/Makefile.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Copyright (c) 1994, Regents of the University of California
77
#
88
# IDENTIFICATION
9-
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile.in,v 1.58 2000/02/16 16:18:05 meskes Exp $
9+
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile.in,v 1.59 2000/02/22 19:57:05 meskes Exp $
1010
#
1111
#-------------------------------------------------------------------------
1212

@@ -23,7 +23,7 @@ ifdef KRBVERS
2323
CFLAGS+= $(KRBFLAGS)
2424
endif
2525

26-
OBJS= ecpglib.o typename.o
26+
OBJS= ecpglib.o typename.o descriptor.o
2727

2828
SHLIB_LINK= -L../../libpq -lpq
2929

src/interfaces/ecpg/lib/descriptor.c

Lines changed: 152 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,157 @@ ECPGget_desc_header(int lineno, char * desc_name, int *count)
1010
return false;
1111

1212
*count = PQnfields(ECPGresult);
13-
ECPGlog("ECPGget-desc_header: found %d sttributes.\n", *count);
13+
ECPGlog("ECPGget_desc_header: found %d attributes.\n", *count);
1414
return true;
1515
}
16+
17+
static bool
18+
get_int_item(int lineno, void *var, enum ECPGdtype vartype, int value)
19+
{
20+
switch (vartype)
21+
{
22+
case ECPGt_short:
23+
*(short *)var = value;
24+
break;
25+
case ECPGt_int:
26+
*(int *)var = value;
27+
break;
28+
case ECPGt_long:
29+
*(long *)var = value;
30+
break;
31+
case ECPGt_unsigned_short:
32+
*(unsigned short *)var = value;
33+
break;
34+
case ECPGt_unsigned_int:
35+
*(unsigned int *)var = value;
36+
break;
37+
case ECPGt_unsigned_long:
38+
*(unsigned long *)var = value;
39+
break;
40+
case ECPGt_float:
41+
*(float *)var = value;
42+
break;
43+
case ECPGt_double:
44+
*(double *)var = value;
45+
break;
46+
default:
47+
ECPGraise(lineno, ECPG_VAR_NOT_NUMERIC, NULL);
48+
return (false);
49+
}
50+
51+
return(true);
52+
}
53+
54+
bool
55+
ECPGget_desc(int lineno, char *desc_name, int index, ...)
56+
{
57+
va_list args;
58+
PGresult *ECPGresult = ECPGresultByDescriptor(lineno, desc_name);
59+
enum ECPGdtype type;
60+
bool DataButNoIndicator = false;
61+
62+
va_start(args, index);
63+
if (!ECPGresult)
64+
return (false);
65+
66+
if (PQntuples(ECPGresult) < 1)
67+
{
68+
ECPGraise(lineno, ECPG_NOT_FOUND, NULL);
69+
return (false);
70+
}
71+
72+
if (index < 1 || index >PQnfields(ECPGresult))
73+
{
74+
ECPGraise(lineno, ECPG_INVALID_DESCRIPTOR_INDEX, NULL);
75+
return (false);
76+
}
77+
78+
ECPGlog("ECPGget_desc: reading items for tuple %d\n", index);
79+
--index;
80+
81+
type = va_arg(args, enum ECPGdtype);
82+
83+
while (type != ECPGd_EODT)
84+
{
85+
char type_str[20];
86+
long varcharsize;
87+
long offset;
88+
long arrsize;
89+
enum ECPGttype vartype;
90+
void *var;
91+
92+
vartype = va_arg(args, enum ECPGttype);
93+
var = va_arg(args, void *);
94+
varcharsize = va_arg(args, long);
95+
arrsize = va_arg(args, long);
96+
offset = va_arg(args, long);
97+
98+
switch (type)
99+
{
100+
case (ECPGd_indicator):
101+
if (!get_int_item(lineno, var, vartype, -PQgetisnull(ECPGresult, 0, index)))
102+
return (false);
103+
break;
104+
105+
case ECPGd_name:
106+
strncpy((char *)var, PQfname(ECPGresult, index), varcharsize);
107+
break;
108+
109+
case ECPGd_nullable:
110+
if (!get_int_item(lineno, var, vartype, 1))
111+
return (false);
112+
break;
113+
114+
case ECPGd_key_member:
115+
if (!get_int_item(lineno, var, vartype, 0))
116+
return (false);
117+
break;
118+
119+
case ECPGd_scale:
120+
if (!get_int_item(lineno, var, vartype, (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff))
121+
return (false);
122+
break;
123+
124+
case ECPGd_precision:
125+
if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) >> 16))
126+
return (false);
127+
break;
128+
129+
case ECPGd_ret_length:
130+
case ECPGd_ret_octet:
131+
if (!get_int_item(lineno, var, vartype, PQgetlength(ECPGresult, 0, index)))
132+
return (false);
133+
break;
134+
135+
case ECPGd_octet:
136+
if (!get_int_item(lineno, var, vartype, PQfsize(ECPGresult, index)))
137+
return (false);
138+
break;
139+
140+
case ECPGd_length:
141+
if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) - VARHDRSZ))
142+
return (false);
143+
break;
144+
145+
case ECPGd_type:
146+
if (!get_int_item(lineno, var, vartype, ECPGDynamicType(PQftype(ECPGresult, index))))
147+
return (false);
148+
break;
149+
150+
default:
151+
snprintf(type_str, sizeof(type_str), "%d", type);
152+
ECPGraise(lineno, ECPG_UNKNOWN_DESCRIPTOR_ITEM, type_str);
153+
return(false);
154+
}
155+
156+
type = va_arg(args, enum ECPGdtype);
157+
}
158+
159+
if (DataButNoIndicator && PQgetisnull(ECPGresult, 0, index))
160+
{
161+
ECPGraise(lineno, ECPG_MISSING_INDICATOR, NULL);
162+
return (false);
163+
}
164+
165+
return (true);
166+
}

src/interfaces/ecpg/lib/dynamic.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* Copyright (c) 2000, Christof Petig <christof.petig@wtal.de>
44
*
5-
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/dynamic.c,v 1.4 2000/02/18 16:02:49 meskes Exp $
5+
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/dynamic.c,v 1.5 2000/02/22 19:57:05 meskes Exp $
66
*/
77

88
/* I borrowed the include files from ecpglib.c, maybe we don't need all of them */
@@ -198,15 +198,16 @@ bool ECPGdo_descriptor(int line,const char *connection,
198198

199199
/* free previous result */
200200
if (i->result) PQclear(i->result);
201-
i->result=NULL;
201+
i->result=NULL;
202202

203203
status=do_descriptor2(line,connection,&i->result,query);
204204

205205
if (!i->result) PQmakeEmptyPGresult(NULL, 0);
206206
return (status);
207207
}
208208
}
209-
ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, NULL);
209+
210+
ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, descriptor);
210211
return false;
211212
}
212213

@@ -219,7 +220,7 @@ PGresult *ECPGresultByDescriptor(int line,const char *name)
219220
if (!strcmp(name, i->name)) return i->result;
220221
}
221222

222-
ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, NULL);
223+
ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, name);
223224

224225
return NULL;
225226
}
@@ -238,7 +239,7 @@ bool ECPGdeallocate_desc(int line,const char *name)
238239
return true;
239240
}
240241
}
241-
ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, NULL);
242+
ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, name);
242243
return false;
243244
}
244245

@@ -259,7 +260,7 @@ ECPGraise(int line, int code, const char *str)
259260
{
260261
struct auto_mem *am;
261262

262-
sqlca.sqlcode=code;
263+
sqlca.sqlcode = code;
263264
switch (code)
264265
{
265266
case ECPG_NOT_FOUND:
@@ -294,15 +295,25 @@ ECPGraise(int line, int code, const char *str)
294295

295296
case ECPG_UNKNOWN_DESCRIPTOR:
296297
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
297-
"descriptor not found, line %d.", line);
298+
"descriptor %s not found, line %d.", str, line);
298299
break;
299300

300301
case ECPG_INVALID_DESCRIPTOR_INDEX:
301302
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
302303
"descriptor index out of range, line %d.", line);
303304
break;
305+
306+
case ECPG_UNKNOWN_DESCRIPTOR_ITEM:
307+
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
308+
"unknown descriptor item %s, line %d.", str, line);
309+
break;
310+
311+
case ECPG_VAR_NOT_NUMERIC:
312+
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
313+
"variable is not a numeric type, line %d.", line);
314+
break;
304315

305-
default:
316+
default:
306317
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
307318
"SQL error #%d, line %d.",code, line);
308319
break;

0 commit comments

Comments
 (0)