slave.c
/* Run a query, whenever server comes back up, return lats resultset data */
Run a query, whenever server comes back up, return lats resultset data
Run a query whenever server comes back up return lats resultset data
MYSQL_RES *slave_query(MYSQL * slave, char *query, unsigned long length)
{
    MYSQL_RES *res = NULL, *ret = NULL;
    int i = 0, status = 0;
    if (!length)
        length = strlen(query);
    while (mysql_real_query(slave, query, length)) {
        if (mysql_errno(slave) == CR_SERVER_LOST
            || mysql_errno(slave) == CR_CONN_HOST_ERROR)
            connect_or_keep_connecting(slave);
        else {
            g_warning("%s", mysql_error(slave));
            return NULL;
        }
        if (i++ >= 3)
            return NULL;
    }
    do {
        res = mysql_store_result(slave);
        if (res) {
            if (ret)
                mysql_free_result(ret);
            ret = res;
        }
        if ((status = mysql_next_result(slave)) > 0)
            if (mysql_errno(slave) != 1180 && mysql_errno(slave) != 1062)
                g_warning("Could not execute statement: %s (%d)",
                          mysql_error(slave), mysql_errno(slave));
    } while (status == 0);
    return ret;
}
MYSQL_RES * slave_query ( MYSQL * slave , char * query , unsigned long length ) { MYSQL_RES * res = NULL , * ret = NULL ; int i = 0 , status = 0 ; if ( ! length ) length = strlen ( query ) ; while ( mysql_real_query ( slave , query , length ) ) { if ( mysql_errno ( slave ) == CR_SERVER_LOST || mysql_errno ( slave ) == CR_CONN_HOST_ERROR ) connect_or_keep_connecting ( slave ) ; else { g_warning ( " " , mysql_error ( slave ) ) ; return NULL ; } if ( i ++ >= 3 ) return NULL ; } do { res = mysql_store_result ( slave ) ; if ( res ) { if ( ret ) mysql_free_result ( ret ) ; ret = res ; } if ( ( status = mysql_next_result ( slave ) ) > 0 ) if ( mysql_errno ( slave ) != 1180 && mysql_errno ( slave ) != 1062 ) g_warning ( " " , mysql_error ( slave ) , mysql_errno ( slave ) ) ; } while ( status == 0 ) ; return ret ; }
Run a query, whenever server comes back up, return lats resultset data
Run a query whenever server comes back up return lats resultset data
/* We will reconnect and try again,
           don't trust MySQL API reconnects */ /* There were enough reconnects to prove ourselves
           that we get disconnected while running this query,
           oh noes. */ /* The very awesome MySQL C API boilerplate */