17.10.2018, 13:33
(
Last edited by Mandrack_FreeZe; 20/10/2018 at 02:27 PM.
)
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:
Small Example:
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"
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[]);
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;
}
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"