Exemple #1
0
static VALUE rb_mysql_client_warning_count(VALUE self) {
  unsigned int warning_count;
  GET_CLIENT(self);

  warning_count = mysql_warning_count(wrapper->client);

  return UINT2NUM(warning_count);
}
static int test_conc70(MYSQL *my)
{
  int rc;
  MYSQL_RES *res;
  MYSQL_ROW row;
  MYSQL *mysql;

  SKIP_CONNECTION_HANDLER;

  mysql= mysql_init(NULL);

  rc= mysql_query(my, "SET @a:=@@max_allowed_packet");
  check_mysql_rc(rc, my);

  mysql_query(my, "SET global max_allowed_packet=1024*1024*22");

  mysql_options(mysql, MYSQL_OPT_COMPRESS, (void *)1);
  FAIL_IF(!mysql_real_connect(mysql, hostname, username, password, schema,
                         port, socketname, 0), mysql_error(my));

  rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
  check_mysql_rc(rc, mysql);

  rc= mysql_query(mysql, "CREATE TABLE t1 (a LONGBLOB) engine=MyISAM");
  check_mysql_rc(rc, mysql);

  rc= mysql_query(mysql, "INSERT INTO t1 VALUES (REPEAT('A', 1024 * 1024 * 20))");
  check_mysql_rc(rc, mysql); 

  if (mysql_warning_count(mysql))
  {
    diag("server doesn't accept package size");
    return SKIP;
  }

  sleep(20);

  rc= mysql_query(mysql, "SELECT a FROM t1");
  check_mysql_rc(rc, mysql);

  if (!(res= mysql_store_result(mysql)))
  {
    diag("Error: %s", mysql_error(mysql));
    return FAIL;
  }

  row= mysql_fetch_row(res);
  diag("Length: %ld", strlen(row[0]));
  FAIL_IF(strlen(row[0]) != 1024 * 1024 * 20, "Wrong length");

  mysql_free_result(res);
  mysql_close(mysql);

  rc= mysql_query(my, "SET global max_allowed_packet=@a");
  check_mysql_rc(rc, my);

  return OK;
}
Exemple #3
0
void my_process_warnings(MYSQL *conn, unsigned expected_warning_count)
{
 MYSQL_RES *result;
 int rc;

 if (!opt_silent)
 fprintf(stdout, "\n total warnings: %u (expected: %u)\n",
 mysql_warning_count(conn), expected_warning_count);

 DIE_UNLESS(mysql_warning_count(mysql) == expected_warning_count);

 rc= mysql_query(conn, "SHOW WARNINGS");
 DIE_UNLESS(rc == 0);

 result= mysql_store_result(conn);
 mytest(result);

 rc= my_process_result_set(result);
 mysql_free_result(result);
}
Exemple #4
0
Variant f_mysql_warning_count(CVarRef link_identifier /* = null */) {
  MySQL *mySQL = MySQL::Get(link_identifier);
  if (!mySQL) {
    raise_warning("supplied argument is not a valid MySQL-Link resource");
    return false;
  }
  MYSQL *conn = mySQL->get();
  if (conn) {
    return (int64_t)mysql_warning_count(conn);
  }
  return false;
}
Exemple #5
0
Variant HHVM_FUNCTION(mysql_warning_count,
                      const Variant& link_identifier /* = null */) {
  auto mySQL = MySQL::Get(link_identifier);
  if (!mySQL) {
    raise_warning("supplied argument is not a valid MySQL-Link resource");
    return false;
  }
  MYSQL *conn = mySQL->get();
  if (conn) {
    return (int64_t)mysql_warning_count(conn);
  }
  return false;
}
Exemple #6
0
static int test_client_warnings(MYSQL *mysql)
{
  int        rc;

  rc= mysql_query(mysql, "DROP TABLE if exists test_non_exists");
  check_mysql_rc(rc, mysql); 
  rc= mysql_query(mysql, "DROP TABLE if exists test_non_exists");
  check_mysql_rc(rc, mysql); 

  FAIL_IF(!mysql_warning_count(mysql), "Warning expected");

  return OK;
}
Exemple #7
0
static int test_ps_client_warnings(MYSQL *mysql)
{
  int        rc;
  MYSQL_STMT *stmt;
  char       *query= "DROP TABLE IF EXISTS test_non_exists";

  rc= mysql_query(mysql, "DROP TABLE if exists test_non_exists");
  check_mysql_rc(rc, mysql); 

  stmt= mysql_stmt_init(mysql);
  rc= mysql_stmt_prepare(stmt, query, strlen(query));
  FAIL_IF(rc, mysql_stmt_error(stmt));

  rc= mysql_stmt_execute(stmt);
  FAIL_IF(rc, mysql_stmt_error(stmt));

  FAIL_IF(!mysql_warning_count(mysql), "Warning expected");

  mysql_stmt_close(stmt);

  return OK;
}
bool CMySQLQuery::StoreResult(MYSQL *mysql_connection, MYSQL_RES *mysql_result)
{
    if (mysql_result != NULL)
    {
        MYSQL_FIELD *mysql_field;
        MYSQL_ROW mysql_row;

        CMySQLResult *result_ptr = Result = new CMySQLResult;

        Result->m_WarningCount = mysql_warning_count(mysql_connection);

        const my_ulonglong num_rows = Result->m_Rows = mysql_num_rows(mysql_result);
        const unsigned int num_fields = Result->m_Fields = mysql_num_fields(mysql_result);

        Result->m_FieldNames.reserve(Result->m_Fields + 1);


        size_t row_data_size = 0;
        while (mysql_field = mysql_fetch_field(mysql_result))
        {
            Result->m_FieldNames.push_back(mysql_field->name);
            row_data_size += mysql_field->max_length + 1;
        }


        size_t
        mem_head_size = sizeof(char **) * static_cast<size_t>(num_rows),
        mem_row_size = (sizeof(char *) * (num_fields + 1)) + ((row_data_size) * sizeof(char));
        //+1 because there is another value in memory pointing to somewhere
        //mem_row_size has to be a multiple of 8
        while (mem_row_size % 8 != 0)
            mem_row_size++;

        const size_t mem_size = mem_head_size + static_cast<size_t>(num_rows) * mem_row_size;
        char ***mem_data = result_ptr->m_Data = static_cast<char ***>(malloc(mem_size));
        char **mem_offset = reinterpret_cast<char **>(&mem_data[num_rows]);

        for (size_t r = 0; r != num_rows; ++r)
        {
            mysql_row = mysql_fetch_row(mysql_result);

            //copy mysql result data to our location
            mem_data[r] = mem_offset;
            mem_offset += mem_row_size / sizeof(char **);
            memcpy(mem_data[r], mysql_row, mem_row_size);

            //correct the pointers of the copied mysql result data
            for (size_t f = 0; f != num_fields; ++f)
            {
                if(mysql_row[f] == NULL)
                    continue;
                size_t dist = mysql_row[f] - reinterpret_cast<char *>(mysql_row);
                mem_data[r][f] = reinterpret_cast<char *>(mem_data[r]) + dist;
            }
        }
        return true;
    }
    else if (mysql_field_count(mysql_connection) == 0) //query is non-SELECT query
    {
        Result = new CMySQLResult;
        Result->m_WarningCount = mysql_warning_count(mysql_connection);
        Result->m_AffectedRows = mysql_affected_rows(mysql_connection);
        Result->m_InsertID = mysql_insert_id(mysql_connection);
        return true;
    }
    else //error
    {
        //we clear the callback name and forward it to the callback handler
        //the callback handler free's all memory but doesn't call the callback because there's no callback name
        Callback.Name.clear();
        return false;
    }
}
Exemple #9
0
ResultSet_t CResultSet::Create(MYSQL *connection,
                               default_clock::duration &exec_time,
                               string query_str)
{
    CLog::Get()->Log(LogLevel::DEBUG,
                     "CResultSet::Create(connection={}, query_str='{}')",
                     static_cast<const void *>(connection), query_str);

    if (connection == nullptr)
        return nullptr;


    ResultSet_t resultset = ResultSet_t(new CResultSet);
    CLog::Get()->Log(LogLevel::DEBUG, "created new resultset '{}'",
                     static_cast<const void *>(resultset.get()));
    bool error = false;
    MYSQL_RES *raw_result = nullptr;
    do
    {
        raw_result = mysql_store_result(connection);
        CLog::Get()->Log(LogLevel::DEBUG, "fetched MySQL result '{}'",
                         static_cast<const void*>(raw_result));

        if (raw_result == nullptr) //result empty: non-SELECT-type query or error
        {
            if (mysql_field_count(connection) == 0) //query is non-SELECT-type query
            {
                CResult *result = new CResult;

                resultset->m_Results.push_back(result);

                result->m_WarningCount = mysql_warning_count(connection);
                result->m_AffectedRows = mysql_affected_rows(connection);
                result->m_InsertId = mysql_insert_id(connection);
            }
            else //error
            {
                error = true;
                break;
            }
        }
        else //SELECT-type query
        {
            CResult *result = new CResult;

            resultset->m_Results.push_back(result);

            result->m_WarningCount = mysql_warning_count(connection);

            MYSQL_FIELD *mysql_field;
            MYSQL_ROW mysql_row;

            const my_ulonglong num_rows
                = result->m_NumRows = mysql_num_rows(raw_result);
            const unsigned int num_fields
                = result->m_NumFields = mysql_num_fields(raw_result);

            result->m_Fields.reserve(num_fields + 1);


            size_t row_data_size = 0;
            while ((mysql_field = mysql_fetch_field(raw_result)))
            {
                result->m_Fields.push_back({ mysql_field->name, mysql_field->type });
                row_data_size += mysql_field->max_length + 1;
            }


            size_t
            mem_head_size = sizeof(char **) * static_cast<size_t>(num_rows),
            mem_row_size = (sizeof(char *) * (num_fields + 1)) + ((row_data_size) * sizeof(char));
            //+ 1 because there is another value in memory pointing to behind the last MySQL field

            //mem_row_size has to be a multiple of 8
            mem_row_size += 8 - (mem_row_size % 8);

            const size_t mem_size = mem_head_size + static_cast<size_t>(num_rows) * mem_row_size;
            char ***mem_data = result->m_Data = static_cast<char ***>(malloc(mem_size));
            if (mem_data == nullptr) //error while allocating memory
            {
                error = true;
                break;
            }

            CLog::Get()->Log(LogLevel::DEBUG,
                             "allocated {} bytes for PAWN result", mem_size);

            char **mem_offset = reinterpret_cast<char **>(&mem_data[num_rows]);
            for (size_t r = 0; r != num_rows; ++r)
            {
                mysql_row = mysql_fetch_row(raw_result);

                //copy mysql result data to our location
                mem_data[r] = mem_offset;
                mem_offset += mem_row_size / sizeof(char **);
                size_t copy_size = mysql_row[num_fields] - reinterpret_cast<char *>(mysql_row);
                memcpy(mem_data[r], mysql_row, copy_size);

                //correct the pointers of the copied mysql result data
                for (size_t f = 0; f != num_fields; ++f)
                {
                    if (mysql_row[f] == nullptr)
                        continue;
                    size_t dist = mysql_row[f] - reinterpret_cast<char *>(mysql_row);
                    mem_data[r][f] = reinterpret_cast<char *>(mem_data[r]) + dist;
                }
                //useless field we had to copy
                //set it to nullptr to avoid invalid memory access errors
                //(very unlikely to happen in first place though)
                mem_data[r][num_fields] = nullptr;
            }

            mysql_free_result(raw_result);
            raw_result = nullptr;
        }
    }
    while (mysql_next_result(connection) == 0);

    if (error)
    {
        mysql_free_result(raw_result);

        // go through all results to avoid "out of sync" error
        while (mysql_next_result(connection) == 0)
            mysql_free_result(mysql_store_result(connection));
    }
    resultset->m_ExecTimeMilli = static_cast<unsigned int>(
                                     std::chrono::duration_cast<std::chrono::milliseconds>(exec_time).count());
    resultset->m_ExecTimeMicro = static_cast<unsigned int>(
                                     std::chrono::duration_cast<std::chrono::microseconds>(exec_time).count());

    resultset->m_ExecQuery = std::move(query_str);

    return resultset;
}
Exemple #10
0
static int test_wl4166_3(MYSQL *mysql)
{
  int rc;
  MYSQL_STMT *stmt;
  MYSQL_BIND my_bind[1];
  MYSQL_TIME tm[1];

  if (mysql_get_server_version(mysql) < 50100) {
    diag("Test requires MySQL Server version 5.1 or above");
    return SKIP;
  }

  rc= mysql_query(mysql, "drop table if exists t1");
  check_mysql_rc(rc, mysql);

  rc= mysql_query(mysql, "create table t1 (year datetime)");
  check_mysql_rc(rc, mysql);

  stmt= mysql_stmt_init(mysql);
  FAIL_IF(!stmt, mysql_error(mysql));
  rc= mysql_stmt_prepare(stmt, "insert into t1 (year) values (?)", strlen("insert into t1 (year) values (?)"));
  check_stmt_rc(rc, stmt);

  FAIL_IF(mysql_stmt_param_count(stmt) != 1, "param_count != 1");

  memset(my_bind, '\0', sizeof(my_bind));
  my_bind[0].buffer_type= MYSQL_TYPE_DATETIME;
  my_bind[0].buffer= &tm[0];

  rc= mysql_stmt_bind_param(stmt, my_bind);
  check_stmt_rc(rc, stmt);

  tm[0].year= 10000;
  tm[0].month= 1; tm[0].day= 1;
  tm[0].hour= 1; tm[0].minute= 1; tm[0].second= 1;
  tm[0].second_part= 0; tm[0].neg= 0;

  /* Cause a statement reprepare */
  rc= mysql_query(mysql, "alter table t1 add column c int");
  check_mysql_rc(rc, mysql);

  rc= mysql_stmt_execute(stmt);
  check_stmt_rc(rc, stmt);
  /*
    Sic: only one warning, instead of two. The warning
    about data truncation when assigning a parameter is lost.
    This is a bug.
  */
  FAIL_IF(mysql_warning_count(mysql) != 1, "warning count != 1");

  if (verify_col_data(mysql, "t1", "year", "0000-00-00 00:00:00")) {
    mysql_stmt_close(stmt);
    rc= mysql_query(mysql, "drop table t1");
    return FAIL;
  }

  mysql_stmt_close(stmt);

  rc= mysql_query(mysql, "drop table t1");
  check_mysql_rc(rc, mysql);
  return OK;
}
unsigned int Connection::GetWarningCount()
{
    return mysql_warning_count(MySQL);
}
Exemple #12
0
/* {{{ mysqli_warning_construct(object obj) */
PHP_METHOD(mysqli_warning, __construct)
{
	zval			*z;
	mysqli_object	*obj;
#ifndef MYSQLI_USE_MYSQLND
	MYSQL			*hdl;
#endif
	MYSQLI_WARNING  *w;
	MYSQLI_RESOURCE *mysqli_resource;

	if (ZEND_NUM_ARGS() != 1) {
		WRONG_PARAM_COUNT;
	}
	if (zend_parse_parameters(1, "o", &z)==FAILURE) {
		return;
	}
	obj = Z_MYSQLI_P(z);

	if (obj->zo.ce == mysqli_link_class_entry) {
		MY_MYSQL *mysql;
		MYSQLI_FETCH_RESOURCE_CONN(mysql, z, MYSQLI_STATUS_VALID);
		if (mysql_warning_count(mysql->mysql)) {
#ifndef MYSQLI_USE_MYSQLND
			w = php_get_warnings(mysql->mysql);
#else
			w = php_get_warnings(mysql->mysql->data);
#endif
		} else {
			php_error_docref(NULL, E_WARNING, "No warnings found");
			RETURN_FALSE;
		}
	} else if (obj->zo.ce == mysqli_stmt_class_entry) {
		MY_STMT *stmt;
		MYSQLI_FETCH_RESOURCE_STMT(stmt, z, MYSQLI_STATUS_VALID);
#ifndef MYSQLI_USE_MYSQLND
		hdl = mysqli_stmt_get_connection(stmt->stmt);
		if (mysql_warning_count(hdl)) {
			w = php_get_warnings(hdl);
#else
		if (mysqlnd_stmt_warning_count(stmt->stmt)) {
			w = php_get_warnings(mysqli_stmt_get_connection(stmt->stmt));
#endif
		} else {
			php_error_docref(NULL, E_WARNING, "No warnings found");
			RETURN_FALSE;
		}
	} else {
		php_error_docref(NULL, E_WARNING, "invalid class argument");
		RETURN_FALSE;
	}

	mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
	mysqli_resource->ptr = mysqli_resource->info = (void *)w;
	mysqli_resource->status = MYSQLI_STATUS_VALID;

	if (!getThis() || !instanceof_function(Z_OBJCE_P(getThis()), mysqli_warning_class_entry)) {
		MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_warning_class_entry);
	} else {
		(Z_MYSQLI_P(getThis()))->ptr = mysqli_resource;
	}

}
/* }}} */

/* {{{ mysqli_warning_methods */
const zend_function_entry mysqli_warning_methods[] = {
	PHP_ME(mysqli_warning, __construct,		NULL, ZEND_ACC_PROTECTED)
	PHP_ME(mysqli_warning, next, 			NULL, ZEND_ACC_PUBLIC)
	{NULL, NULL, NULL}
};
/* }}} */

/* {{{ mysqli_warning_property_entries */
const mysqli_property_entry mysqli_warning_property_entries[] = {
	{"message", sizeof("message") - 1, mysqli_warning_message, NULL},
	{"sqlstate", sizeof("sqlstate") - 1, mysqli_warning_sqlstate, NULL},
	{"errno", sizeof("errno") - 1, mysqli_warning_errno, NULL},
	{NULL, 0, NULL, NULL}
};
Exemple #13
0
static PyObject* wsql_connection_get_warning_count(wsql_connection *self, void *closure)
{
    CHECK_CONNECTION(self, NULL);
    return PyLong_FromLong(mysql_warning_count(&(self->connection)));
}
Exemple #14
0
/*	warning_count()	*/
static VALUE warning_count(VALUE obj)
{
    return INT2NUM(mysql_warning_count(GetHandler(obj)));
}
unsigned int CDatabase_Connection::warning_count()
{
	return mysql_warning_count(&my);
}