Raised This Month: $51 Target: $400
 12% 

[ANY] DB++ (Optimized way to use queries)


Post New Thread Reply   
 
Thread Tools Display Modes
Author
jakesmokie
Member
Join Date: Aug 2016
Plugin ID:
5342
Plugin Version:
1.0
Plugin Category:
Technical/Development
Plugin Game:
Any
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    Old 09-07-2016 , 06:24   [ANY] DB++ (Optimized way to use queries)
    Reply With Quote #1

    Hello! Want to release my new plugin, which will help you to optimize network oriented queries.

    Installation:
    1. Put folder from `dbpp.zip` to root folder of game (Example: tf2/ csgo/).
    2. Add in databases.cfg this one:
    PHP Code:
    "dbpp"
    {
        
    "driver"    "mysql"
        "host"    "your_ip"
        "database"    "your_db"
        "user"    "your_user"
        "pass"    "your_password"

    3. Test and write your own plugins!

    How to use this API?
    1. Analyze this example
    PHP Code:
    #include <sourcemod>
    #include <dbplusplus>

    #pragma semicolon 1
    #pragma newdecls required

    public Plugin myinfo 
    {
        
    name "[DB++] Test Plugin",
        
    author "Jake",
        
    description "-",
        
    version "0.1 beta",
        
    url "http://ezplay.pro/"
    };

    /**
     * We're creating datapack 
     *    to identify query
     *    and send some data
     **/
    DataPack gDataPackConnections[MAXPLAYERS];
        
    public 
    void OnPluginStart()
    {
        
    /* Create datapack for each player */
        
    for (int i 1<= MaxClientsi++)
            
    gDataPackConnections[i] = new DataPack();
    }

    /* Player has joined and transaction is ready */
    public void DBPP_PlayerJoin(int iClient, const char[] sSteamTransaction hTransaction)
    {
        
    /* We want to send nick, so let get it */
        
    char sNick[64];
        
    GetClientName(iClientsNick64);
        
        
    ReplaceString(sNick64"`",     "");
        
    ReplaceString(sNick64"'",     "");
        
    ReplaceString(sNick64"\"",     "");

        
    /* Time of connection */
        
    int iTime GetTime();
        
        
    /* Formatting query */
        
    char sQuery[256];
        
        
    /* Just insert data in MySQL */
        /* For Example: */
        
        /* INSERT INTO `table` (`field`) VALUES (`data`); */
        
    FormatEx(sQuery256"INSERT INTO `connections` (`steam`, `nick`, `time`) VALUES ('%s', '%s', '%d');"
            
    sSteamsNickiTime);

        
    /* Clearing data from datapack */
        
    gDataPackConnections[iClient].Reset(true);
        
        
    /* Writing new data */
        
    gDataPackConnections[iClient].WriteString(sNick);
        
    gDataPackConnections[iClient].WriteCell(iTime);
        
    gDataPackConnections[iClient].WriteString(sQuery);
        
        
    /* Ok, we are ready to */
        /* add query in transaction */
        
        /* 1st param - query */
        /* 2nd param - datapack */
        
    hTransaction.AddQuery(sQuerygDataPackConnections[iClient]);
    }

    /* Ok, we have a result, so let's log it out */
    public void DBPP_PlayerJoin_Results(int iClient, const char[] sSteamint iQueryDBResultSet hResultSetDataPack dPack)
    {
        
    LogConnection(iClientdPackfalse);
        
        
    /* Don't forget: */
        /* Result sets will be deleted automaticly */
    }

    /* Something goes wrong, but we still can log data */
    public void DBPP_PlayerJoin_Fail(int iClient, const char[] sSteamint iFailedQueryDataPack dPack)
    {
        
    LogConnection(iClientdPacktrue);
    }

    void LogConnection(int iClientDataPack dPackbool bFailure)
    {
        
    /* Checking for needed query */
        /* If false - it's not our query */
        
    if (dPack != gDataPackConnections[iClient])
            return;
        
        
    /* Reset position in datapack */
        
    dPack.Reset();
        
        
    /* Read data and log it. Simple. */
        
    char sNick[64];
        
    dPack.ReadString(sNick64);
            
        
    int iTime dPack.ReadCell();
        
        
    char sTime[32];
        
    FormatTime(sTime32"%d/%m/%y %H:%M:%S"iTime);
        
        
    LogMessage("[DB++] Player %s joined at %s"sNicksTime);
        
        
    /* Our query was failure */
        
    if (bFailure == true)
        {
            
    char sQuery[256];
            
    dPack.ReadString(sQuery256);
        
            
    LogMessage("[DB++] Failed query: %s"sQuery);
        }

    2. Write your own (Tutorial will be later )

    You can change config source code of API
    PHP Code:
    // Config name in `databases.cfg`
    #define CONFIG_NAME "dbpp"

    // Charset, which is used in database
    //  (be careful when you change it)
    #define CONFIG_CHARSET "utf8"

    // Auth ID
    //  (change if you know what you do)
    #define CONFIG_AUTHID AuthId_Steam2

    // Auth ID Length
    //  (not necessary to change it)
    #define CONFIG_STEAMLENGTH 32

    // Database Priorities
    //   (please don't set all to high if you don't need)
    #define CONFIG_DBPRIO_JOIN     DBPrio_Normal
    #define CONFIG_DBPRIO_LEAVE DBPrio_Normal
    #define CONFIG_DBPRIO_EVENT DBPrio_Low

    // Comment line below if loading of player data on plugin start is not needed
    #define CONFIG_LOAD_PLAYERS_ON_INIT 
    Attached Files
    File Type: zip dbpp.zip (18.6 KB, 174 views)

    Last edited by jakesmokie; 09-07-2016 at 06:33.
    jakesmokie is offline
    Neuro Toxin
    Veteran Member
    Join Date: Oct 2013
    Location: { closing the void; }
    Old 09-07-2016 , 19:46   Re: [ANY] DB++ (Optimized way to use queries)
    Reply With Quote #2

    I dont think this optimises much.

    I see problems in your example.

    1. You dont escape your strings properly
    2. Use of datapacks is crazy and not well thought out
    3. Use a 64bit steamid and have your database table as long int rather than string lookups
    4. Where's a callback, most ppl need to callback to process big threaded chains
    __________________

    Last edited by Neuro Toxin; 09-07-2016 at 19:48.
    Neuro Toxin is offline
    Reply



    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 07:08.


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