1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-27 07:42:10 +03:00

Add Oracle like handling of char arrays.

In some cases Oracle Pro*C handles char array differently than ECPG. This patch
adds a Oracle compatibility mode to make ECPG behave like Pro*C.

Patch by David Rader <davidr@openscg.com>
This commit is contained in:
Michael Meskes
2018-03-14 00:54:13 +01:00
parent db2fc801f6
commit 3b7ab43804
12 changed files with 513 additions and 5 deletions

View File

@@ -464,7 +464,45 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (varcharsize == 0 || varcharsize > size)
{
strncpy(str, pval, size + 1);
/* compatibility mode, blank pad and null terminate char array */
if (ORACLE_MODE(compat) && (type == ECPGt_char || type == ECPGt_unsigned_char))
{
memset(str, ' ', varcharsize);
memcpy(str, pval, size);
str[varcharsize-1] = '\0';
/* compatiblity mode empty string gets -1 indicator but no warning */
if (size == 0) {
/* truncation */
switch (ind_type)
{
case ECPGt_short:
case ECPGt_unsigned_short:
*((short *) (ind + ind_offset * act_tuple)) = -1;
break;
case ECPGt_int:
case ECPGt_unsigned_int:
*((int *) (ind + ind_offset * act_tuple)) = -1;
break;
case ECPGt_long:
case ECPGt_unsigned_long:
*((long *) (ind + ind_offset * act_tuple)) = -1;
break;
#ifdef HAVE_LONG_LONG_INT
case ECPGt_long_long:
case ECPGt_unsigned_long_long:
*((long long int *) (ind + ind_offset * act_tuple)) = -1;
break;
#endif /* HAVE_LONG_LONG_INT */
default:
break;
}
}
}
else
{
strncpy(str, pval, size + 1);
}
/* do the rtrim() */
if (type == ECPGt_string)
{
@@ -481,7 +519,14 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
{
strncpy(str, pval, varcharsize);
if (varcharsize < size)
/* compatibility mode, null terminate char array */
if (ORACLE_MODE(compat) && (varcharsize - 1) < size)
{
if (type == ECPGt_char || type == ECPGt_unsigned_char)
str[varcharsize-1] = '\0';
}
if (varcharsize < size || (ORACLE_MODE(compat) && (varcharsize - 1) < size))
{
/* truncation */
switch (ind_type)