X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A6656DB231 for ; Sun, 30 Oct 2005 09:07:13 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 77499-06 for ; Sun, 30 Oct 2005 13:07:10 +0000 (GMT) Received: from fep30-app.kolumbus.fi (fep30-0.kolumbus.fi [193.229.0.32]) by svr1.postgresql.org (Postfix) with ESMTP id 57355D7011 for ; Sun, 30 Oct 2005 09:07:10 -0400 (AST) Received: from [192.168.1.101] (really [80.186.93.179]) by fep30-app.kolumbus.fi with ESMTP id <20051030130714.QUIA15053.fep30-app.kolumbus.fi@[192.168.1.101]>; Sun, 30 Oct 2005 15:07:14 +0200 Message-ID: <4364D392.8040503@kolumbus.fi> Date: Sun, 30 Oct 2005 16:07:14 +0200 From: Marko Ristola User-Agent: Debian Thunderbird 1.0.2 (X11/20051002) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Dave Page Cc: Anoop Kumar , pgsql-odbc@postgresql.org, Victor Rivero Subject: Re: Fix for Declare/Fetch issue References: In-Reply-To: Content-Type: multipart/mixed; boundary="------------070603050607070104030105" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.072 required=5 tests=[AWL=0.072, UPPERCASE_25_50=0] X-Spam-Score: 0.072 X-Spam-Level: X-Archive-Number: 200510/125 X-Sequence-Number: 6227 This is a multi-part message in MIME format. --------------070603050607070104030105 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit My test case failed. I tested only column wise query. It returned the correct number of rows, but only the first cursor fetch got correct data. The self contained test case is attached: it creates a test table, inserts there six rows and fetches those rows as column wise. Please use Fetch=2 with it. Finally it drops the test table. You need to change DATABASE, USERID and PASSWORD. It worked without Declare/fetch as it should: OK(UseDeclareFetch=0): After colwise query: data[1] = { 4, 0001 }, data[2] = { 4, 1001 } After colwise query: data[1] = { 4, 2001 }, data[2] = { 4, 3001 } After colwise query: data[1] = { 4, 4001 }, data[2] = { 4, 5001 } ok. (4= number of characters. "0001" is a character string value.) FAILED (UseDeclareFetch=1,Fetch=2): After colwise query: data[1] = { 4, 0001 }, data[2] = { 4, 1001 } After colwise query: data[1] = { -1, UNSET }, data[2] = { -1, UNSET } After colwise query: data[1] = { -1, UNSET }, data[2] = { -1, UNSET } ok. -1 means possibly a NULL value(?). UNSET means that the string buffer is uninitialized after SQLFetchScroll. Unfreed memory was a problem with this failed test case. You can confirm that by setting the number of rows into 600 000 and using Fetch=2 with Declare/Fetch. The program prints "INITIALIZATION OF 600000 ROWS DONE". Then the process's used memory grows very fast. Regards, Marko Ristola. Dave Page wrote: >Great, thanks Anoop. > >Can anyone test this fairly quickly? I don't have the appropriate hardware >to hand for the next few days, and it would be helpful for a number of >reasons if we could get this committed before November. > >Thanks, Dave. > > > --------------070603050607070104030105 Content-Type: text/x-csrc; name="TestColwiseQuery.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="TestColwiseQuery.c" #include #include #include #include #include #define NUMBEROF_TEST_ROWS (6) int CHECK(SQLSMALLINT handle_type,SQLHANDLE handle,SQLRETURN ret) { if (ret != SQL_SUCCESS && ret != SQL_NO_DATA) { SQLRETURN ret; SQLINTEGER i = 0; SQLCHAR state[32]; SQLINTEGER native; SQLCHAR text[512]; SQLSMALLINT text_len; int has_err = 0; do { i++; ret = SQLGetDiagRec(handle_type,handle,i,state,&native,text,sizeof(text), &text_len); fprintf(stderr,"message=%s\nstate=%s native error %d.\n",text,state,native); has_err=1; } while(ret == SQL_SUCCESS); if (!has_err) fprintf(stderr,"An unknonw error occurred\n"); } if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO || ret == SQL_NO_DATA) return 1; return 0; } // PREPARATIONS int CreateInitialData(SQLHANDLE m_env,SQLHANDLE m_conn) { int row; int nextVacuum=1024; SQLHANDLE stmt; if (!CHECK(SQL_HANDLE_DBC,m_conn,SQLSetConnectOption(m_conn,SQL_AUTOCOMMIT,0))) return 1; if (!CHECK(SQL_HANDLE_DBC,m_conn,SQLAllocHandle(SQL_HANDLE_STMT,m_conn,&stmt))) return 1; if (!CHECK(SQL_HANDLE_STMT,stmt,SQLExecDirect(stmt,(SQLCHAR*)"CREATE TABLE test_testcolwisequery (" " key1 VARCHAR(250)," " key2 VARCHAR(250)," " value1 VARCHAR(250)," " value2 VARCHAR(250)," " primary key(key1,key2))",SQL_NTS))) goto fail; for (row=0; row < NUMBEROF_TEST_ROWS; row++) { char key1[200],key2[200],value1[200]; char sqlcmd[512]; sprintf(key1,"%d000",row); sprintf(key2,"%d001",row); sprintf(value1,"%d002",row); sprintf(sqlcmd,"INSERT INTO test_testcolwisequery(key1,key2,value1) values( '%s' , '%s' , '%s' )", key1,key2,value1); if (!CHECK(SQL_HANDLE_STMT,stmt,SQLExecDirect(stmt,(SQLCHAR*)sqlcmd,SQL_NTS))) goto fail; if (row % 10000 == 0) { if (!CHECK(SQL_HANDLE_DBC,m_conn,SQLTransact(m_env,m_conn,SQL_COMMIT))) goto fail; } if (row == nextVacuum) { if (!CHECK(SQL_HANDLE_DBC,m_conn,SQLTransact(m_env,m_conn,SQL_COMMIT))) goto fail; if (!CHECK(SQL_HANDLE_STMT,stmt,SQLExecDirect(stmt,(SQLCHAR*)"VACUUM ANALYZE test_testcolwisequery",SQL_NTS))) goto fail; if (!CHECK(SQL_HANDLE_DBC,m_conn,SQLTransact(m_env,m_conn,SQL_COMMIT))) goto fail; nextVacuum *=2; } } if (!CHECK(SQL_HANDLE_DBC,m_conn,SQLTransact(m_env,m_conn,SQL_COMMIT))) goto fail; SQLFreeHandle(SQL_HANDLE_STMT,stmt); if (NUMBEROF_TEST_ROWS > 100) printf("INITIALIZATION OF %d ROWS DONE.\n",NUMBEROF_TEST_ROWS); return 1; fail: SQLFreeHandle(SQL_HANDLE_STMT,stmt); return 0; } int DropTestEnv(SQLHANDLE m_env,SQLHANDLE m_conn) { SQLHANDLE stmt; if (!CHECK(SQL_HANDLE_DBC,m_conn,SQLAllocHandle(SQL_HANDLE_STMT,m_conn,&stmt))) return 1; if (!CHECK(SQL_HANDLE_STMT,stmt,SQLExecDirect(stmt,(SQLCHAR*)"DROP TABLE test_testcolwisequery",SQL_NTS))) goto fail; if (!CHECK(SQL_HANDLE_DBC,m_conn,SQLTransact(m_env,m_conn,SQL_COMMIT))) goto fail; SQLFreeHandle(SQL_HANDLE_STMT,stmt); return 1; fail: SQLFreeHandle(SQL_HANDLE_STMT,stmt); return 0; } // PREPARATIONS END #define TEXT_SIZE 300 SQLINTEGER data_len[2]; char data[2][TEXT_SIZE]; void initBufs() { data_len[0]=-123; data_len[1]=-123; strcpy(data[0],"UNSET"); strcpy(data[1],"UNSET"); } void PrintData(char *msg,SQLUINTEGER nrows) { unsigned int i; printf("%s: ",msg); for (i=0; i