Обсуждение: Why this code fails

Поиск
Список
Период
Сортировка

Why this code fails

От
Igor Korot
Дата:
Hi,
Following code fails with the error "Invalid column nuber in DescribeCol".

I'm trying to run it with the iODBC DM and the official PG ODBC driver.

[code]
int ODBCDatabase::AskPostgresForLogFile()
{
    int result = 0;
    SQLWCHAR *columnName = new SQLWCHAR[256], *columnData;
    SQLSMALLINT columnNameLen, columnDataType, columnDataDigits,
columnDataNullable;
    SQLLEN columnDataLen;
    SQLULEN columnDataSize;
    std::wstring query = L"SHOW log_directory";
    std::vector<std::wstring> errorMsg;
    SQLWCHAR *qry = new SQLWCHAR[query.length() + 2];
    memset( qry, '\0', query.length() + 2 );
    uc_to_str_cpy( qry, query );
    RETCODE ret = SQLAllocHandle( SQL_HANDLE_STMT, m_hdbc, &m_hstmt );
    if( ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO )
    {
        ret = SQLPrepare( m_hstmt, qry, SQL_NTS );
        if( ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO )
        {
            GetErrorMessage( errorMsg, 1 );
            result = 1;
        }
        else
        {
            ret = SQLDescribeCol( m_hstmt, 1, columnName, 256,
&columnNameLen, &columnDataType, &columnDataSize, &columnDataDigits,
&columnDataNullable );
            if( ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO )
            {
                GetErrorMessage( errorMsg, 1 );
                result = 1;
            }
            else
            {
            }
}
[/code]

Thank you.


Re: Why this code fails

От
Clemens Ladisch
Дата:
Igor Korot wrote:
> Following code fails with the error "Invalid column nuber in DescribeCol".
>
>     std::wstring query = L"SHOW log_directory";
>     ret = SQLPrepare( m_hstmt, qry, SQL_NTS );
>     ret = SQLDescribeCol( m_hstmt, 1, columnName, 256, &columnNameLen, &columnDataType, &columnDataSize,
&columnDataDigits,&columnDataNullable );
 

So SQLNumResultCols() does not return the correct count, either?

I suspect the "Parse Statements" ODBC driver option is enabled.
Does it work if you disable that option, or if you call SQLExecute() before,
or if you use SQLExecDirect()?


Regards,
Clemens