/** * Retrieve a result set * \param _h handle to the database * \param _r result set that should be retrieved * \return zero on success, negative value on failure */ static int db_mysql_store_result(const db1_con_t* _h, db1_res_t** _r) { int code; if ((!_h) || (!_r)) { LM_ERR("invalid parameter value\n"); return -1; } *_r = db_mysql_new_result(); if (*_r == 0) { LM_ERR("no memory left\n"); return -2; } RES_RESULT(*_r) = mysql_store_result(CON_CONNECTION(_h)); if (!RES_RESULT(*_r)) { if (mysql_field_count(CON_CONNECTION(_h)) == 0) { (*_r)->col.n = 0; (*_r)->n = 0; goto done; } else { LM_ERR("driver error: %s\n", mysql_error(CON_CONNECTION(_h))); code = mysql_errno(CON_CONNECTION(_h)); if (code == CR_SERVER_GONE_ERROR || code == CR_SERVER_LOST) { counter_inc(mysql_cnts_h.driver_err); } db_mysql_free_result(_h, *_r); *_r = 0; return -3; } } if (db_mysql_convert_result(_h, *_r) < 0) { LM_ERR("error while converting result\n"); LM_DBG("freeing result set at %p\n", _r); /* all mem on Kamailio API side is already freed by * db_mysql_convert_result in case of error, but we also need * to free the mem from the mysql lib side, internal pkg for it * and *_r */ db_mysql_free_result(_h, *_r); *_r = 0; #if (MYSQL_VERSION_ID >= 40100) while( mysql_more_results(CON_CONNECTION(_h)) && mysql_next_result(CON_CONNECTION(_h)) == 0 ) { MYSQL_RES *res = mysql_store_result( CON_CONNECTION(_h) ); mysql_free_result(res); } #endif return -4; } done: #if (MYSQL_VERSION_ID >= 40100) while( mysql_more_results(CON_CONNECTION(_h)) && mysql_next_result(CON_CONNECTION(_h)) == 0 ) { MYSQL_RES *res = mysql_store_result( CON_CONNECTION(_h) ); mysql_free_result(res); } #endif return 0; }
/** Reads COM_SELECT and COM_INSERT variables from all nodes and stores into 'selects' and 'inserts' */ int get_global_status_allnodes(int *selects, int *inserts, Mariadb_nodes * nodes, int silent) { int i; MYSQL_RES *res; MYSQL_ROW row; for (i=0; i< nodes->N; i++) { if (nodes->nodes[i] != NULL) { if(mysql_query(nodes->nodes[i], "show global status like 'COM_SELECT';") != 0) printf("Error: can't execute SQL-query\n"); res = mysql_store_result(nodes->nodes[i]); if(res == NULL) printf("Error: can't get the result description\n"); if(mysql_num_rows(res) > 0) { while((row = mysql_fetch_row(res)) != NULL) { if (silent == 0) {printf("Node %d COM_SELECT=%s\n", i, row[1]);} sscanf(row[1], "%d", &selects[i]); } } mysql_free_result(res); while ( mysql_next_result(nodes->nodes[i]) == 0 ) { res = mysql_store_result(nodes->nodes[i]); mysql_free_result(res); } if(mysql_query(nodes->nodes[i], "show global status like 'COM_INSERT';") != 0) printf("Error: can't execute SQL-query\n"); res = mysql_store_result(nodes->nodes[i]); if(res == NULL) printf("Error: can't get the result description\n"); if(mysql_num_rows(res) > 0) { while((row = mysql_fetch_row(res)) != NULL) { if (silent == 0) {printf("Node %d COM_INSERT=%s\n", i, row[1]);} sscanf(row[1], "%d", &inserts[i]); } } mysql_free_result(res); while ( mysql_next_result(nodes->nodes[i]) == 0 ) { res = mysql_store_result(nodes->nodes[i]); mysql_free_result(res); } } else { selects[i] = 0; inserts[i] = 0; } } return(0); }
/* * Retrieve result set */ static int db_mysql_store_result(db_con_t* _h, db_res_t** _r) { if ((!_h) || (!_r)) { LM_ERR("invalid parameter value\n"); return -1; } *_r = db_new_result(); if (*_r == 0) { LM_ERR("no memory left\n"); return -2; } CON_RESULT(_h) = mysql_store_result(CON_CONNECTION(_h)); if (!CON_RESULT(_h)) { if (mysql_field_count(CON_CONNECTION(_h)) == 0) { (*_r)->col.n = 0; (*_r)->n = 0; goto done; } else { LM_ERR("driver error: %s\n", mysql_error(CON_CONNECTION(_h))); db_mysql_free_dbresult(*_r); *_r = 0; return -3; } } if (db_mysql_convert_result(_h, *_r) < 0) { LM_ERR("error while converting result\n"); pkg_free(*_r); *_r = 0; /* all mem on openser API side is already freed by * db_mysql_convert_result in case of error, but we also need * to free the mem from the mysql lib side */ mysql_free_result(CON_RESULT(_h)); #if (MYSQL_VERSION_ID >= 40100) while( mysql_next_result( CON_CONNECTION(_h) ) > 0 ) { MYSQL_RES *res = mysql_store_result( CON_CONNECTION(_h) ); mysql_free_result( res ); } #endif CON_RESULT(_h) = 0; return -4; } done: #if (MYSQL_VERSION_ID >= 40100) while( mysql_next_result( CON_CONNECTION(_h) ) > 0 ) { MYSQL_RES *res = mysql_store_result( CON_CONNECTION(_h) ); mysql_free_result( res ); } #endif return 0; }
static int UdmMySQLQuery(UDM_DB *db,UDM_SQLRES *R,const char *query) { int rc= UdmMySQLExecDirect(db, R, query); if (rc != UDM_OK) return rc; if (!R->specific) return UDM_OK; rc= UdmMySQLStoreResult(db, R); #if (MYSQL_VERSION_ID > 40100) { UDM_MYSQL *mydb= (UDM_MYSQL*) db->specific; while (mysql_next_result(db->specific) == 0) { MYSQL_RES *res; if ((res= mysql_store_result(&mydb->mysql))) { mysql_free_result(res); } else { /* Non-select query */ } } } #endif return rc; }
quint64 CMySqlDatabase::GetRowData( QStringList& lstRows, QString& strError ) { lstRows.clear( ); my_ulonglong nRows = 0; MYSQL_RES* pRowSet = NULL; unsigned int nFields = 0; MYSQL_ROW row = NULL; do { // MultiStatement MultiResult pRowSet = mysql_store_result( &hConnect ); if ( NULL == pRowSet ) { GetErrorMsg( 0, strError, true, strError ); // return 0; } else { nRows += mysql_num_rows( pRowSet ); // Row nFields = mysql_num_fields( pRowSet ); //Column // mysql_fetch_lengths( ) field length while ( NULL != ( row = mysql_fetch_row( pRowSet ) ) ) { // One Resultset for ( unsigned int nIndex = 0; nIndex < nFields; nIndex++ ){ qDebug( ) << row[ nIndex ] << endl; lstRows << row[ nIndex ]; } } mysql_free_result( pRowSet ); } } while ( mysql_next_result( &hConnect ) == 0 ) ; return nRows; }
/* {{{ mysql_handle_doer */ static zend_long mysql_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; PDO_DBG_ENTER("mysql_handle_doer"); PDO_DBG_INF_FMT("dbh=%p", dbh); PDO_DBG_INF_FMT("sql=%.*s", (int)sql_len, sql); if (mysql_real_query(H->server, sql, sql_len)) { pdo_mysql_error(dbh); PDO_DBG_RETURN(-1); } else { my_ulonglong c = mysql_affected_rows(H->server); if (c == (my_ulonglong) -1) { pdo_mysql_error(dbh); PDO_DBG_RETURN(H->einfo.errcode ? -1 : 0); } else { /* MULTI_QUERY support - eat up all unfetched result sets */ MYSQL_RES* result; while (mysql_more_results(H->server)) { if (mysql_next_result(H->server)) { PDO_DBG_RETURN(1); } result = mysql_store_result(H->server); if (result) { mysql_free_result(result); } } PDO_DBG_RETURN((int)c); } } }
static int test_bug12001(MYSQL *mysql) { MYSQL_RES *result; const char *query= "DROP TABLE IF EXISTS test_table;" "CREATE TABLE test_table(id INT);" "INSERT INTO test_table VALUES(10);" "UPDATE test_table SET id=20 WHERE id=10;" "SELECT * FROM test_table;" "INSERT INTO non_existent_table VALUES(11);"; int rc, res; rc= mysql_query(mysql, query); check_mysql_rc(rc, mysql); do { if (mysql_field_count(mysql) && (result= mysql_use_result(mysql))) { mysql_free_result(result); } } while (!(res= mysql_next_result(mysql))); rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_table"); check_mysql_rc(rc, mysql); FAIL_UNLESS(res==1, "res != 1"); return OK; }
/************************************************************************* * * Function: sql_store_result * * Purpose: database specific store_result function. Returns a result * set for the query. In case of multiple results, get the * first non-empty one. * *************************************************************************/ static int sql_store_result(SQLSOCK * sqlsocket, UNUSED SQL_CONFIG *config) { rlm_sql_mysql_sock *mysql_sock = sqlsocket->conn; int status; if (mysql_sock->sock == NULL) { radlog(L_ERR, "rlm_sql_mysql: Socket not connected"); return SQL_DOWN; } retry_store_result: if (!(mysql_sock->result = mysql_store_result(mysql_sock->sock))) { status = sql_check_error(mysql_errno(mysql_sock->sock)); if (status != 0) { radlog(L_ERR, "rlm_sql_mysql: Cannot store result"); radlog(L_ERR, "rlm_sql_mysql: MySQL error '%s'", mysql_error(mysql_sock->sock)); return status; } #if (MYSQL_VERSION_ID >= 40100) status = mysql_next_result(mysql_sock->sock); if (status == 0) { /* there are more results */ goto retry_store_result; } else if (status > 0) { radlog(L_ERR, "rlm_sql_mysql: Cannot get next result"); radlog(L_ERR, "rlm_sql_mysql: MySQL error '%s'", mysql_error(mysql_sock->sock)); return sql_check_error(status); } #endif } return 0; }
MySQLResult::~MySQLResult() { if (_result) mysql_free_result(_result); boost::recursive_mutex::scoped_lock lock(_db->_connectionMutex); // Consume remaining results in case of a multi statement query. // TODO: the remainding queries should also be available through the API. int status; while (mysql_more_results(_db->_connection)) { if ((status = mysql_next_result(_db->_connection)) == -1) { break; } if (status > 0) { _db->_throwException("Could not execute statement"); } MYSQL_RES *res = mysql_store_result(_db->_connection); if (res) { mysql_free_result(res); } else { _db->_throwException("MySQL error in mysql_store_result()"); } } }
int main(int argc, char* argv[]) { MYSQL *mysql,*sock; MYSQL_ROW row; MYSQL_RES *result; mysql = mysql_init(NULL); if (!(sock = CONN(CLIENT_MULTI_STATEMENTS))) { fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); perror(""); exit(1); } char *sql = "select 1;select * from n"; mysql_query(sock, sql); do { printf("total affected rows: %lld\n", mysql_affected_rows(sock)); if (!(result= mysql_store_result(sock))) { printf("Got fatal error processing query\n"); exit(1); } row = mysql_fetch_row(result); printf("%s\n", row[0]); mysql_free_result(result); } while (!mysql_next_result(sock)); return 0; }
/************************************************************************* * * Function: sql_finish_query * * Purpose: As a single SQL statement may return multiple results * sets, (for example stored procedures) it is necessary to check * whether more results exist and process them in turn if so. * *************************************************************************/ static int sql_finish_query(SQLSOCK * sqlsocket, UNUSED SQL_CONFIG *config) { #if (MYSQL_VERSION_ID >= 40100) rlm_sql_mysql_sock *mysql_sock = sqlsocket->conn; int status; skip_next_result: status = sql_store_result(sqlsocket, config); if (status != 0) { return status; } else if (mysql_sock->result != NULL) { radlog(L_DBG, "rlm_sql_mysql: SQL statement returned unexpected result"); sql_free_result(sqlsocket, config); } status = mysql_next_result(mysql_sock->sock); if (status == 0) { /* there are more results */ goto skip_next_result; } else if (status > 0) { radlog(L_ERR, "rlm_sql_mysql: Cannot get next result"); radlog(L_ERR, "rlm_sql_mysql: MySQL error '%s'", mysql_error(mysql_sock->sock)); return sql_check_error(status); } #endif return 0; }
/************************************************************************* * * Function: sql_store_result * * Purpose: database specific store_result function. Returns a result * set for the query. In case of multiple results, get the * first non-empty one. * *************************************************************************/ static sql_rcode_t sql_store_result(rlm_sql_handle_t * handle, UNUSED rlm_sql_config_t *config) { rlm_sql_mysql_conn_t *conn = handle->conn; int status; if (!conn->sock) { ERROR("rlm_sql_mysql: Socket not connected"); return RLM_SQL_RECONNECT; } retry_store_result: if (!(conn->result = mysql_store_result(conn->sock))) { status = sql_check_error(mysql_errno(conn->sock)); if (status != 0) { ERROR("rlm_sql_mysql: Cannot store result"); ERROR("rlm_sql_mysql: MySQL error '%s'", mysql_error(conn->sock)); return status; } #if (MYSQL_VERSION_ID >= 40100) status = mysql_next_result(conn->sock); if (status == 0) { /* there are more results */ goto retry_store_result; } else if (status > 0) { ERROR("rlm_sql_mysql: Cannot get next result"); ERROR("rlm_sql_mysql: MySQL error '%s'", mysql_error(conn->sock)); return sql_check_error(status); } #endif } return 0; }
std::shared_ptr<DataItem> Command::ExecuteScalar() { std::shared_ptr<DataItem> ret = nullptr; std::vector<std::string> multi_query = SplitMultiQuery(); for (auto& query : multi_query) { if (mysql_query(&m_conn->m_mysql, query.c_str()) != 0) { Log::DbErr(&m_conn->m_mysql, query); return nullptr; } MYSQL_RES* res = mysql_store_result(&m_conn->m_mysql); if (res) { uint32_t cols = mysql_num_fields(res); MYSQL_FIELD* field = mysql_fetch_fields(res); if (cols > 0 && field) { std::shared_ptr<DataField> data_field(new DataField(field[0])); MYSQL_ROW row = mysql_fetch_row(res); if (row && mysql_num_rows(res) > 0) { if (row[0]) { ret = std::shared_ptr<DataItem>(new DataItem(data_field)); ret->SetData((char*)row[0]); } } mysql_free_result(res); do { MYSQL_RES* res = mysql_store_result(&m_conn->m_mysql); mysql_free_result(res); } while (!mysql_next_result(&m_conn->m_mysql)); } } } return ret; }
/************************************************************************* * * Function: sql_finish_query * * Purpose: As a single SQL statement may return multiple results * sets, (for example stored procedures) it is necessary to check * whether more results exist and process them in turn if so. * *************************************************************************/ static int sql_finish_query(rlm_sql_handle_t * handle, UNUSED rlm_sql_config_t *config) { #if (MYSQL_VERSION_ID >= 40100) rlm_sql_mysql_conn_t *conn = handle->conn; int status; skip_next_result: status = sql_store_result(handle, config); if (status != 0) { return status; } else if (conn->result != NULL) { radlog(L_DBG, "rlm_sql_mysql: SQL statement returned unexpected result"); sql_free_result(handle, config); } status = mysql_next_result(conn->sock); if (status == 0) { /* there are more results */ goto skip_next_result; } else if (status > 0) { radlog(L_ERR, "rlm_sql_mysql: Cannot get next result"); radlog(L_ERR, "rlm_sql_mysql: MySQL error '%s'", mysql_error(conn->sock)); return sql_check_error(status); } #endif return 0; }
PreparedResultSet* MySQLConnection::Query(PreparedStatement* stmt) { this->Execute(stmt); if (mysql_more_results(m_Mysql)) { mysql_next_result(m_Mysql); } return new PreparedResultSet(stmt->m_stmt->GetSTMT()); }
static VALUE rb_mysql_client_next_result(VALUE self) { GET_CLIENT(self); int ret; ret = mysql_next_result(wrapper->client); if (ret == 0) return Qtrue; return Qfalse; }
ResultSet* MySQLPreparedStatement::getResultSet() { checkClosed(); if (mysql_more_results(stmt->mysql)) mysql_next_result(stmt->mysql); return new MySQLPreparedResultSet(this, stmt); }
static int test_bug15752(MYSQL *mysql) { int rc, i; const int ITERATION_COUNT= 100; const char *query= "CALL p1()"; rc= mysql_query(mysql, "drop procedure if exists p1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create procedure p1() select 1"); check_mysql_rc(rc, mysql); rc= mysql_real_query(mysql, query, strlen(query)); check_mysql_rc(rc, mysql); mysql_free_result(mysql_store_result(mysql)); rc= mysql_real_query(mysql, query, strlen(query)); FAIL_UNLESS(rc && mysql_errno(mysql) == CR_COMMANDS_OUT_OF_SYNC, "Error expected"); rc= mysql_next_result(mysql); check_mysql_rc(rc, mysql); mysql_free_result(mysql_store_result(mysql)); rc= mysql_next_result(mysql); FAIL_IF(rc != -1, "rc != -1"); for (i = 0; i < ITERATION_COUNT; i++) { rc= mysql_real_query(mysql, query, strlen(query)); check_mysql_rc(rc, mysql); mysql_free_result(mysql_store_result(mysql)); rc= mysql_next_result(mysql); check_mysql_rc(rc, mysql); mysql_free_result(mysql_store_result(mysql)); rc= mysql_next_result(mysql); FAIL_IF(rc != -1, "rc != -1"); } rc= mysql_query(mysql, "drop procedure p1"); check_mysql_rc(rc, mysql); return OK; }
int Mariadb_nodes::check_replication(int master) { int res1 = 0; char str[1024]; MYSQL *conn; MYSQL_RES *res; printf("Checking Master/Slave setup\n"); fflush(stdout); for (int i = 0; i < N; i++) { conn = open_conn(port[i], IP[i], user_name, password, ssl); if (mysql_errno(conn) != 0) { printf("Error connectiong node %d\n", i); fflush(stdout); res1 = 1; } else { if ( i == master ) { // checking master if (conn != NULL ) { if(mysql_query(conn, (char *) "SHOW SLAVE HOSTS;") != 0) { printf("%s\n", mysql_error(conn)); res1 = 1; } else { res = mysql_store_result(conn); if(res == NULL) { printf("Error: can't get the result description\n"); fflush(stdout); res1 = 1; } else { if (mysql_num_rows(res) != N-1) { printf("Number if slaves is not equal to N-1\n"); fflush(stdout); res1 = 1; } } mysql_free_result(res); do { res = mysql_store_result(conn); mysql_free_result(res); } while ( mysql_next_result(conn) == 0 ); } } } else { // checking slave if (find_field(conn, (char *) "SHOW SLAVE STATUS;", (char *) "Slave_IO_Running", str) != 0) { printf("Slave_IO_Running is not found in SHOW SLAVE STATUS results\n"); fflush(stdout); res1 = 1; } else { if (strcmp(str, "Yes") !=0 ) { printf("Slave_IO_Running is not Yes\n"); fflush(stdout); res1 = 1; } } } } mysql_close(conn); } return(res1); }
void process_multi_statement (MYSQL *conn, char *stmt_str) { MYSQL_RES *res_set; int status; int keep_going = 1; if (mysql_query (conn, stmt_str) != 0) /* the statement(s) failed */ { print_error (conn, "Could not execute statement(s)"); return; } /* the statement(s) succeeded; enter result-retrieval loop */ do { /* determine whether current statement returned data */ res_set = mysql_store_result (conn); if (res_set) /* a result set was returned */ { /* process rows and free the result set */ process_result_set (conn, res_set); mysql_free_result (res_set); } else /* no result set was returned */ { /* * does the lack of a result set mean that the statement didn't * return one, or that it should have but an error occurred? */ if (mysql_field_count (conn) == 0) { /* * statement generated no result set (it was not a SELECT, * SHOW, DESCRIBE, etc.); just report rows-affected value. */ printf ("Number of rows affected: %lu\n", (unsigned long) mysql_affected_rows (conn)); } else /* an error occurred */ { print_error (conn, "Could not retrieve result set"); keep_going = 0; } } /* determine whether more results exist */ /* 0 = yes, -1 = no, >0 = error */ status = mysql_next_result (conn); if (status != 0) /* no more results, or an error occurred */ { keep_going = 0; if (status > 0) /* error */ print_error (conn, "Could not execute statement"); } } while (keep_going); }
// perform sql statement db_query_basic::list_rec_set_t db_query_basic::perform(std::string query) { if (query.empty()) return list_rec_set_t(); // replace "%table_name%" to table_name //query = std::regex_replace(query, std::regex("\\%table_name%"), _table); int ret = mysql_real_query(_db.conn(), query.c_str(), static_cast<unsigned long>(query.length())); assert_ret(ret); list_rec_set_t list_rec_set; int status = 0; do { size_t num_col = mysql_field_count(_db.conn()); MYSQL_RES* res = mysql_store_result(_db.conn()); size_t affected = static_cast<size_t>(mysql_affected_rows(_db.conn())); if (res == nullptr) { // raise exception if result is supposed to be returned if (num_col > 0) throw ex_db_mariadb(_db.conn()); db_record_meta::list_column_t list_col_empty; db_record_meta meta_empty(list_col_empty); db_record_set rec_set_empty(meta_empty); rec_set_empty._affected = affected; list_rec_set.push_back(rec_set_empty); } else // when MYSQL_RES* available { MYSQL_FIELD* p_col = mysql_fetch_fields(res); db_record_set rec_set(db_record_meta(p_col, num_col)); for (size_t idx_row = 0; idx_row < res->row_count; idx_row++) { assert_res(res); const MYSQL_ROW row = mysql_fetch_row(res); assert_row(row); record_t rec_d = rec_set.record_new(); for (size_t idx_col = 0; idx_col < num_col; idx_col++) rec_d[idx_col] = (row[idx_col] == nullptr ? "" : row[idx_col]); rec_set.list_record().push_back(rec_d); } rec_set._affected = res->row_count; list_rec_set.push_back(rec_set); mysql_free_result(res); } // check whether there are more result sets: // status > 0 error occurred; // status = 0 more result sets returned; // status < 0 no next result set; if ((status = mysql_next_result(_db.conn())) > 0) throw ex_db_mariadb(_db.conn()); } while (status == 0); return list_rec_set; }
//执行数据操作语言(DML)类语句 bool CMysqlStore::Query(const std::string &dml) { //清除缓冲 Clear(); if(mysql_query(m_connptr,dml.c_str()) != 0) //if(mysql_real_query(m_connptr,dml.c_str(), dml.length()) != 0) { m_err = mysql_error(m_connptr); return false; } do { m_resultptr = mysql_store_result(m_connptr); if(m_resultptr == NULL) continue; //得到查询返回的行数 m_row += (unsigned long)mysql_affected_rows(m_connptr); //指向 mysql 的查询字段集 MYSQL_FIELD *fieldptr = NULL; //取得各字段名和类型 while(fieldptr = mysql_fetch_field(m_resultptr)) { typeset_t typeset; typeset.index = (unsigned int)m_fieldtype.size(); typeset.length = fieldptr->length; typeset.name = fieldptr->name; typeset.type = SetFieldType(fieldptr->type); m_fieldtype.push_back(typeset); } MYSQL_ROW currrow = NULL; while((currrow = mysql_fetch_row(m_resultptr))) { //读行的记录 const unsigned int colcount = mysql_num_fields(m_resultptr); m_colcount = colcount; row_t rows(colcount); for(unsigned int i = 0; i < colcount; ++i) { rows[i] = currrow[i] ? currrow[i] : "NULL"; } m_recordset.push_back(rows); } mysql_free_result(m_resultptr); m_resultptr = NULL; } while(!mysql_next_result(m_connptr)); return true; }
void MySQLQuery::ClearMoreResult() { MYSQL* pConn= m_sqlConn->getConn (); if ( !pConn) { return ; } while ( mysql_more_results(pConn) ) { mysql_next_result(pConn); } }
Result Query::store_next() { #if MYSQL_VERSION_ID > 41000 // only in MySQL v4.1 + if (lock()) { if (throw_exceptions()) { throw LockFailed(); } else { return Result(); } } int ret; if ((ret = mysql_next_result(&conn_->mysql_)) == 0) { // There are more results, so return next result set. MYSQL_RES* res = mysql_store_result(&conn_->mysql_); unlock(); if (res) { return Result(res, throw_exceptions()); } else { // Result set is null, but throw an exception only i it is // null because of some error. If not, it's just an empty // result set, which is harmless. We return an empty result // set if exceptions are disabled, as well. if (conn_->errnum() && throw_exceptions()) { throw BadQuery(error()); } else { return Result(); } } } else { // No more results, or some other error occurred. unlock(); if (throw_exceptions()) { if (ret > 0) { throw BadQuery(error()); } else { throw EndOfResultSets(); } } else { return Result(); } } #else return store(); #endif // MySQL v4.1+ }
int f_mysql_next_result(CVarRef link_identifier /* = null */) { MYSQL *conn = MySQL::GetConn(link_identifier); if (conn == nullptr) { return 2006 /* CR_SERVER_GONE_ERROR */; } if (!mysql_more_results(conn)) { raise_strict_warning("There is no next result set. " "Please, call mysql_more_results() to check " "whether to call this function/method"); } return mysql_next_result(conn); }
bool SQL::GetResult(SqlTable &table) { if (mysql_next_result(m_MYSQL)) { MYSQL_RES *pRes; pRes = mysql_store_result(m_MYSQL); bool bRet = table.InitFromSqlData(TABLE_USERTABLE, m_pMySQL, pRes); mysql_free_result(pRes); return true; } else return false; }
SEXP RS_MySQL_nextResultSet(SEXP conHandle) { RS_DBI_resultSet *result; SEXP rsHandle; int num_fields, is_select; RS_DBI_connection* con = RS_DBI_getConnection(conHandle); MYSQL* my_connection = con->drvConnection; int rc = mysql_next_result(my_connection); if (rc < 0) { error("no more result sets"); } else if (rc > 0){ error("error in getting next result set"); } /* the following comes verbatim from RS_MySQL_exec() */ MYSQL_RES* my_result = mysql_use_result(my_connection); if (!my_result) my_result = NULL; num_fields = mysql_field_count(my_connection); is_select = TRUE; if (!my_result) { if (num_fields > 0) { error("error in getting next result set"); } else { is_select = FALSE; } } /* we now create the wrapper and copy values */ rsHandle = RS_DBI_allocResultSet(conHandle); result = RS_DBI_getResultSet(rsHandle); result->statement = RS_DBI_copyString("<UNKNOWN>"); result->drvResultSet = (void *) my_result; result->rowCount = (int) 0; result->isSelect = is_select; if (!is_select){ result->rowsAffected = (int) mysql_affected_rows(my_connection); result->completed = 1; } else { result->rowsAffected = (int) -1; result->completed = 0; } if (is_select) result->fields = RS_MySQL_createDataMappings(rsHandle); return rsHandle; }
/* call-seq: * client.next_result * * Fetch the next result set from the server. * Returns nothing. */ static VALUE rb_mysql_client_next_result(VALUE self) { int ret; GET_CLIENT(self); ret = mysql_next_result(wrapper->client); if (ret > 0) { rb_raise_mysql2_error(wrapper); return Qfalse; } else if (ret == 0) { return Qtrue; } else { return Qfalse; } }
bool SQL::Excute(const char *sql, UINT &rowCount) { if (mysql_query(m_MYSQL, sql) == 0) { rowCount = (UINT)mysql_affected_rows(m_MYSQL); while (!mysql_next_result(m_MYSQL)); return true; } else { Log("ExcuteSql Error:%s, msg:%s", sql, mysql_error(m_MYSQL) ); return false; } }
PreparedResultSet* MySQLConnection::Query(PreparedStatement* stmt) { MYSQL_RES *result = NULL; uint64 rowCount = 0; uint32 fieldCount = 0; if (!_Query(stmt, &result, &rowCount, &fieldCount)) return NULL; if (mysql_more_results(m_Mysql)) { mysql_next_result(m_Mysql); } return new PreparedResultSet(stmt->m_stmt->GetSTMT(), result, rowCount, fieldCount); }