Skip to content

Commit ab0c8c6

Browse files
author
Michael Meskes
committed
*** empty log message ***
1 parent e3a97b3 commit ab0c8c6

File tree

11 files changed

+346
-335
lines changed

11 files changed

+346
-335
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,5 +814,10 @@ Wed Feb 16 17:04:41 CET 2000
814814

815815
- Apply patch by Christof Petig <christof.petig@wtal.de> that adds
816816
descriptors.
817+
818+
Thu Feb 17 19:37:44 CET 2000
819+
820+
- Synced preproc.y with gram.y.
821+
- Started to clean up preproc.y.
817822
- Set library version to 3.1.0.
818823
- 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
@@ -26,6 +26,8 @@ Add a semantic check level, e.g. check if a table really exists.
2626
It would be nice if there was a alternative library using SPI functions
2727
instead of libpq so we can write backend functions using ecpg.
2828

29+
make ECPGnumeric_lvalue more accurate by using something like ECPGdump_a_*
30+
2931
Missing statements:
3032
- exec sql ifdef
3133
- SQLSTATE

src/interfaces/ecpg/include/ecpglib.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ extern "C"
1616
bool ECPGdisconnect(int, const char *);
1717
bool ECPGprepare(int, char *, char *);
1818
bool ECPGdeallocate(int, char *);
19-
char *ECPGprepared_statement(char *);
20-
19+
char *ECPGprepared_statement(char *);
20+
2121
void ECPGlog(const char *format,...);
2222

2323
#ifdef LIBPQ_FE_H
@@ -54,12 +54,14 @@ extern "C"
5454

5555
unsigned int ECPGDynamicType(Oid type);
5656
unsigned int ECPGDynamicType_DDT(Oid type);
57-
PGresult * ECPGresultByDescriptor(int line,const char *name);
58-
bool ECPGdo_descriptor(int line,const char *connection,
57+
PGresult * ECPGresultByDescriptor(int line,const char *name);
58+
bool ECPGdo_descriptor(int line,const char *connection,
5959
const char *descriptor,const char *query);
60-
bool ECPGdeallocate_desc(int line,const char *name);
61-
bool ECPGallocate_desc(int line,const char *name);
62-
void ECPGraise(int line,int code);
60+
bool ECPGdeallocate_desc(int line,const char *name);
61+
bool ECPGallocate_desc(int line,const char *name);
62+
void ECPGraise(int line,int code);
63+
bool ECPGget_desc_header(int, char *, int *);
64+
6365

6466
#ifdef __cplusplus
6567
}

src/interfaces/ecpg/lib/descriptor.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <ecpgtype.h>
2+
#include <ecpglib.h>
3+
4+
bool
5+
ECPGget_desc_header(int lineno, char * desc_name, int *count)
6+
{
7+
PGresult *ECPGresult = ECPGresultByDescriptor(lineno, desc_name);
8+
9+
if (!ECPGresult)
10+
return false;
11+
12+
*count = PQnfields(ECPGresult);
13+
ECPGlog("ECPGget-desc_header: found %d sttributes.\n", *count);
14+
return true;
15+
}

src/interfaces/ecpg/lib/dynamic.c

Lines changed: 14 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.2 2000/02/17 19:48:41 meskes Exp $
5+
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/dynamic.c,v 1.3 2000/02/18 14:34:05 meskes Exp $
66
*/
77

88
/* I borrowed the include files from ecpglib.c, maybe we don't need all of them */
@@ -211,11 +211,15 @@ bool ECPGdo_descriptor(int line,const char *connection,
211211
PGresult *ECPGresultByDescriptor(int line,const char *name)
212212
{
213213
struct descriptor *i;
214-
for (i=all_descriptors;i!=NULL;i=i->next)
215-
{ if (!strcmp(name,i->name)) return i->result;
214+
215+
for (i = all_descriptors; i != NULL; i = i->next)
216+
{
217+
if (!strcmp(name, i->name)) return i->result;
216218
}
219+
217220
ECPGraise(line,ECPG_UNKNOWN_DESCRIPTOR);
218-
return 0;
221+
222+
return NULL;
219223
}
220224

221225

@@ -248,10 +252,12 @@ bool ECPGallocate_desc(int line,const char *name)
248252
return true;
249253
}
250254

251-
void ECPGraise(int line,int code)
252-
{ sqlca.sqlcode=code;
255+
void ECPGraise(int line, int code)
256+
{
257+
sqlca.sqlcode=code;
253258
switch (code)
254-
{ case ECPG_NOT_FOUND:
259+
{
260+
case ECPG_NOT_FOUND:
255261
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
256262
"No data found line %d.",line);
257263
break;
@@ -268,7 +274,7 @@ void ECPGraise(int line,int code)
268274
"descriptor index out of range, line %d.",line);
269275
break;
270276
default:
271-
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
277+
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
272278
"SQL error #%d, line %d.",code,line);
273279
break;
274280
}

src/interfaces/ecpg/preproc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CFLAGS+=-I../include -DMAJOR_VERSION=$(MAJOR_VERSION) \
99
-DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL) \
1010
-DINCLUDE_PATH=\"$(HEADERDIR)\" -g
1111

12-
OBJ=preproc.o pgc.o type.o ecpg.o ecpg_keywords.o \
12+
OBJ=preproc.o pgc.o type.o ecpg.o ecpg_keywords.o output.o\
1313
keywords.o c_keywords.o ../lib/typename.o descriptor.o variable.o
1414

1515
all:: ecpg

src/interfaces/ecpg/preproc/descriptor.c

Lines changed: 92 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,35 @@
1111

1212
struct assignment *assignments;
1313

14-
void push_assignment(char *var,char *value)
14+
void push_assignment(char *var, char *value)
1515
{
16-
struct assignment *new=(struct assignment *)mm_alloc(sizeof(struct assignment));
16+
struct assignment *new = (struct assignment *)mm_alloc(sizeof(struct assignment));
1717

18-
new->next=assignments;
19-
new->variable=mm_alloc(strlen(var)+1);
18+
new->next = assignments;
19+
new->variable = mm_alloc(strlen(var)+1);
2020
strcpy(new->variable,var);
21-
new->value=mm_alloc(strlen(value)+1);
21+
new->value = mm_alloc(strlen(value)+1);
2222
strcpy(new->value,value);
23-
assignments=new;
23+
assignments = new;
2424
}
2525

2626
static void
2727
drop_assignments(void)
28-
{ while (assignments)
29-
{ struct assignment *old_head=assignments;
28+
{
29+
while (assignments)
30+
{
31+
struct assignment *old_head = assignments;
3032

31-
assignments=old_head->next;
33+
assignments = old_head->next;
3234
free(old_head->variable);
3335
free(old_head->value);
3436
free(old_head);
3537
}
3638
}
3739

38-
/* XXX: these should be more accurate (consider ECPGdump_a_* ) */
3940
static void ECPGnumeric_lvalue(FILE *f,char *name)
40-
{ const struct variable *v=find_variable(name);
41+
{
42+
const struct variable *v=find_variable(name);
4143

4244
switch(v->type->typ)
4345
{
@@ -54,10 +56,10 @@ static void ECPGnumeric_lvalue(FILE *f,char *name)
5456
,name);
5557
mmerror(ET_ERROR,errortext);
5658
break;
57-
}
59+
}
5860
}
5961

60-
static void ECPGstring_buffer(FILE *f,char *name)
62+
static void ECPGstring_buffer(FILE *f, char *name)
6163
{
6264
const struct variable *v=find_variable(name);
6365

@@ -167,30 +169,94 @@ static void ECPGdata_assignment(char *variable,char *index_plus_1)
167169
}
168170
}
169171

172+
/*
173+
* descriptor name lookup
174+
*/
175+
176+
static struct descriptor *descriptors;
177+
178+
void add_descriptor(char *name,char *connection)
179+
{
180+
struct descriptor *new=(struct descriptor *)mm_alloc(sizeof(struct descriptor));
181+
182+
new->next=descriptors;
183+
new->name=mm_alloc(strlen(name)+1);
184+
strcpy(new->name,name);
185+
if (connection)
186+
{ new->connection=mm_alloc(strlen(connection)+1);
187+
strcpy(new->connection,connection);
188+
}
189+
else new->connection=connection;
190+
descriptors=new;
191+
}
192+
193+
void
194+
drop_descriptor(char *name,char *connection)
195+
{
196+
struct descriptor *i;
197+
struct descriptor **lastptr=&descriptors;
198+
199+
for (i=descriptors;i;lastptr=&i->next,i=i->next)
200+
{
201+
if (!strcmp(name,i->name))
202+
{
203+
if ((!connection && !i->connection)
204+
|| (connection && i->connection
205+
&& !strcmp(connection,i->connection)))
206+
{
207+
*lastptr=i->next;
208+
if (i->connection) free(i->connection);
209+
free(i->name);
210+
free(i);
211+
return;
212+
}
213+
}
214+
}
215+
snprintf(errortext,sizeof errortext,"unknown descriptor %s",name);
216+
mmerror(ET_WARN,errortext);
217+
}
218+
219+
struct descriptor
220+
*lookup_descriptor(char *name,char *connection)
221+
{
222+
struct descriptor *i;
223+
224+
for (i=descriptors;i;i=i->next)
225+
{
226+
if (!strcmp(name,i->name))
227+
{
228+
if ((!connection && !i->connection)
229+
|| (connection && i->connection
230+
&& !strcmp(connection,i->connection)))
231+
{
232+
return i;
233+
}
234+
}
235+
}
236+
snprintf(errortext,sizeof errortext,"unknown descriptor %s",name);
237+
mmerror(ET_WARN,errortext);
238+
return NULL;
239+
}
240+
170241
void
171242
output_get_descr_header(char *desc_name)
172243
{
173244
struct assignment *results;
174245

175-
fprintf(yyout,"{\tPGresult *ECPGresult=ECPGresultByDescriptor(%d, \"%s\");\n" ,yylineno,desc_name);
176-
fputs("\tif (ECPGresult)\n\t{",yyout);
177-
for (results=assignments;results!=NULL;results=results->next)
246+
fprintf(yyout, "{ ECPGget_desc_header(%d, \"%s\", &(", yylineno, desc_name);
247+
for (results = assignments; results != NULL; results = results->next)
178248
{
179-
if (!strcasecmp(results->value,"count"))
180-
{
181-
fputs("\t\t",yyout);
249+
if (!strcasecmp(results->value, "count"))
182250
ECPGnumeric_lvalue(yyout,results->variable);
183-
fputs("=PQnfields(ECPGresult);\n",yyout);
184-
}
185251
else
186-
{ snprintf(errortext,sizeof errortext,"unknown descriptor header item '%s'",results->value);
187-
mmerror(ET_WARN,errortext);
252+
{ snprintf(errortext, sizeof errortext, "unknown descriptor header item '%s'", results->value);
253+
mmerror(ET_WARN, errortext);
188254
}
189255
}
190-
drop_assignments();
191-
fputs("}",yyout);
192256

193-
whenever_action(2|1);
257+
drop_assignments();
258+
fprintf(yyout, "));\n");
259+
whenever_action(3);
194260
}
195261

196262
void
@@ -305,96 +371,3 @@ output_get_descr(char *desc_name)
305371

306372
whenever_action(2|1);
307373
}
308-
309-
/*
310-
* descriptor name lookup
311-
*/
312-
313-
static struct descriptor *descriptors;
314-
315-
void add_descriptor(char *name,char *connection)
316-
{
317-
struct descriptor *new=(struct descriptor *)mm_alloc(sizeof(struct descriptor));
318-
319-
new->next=descriptors;
320-
new->name=mm_alloc(strlen(name)+1);
321-
strcpy(new->name,name);
322-
if (connection)
323-
{ new->connection=mm_alloc(strlen(connection)+1);
324-
strcpy(new->connection,connection);
325-
}
326-
else new->connection=connection;
327-
descriptors=new;
328-
}
329-
330-
void drop_descriptor(char *name,char *connection)
331-
{
332-
struct descriptor *i;
333-
struct descriptor **lastptr=&descriptors;
334-
335-
for (i=descriptors;i;lastptr=&i->next,i=i->next)
336-
{
337-
if (!strcmp(name,i->name))
338-
{
339-
if ((!connection && !i->connection)
340-
|| (connection && i->connection
341-
&& !strcmp(connection,i->connection)))
342-
{
343-
*lastptr=i->next;
344-
if (i->connection) free(i->connection);
345-
free(i->name);
346-
free(i);
347-
return;
348-
}
349-
}
350-
}
351-
snprintf(errortext,sizeof errortext,"unknown descriptor %s",name);
352-
mmerror(ET_WARN,errortext);
353-
}
354-
355-
struct descriptor *lookup_descriptor(char *name,char *connection)
356-
{
357-
struct descriptor *i;
358-
359-
for (i=descriptors;i;i=i->next)
360-
{
361-
if (!strcmp(name,i->name))
362-
{
363-
if ((!connection && !i->connection)
364-
|| (connection && i->connection
365-
&& !strcmp(connection,i->connection)))
366-
{
367-
return i;
368-
}
369-
}
370-
}
371-
snprintf(errortext,sizeof errortext,"unknown descriptor %s",name);
372-
mmerror(ET_WARN,errortext);
373-
return NULL;
374-
}
375-
376-
void
377-
output_statement_desc(char * stmt, int mode)
378-
{
379-
int i, j=strlen(stmt);
380-
381-
fprintf(yyout, "{ ECPGdo_descriptor(__LINE__, %s, \"%s\", \"",
382-
connection ? connection : "NULL", descriptor_name);
383-
384-
/* do this char by char as we have to filter '\"' */
385-
for (i = 0;i < j; i++) {
386-
if (stmt[i] != '\"')
387-
fputc(stmt[i], yyout);
388-
else
389-
fputs("\\\"", yyout);
390-
}
391-
392-
fputs("\");", yyout);
393-
394-
mode |= 2;
395-
whenever_action(mode);
396-
free(stmt);
397-
if (connection != NULL)
398-
free(connection);
399-
free(descriptor_name);
400-
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy