pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedSQLExecute returns 0 rows with BoolsAsChar=1
12+ messages / 2 participants
[nested] [flat]
* SQLExecute returns 0 rows with BoolsAsChar=1
@ 2013-03-18 22:25 Heikki Linnakangas <hlinnakangas@vmware.com>
0 siblings, 2 replies; 12+ messages in thread
From: Heikki Linnakangas @ 2013-03-18 22:25 UTC (permalink / raw)
To: pgsql-odbc
If you SQLPrepare a query, and bind a VARCHAR parameter with column_size
of exactly 5, and you have BoolsAsChar=1 (which is the default), the
subsequent SQLExecute will return 0 rows.
With those conditions, HowToPrepareBeforeExec returns shouldExec, which
means that the query is sent to the server to be parse, in a Parse
message. PGAPI_Execute() calls HowToPrepareBeforeExec, and calls
prepareParameters(), which sends the Parse message, and reads the
resulting ParameterDescription messages from the server. It also creates
a new QResultClass object, and stores it as the statement's result. Now,
when PGAPI_Execute() proceeds to execute the statement for real, it
doesn't clear the dummy result set created by prepareParameters(), but
just appends the real result set to the statement object's chain of
results. When SQLExecute() returns, the first result set (the one that
the application cares about) is the dummy one, with 0 rows.
As a quick fix, but which I believe is quite safe and correct anyway, is
to always clear any existing result sets in PGAPI_Execute() before
actually executing the query. Normally, there shouldn't be any result
sets, so clearing is harmless. In this buggy corner, case it clears the
dummy result set, fixing the problem.
Attached is a patch to fix that. As usual, this is also present in my
github repository at https://github.com/hlinnaka/psqlodbc/, as well as a
test case in the master-with-testcases branch.
- Heikki
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
Attachments:
0001-Fix-column_size-5-varchar-field-in-BoolsAsChar-1-mod.patch (text/x-diff, 924B) download
From 79fa21bd5c52157cf9a2296b06aa7ad6cb9c8b9c Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Tue, 19 Mar 2013 00:04:19 +0200
Subject: [PATCH 1/1] Fix column_size=5 varchar field in BoolsAsChar=1 mode.
If a query was sent to the server using the Parse command, we returned the
dummy QResult for the Parse, with 0 rows, to the caller of SQLExecute.
Fix by clearing out the result set just before executing.
---
execute.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/execute.c b/execute.c
index 1339b58..a680dc8 100644
--- a/execute.c
+++ b/execute.c
@@ -1149,6 +1149,12 @@ next_param_row:
}
}
+ /*
+ * Clear any old result sets before executing. The prepare stage might've
+ * created one.
+ */
+ SC_set_Result(stmt, NULL);
+
if (0 != (flag & PODBC_WITH_HOLD))
SC_set_with_hold(stmt);
retval = Exec_with_parameters_resolved(stmt, &exec_end);
--
1.7.10.4
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: SQLExecute returns 0 rows with BoolsAsChar=1
@ 2013-03-20 08:56 Hiroshi Inoue <inoue@tpf.co.jp>
parent: Heikki Linnakangas <hlinnakangas@vmware.com>
1 sibling, 1 reply; 12+ messages in thread
From: Hiroshi Inoue @ 2013-03-20 08:56 UTC (permalink / raw)
To: Heikki Linnakangas <hlinnakangas@vmware.com>; +Cc: pgsql-odbc
Hi,
(2013/03/19 7:25), Heikki Linnakangas wrote:
> If you SQLPrepare a query, and bind a VARCHAR parameter with column_size
> of exactly 5, and you have BoolsAsChar=1 (which is the default), the
> subsequent SQLExecute will return 0 rows.
>
> With those conditions, HowToPrepareBeforeExec returns shouldExec, which
> means that the query is sent to the server to be parse, in a Parse
> message. PGAPI_Execute() calls HowToPrepareBeforeExec, and calls
> prepareParameters(), which sends the Parse message, and reads the
> resulting ParameterDescription messages from the server. It also creates
> a new QResultClass object, and stores it as the statement's result. Now,
> when PGAPI_Execute() proceeds to execute the statement for real, it
> doesn't clear the dummy result set created by prepareParameters(), but
> just appends the real result set to the statement object's chain of
> results. When SQLExecute() returns, the first result set (the one that
> the application cares about) is the dummy one, with 0 rows.
>
> As a quick fix, but which I believe is quite safe and correct anyway, is
I don't think it's safe.
It's in the middle of handling an array of parameter set and may
go back to next_param_row label.
In addtion, apps may get out of PGAPI_Execute() in the middle of
paramater handling when there are data at execution parameters.
> to always clear any existing result sets in PGAPI_Execute() before
> actually executing the query. Normally, there shouldn't be any result
> sets, so clearing is harmless. In this buggy corner, case it clears the
> dummy result set, fixing the problem.
>
> Attached is a patch to fix that. As usual, this is also present in my
> github repository at https://github.com/hlinnaka/psqlodbc/, as well as a
> test case in the master-with-testcases branch.
>
> - Heikki
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: SQLExecute returns 0 rows with BoolsAsChar=1
@ 2013-03-20 13:04 Heikki Linnakangas <hlinnakangas@vmware.com>
parent: Hiroshi Inoue <inoue@tpf.co.jp>
0 siblings, 1 reply; 12+ messages in thread
From: Heikki Linnakangas @ 2013-03-20 13:04 UTC (permalink / raw)
To: Hiroshi Inoue <inoue@tpf.co.jp>; +Cc: pgsql-odbc
On 20.03.2013 10:56, Hiroshi Inoue wrote:
> Hi,
>
> (2013/03/19 7:25), Heikki Linnakangas wrote:
>> If you SQLPrepare a query, and bind a VARCHAR parameter with column_size
>> of exactly 5, and you have BoolsAsChar=1 (which is the default), the
>> subsequent SQLExecute will return 0 rows.
>>
>> With those conditions, HowToPrepareBeforeExec returns shouldExec, which
>> means that the query is sent to the server to be parse, in a Parse
>> message. PGAPI_Execute() calls HowToPrepareBeforeExec, and calls
>> prepareParameters(), which sends the Parse message, and reads the
>> resulting ParameterDescription messages from the server. It also creates
>> a new QResultClass object, and stores it as the statement's result. Now,
>> when PGAPI_Execute() proceeds to execute the statement for real, it
>> doesn't clear the dummy result set created by prepareParameters(), but
>> just appends the real result set to the statement object's chain of
>> results. When SQLExecute() returns, the first result set (the one that
>> the application cares about) is the dummy one, with 0 rows.
>>
>> As a quick fix, but which I believe is quite safe and correct anyway, is
>
> I don't think it's safe.
> It's in the middle of handling an array of parameter set and may
> go back to next_param_row label.
Ah, I see.
> In addtion, apps may get out of PGAPI_Execute() in the middle of
> paramater handling when there are data at execution parameters.
Hmm, I don't think that's a problem. Even with data-at-execution
parameters, the statement is only really going to be executed once.
Until all data-at-execution parameters have filled in by the
application, PGAPI_Execute() won't actually execute the statement, it
will just return SQL_NEED_DATA. It's OK to reset the result set between
those PGAPI_Execute() calls - there shouldn't be any results yet. The
last PGAPI_Execute() call produces all the result sets.
I think we're OK if we just move the SC_set_Result call to before the
next_param_row label. Does the attached look right to you?
- Heikki
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
Attachments:
clear-bogus-result-set-2.patch (text/x-diff, 444B) download
diff --git a/execute.c b/execute.c
index 1339b58..4e3c533 100644
--- a/execute.c
+++ b/execute.c
@@ -1065,6 +1065,12 @@ mylog("prepareParameters was %s called, prepare state:%d\n", shouldParse == nCal
parse_sqlsvr(stmt);
}
+ /*
+ * Clear any old result sets before executing. The prepare stage might've
+ * created one.
+ */
+ SC_set_Result(stmt, NULL);
+
next_param_row:
#if (ODBCVER >= 0x0300)
if (apdopts->param_operation_ptr)
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: SQLExecute returns 0 rows with BoolsAsChar=1
@ 2013-03-20 14:23 Hiroshi Inoue <inoue@tpf.co.jp>
parent: Heikki Linnakangas <hlinnakangas@vmware.com>
0 siblings, 0 replies; 12+ messages in thread
From: Hiroshi Inoue @ 2013-03-20 14:23 UTC (permalink / raw)
To: Heikki Linnakangas <hlinnakangas@vmware.com>; +Cc: pgsql-odbc
(2013/03/20 22:04), Heikki Linnakangas wrote:
> On 20.03.2013 10:56, Hiroshi Inoue wrote:
>> Hi,
>>
>> (2013/03/19 7:25), Heikki Linnakangas wrote:
>>> If you SQLPrepare a query, and bind a VARCHAR parameter with column_size
>>> of exactly 5, and you have BoolsAsChar=1 (which is the default), the
>>> subsequent SQLExecute will return 0 rows.
>>>
>>> With those conditions, HowToPrepareBeforeExec returns shouldExec, which
>>> means that the query is sent to the server to be parse, in a Parse
>>> message. PGAPI_Execute() calls HowToPrepareBeforeExec, and calls
>>> prepareParameters(), which sends the Parse message, and reads the
>>> resulting ParameterDescription messages from the server. It also creates
>>> a new QResultClass object, and stores it as the statement's result. Now,
>>> when PGAPI_Execute() proceeds to execute the statement for real, it
>>> doesn't clear the dummy result set created by prepareParameters(), but
>>> just appends the real result set to the statement object's chain of
>>> results. When SQLExecute() returns, the first result set (the one that
>>> the application cares about) is the dummy one, with 0 rows.
>>>
>>> As a quick fix, but which I believe is quite safe and correct anyway, is
>>
>> I don't think it's safe.
>> It's in the middle of handling an array of parameter set and may
>> go back to next_param_row label.
>
> Ah, I see.
>
>> In addtion, apps may get out of PGAPI_Execute() in the middle of
>> paramater handling when there are data at execution parameters.
>
> Hmm, I don't think that's a problem. Even with data-at-execution
> parameters, the statement is only really going to be executed once.
The statement may be executed many (at most parameter set array size)
times in the current implementation.
> Until all data-at-execution parameters have filled in by the
> application, PGAPI_Execute() won't actually execute the statement, it
> will just return SQL_NEED_DATA. It's OK to reset the result set between
> those PGAPI_Execute() calls - there shouldn't be any results yet. The
> last PGAPI_Execute() call produces all the result sets.
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: SQLExecute returns 0 rows with BoolsAsChar=1
@ 2013-03-21 12:19 Hiroshi Inoue <inoue@tpf.co.jp>
parent: Heikki Linnakangas <hlinnakangas@vmware.com>
1 sibling, 1 reply; 12+ messages in thread
From: Hiroshi Inoue @ 2013-03-21 12:19 UTC (permalink / raw)
To: Heikki Linnakangas <hlinnakangas@vmware.com>; +Cc: pgsql-odbc
(2013/03/19 7:25), Heikki Linnakangas wrote:
> If you SQLPrepare a query, and bind a VARCHAR parameter with column_size
> of exactly 5, and you have BoolsAsChar=1 (which is the default), the
> subsequent SQLExecute will return 0 rows.
Hmm I can't reproduce it here.
Could you send me the Mylog output of the case?
regards,
Hiroshi Inoue
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: SQLExecute returns 0 rows with BoolsAsChar=1
@ 2013-03-21 16:42 Heikki Linnakangas <hlinnakangas@vmware.com>
parent: Hiroshi Inoue <inoue@tpf.co.jp>
0 siblings, 1 reply; 12+ messages in thread
From: Heikki Linnakangas @ 2013-03-21 16:42 UTC (permalink / raw)
To: Hiroshi Inoue <inoue@tpf.co.jp>; +Cc: pgsql-odbc
On 21.03.2013 14:19, Hiroshi Inoue wrote:
> (2013/03/19 7:25), Heikki Linnakangas wrote:
>> If you SQLPrepare a query, and bind a VARCHAR parameter with column_size
>> of exactly 5, and you have BoolsAsChar=1 (which is the default), the
>> subsequent SQLExecute will return 0 rows.
>
> Hmm I can't reproduce it here.
> Could you send me the Mylog output of the case?
Sure. Here's a test program to reproduce it, and the mylog output from
running it. It should print:
got result: foobar
But due to the bug, you get:
SQLFetch returned SQL_NO_DATA
- Heikki
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
Attachments:
colsize5.c (text/x-csrc, 2.7K) download
#include <stdlib.h>
#include <stdio.h>
#include <sql.h>
#include <sqlext.h>
static SQLHENV env;
static SQLHDBC conn;
#define CHECK_STMT_RESULT(rc, msg, hstmt) \
if (!SQL_SUCCEEDED(rc)) \
{ \
print_diag(msg, SQL_HANDLE_STMT, hstmt); \
exit(1); \
}
static void
print_diag(char *msg, SQLSMALLINT htype, SQLHANDLE handle)
{
char sqlstate[32];
char message[1000];
SQLINTEGER nativeerror;
SQLSMALLINT textlen;
SQLRETURN ret;
if (msg)
printf("%s\n", msg);
ret = SQLGetDiagRec(htype, handle, 1,
sqlstate, &nativeerror, message, 256, &textlen);
if (ret != SQL_ERROR)
printf("%s=%s\n", (CHAR *)sqlstate, (CHAR *)message);
}
static void
test_connect(void)
{
SQLRETURN ret;
SQLCHAR str[1024];
SQLSMALLINT strl;
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
SQLAllocHandle(SQL_HANDLE_DBC, env, &conn);
ret = SQLDriverConnect(conn, NULL, "DSN=psqlodbc_test_dsn;%s", SQL_NTS,
str, sizeof(str), &strl,
SQL_DRIVER_COMPLETE);
if (SQL_SUCCEEDED(ret)) {
printf("connected\n");
} else {
print_diag("SQLDriverConnect failed.", SQL_HANDLE_DBC, conn);
exit(1);
}
}
int main(int argc, char **argv)
{
SQLRETURN rc;
HSTMT hstmt = SQL_NULL_HSTMT;
char *param1;
SQLLEN cbParam1;
long longparam;
SQL_INTERVAL_STRUCT intervalparam;
SQLSMALLINT colcount;
char buf[40];
test_connect();
rc = SQLAllocStmt(conn, &hstmt);
if (!SQL_SUCCEEDED(rc))
{
print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn);
exit(1);
}
/****
* With BoolsAsChar=1, a varchar param with column_size=5 forces a
* server-side Prepare. So test that.
*/
/* bind param */
param1 = "foo";
cbParam1 = SQL_NTS;
rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT,
SQL_C_CHAR, /* value type */
SQL_VARCHAR, /* param type */
5, /* column size. 5 Triggers special
* behavior with BoolsAsChar=1 */
0, /* dec digits */
param1, /* param value ptr */
0, /* buffer len */
&cbParam1 /* StrLen_or_IndPtr */);
CHECK_STMT_RESULT(rc, "SQLBindParameter failed", hstmt);
/* Execute a simple query that returns a single value */
rc = SQLExecDirect(hstmt,
(SQLCHAR *) "SELECT 'foobar' WHERE 'foo' = ?", SQL_NTS);
CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
/* Fetch result */
rc = SQLFetch(hstmt);
if (rc == SQL_NO_DATA)
{
printf("SQLFetch returned SQL_NO_DATA\n");
exit(1);
}
/* Should return a single value. Print it. */
rc = SQLGetData(hstmt,1, SQL_C_CHAR, buf, sizeof(buf), NULL);
if (!SQL_SUCCEEDED(rc))
{
print_diag("SQLGetData failed", SQL_HANDLE_STMT, hstmt);
exit(1);
}
printf("got result: %s\n", buf);
return 0;
}
mylog_heikki23223.log (text/x-log, 16.1K) download
[139958134339328]calling getDSNdefaults
[139958134339328]CC_connect: entering...
[139958134339328]sslmode=disable
[139958134339328]LIBPQ_CC_connect: entering...
[139958134339328]Driver Version='09.01.0200,201208160000'
[139958134339328]LIBPQ_CC_connect: DSN = 'psqlodbc_test_dsn', server = 'localhost', port = '5432', database = 'contrib_regression', username = '', password='xxxxx'
[139958134339328]connecting to the database using localhost as the server
[139958134339328]sizeof connectdb option = 76
[139958134339328]libpq connection to the database succeeded.
[139958134339328]protocol=7.4
[139958134339328]Server version=9.3.0
[139958134339328]PQuser=heikki
[139958134339328]LIBPQ_connect: retuning 1
[139958134339328]CC_setenv: entering...
[139958134339328]PGAPI_AllocStmt: entering...
[139958134339328]**** PGAPI_AllocStmt: hdbc = 0x13b20e0, stmt = 0x13c2cb0
[139958134339328]CC_add_statement: self=0x13b20e0, stmt=0x13c2cb0
[139958134339328]PGAPI_ExecDirect: entering...0
[139958134339328]SC_recycle_statement: self= 0x13c2cb0
[139958134339328]**** PGAPI_ExecDirect: hstmt=0x13c2cb0, statement='set DateStyle to 'ISO''
[139958134339328]PGAPI_ExecDirect: calling PGAPI_Execute...
[139958134339328]PGAPI_Execute: entering...0
[139958134339328]PGAPI_Execute: clear errors...
[139958134339328]PGAPI_NumParams: entering...
[139958134339328]SC_scanQueryAndCountParams: entering...
[139958134339328]prepareParameters was not called, prepare state:2
[139958134339328]SC_recycle_statement: self= 0x13c2cb0
[139958134339328]Exec_with_parameters_resolved: copying statement params: trans_status=1, len=22, stmt='set DateStyle to 'ISO''
[139958134339328] stmt_with_params = 'set DateStyle to 'ISO''
[139958134339328]about to begin SC_execute
[139958134339328] it's NOT a select statement: stmt=0x13c2cb0
[139958134339328]CC_send_query: conn=0x13b20e0, query='set DateStyle to 'ISO''
[139958134339328]send_query: done sending query 28bytes flushed
[139958134339328]in QR_Constructor
[139958134339328]exit QR_Constructor
[139958134339328]read -1, global_socket_buffersize=4096
[139958134339328]Lasterror=11
[139958134339328]!!! poll ret=1 revents=1
[139958134339328]read 39, global_socket_buffersize=4096
[139958134339328]send_query: got id = 'S'
[139958134339328]send_query: got id = 'C'
[139958134339328]send_query: ok - 'C' - SET
[139958134339328]send_query: setting cmdbuffer = 'SET'
[139958134339328]send_query: returning res = 0x13c2850
[139958134339328]send_query: got id = 'Z'
[139958134339328]SC_set_Result(13c2cb0, 13c2850)[139958134339328]QResult: enter DESTRUCTOR
[139958134339328]retval=0
[139958134339328]PGAPI_ExecDirect: returned 0 from PGAPI_Execute
[139958134339328]CC_setenv: result 0, status 1 from set DateStyle
[139958134339328]PGAPI_ExecDirect: entering...0
[139958134339328]SC_recycle_statement: self= 0x13c2cb0
[139958134339328]QResult: enter DESTRUCTOR
[139958134339328]QResult: in QR_close_result
[139958134339328]QResult: free memory in, fcount=0
[139958134339328]QResult: free memory out
[139958134339328]QResult: enter DESTRUCTOR
[139958134339328]QResult: exit close_result
[139958134339328]QResult: exit DESTRUCTOR
[139958134339328]SC_init_Result(13c2cb0)[139958134339328]PDATA_free_params: ENTER, self=0x13c2f90
[139958134339328]**** PGAPI_ExecDirect: hstmt=0x13c2cb0, statement='set extra_float_digits to 2'
[139958134339328]PGAPI_ExecDirect: calling PGAPI_Execute...
[139958134339328]PGAPI_Execute: entering...0
[139958134339328]PGAPI_Execute: clear errors...
[139958134339328]PGAPI_NumParams: entering...
[139958134339328]SC_scanQueryAndCountParams: entering...
[139958134339328]prepareParameters was not called, prepare state:2
[139958134339328]SC_recycle_statement: self= 0x13c2cb0
[139958134339328]PDATA_free_params: ENTER, self=0x13c2f90
[139958134339328]Exec_with_parameters_resolved: copying statement params: trans_status=1, len=27, stmt='set extra_float_digits to 2'
[139958134339328] stmt_with_params = 'set extra_float_digits to 2'
[139958134339328]about to begin SC_execute
[139958134339328] it's NOT a select statement: stmt=0x13c2cb0
[139958134339328]CC_send_query: conn=0x13b20e0, query='set extra_float_digits to 2'
[139958134339328]send_query: done sending query 33bytes flushed
[139958134339328]in QR_Constructor
[139958134339328]exit QR_Constructor
[139958134339328]read -1, global_socket_buffersize=4096
[139958134339328]Lasterror=11
[139958134339328]!!! poll ret=1 revents=1
[139958134339328]read 15, global_socket_buffersize=4096
[139958134339328]send_query: got id = 'C'
[139958134339328]send_query: ok - 'C' - SET
[139958134339328]send_query: setting cmdbuffer = 'SET'
[139958134339328]send_query: returning res = 0x13c2850
[139958134339328]send_query: got id = 'Z'
[139958134339328]SC_set_Result(13c2cb0, 13c2850)[139958134339328]QResult: enter DESTRUCTOR
[139958134339328]retval=0
[139958134339328]PGAPI_ExecDirect: returned 0 from PGAPI_Execute
[139958134339328]CC_setenv: result 0, status 1 from set extra_float_digits
[139958134339328]PGAPI_FreeStmt: entering...hstmt=0x13c2cb0, fOption=1
[139958134339328]QResult: enter DESTRUCTOR
[139958134339328]QResult: in QR_close_result
[139958134339328]QResult: free memory in, fcount=0
[139958134339328]QResult: free memory out
[139958134339328]QResult: enter DESTRUCTOR
[139958134339328]QResult: exit close_result
[139958134339328]QResult: exit DESTRUCTOR
[139958134339328]SC_init_Result(13c2cb0)[139958134339328]SC_Destructor: self=0x13c2cb0, self->result=(nil), self->hdbc=0x13b20e0
[139958134339328]APD_free_params: ENTER, self=0x13c2e58
[139958134339328]IPD_free_params: ENTER, self=0x13c2ec8
[139958134339328]PDATA_free_params: ENTER, self=0x13c2f90
[139958134339328]SC_Destructor: EXIT
[139958134339328]CC_send_settings: entering...
[139958134339328]PGAPI_AllocStmt: entering...
[139958134339328]**** PGAPI_AllocStmt: hdbc = 0x13b20e0, stmt = 0x13c2cb0
[139958134339328]CC_add_statement: self=0x13b20e0, stmt=0x13c2cb0
[139958134339328]PGAPI_FreeStmt: entering...hstmt=0x13c2cb0, fOption=1
[139958134339328]QResult: enter DESTRUCTOR
[139958134339328]SC_init_Result(13c2cb0)[139958134339328]SC_Destructor: self=0x13c2cb0, self->result=(nil), self->hdbc=0x13b20e0
[139958134339328]APD_free_params: ENTER, self=0x13c2e58
[139958134339328]IPD_free_params: ENTER, self=0x13c2ec8
[139958134339328]PDATA_free_params: ENTER, self=0x13c2f90
[139958134339328]SC_Destructor: EXIT
[139958134339328]CC_lookup_lo: entering...
[139958134339328]CC_send_query: conn=0x13b20e0, query='select oid, typbasetype from pg_type where typname = 'lo''
[139958134339328]send_query: done sending query 63bytes flushed
[139958134339328]in QR_Constructor
[139958134339328]exit QR_Constructor
[139958134339328]read -1, global_socket_buffersize=4096
[139958134339328]Lasterror=11
[139958134339328]!!! poll ret=1 revents=1
[139958134339328]read 79, global_socket_buffersize=4096
[139958134339328]send_query: got id = 'T'
[139958134339328]QR_fetch_tuples: cursor = '', self->cursor=(nil)
[139958134339328]num_fields = 2
[139958134339328]READING ATTTYPMOD
[139958134339328]CI_read_fields: fieldname='oid', adtid=26, adtsize=4, atttypmod=-1 (rel,att)=(1247,65534)
[139958134339328]READING ATTTYPMOD
[139958134339328]CI_read_fields: fieldname='typbasetype', adtid=26, adtsize=4, atttypmod=-1 (rel,att)=(1247,24)
[139958134339328]QR_fetch_tuples: past CI_read_fields: num_fields = 2
[139958134339328]MALLOC: tuple_size = 100, size = 3200
[139958134339328]QR_next_tuple: inTuples = true, falling through: fcount = 0, fetch_number = 0
[139958134339328]end of tuple list -- setting inUse to false: this = 0x13c2850 SELECT 0
[139958134339328]_QR_next_tuple: 'C' fetch_total = 0 & this_fetch = 0
[139958134339328]QR_next_tuple: backend_rows < CACHE_SIZE: brows = 0, cache_size = 0
[139958134339328]QR_next_tuple: reached eof now
[139958134339328]_QR_next_tuple: 'C': DONE (fcount == 0)
[139958134339328]send_query: got id = 'Z'
[139958134339328]QResult: enter DESTRUCTOR
[139958134339328]QResult: in QR_close_result
[139958134339328]QResult: free memory in, fcount=0
[139958134339328]QResult: free memory out
[139958134339328]QResult: enter DESTRUCTOR
[139958134339328]QResult: exit close_result
[139958134339328]QResult: exit DESTRUCTOR
[139958134339328]Got the large object oid: -999
[139958134339328]CC_lookup_characterset: entering...
[139958134339328]CC_send_query: conn=0x13b20e0, query='select pg_client_encoding()'
[139958134339328]send_query: done sending query 33bytes flushed
[139958134339328]in QR_Constructor
[139958134339328]exit QR_Constructor
[139958134339328]read -1, global_socket_buffersize=4096
[139958134339328]Lasterror=11
[139958134339328]!!! poll ret=1 revents=1
[139958134339328]read 79, global_socket_buffersize=4096
[139958134339328]send_query: got id = 'T'
[139958134339328]QR_fetch_tuples: cursor = '', self->cursor=(nil)
[139958134339328]num_fields = 1
[139958134339328]READING ATTTYPMOD
[139958134339328]CI_read_fields: fieldname='pg_client_encoding', adtid=19, adtsize=64, atttypmod=-1 (rel,att)=(0,0)
[139958134339328]QR_fetch_tuples: past CI_read_fields: num_fields = 1
[139958134339328]MALLOC: tuple_size = 100, size = 1600
[139958134339328]QR_next_tuple: inTuples = true, falling through: fcount = 0, fetch_number = 0
[139958134339328]qresult: len=4, buffer='UTF8'
[139958134339328]end of tuple list -- setting inUse to false: this = 0x13c2850 SELECT 1
[139958134339328]_QR_next_tuple: 'C' fetch_total = 1 & this_fetch = 1
[139958134339328]QR_next_tuple: backend_rows < CACHE_SIZE: brows = 0, cache_size = 0
[139958134339328]QR_next_tuple: reached eof now
[139958134339328]send_query: got id = 'Z'
[139958134339328]QResult: enter DESTRUCTOR
[139958134339328]QResult: in QR_close_result
[139958134339328]QResult: free memory in, fcount=1
[139958134339328]QResult: free memory out
[139958134339328]QResult: enter DESTRUCTOR
[139958134339328]QResult: exit close_result
[139958134339328]QResult: exit DESTRUCTOR
[139958134339328]conn->unicode=0
[139958134339328]CC_connect: returning...1
[139958134339328]szConnStrOut = 'DSN=psqlodbc_test_dsn;DATABASE=contrib_regression;SERVER=localhost;PORT=5432;UID=heikki;PWD=;SSLmode=disable;ReadOnly=No;Protocol=7.4;FakeOidIndex=No;ShowOidColumn=No;RowVersioning=No;ShowSystemTables=No;ConnSettings=;Fetch=100;Socket=4096;UnknownSizes=0;MaxVarcharSize=255;MaxLongVarcharSize=8190;Debug=1;CommLog=0;Optimizer=0;Ksqo=1;UseDeclareFetch=0;TextAsLongVarchar=1;UnknownsAsLongVarchar=0;BoolsAsChar=1;Parse=0;CancelAsFreeStmt=0;ExtraSysTablePrefixes=dd_;;LFConversion=0;UpdatableCursors=1;DisallowPremature=0;TrueIsMinus1=0;BI=0;ByteaAsLongVarBinary=0;UseServerSidePrepare=0;LowerCaseIdentifier=0;' len=607,1024
[139958134339328]PGAPI_DriverConnect: returning 0
[139958134339328][SQLGetFunctions][139958134339328][SQLGetInfo(30)][139958134339328]PGAPI_GetInfo: entering...fInfoType=77
[139958134339328]PGAPI_GetInfo: p='03.51', len=0, value=0, cbMax=20
[139958134339328][[SQLGetDiagRec]]
[139958134339328]PGAPI_GetDiagRec entering type=2 rec=1
[139958134339328]**** PGAPI_ConnectError: hdbc=0x13b20e0 <512>
[139958134339328]enter CC_get_error
[139958134339328]enter CC_create_errormsg
[139958134339328]msg = ''
[139958134339328]exit CC_create_errormsg
[139958134339328]exit CC_get_error
[139958134339328]CC_Get_error returned nothing.
[139958134339328]PGAPI_GetDiagRec exiting 100
[139958134339328][[SQLAllocHandle]][139958134339328]PGAPI_AllocStmt: entering...
[139958134339328]**** PGAPI_AllocStmt: hdbc = 0x13b20e0, stmt = 0x13c3330
[139958134339328]CC_add_statement: self=0x13b20e0, stmt=0x13c3330
[139958134339328][[SQLGetStmtAttr]] Handle=20722480 10010
[139958134339328]PGAPI_GetStmtAttr Handle=0x13c3330 10010
[139958134339328][[SQLGetStmtAttr]] Handle=20722480 10011
[139958134339328]PGAPI_GetStmtAttr Handle=0x13c3330 10011
[139958134339328][[SQLGetStmtAttr]] Handle=20722480 10012
[139958134339328]PGAPI_GetStmtAttr Handle=0x13c3330 10012
[139958134339328][[SQLGetStmtAttr]] Handle=20722480 10013
[139958134339328]PGAPI_GetStmtAttr Handle=0x13c3330 10013
[139958134339328][SQLBindParameter][139958134339328]PGAPI_BindParameter: entering...
[139958134339328]extend_parameter_bindings: entering ... self=0x13c34d8, parameters_allocated=0, num_params=1,(nil)
[139958134339328]exit extend_parameter_bindings=0x13b9df0
[139958134339328]extend_iparameter_bindings: entering ... self=0x13c3548, parameters_allocated=0, num_params=1
[139958134339328]exit extend_iparameter_bindings=0x13b9e20
[139958134339328]extend_putdata_info: entering ... self=0x13c3610, parameters_allocated=0, num_params=1
[139958134339328]exit extend_putdata_info=0x13c2460
[139958134339328]PGAPI_BindParameter: ipar=0, paramType=1, fCType=1, fSqlType=12, cbColDef=5, ibScale=0,[139958134339328]rgbValue=0x400ec7(0), pcbValue=0x7fffece77ea0
[139958134339328][SQLExecDirect][139958134339328]PGAPI_ExecDirect: entering...1
[139958134339328]SC_recycle_statement: self= 0x13c3330
[139958134339328]**** PGAPI_ExecDirect: hstmt=0x13c3330, statement='SELECT 'foobar' WHERE 'foo' = ?'
[139958134339328]PGAPI_ExecDirect: calling PGAPI_Execute...
[139958134339328]PGAPI_Execute: entering...1
[139958134339328]PGAPI_Execute: clear errors...
[139958134339328]PGAPI_NumParams: entering...
[139958134339328]SC_scanQueryAndCountParams: entering...
[139958134339328]SendParseRequest: plan_name= query=SELECT 'foobar' WHERE 'foo' = $1
[139958134339328]SendDescribeRequest:plan_name=
[139958134339328]in QR_Constructor
[139958134339328]exit QR_Constructor
[139958134339328]read -1, global_socket_buffersize=4096
[139958134339328]Lasterror=11
[139958134339328]!!! poll ret=1 revents=1
[139958134339328]read 56, global_socket_buffersize=4096
[139958134339328]extend_iparameter_bindings: entering ... self=0x13c3548, parameters_allocated=1, num_params=1
[139958134339328]exit extend_iparameter_bindings=0x13b9e20
[139958134339328]num_fields = 1
[139958134339328]READING ATTTYPMOD
[139958134339328]CI_read_fields: fieldname='?column?', adtid=705, adtsize=-2, atttypmod=-1 (rel,att)=(0,0)
[139958134339328]SC_set_Result(13c3330, 13c2850)[139958134339328]QResult: enter DESTRUCTOR
[139958134339328]prepareParameters was called, prepare state:2
[139958134339328]SC_recycle_statement: self= 0x13c3330
[139958134339328]Exec_with_parameters_resolved: copying statement params: trans_status=1, len=31, stmt='SELECT 'foobar' WHERE 'foo' = ?'
[139958134339328]ResolveOneParam: from(fcType)=1, to(fSqlType)=12(25)
[139958134339328]cvt_null_date_string=0 pgtype=25 buf=0x400ec7
[139958134339328]buf=0x400ec7 flag=2304
[139958134339328] stmt_with_params = 'SELECT 'foobar' WHERE 'foo' = 'foo''
[139958134339328]about to begin SC_execute
[139958134339328] Sending SELECT statement on stmt=0x13c3330, cursor_name='SQL_CUR0x13c3330' qflag=0,1
[139958134339328]CC_send_query: conn=0x13b20e0, query='SELECT 'foobar' WHERE 'foo' = 'foo''
[139958134339328]send_query: done sending query 41bytes flushed
[139958134339328]in QR_Constructor
[139958134339328]exit QR_Constructor
[139958134339328]read -1, global_socket_buffersize=4096
[139958134339328]Lasterror=11
[139958134339328]!!! poll ret=1 revents=1
[139958134339328]read 71, global_socket_buffersize=4096
[139958134339328]send_query: got id = 'T'
[139958134339328]QR_fetch_tuples: cursor = '', self->cursor=(nil)
[139958134339328]num_fields = 1
[139958134339328]READING ATTTYPMOD
[139958134339328]CI_read_fields: fieldname='?column?', adtid=705, adtsize=-2, atttypmod=-1 (rel,att)=(0,0)
[139958134339328]QR_fetch_tuples: past CI_read_fields: num_fields = 1
[139958134339328]MALLOC: tuple_size = 100, size = 1600
[139958134339328]QR_next_tuple: inTuples = true, falling through: fcount = 0, fetch_number = 0
[139958134339328]qresult: len=6, buffer='foobar'
[139958134339328]end of tuple list -- setting inUse to false: this = 0x13c5f10 SELECT 1
[139958134339328]_QR_next_tuple: 'C' fetch_total = 1 & this_fetch = 1
[139958134339328]QR_next_tuple: backend_rows < CACHE_SIZE: brows = 0, cache_size = 0
[139958134339328]QR_next_tuple: reached eof now
[139958134339328]send_query: got id = 'Z'
[139958134339328] done sending the query:
[139958134339328]extend_column_bindings: entering ... self=0x13c3410, bindings_allocated=0, num_columns=1
[139958134339328]exit extend_column_bindings=0x13c60e0
[139958134339328]retval=0
[139958134339328]PGAPI_ExecDirect: returned 0 from PGAPI_Execute
[139958134339328][[SQLFetch]][139958134339328]PGAPI_ExtendedFetch: stmt=0x13c3330 rowsetSize=1
[139958134339328]SQL_FETCH_NEXT: num_tuples=0, currtuple=-1, rowst=-1
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: SQLExecute returns 0 rows with BoolsAsChar=1
@ 2013-03-24 10:07 Hiroshi Inoue <inoue@tpf.co.jp>
parent: Heikki Linnakangas <hlinnakangas@vmware.com>
0 siblings, 1 reply; 12+ messages in thread
From: Hiroshi Inoue @ 2013-03-24 10:07 UTC (permalink / raw)
To: Heikki Linnakangas <hlinnakangas@vmware.com>; +Cc: pgsql-odbc
(2013/03/22 1:42), Heikki Linnakangas wrote:
> On 21.03.2013 14:19, Hiroshi Inoue wrote:
>> (2013/03/19 7:25), Heikki Linnakangas wrote:
>>> If you SQLPrepare a query, and bind a VARCHAR parameter with column_size
>>> of exactly 5, and you have BoolsAsChar=1 (which is the default), the
>>> subsequent SQLExecute will return 0 rows.
>>
>> Hmm I can't reproduce it here.
>> Could you send me the Mylog output of the case?
>
> Sure. Here's a test program to reproduce it, and the mylog output from
> running it.
Thanks.
I can reproduce it now when I turn off the *Server side prepare* option
or turn on the *Use Declare/Fetch* option.
Attached is a patch to fix the bug.
regards,
Hiroshi Inoue
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
Attachments:
statement.c.patch (text/x-patch, 584B) download
diff --git a/statement.c b/statement.c
index 1b1980b..7e1cafd 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 ? */
@@ -1904,6 +1905,7 @@ SC_execute(StatementClass *self)
break;
case PREPARING_TEMPORARILY:
case PREPARED_TEMPORARILY:
+ case ONCE_DESCRIBED:
if (!issue_begin)
{
switch (SC_get_prepare_method(self))
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: SQLExecute returns 0 rows with BoolsAsChar=1
@ 2013-03-25 11:44 Heikki Linnakangas <hlinnakangas@vmware.com>
parent: Hiroshi Inoue <inoue@tpf.co.jp>
0 siblings, 1 reply; 12+ messages in thread
From: Heikki Linnakangas @ 2013-03-25 11:44 UTC (permalink / raw)
To: Hiroshi Inoue <inoue@tpf.co.jp>; +Cc: pgsql-odbc
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.
- Heikki
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
Attachments:
arraybinding.out (text/plain, 497B) download
\! ./src/arraybinding-test
connected
Parameter Status
Result set:
10000
Result set:
0 columnwise 0
1 columnwise 1
100 columnwise 100
9999 columnwise 9999
Parameter Status
Fetching result sets for array bound (5 results expected)
1: Result set:
columnwise 100
2: Result set:
columnwise 101
3: Result set:
columnwise 102
4: Result set:
columnwise 103
5: Result set:
columnwise 104
Number of rows in table:
Result set:
9995
Result set:
0 columnwise 0
1 columnwise 1
9999 columnwise 9999
disconnecting
arraybinding-test.c (text/x-csrc, 6.5K) download
#include <stdio.h>
#include <stdlib.h>
#include "common.h"
#define ARRAY_SIZE 10000
#define ARRAY_SIZE_SMALL 5
int main(int argc, char **argv)
{
SQLRETURN rc;
HSTMT hstmt = SQL_NULL_HSTMT;
char *sql;
int i;
SQLUINTEGER int_array[ARRAY_SIZE];
SQLCHAR str_array[ARRAY_SIZE][30];
SQLCHAR str_array2[ARRAY_SIZE][6];
SQLLEN int_ind_array[ARRAY_SIZE];
SQLLEN str_ind_array[ARRAY_SIZE];
SQLUSMALLINT status_array[ARRAY_SIZE];
SQLULEN nprocessed;
test_connect();
rc = SQLAllocStmt(conn, &hstmt);
if (!SQL_SUCCEEDED(rc))
{
print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn);
exit(1);
}
sql = "CREATE TEMPORARY TABLE tmptable (i int4, t text)";
rc = SQLExecDirect(hstmt, (SQLCHAR *) sql, SQL_NTS);
CHECK_STMT_RESULT(rc, "SQLExecDirect failed while creating temp table", hstmt);
rc = SQLFreeStmt(hstmt, SQL_CLOSE);
CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
/****
* 1. Test column-wise binding
*/
for (i = 0; i < ARRAY_SIZE; i++)
{
int_array[i] = i;
int_ind_array[i] = 0;
sprintf(str_array[i], "columnwise %d", i);
str_ind_array[i] = SQL_NTS;
}
SQLSetStmtAttr(hstmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0);
SQLSetStmtAttr(hstmt, SQL_ATTR_PARAM_STATUS_PTR, status_array, 0);
SQLSetStmtAttr(hstmt, SQL_ATTR_PARAMS_PROCESSED_PTR, &nprocessed, 0);
SQLSetStmtAttr(hstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER) ARRAY_SIZE, 0);
/* Bind the parameter arrays. */
SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 5, 0,
int_array, 0, int_ind_array);
SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 29, 0,
str_array, 30, str_ind_array);
/* Execute */
sql = "INSERT INTO tmptable VALUES (?, ?)";
rc = SQLExecDirect(hstmt, (SQLCHAR *) sql, SQL_NTS);
CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
/* Fetch results */
printf("Parameter Status\n");
for (i = 0; i < nprocessed; i++)
{
switch (status_array[i])
{
case SQL_PARAM_SUCCESS:
case SQL_PARAM_SUCCESS_WITH_INFO:
break;
case SQL_PARAM_ERROR:
printf("%d\tError\n", i);
break;
case SQL_PARAM_UNUSED:
printf("%d\tUnused\n", i);
break;
case SQL_PARAM_DIAG_UNAVAILABLE:
printf("%d\tDiag unavailable\n", i);
break;
}
}
rc = SQLFreeStmt(hstmt, SQL_CLOSE);
CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
/*
* Free and allocate a new handle for the next SELECT statement, as we don't
* want to array bind that one. The parameters set with SQLSetStmtAttr
* survive SQLFreeStmt.
*/
rc = SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
CHECK_STMT_RESULT(rc, "SQLFreeHandle failed", hstmt);
rc = SQLAllocStmt(conn, &hstmt);
if (!SQL_SUCCEEDED(rc))
{
print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn);
exit(1);
}
/* Check that all the rows were inserted */
sql = "SELECT COUNT(*) FROM tmptable";
rc = SQLExecDirect(hstmt, (SQLCHAR *) sql, SQL_NTS);
CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
print_result(hstmt);
rc = SQLFreeStmt(hstmt, SQL_CLOSE);
CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
/* Check the contents of a few rows */
sql = "SELECT * FROM tmptable WHERE i IN (0, 1, 100, 9999, 10000) ORDER BY i";
rc = SQLExecDirect(hstmt, (SQLCHAR *) sql, SQL_NTS);
CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
print_result(hstmt);
rc = SQLFreeStmt(hstmt, SQL_CLOSE);
CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
/****
* 2. Test column-wise binding. With a column_size=5 VARCHAR param - that
* causes the driver to do a server-side prepare, assuming BoolsAsChar=1.
*/
/* a small array will do for this test */
for (i = 0; i < ARRAY_SIZE_SMALL; i++)
{
sprintf(str_array2[i], "%d", 100+i);
str_ind_array[i] = SQL_NTS;
}
SQLSetStmtAttr(hstmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0);
SQLSetStmtAttr(hstmt, SQL_ATTR_PARAM_STATUS_PTR, status_array, 0);
SQLSetStmtAttr(hstmt, SQL_ATTR_PARAMS_PROCESSED_PTR, &nprocessed, 0);
SQLSetStmtAttr(hstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER) ARRAY_SIZE_SMALL, 0);
/* Bind the parameter array. */
SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 5, 0,
str_array2, 6, str_ind_array);
/* Execute */
sql = "DELETE FROM tmptable WHERE i = ? RETURNING (t)";
rc = SQLExecDirect(hstmt, (SQLCHAR *) sql, SQL_NTS);
CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
/* Fetch results */
printf("Parameter Status\n");
for (i = 0; i < nprocessed; i++)
{
switch (status_array[i])
{
case SQL_PARAM_SUCCESS:
case SQL_PARAM_SUCCESS_WITH_INFO:
break;
case SQL_PARAM_ERROR:
printf("%d\tError\n", i);
break;
case SQL_PARAM_UNUSED:
printf("%d\tUnused\n", i);
break;
case SQL_PARAM_DIAG_UNAVAILABLE:
printf("%d\tDiag unavailable\n", i);
break;
}
}
printf ("Fetching result sets for array bound (%d results expected)\n",
nprocessed);
for (i = 1; rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO; i++)
{
printf("%d: ", i);
print_result(hstmt);
rc = SQLMoreResults(hstmt);
}
if (rc != SQL_NO_DATA)
CHECK_STMT_RESULT(rc, "SQLMoreResults failed", hstmt);
rc = SQLFreeStmt(hstmt, SQL_CLOSE);
CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
/*
* Free and allocate a new handle for the next SELECT statement, as we don't
* want to array bind that one. The parameters set with SQLSetStmtAttr
* survive SQLFreeStmt.
*/
rc = SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
CHECK_STMT_RESULT(rc, "SQLFreeHandle failed", hstmt);
rc = SQLAllocStmt(conn, &hstmt);
if (!SQL_SUCCEEDED(rc))
{
print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn);
exit(1);
}
/* Check that all the rows were inserted */
printf("Number of rows in table:\n");
sql = "SELECT COUNT(*) FROM tmptable";
rc = SQLExecDirect(hstmt, (SQLCHAR *) sql, SQL_NTS);
CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
print_result(hstmt);
rc = SQLFreeStmt(hstmt, SQL_CLOSE);
CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
/* Check the contents of a few rows */
sql = "SELECT * FROM tmptable WHERE i IN (0, 1, 100, 9999, 10000) ORDER BY i";
rc = SQLExecDirect(hstmt, (SQLCHAR *) sql, SQL_NTS);
CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
print_result(hstmt);
rc = SQLFreeStmt(hstmt, SQL_CLOSE);
CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
/* Clean up */
test_disconnect();
return 0;
}
common.h (text/x-chdr, 5.3K) download
#include <stdio.h>
#include <string.h>
#include <sql.h>
#include <sqlext.h>
static SQLHENV env;
static SQLHDBC conn;
#define CHECK_STMT_RESULT(rc, msg, hstmt) \
if (!SQL_SUCCEEDED(rc)) \
{ \
print_diag(msg, SQL_HANDLE_STMT, hstmt); \
exit(1); \
}
static void
print_diag(char *msg, SQLSMALLINT htype, SQLHANDLE handle)
{
char sqlstate[32];
char message[1000];
SQLINTEGER nativeerror;
SQLSMALLINT textlen;
SQLRETURN ret;
if (msg)
printf("%s\n", msg);
ret = SQLGetDiagRec(htype, handle, 1,
sqlstate, &nativeerror, message, 256, &textlen);
if (ret != SQL_ERROR)
printf("%s=%s\n", (CHAR *)sqlstate, (CHAR *)message);
}
static void
test_connect_ext(char *extraparams)
{
SQLRETURN ret;
SQLCHAR str[1024];
SQLSMALLINT strl;
SQLCHAR dsn[1024];
snprintf(dsn, sizeof(dsn), "DSN=psqlodbc_test_dsn;%s",
extraparams ? extraparams : "");
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
SQLAllocHandle(SQL_HANDLE_DBC, env, &conn);
ret = SQLDriverConnect(conn, NULL, dsn, SQL_NTS,
str, sizeof(str), &strl,
SQL_DRIVER_COMPLETE);
if (SQL_SUCCEEDED(ret)) {
printf("connected\n");
} else {
print_diag("SQLDriverConnect failed.", SQL_HANDLE_DBC, conn);
exit(1);
}
}
static void
test_connect(void)
{
test_connect_ext(NULL);
}
static void
test_disconnect(void)
{
SQLRETURN rc;
printf("disconnecting\n");
rc = SQLDisconnect(conn);
if (!SQL_SUCCEEDED(rc))
{
print_diag("SQLDisconnect failed", SQL_HANDLE_DBC, conn);
exit(1);
}
rc = SQLFreeConnect(conn);
if (!SQL_SUCCEEDED(rc))
{
print_diag("SQLFreeConnect failed", SQL_HANDLE_DBC, conn);
exit(1);
}
conn = NULL;
rc = SQLFreeEnv(env);
if (!SQL_SUCCEEDED(rc))
{
print_diag("SQLFreeEnv failed", SQL_HANDLE_ENV, env);
exit(1);
}
env = NULL;
}
static const char *
datatype_str(SQLSMALLINT datatype)
{
static char buf[100];
switch (datatype)
{
case SQL_CHAR:
return "CHAR";
case SQL_VARCHAR:
return "VARCHAR";
case SQL_LONGVARCHAR:
return "LONGVARCHAR";
case SQL_WCHAR:
return "WCHAR";
case SQL_WVARCHAR:
return "WVARCHAR";
case SQL_WLONGVARCHAR:
return "WLONGVARCHAR";
case SQL_DECIMAL:
return "DECIMAL";
case SQL_NUMERIC:
return "NUMERIC";
case SQL_SMALLINT:
return "SMALLINT";
case SQL_INTEGER:
return "INTEGER";
case SQL_REAL:
return "REAL";
case SQL_FLOAT:
return "FLOAT";
case SQL_DOUBLE:
return "DOUBLE";
case SQL_BIT:
return "BIT";
case SQL_TINYINT:
return "TINYINT";
case SQL_BIGINT:
return "BIGINT";
case SQL_BINARY:
return "BINARY";
case SQL_VARBINARY:
return "VARBINARY";
case SQL_LONGVARBINARY:
return "LONGVARBINARY";
case SQL_TYPE_DATE:
return "TYPE_DATE";
case SQL_TYPE_TIME:
return "TYPE_TIME";
case SQL_TYPE_TIMESTAMP:
return "TYPE_TIMESTAMP";
case SQL_GUID:
return "GUID";
default:
snprintf(buf, sizeof(buf), "unknown sql type %d", datatype);
return buf;
}
}
static const char *nullable_str(SQLSMALLINT nullable)
{
static char buf[100];
switch(nullable)
{
case SQL_NO_NULLS:
return "not nullable";
case SQL_NULLABLE:
return "nullable";
case SQL_NULLABLE_UNKNOWN:
return "nullable_unknown";
default:
snprintf(buf, sizeof(buf), "unknown nullable value %d", nullable);
return buf;
}
}
static void
print_result_meta(HSTMT hstmt)
{
SQLRETURN rc;
SQLSMALLINT numcols;
int i;
rc = SQLNumResultCols(hstmt, &numcols);
if (!SQL_SUCCEEDED(rc))
{
print_diag("SQLNumResultCols failed", SQL_HANDLE_STMT, hstmt);
return;
}
printf("Result set metadata:\n");
for (i = 1; i <= numcols; i++)
{
SQLCHAR colname[50];
SQLSMALLINT colnamelen;
SQLSMALLINT datatype;
SQLULEN colsize;
SQLSMALLINT decdigits;
SQLSMALLINT nullable;
rc = SQLDescribeCol(hstmt, i,
colname, sizeof(colname),
&colnamelen,
&datatype,
&colsize,
&decdigits,
&nullable);
if (!SQL_SUCCEEDED(rc))
{
print_diag("SQLDescribeCol failed", SQL_HANDLE_STMT, hstmt);
return;
}
printf("%s: %s(%d) digits: %d, %s\n",
colname, datatype_str(datatype), colsize,
decdigits, nullable_str(nullable));
}
}
static void
print_result(HSTMT hstmt)
{
SQLRETURN rc;
SQLSMALLINT numcols;
rc = SQLNumResultCols(hstmt, &numcols);
if (!SQL_SUCCEEDED(rc))
{
print_diag("SQLNumResultCols failed", SQL_HANDLE_STMT, hstmt);
return;
}
printf("Result set:\n");
while(1)
{
rc = SQLFetch(hstmt);
if (rc == SQL_NO_DATA)
break;
if (rc == SQL_SUCCESS)
{
char buf[40];
int i;
SQLLEN ind;
for (i = 1; i <= numcols; i++)
{
rc = SQLGetData(hstmt,i, SQL_C_CHAR, buf, sizeof(buf), &ind);
if (!SQL_SUCCEEDED(rc))
{
print_diag("SQLGetData failed", SQL_HANDLE_STMT, hstmt);
return;
}
if (ind == SQL_NULL_DATA)
strcpy(buf, "NULL");
printf("%s%s", (i > 1) ? "\t" : "", buf);
}
printf("\n");
}
else
{
print_diag("SQLFetch failed", SQL_HANDLE_STMT, hstmt);
exit(1);
}
}
}
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: SQLExecute returns 0 rows with BoolsAsChar=1
@ 2013-03-26 15:02 Hiroshi Inoue <inoue@tpf.co.jp>
parent: Heikki Linnakangas <hlinnakangas@vmware.com>
0 siblings, 1 reply; 12+ messages in thread
From: Hiroshi Inoue @ 2013-03-26 15:02 UTC (permalink / raw)
To: Heikki Linnakangas <hlinnakangas@vmware.com>; +Cc: pgsql-odbc
(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.
regards,
Hiroshi Inoue
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
Attachments:
statement.c.patch (text/x-patch, 1019B) download
diff --git a/statement.c b/statement.c
index 1b1980b..c900f29 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)
{
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: SQLExecute returns 0 rows with BoolsAsChar=1
@ 2013-03-29 13:51 Hiroshi Inoue <inoue@tpf.co.jp>
parent: Hiroshi Inoue <inoue@tpf.co.jp>
0 siblings, 1 reply; 12+ messages in thread
From: Hiroshi Inoue @ 2013-03-29 13:51 UTC (permalink / raw)
To: Heikki Linnakangas <hlinnakangas@vmware.com>; +Cc: pgsql-odbc
(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
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
Attachments:
parse_execute.patch (text/x-patch, 12.2K) download
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;
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: SQLExecute returns 0 rows with BoolsAsChar=1
@ 2013-04-24 15:42 Heikki Linnakangas <hlinnakangas@vmware.com>
parent: Hiroshi Inoue <inoue@tpf.co.jp>
0 siblings, 1 reply; 12+ messages in thread
From: Heikki Linnakangas @ 2013-04-24 15:42 UTC (permalink / raw)
To: Hiroshi Inoue <inoue@tpf.co.jp>; +Cc: pgsql-odbc
On 29.03.2013 15:51, Hiroshi Inoue wrote:
> (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.
Many thanks! Although I still don't fully understand the fix, I
committed that with minor copy-editing.
- Heikki
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: SQLExecute returns 0 rows with BoolsAsChar=1
@ 2013-04-25 21:10 Hiroshi Inoue <inoue@tpf.co.jp>
parent: Heikki Linnakangas <hlinnakangas@vmware.com>
0 siblings, 0 replies; 12+ messages in thread
From: Hiroshi Inoue @ 2013-04-25 21:10 UTC (permalink / raw)
To: Heikki Linnakangas <hlinnakangas@vmware.com>; +Cc: pgsql-odbc
(2013/04/25 0:42), Heikki Linnakangas wrote:
> On 29.03.2013 15:51, Hiroshi Inoue wrote:
>> (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.
>
> Many thanks! Although I still don't fully understand the fix, I
> committed that with minor copy-editing.
Thanks.
I'm examing the report from Jack Wilson.
Probably I can reproduce his case now.
regards,
Hiroshi Inoue
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 12+ messages in thread
end of thread, other threads:[~2013-04-25 21:10 UTC | newest]
Thread overview: 12+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-03-18 22:25 SQLExecute returns 0 rows with BoolsAsChar=1 Heikki Linnakangas <hlinnakangas@vmware.com>
2013-03-20 08:56 ` Hiroshi Inoue <inoue@tpf.co.jp>
2013-03-20 13:04 ` Heikki Linnakangas <hlinnakangas@vmware.com>
2013-03-20 14:23 ` Hiroshi Inoue <inoue@tpf.co.jp>
2013-03-21 12:19 ` Hiroshi Inoue <inoue@tpf.co.jp>
2013-03-21 16:42 ` Heikki Linnakangas <hlinnakangas@vmware.com>
2013-03-24 10:07 ` Hiroshi Inoue <inoue@tpf.co.jp>
2013-03-25 11:44 ` Heikki Linnakangas <hlinnakangas@vmware.com>
2013-03-26 15:02 ` Hiroshi Inoue <inoue@tpf.co.jp>
2013-03-29 13:51 ` Hiroshi Inoue <inoue@tpf.co.jp>
2013-04-24 15:42 ` Heikki Linnakangas <hlinnakangas@vmware.com>
2013-04-25 21:10 ` Hiroshi Inoue <inoue@tpf.co.jp>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox