Commit f3dda5be authored by Michael Meskes's avatar Michael Meskes

Data transferred binary is now put into the variables verbatim.

Also added a test case for a binary cursor.
parent 73e35660
...@@ -1962,6 +1962,15 @@ Fri Dec 2 16:00:10 CET 2005 ...@@ -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 @@ ...@@ -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 ...@@ -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 \
......
/* $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, ...@@ -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, ...@@ -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, ...@@ -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 @@ ...@@ -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 = ../../../.. ...@@ -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) \
......
...@@ -7,60 +7,100 @@ EXEC SQL typedef short mmSmallInt; ...@@ -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; 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;
EXEC SQL END DECLARE SECTION; char *data = "\\001\\155\\000\\212";
FILE *dbgs; union
{
mmSmallInt accs;
char t[2];
} a;
EXEC SQL END DECLARE SECTION;
FILE *dbgs;
int i;
if ((dbgs = fopen ("log", "w")) != NULL)
ECPGdebug (1, dbgs);
empl.idnum = 1;
EXEC SQL connect to mm;
if (sqlca.sqlcode)
{
printf ("connect error = %ld\n", sqlca.sqlcode);
exit (sqlca.sqlcode);
}
EXEC SQL create table empl
(idnum integer, name char (20), accs smallint, byte bytea);
if (sqlca.sqlcode)
{
printf ("create error = %ld\n", sqlca.sqlcode);
exit (sqlca.sqlcode);
}
EXEC SQL insert into empl values (1, 'first user', 320,:data);
if (sqlca.sqlcode)
{
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);
}
if ((dbgs = fopen("log", "w")) != NULL) printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte);
ECPGdebug(1, dbgs);
empl.idnum = 1;
EXEC SQL connect to mm;
if (sqlca.sqlcode)
{
printf("connect error = %ld\n", sqlca.sqlcode);
exit(sqlca.sqlcode);
}
EXEC SQL create table empl memset(empl.name, 0, 21L);
( memset(empl.byte, '#', 20L);
idnum integer, EXEC SQL DECLARE B BINARY CURSOR FOR select name, accs, byte from empl where idnum =:empl.idnum;
name char(20), EXEC SQL OPEN B;
accs smallint EXEC SQL FETCH B INTO :empl.name,:a.accs,:empl.byte;
); if (sqlca.sqlcode)
if (sqlca.sqlcode) {
{ printf ("fetch error = %ld\n", sqlca.sqlcode);
printf("select error = %ld\n", sqlca.sqlcode); exit (sqlca.sqlcode);
exit(sqlca.sqlcode); }
}
EXEC SQL insert into empl values (1, 'first user', 20); EXEC SQL CLOSE B;
if (sqlca.sqlcode)
{
printf("select error = %ld\n", sqlca.sqlcode);
exit(sqlca.sqlcode);
}
EXEC SQL select name, accs i=a.t[0];
into :empl.name, :empl.accs a.t[0]=a.t[1];
from empl where idnum = :empl.idnum; a.t[1]=i;
if (sqlca.sqlcode)
{ printf ("name=%s, accs=%d byte=", empl.name, a.accs);
printf("select error = %ld\n", sqlca.sqlcode); for (i=0; i<20; i++)
exit(sqlca.sqlcode); {
} if (empl.byte[i] == '#')
printf("name=%s, accs=%d\n", empl.name, empl.accs); break;
EXEC SQL disconnect; printf("(%o)", (unsigned char)empl.byte[i]);
fclose(dbgs); }
exit(0); printf("\n");
EXEC SQL disconnect;
fclose (dbgs);
exit (0);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment