MySQL Forums
Forum List  »  Connector/ODBC

No rows is inserted in the table
Posted by: Igor Korot
Date: October 25, 2025 07:58PM

Hi, ALL,
Apologies if this subforum is a wrong place to ask about this.

My application that I'm working on uses mySQL. As of this moment I'm using version 8.0.

I'm also using 8.0 ODBC driver.

I'm working with Gentoo Linux and unixODBC.

Below is my (simplified) code:

                std::wstring qry2 = L"INSERT IGNORE INTO abcattbl VALUES( ?, ?, (SELECT CASE WHEN t.engine = 'InnoDB' THEN (SELECT st.table_id FROM information_schema.INNODB_TABLES st WHERE name = CONCAT(?,'/', ?) ) ELSE (SELECT 0) END AS id FROM information_schema.tables t WHERE t.table_name = ? AND t.table_schema = ?), \'\', 8, 400, \'N\', \'N\', 0, 34, 0, \'Serif\', 8, 400, \'N\', \'N\', 0, 34, 0, \'Serif\', 8, 400, \'N\', \'N\', 0, 34, 0, \'Serif\', \'\' );";

    SQLWCHAR *qry = new SQLWCHAR[qry2.length() + 2];
    memset( qry, '\0', qry2.length() + 2 );
    uc_to_str_cpy( qry, qry2 );

    auto qry1 = new SQLWCHAR[30];
    memset( qry1, '\0', 30 );
    uc_to_str_cpy( qry1, L"BEGIN" );
    ret = SQLExecDirect( m_hstmt, qry1, SQL_NTS );
    delete[] qry1;
    qry1 = nullptr;
    ret = SQLPrepare( m_hstmt, qry, SQL_NTS );
    ret = SQLBindParameter( m_hstmt, 1, SQL_PARAM_INPUT, SQL_C_TINYINT, SQL_TINYINT, 0, 0, &osid, 0, &cbParam[2] );
    for( auto it = pimpl.m_tableDefinitions[cat].begin(); it < pimpl.m_tableDefinitions[cat].end(); ++it )
    {
        schemaName = new SQLWCHAR[(*it).schemaName.length() + 2];
        tableName = new SQLWCHAR[(*it).tableName.length() + 2];
        memset( schemaName, '\0', (*it).schemaName.length() + 2 );
        memset( tableName, '\0', (*it).tableName.length() + 2 );
        uc_to_str_cpy( schemaName, (*it).schemaName );
        uc_to_str_cpy( tableName, (*it).tableName );
        ret = SQLBindParameter( m_hstmt, 2, SQL_PARAM_INPUT, SQL_C_WCHAR, SQL_WCHAR, (*it).tableName.length(), 0, tableName, 0, &cbParam[1] );
        ret = SQLBindParameter( m_hstmt, 3, SQL_PARAM_INPUT, SQL_C_WCHAR, SQL_WCHAR, (*it).schemaName.length(), 0, schemaName, 0, &cbParam[2] );
        ret = SQLBindParameter( m_hstmt, 4, SQL_PARAM_INPUT, SQL_C_WCHAR, SQL_WCHAR, (*it).tableName.length(), 0, tableName, 0, &cbParam[3] );
        ret = SQLBindParameter( m_hstmt, 5, SQL_PARAM_INPUT, SQL_C_WCHAR, SQL_WCHAR, (*it).tableName.length(), 0, tableName, 0, &cbParam[3] );
        ret = SQLBindParameter( m_hstmt, 6, SQL_PARAM_INPUT, SQL_C_WCHAR, SQL_WCHAR, (*it).schemaName.length(), 0, schemaName, 0, &cbParam[2] );
        ret = SQLExecute( m_hstmt );
        delete[] schemaName;
        delete[] tableName;
        schemaName = nullptr;
        tableName = nullptr;
    }
    ret = SQLEndTran( SQL_HANDLE_DBC, m_hdbc, SQL_COMMIT );

Table structure is as follows:

CREATE TABLE IF NOT EXISTS abcattbl(abt_os tinyint, abt_tnam char(129) NOT NULL, abt_tid integer, abt_ownr char(129) NOT NULL, abd_fhgt smallint, abd_fwgt smallint, abd_fitl char(1), abd_funl integer, abd_fstr integer, abd_fchr smallint, abd_fptc smallint, abd_ffce char(18), abh_fhgt smallint, abh_fwgt smallint, abh_fitl char(1), abh_funl integer, abh_fstr integer, abh_fchr smallint, abh_fptc smallint, abh_ffce char(18), abl_fhgt smallint, abl_fwgt smallint, abl_fitl char(1), abl_funl integer, abl_fstr integer, abl_fchr smallint, abl_fptc smallint, abl_ffce char(18), abt_cmnt char(254), PRIMARY KEY( abt_tnam, abt_ownr ));
CREATE UNIQUE INDEX abcatt_x ON abcattbl(abt_os ASC, abt_tnam ASC, abt_ownr ASC)\"));

The problem is that after executing all those SQLBindParameter() and SQLExecute() the table contains only 1 row.

I turned on server logging and for some reason only the first parameter is properly bound. No table/schema parameter is bound as appropriate.

One other thing:

With the ODBC driver it seems I can't retrieve any of the INFORMATION_SCHEMA table or system tables of mySQL. Calling SQLTables() retrieves only my own tables.
Is this how the driver operates? In odbc.ini I do have a database name defied.

Thank you for any pointers.

void ODBCDatabase::uc_to_str_cpy(SQLWCHAR *dest, const std::wstring &src)
{
    const wchar_t *temp = src.c_str();
    while( *dest )
    {
        dest++;
    }
    while( *temp )
    {
        *dest = *temp;
        dest++;
        temp++;
    }
    *dest++ = '\0';
    *dest = '\0';
}


Options: ReplyQuote


Subject
Written By
Posted
No rows is inserted in the table
October 25, 2025 07:58PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.