Skip to content

Commit 8cb8da3

Browse files
author
Michael Meskes
committed
*** empty log message ***
1 parent a50aaa7 commit 8cb8da3

File tree

11 files changed

+278
-190
lines changed

11 files changed

+278
-190
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,5 +832,10 @@ Wed Feb 23 17:08:28 CET 2000
832832
Fri Feb 25 16:13:11 CET 2000
833833

834834
- Fixed some bugs I created when I cleaned up, thanks Christof.
835+
836+
Wed Mar 1 10:49:03 CET 2000
837+
838+
- Synced preproc.y with gram.y.
839+
- Added output of arrays.
835840
- Set library version to 3.1.0.
836841
- Set ecpg version to 2.7.0.

src/interfaces/ecpg/TODO

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ the parser.
1616
it would be nice to be able to use :var[:index] or :var[<integer>] as
1717
cvariable for an array var
1818

19-
How can one insert arrays from c variables?
20-
2119
What happens to the output variable during read if there was an
2220
indicator-error?
2321

@@ -26,10 +24,7 @@ Add a semantic check level, e.g. check if a table really exists.
2624
It would be nice if there was a alternative library using SPI functions
2725
instead of libpq so we can write backend functions using ecpg.
2826

29-
make ECPGnumeric_lvalue more accurate by using something like ECPGdump_a_*
30-
3127
remove space_or_nl and line_end from pgc.l
3228

3329
Missing statements:
34-
- exec sql ifdef
3530
- SQLSTATE

src/interfaces/ecpg/include/ecpgerrno.h

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,34 @@
1313
#define ECPG_OUT_OF_MEMORY -ENOMEM
1414

1515
/* first we have a set of ecpg messages, they start at 200 */
16-
#define ECPG_UNSUPPORTED -200
17-
#define ECPG_TOO_MANY_ARGUMENTS -201
18-
#define ECPG_TOO_FEW_ARGUMENTS -202
19-
#define ECPG_TOO_MANY_MATCHES -203
20-
#define ECPG_INT_FORMAT -204
21-
#define ECPG_UINT_FORMAT -205
22-
#define ECPG_FLOAT_FORMAT -206
23-
#define ECPG_CONVERT_BOOL -207
24-
#define ECPG_EMPTY -208
25-
#define ECPG_MISSING_INDICATOR -209
26-
27-
#define ECPG_NO_CONN -220
28-
#define ECPG_NOT_CONN -221
29-
30-
#define ECPG_INVALID_STMT -230
16+
#define ECPG_UNSUPPORTED -200
17+
#define ECPG_TOO_MANY_ARGUMENTS -201
18+
#define ECPG_TOO_FEW_ARGUMENTS -202
19+
#define ECPG_TOO_MANY_MATCHES -203
20+
#define ECPG_INT_FORMAT -204
21+
#define ECPG_UINT_FORMAT -205
22+
#define ECPG_FLOAT_FORMAT -206
23+
#define ECPG_CONVERT_BOOL -207
24+
#define ECPG_EMPTY -208
25+
#define ECPG_MISSING_INDICATOR -209
26+
#define ECPG_NO_ARRAY -210
27+
#define ECPG_DATA_NOT_ARRAY -211
28+
29+
#define ECPG_NO_CONN -220
30+
#define ECPG_NOT_CONN -221
31+
32+
#define ECPG_INVALID_STMT -230
3133

3234
/* dynamic SQL related */
33-
#define ECPG_UNKNOWN_DESCRIPTOR -240
35+
#define ECPG_UNKNOWN_DESCRIPTOR -240
3436
#define ECPG_INVALID_DESCRIPTOR_INDEX -241
3537
#define ECPG_UNKNOWN_DESCRIPTOR_ITEM -242
36-
#define ECPG_VAR_NOT_NUMERIC -243
37-
#define ECPG_VAR_NOT_CHAR -244
38+
#define ECPG_VAR_NOT_NUMERIC -243
39+
#define ECPG_VAR_NOT_CHAR -244
3840

3941
/* finally the backend error messages, they start at 400 */
40-
#define ECPG_PGSQL -400
41-
#define ECPG_TRANS -401
42-
#define ECPG_CONNECT -402
42+
#define ECPG_PGSQL -400
43+
#define ECPG_TRANS -401
44+
#define ECPG_CONNECT -402
4345

4446
#endif /* !_ECPG_ERROR_H */

src/interfaces/ecpg/include/ecpglib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ extern "C"
3030

3131
/* Here are some methods used by the lib. */
3232
/* Returns a pointer to a string containing a simple type name. */
33-
const char *ECPGtype_name(enum ECPGttype);
3433
bool get_data(PGresult *, int, int, int, enum ECPGttype type,
35-
enum ECPGttype, void *, void *, long, long);
34+
enum ECPGttype, void *, void *, long, long, bool);
3635
char *ecpg_alloc(long, int);
3736
char *ecpg_strdup(const char *, int);
3837
const char *ECPGtype_name(enum ECPGttype);
38+
unsigned int ECPGDynamicType(Oid);
3939

4040
/* and some vars */
4141
extern struct auto_mem *auto_allocs;

src/interfaces/ecpg/include/sql3types.h

Lines changed: 1 addition & 1 deletion
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/include/sql3types.h,v 1.1 2000/02/16 16:18:03 meskes Exp $
5+
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/include/sql3types.h,v 1.2 2000/03/01 12:49:41 meskes Exp $
66
*/
77

88
/* chapter 13.1 table 2: Codes used for SQL data types in Dynamic SQL */

src/interfaces/ecpg/lib/data.c

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,26 @@
88
bool
99
get_data(PGresult *results, int act_tuple, int act_field, int lineno,
1010
enum ECPGttype type, enum ECPGttype ind_type,
11-
void *var, void *ind, long varcharsize, long offset)
11+
void *var, void *ind, long varcharsize, long offset,
12+
bool isarray)
1213
{
1314
char *pval = (char *)PQgetvalue(results, act_tuple, act_field);
1415

1516
ECPGlog("get_data line %d: RESULT: %s\n", lineno, pval ? pval : "");
1617

1718
/* Now the pval is a pointer to the value. */
19+
/* let's check is it really is an array if it should be */
20+
if (isarray)
21+
{
22+
if (*pval != '{')
23+
{
24+
ECPGlog("get_data data entry does not look like an array in line %d\n", lineno);
25+
ECPGraise(lineno, ECPG_DATA_NOT_ARRAY, NULL);
26+
return(false);
27+
}
28+
else ++pval;
29+
}
30+
1831
/* We will have to decode the value */
1932

2033
/*
@@ -48,8 +61,10 @@ get_data(PGresult *results, int act_tuple, int act_field, int lineno,
4861
break;
4962
}
5063

51-
switch (type)
52-
{
64+
do
65+
{
66+
switch (type)
67+
{
5368
long res;
5469
unsigned long ures;
5570
double dres;
@@ -61,7 +76,8 @@ get_data(PGresult *results, int act_tuple, int act_field, int lineno,
6176
if (pval)
6277
{
6378
res = strtol(pval, &scan_length, 10);
64-
if (*scan_length != '\0') /* Garbage left */
79+
if ((isarray && *scan_length != ',' && *scan_length != '}')
80+
|| (!isarray && *scan_length != '\0')) /* Garbage left */
6581
{
6682
ECPGraise(lineno, ECPG_INT_FORMAT, pval);
6783
return (false);
@@ -94,7 +110,8 @@ get_data(PGresult *results, int act_tuple, int act_field, int lineno,
94110
if (pval)
95111
{
96112
ures = strtoul(pval, &scan_length, 10);
97-
if (*scan_length != '\0') /* Garbage left */
113+
if ((isarray && *scan_length != ',' && *scan_length != '}')
114+
|| (!isarray && *scan_length != '\0')) /* Garbage left */
98115
{
99116
ECPGraise(lineno, ECPG_UINT_FORMAT, pval);
100117
return (false);
@@ -127,7 +144,8 @@ get_data(PGresult *results, int act_tuple, int act_field, int lineno,
127144
if (pval)
128145
{
129146
dres = strtod(pval, &scan_length);
130-
if (*scan_length != '\0') /* Garbage left */
147+
if ((isarray && *scan_length != ',' && *scan_length != '}')
148+
|| (!isarray && *scan_length != '\0')) /* Garbage left */
131149
{
132150
ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval);
133151
return (false);
@@ -246,7 +264,23 @@ get_data(PGresult *results, int act_tuple, int act_field, int lineno,
246264
ECPGraise(lineno, ECPG_UNSUPPORTED, ECPGtype_name(type));
247265
return (false);
248266
break;
249-
}
250-
267+
}
268+
if (isarray)
269+
{
270+
bool string = false;
271+
272+
/* set array to next entry */
273+
++act_tuple;
274+
275+
/* set pval to the next entry */
276+
for (; string || (*pval != ',' && *pval != '}'); ++pval)
277+
if (*pval == '"')
278+
string = string ? false : true;
279+
280+
if (*pval == ',')
281+
++pval;
282+
}
283+
} while (isarray && *pval != '}');
284+
251285
return (true);
252286
}

src/interfaces/ecpg/lib/descriptor.c

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,6 @@ static PGresult
2525
return NULL;
2626
}
2727

28-
static unsigned int
29-
ECPGDynamicType(Oid type)
30-
{
31-
switch(type)
32-
{
33-
case 16: return SQL3_BOOLEAN; /* bool */
34-
case 21: return SQL3_SMALLINT; /* int2 */
35-
case 23: return SQL3_INTEGER; /* int4 */
36-
case 25: return SQL3_CHARACTER; /* text */
37-
case 700: return SQL3_REAL; /* float4 */
38-
case 701: return SQL3_DOUBLE_PRECISION; /* float8 */
39-
case 1042: return SQL3_CHARACTER; /* bpchar */
40-
case 1043: return SQL3_CHARACTER_VARYING; /* varchar */
41-
case 1082: return SQL3_DATE_TIME_TIMESTAMP; /* date */
42-
case 1083: return SQL3_DATE_TIME_TIMESTAMP; /* time */
43-
case 1184: return SQL3_DATE_TIME_TIMESTAMP; /* datetime */
44-
case 1296: return SQL3_DATE_TIME_TIMESTAMP; /* timestamp */
45-
case 1700: return SQL3_NUMERIC; /* numeric */
46-
default: return -type;
47-
}
48-
}
49-
5028
static unsigned int
5129
ECPGDynamicType_DDT(Oid type)
5230
{
@@ -61,7 +39,6 @@ ECPGDynamicType_DDT(Oid type)
6139
}
6240
}
6341

64-
6542
bool
6643
ECPGget_desc_header(int lineno, char * desc_name, int *count)
6744
{
@@ -266,7 +243,7 @@ ECPGget_desc(int lineno, char *desc_name, int index, ...)
266243
ECPGlog("ECPGget_desc: TYPE = %d\n", ECPGDynamicType_DDT(PQftype(ECPGresult, index)));
267244
break;
268245
case ECPGd_data:
269-
if (!get_data(ECPGresult, 0, index, lineno, vartype, ECPGt_NO_INDICATOR, var, NULL, varcharsize, offset))
246+
if (!get_data(ECPGresult, 0, index, lineno, vartype, ECPGt_NO_INDICATOR, var, NULL, varcharsize, offset, false))
270247
return (false);
271248

272249
break;

src/interfaces/ecpg/lib/ecpglib.c

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <ecpgtype.h>
2525
#include <ecpglib.h>
2626
#include <sqlca.h>
27+
#include <sql3types.h>
2728

2829
/* variables visible to the programs */
2930
static struct sqlca sqlca_init =
@@ -689,23 +690,46 @@ ECPGexecute(struct statement * stmt)
689690
isarray = 0;
690691
if (PQresultStatus(query) == PGRES_TUPLES_OK) {
691692
isarray = atol((char *)PQgetvalue(query, 0, 0));
693+
if (ECPGDynamicType(PQftype(results, act_field)) == SQL3_CHARACTER ||
694+
(PQftype(results, act_field)) == SQL3_CHARACTER_VARYING)
695+
{
696+
/* arrays of character strings are not yet implemented */
697+
isarray = false;
698+
}
692699
ECPGlog("ECPGexecute line %d: TYPE database: %d C: %d array: %s\n", stmt->lineno, PQftype(results, act_field), var->type, isarray ? "yes" : "no");
693700
}
694701
PQclear(query);
695702

696-
/*
697-
* if we don't have enough space, we cannot read all
698-
* tuples
699-
*/
700-
if ((var->arrsize > 0 && ntuples > var->arrsize) || (var->ind_arrsize > 0 && ntuples > var->ind_arrsize))
703+
if (!isarray)
701704
{
702-
ECPGlog("ECPGexecute line %d: Incorrect number of matches: %d don't fit into array of %d\n",
705+
/*
706+
* if we don't have enough space, we cannot read all
707+
* tuples
708+
*/
709+
if ((var->arrsize > 0 && ntuples > var->arrsize) || (var->ind_arrsize > 0 && ntuples > var->ind_arrsize))
710+
{
711+
ECPGlog("ECPGexecute line %d: Incorrect number of matches: %d don't fit into array of %d\n",
703712
stmt->lineno, ntuples, var->arrsize);
704-
ECPGraise(stmt->lineno, ECPG_TOO_MANY_MATCHES, NULL);
705-
status = false;
706-
break;
713+
ECPGraise(stmt->lineno, ECPG_TOO_MANY_MATCHES, NULL);
714+
status = false;
715+
break;
716+
}
707717
}
708-
718+
else
719+
{
720+
/*
721+
* since we read an array, the variable has to be
722+
* an array too
723+
*/
724+
if (var->arrsize == 0)
725+
{
726+
ECPGlog("ECPGexecute line %d: variable is not an array\n");
727+
ECPGraise(stmt->lineno, ECPG_NO_ARRAY, NULL);
728+
status = false;
729+
break;
730+
}
731+
}
732+
709733
/*
710734
* allocate memory for NULL pointers
711735
*/
@@ -745,7 +769,7 @@ ECPGexecute(struct statement * stmt)
745769
{
746770
if (!get_data(results, act_tuple, act_field, stmt->lineno,
747771
var->type, var->ind_type, var->value,
748-
var->ind_value, var->varcharsize, var->offset))
772+
var->ind_value, var->varcharsize, var->offset, isarray))
749773
status = false;
750774
}
751775
var = var->next;
@@ -1067,13 +1091,9 @@ ECPGlog(const char *format,...)
10671091
*
10681092
* Copyright (c) 2000, Christof Petig <christof.petig@wtal.de>
10691093
*
1070-
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/ecpglib.c,v 1.60 2000/02/23 19:25:43 meskes Exp $
1094+
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/ecpglib.c,v 1.61 2000/03/01 12:49:42 meskes Exp $
10711095
*/
10721096

1073-
/* I borrowed the include files from ecpglib.c, maybe we don't need all of them */
1074-
1075-
#include <sql3types.h>
1076-
10771097
PGconn *ECPG_internal_get_connection(char *name);
10781098

10791099
extern struct descriptor

src/interfaces/ecpg/lib/error.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ ECPGraise(int line, int code, const char *str)
6767
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
6868
"NULL value without indicator in line %d.", line);
6969
break;
70+
71+
case ECPG_NO_ARRAY:
72+
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
73+
"variable is not an array in line %d.", line);
74+
break;
75+
76+
case ECPG_DATA_NOT_ARRAY:
77+
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
78+
"data read from backend is not an array in line %d.", line);
79+
break;
7080

7181
case ECPG_NO_CONN:
7282
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),

src/interfaces/ecpg/lib/typename.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include <stdlib.h>
22
#include <ecpgtype.h>
3+
#include <ecpglib.h>
4+
#include <sql3types.h>
5+
36
/*
47
* This function is used to generate the correct type names.
58
*/
@@ -39,3 +42,25 @@ ECPGtype_name(enum ECPGttype typ)
3942
}
4043
return NULL;
4144
}
45+
46+
unsigned int
47+
ECPGDynamicType(Oid type)
48+
{
49+
switch(type)
50+
{
51+
case 16: return SQL3_BOOLEAN; /* bool */
52+
case 21: return SQL3_SMALLINT; /* int2 */
53+
case 23: return SQL3_INTEGER; /* int4 */
54+
case 25: return SQL3_CHARACTER; /* text */
55+
case 700: return SQL3_REAL; /* float4 */
56+
case 701: return SQL3_DOUBLE_PRECISION; /* float8 */
57+
case 1042: return SQL3_CHARACTER; /* bpchar */
58+
case 1043: return SQL3_CHARACTER_VARYING; /* varchar */
59+
case 1082: return SQL3_DATE_TIME_TIMESTAMP; /* date */
60+
case 1083: return SQL3_DATE_TIME_TIMESTAMP; /* time */
61+
case 1184: return SQL3_DATE_TIME_TIMESTAMP; /* datetime */
62+
case 1296: return SQL3_DATE_TIME_TIMESTAMP; /* timestamp */
63+
case 1700: return SQL3_NUMERIC; /* numeric */
64+
default: return -type;
65+
}
66+
}

0 commit comments

Comments
 (0)