MySQL Question important.
#1

I have a cellphone system so I decided to make a mailbox.
my question is if the code is good to use, and not taking to much memory.
this is my code:

pawn Код:
#define MAX_PLAYER_SMS 5

enum SMS_INFO
{
    smsID,
    smsOwner[256],
    smsInfo[256],
    smsFrom,
    smsOn,
}
new SmsInfo[MAX_PLAYER_SMS][MAX_PLAYERS][SMS_INFO];

CMD:smsbox(playerid, params[])
{
    new query[256];
    format(query, sizeof(query), "SELECT * FROM `smslog` WHERE `name` = '%s'", GetName(playerid));
    mysql_function_query(dbHandle, query, true, "DisplaySMSLog", "i", playerid);
    return 1;
}

CMD:deletesms(playerid, params[])
{
    new query[256], smsslot;
    if(sscanf(params,"d",smsslot)) return SyntaxMSG(playerid, "/deletesms [sms-slot] (/smsbox)");
    if(!SmsInfo[smsslot][playerid][smsOn]) return SCM(playerid, -1, "Invalid SMS slot id.");
    format(query, sizeof(query), "DELETE FROM `smslog` WHERE `id` = %d", SmsInfo[smsslot][playerid][smsID]);
    mysql_function_query(dbHandle, query, true, "OnPlayerDeleteSMS", "ii", playerid, smsslot);
    return 1;
}

forward OnPlayerDeleteSMS(playerid, smsslot);
public OnPlayerDeleteSMS(playerid, smsslot)
{
    SmsInfo[smsslot][playerid][smsOn] = 0;
    return 1;
}

forward DisplaySMSLog(playerid);
public DisplaySMSLog(playerid)
{
    new rows, fields, str[256], temp[128], total = 0;
    cache_get_data(rows, fields);
    if(!rows) return SCM(playerid, COLOR_YELLOWG, "You have no SMS's in your smsbox.");
    while(total < rows)
    {
        cache_get_row(total, 0, temp), SmsInfo[total][playerid][smsID] = strval(temp);
        cache_get_row(total, 1, SmsInfo[total][playerid][smsOwner]);
        cache_get_row(total, 2, temp), SmsInfo[total][playerid][smsFrom] = strval(temp);
        cache_get_row(total, 3, SmsInfo[total][playerid][smsInfo]);
        SmsInfo[total][playerid][smsOn] = 1;
        format(str, sizeof(str), "SMS %d: from %d, %s.", total, SmsInfo[total][playerid][smsFrom], SmsInfo[total][playerid][smsInfo]);
        SCM(playerid, COLOR_YELLOWG, str);
        total++;
    }
    return 1;
}

stock AddSMSToMySQL(playerid, fromnumber, info[])
{
    new Query[500];
    format(Query, sizeof(Query), "INSERT INTO `smslog` (name, fromnumber, info) VALUES('%s', %d, '%s')",GetName(playerid), fromnumber, info);
    mysql_function_query(dbHandle, Query, true, "", "");
    return 1;
}
Reply
#2

Um... you're using threaded queries, so... you have [almost] nothing to worry about.
Reply
#3

i need a command to remove sms from exact slot.. i've no idea how to do it
Reply
#4

Well firstly why use 256 cells for chat when it can only hold 128?
https://sampforum.blast.hk/showthread.php?tid=55261
Reply
#5

I wonder why you are using slots in the first place. Just load the data from the database when you need it. Copying the data to variables in the gamemode serves no purpose at all.
Reply
#6

but if I won't load into a variables, there will be no way to delete an SMS in exact slot
Reply
#7

bump
Reply
#8

someone?
Reply
#9

Quote:
Originally Posted by PaulDinam
Посмотреть сообщение
but if I won't load into a variables, there will be no way to delete an SMS in exact slot
... load just the SMS ID into a variable?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)