Exemple #1
0
/**
 * 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;
}
Exemple #2
0
/* {{{ 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);
		}
	}
}
Exemple #3
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()");
				}
			}
		}
Exemple #4
0
bool f_mysql_more_results(CVarRef link_identifier /* = null */) {
  MYSQL *conn = MySQL::GetConn(link_identifier);
  if (conn == nullptr) {
    return false;
  }
  return mysql_more_results(conn);
}
Exemple #5
0
static bool HHVM_FUNCTION(mysql_more_results,
                   const Variant& link_identifier /* = null */) {
  MYSQL *conn = MySQL::GetConn(link_identifier);
  if (conn == nullptr) {
    return false;
  }
  return mysql_more_results(conn);
}
Exemple #6
0
/* call-seq:
 *    client.more_results?
 *
 * Returns true or false if there are more results to process.
 */
static VALUE rb_mysql_client_more_results(VALUE self)
{
  GET_CLIENT(self);
    if (mysql_more_results(wrapper->client) == 0)
      return Qfalse;
    else
      return Qtrue;
}
Exemple #7
0
bool 
Query::more_results()
{
#if MYSQL_VERSION_ID > 41000		// only in MySQL v4.1 +
	return mysql_more_results(&conn_->mysql_);
#else
	return false;
#endif
}
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());
}
ResultSet* MySQLPreparedStatement::getResultSet()
{
    checkClosed();

    if (mysql_more_results(stmt->mysql))
        mysql_next_result(stmt->mysql);

    return new MySQLPreparedResultSet(this, stmt);
}
Exemple #10
0
SEXP RS_MySQL_moreResultSets(SEXP conHandle) {
  RS_DBI_connection *con;
  MYSQL             *my_connection;
  my_bool           tmp;

  con = RS_DBI_getConnection(conHandle);
  my_connection = (MYSQL *) con->drvConnection;

  tmp = mysql_more_results(my_connection);
  return ScalarLogical(tmp);
}
Exemple #11
0
void MySQLQuery::ClearMoreResult()
{
    MYSQL* pConn= m_sqlConn->getConn ();
    if ( !pConn)
    {
        return ;
    }
    while ( mysql_more_results(pConn) )
    {
        mysql_next_result(pConn);
    }
}
Exemple #12
0
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);
}
Exemple #13
0
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);
}
Exemple #14
0
        bool mysql_resultset::next()
        {
            if (res_ == NULL || !db_->is_open())
                return false;

            bool value = (row_ = mysql_fetch_row(res_)) != NULL;

            if (!value && !mysql_more_results(db_->db_))
            {
                mysql_free_result(res_);
                if ((res_ = mysql_use_result(db_->db_)) != NULL)
                    value = (row_ = mysql_fetch_row(res_)) != NULL;
            }

            return value;
        }
PreparedResultSet* MySqlConnection::Query(PreparedStmt* 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);
	}
	PreparedResultSet* pResultSet =  new PreparedResultSet(stmt->m_pStmt->GetMySqlStmt(), result, rowCount, fieldCount);
	M_CHECKIN(pResultSet);

	return pResultSet;
}
Exemple #16
0
/* call-seq:
 *    client.abandon_results!
 *
 * When using MULTI_STATEMENTS support, calling this will throw
 * away any unprocessed results as fast as it can in order to
 * put the connection back into a state where queries can be issued
 * again.
 */
static VALUE rb_mysql_client_abandon_results(VALUE self) {
  MYSQL_RES *result;
  int ret;

  GET_CLIENT(self);

  while (mysql_more_results(wrapper->client) == 1) {
    ret = mysql_next_result(wrapper->client);
    if (ret > 0) {
      rb_raise_mysql2_error(wrapper);
    }

    result = (MYSQL_RES *)rb_thread_call_without_gvl(nogvl_store_result, wrapper, RUBY_UBF_IO, 0);

    if (result != NULL) {
      mysql_free_result(result);
    }
  }

  return Qnil;
}
bool MyQuery::FetchMoreResults()
{
	if (m_rs.m_pRes == NULL)
	{
		return false;
	} else if (!mysql_more_results(m_pParent->m_mysql)) {
		return false;
	}

	mysql_free_result(m_rs.m_pRes);
	m_rs.m_pRes = NULL;

	if (mysql_next_result(m_pParent->m_mysql) != 0)
	{
		return false;
	}

	m_rs.m_pRes = mysql_store_result(m_pParent->m_mysql);
	m_rs.Update();

	return (m_rs.m_pRes != NULL);
}
Exemple #18
0
static package bf_mysql_query( Var arglist, Byte next, void *vdata, Objid progr)
{
  Var r;
  char error_string[MOOSQL_ERROR_LEN];
  MYSQL_CONN *wrapper;
  MYSQL_RES *res_set;
#ifdef MOOSQL_MULTIPLE_STATEMENTS
  Var tmp;
  Var end;
  int len = 0; 
  int continu = 1;
#endif
  if (!is_wizard(progr))
    {
      free_var(arglist);
      return make_error_pack(E_PERM);
    }
  Objid oid = arglist.v.list[1].v.obj;
  wrapper = resolve_mysql_connection(oid);
  if (wrapper == NULL || wrapper->conn == NULL || wrapper->active == 0)
    {
      free_var(arglist);
      return make_error_pack(E_INVARG);
    }
  const char *query = arglist.v.list[2].v.str;
  free_var(arglist);
  /* we do the query now. */
  if (mysql_query (wrapper->conn, query) != 0)   /* failed */
   {
     /* there is an error, so we will return that string. similar to below which
      * returns a string for a successful query with no result set which is handled in
      * process_mysql_query */
     snprintf(error_string,MOOSQL_ERROR_LEN,"ERR: %s",mysql_error(wrapper->conn));
     r.type = TYPE_STR;
     r.v.str = str_dup(error_string);
     return make_var_pack(r);
   }
  wrapper->last_query_time = time(0);
#ifdef MOOSQL_MULTIPLE_STATEMENTS
  r = new_list(1);
  r.v.list[1].type = TYPE_INT;
  r.v.list[1].v.num = 0;
  end = new_list(0);
  while (continu)
    {
      len++;
      res_set = process_mysql_query(wrapper,error_string);
      if (res_set == NULL) /* there was no result on this query */
	{
	  tmp.type = TYPE_STR;
	  tmp.v.str = str_dup(error_string);
	  end = listappend(end,var_dup(tmp));
	}
      else 
	{
	  tmp = process_result_set(wrapper,res_set);
	  end = listappend(end,var_dup(tmp));
	}
      if (mysql_more_results(wrapper->conn))
	{
	  mysql_next_result(wrapper->conn);
	  continu = 1;
	}
      else
	continu = 0;
    }
  if (len <= 1) /* if there is only one result return it like in previous versions, a list of rows */
    return make_var_pack(end.v.list[1]);
  r.v.list[1].v.num = len;
  /* if there are more return it in this format {X, Y} where X is the number of results and Y is a list of results */
  r = listappend(r,end); 
  return make_var_pack(r);
#else
  res_set = process_mysql_query(wrapper,error_string);

  if (res_set == NULL) /* there was either an error / no result on this query */
    {
      r.type = TYPE_STR;
      r.v.str = str_dup(error_string);
      return make_var_pack(r);
    }
  r = process_result_set(wrapper,res_set); 
  return make_var_pack(r);
#endif

}