Problem with ODBC class - Mailing list pgsql-odbc
From | Igor Korot |
---|---|
Subject | Problem with ODBC class |
Date | |
Msg-id | CA+FnnTxkBW42t2VvdL-CDiV=WJOu6nd-86-wkwfbWNMkwLic3A@mail.gmail.com Whole thread Raw |
Responses |
Re: Problem with ODBC class
|
List | pgsql-odbc |
Hi, ALL, Is there a reason why following function returns empty string? SQLHSTMT stmt = 0; SQLHDBC hdbc = 0; int result = 0; SQLLEN cbTableName = SQL_NTS, cbSchemaName = SQL_NTS; SQLWCHAR *table_name = NULL, *schema_name = NULL, *qry = NULL; SQLWCHAR *owner = NULL; std::wstring query; if( pimpl->m_subtype == L"PostgreSQL" ) query = L"SELECT u.usename FROM pg_class c, pg_user u, pg_namespace n WHERE n.oid = c.relnamespace AND u.usesysid = c.relowner AND n.nspname = ? AND relname = ?"; SQLRETURN retcode = SQLAllocHandle( SQL_HANDLE_DBC, m_env, &hdbc ); if( retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { GetErrorMessage( errorMsg, 0 ); result = 1; } else { SQLSMALLINT OutConnStrLen; retcode = SQLDriverConnect( hdbc, NULL, m_connectString, SQL_NTS, NULL, 0, &OutConnStrLen, SQL_DRIVER_NOPROMPT ); if( retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { GetErrorMessage( errorMsg, 2, hdbc ); result = 1; } else { retcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &stmt ); if( retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { GetErrorMessage( errorMsg, 2, hdbc ); result = 1; } else { table_name = new SQLWCHAR[tableName.length() + 2]; schema_name = new SQLWCHAR[schemaName.length() + 2]; qry = new SQLWCHAR[query.length() + 2]; memset( qry, '\0', query.size() + 2 ); memset( table_name, '\0', tableName.length() + 2 ); memset( schema_name, '\0', schemaName.length() + 2 ); uc_to_str_cpy( qry, query ); uc_to_str_cpy( table_name, tableName ); uc_to_str_cpy( schema_name, schemaName ); retcode = SQLPrepare( stmt, qry, SQL_NTS ); if( retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO ) { retcode = SQLBindParameter( stmt, 1, SQL_PARAM_INPUT, SQL_C_WCHAR, SQL_WCHAR, schemaName.length(), 0, schema_name, 0, &cbSchemaName ); if( retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO ) { retcode = SQLBindParameter( stmt, 2, SQL_PARAM_INPUT, SQL_C_WCHAR, SQL_WCHAR, tableName.length(), 0, table_name, 0, &cbTableName ); if( retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO ) { retcode = SQLExecute( stmt ); if( retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO ) { SQLSMALLINT nameBufLength, dataTypePtr, decimalDigitsPtr, isNullable; SQLULEN columnSizePtr; SQLLEN cbTableOwner; retcode = SQLDescribeCol( stmt, 1, NULL, 0, &nameBufLength, &dataTypePtr, &columnSizePtr, &decimalDigitsPtr, &isNullable ); if( retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO ) { owner = new SQLWCHAR[columnSizePtr + 1]; retcode = SQLBindCol( stmt, 1, SQL_C_WCHAR, &owner, columnSizePtr, &cbTableOwner ); if( retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO ) { retcode = SQLFetch( stmt ); if( retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO && retcode != SQL_NO_DATA ) { GetErrorMessage( errorMsg, 1, stmt ); result = 1; } if( retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO ) str_to_uc_cpy( tableOwner, owner ); } else { if( pimpl->m_subtype == L"Microsoft SQL Server" ) { tableOwner = L"dbo"; result = 0; } else { GetErrorMessage( errorMsg, 1, stmt ); result = 1; } } } else if( retcode != SQL_NO_DATA ) { GetErrorMessage( errorMsg, 1, stmt ); result = 1; } } else if( retcode != SQL_NO_DATA ) { GetErrorMessage( errorMsg, 1, stmt ); result = 1; } } else if( retcode != SQL_NO_DATA ) { GetErrorMessage( errorMsg, 1, stmt ); result = 1; } } else if( retcode != SQL_NO_DATA ) { GetErrorMessage( errorMsg, 1, stmt ); result = 1; } } else if( retcode != SQL_NO_DATA ) { GetErrorMessage( errorMsg, 1, stmt ); result = 1; } } } } if( stmt ) { retcode = SQLFreeHandle( SQL_HANDLE_STMT, stmt ); if( retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { GetErrorMessage( errorMsg, 1, stmt ); result = 1; } else { stmt = 0; retcode = SQLDisconnect( hdbc ); if( retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { GetErrorMessage( errorMsg, 1, stmt ); result = 1; } else { retcode = SQLFreeHandle( SQL_HANDLE_DBC, hdbc ); if( retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { GetErrorMessage( errorMsg, 1, stmt ); result = 1; } else hdbc = 0; } } } delete qry; qry = NULL; delete table_name; table_name = NULL; delete schema_name; schema_name = NULL; delete owner; owner = NULL; return result; All ODBC calls are succeeding but the owner value is <Bad Pointer>. Thank you for any pointers.
pgsql-odbc by date: