/** Issue a non-SELECT query (ie: update/delete/insert) to the database. * */ static sql_rcode_t sql_query(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config, char const *query) { rlm_sql_firebird_conn_t *conn = handle->conn; int deadlock = 0; #ifdef _PTHREAD_H pthread_mutex_lock(&conn->mut); #endif try_again: /* * Try again query when deadlock, beacuse in any case it * will be retried. */ if (fb_sql_query(conn, query)) { /* but may be lost for short sessions */ if ((conn->sql_code == DEADLOCK_SQL_CODE) && !deadlock) { DEBUG("conn_id deadlock. Retry query %s", query); /* * @todo For non READ_COMMITED transactions put * rollback here * fb_rollback(conn); */ deadlock = 1; goto try_again; } ERROR("conn_id rlm_sql_firebird,sql_query error: sql_code=%li, error='%s', query=%s", (long int) conn->sql_code, conn->error, query); if (conn->sql_code == DOWN_SQL_CODE) { #ifdef _PTHREAD_H pthread_mutex_lock(&conn->mut); #endif return RLM_SQL_RECONNECT; } /* Free problem query */ if (fb_rollback(conn)) { //assume the network is down if rollback had failed ERROR("Fail to rollback transaction after previous error: %s", conn->error); return RLM_SQL_RECONNECT; } // conn->in_use=0; return -1; } if (conn->statement_type != isc_info_sql_stmt_select) { if (fb_commit(conn)) { return -1; } } return 0; }
static int sql_query(SQLSOCK *sqlsocket, SQL_CONFIG *config, char *querystr) { rlm_sql_firebird_sock *firebird_sock = sqlsocket->conn; int deadlock=0; if (config->sqltrace) radlog(L_DBG, "sock_id %i: query: %s", sqlsocket->id,querystr); #ifdef _PTHREAD_H pthread_mutex_lock(&firebird_sock->mut); #endif TryAgain: if (fb_sql_query(firebird_sock,querystr)) { //Try again query when deadlock, beacuse in any case it will be retried. // but may be lost for short sessions if ((firebird_sock->sql_code==DEADLOCK_SQL_CODE) && !deadlock) { radlog(L_DBG,"sock_id %i: deadlock. Retry query %s\n",sqlsocket->id,querystr); //For non READ_COMMITED transactions put rollback here // fb_rollback(sock); deadlock=1; goto TryAgain; } radlog(L_ERR, "sock_id %i: rlm_sql_firebird,sql_query error:sql_code=%li, error='%s', query=%s\n", sqlsocket->id, firebird_sock->sql_code, firebird_sock->lasterror, querystr); if ((firebird_sock->sql_code==DOWN_SQL_CODE)) return SQL_DOWN; //free problem query if (fb_rollback(firebird_sock)) { //assume the network is down if rollback had failed radlog(L_ERR,"Fail to rollback transaction after previous error. Error: %s\n", firebird_sock->lasterror); return SQL_DOWN; } // firebird_sock->in_use=0; return -1; } if (firebird_sock->statement_type!=isc_info_sql_stmt_select) { if (fb_commit(firebird_sock)) return -1; } return 0; }
/** Issue a non-SELECT query (ie: update/delete/insert) to the database. * */ static int sql_query(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config, char *querystr) { rlm_sql_firebird_sock *firebird_sock = handle->conn; int deadlock = 0; #ifdef _PTHREAD_H pthread_mutex_lock(&firebird_sock->mut); #endif try_again: /* * Try again query when deadlock, beacuse in any case it * will be retried. */ if (fb_sql_query(firebird_sock,querystr)) { /* but may be lost for short sessions */ if ((firebird_sock->sql_code == DEADLOCK_SQL_CODE) && !deadlock) { radlog(L_DBG,"sock_id deadlock. Retry query %s", querystr); /* * @todo For non READ_COMMITED transactions put * rollback here * fb_rollback(sock); */ deadlock = 1; goto try_again; } radlog(L_ERR, "sock_id rlm_sql_firebird,sql_query error: " "sql_code=%li, error='%s', query=%s", (long int) firebird_sock->sql_code, firebird_sock->lasterror, querystr); if (firebird_sock->sql_code == DOWN_SQL_CODE) { return SQL_DOWN; } /* Free problem query */ if (fb_rollback(firebird_sock)) { //assume the network is down if rollback had failed radlog(L_ERR,"Fail to rollback transaction after " "previous error. Error: %s", firebird_sock->lasterror); return SQL_DOWN; } // firebird_sock->in_use=0; return -1; } if (firebird_sock->statement_type != isc_info_sql_stmt_select) { if (fb_commit(firebird_sock)) { return -1; } } return 0; }