Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1ULZik-00009L-NA for pgsql-odbc@arkaria.postgresql.org; Fri, 29 Mar 2013 13:51:54 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1ULZik-0007je-4s for pgsql-odbc@arkaria.postgresql.org; Fri, 29 Mar 2013 13:51:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1ULZij-0007jY-6Q for pgsql-odbc@postgresql.org; Fri, 29 Mar 2013 13:51:53 +0000 Received: from sd.tpf.co.jp ([210.161.239.34]) by magus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1ULZic-0005jR-CH for pgsql-odbc@postgresql.org; Fri, 29 Mar 2013 13:51:52 +0000 Received: (qmail 3151 invoked by uid 512); 29 Mar 2013 13:51:42 -0000 X-Authentication: inoue was authenticated by sd.tpf.co.jp at 29 Mar 2013 13:51:42 -0000 Received: from unknown (HELO ?192.168.1.4?) (183.76.63.59) by sd.tpf.co.jp with SMTP; 29 Mar 2013 13:51:42 -0000 Message-ID: <51559C6B.5000006@tpf.co.jp> Date: Fri, 29 Mar 2013 22:51:39 +0900 From: Hiroshi Inoue User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 MIME-Version: 1.0 To: Heikki Linnakangas CC: pgsql-odbc@postgresql.org Subject: Re: SQLExecute returns 0 rows with BoolsAsChar=1 References: <51479445.7020905@vmware.com> <514AFABC.7000808@tpf.co.jp> <514B3870.2060208@vmware.com> <514ED061.10906@tpf.co.jp> <51503885.5090001@vmware.com> <5151B89D.8060902@tpf.co.jp> In-Reply-To: <5151B89D.8060902@tpf.co.jp> Content-Type: multipart/mixed; boundary="------------000803010605020905020005" X-Pg-Spam-Score: -3.2 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org This is a multi-part message in MIME format. --------------000803010605020905020005 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit (2013/03/27 0:02), Hiroshi Inoue wrote: > (2013/03/25 20:44), Heikki Linnakangas wrote: >> On 24.03.2013 12:07, Hiroshi Inoue wrote: >>> I can reproduce it now when I turn off the *Server side prepare* option >>> or turn on the *Use Declare/Fetch* option. >> >> Ah yeah, UseServerSidePrepare hides it. I'm also seeing the problem >> without UseDeclareFetch, though. >> >>> Attached is a patch to fix the bug. >> >> Thanks. I must admit I don't understand how this works. Also, the 2nd >> test case in attached file now fails. It does a DELETE ... RETURNING, >> binding a parameter array with a VARCHAR(5) column, and fetches the >> results. With the patch, it can't fetch the result sets. > > Thanks for the test case. > The attached patch instead of the previous one would fix the problem > but still has a problem when the server side prepare option is turned > on. OK attached is a patch to fix the problem with the *Server side Prepare* option. regards, Hiroshi Inoue --------------000803010605020905020005 Content-Type: text/x-patch; name="parse_execute.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="parse_execute.patch" diff --git a/columninfo.c b/columninfo.c index a7d7452..71b64d3 100755 --- a/columninfo.c +++ b/columninfo.c @@ -30,6 +30,7 @@ CI_Constructor() if (rv) { + rv->refcount = 0; rv->num_fields = 0; rv->coli_array = NULL; } diff --git a/columninfo.h b/columninfo.h index af65a21..60651bc 100755 --- a/columninfo.h +++ b/columninfo.h @@ -13,6 +13,7 @@ struct ColumnInfoClass_ { + UInt4 refcount; Int2 num_fields; struct srvr_info { diff --git a/execute.c b/execute.c index aa1c1d5..6bbc0bf 100755 --- a/execute.c +++ b/execute.c @@ -528,10 +528,8 @@ mylog("about to begin SC_execute\n"); if (kres = res->next, kres) { - if (kres->fields) - CI_Destructor(kres->fields); - kres->fields = res->fields; - res->fields = NULL; + QR_set_fields(kres, QR_get_fields(res)); + QR_set_fields(res, NULL); kres->num_fields = res->num_fields; res->next = NULL; SC_set_Result(stmt, kres); diff --git a/pgtypes.c b/pgtypes.c index 031c3e4..1544c8f 100755 --- a/pgtypes.c +++ b/pgtypes.c @@ -1570,7 +1570,7 @@ getNumericDecimalDigits(const StatementClass *stmt, OID type, int col) return (atttypmod & 0xffff); if (stmt->catalog_result) { - flds = result->fields; + flds = QR_get_fields(result); if (flds) { int fsize = CI_get_fieldsize(flds, col); @@ -1614,7 +1614,7 @@ getNumericColumnSize(const StatementClass *stmt, OID type, int col) return (atttypmod >> 16) & 0xffff; if (stmt->catalog_result) { - flds = result->fields; + flds = QR_get_fields(result); if (flds) { int fsize = CI_get_fieldsize(flds, col); diff --git a/qresult.c b/qresult.c index c293793..38bfb73 100755 --- a/qresult.c +++ b/qresult.c @@ -38,7 +38,7 @@ QR_set_num_fields(QResultClass *self, int new_num_fields) if (!self) return; mylog("in QR_set_num_fields\n"); - CI_set_num_fields(self->fields, new_num_fields, allocrelatt); + CI_set_num_fields(QR_get_fields(self), new_num_fields, allocrelatt); mylog("exit QR_set_num_fields\n"); } @@ -137,6 +137,26 @@ QR_inc_rowstart_in_cache(QResultClass *self, SQLLEN base_inc) /* * CLASS QResult */ + +void QR_set_fields(QResultClass *self, ColumnInfoClass *fields) +{ + ColumnInfoClass *curfields = QR_get_fields(self); + + if (curfields == fields) + return; + if (NULL != curfields) + { + if (curfields->refcount > 1) + curfields->refcount--; + else + CI_Destructor(curfields); + } + self->_fields = fields; + if (NULL != fields) + fields->refcount++; + return; +} + QResultClass * QR_Constructor() { @@ -147,15 +167,19 @@ QR_Constructor() if (rv != NULL) { + ColumnInfoClass *fields; + rv->rstatus = PORES_EMPTY_QUERY; rv->pstatus = 0; /* construct the column info */ - if (!(rv->fields = CI_Constructor())) + rv->_fields = NULL; + if (fields = CI_Constructor(), NULL == fields) { free(rv); return NULL; } + QR_set_fields(rv, fields); rv->backend_tuples = NULL; rv->sqlstate[0] = '\0'; rv->message = NULL; @@ -241,10 +265,9 @@ QR_close_result(QResultClass *self, BOOL destroy) QR_set_cursor(self, NULL); /* Free up column info */ - if (destroy && self->fields) + if (destroy) { - CI_Destructor(self->fields); - self->fields = NULL; + QR_set_fields(self, NULL); } /* Free command info (this is from strdup()) */ @@ -560,7 +583,7 @@ QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, const char *cursor, i if (CI_read_fields(QR_get_fields(self), QR_get_conn(self))) { QR_set_rstatus(self, PORES_FIELDS_OK); - self->num_fields = CI_get_num_fields(self->fields); + self->num_fields = CI_get_num_fields(QR_get_fields(self)); if (QR_haskeyset(self)) self->num_fields -= self->num_key_fields; } @@ -1553,7 +1576,7 @@ else bitmap_pos = 0; bitcnt = 0; bmp = bitmap[bitmap_pos]; - flds = self->fields; + flds = QR_get_fields(self); for (field_lf = 0; field_lf < ci_num_fields; field_lf++) { diff --git a/qresult.h b/qresult.h index d723bec..6cc41d4 100755 --- a/qresult.h +++ b/qresult.h @@ -52,7 +52,7 @@ enum struct QResultClass_ { - ColumnInfoClass *fields; /* the Column information */ + ColumnInfoClass *_fields; /* the Column information */ ConnectionClass *conn; /* the connection this result is using * (backend) */ QResultClass *next; /* the following result class */ @@ -125,7 +125,7 @@ enum { #define QR_is_withhold(self) (0 != (self->flags & FQR_WITHHOLD)) #define QR_is_permanent(self) (0 != (self->flags & FQR_HOLDPERMANENT)) #define QR_synchronize_keys(self) (0 != (self->flags & FQR_SYNCHRONIZEKEYS)) -#define QR_get_fields(self) (self->fields) +#define QR_get_fields(self) (self->_fields) /* These functions are for retrieving data from the qresult */ @@ -135,22 +135,22 @@ enum { #define QR_get_value_backend_int(self, tupleno, fieldno, isNull) atoi(QR_get_value_backend_row(self, tupleno, fieldno)) /* These functions are used by both manual and backend results */ -#define QR_NumResultCols(self) (CI_get_num_fields(self->fields)) -#define QR_NumPublicResultCols(self) (QR_haskeyset(self) ? (CI_get_num_fields(self->fields) - self->num_key_fields) : CI_get_num_fields(self->fields)) -#define QR_get_fieldname(self, fieldno_) (CI_get_fieldname(self->fields, fieldno_)) -#define QR_get_fieldsize(self, fieldno_) (CI_get_fieldsize(self->fields, fieldno_)) -#define QR_get_display_size(self, fieldno_) (CI_get_display_size(self->fields, fieldno_)) -#define QR_get_atttypmod(self, fieldno_) (CI_get_atttypmod(self->fields, fieldno_)) -#define QR_get_field_type(self, fieldno_) (CI_get_oid(self->fields, fieldno_)) -#define QR_get_relid(self, fieldno_) (CI_get_relid(self->fields, fieldno_)) -#define QR_get_attid(self, fieldno_) (CI_get_attid(self->fields, fieldno_)) +#define QR_NumResultCols(self) (CI_get_num_fields(self->_fields)) +#define QR_NumPublicResultCols(self) (QR_haskeyset(self) ? (CI_get_num_fields(self->_fields) - self->num_key_fields) : CI_get_num_fields(self->_fields)) +#define QR_get_fieldname(self, fieldno_) (CI_get_fieldname(self->_fields, fieldno_)) +#define QR_get_fieldsize(self, fieldno_) (CI_get_fieldsize(self->_fields, fieldno_)) +#define QR_get_display_size(self, fieldno_) (CI_get_display_size(self->_fields, fieldno_)) +#define QR_get_atttypmod(self, fieldno_) (CI_get_atttypmod(self->_fields, fieldno_)) +#define QR_get_field_type(self, fieldno_) (CI_get_oid(self->_fields, fieldno_)) +#define QR_get_relid(self, fieldno_) (CI_get_relid(self->_fields, fieldno_)) +#define QR_get_attid(self, fieldno_) (CI_get_attid(self->_fields, fieldno_)) /* These functions are used only for manual result sets */ #define QR_get_num_total_tuples(self) (QR_once_reached_eof(self) ? (self->num_total_read + self->ad_count) : self->num_total_read) #define QR_get_num_total_read(self) (self->num_total_read) #define QR_get_num_cached_tuples(self) (self->num_cached_rows) -#define QR_set_field_info(self, field_num, name, adtid, adtsize, relid, attid) (CI_set_field_info(self->fields, field_num, name, adtid, adtsize, -1, relid, attid)) -#define QR_set_field_info_v(self, field_num, name, adtid, adtsize) (CI_set_field_info(self->fields, field_num, name, adtid, adtsize, -1, 0, 0)) +#define QR_set_field_info(self, field_num, name, adtid, adtsize, relid, attid) (CI_set_field_info(self->_fields, field_num, name, adtid, adtsize, -1, relid, attid)) +#define QR_set_field_info_v(self, field_num, name, adtid, adtsize) (CI_set_field_info(self->_fields, field_num, name, adtid, adtsize, -1, 0, 0)) /* status macros */ #define QR_command_successful(self) (self && !(self->rstatus == PORES_BAD_RESPONSE || self->rstatus == PORES_NONFATAL_ERROR || self->rstatus == PORES_FATAL_ERROR || self->rstatus == PORES_NO_MEMORY_ERROR)) @@ -235,6 +235,7 @@ void QR_set_notice(QResultClass *self, const char *msg); void QR_add_notice(QResultClass *self, const char *msg); void QR_set_num_fields(QResultClass *self, int new_num_fields); /* catalog functions' result only */ +void QR_set_fields(QResultClass *self, ColumnInfoClass *); void QR_set_num_cached_rows(QResultClass *, SQLLEN); void QR_set_rowstart_in_cache(QResultClass *, SQLLEN); diff --git a/statement.c b/statement.c index 1b1980b..5d26a39 100755 --- a/statement.c +++ b/statement.c @@ -1835,7 +1835,8 @@ SC_execute(StatementClass *self) { QResultClass *curres = SC_get_Curres(self); - if (NULL != curres) + if (NULL != curres && + curres->dataFilled) useCursor = (NULL != QR_get_cursor(curres)); } /* issue BEGIN ? */ @@ -1913,13 +1914,19 @@ SC_execute(StatementClass *self) #endif /* BYPASS_ONESHOT_PLAN_EXECUTION */ case NAMED_PARSE_REQUEST: use_extended_protocol = TRUE; + break; } } - if (!use_extended_protocol) + if (use_extended_protocol) + break; + case ONCE_DESCRIBED: + SC_forget_unnamed(self); { - SC_forget_unnamed(self); - SC_set_Result(self, NULL); /* discard the parsed information */ + QResultClass *pres = SC_get_Result(self); + if (NULL != pres && NULL == QR_get_command(pres)) + SC_set_Result(self, NULL); /* discard the parsed information */ } + break; } if (use_extended_protocol) { @@ -2103,10 +2110,8 @@ inolog("!!%p->SC_is_concat_pre=%x res=%p\n", self, self->miscinfo, res); { if (tres = res->next, tres) { - if (tres->fields) - CI_Destructor(tres->fields); - tres->fields = res->fields; - res->fields = NULL; + QR_set_fields(tres, QR_get_fields(res)); + QR_set_fields(res, NULL); tres->num_fields = res->num_fields; res->next = NULL; QR_Destructor(res); @@ -2376,7 +2381,7 @@ SC_log_error(const char *func, const char *desc, const StatementClass *self) if (res) { - qlog(" fields=%p, backend_tuples=%p, tupleField=%d, conn=%p\n", res->fields, res->backend_tuples, res->tupleField, res->conn); + qlog(" fields=%p, backend_tuples=%p, tupleField=%d, conn=%p\n", QR_get_fields(res), res->backend_tuples, res->tupleField, res->conn); qlog(" fetch_count=%d, num_total_rows=%d, num_fields=%d, cursor='%s'\n", res->fetch_number, QR_get_num_total_tuples(res), res->num_fields, nullcheck(QR_get_cursor(res))); qlog(" message='%s', command='%s', notice='%s'\n", nullcheck(QR_get_message(res)), nullcheck(res->command), nullcheck(res->notice)); qlog(" status=%d, inTuples=%d\n", QR_get_rstatus(res), QR_is_fetching_tuples(res)); @@ -2421,6 +2426,31 @@ RequestStart(StatementClass *stmt, ConnectionClass *conn, const char *func) return ret; } +static BOOL ReflectColumnsInfo(StatementClass *self, QResultClass *res) +{ + QResultClass *pres; + + if (NOT_YET_PREPARED == self->prepared) + return FALSE; + if (res->num_fields > 0) + return FALSE; + pres = SC_get_Result(self); + if (pres != res && + pres->num_fields > 0) + { + QR_set_fields(res, QR_get_fields(pres)); + QR_set_conn(res, SC_get_conn(self)); + if (QR_haskeyset(pres)) + QR_set_haskeyset(res); + if (QR_is_withhold(pres)) + QR_set_withhold(res); + res->num_fields = pres->num_fields; + + return TRUE; + } + return FALSE; +} + BOOL SendBindRequest(StatementClass *stmt, const char *plan_name) { @@ -2591,7 +2621,7 @@ inolog("num_params=%d info=%d\n", stmt->num_params, num_p); int cidx; QR_set_rstatus(res, PORES_FIELDS_OK); - res->num_fields = CI_get_num_fields(res->fields); + res->num_fields = CI_get_num_fields(QR_get_fields(res)); if (QR_haskeyset(res)) res->num_fields -= res->num_key_fields; num_io_params = CountParameters(stmt, NULL, &dummy1, &dummy2); @@ -2608,8 +2638,8 @@ inolog("num_params=%d info=%d\n", stmt->num_params, num_p); if (SQL_PARAM_OUTPUT == paramType || SQL_PARAM_INPUT_OUTPUT == paramType) { -inolog("!![%d].PGType %u->%u\n", i, PIC_get_pgtype(ipdopts->parameters[i]), CI_get_oid(res->fields, cidx)); - PIC_set_pgtype(ipdopts->parameters[i], CI_get_oid(res->fields, cidx)); +inolog("!![%d].PGType %u->%u\n", i, PIC_get_pgtype(ipdopts->parameters[i]), CI_get_oid(QR_get_fields(res), cidx)); + PIC_set_pgtype(ipdopts->parameters[i], CI_get_oid(QR_get_fields(res), cidx)); cidx++; } } @@ -2632,6 +2662,7 @@ inolog("!![%d].PGType %u->%u\n", i, PIC_get_pgtype(ipdopts->parameters[i]), CI_g break; case 'B': /* Binary data */ case 'D': /* ASCII data */ + ReflectColumnsInfo(stmt, res); if (!QR_get_tupledata(res, id == 'B')) { loopend = TRUE; --------------000803010605020905020005 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc --------------000803010605020905020005--