Let SQLDescribeCol() use parsed result when the current executed result is NULL.
authorHiroshi Inoue <h-inoue@dream.email.ne.jp>
Wed, 7 Apr 2021 09:36:40 +0000 (18:36 +0900)
committerHiroshi Inoue <h-inoue@dream.email.ne.jp>
Wed, 21 Apr 2021 12:05:15 +0000 (21:05 +0900)
This change fixes the diff of prepare-test regression test reported by Mangold Fabian.

parse.c
pgtypes.c
results.c
statement.c
statement.h

diff --git a/parse.c b/parse.c
index b41143060c7a6f1951a688d6d9fcf229fb28a483..366d514d7fa1da979f4ca7b948a0829527ce7a29 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -613,7 +613,7 @@ static BOOL
 ColAttSet(StatementClass *stmt, TABLE_INFO *rti)
 {
    CSTR        func = "ColAttSet";
-   QResultClass    *res = SC_get_Parsed(stmt);
+   QResultClass    *res = SC_get_ExecdOrParsed(stmt);
    IRDFields   *irdflds = SC_get_IRDF(stmt);
    COL_INFO    *col_info = NULL;
    FIELD_INFO  **fi, *wfi;
@@ -824,7 +824,7 @@ getColumnsInfo(ConnectionClass *conn, TABLE_INFO *wti, OID greloid, StatementCla
                               PODBC_NOT_SEARCH_PATTERN, 0, 0);
 
    MYLOG(0, "        Past PG_Columns\n");
-   res = SC_get_Parsed(col_stmt);
+   res = SC_get_ExecdOrParsed(col_stmt);
    if (SQL_SUCCEEDED(result)
        && res != NULL && QR_get_num_cached_tuples(res) > 0)
    {
index c09df05c4101971c730040a7e0aec4664c24f043..a8ded27063bb2f0e9e9c4dfb94d9e4e4f0313094 100644 (file)
--- a/pgtypes.c
+++ b/pgtypes.c
@@ -877,6 +877,7 @@ Int4    /* PostgreSQL restriction */
 pgtype_attr_column_size(const ConnectionClass *conn, OID type, int atttypmod, int adtsize_or_longest, int handle_unknown_size_as)
 {
    const ConnInfo  *ci = &(conn->connInfo);
+MYLOG(0, "entering type=%d, atttypmod=%d, adtsize_or=%d, unknown = %d\n", type, atttypmod, adtsize_or_longest, handle_unknown_size_as);
 
    switch (type)
    {
@@ -1486,7 +1487,7 @@ getAtttypmodEtc(const StatementClass *stmt, int col, int *adtsize_or_longestlen)
    {
        const QResultClass  *res;
 
-       if (res = SC_get_Curres(stmt), NULL != res)
+       if (res = SC_get_ExecdOrParsed(stmt), NULL != res)
        {
            atttypmod = QR_get_atttypmod(res, col);
            if (NULL != adtsize_or_longestlen)
index b9d96d97db51f70ec45f939d03e3abf9d5ccd25d..1f6a12c8eaa78f05f7e146fbc9a82354b52ea66f 100644 (file)
--- a/results.c
+++ b/results.c
@@ -93,7 +93,7 @@ SC_describe_ok(StatementClass *stmt, BOOL build_fi, int col_idx, const char *fun
    BOOL        exec_ok = TRUE;
 
    num_fields = SC_describe(stmt);
-   result = SC_get_Parsed(stmt);
+   result = SC_get_ExecdOrParsed(stmt);
 
    MYLOG(0, "entering result = %p, status = %d, numcols = %d\n", result, stmt->status, result != NULL ? QR_NumResultCols(result) : -1);
    /****if ((!result) || ((stmt->status != STMT_FINISHED) && (stmt->status != STMT_PREMATURE))) ****/
@@ -191,7 +191,7 @@ PGAPI_NumResultCols(HSTMT hstmt,
            goto cleanup;
        }
 
-       result = SC_get_Parsed(stmt);
+       result = SC_get_ExecdOrParsed(stmt);
        *pccol = QR_NumPublicResultCols(result);
    }
 
@@ -321,7 +321,7 @@ MYLOG(DETAIL_LOG_LEVEL, "answering bookmark info\n");
            goto cleanup;
        }
 
-       res = SC_get_Parsed(stmt);
+       res = SC_get_ExecdOrParsed(stmt);
        if (icol >= QR_NumPublicResultCols(res))
        {
            SC_set_error(stmt, STMT_INVALID_COLUMN_NUMBER_ERROR, "Invalid column number in DescribeCol.", func);
@@ -333,7 +333,7 @@ MYLOG(DETAIL_LOG_LEVEL, "answering bookmark info\n");
        if (icol < irdflds->nfields && irdflds->fi)
            fi = irdflds->fi[icol];
    }
-   res = SC_get_Parsed(stmt);
+   res = SC_get_ExecdOrParsed(stmt);
 #ifdef SUPPRESS_LONGEST_ON_CURSORS
    if (UNKNOWNS_AS_LONGEST == unknown_sizes)
    {
@@ -513,7 +513,7 @@ PGAPI_ColAttributes(HSTMT hstmt,
     * is ignored anyway, so it may be 0.
     */
 
-   res = SC_get_Parsed(stmt);
+   res = SC_get_ExecdOrParsed(stmt);
    if (0 == icol && SQL_DESC_COUNT != fDescType) /* bookmark column */
    {
 MYLOG(DETAIL_LOG_LEVEL, "answering bookmark info\n");
@@ -600,7 +600,7 @@ MYLOG(DETAIL_LOG_LEVEL, "answering bookmark info\n");
        if (!SC_describe_ok(stmt, build_fi, col_idx, func))
            return SQL_ERROR;
 
-       res = SC_get_Parsed(stmt);
+       res = SC_get_ExecdOrParsed(stmt);
        cols = QR_NumPublicResultCols(res);
 
        /*
index eea2c869b2aace7c8227b38e1f2bcb80ffe0abed..d79d323a2d9fa727ed43da7808cd79dde26ab8e4 100644 (file)
@@ -1134,7 +1134,7 @@ SC_describe(StatementClass *self)
    QResultClass    *res;
    MYLOG(0, "entering status = %d\n", self->status);
 
-   res = SC_get_Parsed(self);
+   res = SC_get_ExecdOrParsed(self);
    if (NULL != res)
    {
        num_fields = QR_NumResultCols(res);
@@ -1168,7 +1168,7 @@ MYLOG(0, "              preprocess: status = READY\n");
                self->status = STMT_DESCRIBED;
                break;
        }
-       if (res = SC_get_Parsed(self), NULL != res)
+       if (res = SC_get_ExecdOrParsed(self), NULL != res)
        {
            num_fields = QR_NumResultCols(res);
            return num_fields;
@@ -1215,7 +1215,7 @@ SC_clear_error(StatementClass *self)
        self->pgerror = NULL;
    }
    self->diag_row_count = 0;
-   if (res = SC_get_Curres(self), res)
+   if (res = SC_get_ExecdOrParsed(self), res)
    {
        QR_set_message(res, NULL);
        QR_set_notice(res, NULL);
@@ -1291,7 +1291,7 @@ static const struct
 static PG_ErrorInfo *
 SC_create_errorinfo(const StatementClass *self, PG_ErrorInfo *pgerror_fail_safe)
 {
-   QResultClass *res = SC_get_Curres(self);
+   QResultClass *res = SC_get_ExecdOrParsed(self);
    ConnectionClass *conn = SC_get_conn(self);
    Int4    errornum;
    size_t      pos;
@@ -1301,8 +1301,6 @@ SC_create_errorinfo(const StatementClass *self, PG_ErrorInfo *pgerror_fail_safe)
    char        *ermsg = NULL, *sqlstate = NULL;
    PG_ErrorInfo    *pgerror;
 
-   if (!res)
-       res = SC_get_Parsed(self);
    if (self->pgerror)
        return self->pgerror;
    errornum = self->__error_number;
@@ -1491,7 +1489,7 @@ MYLOG(DETAIL_LOG_LEVEL, "entering %p->%p check=%i\n", from_res ,self, check);
        ER_Destructor(self->pgerror);
        self->pgerror = NULL;
    }
-   self_res = SC_get_Curres(self);
+   self_res = SC_get_ExecdOrParsed(self);
    if (!self_res) return;
    if (self_res == from_res)   return;
    QR_add_message(self_res, QR_get_message(from_res));
@@ -1539,8 +1537,8 @@ MYLOG(DETAIL_LOG_LEVEL, "entering %p->%p check=%i\n", from ,self, check);
        ER_Destructor(self->pgerror);
        self->pgerror = NULL;
    }
-   self_res = SC_get_Curres(self);
-   from_res = SC_get_Curres(from);
+   self_res = SC_get_ExecdOrParsed(self);
+   from_res = SC_get_ExecdOrParsed(from);
    if (!self_res || !from_res)
        return;
    QR_add_message(self_res, QR_get_message(from_res));
index 9ba1c7bf6e0e7af6541fbcac63c522b3c93e6f35..230c3aefc08c7654cf5a3d0034b2d967ff32e8a1 100644 (file)
@@ -327,7 +327,7 @@ QResultClass *SC_get_lastres(StatementClass *stmt);
 #define SC_get_Result(a)  ((a)->rhold).first
 #define SC_set_Curres(a, b)  ((a)->curres = b)
 #define SC_get_Curres(a)  ((a)->curres)
-#define SC_get_Parsed(a)  ((a)->parsed ? (a)->parsed : (a)->curres)
+#define SC_get_ExecdOrParsed(a)  ((a)->curres ? (a)->curres : (a)->parsed)
 #define SC_get_ARD(a)  ((a)->ard)
 #define SC_get_APD(a)  ((a)->apd)
 #define SC_get_IRD(a)  ((a)->ird)