PDA

View Full Version : Databases with AMXx 0.2


BAILOPAN
04-02-2004, 19:31
I am announcing an important change in AMX Mod X structure which pertains to scripters for 0.2.

I have implemented a trivial Database API so a plugin that uses SQL will work anywhere. As long as the user has a database interface module loaded, and the plugin author uses ANSI-SQL, it will work. If you would like something other than MySQL or PgSQL supported, please list it here.

Change for scripters:

#include <mysql>


Should be changed to:

#include <dbi>


Any function that references a native like this:
mysql_query, mysql_connect
Is now:
dbi_query, dbi_connect, et cetera.
configs/mysql.cfg is now configs/sql.cfg
amx_mysql_cvars are now amx_sql_cvars

Remember, this is for 0.2 only. (changes are in CVS).

Please be ready to change to this new format when the next release comes out.

(btw - I fixed those infamous crashing bugs in mysql module)

Geesu
04-02-2004, 19:47
(btw - I fixed those infamous crashing bugs in mysql module)


THANK GOD!!! Can you give us any input as to why it was happening?

BAILOPAN
04-02-2004, 19:58
there was actually, believe it or not, no error checking in the module at all.
if you find something that crashes it, please tell me and I will fix it

DopeFish
04-02-2004, 20:31
will thy mysql.cfg file also be renamed?

BAILOPAN
04-02-2004, 20:32
yes, to sql.cfg

knekter
04-02-2004, 20:40
hurray much simnpler, good job!

DopeFish
04-02-2004, 20:44
k, will the cvars change too?
"amx_mysql_db,amx_mysql_host,......."

sorry for all the questions, but I'm updating my code at the moment.

BAILOPAN
04-02-2004, 21:14
Yes, sorry, I should mention that
mysql => sql in cvar name

QwertyAccess
04-02-2004, 22:29
someone asked me if sql is a thing used to hack people....

Geesu
04-02-2004, 22:51
I love you BAIL, I've HATED the mysql module for so long because you couldn't execute multiple commands w/o a crash.

one question though.

Lets say when someone types /rank I query a server and display some info. And the ping b/t my server and the mysql server is around like 200 (not very good). Will the server freeze up? This is what happened with the old one, was wondering if this would still be an issue.

BAILOPAN
04-02-2004, 23:00
Yes, that will indeed still happen because it is not multithreading.

Maybe in the future I can make a multithreading version of it

Geesu
04-02-2004, 23:07
Someone started a multithreading version of it. I got the source from him a while back. I think it was Scott Beaman (thats in the source files..) I can send it to you if you like and you can take a peak.

BAILOPAN
04-02-2004, 23:08
sure... bailopan [at] amxmodx [dot] org

Geesu
04-02-2004, 23:09
lol, just PMed it to ya.. i'll email it

_KaszpiR_
04-05-2004, 07:39
Bailopan - i know enough the mysql an oracle and i can say the differences (as you probably know) are not only in the functuion calls - i would also recommend the adding var /define statement to determine what sql system is used, so that different sql queries could be used on specifiled platforms

also i imagine there will be a big welcome from mssql

Bionic
04-05-2004, 07:50
i remember trying a plugin called mthread by DJeyl. it could execute a command in a separate thread f.i sql-queries, thus not freezing up the server

_KaszpiR_
04-05-2004, 07:52
yes, but it was buggy, the dev team says they may rewrite it (afair)

DopeFish
04-05-2004, 08:54
yeah, certain problems arose when heavily multithreading stuff in a non multithreading enviroment (hlds)

BAILOPAN
04-05-2004, 09:41
Sometime in the future I will write mthreading versions of each database driver we put out, that way the problems will be contained in the module and won't be suspectible to the problems of global multithreading which plugin authors do not know how to handle well.

As for other database driver properties, yes, I am planning an Ms-SQL driver (as I happen to like MS-SQL). However, beyond the basic dbi_connect and dbi_query, I don't have anything planned unless someone contributes code. I don't think anything else is really necessary unless you are planning TRANSACT support (which should be already there with dbi_query).

_KaszpiR_
04-06-2004, 04:13
i guess the same functions as are implemented in mysql version are enough

Sonic
04-06-2004, 16:50
bug in the connect function

static cell AMX_NATIVE_CALL sql_connect(AMX *amx, cell *params) // 6 param
{
int i;
const char *host = GET_AMXSTRING(amx,params[1],0,i);
const char *user = GET_AMXSTRING(amx,params[2],1,i);
const char *pass = GET_AMXSTRING(amx,params[3],2,i);
const char *dbname = GET_AMXSTRING(amx,params[4],3,i);

sql_list* c = sql_exists(list_head,host,user,pass,dbname);

if (c){
add_owner(&c->owner,amx);
return (cell)c->address;
}

c = create_sql(&list_head,host,user,pass,dbname);

if (!c || !c->address)
return MEM_ALLOC_FAILED;

mysql_t *mysql = c->address;

char *sqlerror=NULL;

if(!sqlconnect(&(mysql->mysql),host,user,pass,dbname,&sqlerror)) {
SET_AMXSTRING(amx,params[5],sqlerror ? sqlerror : "unknown error",params[6]);
return CONNECT_FAILED;
}

SET_AMXSTRING(amx,params[5],"",params[6]);
mysql->result = NULL;
add_owner(&c->owner,amx);

return (cell)mysql;
}


on CONNECT_FAILED/MEM_ALLOC_FAILED we need to delete_sql from the sql list
or the next plugin that uses the connect function get no CONNECT_FAILED/MEM_ALLOC_FAILED error.

and please add support for last_insertid

BAILOPAN
04-06-2004, 18:40
thanks for the bug report I will fix that