From 14c4dbc99d5fdd55c58dc137f0adf44f58882a65 Mon Sep 17 00:00:00 2001 From: Laurenz Albe Date: Mon, 25 Jun 2012 13:28:12 +0000 Subject: [PATCH] Assorted fixes and improvements for the recent patches, release 0.9.6 --- CHANGELOG | 2 +- README.oracle_fdw | 6 +++--- oracle_fdw.c | 6 +++--- oracle_utils.c | 20 ++++++++++---------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a6b29a3..82f09f6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -Version 0.9.6 (beta) +Version 0.9.6 (beta), released 2012-06-25 Enhancements: - Support Oracle types LONG and LONG RAW. Introduce table option "max_long" (default 32767) to set the maximal diff --git a/README.oracle_fdw b/README.oracle_fdw index df8121c..280adaa 100644 --- a/README.oracle_fdw +++ b/README.oracle_fdw @@ -171,9 +171,9 @@ Foreign table options - max_long (optional, defaults to "32767") The maximal length of any LONG or LONG RAW columns in the Oracle table. - Possible values are integers between 1 and 2147483642. This amount of - memory will be allocated at least twice, so large values will consume a lot - of memory. + Possible values are integers between 1 and 1073741823 (the maximal size of a + bytea in PostgreSQL). This amount of memory will be allocated at least + twice, so large values will consume a lot of memory. If "max_long" is less than the length of the longest value retrieved, you will receive the error message "ORA-01406: fetched column value was truncated". diff --git a/oracle_fdw.c b/oracle_fdw.c index 64706c9..319702e 100644 --- a/oracle_fdw.c +++ b/oracle_fdw.c @@ -293,11 +293,11 @@ oracle_fdw_validator(PG_FUNCTION_ARGS) char *val = ((Value *) (def->arg))->val.str; char *endptr; unsigned long max_long = strtoul(val, &endptr, 0); - if (val[0] == '\0' || *endptr != '\0' || max_long < 1 || max_long > 2147483642ul) + if (val[0] == '\0' || *endptr != '\0' || max_long < 1 || max_long > 1073741823ul) ereport(ERROR, (errcode(ERRCODE_FDW_INVALID_ATTRIBUTE_VALUE), errmsg("invalid value for option \"%s\"", def->defname), - errhint("Valid values in this context are integers between 1 and 2147483642"))); + errhint("Valid values in this context are integers between 1 and 1073741823"))); } } @@ -2572,7 +2572,7 @@ struct OracleFdwState state->oraTable->cols[i]->val_size = deserializeLong(lfirst(cell)); cell = lnext(cell); /* allocate memory for the result value */ - state->oraTable->cols[i]->val = (char *)palloc(state->oraTable->cols[i]->val_size); + state->oraTable->cols[i]->val = (char *)palloc(state->oraTable->cols[i]->val_size + 1); state->oraTable->cols[i]->val_len = 0; state->oraTable->cols[i]->val_null = 1; } diff --git a/oracle_utils.c b/oracle_utils.c index ce99de2..78b3b9f 100644 --- a/oracle_utils.c +++ b/oracle_utils.c @@ -104,7 +104,7 @@ struct oracleSession static void setOracleEnvironment(char *nls_lang); static void oracleQueryPlan(oracleSession *session, const char *query, const char *desc_query, int nres, dvoid **res, sb4 *res_size, ub2 *res_type, ub2 *res_len, sb2 *res_ind); static sword checkerr(sword status, dvoid *handle, ub4 handleType); -static char *copyOraText(const OraText *string, ub4 size, int quote); +static char *copyOraText(const OraText *string, int size, int quote); static void closeSession(OCIEnv *envhp, OCIServer *srvhp, OCISession *userhp, int disconnect); static void disconnectServer(OCIEnv *envhp, OCIServer *srvhp); static void removeEnvironment(OCIEnv *envhp); @@ -708,7 +708,7 @@ struct oraTable oraMessage); } - name = copyOraText(ident, ident_size, 1); + name = copyOraText(ident, (int)ident_size, 1); /* referenced table schema */ if (checkerr( @@ -721,7 +721,7 @@ struct oraTable oraMessage); } - schema = copyOraText(ident, ident_size, 1); + schema = copyOraText(ident, (int)ident_size, 1); /* referenced table database link */ if (checkerr( @@ -734,7 +734,7 @@ struct oraTable oraMessage); } - link = copyOraText(ident, ident_size, 0); + link = copyOraText(ident, (int)ident_size, 0); /* construct a table name for the next lookup */ synonym_len = strlen(name); @@ -861,7 +861,7 @@ struct oraTable oraMessage); } - reply->cols[i-1]->name = copyOraText(ident, ident_size, 1); + reply->cols[i-1]->name = copyOraText(ident, (int)ident_size, 1); /* get the data type */ if (checkerr( @@ -1029,12 +1029,12 @@ struct oraTable case SQLT_LBI: /* LONG RAW */ reply->cols[i-1]->oratype = ORA_TYPE_LONGRAW; - reply->cols[i-1]->val_size = max_long + 5; + reply->cols[i-1]->val_size = max_long + 4; break; case SQLT_LNG: /* LONG */ reply->cols[i-1]->oratype = ORA_TYPE_LONG; - reply->cols[i-1]->val_size = max_long + 5; + reply->cols[i-1]->val_size = max_long + 4; break; case SQLT_BIN: /* RAW(n) */ @@ -1911,7 +1911,7 @@ checkerr(sword status, dvoid *handle, ub4 handleType) * Returns a palloc'ed string containing a (possibly quoted) copy of "string". */ char -*copyOraText(const OraText *string, ub4 size, int quote) +*copyOraText(const OraText *string, int size, int quote) { int resultsize = (quote ? size + 2 : size); register int i, j=-1; @@ -1919,7 +1919,7 @@ char if (quote) { - for (i=0; i<(int)size; ++i) + for (i=0; i