Bug #39561 SQLTables() doesn't properly handle empty strings to list catalogs and tables
Submitted: 20 Sep 2008 20:21 Modified: 10 Oct 2008 14:54
Reporter: Farid Zidan (Candidate Quality Contributor)
Status: Closed
Category:Connector/ODBC Severity:S1 (Critical)
Version:5.1.5 OS:Microsoft Windows (XP SP3)
Assigned to: Bugs System Target Version:5.1
Tags: SQLTables table name NULL, qc
Triage: D3 (Medium)

[20 Sep 2008 20:21] Farid Zidan
Description:
Execute SQLTables passing NULL as tablename. You should get all the tables for the given
database, instead you get only one row in the resultset with table name of NULL.

ODBC connect 3.5x.x correctly handles this call, but the 5.1.5 driver does not.

How to repeat:
// execute code fragment after replacing szTableCat with your own test database
// name. Should return all tables for the database. Instead one row is returned
//
    const TCHAR *szTableCat = "your database name"; ASSERT(FALSE);
    const TCHAR *szTableSchem = "";
    const TCHAR *szTableName  = "";
    const TCHAR *szTableType = "TABLE";

    size_t  cbTableCat   = strlen( szTableCat );
    size_t  cbTableSchem = strlen( szTableSchem );
    size_t  cbTableName  = strlen( szTableName );
    size_t  cbTableType  = m_sTableType.GetLength();

    SQLRETURN rc = ::SQLTables( 
        pSQL->Gethstmt(),
        ( SQLCHAR * )   ( *szTableCat ? szTableCat : NULL ),
        ( SQLSMALLINT ) cbTableCat,
        ( SQLCHAR * )   ( *szTableSchem ? szTableSchem : NULL ),
        ( SQLSMALLINT ) cbTableSchem,
        ( SQLCHAR * )   ( *szTableName ? szTableName : NULL ),
        ( SQLSMALLINT ) cbTableName ,
( SQLCHAR * )   ( !m_sTableType.IsEmpty() ? (SQLCHAR *)(LPCTSTR) m_sTableType : NULL ),
        ( SQLSMALLINT ) cbTableType );

Suggested fix:
Correctly handle NULL passed as catalog name, table name, or type type.
[2 Oct 2008 18:11] Jess Balint
Branch pushed to launchpad:
bug39561">https://code.launchpad.net/~myodbc-developers/myodbc/bug39561
[9 Oct 2008 19:30] Jess Balint
Merged to trunk. Will be released in 5.1.6.
[10 Oct 2008 14:54] Tony Bedford
An entry was added to the 5.1.6 changelog:

When the SQLTables method was called with NULL passed as the tablename parameter, only
one row in the resultset, with table name of NULL was returned, instead of all tables for
the given database.