Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WKqDe-000100-Ly for pgsql-odbc@arkaria.postgresql.org; Tue, 04 Mar 2014 14:21:18 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WKqDe-00041t-64 for pgsql-odbc@arkaria.postgresql.org; Tue, 04 Mar 2014 14:21:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WKqDd-00041i-KX for pgsql-odbc@postgresql.org; Tue, 04 Mar 2014 14:21:17 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WKqDZ-0001er-Q4 for pgsql-odbc@postgresql.org; Tue, 04 Mar 2014 14:21:17 +0000 Received: from sc9-mailhost2.vmware.com (sc9-mailhost2.vmware.com [10.113.161.72]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id DA9F7285CC; Tue, 4 Mar 2014 06:21:10 -0800 (PST) Received: from zcs-prod-ext-mta-2.vmware.com (zcs-prod-ext-mta-2.vmware.com [10.113.62.224]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id CC92CB03EA; Tue, 4 Mar 2014 06:21:10 -0800 (PST) Received: from zcs-prod-ext-mta-2.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTP id 8FE49C005B; Tue, 4 Mar 2014 06:21:08 -0800 (PST) Received: from [192.168.1.90] (zimbra-prod-ext-proxy-vip.vmware.com [10.113.63.87]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTPSA; Tue, 4 Mar 2014 06:21:07 -0800 (PST) Message-ID: <5315E154.3080406@vmware.com> Date: Tue, 04 Mar 2014 16:21:08 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10 MIME-Version: 1.0 To: Przemyslaw Rzepecki CC: pgsql-odbc@postgresql.org Subject: Re: SQLFetchScroll with SQL_ATTR_ROWS_FETCHED_PTR closing statement. References: <1385453596.4529.206.camel@salti.rnd.ki.sw.ericsson.se> In-Reply-To: <1385453596.4529.206.camel@salti.rnd.ki.sw.ericsson.se> Content-Type: multipart/mixed; boundary="------------010008090801050608060508" X-Pg-Spam-Score: -6.9 (------) 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. --------------010008090801050608060508 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 --------------010008090801050608060508 Content-Type: text/x-csrc; name="rows_fetched-test.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="rows_fetched-test.c" #include #include #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; } --------------010008090801050608060508 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 --------------010008090801050608060508--