error checking

This commit is contained in:
David Anderson 2004-04-03 01:04:57 +00:00
parent 1f178b916f
commit 23bea839da
2 changed files with 20 additions and 3 deletions

View File

@ -121,6 +121,8 @@ static cell AMX_NATIVE_CALL pgsql_connect(AMX *amx, cell *params)
PGconn *cn = make_connection(host, user, pass, name); PGconn *cn = make_connection(host, user, pass, name);
if (PQstatus(cn) != CONNECTION_OK) { if (PQstatus(cn) != CONNECTION_OK) {
char *error = PQerrorMessage(cn);
SET_AMXSTRING(amx, params[5], (error?error:""), params[6]);
return 0; return 0;
} }
@ -162,10 +164,18 @@ static cell AMX_NATIVE_CALL pgsql_query(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL pgsql_nextrow(AMX *amx, cell *params) static cell AMX_NATIVE_CALL pgsql_nextrow(AMX *amx, cell *params)
{ {
pgs *p = get_conn_i(params[1]); pgs *p = get_conn_i(params[1]);
if (p == NULL) { if (p == NULL) {
return 0; return 0;
} }
if (p->v.cn == NULL) {
return -1;
}
if (PQstatus(p->v.cn)!= CONNECTION_OK) {
return -1;
}
if (p->v.row > PQntuples(p->v.res)) { if (p->v.row > PQntuples(p->v.res)) {
return 0; return 0;
} }
@ -182,6 +192,14 @@ static cell AMX_NATIVE_CALL pgsql_getfield(AMX *amx, cell *params)
if (p == NULL) { if (p == NULL) {
return 0; return 0;
} }
if (p->v.cn == NULL) {
return -1;
}
if (PQstatus(p->v.cn)!= CONNECTION_OK) {
return -1;
}
if (col-1 > PQnfields(p->v.res)) { if (col-1 > PQnfields(p->v.res)) {
return 0; return 0;
} }

View File

@ -112,8 +112,6 @@ public:
destroy(v.user); destroy(v.user);
destroy(v.pass); destroy(v.pass);
destroy(v.name); destroy(v.name);
destroy(v.cn);
destroy(v.res);
v.row = 0; v.row = 0;
free = true; free = true;
} }
@ -133,8 +131,9 @@ public:
close(); close();
} }
bool free;
private: private:
pgs *next; pgs *next;
bool free;
int id; int id;
}; };