View Single Post
Sonic
Junior Member
Join Date: Feb 2004
Location: Germany
Old 04-06-2004 , 16:50  
#21

bug in the connect function

Code:
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
__________________
Sonic is offline