22 RCSID(
"$Id: 57be163cd0603de51a9c609da01210fb5ec2c30a $")
24 #include "sql_fbapi.h"
39 memmove(*dpb,
value, l);
47 for (i = 0; i < sqlda->sqld; i++) {
48 if ((sqlda->sqlvar[i].sqltype & ~1) == SQL_VARYING) {
49 MEM(sqlda->sqlvar[i].sqldata = talloc_array(sqlda,
char, sqlda->sqlvar[i].sqllen +
sizeof(
short)));
51 MEM(sqlda->sqlvar[i].sqldata = talloc_array(sqlda,
char, sqlda->sqlvar[i].sqllen));
54 if (sqlda->sqlvar[i].sqltype & 1) {
55 MEM(sqlda->sqlvar[i].sqlind = talloc(sqlda,
short));
57 sqlda->sqlvar[i].sqlind = 0;
65 ISC_SCHAR error[2048];
73 TALLOC_FREE(conn->error);
79 conn->sql_code = isc_sqlcode(conn->status);
88 pstatus = &conn->status[0];
97 isc_interprete(&error[0], &pstatus);
100 while (isc_interprete(&error[0], &pstatus)) {
101 conn->error = talloc_asprintf_append(conn->error,
"%s. ", &error[0]);
104 memset(&conn->status, 0,
sizeof(conn->status));
107 return conn->sql_code;
109 DIAG_ON(deprecated-declarations)
114 for (i = 0; i < sqlda->sqld; i++) {
115 free(sqlda->sqlvar[i].sqldata);
116 free(sqlda->sqlvar[i].sqlind);
124 #define IS_NULL(x) (x->sqltype & 1) && (*x->sqlind < 0)
135 int dtype, i, nulls = 0;
141 conn->
row = talloc_zero_array(conn,
char *, conn->
sqlda_out->sqld + 1);
143 for (i = 0, var = conn->
sqlda_out->sqlvar; i < conn->sqlda_out->sqld; var++, i++) {
149 dtype = var->sqltype & ~1;
157 vary = (
VARY *)var->sqldata;
174 value = (ISC_INT64) *(
short *)var->sqldata;
178 value = (ISC_INT64) *(
int *)var->sqldata;
182 value = (ISC_INT64) *(ISC_INT64 *)var->sqldata;
185 dscale = var->sqlscale;
192 for (j = 0; j > dscale; j--) {
198 (ISC_INT64)
value / tens,
200 (ISC_INT64)
value % tens);
201 }
else if ((
value / tens) != 0) {
203 (ISC_INT64) (
value / tens),
205 (ISC_INT64) -(
value % tens));
208 "-0", -dscale, (ISC_INT64) - (
value % tens));
224 isc_decode_timestamp((ISC_TIMESTAMP ISC_FAR *)var->sqldata, ×);
226 times.tm_year + 1900,
232 ((ISC_TIMESTAMP *)var->sqldata)->timestamp_time % 10000);
236 isc_decode_sql_date((ISC_DATE ISC_FAR *)var->sqldata, ×);
238 times.tm_year + 1900,
244 isc_decode_sql_time((ISC_TIME ISC_FAR *)var->sqldata, ×);
249 (*((ISC_TIME *)var->sqldata)) % 10000);
255 bid = *(ISC_QUAD ISC_FAR *) var->sqldata;
257 bid.gds_quad_high, bid.gds_quad_low);
273 char *p, *
buff = NULL;
274 char const *database;
285 *conn->
dpb++= isc_dpb_version1;
294 *conn->
dpb++= isc_dpb_num_buffers;
299 *conn->
dpb++= isc_dpb_connect_timeout;
313 if (strchr(
config->sql_server,
':')) {
314 database =
config->sql_server;
320 database =
buff = talloc_asprintf(NULL,
"%s:%s",
config->sql_server,
config->sql_db);
322 DEBUG2(
"rlm_sql_firebird: Connecting to %s", database);
323 isc_attach_database(conn->
status, 0, database, &conn->
dbh,
336 fetch_stat = isc_dsql_fetch(conn->
status, &conn->
stmt,
339 if (fetch_stat!= 100L) {
351 static char stmt_info[] = { isc_info_sql_stmt_type };
352 char info_buffer[128];
356 isc_start_transaction(conn->
status, &conn->
trh, 1, &conn->
dbh,
358 if (!conn->
trh)
return -4;
362 isc_dsql_allocate_statement(conn->
status, &conn->
dbh,
364 if (!conn->
stmt)
return -1;
367 isc_dsql_prepare(conn->
status, &conn->
trh, &conn->
stmt, 0, query,
373 XSQLDA_LENGTH(conn->
sqlda_out->sqld),
"XSQLDA");
375 isc_dsql_describe(conn->
status, &conn->
stmt, SQL_DIALECT_V6,
383 isc_dsql_sql_info(conn->
status, &conn->
stmt,
sizeof(stmt_info),
384 stmt_info,
sizeof(info_buffer), info_buffer);
387 l = (short) isc_vax_integer((
char ISC_FAR *) info_buffer + 1, 2);
388 conn->
statement_type = isc_vax_integer((
char ISC_FAR *) info_buffer + 3, l);
400 case isc_info_sql_stmt_exec_procedure:
414 static char count_info[] = {isc_info_sql_records};
415 char info_buffer[128];
419 if (!conn->
stmt)
return -1;
422 sizeof (count_info), count_info,
423 sizeof (info_buffer), info_buffer);
428 while (*p != isc_info_end) {
430 len = (short)isc_vax_integer(++p, 2);
442 isc_dsql_free_statement(conn->
status, &conn->
stmt, DSQL_drop);
450 isc_rollback_transaction(conn->
status, &conn->
trh);
459 isc_commit_transaction(conn->
status, &conn->
trh);
462 ERROR(
"Fail to commit. Error: %s. Try to rollback.", conn->
error);
static fr_time_delta_t timeout
static const conf_parser_t config[]
sql_rcode_t
Action to take at end of an SQL query.
@ RLM_SQL_NO_MORE_ROWS
No more rows available.
static int affected_rows(PGresult *result)
Return the number of affected rows of the result as an int instead of the string that postgresql prov...
static char buff[sizeof("18446744073709551615")+3]
static void fb_dpb_add_str(char **dpb, char name, char const *value)
int fb_sql_query(rlm_sql_firebird_conn_t *conn, char const *query)
int fb_connect(rlm_sql_firebird_conn_t *conn, rlm_sql_config_t const *config)
static void fb_set_sqlda(XSQLDA *sqlda)
int fb_rollback(rlm_sql_firebird_conn_t *conn)
int fb_error(rlm_sql_firebird_conn_t *conn)
int fb_fetch(rlm_sql_firebird_conn_t *conn)
void fb_free_sqlda(XSQLDA *sqlda)
static int fb_prepare(rlm_sql_firebird_conn_t *conn, char const *query)
sql_rcode_t fb_store_row(rlm_sql_firebird_conn_t *conn)
int fb_commit(rlm_sql_firebird_conn_t *conn)
int fb_affected_rows(rlm_sql_firebird_conn_t *conn)
void fb_free_statement(rlm_sql_firebird_conn_t *conn)
#define DUPLICATE_KEY_SQL_CODE
#define IS_ISC_ERROR(status)
ISC_STATUS status[20]
Magic interbase status code array (holds multiple error codes used to construct more detailed error m...
MEM(pair_append_request(&vp, attr_eap_aka_sim_identity) >=0)
char * talloc_bstrndup(TALLOC_CTX *ctx, char const *in, size_t inlen)
Binary safe strndup function.
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
static int64_t fr_time_delta_to_sec(fr_time_delta_t delta)