34 |
|
|
35 |
static int rad_postgres_reconnect(int type, struct sql_connection *conn); |
static int rad_postgres_reconnect(int type, struct sql_connection *conn); |
36 |
static void rad_postgres_disconnect(struct sql_connection *conn, int drop); |
static void rad_postgres_disconnect(struct sql_connection *conn, int drop); |
|
static int rad_postgres_query(struct sql_connection *conn, char *query, int *return_count); |
|
|
static char *rad_postgres_getpwd(struct sql_connection *conn, char *query); |
|
|
static void *rad_postgres_exec(struct sql_connection *conn, char *query); |
|
|
static char *rad_postgres_column(void *data, int ncol); |
|
|
static int rad_postgres_next_tuple(struct sql_connection *conn, void *data); |
|
|
static void rad_postgres_free(struct sql_connection *conn, void *data); |
|
37 |
|
|
38 |
/* ************************************************************************* */ |
/* ************************************************************************* */ |
39 |
/* Interface routines */ |
/* Interface routines */ |
185 |
int curtuple; |
int curtuple; |
186 |
} EXEC_DATA; |
} EXEC_DATA; |
187 |
|
|
188 |
|
static int |
189 |
|
rad_postgres_n_columns(struct sql_connection *conn, void *data, size_t *np) |
190 |
|
{ |
191 |
|
EXEC_DATA *edata = (EXEC_DATA*)data; |
192 |
|
if (!data) |
193 |
|
return -1; |
194 |
|
*np = edata->nfields; |
195 |
|
return 0; |
196 |
|
} |
197 |
|
|
198 |
|
static int |
199 |
|
rad_postgres_n_tuples(struct sql_connection *conn, void *data, size_t *np) |
200 |
|
{ |
201 |
|
EXEC_DATA *edata = (EXEC_DATA*)data; |
202 |
|
if (!data) |
203 |
|
return -1; |
204 |
|
*np = edata->ntuples; |
205 |
|
return 0; |
206 |
|
} |
207 |
|
|
208 |
static void * |
static void * |
209 |
rad_postgres_exec(struct sql_connection *conn, char *query) |
rad_postgres_exec(struct sql_connection *conn, char *query) |
210 |
{ |
{ |
232 |
PQresStatus(stat))); |
PQresStatus(stat))); |
233 |
|
|
234 |
if (stat != PGRES_TUPLES_OK) { |
if (stat != PGRES_TUPLES_OK) { |
|
radlog(L_ERR, |
|
|
_("PQexec returned %s"), |
|
|
PQresStatus(stat)); |
|
235 |
PQclear(res); |
PQclear(res); |
236 |
if (stat == PGRES_FATAL_ERROR) |
if (stat == PGRES_FATAL_ERROR) { |
237 |
|
radlog(L_ERR, |
238 |
|
_("PQexec returned %s"), |
239 |
|
PQresStatus(stat)); |
240 |
rad_postgres_disconnect(conn, 0); |
rad_postgres_disconnect(conn, 0); |
241 |
|
} |
242 |
return NULL; |
return NULL; |
243 |
} |
} |
244 |
|
|
251 |
} |
} |
252 |
|
|
253 |
static char * |
static char * |
254 |
rad_postgres_column(void *data, int ncol) |
rad_postgres_column(void *data, size_t ncol) |
255 |
{ |
{ |
256 |
EXEC_DATA *edata = (EXEC_DATA*)data; |
EXEC_DATA *edata = (EXEC_DATA*)data; |
257 |
if (!data) |
if (!data) |
258 |
return NULL; |
return NULL; |
259 |
if (ncol >= edata->nfields) { |
if (ncol >= edata->nfields) { |
|
radlog(L_ERR, |
|
|
_("too few columns returned (%d req'd)"), ncol); |
|
260 |
return NULL; |
return NULL; |
261 |
} |
} |
262 |
return PQgetvalue(edata->res, edata->curtuple, ncol); |
return PQgetvalue(edata->res, edata->curtuple, ncol); |
299 |
rad_postgres_exec, |
rad_postgres_exec, |
300 |
rad_postgres_column, |
rad_postgres_column, |
301 |
rad_postgres_next_tuple, |
rad_postgres_next_tuple, |
302 |
rad_postgres_free |
rad_postgres_free, |
303 |
|
rad_postgres_n_tuples, |
304 |
|
rad_postgres_n_columns, |
305 |
}; |
}; |
306 |
|
|
307 |
#endif |
#endif |