static zend_long dblib_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len) { pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; RETCODE ret, resret; dbsetuserdata(H->link, (BYTE*)&H->err); if (FAIL == dbcmd(H->link, sql)) { return -1; } if (FAIL == dbsqlexec(H->link)) { return -1; } resret = dbresults(H->link); if (resret == FAIL) { return -1; } ret = dbnextrow(H->link); if (ret == FAIL) { return -1; } if (dbnumcols(H->link) <= 0) { return DBCOUNT(H->link); } /* throw away any rows it might have returned */ dbcanquery(H->link); return DBCOUNT(H->link); }
static apr_status_t clear_result(void *data) { /* clear cursor */ return (dbcanquery((DBPROCESS*)data) == SUCCEED) ? APR_SUCCESS : APR_EGENERAL; }
CDBL_BlobResult::~CDBL_BlobResult() { try { if (!m_EOR) Check(dbcanquery(GetCmd())); } NCBI_CATCH_ALL_X( 2, NCBI_CURRENT_FUNCTION ) }
CDBL_RowResult::~CDBL_RowResult() { try { if (m_ColFmt) { delete[] m_ColFmt; m_ColFmt = 0; } if (!m_EOR) Check(dbcanquery(GetCmd())); } NCBI_CATCH_ALL_X( 1, NCBI_CURRENT_FUNCTION ) }
void QTDSResult::cleanup() { d->clearErrorMsgs(); d->rec.clear(); for (int i = 0; i < d->buffer.size() / 2; ++i) free(d->buffer.at(i * 2)); d->buffer.clear(); // "can" stands for "cancel"... very clever. dbcanquery(d->dbproc); dbfreebuf(d->dbproc); QSqlCachedResult::cleanup(); }
static void ngx_dbd_freetds_close(ngx_dbd_t *dbd) { RETCODE rc; ngx_dbd_freetds_ctx_t *ctx; ngx_log_debug0(NGX_LOG_DEBUG_MYSQL, dbd->log, 0, "dbd freetds close"); ctx = dbd->ctx; rc = dbcanquery(ctx->db); /* TODO: rc */ dbclose(ctx->db); }
static VALUE rb_tinytds_result_each(int argc, VALUE * argv, VALUE self) { /* Local Vars */ VALUE qopts, opts, block; ID timezone; int symbolize_keys = 0, as_array = 0, cache_rows = 0, first = 0, empty_sets = 0; tinytds_client_userdata *userdata; GET_RESULT_WRAPPER(self); userdata = (tinytds_client_userdata *)dbgetuserdata(rwrap->client); /* Merge Options Hash To Query Options. Populate Opts & Block Var. */ qopts = rb_iv_get(self, "@query_options"); if (rb_scan_args(argc, argv, "01&", &opts, &block) == 1) qopts = rb_funcall(qopts, intern_merge, 1, opts); rb_iv_set(self, "@query_options", qopts); /* Locals From Options */ if (rb_hash_aref(qopts, sym_first) == Qtrue) first = 1; if (rb_hash_aref(qopts, sym_symbolize_keys) == Qtrue) symbolize_keys = 1; if (rb_hash_aref(qopts, sym_as) == sym_array) as_array = 1; if (rb_hash_aref(qopts, sym_cache_rows) == Qtrue) cache_rows = 1; if (rb_hash_aref(qopts, sym_timezone) == sym_local) { timezone = intern_local; } else if (rb_hash_aref(qopts, sym_timezone) == sym_utc) { timezone = intern_utc; } else { rb_warn(":timezone option must be :utc or :local - defaulting to :local"); timezone = intern_local; } if (rb_hash_aref(qopts, sym_empty_sets) == Qtrue) empty_sets = 1; /* Make The Results Or Yield Existing */ if (NIL_P(rwrap->results)) { RETCODE dbsqlok_rc, dbresults_rc; rwrap->results = rb_ary_new(); dbsqlok_rc = rb_tinytds_result_ok_helper(rwrap->client); dbresults_rc = rb_tinytds_result_dbresults_retcode(self); while ((dbsqlok_rc == SUCCEED) && (dbresults_rc == SUCCEED)) { int has_rows = (DBROWS(rwrap->client) == SUCCEED) ? 1 : 0; if (has_rows || empty_sets || (rwrap->number_of_results == 0)) rb_tinytds_result_fields(self); if ((has_rows || empty_sets) && rwrap->number_of_fields > 0) { /* Create rows for this result set. */ unsigned long rowi = 0; VALUE result = rb_ary_new(); while (nogvl_dbnextrow(rwrap->client) != NO_MORE_ROWS) { VALUE row = rb_tinytds_result_fetch_row(self, timezone, symbolize_keys, as_array); if (cache_rows) rb_ary_store(result, rowi, row); if (!NIL_P(block)) rb_yield(row); if (first) { dbcanquery(rwrap->client); userdata->dbcancel_sent = 1; } rowi++; } rwrap->number_of_rows = rowi; /* Store the result. */ if (cache_rows) { if (rwrap->number_of_results == 0) { rwrap->results = result; } else if (rwrap->number_of_results == 1) { VALUE multi_resultsets = rb_ary_new(); rb_ary_store(multi_resultsets, 0, rwrap->results); rb_ary_store(multi_resultsets, 1, result); rwrap->results = multi_resultsets; } else { rb_ary_store(rwrap->results, rwrap->number_of_results, result); } } // If we find results increment the counter that helpers use and setup the next loop. rwrap->number_of_results = rwrap->number_of_results + 1; dbresults_rc = rb_tinytds_result_dbresults_retcode(self); rb_ary_store(rwrap->fields_processed, rwrap->number_of_results, Qnil); } else { // If we do not find results, side step the rb_tinytds_result_dbresults_retcode helper and // manually populate its memoized array while nullifing any memoized fields too before loop. dbresults_rc = nogvl_dbresults(rwrap->client); rb_ary_store(rwrap->dbresults_retcodes, rwrap->number_of_results, INT2FIX(dbresults_rc)); rb_ary_store(rwrap->fields_processed, rwrap->number_of_results, Qnil); } } if (dbresults_rc == FAIL) rb_warn("TinyTDS: Something in the dbresults() while loop set the return code to FAIL.\n"); userdata->dbsql_sent = 0; } else if (!NIL_P(block)) { unsigned long i; for (i = 0; i < rwrap->number_of_rows; i++) { rb_yield(rb_ary_entry(rwrap->results, i)); } } return rwrap->results; }