Arrays can be read as arrays or as character strings now.

This commit is contained in:
Michael Meskes 2004-06-28 11:47:42 +00:00
parent 04ab0cb5c1
commit e48cfacb84
3 changed files with 29 additions and 5 deletions

View File

@ -1821,6 +1821,10 @@ Sun Jun 27 13:50:58 CEST 2004
- Variables that are out of scope, were not removed all the time.
- Make a varchar NULL set everything to 0 when not using indicators.
- Synced parser.
Mon Jun 28 11:08:42 CEST 2004
- Arrays can be read as arrays or as character strings now.
- Set pgtypes library version to 1.2.
- Set ecpg version to 3.2.0.
- Set compat library version to 1.2.

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.24 2004/06/27 12:28:39 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.25 2004/06/28 11:47:41 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@ -152,6 +152,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
ECPGraise(lineno, ECPG_INT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
pval = scan_length;
}
else
res = 0L;
@ -184,6 +185,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
ECPGraise(lineno, ECPG_UINT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
pval = scan_length;
}
else
ures = 0L;
@ -216,6 +218,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
ECPGraise(lineno, ECPG_INT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
pval = scan_length;
}
else
*((long long int *) (var + offset * act_tuple)) = (long long) 0;
@ -233,6 +236,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
ECPGraise(lineno, ECPG_UINT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
pval = scan_length;
}
else
*((unsigned long long int *) (var + offset * act_tuple)) = (long long) 0;
@ -258,6 +262,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
ECPGraise(lineno, ECPG_FLOAT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
pval = scan_length;
}
else
dres = 0.0;
@ -312,8 +317,9 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
case ECPGt_char:
case ECPGt_unsigned_char:
if (pval)
{
if (varcharsize == 0)
if (varcharsize == 0 || varcharsize > strlen(pval))
strncpy((char *) ((long) var + offset * act_tuple), pval, strlen(pval) + 1);
else
{
@ -348,10 +354,12 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
}
}
pval += strlen(pval);
}
break;
case ECPGt_varchar:
if (pval)
{
struct ECPGgeneric_varchar *variable =
(struct ECPGgeneric_varchar *) ((long) var + offset * act_tuple);
@ -394,6 +402,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
variable->len = varcharsize;
}
}
pval += strlen(pval);
}
break;
@ -433,6 +442,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
return (false);
}
}
pval = scan_length;
}
else
nres = PGTYPESnumeric_from_asc("0.0", &scan_length);
@ -476,6 +486,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
return (false);
}
}
pval = scan_length;
}
else
ires = PGTYPESinterval_from_asc("0 seconds", NULL);
@ -517,6 +528,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
*((date *) (var + offset * act_tuple)) = ddres;
pval = scan_length;
}
break;
@ -555,6 +567,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
*((timestamp *) (var + offset * act_tuple)) = tres;
pval = scan_length;
}
break;
@ -571,7 +584,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
++act_tuple;
/* set pval to the next entry */
for (; string || (*pval != ',' && *pval != '}'); ++pval)
for (; string || (*pval != ',' && *pval != '}' && *pval != '\0'); ++pval)
if (*pval == '"')
string = string ? false : true;
@ -593,7 +606,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (*pval == ' ')
++pval;
}
} while ((isarray == ECPG_ARRAY_ARRAY && *pval != '}') || (isarray == ECPG_ARRAY_VECTOR && *pval != '\0'));
} while (*pval != '\0' && ((isarray == ECPG_ARRAY_ARRAY && *pval != '}') || isarray == ECPG_ARRAY_VECTOR));
return (true);
}

View File

@ -13,7 +13,7 @@ EXEC SQL BEGIN DECLARE SECTION;
int i = 1;
int *did = &i;
int a[10] = {9,8,7,6,5,4,3,2,1,0};
char text[10] = "klmnopqrst";
char text[25] = "klmnopqrst";
char *t = (char *)malloc(10);
double f;
bool b = true;
@ -64,6 +64,13 @@ EXEC SQL END DECLARE SECTION;
printf("Found text=%10.10s\n", t);
EXEC SQL SELECT a
INTO :text
FROM test
WHERE f = :f;
printf("Found text=%s\n", text);
EXEC SQL DROP TABLE test;
EXEC SQL COMMIT;