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

SQL Connection Manager


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   ALL        Category:   Technical/Development        Approver:   ConnorMcLeod (74)
Zefir
Member
Join Date: Oct 2007
Location: Kiev, Ukraine
Old 04-18-2011 , 13:53   SQL Connection Manager
Reply With Quote #1

SQL Connection Manager
version 1.0
by Zefir

SQL Manager (sqlm) although an amxx plugin, but by itself does not perform any visible action. It is a library providing a more convenient functionality for working with SQL servers.

The main purpose of this plugin, it automatically reconnects when disconnected, and the ability to transparently work with several drivers databases.

Description

In sqlm no concept of connection. There is a connection tuple, keeps all the necessary data. The connection is created and updated as necessary. Handle queries are used as usual.

All functions except running's handle, work only with the name of the tuple.

Include sqlm.inc to use this plugin. Required constants from sql_manager.inc will be included automatically.

Depends (Required)
  • Modules
    • sqlx
    • vdf
    • fakemeta
  • Library
    • hashx.inc
    • bits.inc
    • text.inc

API

When connecting to or after the restoration of communication at breakage, called forward sqlm_connection_established function receives as a parameter the name of the raised tuple and name of the driver («mysql» or «sqlite» …).

Forward
  • sqlm_connection_established(tuple[], driver[])
    - Forward function is called when you first connect to the database or after the break when the connection is restored.

Native
  • sqlm_affected_rows(Handle:query);
    - Returns the number of affected rows.
  • bool:sqlm_connected(tuple[] = "default");
    - Returns state of connection.
  • sqlm_exec(Handle:query);
    - Execute a query prepared function .
  • sqlm_field_name_to_num(Handle:query, const name[]);
    - Returns the field number by name in the result set.
  • sqlm_field_num_to_name(Handle:query, num, name[], maxlen);
    - Returns the name of the field by its number in the resulting query.
  • sqlm_free_handle(Handle:query);
    - Releases the handle to the query.
  • sqlm_get_insert_id(Handle:query);
    - Returns the ID of the last inserted row. Used mainly when working with MySQL databases.
  • sqlm_get_query_string(Handle:query, querystring[], maxlen);
    - Returns the original query string for a handle.
  • sqlm_is_null(Handle:query, column);
    - Tells whether a specific column in the current row is NULL or not
  • sqlm_more_results(Handle:query);
    - Returns true if the result is still unread row
  • bool:sqlm_next_row(Handle:query);
    - Checks for available lines in the data set, and if reading the next one.
  • sqlm_num_columns(Handle:query);
    - Returns number of fields in the dataset.
  • sqlm_num_results(Handle:query);
    - Returns the total number of resulting rows.
  • Handle:sqlm_prepare_query(const tuple[SQL_NAME], const fmt[], {Float,_}:...);
    - The function prepares a synchronous request to run.
  • sqlm_query_error(Handle:query, error[], maxlen);
    - Returns the last database driver error
  • sqlm_quote_string(const tuple[SQL_NAME], buffer[], buflen, const fmt[], {Float,_}:...);
    - Escapes a string according to the rules database.
  • sqlm_read_result(Handle:query, column, {Float,_}:...);
    - Reads the value of fields in the current row result set.
  • sqlm_simple_query(const tuple[SQL_NAME], const query_string[], {Float,_}:...);
    - The function sends the request and ignores the result of execution. Often used for logging, etc.
  • sqlm_simple_upd_ins(const tuple[SQL_NAME], const update_string[], const insert_string[]);
    - Assumes the existence of a processing line. Sends two requests, first to update a row, and the second to add, if such a line yet.
  • sqlm_thread_query(const tuple[SQL_NAME], const func[], const query_string[], data);
    - The function creates and sends an asynchronous request to the database. That is when a driver receives a response, it will call the specified function to which the answer will be given.


Configuration file

Configuration is stored in the file config/sql_manager.vdf format Valve Data Format. Tuple «default» if it does not, create based on standard parameters of sql.cfg.

Code:
"Servers"
{
    "default"
    {
        "type" "mysql"
        "host" "127.0.0.1"
        "db"  "amx"
        "user" "admin"
        "pass" "admin_pass"
        "timeout" "0.000"
        "autoconnect" "1"
    }
    "local"
    {
        "type" "sqlite"
        "host" ""
        "db"  "local"
        "user" ""
        "pass" ""
        "timeout" "0.000"
        "autoconnect" "1"
    }
    "remote"
    {
        "type" "mysql"
        "host" "example.tld"
        "db"  "remote_db"
        "user" "admin"
        "pass" "admin_pass"
        "timeout" "0.000"
        "autoconnect" "0"
    }
    "test"
    {
        "type" "mysql"
        "host" "example.tld"
        "db"  "test_db"
        "user" "admin"
        "pass" "admin_pass"
        "timeout" "0.000"
        "autoconnect" "-1"
    }

}
  • default, local, remote, test - random tuple names which are used for the treatment of plug-ins.
  • type - defines the driver used for the tuple. Available «mysql» and «sqlite».
  • host, db, user, pass - as usual
  • timeout - corresponds to the same parameter for the function SQL _MakeDbTuple, and defines the connection timeout.
  • autoconnect - manages the restoration of connections:
    • -1: Allows you to disable unused profile without removing it from the file.
    • 0: the connection to demand. If the link is often broken, but it should be infrequent, for example, only when the map changes, it will not pull the connection constantly.
    • 1: a persistent connection. Disconnection and attempts to connect will always occur.

Debugging

These two constants in sql_manager.sma include debugging and tracing queries:

Code:
#define DEBUG
#define SQL_TRACE
Comment out their to disable debugging.

Statistics

Command sqlm_stats [tuple_name] will show the current state of tuple and statistics queries:

Code:
sqlm_stats db1

SQL Connection Manager, version 1.0, by Zefir
  Statistic for Tuple:............ 'db1'
    Direct Queries:...............  0
    Threaded Queries:.............  6
  Errors:
    Reconnect count:..............  0
    Error count:..................  1
    First Error:.................. (1) 'table 'nets' already exists'
    Last Error:................... (1) 'table 'nets' already exists'
Links

Libs:
Attached Files
File Type: gz sql_manager.tar.gz (7.6 KB, 455 views)
File Type: gz sql_manager_full.tar.gz (67.1 KB, 337 views)
File Type: zip sql_manager_full.zip (69.9 KB, 472 views)
__________________

Last edited by Zefir; 04-19-2011 at 15:16.
Zefir is offline
Send a message via ICQ to Zefir
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 04-19-2011 , 04:19   Re: SQL Connection Manager
Reply With Quote #2

Upload .zip ;)
I don't know .tar.gz is allowed.
__________________
Retired.
Xalus is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-19-2011 , 04:40   Re: SQL Connection Manager
Reply With Quote #3

Yes, ZIP should be used.

Btw, it's nice to see people making API.
__________________
Arkshine is offline
Zefir
Member
Join Date: Oct 2007
Location: Kiev, Ukraine
Old 04-19-2011 , 06:09   Re: SQL Connection Manager
Reply With Quote #4

Ok, .zip attached.

Arkshine, tnx
__________________
Zefir is offline
Send a message via ICQ to Zefir
abalad
Junior Member
Join Date: Oct 2010
Location: Parana-BR
Old 06-05-2011 , 23:59   Re: SQL Connection Manager
Reply With Quote #5

Friend would like to know how that works just fine this plugin since put him in vdf AutoConnect 1 as an option but when the server Cai and I turn again he does not carry the data bank. Only after the exchange of map data it can load the table.

Sorry for the english Google translator: D
abalad is offline
Send a message via MSN to abalad Send a message via Skype™ to abalad
Zefir
Member
Join Date: Oct 2007
Location: Kiev, Ukraine
Old 06-06-2011 , 00:45   Re: SQL Connection Manager
Reply With Quote #6

Hi, abalad!

Please show sqlm_stats 'db_name'.

Also enable debug and show log.
In source code, uncomment this string:
Code:
#define DEBUG
#define SQL_TRAC
and recompile library.

PS: And show your code, please
__________________

Last edited by Zefir; 06-06-2011 at 00:50.
Zefir is offline
Send a message via ICQ to Zefir
abalad
Junior Member
Join Date: Oct 2010
Location: Parana-BR
Old 06-06-2011 , 10:13   Re: SQL Connection Manager
Reply With Quote #7

Hello Friend. First thanks for Responding. I thought That Was Already in oFF TOPIC: D.

Friend put the command in the console Following by HLSW.

Yes friend got this in the console appeared to give me

SQL Connection Manager, version 1.0, by Zefir
Statistic for Tuple :............ 'default'
Direct Query :............... 0
Threaded Query :............. 0
Errors:
Reconnect count :.............. 0
Error count :.................. 0
First Error :.................. (0)''
Last Error :................... (0)''

But not itendi which the functionality of this command .. what good is it? What about the bug that had helped him?

Last edited by abalad; 06-06-2011 at 11:47.
abalad is offline
Send a message via MSN to abalad Send a message via Skype™ to abalad
Zefir
Member
Join Date: Oct 2007
Location: Kiev, Ukraine
Old 06-06-2011 , 17:01   Re: SQL Connection Manager
Reply With Quote #8

Hi, abalad!

Please show code of your plugin.
And show 'configs/sql_manager.vdf'
__________________
Zefir is offline
Send a message via ICQ to Zefir
Zefir
Member
Join Date: Oct 2007
Location: Kiev, Ukraine
Old 06-07-2011 , 03:19   Re: SQL Connection Manager
Reply With Quote #9

Hi abalad!

Please show YOUR plugin with using library 'SQL_Manager'.

"SQL Connection Manager" is not plugin, this is library for simple manipulate connections.
__________________
Zefir is offline
Send a message via ICQ to Zefir
abalad
Junior Member
Join Date: Oct 2010
Location: Parana-BR
Old 06-07-2011 , 11:40   Re: SQL Connection Manager
Reply With Quote #10

Hello Zefir. Amigo now understand the operation of SQL Manager. You mean I have to modify the functions of the original plugin that I have for these SQL MANAGER. Right?

Look I'll post the pluginthat I intend to to use this connection .
Attached Files
File Type: sma Get Plugin or Get Source (gunxpmod.sma - 558 views - 36.0 KB)
__________________
abalad is offline
Send a message via MSN to abalad Send a message via Skype™ to abalad
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 17:32.


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