#include #include #include #include #include #include using namespace std; const string conn_str= "driver={MySQL ODBC 3.51 driver};user=root;port=7007"; #define odbc_ok(Call) \ do { \ SQLRETURN ret= Call; \ assert(SQL_SUCCEEDED(ret)); \ } while (false) class Bug39878_test { SQLHENV henv; SQLHDBC hdbc; SQLHSTMT hstmt; unsigned int m_row_count; unsigned int m_row; bool m_more_rows; char m_col_a[128]; char m_col_b[128]; public: Bug39878_test(const string&); ~Bug39878_test(); bool load_data(void); bool set_timeout(unsigned); unsigned long row_count(void); void start_scan(void); bool next_row(void); bool more_rows(void); unsigned long row(void); void show_row(ostream&); private: bool exec_sql(const string&); }; Bug39878_test::Bug39878_test(const string&) { odbc_ok(SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv)); odbc_ok(SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER*)SQL_OV_ODBC3, 0)); SQLCHAR out_conn_str[255]= ""; SQLSMALLINT out_conn_str_length; odbc_ok(SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc)); odbc_ok(SQLDriverConnect( hdbc, NULL, (SQLCHAR*)conn_str.c_str(), conn_str.length(), out_conn_str, sizeof(out_conn_str), &out_conn_str_length, SQL_DRIVER_NOPROMPT )); odbc_ok(SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt)); } Bug39878_test::~Bug39878_test() { exec_sql("DROP TABLE bug39878.t"); exec_sql("DROP DATABASE bug39878"); SQLFreeHandle(SQL_HANDLE_STMT, hstmt); SQLDisconnect(hdbc); SQLFreeHandle(SQL_HANDLE_DBC, hdbc); SQLFreeHandle(SQL_HANDLE_ENV, henv); } bool Bug39878_test::exec_sql(const string &stmt) { SQLRETURN ret= SQLExecDirect(hstmt,(SQLCHAR*)stmt.c_str(),stmt.length()); if (SQL_SUCCEEDED(ret)) return true; cout <<"!Error when executing SQL: " <