[Include] Easy SQLite: Simplyfing the usage of SQLite queries!
#1

Easy - SQLite


Overview:

I'm basically, copying most(maybe all) the information from my previous thread:

Easy MySQL 1.0 - Simplifying the usage of MySQL queries!

As this include, uses the same syntax on the functions with the difference that this include is bound to SQLite and replaces the SQL:: syntax to SL::


This include allows you to create and manage several SQLite queries in a very simplified way, it means that you no longer need to use mysql_query or anything like it. But you will be able to manage queries like you used to in previous systems like INI for example.


Some advantages of this include:

- No speed reductions in comparison to normal queries.
- Easier management of queries in comparison to normal ones.
- This include has a similar scheme to Y_INI (Thanks ****** for that)
- Ability to update large amounts of data without the need to concatenate strings, which is a pain if you have a lot of data to be updated.
- Ability to create and manage tables script side.
- You don't need a high knowledge in MySL as this include simplifies its usage to the fullest.
- Overall, you won't need to worry about setting up a lot of queries together in order to proceed with some action.


Functions:

Code:
native DB:SL::Connect(database[]);
native SL::DeleteRow(const table[], const column[], columnID, DB:database = DB:1);
native SL::DeleteRowEx(const table[], const column[], columnID[], DB:database = DB:1);
native SL::GetIntEntry(const table[], const field[], const column[], columnID, DB:database = DB:1);
native Float:SL::GetFloatEntry(const table[], const field[], const column[], columnID, DB:database = DB:1);
native SL::GetStringEntry(const table[], const field[], const column[], columnID, dest[], len = sizeof(dest), DB:database = DB:1);
native SL::GetStringEntryEx(const table[], const field[], const column[], const scolumn[], dest[], len = sizeof(dest), DB:database = DB:1)
native SL::GetIntEntryEx(const table[], const field[], const column[], scolumn[], DB:database = DB:1);
native Float:SL::GetFloatEntryEx(const table[], const field[], const column[], scolumn[], DB:database = DB:1);
native SL::CreateTable(const tablename[], DB:database = DB:1);
native SL::AddTableEntry(handle, const field[], SL::datatypes: type = SL_TYPE_INT, maxlength = 11, bool:auto_increment = false, bool:setprimary = false);
native SL::OpenTable_Read(const table[], const column[], columnID, DB:database = DB:1);
native SL::OpenTable_ReadEx(const table[], const column[], columnID[], DB:database = DB:1);
native SL::ReadInt(handle, const field[], &dest);
native SL::ReadFloat(handle, const field[], &Float:dest);
native SL::ReadString(handle, const field[], dest[], len = sizeof(dest));
native SL::OpenTable_Update(const table[], const column[], columnID, DB:database = DB:1);
native SL::OpenTable_UpdateEx(const table[], const column[], columnID[], DB:database = DB:1);
native SL::Open(SL::qtypes:type, const table[], const column[] = "", columnID = -1, DB:database = DB:1);
native SL::ToggleAutoIncrement(handle, bool:toggle);
native SL::OpenEx(SL::qtypes:type, const table[], const column[] = "", columnID[] = "", DB:database = DB:1)
native SL::UpdateIntEntry(handle, const field[], value);
native SL::UpdateFloatEntry(handle, const field[], Float:value);
native SL::UpdateStringEntry(handle, const field[], const value[], bool:use_real_escape = true);
native SL::Close(handle);
native SL::SetIntEntry(const table[], const field[], value, const column[], columnID, DB:database = DB:1);
native SL::SetIntEntryEx(const table[], const field[], value, const column[], columnID[], DB:database = DB:1);
native SL::SetFloatEntry(const table[], const field[], Float:value, const column[], columnID, DB:database = DB:1);
native SL::SetFloatEntryEx(const table[], const field[], Float:value, const column[], columnID[], DB:database = DB:1);
native SL::SetStringEntry(const table[], const field[], const value[], const column[], columnID, bool:use_real_escape = true, DB:database = DB:1);
native SL::SetStringEntryEx(const table[], const field[], const value[], const column[], columnID[], bool:use_real_escape = true, DB:database = DB:1);
native SL::OpenTable_Insert(const table[], DB:database = DB:1);
native SL::InsertIntEntry(handle, const field[], value);
native SL::InsertFloatEntry(handle, const field[], Float:value);
native SL::InsertStringEntry(handle, const field[], const value[], bool:use_real_escape = true);
native SL::ExistsTable(const tablename[], DB:database = DB:1);
native SL::CountRows(const tablename[], DB:database = DB:1);
native SL::CountTables(DB:database = DB:1);
native SL::DropTable(const tablename[], DB:database = DB:1);

v2.0

native SL::Open(SL::qtypes:type, const table[], const column[] = "", columnID = -1, DB:database = DB:1);
native SL::ToggleAutoIncrement(handle, bool:toggle);
native SL::OpenEx(SL::qtypes:type, const table[], const column[] = "", columnID[] = "", DB:database = DB:1)


The following functions replace Insert and Update functions:

native SL::WriteFloat(handle, const field[], Float:value);
native SL::WriteInt(handle, const field[], Float:value);
native SL::WriteString(handle, const field[], const value[]);


This include is mainly for people without experience with SLite as it simplifies its usage.
Login/Register example:


PHP Code:
/* 
 *  Simple register/login system using easy_sqlite.inc! 
*/ 
#include <a_samp> 
#include <easy-sqlite> 
enum p_info 
{ 
    
p_id, 
    
p_name[24], 
    
p_password[64], 
    
p_score, 
    
Float:p_posx, 
    
Float:p_posy, 
    
Float:p_posz, 
    
p_loggedin 
}; 
new 
UserInfo[MAX_PLAYERS][p_info];
#define DIALOG_LOGIN 0 
#define DIALOG_REGISTER 1 
stock ret_pName(playerid) 
{ 
    new 
name[24]; 
    
GetPlayerName(playerid, name, sizeof(name)); 
    return 
name; 
} 
main() 
{ 
     
} 
public 
OnGameModeInit() 
{ 
    
//Connecting to the database 
    
SL::Connect("server.db"); 
    
//Checking if the table 'players' exists 
     
     
    //Checking if the table 'players' exists 
    
if(!SL::ExistsTable("players")) 
    { 
        
//If not, then create a table called 'players'. 
        
new handle = SL::Open(SL::CREATE, "players"); //Opening a valid handle to create a table called 'players' 
        
SL::AddTableEntry(handle, "p_id", SL_TYPE_INT, 11, true); 
        
SL::AddTableEntry(handle, "p_name", SL_TYPE_VCHAR, 24); 
        
SL::AddTableEntry(handle, "p_password", SL_TYPE_VCHAR, 64); 
        
SL::AddTableEntry(handle, "p_score", SL_TYPE_INT); 
        
SL::AddTableEntry(handle, "p_posx", SL_TYPE_FLOAT); 
        
SL::AddTableEntry(handle, "p_posy", SL_TYPE_FLOAT); 
        
SL::AddTableEntry(handle, "p_posz", SL_TYPE_FLOAT); 
        
SL::Close(handle);//Closing the previous opened handle. 
        
print("Table 'players' was successfully created");
    } 
    else 
    {
        print(
"Table 'players' was successfully loaded");
    }
    return 
1; 
} 
public 
OnPlayerConnect(playerid) 
{ 
    
UserInfo[playerid][p_loggedin] = 0; UserInfo[playerid][p_score] = 0;  UserInfo[playerid][p_posx] = 1958.3783; 
    
UserInfo[playerid][p_posy] = 1343.1572; UserInfo[playerid][p_posz] = 15.3746;  
    if(
SL::RowExistsEx("players", "p_name", ret_pName(playerid))) //Check if the name is registered in the database 
    
{ 
        
//Get the player password and unique ID. 
        
new handle = SL::OpenEx(SL::READ, "players", "p_name", ret_pName(playerid)); 
        
SL::ReadString(handle, "p_password", UserInfo[playerid][p_password], 64); 
        
SL::ReadInt(handle, "p_id", UserInfo[playerid][p_id]); 
        
SL::Close(handle); 
        
//Show the login dialog 
        
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{0080FF}Login", "Please input your password below to log in.", "Login", "Exit"); 
    } 
    else 
    { 
        
//If not registered, then show the register DIALOG. 
        
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{0080FF}Register", "Please input a password below to register in.", "Login", "Exit"); 
    } 
    return 
1; 
} 
public 
OnPlayerSpawn(playerid) 
{ 
    
SetPlayerPos(playerid, UserInfo[playerid][p_posx], UserInfo[playerid][p_posy], UserInfo[playerid][p_posz]); 
    return 
1; 
} 
public 
OnPlayerDisconnect(playerid, reason) 
{ 
    if(
UserInfo[playerid][p_loggedin] == 1) 
    { 
        
//Save the player data. 
        
GetPlayerPos(playerid, UserInfo[playerid][p_posx], UserInfo[playerid][p_posy], UserInfo[playerid][p_posz]); 
        new 
handle = SL::Open(SL::UPDATE, "players", "p_id", UserInfo[playerid][p_id]); 
        
SL::WriteInt(handle, "p_score", GetPlayerScore(playerid)); 
        
SL::WriteFloat(handle, "p_posx", UserInfo[playerid][p_posx]); 
        
SL::WriteFloat(handle, "p_posy", UserInfo[playerid][p_posy]); 
        
SL::WriteFloat(handle, "p_posz", UserInfo[playerid][p_posz]); 
        
SL::Close(handle); 
    } 
    return 
1; 
} 
public 
OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) 
{ 
    switch(
dialogid) 
    { 
        case 
DIALOG_REGISTER: 
        { 
            if(!
response) return Kick(playerid); 
            if(
strlen(inputtext) < 5) 
            { 
                
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{0080FF}Register", "Please input a password below to register in.", "Login", "Exit"); 
                return 
1; 
            } 
            
SHA256_PassHash(inputtext, "", UserInfo[playerid][p_password], 64); 
            new 
handle = SL::Open(SL::INSERT, "players"); 
            
SL::ToggleAutoIncrement(handle, true);
            
SL::WriteString(handle, "p_name", ret_pName(playerid)); 
            
SL::WriteString(handle, "p_password", UserInfo[playerid][p_password]); 
            
SL::WriteInt(handle, "p_score", 0); 
            
SL::WriteFloat(handle, "p_posx", 0.0); 
            
SL::WriteFloat(handle, "p_posy", 0.0); 
            
SL::WriteFloat(handle, "p_posz", 0.0); 
            
UserInfo[playerid][p_id] = SL::Close(handle);//If auto_increment was set to true, SL::Close will return the ID of the inserted row. 
            
SendClientMessage(playerid, -1, "Successfully registered in!"); 
            
UserInfo[playerid][p_loggedin] = 1; 
        } 
        case 
DIALOG_LOGIN: 
        { 
            if(!
response) Kick(playerid);  
            new 
hash[64]; 
            
SHA256_PassHash(inputtext, "", hash, 64); 
            if(!
strcmp(hash, UserInfo[playerid][p_password])) 
            {  
                
//Load player data 
                
new handle = SL::Open(SL::READ, "players", "p_id", UserInfo[playerid][p_id]); 
                
SL::ReadInt(handle, "p_score", UserInfo[playerid][p_score]); 
                
SL::ReadFloat(handle, "p_posx", UserInfo[playerid][p_posx]); 
                
SL::ReadFloat(handle, "p_posy", UserInfo[playerid][p_posy]); 
                
SL::ReadFloat(handle, "p_posz", UserInfo[playerid][p_posz]); 
                
SL::Close(handle);//You must close the handle. 
                
SetPlayerScore(playerid, UserInfo[playerid][p_score]); 
                
UserInfo[playerid][p_loggedin] = 1; 
                
SendClientMessage(playerid, -1, "Successfully logged in!"); 
                 
            } 
            else  
            { 
                
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{0080FF}Login", "Please input your password below to log in.", "Login", "Exit"); 
            } 
        } 
    } 
    return 
1; 
} 
Constants:

Code:
SL_TYPE_INT //Describes an integer
SL_TYPE_VCHAR //Describes a varchar
SL_TYPE_FLOAT //Describes a float
SL_INVALID_HANDLE //Describes an invalid handle
SL::UPDATE //Describes an update handle
SL::INSERT //Describes an insert handle
SL::READ //Describes a read handle
SL::CREATE //Describes a handle to create a table


Note:

Functions like:

Code:
native SL::CreateTable(const tablename[], connectionHandle = 1);
native SL::OpenTable_Read(const table[], const column[], columnID, connectionHandle = 1);
native SL::OpenTable_ReadEx(const table[], const column[], columnID[], connectionHandle = 1);
native SL::OpenTable_Update(const table[], const column[], columnID, connectionHandle = 1);
native SL::OpenTable_UpdateEx(const table[], const column[], columnID[], connectionHandle = 1);
native SL::OpenTable_Insert(const table[], connectionHandle = 1);
Were replaced to SL::Open | SL:OpenEx accordingly in v2.0 (The above functions are still used internally).

Creating a table:


PHP Code:
new handle = SL::Open(SL::CREATE, "players"); //Opening a valid handle to create a table called 'players'
SL::AddTableEntry(handle, "p_id", SL_TYPE_INT, 11, true);
SL::AddTableEntry(handle, "p_name", SL_TYPE_VCHAR, 24);
SL::AddTableEntry(handle, "p_password", SL_TYPE_VCHAR, 64);
SL::AddTableEntry(handle, "p_score", SL_TYPE_INT);
SL::AddTableEntry(handle, "p_posx", SL_TYPE_FLOAT);
SL::AddTableEntry(handle, "p_posy", SL_TYPE_FLOAT);
SL::AddTableEntry(handle, "p_posz", SL_TYPE_FLOAT);
SL::Close(handle);//Closing the previous opened handle. 
Inserting data:


PHP Code:
new handle = SL::Open(SL::INSERT, "players");
SL::ToggleAutoIncrement(handle, true);//Toggles auto increment, SL::Close will return the ID of the latest inserted ID
SL::WriteString(handle, "p_name", ret_pName(playerid));
SL::WriteString(handle, "p_password", UserInfo[playerid][p_password]);
SL::WriteInt(handle, "p_score", 0);
SL::WriteFloat(handle, "p_posx", 0.0);
SL::WriteFloat(handle, "p_posy", 0.0);
SL::WriteFloat(handle, "p_posz", 0.0);
UserInfo[playerid][p_id] = SL::Close(handle);//Returns the ID of the latest inserted ID 
Updating data:

PHP Code:
new handle = SL::Open(SL::UPDATE, "players", "p_id", UserInfo[playerid][p_id]);
SL::WriteInt(handle, "p_score", GetPlayerScore(playerid));
SL::WriteFloat(handle, "p_posx", UserInfo[playerid][p_posx]);
SL::WriteFloat(handle, "p_posy", UserInfo[playerid][p_posy]);
SL::WriteFloat(handle, "p_posz", UserInfo[playerid][p_posz]);
SL::Close(handle); 

"Reading"data:


PHP Code:
new handle = SL::Open(SL::READ, "players", "p_id", UserInfo[playerid][p_id]);
SL::ReadInt(handle, "p_score", UserInfo[playerid][p_score]);
SL::ReadFloat(handle, "p_posx", UserInfo[playerid][p_posx]);
SL::ReadFloat(handle, "p_posy", UserInfo[playerid][p_posy]);
SL::ReadFloat(handle, "p_posz", UserInfo[playerid][p_posz]);
SL::Close(handle);//You must close the handle. 
In order to run the action, you must use:
Code:
native SL::Close(handle)
- If you want to update a lot of data of a single shot, then use SL::UPDATE.

Download:

Easy SQLite v2.0


You can comment any suggestions, bugs, typos or feedback below.
Reply
#2

So now we can switch from MySQL to SQLite with just chaning the SQL to SL?
Reply
#3

Exactly.
Reply
#4

Quote:
Originally Posted by ThePhenix
View Post
Exactly.
Great job
Reply
#5

Hello, I'm wondering how you open such simple queries using this include, I've bumped into a little problem.


pawn Code:
SOLUTION: You'll only need this query when opening such simple tabes. (SELECT * FROM serverconfig)  
        ERROR: [SQLITE] - ERROR: (SL::OpenTable) No format has been entered. Format example: (pID)


pawn Code:
hook OnGameModeInit()
{
    if(!SL::ExistsTable(CONFIG_TABLE))
    {
        new tmp_handle;

        tmp_handle = SL::Open(SL::CREATE, CONFIG_TABLE);
        SL::AddTableEntry(tmp_handle, COL_ATTSKIN, SL_TYPE_INT);
        SL::AddTableEntry(tmp_handle, COL_DEFSKIN, SL_TYPE_INT);
        SL::AddTableEntry(tmp_handle, COL_ATTSUBSKIN, SL_TYPE_INT);
        SL::AddTableEntry(tmp_handle, COL_DEFSUBSKIN, SL_TYPE_INT);
        SL::AddTableEntry(tmp_handle, COL_REFEREESKIN, SL_TYPE_INT);
        SL::AddTableEntry(tmp_handle, COL_MAXPING, SL_TYPE_INT);
        SL::AddTableEntry(tmp_handle, COL_MAXPACKET, SL_TYPE_FLOAT);
        SL::Close(tmp_handle);

        tmp_handle = SL::Open(SL::INSERT, CONFIG_TABLE);
        SL::WriteInt(tmp_handle, COL_ATTSKIN, 170);
        SL::WriteInt(tmp_handle, COL_DEFSKIN, 177);
        SL::WriteInt(tmp_handle, COL_ATTSUBSKIN, 53);
        SL::WriteInt(tmp_handle, COL_DEFSUBSKIN, 230);
        SL::WriteInt(tmp_handle, COL_REFEREESKIN, 51);
        SL::WriteInt(tmp_handle, COL_MAXPING, 300);
        SL::WriteFloat(tmp_handle, COL_MAXPACKET, 1.0);
        SL::Close(tmp_handle);

        AddDebug("DATABASE", ""CONFIG_TABLE" has been successfully created.");
    }
    else
    {
        /*
        SOLUTION: You'll only need this query when opening such simple tabes. (SELECT * FROM serverconfig)  
        ERROR: [SQLITE] - ERROR: (SL::OpenTable) No format has been entered. Format example: (pID)

        new tmp_handle = SL::Open(SL::READ, CONFIG_TABLE);
        SL::ReadInt(tmp_handle, COL_ATTSKIN, serverData[attackerSkin]);
        SL::ReadInt(tmp_handle, COL_DEFSKIN, serverData[deffenderSkin]);
        SL::ReadInt(tmp_handle, COL_ATTSUBSKIN, serverData[attackerSubSkin]);
        SL::ReadInt(tmp_handle, COL_DEFSUBSKIN, serverData[deffenderSubSkin]);
        SL::ReadInt(tmp_handle, COL_REFEREESKIN, serverData[refereeSkin]);
        SL::ReadInt(tmp_handle, COL_MAXPING, serverData[maxping]);
        SL::ReadFloat(tmp_handle, COL_MAXPACKET, serverData[maxpacket]);
        SL::Close(tmp_handle);*/


        AddDebug("DATABASE", ""CONFIG_TABLE" has successfully loaded.");
    }
}
EDIT:

Temporary Fix, until the author replies and makes an update.

pawn Code:
stock SL::OpenTable_Read(const table[], const column[], columnID, DB:database = DB:1)
{
    if(DB:database == DB:0)
    {
        SL_Error("(SL::OpenTable) No active connection.");
        return SL_INVALID_HANDLE;
    }
    if(strlen(table) > SL_MAX_TABLE_NAME)
    {
        SL_Error("(SL::OpenTable) Invalid table length.");
        return SL_INVALID_HANDLE;
    }
    /*if(column[0] == '\0')
    {
        SL_Error("(SL::OpenTable) No format has been entered. Format example: (pID)");
        return SL_INVALID_HANDLE;
    }*/

    new
        i = SL::GetFreeUpdatingSlot()
    ;
    if(i == SL_INVALID_HANDLE)
    {
        return SL_INVALID_HANDLE;
    }
    SL::upd_type[i] = SL::READ;
    SL::database[i] = DB:database;

    if(column[0] == '\0' || !columnID)
    {
        format(SL::upd_form, sizeof(SL::upd_form), "SELECT * FROM `%s`", table);
        SL::ReadCache[i] = db_query(DB:database, SL::upd_form);
    }
    else
    {
        format(SL::upd_form, sizeof(SL::upd_form), "SELECT * FROM `%s` WHERE `%s` = '%d' ", table, column, columnID);
        SL::ReadCache[i] = db_query(DB:database, SL::upd_form);
    }
    SL::upd_datacount[i] = 0;
    if((SL::ReadCache[i]))
    {
        SL::UsedHandle[i] = true;
        return i;
    }
    return SL_INVALID_HANDLE;
}
Reply
#6

Added in v2.0 - Transactions:

PHP Code:
SL::Begin(DB:database = DB:1)
SL::Commit(DB:database = DB:1) 
Example code:

PHP Code:
new DB:MyDB;
main()
{
    
MyDB = SL::Connect("test.db");
    new 
handle = SL::Open(SL::CREATE, "example", "", -1, MyDB);
    
SL::AddTableEntry(handle, "fooA", SL_TYPE_INT, 11, true); 
    
SL::AddTableEntry(handle, "fooB", SL_TYPE_VCHAR, 24); 
    
SL::AddTableEntry(handle, "fooC", SL_TYPE_FLOAT); 
    
SL::Close(handle);
    
    
SL::Begin(MyDB);
    for(new 
i; i != 10000; i++)
    {
        
handle = SL::Open(SL::INSERT, "example", "", -1, MyDB); 
        
SL::WriteString(handle, "fooB", "SomeB");  
        
SL::WriteFloat(handle, "fooC", 0.0); 
        
SL::Close(handle);
    }
    
SL::Commit(MyDB);
} 
Reply
#7

goob job.
Reply
#8

Hi the accounts won't save in the database, It creates the database but it doesn't save the account. What am I doing wrong?

Register dialog
PHP Code:
if(dialogid == 5)
    {
        if(!
response) return Kick(playerid);
        if(
response)
        {
            new 
oof[32];
            
GetPVarString(playerid, "confirmpass", oof, 32);
            if(
strcmp(inputtext, oof, true) == 0)
            {
                
SHA256_PassHash(inputtext, "", PlayerInfo[playerid][pPass], 64);
                new 
handle = SL::Open(SL::INSERT, "players");
                
SL::ToggleAutoIncrement(handle, true);
                
SL::WriteString(handle, "Name", GetName(playerid));
                
SL::WriteString(handle,"Password",PlayerInfo[playerid][pPass]);
                
SL::WriteInt(handle,"Cash",0);
                
SL::WriteInt(handle,"Score",0);
                
SL::WriteInt(handle,"Admin",0);
                
SL::WriteInt(handle,"Helper",0);
                
SL::WriteInt(handle,"Kills",0);
                
SL::WriteInt(handle,"Deaths",0);
                
SL::WriteInt(handle,"Skin",0);
                
SL::WriteInt(handle,"Banned", 0);
                
SL::WriteString(handle, "BannedReason", "N/A");
                
SL::WriteString(handle, "BannedBy", "N/A");
                
SL::WriteString(handle, "BannedIP", "N/A");
                
SL::WriteInt(handle, "HitsoundToggle", 0);
                
SL::WriteInt(handle, "Donator", 0);
                
SL::WriteInt(handle, "DonatorSkin", 0);
                
SL::WriteInt(handle, "ExclusiveSkin", 0);
                   
SL::WriteInt(handle, "UnlockedSkin1", 0);
                
SL::WriteInt(handle, "UnlockedSkin2", 0);
                
SL::WriteInt(handle, "UnlockedSkin3", 0);
                
SL::WriteInt(handle, "UnlockedSkin4", 0);
                
SL::WriteInt(handle, "UnlockedSkin5", 0);
                
SL::WriteInt(handle, "UnlockedSkin6", 0);
                
SL::WriteInt(handle, "UnlockedSkin7", 0);
                
SL::WriteInt(handle, "UnlockedSkin8", 0);
                
SL::WriteInt(handle, "UnlockedSkin9", 0);
                
SL::WriteInt(handle, "UnlockedSkin10", 0);
                
SL::WriteInt(handle, "UnlockedSkin11", 0);
                
SL::WriteInt(handle, "UnlockedSkin12", 0);
                
SL::WriteString(handle, "pClan", "None");
                
SL::WriteInt(handle, "pClanID", 0);
                
SL::WriteInt(handle, "pLeader", 0);
                
SL::WriteInt(handle, "Mutes", 0);
                
SL::WriteInt(handle, "Bans", 0);
                
SL::WriteInt(handle, "Kicks", 0);
                
SL::WriteInt(handle, "Warns", 0);
                
SL::WriteInt(handle, "pTitle", 0);
                
SL::WriteString(handle, "CTitle", "");
                
SL::WriteInt(handle, "Headshots", 0);
                
SL::WriteInt(handle, "Achievement1", 0);
                
SL::WriteInt(handle, "Achievement2", 0);
                
SL::WriteInt(handle, "Achievement3", 0);
                
SL::WriteInt(handle, "Achievement4", 0);
                
SL::WriteInt(handle, "Achievement5", 0);
                
PlayerInfo[playerid][pID] = SL::Close(handle);
                
SetPlayerColor(playerid, 0xBAFFFDFF);
                  
InLobby[playerid] = 1;
                  
SaveAccountStats(playerid);
                  
IsLogged[playerid] = 1;
                  
TogglePlayerSpectating(playerid, 0);
                  
SetPlayerClassPosition(playerid);
                  new 
string[128];
                  
format(string, sizeof(string), "~ %s has registered a new account. Welcome to the server!", GetName(playerid));
                  
SendClientMessageToAll(COLOR_GREEN, string); 
Saving the account.
PHP Code:
public SaveAccountStats(playerid)
{
//   if(IsLogged[playerid] == 1)
    
new handle = SL::Open(SL::UPDATE, "players", "ID", PlayerInfo[playerid][pID]);
    
SL::WriteInt(handle, "Cash", GetPlayerCash(playerid));
    
SL::WriteInt(handle, "Score", GetPlayerScore(playerid));
    
SL::WriteInt(handle, "Admin", PlayerInfo[playerid][pAdmin]);
    
SL::WriteInt(handle, "Kills",PlayerInfo[playerid][pKills]);
    
SL::WriteInt(handle, "Deaths",PlayerInfo[playerid][pDeaths]);
    
SL::WriteInt(handle, "Banned", PlayerInfo[playerid][pBanned]);
    
SL::WriteInt(handle, "BannedReason", PlayerInfo[playerid][pBanReason]);
    
SL::WriteInt(handle, "BannedBy", PlayerInfo[playerid][pBannedBy]);
    
SL::WriteInt(handle, "BannedIP", PlayerInfo[playerid][pBannedIP]);
    
SL::WriteInt(handle, "HitsoundToggle", PlayerInfo[playerid][pHitsound]);
    
SL::WriteInt(handle, "Donator", PlayerInfo[playerid][pDonator]);
    
SL::WriteInt(handle, "DonatorSkin", PlayerInfo[playerid][pDonatorSkin]);
    
SL::WriteInt(handle, "ExclusiveSkin", PlayerInfo[playerid][pExclusiveSkin]);
    
SL::WriteInt(handle, "UnlockedSkin1", PlayerInfo[playerid][UnlockedSkin1]);
    
SL::WriteInt(handle, "UnlockedSkin2", PlayerInfo[playerid][UnlockedSkin2]);
    
SL::WriteInt(handle, "UnlockedSkin3", PlayerInfo[playerid][UnlockedSkin3]);
    
SL::WriteInt(handle, "UnlockedSkin4", PlayerInfo[playerid][UnlockedSkin4]);
    
SL::WriteInt(handle, "UnlockedSkin5", PlayerInfo[playerid][UnlockedSkin4]);
    
SL::WriteInt(handle, "UnlockedSkin6", PlayerInfo[playerid][UnlockedSkin4]);
    
SL::WriteInt(handle, "UnlockedSkin7", PlayerInfo[playerid][UnlockedSkin4]);
    
SL::WriteInt(handle, "UnlockedSkin8", PlayerInfo[playerid][UnlockedSkin4]);
    
SL::WriteInt(handle, "UnlockedSkin9", PlayerInfo[playerid][UnlockedSkin4]);
    
SL::WriteInt(handle, "UnlockedSkin10", PlayerInfo[playerid][UnlockedSkin4]);
    
SL::WriteInt(handle, "UnlockedSkin11", PlayerInfo[playerid][UnlockedSkin4]);
    
SL::WriteInt(handle, "UnlockedSkin12", PlayerInfo[playerid][UnlockedSkin4]);
    
SL::WriteInt(handle, "pClan", PlayerInfo[playerid][pClan]);
    
SL::WriteInt(handle, "pClanID", PlayerInfo[playerid][pClanID]);
    
SL::WriteInt(handle, "pLeader", PlayerInfo[playerid][pLeader]);
    
SL::WriteInt(handle, "Mutes", PlayerInfo[playerid][pMutes]);
    
SL::WriteInt(handle, "Bans", PlayerInfo[playerid][pBans]);
    
SL::WriteInt(handle, "Kicks", PlayerInfo[playerid][pKicks]);
    
SL::WriteInt(handle, "Warns", PlayerInfo[playerid][pWarns]);
    
SL::WriteInt(handle, "CTitle", PlayerInfo[playerid][CTitle]);
    
SL::WriteInt(handle, "Headshots", PlayerInfo[playerid][Headshots]);
    
SL::WriteInt(handle, "Achievement1", PlayerInfo[playerid][Achievement1]);
    
SL::WriteInt(handle, "Achievement2", PlayerInfo[playerid][Achievement2]);
    
SL::WriteInt(handle, "Achievement3", PlayerInfo[playerid][Achievement3]);
    
SL::WriteInt(handle, "Achievement4", PlayerInfo[playerid][Achievement4]);
    
SL::WriteInt(handle, "Achievement5", PlayerInfo[playerid][Achievement5]);
    
SL::Close(handle);
    return 
1;
} 
The database
PHP Code:
    SL::Connect("rdm.db");
    if(!
SL::ExistsTable("players"))
    {
        new 
handle = SL::Open(SL::CREATE, "players");
        
SL::AddTableEntry(handle, "ID", SL_TYPE_INT, 11, true);
        
SL::AddTableEntry(handle, "Name", SL_TYPE_VCHAR, 24);
        
SL::AddTableEntry(handle, "Password", SL_TYPE_VCHAR, 64);
        
SL::AddTableEntry(handle, "Cash", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "Score", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "Admin", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "Kills", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "Deaths", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "Banned", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "BannedBy", SL_TYPE_VCHAR, 24);
        
SL::AddTableEntry(handle, "BanReason", SL_TYPE_VCHAR, 128);
        
SL::AddTableEntry(handle, "BannedIP", SL_TYPE_VCHAR, 16);
        
SL::AddTableEntry(handle, "HitsoundToggle", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "Donator", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "DonatorSkin", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "ExclusiveSkin", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "UnlockedSkin1", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "UnlockedSkin2", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "UnlockedSkin3", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "UnlockedSkin4", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "UnlockedSkin5", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "UnlockedSkin6", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "UnlockedSkin7", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "UnlockedSkin8", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "UnlockedSkin9", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "UnlockedSkin10", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "UnlockedSkin11", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "UnlockedSkin12", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "pClan", SL_TYPE_VCHAR, 64);
        
SL::AddTableEntry(handle, "pClanID", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "pLeader", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "Mutes", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "Bans", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "Kicks", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "Warns", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "CTitle", SL_TYPE_VCHAR, 128);
        
SL::AddTableEntry(handle, "Headshots", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "Achievement1", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "Achievement2", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "Achievement3", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "Achievement4", SL_TYPE_INT);
        
SL::AddTableEntry(handle, "Achievement5", SL_TYPE_INT);
        
SL::Close(handle);
        print(
"Table 'players' was successfully created");
    }
    else
    {
        print(
"Table 'players' was successfully loaded");
    } 
Reply
#9

This include is old but you had a mistake in your include.


Wrong.
Code:
stock SL::DeleteRowEx(const table[], const column[], columnID[], DB:database = DB:1)
{
	format(SL::upd_form, sizeof(SL::upd_form), "DELETE FROM `%s` WHERE `%s`='sd' ", table, column, columnID);
	db_free_result(db_query(DB:database, SL::upd_form));
	return 1;
}
Right.
Code:
stock SL::DeleteRowEx(const table[], const column[], columnID[], DB:database = DB:1)
{
	format(SL::upd_form, sizeof(SL::upd_form), "DELETE FROM `%s` WHERE `%s`='%q' ", table, column, columnID);
	db_free_result(db_query(DB:database, SL::upd_form));
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)