1

全部,

    std::wstring query2 = L"SELECT cols.column_name, cols.data_type, cols.character_maximum_length, cols.character_octet_length, cols.numeric_precision, cols.numeric_scale, cols.column_default, cols.is_nullable, cols.ordinal_position, (CASE WHEN kcu.column_name = cols.column_name THEN 1 ELSE 0 END) as pk_flag FROM information_schema.columns cols, information_schema.key_column_usage kcu WHERE kcu.constraint_name = 'PRIMARY' AND kcu.table_schema = cols.table_schema AND kcu.table_name = cols.table_name AND cols.table_schema = ? AND cols.table_name = ?;";
    MYSQL_BIND params[2];
    unsigned long str_length1, str_length2;
    str_data1 = new char[strlen( schema_name )], str_data2 = new char[strlen( table_name )];
    memset( params, 0, sizeof( params ) );
    str_length1 = strlen( schema_name );
    str_length2 = strlen( table_name );
    strncpy( str_data1, schema_name, strlen( schema_name ) );
    strncpy( str_data2, table_name, strlen( table_name ) );
    params[0].buffer_type = MYSQL_TYPE_STRING;
    params[0].buffer = (char *) str_data1;
    params[0].buffer_length = strlen( schema_name );
    params[0].is_null = 0;
    params[0].length = &str_length1;
    params[1].buffer_type = MYSQL_TYPE_STRING;
    params[1].buffer = (char *) str_data2;
    params[1].buffer_length = strlen( table_name );
    params[1].is_null = 0;
    params[1].length = &str_length2;
    res2 = mysql_stmt_init( m_db );
    if( !res2 )
    {
        std::wstring err = m_pimpl->m_myconv.from_bytes( mysql_error( m_db ) );
        errorMsg.push_back( err );
        return 1;
    }
    if( mysql_stmt_prepare( res2, m_pimpl->m_myconv.to_bytes( query2.c_str() ).c_str(), query2.length() ) )
    {
        std::wstring err = m_pimpl->m_myconv.from_bytes( mysql_error( m_db ) );
        errorMsg.push_back( err );
        return 1;
    }
    if( mysql_stmt_bind_param( res2, params ) )
    {
        std::wstring err = m_pimpl->m_myconv.from_bytes( mysql_error( m_db ) );
        errorMsg.push_back( err );
        return 1;
    }
    if( mysql_stmt_execute( res2 ) )
    {
        std::wstring err = m_pimpl->m_myconv.from_bytes( mysql_error( m_db ) );
        errorMsg.push_back( err );
        return 1;
    }
    MYSQL_ROW table_def;
    MYSQL_RES *queryResult1 = mysql_store_result( m_db );
    if( queryResult1 )
    {
        while( ( table_def = mysql_fetch_row( queryResult1 ) ) )
        {
            std::wstring fieldName = m_pimpl->m_myconv.from_bytes( table_def[0] );
            std::wstring fieldType = m_pimpl->m_myconv.from_bytes( table_def[1] );
        }
    }
    if( mysql_stmt_close( res2 ) )
    {
        std::wstring err = m_pimpl->m_myconv.from_bytes( mysql_error( m_db ) );
        errorMsg.push_back( err );
        return 1;
    }
    delete str_data1;
    str_data1 = NULL;
    delete str_data2;
    str_data2 = NULL;

所有 mysql_() 函数都返回成功,但是,queryResult 指针为 NULL。此外,我可以在 Workbench 中成功执行此查询 - 它返回一些行。

我在 Gentoo Linux 上针对 mySQL-5.6.35 使用最新的 Connector/C。

这可能是我想念的非常愚蠢的东西,但我不明白是什么。有人可以提供第二双眼睛吗?

谢谢你。

4

2 回答 2

0

在调试模式下重新编译连接器/C 并尝试调试器后,问题得到解决。

于 2017-07-01T14:06:11.847 回答
0

显然,当您使用准备好的语句时,您不能使用mysql_fetch_row(). 你应该使用mysql_stmt_bind_result()/mysql_stmt_fetch()对。

于 2017-06-22T13:35:09.720 回答