SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 17/10/2018, 02:33 PM   #1
Mandrack_FreeZe
Huge Clucker
 
Mandrack_FreeZe's Avatar
 
Join Date: Dec 2011
Posts: 327
Reputation: 52
Default PGConnector - Handling PostgreSQL DBMS for SA-MP

PGConnector - Handling PostgreSQL DBMS for SA-MP

Good morning people. After a long time inactive from the SA-MP community I decided to develop this Plugin. I know there are other plugins that do the same function as this but I have developed the same for knowledge purposes in the C ++ language. I'm waiting for suggestions and possible bugs.


The plugin supports asynchronous and synchronous querys and currently supports Windows and Linux operating systems. It supports managing up to 50 concurrent connections (in the future I intend to create a configuration file to administer these types of parameters). There are still some points in it that can be improved such as memory manipulation and even performance. In a future version I will make improvements in these questions but by the hour it is usable.

The plugin is available in GitHub and the tutorial on how to install it is also available (in Portuguese). I hope it will be useful to anyone who is interested in using this DBMS and can be used as an object of study by all as it has served me. In case of doubts/suggestions/errors, just leave a comment.

Here is a list of all the commands and forwards:

pawn Code:
//Natives responsible for handling connections
native PG_connect(host[], port[], user[], password[], database[]);
native PG_close(connectionId);
native PG_status(connectionId);
native PG_lastError(connectionId, errorStr[], sizeofErrorStr);
native PG_setClientEncode(connectionId, encode[] = "WIN1252");
native PG_escapeString(connectionId, sourceStr[], destinyStr[], sizeofDestinyStr);

//Natives responsible for handling responses
native PG_query(connectionId, query[]);
native PG_assyncQuery(connectionId, query[], callbackFunction[]);
native PG_responseStatus(responseId);
native PG_responseError(responseId, strError[], sizeofStrError);
native PG_freeResponse(responseId);
native PG_numFields(responseId);
native PG_numRows(responseId);
native PG_getInt(responseId, row, column);
native Float:PG_getFloat(responseId, row, column);
native PG_getStr(responseId, row, column, strValue[], sizeofStrValue);
native PG_isNull(responseId, row, column);

//Forwards
forward OnPostgreSQLError(errorCode, erro[]);

Small Example:
pawn Code:
public OnGameModeInit() {
    new connection = PG_connect("127.0.0.1", "5432", "postgres", "", "sampserver");
    if(PG_status(connection) != PG_CONNECTION_OK){
        new error[200];
        PG_lastError(connection, error, sizeof(error));
        printf("Error at opening connection: %s", error);
        return 0;
    }
    new result = PG_query(connection, "SELECT user.id, user.username FROM user");
    PG_close(connection);
    if(PG_responseStatus(result) != PGRES_TUPLES_OK){
        new error[200];
        PG_responseError(result, error, sizeof(error));
        printf("Error at execution of command: %s", error);
        PG_freeResponse(result);
        return 0;
    }
   
    new numRows = PG_numRows(result);
    printf("Registered Users on the Server:\nNumber of Users: %d\n", numRows);
    for(new i = 0; i < numRows; ++i){
        new userName[MAX_PLAYER_NAME];
        PG_getStr(result, i, 1, userName, sizeof(userName));
        printf("ID: %d\nUser Name: %s\n", PG_getInt(result, i, 0), userName);
    }
    PG_freeResponse(result);
    return 1;
}

To see the detailed explanation and examples of how to use each command go to the project page in GitHub below. Currently her documentation on GitHub is in Portuguese. If you have any problems understanding please try to use a translator, if not (please let me know), I am willing to translate it and post it on this topic. The name of the functions also then in Portuguese, if you need, I also provide an include with the translated functions.

Releases

Version 1.1
Bug Fixes


Github Project/Documentation
Downloads
GitHub
Note: The include with English functions is named "pgconnector_eng.inc" in GitHub realeases.

Créditos
Mandrack_FreeZe by Plugin development and include.
Kyosaur by the tutorial "Plugin development guide"

Last edited by Mandrack_FreeZe; 20/10/2018 at 03:27 PM.
Mandrack_FreeZe is offline   Reply With Quote
Old 19/10/2018, 10:41 PM   #2
Chaprnks
Gangsta
 
Chaprnks's Avatar
 
Join Date: Sep 2007
Location: Soviet America
Posts: 748
Reputation: 64
Default Re: PGConnector - Handling PostgreSQL DBMS for SA-MP

Great to see a PostgreSQL release, the old one from Dan is hella outdated. But please release it with English function names.. adds so much confusion with foreign language functions..
__________________
Chaprnks is offline   Reply With Quote
Old 20/10/2018, 03:06 AM   #3
Mandrack_FreeZe
Huge Clucker
 
Mandrack_FreeZe's Avatar
 
Join Date: Dec 2011
Posts: 327
Reputation: 52
Default Re: PGConnector - Handling PostgreSQL DBMS for SA-MP

Quote:
Originally Posted by Chaprnks View Post
Great to see a PostgreSQL release, the old one from Dan is hella outdated. But please release it with English function names.. adds so much confusion with foreign language functions..
Hello Chaprnks, thanks for the comment, I'll translate the name of the functions. Soon I will make an update of it!

@edit
Added include plugin in English

Last edited by Mandrack_FreeZe; 20/10/2018 at 04:36 AM.
Mandrack_FreeZe is offline   Reply With Quote
Old 20/10/2018, 09:24 AM   #4
Infin1ty
Big Clucker
 
Join Date: Feb 2018
Posts: 78
Reputation: 30
Default Re: PGConnector - Handling PostgreSQL DBMS for SA-MP

f i n a l l y

got a rep from me. will definitely be using this in my script.
Infin1ty is offline   Reply With Quote
Old 20/10/2018, 03:31 PM   #5
Mandrack_FreeZe
Huge Clucker
 
Mandrack_FreeZe's Avatar
 
Join Date: Dec 2011
Posts: 327
Reputation: 52
Default Re: PGConnector - Handling PostgreSQL DBMS for SA-MP

Quote:
Originally Posted by Infin1ty View Post
f i n a l l y

got a rep from me. will definitely be using this in my script.
Hello Infin1ty, thanks for the comment. I strongly recommend that you use version 1.1 of the plugin in your project, some bugs have been fixed.
Mandrack_FreeZe is offline   Reply With Quote
Old 20/10/2018, 09:23 PM   #6
Infin1ty
Big Clucker
 
Join Date: Feb 2018
Posts: 78
Reputation: 30
Default Re: PGConnector - Handling PostgreSQL DBMS for SA-MP

ill experiment with this when i've got free time.

why not go with a more user-friendly function naming scheme? PG_function doesn't really sound appealing to me. how about pgsql_function? or sql_function? i know defines can easily be written for this but that defeats the purpose of keeping your plugins up to date as functions and natives are constantly being added.
Infin1ty is offline   Reply With Quote
Old 20/10/2018, 09:38 PM   #7
Mellnik
Gangsta
 
Mellnik's Avatar
 
Join Date: Dec 2011
Location: Paradise Falls, CAℕADA
Posts: 794
Reputation: 369
Default Re: PGConnector - Handling PostgreSQL DBMS for SA-MP

That's nice but why would you use that instead of MySQL?
Mellnik is offline   Reply With Quote
Old 20/10/2018, 10:55 PM   #8
Mandrack_FreeZe
Huge Clucker
 
Mandrack_FreeZe's Avatar
 
Join Date: Dec 2011
Posts: 327
Reputation: 52
Default Re: PGConnector - Handling PostgreSQL DBMS for SA-MP

Quote:
Originally Posted by Infin1ty View Post
ill experiment with this when i've got free time.

why not go with a more user-friendly function naming scheme? PG_function doesn't really sound appealing to me. how about pgsql_function? or sql_function? i know defines can easily be written for this but that defeats the purpose of keeping your plugins up to date as functions and natives are constantly being added.

I will think about changing the names of the functions in the future, per hour I will focus on issues such as memory manipulation and performance.

Quote:
Originally Posted by Mellnik View Post
That's nice but why would you use that instead of MySQL?
Good night Mellnik, it depends on the user, I for example prefer to use PostgreSQL instead of MySQL. This plugin gives you the chance to work with this DBMS in your projects. If you want more reasons, look for the difference between the PostgreSQL DBMS and MySQL.
Mandrack_FreeZe is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Plugin] PGConnector - Manipulação do SGBD PostgreSQL para SA-MP Mandrack_FreeZe Lançamentos/Releases 3 11/11/2018 10:52 PM
[Plugin] MySQL & PostgreSQL Plugin Dan.. Plugin Development 396 26/08/2017 07:38 AM
MySQL & PostgreSQL Plugin Help duknuken666 Server Support 0 16/12/2013 03:50 PM
Someone should make a PostgreSQL plugin Gamer_Z Plugin Development 19 07/02/2013 12:24 AM
PostgreSQL Steve M. Scripting Help 4 10/12/2011 12:36 PM


All times are GMT. The time now is 03:31 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.