void MySQLConnection::Execute(string query) { //dunno what it does ...leaving untouched int result = mysql_query(handle, query.c_str()); if(result > 0) { uint32 errnom = mysql_errno(handle); const char * reason = mysql_error(handle); Log.Notice("MySQL", "Query Failed: %s\nReason: %s", query.c_str(), reason); // Errors which require us to reconnect. if(errnom == 2006 || errnom == 2008 || errnom == 2013 || errnom == 2055) { handle = mysql_init(NULL); mysql_real_connect(handle, mHost.c_str(), mUser.c_str(), mPassword.c_str(), "", 3306, "", 0); if(!handle) return; UseDatabase(mDatabase); Execute(query); } } }
wyBool ConnectionCommunity::CreateTargetInstance(CopyDatabase *copydb) { MYSQL *tempmysql, *newtargetmysql; copydb->m_newtargettunnel = NULL; copydb->m_tgtprocess = INVALID_HANDLE_VALUE; // create a tunnel and mysql object copydb->m_newtargettunnel = CreateTunnel((wyBool)copydb->m_targettunnel->IsTunnel()); VERIFY(tempmysql = copydb->m_newtargettunnel->mysql_init((MYSQL*)0)); SetMySQLOptions(copydb->m_tgtinfo, copydb->m_newtargettunnel, &tempmysql); newtargetmysql = copydb->m_newtargettunnel->mysql_real_connect(tempmysql, (*copydb->m_targetmysql)->host, (*copydb->m_targetmysql)->user, (*copydb->m_targetmysql)->passwd, NULL, (*copydb->m_targetmysql)->port, NULL, (*copydb->m_targetmysql)->client_flag | CLIENT_MULTI_RESULTS, NULL); if(!newtargetmysql) { ShowMySQLError(copydb->m_hwnddlg, copydb->m_newtargettunnel, &tempmysql, NULL, wyTrue); return wyFalse; } else { copydb->m_newtargetmysql=newtargetmysql; } if(!copydb->CreateTargetDB()) return wyFalse; if(UseDatabase(copydb->m_targetdb, newtargetmysql, copydb->m_newtargettunnel) == wyFalse) { ShowMySQLError(copydb->m_hwnddlg, copydb->m_newtargettunnel, &tempmysql, NULL, wyTrue); return wyFalse; } copydb->m_newtargettunnel->SetServerInfo(newtargetmysql, copydb->m_targettunnel->mysql_get_server_info(*copydb->m_targetmysql)); copydb->m_newtargetmysql = newtargetmysql; return wyTrue; }
wyBool ConnectionCommunity::CreateSourceInstance(CopyDatabase *copydb) { MYSQL *tempmysql, *newsrcmysql; copydb->m_newsrctunnel = NULL; copydb->m_srcprocess = INVALID_HANDLE_VALUE; // create a tunnel and mysql object copydb->m_newsrctunnel = CreateTunnel(wyFalse); VERIFY(tempmysql = copydb->m_newsrctunnel->mysql_init((MYSQL*)0)); //if(IsMySQL41(copydb->m_newtargettunnel, &tempmysql)) //VERIFY((copydb->m_newtargettunnel->mysql_options(tempmysql, MYSQL_SET_CHARSET_NAME, "utf8"))); VERIFY(!(copydb->m_newsrctunnel->mysql_options(tempmysql, MYSQL_INIT_COMMAND, "/*40030 SET net_write_timeout=3600 */"))); SetMySQLOptions(copydb->m_srcinfo, copydb->m_newsrctunnel, &tempmysql, wyTrue); newsrcmysql = copydb->m_newsrctunnel->mysql_real_connect(tempmysql, (*copydb->m_srcmysql)->host, (*copydb->m_srcmysql)->user, (*copydb->m_srcmysql)->passwd, NULL, (*copydb->m_srcmysql)->port, NULL, (*copydb->m_srcmysql)->client_flag | CLIENT_MULTI_RESULTS, NULL); if(!newsrcmysql) { ShowMySQLError(copydb->m_hwnddlg, copydb->m_newsrctunnel, &tempmysql, NULL, wyTrue); return wyFalse; } if(UseDatabase(copydb->m_srcdb, newsrcmysql, copydb->m_newsrctunnel) == wyFalse) { ShowMySQLError(copydb->m_hwnddlg, copydb->m_newsrctunnel, &tempmysql, NULL, wyTrue); return wyFalse; } copydb->m_newsrctunnel->SetServerInfo(newsrcmysql, copydb->m_srctunnel->mysql_get_server_info(*copydb->m_srcmysql)); copydb->m_newsrcmysql = newsrcmysql; return wyTrue; }