I am writing an ODBC wrapper class to read and write with MS Access Database file.Below function is to retrieve all record set from query.However it turned out it does not work properly.I think the main problem is I did something wrong with Array<String*> and dynamic array of array of char(*).Could you please figure me out the proper way to do so?Thanks.
Code: Select all
String** fetchAll(const char* pszSql)
{
int i;
array=Array<String*>{};
if(!pszSql)
return null;
retcode=SQLExecDirectUTF8((SQLCHAR*)pszSql,SQL_NTS);
if((retcode != SQL_SUCCESS) || (retcode != SQL_SUCCESS_WITH_INFO))
{
//dbError(format(retcode));
return null;
}
retcode=SQLNumResultCols(hstmt,&col);
if((retcode != SQL_SUCCESS) || (retcode != SQL_SUCCESS_WITH_INFO))
{
//dbError(format(retcode));
return null;
}
row=0;
colLen = 0;
buf_len = 0;
colType = 0;
while(true)
{
char sz_buf[256];
char* pszBuf;
SQLINTEGER buflen;
char** rowData=new char*[col+1];
if(SQLFetch(hstmt)==SQL_NO_DATA)
{
break;
}
for(i=1;i<=col;i++)
{
SQLColAttribute(hstmt, i, SQL_DESC_NAME, sz_buf, 256, &buf_len, 0);
SQLColAttribute(hstmt, i, SQL_DESC_TYPE, 0, 0, 0, &colType);
SQLColAttribute(hstmt, i, SQL_DESC_LENGTH, NULL, 0, 0, &colLen);
pszBuf=new char[colLen+1];
pszBuf[0]='\0';
SQLGetData(hstmt,i,SQL_C_WCHAR,pszBuf,50,&buflen);
rowData[i-1]=CopyString(pszBuf);
}
array.Add(rowData);
row++;
}
SQLCancel(hstmt);
SQLFreeStmt(hstmt, SQL_DROP);
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);
return array;
}