1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-18 17:42:25 +03:00

Data transferred binary is now put into the variables verbatim.

Also added a test case for a binary cursor.
This commit is contained in:
Michael Meskes
2006-01-17 19:49:23 +00:00
parent 73e3566078
commit f3dda5be89
5 changed files with 154 additions and 59 deletions

View File

@ -1962,6 +1962,15 @@ Fri Dec 2 16:00:10 CET 2005
- Added special handling of CONNECTION variable that is used by ECPG - Added special handling of CONNECTION variable that is used by ECPG
instead of given to the backend. instead of given to the backend.
Fr Jan 13 17:29:30 CET 2006
- Fixed a fixed size buffer in preproc.y to be variable size since an
overflow could occur on the fixed one.
Tu Jan 17 18:53:03 CET 2006
- Data transferred binary is now put into the variables verbatim.
- Set ecpg library version to 5.2. - Set ecpg library version to 5.2.
- Set ecpg version to 4.2.1. - Set ecpg version to 4.2.1.

View File

@ -4,7 +4,7 @@
# #
# Copyright (c) 1994, Regents of the University of California # Copyright (c) 1994, Regents of the University of California
# #
# $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.37 2005/12/09 21:19:35 petere Exp $ # $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.38 2006/01/17 19:49:23 meskes Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -14,7 +14,7 @@ include $(top_builddir)/src/Makefile.global
NAME= ecpg NAME= ecpg
SO_MAJOR_VERSION= 5 SO_MAJOR_VERSION= 5
SO_MINOR_VERSION= 3 SO_MINOR_VERSION= 2
DLTYPE= library DLTYPE= library
override CPPFLAGS := -DFRONTEND -I$(top_srcdir)/src/interfaces/ecpg/include \ override CPPFLAGS := -DFRONTEND -I$(top_srcdir)/src/interfaces/ecpg/include \

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.29 2005/10/15 02:49:47 momjian Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.30 2006/01/17 19:49:23 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL #define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h" #include "postgres_fe.h"
@ -45,11 +45,12 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
long ind_offset, enum ARRAY_TYPE isarray, enum COMPAT_MODE compat, bool force_indicator) long ind_offset, enum ARRAY_TYPE isarray, enum COMPAT_MODE compat, bool force_indicator)
{ {
struct sqlca_t *sqlca = ECPGget_sqlca(); struct sqlca_t *sqlca = ECPGget_sqlca();
char *pval = (char *) PQgetvalue(results, act_tuple, act_field); char *pval = (char *) PQgetvalue(results, act_tuple, act_field);
int value_for_indicator = 0; int binary = PQfformat(results, act_field);
int size = PQgetlength(results, act_tuple, act_field);
ECPGlog("ECPGget_data line %d: RESULT: %s offset: %ld array: %s\n", lineno, pval ? pval : "", offset, isarray ? "Yes" : "No"); int value_for_indicator = 0;
ECPGlog("ECPGget_data line %d: RESULT: %s offset: %ld array: %s\n", lineno, pval ? (binary ? "BINARY" : pval) : "EMPTY", offset, isarray ? "Yes" : "No");
/* We will have to decode the value */ /* We will have to decode the value */
/* /*
@ -131,6 +132,50 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
do do
{ {
if (binary)
{
if (pval)
{
if (varcharsize == 0 || varcharsize*offset >= size)
memcpy((char *) ((long) var + offset * act_tuple), pval, size);
else
{
memcpy((char *) ((long) var + offset * act_tuple), pval, varcharsize*offset);
if (varcharsize*offset < size)
{
/* truncation */
switch (ind_type)
{
case ECPGt_short:
case ECPGt_unsigned_short:
*((short *) (ind + ind_offset * act_tuple)) = size;
break;
case ECPGt_int:
case ECPGt_unsigned_int:
*((int *) (ind + ind_offset * act_tuple)) = size;
break;
case ECPGt_long:
case ECPGt_unsigned_long:
*((long *) (ind + ind_offset * act_tuple)) = size;
break;
#ifdef HAVE_LONG_LONG_INT_64
case ECPGt_long_long:
case ECPGt_unsigned_long_long:
*((long long int *) (ind + ind_offset * act_tuple)) = size;
break;
#endif /* HAVE_LONG_LONG_INT_64 */
default:
break;
}
sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
}
}
pval += size;
}
}
else
{
switch (type) switch (type)
{ {
long res; long res;
@ -619,6 +664,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (*pval == ' ') if (*pval == ' ')
++pval; ++pval;
} }
}
} while (*pval != '\0' && ((isarray == ECPG_ARRAY_ARRAY && *pval != '}') || isarray == ECPG_ARRAY_VECTOR)); } while (*pval != '\0' && ((isarray == ECPG_ARRAY_ARRAY && *pval != '}') || isarray == ECPG_ARRAY_VECTOR));
return (true); return (true);

View File

@ -4,7 +4,7 @@
# #
# Copyright (c) 1998-2005, PostgreSQL Global Development Group # Copyright (c) 1998-2005, PostgreSQL Global Development Group
# #
# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.117 2005/12/09 21:19:36 petere Exp $ # $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.118 2006/01/17 19:49:23 meskes Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -14,7 +14,7 @@ top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
MAJOR_VERSION= 4 MAJOR_VERSION= 4
MINOR_VERSION= 3 MINOR_VERSION= 2
PATCHLEVEL=1 PATCHLEVEL=1
override CPPFLAGS := -I$(srcdir)/../include -I$(srcdir) $(CPPFLAGS) \ override CPPFLAGS := -I$(srcdir)/../include -I$(srcdir) $(CPPFLAGS) \

View File

@ -7,60 +7,100 @@ EXEC SQL typedef short mmSmallInt;
EXEC SQL BEGIN DECLARE SECTION; EXEC SQL BEGIN DECLARE SECTION;
struct TBempl struct TBempl
{
mmInteger idnum;
mmChar name[21];
mmSmallInt accs;
};
EXEC SQL END DECLARE SECTION;
int main(void)
{ {
EXEC SQL BEGIN DECLARE SECTION; mmInteger idnum;
struct TBempl empl; mmChar name[21];
mmSmallInt accs;
mmChar byte[20];
};
EXEC SQL END DECLARE SECTION; EXEC SQL END DECLARE SECTION;
FILE *dbgs;
if ((dbgs = fopen("log", "w")) != NULL) int
ECPGdebug(1, dbgs); main (void)
{
empl.idnum = 1; EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL connect to mm; struct TBempl empl;
if (sqlca.sqlcode) char *data = "\\001\\155\\000\\212";
{ union
printf("connect error = %ld\n", sqlca.sqlcode); {
exit(sqlca.sqlcode); mmSmallInt accs;
} char t[2];
} a;
EXEC SQL END DECLARE SECTION;
FILE *dbgs;
int i;
EXEC SQL create table empl if ((dbgs = fopen ("log", "w")) != NULL)
( ECPGdebug (1, dbgs);
idnum integer,
name char(20),
accs smallint
);
if (sqlca.sqlcode)
{
printf("select error = %ld\n", sqlca.sqlcode);
exit(sqlca.sqlcode);
}
EXEC SQL insert into empl values (1, 'first user', 20); empl.idnum = 1;
if (sqlca.sqlcode) EXEC SQL connect to mm;
{ if (sqlca.sqlcode)
printf("select error = %ld\n", sqlca.sqlcode); {
exit(sqlca.sqlcode); printf ("connect error = %ld\n", sqlca.sqlcode);
} exit (sqlca.sqlcode);
}
EXEC SQL select name, accs EXEC SQL create table empl
into :empl.name, :empl.accs (idnum integer, name char (20), accs smallint, byte bytea);
from empl where idnum = :empl.idnum; if (sqlca.sqlcode)
if (sqlca.sqlcode) {
{ printf ("create error = %ld\n", sqlca.sqlcode);
printf("select error = %ld\n", sqlca.sqlcode); exit (sqlca.sqlcode);
exit(sqlca.sqlcode); }
}
printf("name=%s, accs=%d\n", empl.name, empl.accs); EXEC SQL insert into empl values (1, 'first user', 320,:data);
EXEC SQL disconnect; if (sqlca.sqlcode)
fclose(dbgs); {
exit(0); printf ("insert error = %ld\n", sqlca.sqlcode);
exit (sqlca.sqlcode);
}
EXEC SQL select name, accs, byte into:empl.name,:empl.accs,:empl.byte from empl where idnum =:empl.idnum;
if (sqlca.sqlcode)
{
printf ("select error = %ld\n", sqlca.sqlcode);
exit (sqlca.sqlcode);
}
printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte);
EXEC SQL DECLARE C CURSOR FOR select name, accs, byte from empl where idnum =:empl.idnum;
EXEC SQL OPEN C;
EXEC SQL FETCH C INTO:empl.name,:empl.accs,:empl.byte;
if (sqlca.sqlcode)
{
printf ("fetch error = %ld\n", sqlca.sqlcode);
exit (sqlca.sqlcode);
}
printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte);
memset(empl.name, 0, 21L);
memset(empl.byte, '#', 20L);
EXEC SQL DECLARE B BINARY CURSOR FOR select name, accs, byte from empl where idnum =:empl.idnum;
EXEC SQL OPEN B;
EXEC SQL FETCH B INTO :empl.name,:a.accs,:empl.byte;
if (sqlca.sqlcode)
{
printf ("fetch error = %ld\n", sqlca.sqlcode);
exit (sqlca.sqlcode);
}
EXEC SQL CLOSE B;
i=a.t[0];
a.t[0]=a.t[1];
a.t[1]=i;
printf ("name=%s, accs=%d byte=", empl.name, a.accs);
for (i=0; i<20; i++)
{
if (empl.byte[i] == '#')
break;
printf("(%o)", (unsigned char)empl.byte[i]);
}
printf("\n");
EXEC SQL disconnect;
fclose (dbgs);
exit (0);
} }