Raised This Month: $ Target: $400
 0% 

LAG caused by SQL


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
abubhz
Junior Member
Join Date: Aug 2009
Old 08-11-2009 , 20:41   Re: LAG caused by SQL
Reply With Quote #2

Code:
public bool:FMAPI_GetReggedInformation(const STEAMID[], const bool:LOOKFORGROUPS, &forum_account_id, forumname[32], groups[], const MAX_GROUPS) { 
    // Each FtPplugin implements this part 
    // Paramaters: byref, set the data to be returned back to the FM plugin... 
    // $return: bool, regged or not 
 
    new Sql:sql 
    if (!fm_db_connect(sql)) { 
        return false 
    } 
 
    const SIZE = 512 
    new query[SIZE + 1] 
 
    format(query, SIZE, "SELECT `%s`, `%s` FROM `%s` WHERE `%s` = ^"%%%s%%^" LIMIT 1", g_FIELD_USERS_NAME, g_FIELD_USERS_USERID, g_TABLE_USERS, g_FIELD_USERS_STEAMID, STEAMID) 
    server_print("query: %s", query) 
 
    //server_print("[%s] Query: ^"%s^"", PLUGINNAME, query) 
    new Result:result = dbi_query(sql, query) 
 
    if (result < RESULT_NONE) { 
        new sqlerror[256] 
        dbi_error(sql, sqlerror, 255) 
        log_amx("Error: %s", sqlerror) 
        dbi_close(sql) 
        return false 
    } 
    else if (result == RESULT_NONE) { 
        dbi_close(sql) 
        return false 
    } 
    // else... 
 
    if (!dbi_nextrow(result)) { 
        //log_amx("%s just doesn't exist in forum database (dbi_nextrow() failed).", authid) 
        //server_print("[%s] %s just doesn't exist in phpBB database (dbi_nextrow() failed) Number of rows: %d", PLUGINNAME, authid, dbi_num_rows(result)) 
        dbi_free_result(result) 
        dbi_close(sql) 
        return false // should have been a result, but nextrow somehow failed (because the set succeeded, but is empty?) 
    } 
 
    // Get name 
    dbi_field(result, 1, forumname, 31) 
 
    // Get userid 
    new celldata[64] 
    dbi_field(result, 2, celldata, 63) 
    forum_account_id = str_to_num(celldata) 
 
    dbi_free_result(result) 
 
    // Get groups 
    groups[0] = 0 
 
    // Say goodbye if we shouldn't look for groups... 
    if (!LOOKFORGROUPS) { 
        dbi_close(sql) 
        return true 
    } 
 
    // PHPBB has its own reference table of the sort many<->many (groups<->users) 
    format(query, SIZE, "SELECT `group_id` FROM `phpbb_user_group` WHERE `user_id` = %d && `user_pending` = 0", forum_account_id) 
 
    result = dbi_query(sql, query) 
    if (result < RESULT_NONE) { 
        new error[256] 
        dbi_error(sql, error, 255) 
        log_amx("[%s] ERROR - while quering SQL server for %s's group memberships: %s", PLUGINNAME, forumname, error) 
        dbi_close(sql) 
        return true 
    } 
    else if (result == RESULT_NONE) { 
        // No memberships at all... which should be odd? 
        log_amx("[%s] ERROR - while quering SQL server for %s's group memberships! Membership count was ZERO while at least a few was expected...", PLUGINNAME, forumname) 
        dbi_close(sql) 
        return true 
    } 
    // else... 
 
    new i = 0 
    while (i < MAXGROUPS && dbi_nextrow(result)) 
        groups[i++] = dbi_field(result, 1) 
 
    dbi_free_result(result) 
 
    dbi_close(sql) 
 
    return true 
}

Last edited by abubhz; 08-11-2009 at 20:52.
abubhz is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:18.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode