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

[SQLite] Combining Rows like nVault


Post New Thread Reply   
 
Thread Tools Display Modes
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-08-2016 , 04:41   Re: [SQLite] Combining Rows like nVault
Reply With Quote #11

You should do some reading on database normalization. That's not the only possible way, and it's a bad one.

If you happen to normalize your database properly, I would advise against using Steam ID as a primary key. I would leave Steam ID as a unique key, but make a new auto-increment column and set it to primary key, and use that new 'database ID' for all future queries. It should make joins faster and possibly other simple queries.
If you continue having all skill levels in the same column, you will most likely run into a wall if you try to add new skills or remove old ones.

EDIT:
Also, you should (more like 'must' than 'should') use threaded queries to avoid lagspikes, especially if the database server is not hosted on the same machine.

Last edited by klippy; 09-08-2016 at 04:56.
klippy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-08-2016 , 08:37   Re: [SQLite] Combining Rows like nVault
Reply With Quote #12

We could take a stab at this using nvault_get/setarray using nvault utility. If you do not need top15 or any querying or web interaction then it should be ok.
__________________
Bugsy is offline
WAR3DM
Senior Member
Join Date: Mar 2016
Old 09-08-2016 , 15:27   Re: [SQLite] Combining Rows like nVault
Reply With Quote #13

Quote:
Originally Posted by KliPPy View Post
I would leave Steam ID as a unique key
That's the plan.

Quote:
Originally Posted by KliPPy View Post
If you continue having all skill levels in the same column, you will most likely run into a wall if you try to add new skills or remove old ones.
An easy fix.

Quote:
Originally Posted by KliPPy View Post
Also, you should (more like 'must' than 'should') use threaded queries to avoid lagspikes, especially if the database server is not hosted on the same machine.
Converting to multi-thread sounds difficult.



Quote:
Originally Posted by Bugsy View Post
We could take a stab at this using nvault_get/setarray using nvault utility. If you do not need top15 or any querying or web interaction then it should be ok.
Sounds good, I don't need top15 or web interaction.
WAR3DM is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-08-2016 , 21:27   Re: [SQLite] Combining Rows like nVault
Reply With Quote #14

Here's a simple nVault way to do it.
PHP Code:
#include <amxmodx>
#include <nvault_util>

#define MAX_PLAYERS 32

const MAX_SKILLS 9;

new 
g_PlayerSkillsMAX_PLAYERS ][ MAX_SKILLS ];
new 
g_szAuthIDMAX_PLAYERS ][ 34 ];
new 
g_Vault;

public 
plugin_init() 
{
    
register_clcmd"say setskills" "SetFakeSkills" );
    
    
g_Vault nvault_open"SkillsVault" );
}

public 
client_authorizedid )
{
    new 
iTS;
    
    
get_user_authidid g_szAuthIDid ] , charsmaxg_szAuthID[] ) );
    
    if ( 
nvault_get_arrayg_Vault g_szAuthIDid ] , g_PlayerSkillsid ] , sizeofg_PlayerSkills[] ) , iTS ) )
    {
        
server_print"Skills loaded %d %d %d %d %d %d %d %d" g_PlayerSkillsid ][ ] , g_PlayerSkillsid ][ ] ,
                                    
g_PlayerSkillsid ][ ] , g_PlayerSkillsid ][ ] ,
                                    
g_PlayerSkillsid ][ ] , g_PlayerSkillsid ][ ] ,
                                    
g_PlayerSkillsid ][ ] , g_PlayerSkillsid ][ ] ,
                                    
g_PlayerSkillsid ][ ] );
    }
    else
    {
        
server_print"No skills exist" );
    }
}

public 
client_disconnectid )
{
    
nvault_set_arrayg_Vault g_szAuthIDid ] , g_PlayerSkillsid ] , sizeofg_PlayerSkills[] ) );
}

public 
SetFakeSkillsid )
{
    for ( new 
MAX_SKILLS i++ )
        
g_PlayerSkillsid ][ ] = random_num50100 );

    
nvault_set_arrayg_Vault g_szAuthIDid ] , g_PlayerSkillsid ] , sizeofg_PlayerSkills[] ) );

__________________
Bugsy is offline
WAR3DM
Senior Member
Join Date: Mar 2016
Old 09-08-2016 , 21:42   Re: [SQLite] Combining Rows like nVault
Reply With Quote #15

Awesome, thanks for the example!

Unfortunately, it outputs "øªªªbøªªªTøªªªAøªªªdøªªª4øªªªcøªªª;øªªªPøªªª _" next to my Steam_ID.
WAR3DM is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-08-2016 , 21:56   Re: [SQLite] Combining Rows like nVault
Reply With Quote #16

Read the nvault utility thread. nvault_set stores the data in binary format so you cannot use an nvault editor app to view the data. It is stored correctly, though it will not appear that way in a viewer application.
__________________
Bugsy is offline
WAR3DM
Senior Member
Join Date: Mar 2016
Old 09-08-2016 , 22:58   Re: [SQLite] Combining Rows like nVault
Reply With Quote #17

Quote:
Originally Posted by Bugsy View Post
Read the nvault utility thread. nvault_set stores the data in binary format so you cannot use an nvault editor app to view the data. It is stored correctly, though it will not appear that way in a viewer application.
Perfect, thanks!
WAR3DM 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 03:15.


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