Skip to content

Commit 5933f18

Browse files
author
Michael Meskes
committed
*** empty log message ***
1 parent 68be513 commit 5933f18

File tree

7 files changed

+130
-30
lines changed

7 files changed

+130
-30
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,5 +799,15 @@ Tue Feb 15 11:14:07 CET 2000
799799

800800
- Synced keyword.c.
801801
- Synced preproc.y with gram.y.
802+
803+
Tue Feb 15 17:39:19 CET 2000
804+
805+
- Do only write the first 70 bytes of the error message to the
806+
sqlca structure since there are only 70 bytes free space.
802807
- Set library version to 3.0.10.
808+
809+
Wed Feb 16 11:57:02 CET 2000
810+
811+
- Fixed library to be able to input complete arrays.
812+
- Set library version to 3.1.0.
803813
- Set ecpg version to 2.7.0.

src/interfaces/ecpg/TODO

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ stderr. Instead it should be listed as a warning.
1313
The error handling has to be improved by adding additional error-rules to
1414
the parser.
1515

16-
it would be nice to be able to use :var[:index] as cvariable for an array var
16+
it would be nice to be able to use :var[:index] or :var[<integer>] as
17+
cvariable for an array var
1718

1819
How can one insert arrays from c variables?
1920

src/interfaces/ecpg/lib/Makefile.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
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.56 2000/01/18 13:03:47 meskes Exp $
9+
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile.in,v 1.57 2000/02/16 11:52:24 meskes Exp $
1010
#
1111
#-------------------------------------------------------------------------
1212

1313
NAME= ecpg
1414
SO_MAJOR_VERSION= 3
15-
SO_MINOR_VERSION= 0.10
15+
SO_MINOR_VERSION= 1.0
1616

1717
SRCDIR= @top_srcdir@
1818
include $(SRCDIR)/Makefile.global

src/interfaces/ecpg/lib/ecpglib.c

Lines changed: 102 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ ECPGexecute(struct statement * stmt)
414414
char *mallocedval = NULL;
415415
char *tobeinserted = NULL;
416416
char *p;
417-
char buff[20];
417+
char buff[20];
418418

419419
/*
420420
* Some special treatment is needed for records since we want
@@ -450,49 +450,132 @@ ECPGexecute(struct statement * stmt)
450450
{
451451
switch (var->type)
452452
{
453+
int element;
454+
453455
case ECPGt_short:
454-
sprintf(buff, "%d", *(short *) var->value);
455-
tobeinserted = buff;
456+
if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
457+
return false;
458+
459+
sprintf(mallocedval, "%s", (var->arrsize > 1) ? "'{" : "");
460+
461+
for (element = 0; element < var->arrsize; element++)
462+
sprintf(mallocedval + strlen(mallocedval), "%d,", ((short *) var->value)[element]);
463+
464+
sprintf(mallocedval + strlen(mallocedval) - 1, "%s", (var->arrsize > 1) ? "}'" : "");
465+
466+
tobeinserted = mallocedval;
456467
break;
457468

458469
case ECPGt_int:
459-
sprintf(buff, "%d", *(int *) var->value);
460-
tobeinserted = buff;
470+
if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
471+
return false;
472+
473+
sprintf(mallocedval, "%s", (var->arrsize > 1) ? "'{" : "");
474+
475+
for (element = 0; element < var->arrsize; element++)
476+
sprintf(mallocedval + strlen(mallocedval), "%d,", ((int *) var->value)[element]);
477+
478+
sprintf(mallocedval + strlen(mallocedval) - 1, "%s", (var->arrsize > 1) ? "}'" : "");
479+
480+
tobeinserted = mallocedval;
461481
break;
462482

463483
case ECPGt_unsigned_short:
464-
sprintf(buff, "%d", *(unsigned short *) var->value);
465-
tobeinserted = buff;
484+
if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
485+
return false;
486+
487+
sprintf(mallocedval, "%s", (var->arrsize > 1) ? "'{" : "");
488+
489+
for (element = 0; element < var->arrsize; element++)
490+
sprintf(mallocedval + strlen(mallocedval), "%d,", ((unsigned short *) var->value)[element]);
491+
492+
sprintf(mallocedval + strlen(mallocedval) - 1, "%s", (var->arrsize > 1) ? "}'" : "");
493+
494+
tobeinserted = mallocedval;
466495
break;
467496

468497
case ECPGt_unsigned_int:
469-
sprintf(buff, "%d", *(unsigned int *) var->value);
470-
tobeinserted = buff;
498+
if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
499+
return false;
500+
501+
sprintf(mallocedval, "%s", (var->arrsize > 1) ? "'{" : "");
502+
503+
for (element = 0; element < var->arrsize; element++)
504+
sprintf(mallocedval + strlen(mallocedval), "%d,", ((unsigned int *) var->value)[element]);
505+
506+
sprintf(mallocedval + strlen(mallocedval) - 1, "%s", (var->arrsize > 1) ? "}'" : "");
507+
508+
tobeinserted = mallocedval;
471509
break;
472510

473511
case ECPGt_long:
474-
sprintf(buff, "%ld", *(long *) var->value);
475-
tobeinserted = buff;
512+
if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
513+
return false;
514+
515+
sprintf(mallocedval, "%s", (var->arrsize > 1) ? "'{" : "");
516+
517+
for (element = 0; element < var->arrsize; element++)
518+
sprintf(mallocedval + strlen(mallocedval), "%ld,", ((long *) var->value)[element]);
519+
520+
sprintf(mallocedval + strlen(mallocedval) - 1, "%s", (var->arrsize > 1) ? "}'" : "");
521+
522+
tobeinserted = mallocedval;
476523
break;
477524

478525
case ECPGt_unsigned_long:
479-
sprintf(buff, "%ld", *(unsigned long *) var->value);
480-
tobeinserted = buff;
526+
if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
527+
return false;
528+
529+
sprintf(mallocedval, "%s", (var->arrsize > 1) ? "'{" : "");
530+
531+
for (element = 0; element < var->arrsize; element++)
532+
sprintf(mallocedval + strlen(mallocedval), "%ld,", ((unsigned long *) var->value)[element]);
533+
534+
sprintf(mallocedval + strlen(mallocedval) - 1, "%s", (var->arrsize > 1) ? "}'" : "");
535+
536+
tobeinserted = mallocedval;
481537
break;
482538

483539
case ECPGt_float:
484-
sprintf(buff, "%.14g", *(float *) var->value);
485-
tobeinserted = buff;
540+
if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
541+
return false;
542+
543+
sprintf(mallocedval, "%s", (var->arrsize > 1) ? "'{" : "");
544+
545+
for (element = 0; element < var->arrsize; element++)
546+
sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((float *) var->value)[element]);
547+
548+
sprintf(mallocedval + strlen(mallocedval) - 1, "%s", (var->arrsize > 1) ? "}'" : "");
549+
550+
tobeinserted = mallocedval;
486551
break;
487552

488553
case ECPGt_double:
489-
sprintf(buff, "%.14g", *(double *) var->value);
490-
tobeinserted = buff;
554+
if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
555+
return false;
556+
557+
sprintf(mallocedval, "%s", (var->arrsize > 1) ? "'{" : "");
558+
559+
for (element = 0; element < var->arrsize; element++)
560+
sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((double *) var->value)[element]);
561+
562+
sprintf(mallocedval + strlen(mallocedval) - 1, "%s", (var->arrsize > 1) ? "}'" : "");
563+
564+
tobeinserted = mallocedval;
491565
break;
492566

493567
case ECPGt_bool:
494-
sprintf(buff, "'%c'", (*(char *) var->value ? 't' : 'f'));
495-
tobeinserted = buff;
568+
if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
569+
return false;
570+
571+
sprintf(mallocedval, "%s", (var->arrsize > 1) ? "'{" : "");
572+
573+
for (element = 0; element < var->arrsize; element++)
574+
sprintf(mallocedval + strlen(mallocedval), "%c,", (((char *) var->value)[element]) ? 't' : 'f');
575+
576+
sprintf(mallocedval + strlen(mallocedval) - 1, "%s", (var->arrsize > 1) ? "}'" : "");
577+
578+
tobeinserted = mallocedval;
496579
break;
497580

498581
case ECPGt_char:

src/interfaces/ecpg/test/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
all: stp.so test1 test2 test3 test4 test5 perftest
22

33
#LDFLAGS=-g -I /usr/local/pgsql/include -L/usr/local/pgsql/lib -lecpg -lpq -lcrypt
4-
LDFLAGS=-g -I../include -I/usr/include/postgresql -L/usr/lib/postgresql -L../lib -lecpg -lpq -lcrypt
5-
#LDFLAGS=-g -I/usr/include/postgresql -lecpg -lpq -lcrypt
4+
#LDFLAGS=-g -I../include -I/usr/include/postgresql -L/usr/lib/postgresql -L../lib -lecpg -lpq -lcrypt
5+
LDFLAGS=-g -I/usr/include/postgresql -lecpg -lpq -lcrypt
66

77
#ECPG=/usr/local/pgsql/bin/ecpg
88
ECPG=../preproc/ecpg -I../include

src/interfaces/ecpg/test/test1.pgc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void warn(void)
1818
exec sql include sqlca;
1919

2020
/* comment */
21-
exec sql define AMOUNT 4;
21+
exec sql define AMOUNT 6;
2222

2323
exec sql type intarray is int[AMOUNT];
2424
exec sql type string is char(8);
@@ -97,12 +97,18 @@ exec sql end declare section;
9797
printf("Database: mm\n");
9898
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
9999
{
100-
printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, name[i], i, amount[i],i, letter[i][0]);
100+
exec sql begin declare section;
101+
char n[8], l = letter[i][0];
102+
int a = amount[i];
103+
exec sql end declare section;
104+
105+
strncpy(n, name[i], 8);
106+
printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
101107
amount[i]+=1000;
102-
}
103108

104-
strcpy(msg, "insert");
105-
exec sql at pm insert into "Test" (name, amount, letter) values (:name, :amount, :letter);
109+
strcpy(msg, "insert");
110+
exec sql at pm insert into "Test" (name, amount, letter) values (:n, :a, :l);
111+
}
106112

107113
strcpy(msg, "select");
108114
exec sql at pm select * into :name, :amount, :letter from "Test";

src/interfaces/ecpg/test/test4.pgc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ EXEC SQL END DECLARE SECTION;
3030

3131
EXEC SQL INSERT INTO test(f,i,a) VALUES(404.90,1,'{0,1,2,3,4,5,6,7,8,9}');
3232

33-
/* EXEC SQL INSERT INTO test(f,i,a) VALUES(140787.0,2,:a);*/
33+
EXEC SQL INSERT INTO test(f,i,a) VALUES(140787.0,2,:a);
3434

3535
EXEC SQL COMMIT;
3636

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