Raised This Month: $32 Target: $400
 8% 

[DB] Database Manager


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 08-25-2007 , 17:18   [DB] Database Manager
Reply With Quote #1

Database manager

Description:
Different plugins may require different tables to get user informations, like XP, level, money, kills, deaths and bla bla bla... This plugin/stock automatically select info from table, create columns where necessary and makes it easy for people that want to use the database

How it works
Database manager detects all columns from the sm_users. Plugins can enable,disable the selecting of each column, or create a new column if needed.

Cvars
  • sm_db_config (deafult: "default") - The connection DB manager will use
  • sm_db_persit (deafult: "1") - Set to true to use persistant connection
  • sm_db_autolite (deafult: "1") - If the DB does not exist, SQLite will be used

Installation:
  • MySQL
    First, go to the file addons\sourcemod\configs\databases.cfg , and edit the "default" connection to your needs, it shouldn't be complicated, It should end up looking something like this:
    PHP Code:
    "default"
        
    {
            
    "driver"        "default"
            "host"            "localhost"
            "database"        "sm"
            "user"            "root"
            "pass"            ""
            
    //"timeout"            "0"
            //"port"            "0"
        

    And the leave the plugin to do the rest
    -----------------------------------
  • SQLite
    Change the cvar sm_db_config to "storage-local"
    and make sure that in addons\sourcemod\configs\databases.cfg this exists:
    PHP Code:
        "storage-local"
        
    {
            
    "driver"            "sqlite"
            "database"            "sourcemod-local"
        

  • Put a_mysql.smx file into your /addons/sourcemod/plugins folder, you can easily get the a_mysql.smx file by clicking at "Get Plugin" at the end of this message


FAQ:
  • I am getting an error "Can't connect to local MySQL server through socket '/tmp/mysql.sock'"
    • If you have acess to root in your linux computer, execute this in shell "ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock"



Example
See next post

ChangeLog:
  • August 25, 2007
    • Initial Release
    • Fixed Float Adding
    • Started Lock tables
    • Removed all FastQueries
  • August 26, 2007
    • Removed all the connecting/disconecting
    • Added cvars
    • Made it a lot user to use
  • August 27, 2007
    • Added SQLite support
    • Started using atd_array, there is no more limits now
  • August 29, 2007
    • MAJOR UPDATE!
  • August 30, 2007
    • Fixed adt_size array bug
  • September 06, 2007
    • Added new cvar
  • September 15, 2007 (3.1)
    • Changed some "new" to "decl"
    • Removed some fail states
  • January 10, 2007 (4.0)
    • Now the plugin will story all data in 2 Adt arrays.
    • Fixed possible error of things
    • Changed the way the plugin saves data on the database.
    • Added some extra checks to prevent errors.
  • January 21, 2008
    • Data is now saved on every round start.

Notes:
Put the globaldb.inc in addons\sourcemod\scripting\include
Attached Files
File Type: sp Get Plugin or Get Source (a_mysql.sp - 2991 views - 30.8 KB)
File Type: inc globaldb.inc (2.2 KB, 1608 views)
File Type: sp Get Plugin or Get Source (a_mysql_beta.sp - 1957 views - 35.0 KB)
__________________
http://www.nican132.com
I require reputation!

Last edited by Nican; 03-23-2008 at 11:41. Reason: Update!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 08-26-2007 , 23:20   Re: [MySQL] Database Manager
Reply With Quote #2

Exemples:

Simple bank plugin:

PHP Code:
new db_money;

public 
OnPluginStart()
{
}

public 
DB_OnRowsUpdated(){
    
db_money DB_GetColumnId("my_money"truetrueDB_INT);
    if(
db_money == -1)
        
SetFailState("[SMbank] Could not create money column!");
}

stock GetUserMoney(client){
    return 
DB_GetColumnclientdb_money );
}

stock SetUserMoney(clientmoney){
    return 
DB_SetInfo(clientdb_money money);


This function is called right after the server receives information from the database.
DO NOT try to use DB_GetColumn on player OnClientConnect or anything of the type.
PHP Code:
public DB_OnClientUpdate(client){
     
//Do something...

Note: Information is saved on OnClientDisconnect_Post, so it is OK to do this:
PHP Code:
public OnClientDisconnect(client){
    
DB_SetInfoclientdb_money5000 );


Functions
PHP Code:
#define DB_INT 0
#define DB_STRING 1
#define DB_FLOAT 2

/**
 * Gets the ID of a row
 * @param RowName Name of the mysql Column you want to get
 * @param autoenable To enable this row on select query
 * @param autocreate If the row does not exist, create it
 * @param rowtype row type if it is being created
 * @param rowsize row size if it is being created, 0 = default, float has no size
*/

native DB_GetColumnId(const String:RowName[], bool:autoenable truebool:autocreate falserowtype DB_INTrowsize 0);

/**
 * Gets the ID of a row
 * @param Enable Row id from fetching when client connect
*/
native DB_EnableIdColumnId );

/**
 * Gets the ID of a row
 * @param Disable Row Id from fetching when client connect
*/
native DB_DisableIdColumnId );

/**
 * Gets the ID of a row
 * @param client Client ID for set info
 * @param ColumnId The column ID for set info
 * @param value The information to set it to
*  @param add Set to true if you want to add the value to the old amount
*/
native DB_SetInfoclientColumnIdany:value booladd false);
native DB_SetInfoStringclientColumnId, const String:name[] );


/**
 * Gets the ID of a row
 * @param client Client ID for get info
 * @param ColumnId The column ID for get info
*/
native any:DB_GetColumnclient ,  ColumnId );
native DB_GetColumnStringclientColumnIdString:value[], maxsize);


/**
 * Gets the ID of a row
 * @param RowName Name of the mysql Column you want to get
*/
native DB_ColumnTypeColumnId );

/**
 * Returns the DB handle, for your own personal use
*/
native Handle:DB_GetHandle( );


/**
 * Gets the ID of a row
 * @param RowName The name of the new row
 * @param RowType Use DB_* and define the new row type
 * @param Size The size of this now row, leave blank for default
 * @return RowId, -1 on failure
*/
stock DB_CreateRow( const String:Rowname[], RowtypeDB_INTsize ){
    return 
DB_GetColumnId(RowNametruetrueRowtype size);
}

/**
 * Called when info of a client has been updated
 * @param client client
 */
forward DB_OnClientUpdate(client); 
__________________
http://www.nican132.com
I require reputation!

Last edited by Nican; 02-03-2008 at 20:21.
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
kipplitz
Junior Member
Join Date: Aug 2007
Old 08-27-2007 , 00:52   Re: [MySQL] Database Manager
Reply With Quote #3

Ok, completely new here at this...so walk with me...do I need a mysql database to use this as well as the bank mod you have? Give me some insight here oh great one!

KippLitz
kipplitz is offline
Rainbow 6
Junior Member
Join Date: Mar 2006
Old 08-29-2007 , 18:34   Re: [DB] Database Manager
Reply With Quote #4

Which one do we need or do we need both?
Rainbow 6 is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 08-29-2007 , 21:13   Re: [DB] Database Manager
Reply With Quote #5

Just the a_mysql.sp
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
tkaway69
Senior Member
Join Date: Dec 2004
Location: Millbrook Alabama
Old 08-29-2007 , 21:33   Re: [DB] Database Manager
Reply With Quote #6

I know this will be Noobish, but it would be nice if you had some kind of instalation instructions. We would like to use the Bank mod you fixed up. We are just not real Mysql savy. Thanks.
__________________
tkaway69 is offline
Send a message via AIM to tkaway69 Send a message via MSN to tkaway69 Send a message via Yahoo to tkaway69
Rainbow 6
Junior Member
Join Date: Mar 2006
Old 08-29-2007 , 22:18   Re: [DB] Database Manager
Reply With Quote #7

I will try to come up with one as soon as i get the bank mod + the mysql Manager plugin to work.
Rainbow 6 is offline
tkaway69
Senior Member
Join Date: Dec 2004
Location: Millbrook Alabama
Old 08-29-2007 , 23:06   Re: [DB] Database Manager
Reply With Quote #8

Thanks. I assume we can use the mysql database for our website? Waiting for some info.
__________________
tkaway69 is offline
Send a message via AIM to tkaway69 Send a message via MSN to tkaway69 Send a message via Yahoo to tkaway69
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 08-29-2007 , 23:40   Re: [DB] Database Manager
Reply With Quote #9

Ok... I just majorly update it... there was a major error...


And what do you mean by "use the mysql database for our website"
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
tkaway69
Senior Member
Join Date: Dec 2004
Location: Millbrook Alabama
Old 08-30-2007 , 11:01   Re: [DB] Database Manager
Reply With Quote #10

Well I am not sure how this mysql stuff works, but we have a msql that holds all the info to our forums and such. I was assuming we could use that to create a database for the server as well.
__________________
tkaway69 is offline
Send a message via AIM to tkaway69 Send a message via MSN to tkaway69 Send a message via Yahoo to tkaway69
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 22:03.


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