viewing paste LA_quickfix.c | C

Posted on the | Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
int pc_getLvlProfession(int char_id, const char* profession)        
{
    char tmp_sql[65535];    
    static Sql* mmysql_handle3 = NULL;
    char* data;
    
    unsigned int nivelProfesion = 0;
 
    //we now retain mmysql_handle3 to reuse it for next function call
    //please remenber to free it on mapserv do_final to avoid memleak
    if( mmysql_handle3 == NULL){ 
        mmysql_handle3 = Sql_Malloc();
        if( SQL_ERROR == Sql_Connect(mmysql_handle3, "user", "pass", "host", 3306, "database") )
        {   
            ShowDebug("Error al intentar hacer un pc_getLvlProfession(1)");
            exit(EXIT_FAILURE); 
        }   
    }
    sprintf(tmp_sql, "SELECT c.`nivel` FROM `charprofesiones` WHERE `char_id` = %d LIMIT 1", char_id);
 
    if ( SQL_ERROR == Sql_Query(mmysql_handle3, tmp_sql))
    {
        Sql_FreeResult(mmysql_handle3);
        return nivelProfesion;
    }
    
    if( SQL_SUCCESS != Sql_NextRow(mmysql_handle3))
    {
        Sql_FreeResult(mmysql_handle3);
        return nivelProfesion; 
    }   
    
    Sql_GetData(mmysql_handle3,  0, &data, NULL); 
    nivelProfesion = atoi(data);
    Sql_FreeResult(mmysql_handle3);
 
    return nivelProfesion;
}
 
Viewed 1401 times, submitted by lighta.