Just a pgsql module for mta. I accept any help with developing the module. Feel free to make PRs and Issues.
Put misc files from Releases to server\x64\ make a modules directory and put the ml_pgsql.dll file there.
And put this line <module src="ml_pgsql.dll" /> to mtaserver.conf
Not yet.
Make a connect to your postgres server.
String can be like:
postgresql://USER:PASSWORD@IP:PORT/dbname?connect_timeout=3
or
hostaddr=IP port=5432 dbname=DBNAME user=USERNAME password=PASSWORD
return userdata with connect in sucsessful connection. or bool and string with error otherwise.
local conn,err = pg_conn("postgresql://user:123qwe@127.0.03:5432/mydb?connect_timeout=3");
if (err ~= nil) then
print(error)
return 1;
endQuery data from a query string. String escaping is support.
return userdata with a query. Otherwise bool and string error.
local query,qerr = pg_query(conn, "SELECT $1 as a, $2 as b", -67, 2)
if (query == false) then
iprint(qerr)
endGet data from the userdata to the array
return a table or TODO
local query,qerr = pg_query(conn, "SELECT $1 as a, $2 as b", -67, 2)
if (query == false) then
iprint(qerr)
end
iprint(pg_poll(query));Free a memory after executing query (if it don't happens)
return true
local query,qerr = pg_query(conn, "SELECT $1 as a, $2 as b", -67, 2)
pg_free(quey)Like a pg_query it make a query, but do not return any data.
return bool as a result of executing the query. Otherwise bool and string error.
local exec = pg_exec(conn, "INSERT INTO users (name, password, money) VALUES ($1,$2,$3)", "a man", "mypasswd", "13");
iprint(exec);Close a database connection.
return boolean
local conn,err = pg_conn("postgresql://user:123qwe@127.0.03:5432/mydb?connect_timeout=3");
...
pg_close(conn);Begin new transaction for current connection (cannot create subtransaction)
return boolean
local conn,err = pg_conn("postgresql://user:123qwe@127.0.03:5432/mydb?connect_timeout=3");
...
pg_tx_begin(conn);
local exec = pg_exec(conn, "INSERT INTO users (name, password, money) VALUES ($1,$2,$3)", "a man", "mypasswd", "13");
local exec = pg_exec(conn, "INSERT INTO users (name, password, money) VALUES ($1,$2,$3)", "a woman", "somepass", "44");
pg_tx_commit(conn);Commit transaction for current connection
return boolean
local conn,err = pg_conn("postgresql://user:123qwe@127.0.03:5432/mydb?connect_timeout=3");
...
pg_tx_begin(conn);
local exec = pg_exec(conn, "INSERT INTO users (name, password, money) VALUES ($1,$2,$3)", "a man", "mypasswd", "13");
local exec = pg_exec(conn, "INSERT INTO users (name, password, money) VALUES ($1,$2,$3)", "a woman", "somepass", "44");
pg_tx_commit(conn);Rollback transaction for current connection
return boolean
local conn,err = pg_conn("postgresql://user:123qwe@127.0.03:5432/mydb?connect_timeout=3");
...
pg_tx_begin(conn);
local exec = pg_exec(conn, "INSERT INTO users (name, password, money) VALUES ($1,$2,$3)", "a man", "mypasswd", "13");
local exec = pg_exec(conn, "INSERT INTO users (name, password, money) VALUES ($1,$2,$3)", "a woman", "somepass", "44");
if (<state validation condition>) then
pg_tx_commit(conn);
else
pg_tx_rollback(conn);
end