From: Heikki Linnakangas <hlinnakangas@vmware.com>
To: Przemyslaw Rzepecki <przemyslaw.rzepecki@ericsson.com>
Cc: pgsql-odbc@postgresql.org
Subject: Re: SQLFetchScroll with SQL_ATTR_ROWS_FETCHED_PTR closing statement.
Date: Tue, 04 Mar 2014 16:21:08 +0200
Message-ID: <5315E154.3080406@vmware.com> (raw)
In-Reply-To: <1385453596.4529.206.camel@salti.rnd.ki.sw.ericsson.se>
References: <1385453596.4529.206.camel@salti.rnd.ki.sw.ericsson.se>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-odbc>
On 11/26/2013 10:13 AM, Przemyslaw Rzepecki wrote:
> Hi,
>
> I have encountered some problems with SQLFetchScroll when
> SQL_ATTR_ROWS_FETCHED_PTR attribute is set. The statement is closed
> after first call to SQLFetchScroll. This first call is successful the
> numbers of fetched rows correct, but the statement handle, is after the
> call, invalid and can not be used in any other SQLFetchScroll calls.
>
> // table test with 'id' integer column and 20 rows.
> The code looks like that:
> alloc_stmt(hdbc, &hstmt);
> SQLPrepare(hstmt, (SQLCHAR *)"select * from test", SQL_NTS);
> SQLExecute(hstmt);
> SQLSetStmtAttr(hstmt, SQL_ATTR_ROWS_FETCHED_PTR, &rowsFetched, 0);
> SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_ARRAY_SIZE, 1, 0);
> SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_STATUS_PTR, rowStatus, 0);
> SQLBindCol(hstmt, 1, SQL_C_LONG, idout, sizeof(SQLINTEGER), indicator);
> SQLFetchScroll(hstmt, SQL_FETCH_NEXT, 0);
> // all above is success and rowStatus and idout arrays are correctly
> // updated.
>
> SQLFetchScroll(hstmt, SQL_FETCH_NEXT, 0);
> // fails with error INVALID HANDLE
>
> Is my usage of the fetch scroll function incorrect?
Looks correct to me. I tried to reproduce this with the attached test
program (modified from the regression tests), and it worked fine.
- Heikki
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbcAttachments:rows_fetched-test.c (text/x-csrc, 1.6K) download
#include <stdio.h>
#include <stdlib.h>
#include "common.h"
#define ARRAY_SIZE 100
int main(int argc, char **argv)
{
SQLRETURN rc;
HSTMT hstmt = SQL_NULL_HSTMT;
char *sql;
SQLINTEGER int_array[ARRAY_SIZE];
SQLLEN ind_array[ARRAY_SIZE];
SQLULEN rowsFetched[ARRAY_SIZE];
SQLUSMALLINT rowStatus[ARRAY_SIZE];
int i;
test_connect();
rc = SQLAllocStmt(conn, &hstmt);
if (!SQL_SUCCEEDED(rc))
{
print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn);
exit(1);
}
/* Prepare + Execute */
sql = "SELECT generate_series(1,20)";
rc = SQLPrepare(hstmt, (SQLCHAR *) sql, SQL_NTS);
CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
rc = SQLExecute(hstmt);
CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
/* Set attributes */
rc = SQLSetStmtAttr(hstmt, SQL_ATTR_ROWS_FETCHED_PTR, &rowsFetched, 0);
CHECK_STMT_RESULT(rc, "SQLSetStmtAttr(SQL_ATTR_ROWS_FETCHED_PTR) failed", hstmt);
rc = SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER) 1, 0);
CHECK_STMT_RESULT(rc, "SQLSetStmtAttr(SQL_ATTR_ROW_ARRAY_SIZE) failed", hstmt);
rc = SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_STATUS_PTR, &rowStatus, 0);
CHECK_STMT_RESULT(rc, "SQLSetStmtAttr(SQL_ATTR_ROW_STATUS_PTR) failed", hstmt);
/* Bind */
rc = SQLBindCol(hstmt, 1, SQL_INTEGER, int_array, sizeof(SQLLEN), ind_array);
CHECK_STMT_RESULT(rc, "SQLBindCol failed", hstmt);
/* Fetch results with SQLFetchScroll */
i = 0;
while ((rc = SQLFetchScroll(hstmt, SQL_FETCH_NEXT, 0)) != SQL_NO_DATA)
{
i++;
CHECK_STMT_RESULT(rc, "SQLFetchScroll failed", hstmt);
printf("row %d: %d\n", i, int_array[0]);
}
/* Clean up */
test_disconnect();
return 0;
}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-odbc@postgresql.org
Cc: hlinnakangas@vmware.com, przemyslaw.rzepecki@ericsson.com
Subject: Re: SQLFetchScroll with SQL_ATTR_ROWS_FETCHED_PTR closing statement.
In-Reply-To: <5315E154.3080406@vmware.com>
References: <1385453596.4529.206.camel@salti.rnd.ki.sw.ericsson.se> <5315E154.3080406@vmware.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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