A code cleaup.
authorHiroshi Inoue <h-inoue@dream.email.ne.jp>
Thu, 2 Jul 2020 10:53:34 +0000 (19:53 +0900)
committerHiroshi Inoue <h-inoue@dream.email.ne.jp>
Sun, 19 Jul 2020 04:29:29 +0000 (13:29 +0900)
Remove curr_param_result property of StatementClass and separate parsed result from the exec result.

convert.c
execute.c
parse.c
results.c
statement.c
statement.h

index ce0ee46fddbd566a6b6439d4a9f466eca6bbfa0c..47539de3ae923878c15cfc354fdda6e6705d722f 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -2839,7 +2839,9 @@ MYLOG(DETAIL_LOG_LEVEL, "entering\n");
    res = ParseAndDescribeWithLibpq(stmt, plan_name, pstmt->query, pstmt->num_params, "prepare_and_describe", NULL);
    if (res == NULL)
        goto cleanup;
-   SC_set_Result(stmt, res);
+   // SC_set_Result(stmt, res);
+   QR_Destructor(stmt->parsed);
+   stmt->parsed = res;
    if (!QR_command_maybe_successful(res))
    {
        SC_set_error(stmt, STMT_EXEC_ERROR, "Error while preparing parameters", func);
index 11cf4bcff415d06e2b39ce7a832d3d7d12bfc2b2..8ea02b91870cf77adcc1c74e22e896a89ca2c15f 100644 (file)
--- a/execute.c
+++ b/execute.c
@@ -1181,7 +1181,6 @@ next_param_row:
    retval = Exec_with_parameters_resolved(stmt, stmt->exec_type, &exec_end);
    if (!exec_end)
    {
-       stmt->curr_param_result = 0;
        goto next_param_row;
    }
 cleanup:
@@ -1475,10 +1474,6 @@ MYLOG(DETAIL_LOG_LEVEL, "ipdopts=%p\n", ipdopts);
            retval = dequeueNeedDataCallback(retval, stmt);
            goto cleanup;
        }
-       else
-       {
-           stmt->curr_param_result = 0;
-       }
 
        if (retval = PGAPI_Execute(estmt, flag), SQL_NEED_DATA != retval)
        {
diff --git a/parse.c b/parse.c
index 88593a1a06b90d5690094a0aaa9acc9ba6ea3399..b41143060c7a6f1951a688d6d9fcf229fb28a483 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_Curres(stmt);
+   QResultClass    *res = SC_get_Parsed(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_Curres(col_stmt);
+   res = SC_get_Parsed(col_stmt);
    if (SQL_SUCCEEDED(result)
        && res != NULL && QR_get_num_cached_tuples(res) > 0)
    {
index b8c6f456070073a9bcfd68d8f699bec358a2b630..b9d96d97db51f70ec45f939d03e3abf9d5ccd25d 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_Curres(stmt);
+   result = SC_get_Parsed(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_Curres(stmt);
+       result = SC_get_Parsed(stmt);
        *pccol = QR_NumPublicResultCols(result);
    }
 
@@ -321,7 +321,7 @@ MYLOG(DETAIL_LOG_LEVEL, "answering bookmark info\n");
            goto cleanup;
        }
 
-       res = SC_get_Curres(stmt);
+       res = SC_get_Parsed(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_Curres(stmt);
+   res = SC_get_Parsed(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_Curres(stmt);
+   res = SC_get_Parsed(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_Curres(stmt);
+       res = SC_get_Parsed(stmt);
        cols = QR_NumPublicResultCols(res);
 
        /*
index 9e5b411b1656e3767d25b79dcec0cfcf29975494..07e4ff888875e2ec5e3f6ee75e8d054b51f76606 100644 (file)
@@ -380,6 +380,7 @@ SC_Constructor(ConnectionClass *conn)
        rv->phstmt = NULL;
        rv->rhold.first = rv->rhold.last = NULL;
        rv->curres = NULL;
+       rv->parsed = NULL;
        rv->catalog_result = FALSE;
        rv->prepare = NON_PREPARE_STATEMENT;
        rv->prepared = NOT_YET_PREPARED;
@@ -418,7 +419,6 @@ SC_Constructor(ConnectionClass *conn)
        rv->put_data = FALSE;
        rv->ref_CC_error = FALSE;
        rv->join_info = 0;
-       rv->curr_param_result = 0;
        SC_init_parse_method(rv);
 
        rv->lobj_fd = -1;
@@ -530,7 +530,6 @@ SC_init_Result(StatementClass *self)
 {
    self->rhold.first = self->rhold.last = NULL;
    self->curres = NULL;
-   self->curr_param_result = 0;
    MYLOG(0, "leaving(%p)\n", self);
 }
 
@@ -542,14 +541,14 @@ SC_set_Result(StatementClass *self, QResultClass *first)
        QResultClass *last = NULL, *res;
 
        MYLOG(0, "(%p, %p)\n", self, first);
+       QR_Destructor(self->parsed);
+       self->parsed = NULL;
        QR_Destructor(self->rhold.first);
        for (res = first; res; res = QR_nextr(res))
            last = res;
        self->curres = first;
        self->rhold.first = first;
        self->rhold.last = last;
-       if (NULL != first)
-           self->curr_param_result = 1;
    }
 }
 
@@ -559,11 +558,11 @@ SC_set_ResultHold(StatementClass *self, QResultHold rhold)
    if (rhold.first != self->rhold.first)
    {
        MYLOG(0, "(%p, {%p, %p})\n", self, rhold.first, rhold.last);
+       QR_Destructor(self->parsed);
+       self->parsed = NULL;
        QR_Destructor(self->rhold.first);
        self->curres = rhold.first;
        self->rhold = rhold;
-       if (NULL != rhold.first)
-           self->curr_param_result = 1;
    }
    else if (rhold.last != self->rhold.last)
    {
@@ -836,7 +835,6 @@ SC_reset_result_for_rerun(StatementClass *self)
    else
    {
        QR_reset_for_re_execute(res);
-       self->curr_param_result = 1;
        SC_set_Curres(self, NULL);
    }
 }
@@ -901,6 +899,8 @@ MYLOG(DETAIL_LOG_LEVEL, "SC_clear_parse_status\n");
    /* Free any cursors */
    if (SC_get_Result(self))
        SC_set_Result(self, NULL);
+   QR_Destructor(self->parsed);
+   self->parsed = NULL;
    self->miscinfo = 0;
    self->execinfo = 0;
    /* self->rbonerr = 0; Never clear the bits here */
@@ -1134,7 +1134,7 @@ SC_describe(StatementClass *self)
    QResultClass    *res;
    MYLOG(0, "entering status = %d\n", self->status);
 
-   res = SC_get_Curres(self);
+   res = SC_get_Parsed(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_Curres(self), NULL != res)
+       if (res = SC_get_Parsed(self), NULL != res)
        {
            num_fields = QR_NumResultCols(res);
            return num_fields;
@@ -1292,6 +1292,8 @@ static PG_ErrorInfo *
 SC_create_errorinfo(const StatementClass *self, PG_ErrorInfo *pgerror_fail_safe)
 {
    QResultClass *res = SC_get_Curres(self);
+   if (!res)
+       res = SC_get_Parsed(self);
    ConnectionClass *conn = SC_get_conn(self);
    Int4    errornum;
    size_t      pos;
@@ -2043,9 +2045,6 @@ SC_execute(StatementClass *self)
            appendq = fetch;
            qflag &= (~READ_ONLY_QUERY); /* must be a SAVEPOINT after DECLARE */
        }
-       first = SC_get_Result(self);
-       if (self->curr_param_result && first)
-           SC_set_Result(self, QR_nextr(first));
        rhold = CC_send_query_append(conn, self->stmt_with_params, qryi, qflag, SC_get_ancestor(self), appendq);
        first = rhold.first;    
        if (useCursor && QR_command_maybe_successful(first))
@@ -2233,7 +2232,6 @@ MYLOG(DETAIL_LOG_LEVEL, "!!%p->miscinfo=%x res=%p\n", self, self->miscinfo, firs
        if (self->rhold.last != rhold.first)
            QR_concat(self->rhold.last, rhold.first);
        self->rhold.last = rhold.last;
-       self->curr_param_result = 1;
    }
    if (NULL == SC_get_Curres(self))
        SC_set_Curres(self, SC_get_Result(self));
@@ -2535,10 +2533,7 @@ QResultClass *add_libpq_notice_receiver(StatementClass *stmt, notice_receiver_ar
 {
    QResultClass *res = NULL, *newres = NULL;
 
-   if (stmt->curr_param_result)
-       res = stmt->rhold.last;
-   if (!res)
-       newres = res = QR_Constructor();
+   newres = res = QR_Constructor();
    nrarg->conn = SC_get_conn(stmt);
    nrarg->comment = __FUNCTION__;
    nrarg->res = res;
@@ -2666,7 +2661,7 @@ libpq_bind_and_exec(StatementClass *stmt)
    }
 
    /* 3. Receive results */
-MYLOG(DETAIL_LOG_LEVEL, "get_Result=%p %p %d\n", res, SC_get_Result(stmt), stmt->curr_param_result);
+MYLOG(DETAIL_LOG_LEVEL, "get_Result=%p %p\n", res, SC_get_Result(stmt));
    pgresstatus = PQresultStatus(pgres);
    switch (pgresstatus)
    {
index 84df7de295b3e42f2df977717eea915288eae822..9ba1c7bf6e0e7af6541fbcac63c522b3c93e6f35 100644 (file)
@@ -206,9 +206,8 @@ struct StatementClass_
    ConnectionClass *hdbc;      /* pointer to ConnectionClass this
                                 * statement belongs to */
    QResultHold rhold;
-   // QResultClass *result;        /* result of the current statement */
    QResultClass *curres;       /* the current result in the chain */
-   // QResultClass *lastres;       /* maybe the last result in the chain */
+   QResultClass *parsed;       /* parsed result before exec */
    HSTMT      *phstmt;
    StatementOptions options;
    StatementOptions options_orig;
@@ -279,7 +278,6 @@ struct StatementClass_
    po_ind_t    lock_CC_for_rb; /* lock CC for statement rollback ? */
    po_ind_t    join_info;  /* have joins ? */
    po_ind_t    parse_method;   /* parse_statement is forced or ? */
-   po_ind_t    curr_param_result; /* current param result is set ? */
    po_ind_t    has_notice; /* exec result contains notice messages ? */
    pgNAME      cursor_name;
    char        *plan_name;
@@ -329,6 +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_ARD(a)  ((a)->ard)
 #define SC_get_APD(a)  ((a)->apd)
 #define SC_get_IRD(a)  ((a)->ird)