Data transferred binary is now put into the variables verbatim.
Also added a test case for a binary cursor.
This commit is contained in:
parent
73e3566078
commit
f3dda5be89
@ -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.
|
||||||
|
|
||||||
|
@ -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 \
|
||||||
|
@ -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"
|
||||||
@ -46,10 +46,11 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
|||||||
{
|
{
|
||||||
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 binary = PQfformat(results, act_field);
|
||||||
|
int size = PQgetlength(results, act_tuple, act_field);
|
||||||
int value_for_indicator = 0;
|
int value_for_indicator = 0;
|
||||||
|
|
||||||
ECPGlog("ECPGget_data line %d: RESULT: %s offset: %ld array: %s\n", lineno, pval ? pval : "", offset, isarray ? "Yes" : "No");
|
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 */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -130,6 +131,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)
|
||||||
{
|
{
|
||||||
@ -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);
|
||||||
|
@ -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) \
|
||||||
|
@ -11,15 +11,24 @@ struct TBempl
|
|||||||
mmInteger idnum;
|
mmInteger idnum;
|
||||||
mmChar name[21];
|
mmChar name[21];
|
||||||
mmSmallInt accs;
|
mmSmallInt accs;
|
||||||
|
mmChar byte[20];
|
||||||
};
|
};
|
||||||
EXEC SQL END DECLARE SECTION;
|
EXEC SQL END DECLARE SECTION;
|
||||||
|
|
||||||
int main(void)
|
int
|
||||||
|
main (void)
|
||||||
{
|
{
|
||||||
EXEC SQL BEGIN DECLARE SECTION;
|
EXEC SQL BEGIN DECLARE SECTION;
|
||||||
struct TBempl empl;
|
struct TBempl empl;
|
||||||
|
char *data = "\\001\\155\\000\\212";
|
||||||
|
union
|
||||||
|
{
|
||||||
|
mmSmallInt accs;
|
||||||
|
char t[2];
|
||||||
|
} a;
|
||||||
EXEC SQL END DECLARE SECTION;
|
EXEC SQL END DECLARE SECTION;
|
||||||
FILE *dbgs;
|
FILE *dbgs;
|
||||||
|
int i;
|
||||||
|
|
||||||
if ((dbgs = fopen ("log", "w")) != NULL)
|
if ((dbgs = fopen ("log", "w")) != NULL)
|
||||||
ECPGdebug (1, dbgs);
|
ECPGdebug (1, dbgs);
|
||||||
@ -33,33 +42,64 @@ if (sqlca.sqlcode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
EXEC SQL create table empl
|
EXEC SQL create table empl
|
||||||
(
|
(idnum integer, name char (20), accs smallint, byte bytea);
|
||||||
idnum integer,
|
|
||||||
name char(20),
|
|
||||||
accs smallint
|
|
||||||
);
|
|
||||||
if (sqlca.sqlcode)
|
if (sqlca.sqlcode)
|
||||||
{
|
{
|
||||||
printf("select error = %ld\n", sqlca.sqlcode);
|
printf ("create error = %ld\n", sqlca.sqlcode);
|
||||||
exit (sqlca.sqlcode);
|
exit (sqlca.sqlcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXEC SQL insert into empl values (1, 'first user', 20);
|
EXEC SQL insert into empl values (1, 'first user', 320,:data);
|
||||||
if (sqlca.sqlcode)
|
if (sqlca.sqlcode)
|
||||||
{
|
{
|
||||||
printf("select error = %ld\n", sqlca.sqlcode);
|
printf ("insert error = %ld\n", sqlca.sqlcode);
|
||||||
exit (sqlca.sqlcode);
|
exit (sqlca.sqlcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXEC SQL select name, accs
|
EXEC SQL select name, accs, byte into:empl.name,:empl.accs,:empl.byte from empl where idnum =:empl.idnum;
|
||||||
into :empl.name, :empl.accs
|
|
||||||
from empl where idnum = :empl.idnum;
|
|
||||||
if (sqlca.sqlcode)
|
if (sqlca.sqlcode)
|
||||||
{
|
{
|
||||||
printf ("select 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);
|
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;
|
EXEC SQL disconnect;
|
||||||
fclose (dbgs);
|
fclose (dbgs);
|
||||||
exit (0);
|
exit (0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user