[Plugin] PGConnector - Handling PostgreSQL DBMS for SA-MP
#1

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"
Reply
#2

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..
Reply
#3

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
Reply
#4

f i n a l l y

got a rep from me. will definitely be using this in my script.
Reply
#5

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.
Reply
#6

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.
Reply
#7

That's nice but why would you use that instead of MySQL?
Reply
#8

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)