コード例 #1
0
ファイル: mysqlpp_statement.cpp プロジェクト: mnpk/waspp
	unsigned long long int statement::execute()
	{
		unsigned long long int affected_rows = 0;

		try
		{
			if (param_count > 0 && !binds.empty())
			{
				if (mysql_stmt_bind_param(stmt, &binds.front()) != 0)
				{
					throw exception(__FILE__, __LINE__, mysql_stmt_error(stmt));
				}
			}

			if (mysql_stmt_execute(stmt) != 0)
			{
				throw exception(__FILE__, __LINE__, mysql_stmt_error(stmt));
			}

			affected_rows = mysql_stmt_affected_rows(stmt);
		}
		catch (...)
		{
			throw;
		}

		return affected_rows;
	}
コード例 #2
0
ファイル: ods-migrate.c プロジェクト: opendnssec/opendnssec
static void
dblayer_mysql_foreach(const char* listQueryStr, const char* updateQueryStr, int (*compute)(char**,int*,uint16_t*))
{
    int id;
    uint16_t keytag;
    MYSQL_BIND bind[2];
    MYSQL_STMT *updateStmt;
    MYSQL_RES* res;
    MYSQL_ROW row;
    updateStmt = mysql_stmt_init(dblayer_mysql.handle);
    mysql_stmt_prepare(updateStmt, updateQueryStr, strlen(updateQueryStr) + 1);
    mysql_query(dblayer_mysql.handle, listQueryStr);
    res = mysql_store_result(dblayer_mysql.handle);
    if (!res) {
        fprintf(stderr, "Failed to update db. Is it set correctly in conf.xml?\n");
        exit(1);
    }
    mysql_num_fields(res);
    while ((row = mysql_fetch_row(res))) {
        compute(row, &id, &keytag);
        memset(bind, 0, sizeof (bind));
        bind[0].buffer = &keytag;
        bind[0].buffer_length = sizeof(keytag);
        bind[0].buffer_type = MYSQL_TYPE_SHORT;
        bind[0].is_unsigned = 1;
        bind[1].buffer = &id;
        bind[1].buffer_length = sizeof(id);
        bind[1].buffer_type = MYSQL_TYPE_LONG;
        mysql_stmt_bind_param(updateStmt, bind);
        mysql_stmt_execute(updateStmt);
        mysql_stmt_affected_rows(updateStmt);
    }
    mysql_free_result(res);
    mysql_stmt_close(updateStmt);
}
コード例 #3
0
ファイル: ob_ps_test.cpp プロジェクト: cuiwm/oceanbase
void ObPSTest::delete_test()
{
    MYSQL_STMT *stmt = mysql_stmt_init(&my_);
    ASSERT_TRUE(stmt);
    const char* QUERY = "delete from ob_ps_test where c1 = ?";
    // 1. prepare
    int ret = mysql_stmt_prepare(stmt, QUERY, strlen(QUERY));
    ASSERT_QUERY_RET(ret);
    int param_count = (int)mysql_stmt_param_count(stmt);
    ASSERT_EQ(1, param_count);
    // 2. bind params
    MYSQL_BIND bind[1];
    memset(bind, 0, sizeof(bind));
    int int_data = 0;
    bind[0].buffer_type= MYSQL_TYPE_LONG;
    bind[0].buffer= (char *)&int_data;
    bind[0].is_null= 0;
    bind[0].length= 0;
    ret = mysql_stmt_bind_param(stmt, bind);
    ASSERT_QUERY_RET(ret);
    // 3. execute
    int_data = 3;
    ret = mysql_stmt_execute(stmt);
    ASSERT_QUERY_RET(ret);
    // 4. results
    my_ulonglong affected_rows = mysql_stmt_affected_rows(stmt);
    ASSERT_EQ(1U, affected_rows);

    // 5. clean up
    ret = mysql_stmt_close(stmt);
    ASSERT_QUERY_RET(ret);
}
コード例 #4
0
ファイル: mysqli_prop.c プロジェクト: AmesianX/php-src
/* {{{ property stmt_affected_rows_read */
static zval *stmt_affected_rows_read(mysqli_object *obj, zval *retval)
{
	MY_STMT *p;
	my_ulonglong rc;

	CHECK_STATUS(MYSQLI_STATUS_VALID);

 	p = (MY_STMT *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;

	if (!p) {
		ZVAL_NULL(retval);
	} else {
		rc = mysql_stmt_affected_rows(p->stmt);

		if (rc == (my_ulonglong) -1) {
			ZVAL_LONG(retval, -1);
			return retval;
		}

		if (rc < ZEND_LONG_MAX) {
			ZVAL_LONG(retval, (zend_long) rc);
		} else {
			ZVAL_NEW_STR(retval, strpprintf(0, MYSQLI_LLU_SPEC, rc));
		}
	}
	return retval;
}
コード例 #5
0
ファイル: mysql_client_fw.c プロジェクト: lanqiyi/CacheDB
static void verify_st_affected_rows(MYSQL_STMT *stmt, ulonglong exp_count)
{
 ulonglong affected_rows= mysql_stmt_affected_rows(stmt);
 if (!opt_silent)
 fprintf(stdout, "\n total affected rows: `%ld` (expected: `%ld`)",
 (long) affected_rows, (long) exp_count);
 DIE_UNLESS(affected_rows == exp_count);
}
コード例 #6
0
ファイル: clsql_mysql.c プロジェクト: vikram/lisplibraries
DLLEXPORT
DLLEXPORT
unsigned int
clsql_mysql_stmt_affected_rows (MYSQL_STMT* stmt, unsigned int* pHigh32)
{
  my_ulonglong nAffected = mysql_stmt_affected_rows (stmt);
  *pHigh32 = upper_32bits(nAffected);
  return lower_32bits(nAffected);
}
コード例 #7
0
ファイル: cache.cpp プロジェクト: fefed22/Phraseanet
bool CACHE_SESSION::save()
{
  bool ret = false;
  MYSQL_STMT   *stmt;
  MYSQL_BIND   bind[2];
  char *query = (char *)("UPDATE cache SET session=? WHERE session_id=?");
  char *binbuff;
  unsigned long binlen;
  int session_id = this->session_id;
  MYSQL *mysql = (MYSQL *)epublisher->get_native_conn();

//zend_printf("LINE %i <br/>\n", __LINE__);
	if( (stmt = mysql_stmt_init(mysql)) )
	{
//zend_printf("LINE %i <br/>\n", __LINE__);
		if( (mysql_stmt_prepare(stmt, query, strlen(query))) == 0 )
		{
//zend_printf("LINE %i <br/>\n", __LINE__);
			binlen = this->get_binsize();		// obtient la taille maximum n�cessaire
			if(binbuff = (char *)EMALLOC(binlen))
			{
//zend_printf("LINE %i <br/>\n", __LINE__);
				binlen = this->serialize_bin((long *)binbuff);		// s�rialise et obtient la taille r�elle

//zend_printf("LINE %i binlen=%li <br/>\n", __LINE__, binlen);
				bind[0].buffer_type = MYSQL_TYPE_VAR_STRING;
				bind[0].buffer = binbuff;
				bind[0].buffer_length = binlen;
				bind[0].is_null= 0;
				bind[0].length= &binlen;

				bind[1].buffer_type= MYSQL_TYPE_LONG;
				bind[1].buffer= (char *)&session_id;
				bind[1].is_null= 0;
				bind[1].length= 0;

				if (mysql_stmt_bind_param(stmt, bind) == 0)
				{
//zend_printf("LINE %i <br/>\n", __LINE__);
					if (mysql_stmt_execute(stmt) == 0)
					{
//zend_printf("LINE %i <br/>\n", __LINE__);
						if(mysql_stmt_affected_rows(stmt) == 1)
						{
//zend_printf("LINE %i <br/>\n", __LINE__);
							ret = true;
						}
					}
				}
				EFREE(binbuff);
			}
		}
		mysql_stmt_close(stmt);
	}
	return(ret);
}
コード例 #8
0
ファイル: statement.c プロジェクト: nikkiii/luadbi
/*
 * num_affected_rows = statement:affected()
 */
static int statement_affected(lua_State *L) {
    statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT);

    if (!statement->stmt) {
        luaL_error(L, DBI_ERR_INVALID_STATEMENT);
    }

    lua_pushinteger(L, mysql_stmt_affected_rows(statement->stmt));

    return 1;
}
コード例 #9
0
ファイル: statement.c プロジェクト: AhmedElassuty/mysql2
/* call-seq:
 *    stmt.affected_rows
 *
 * Returns the number of rows changed, deleted, or inserted.
 */
static VALUE rb_mysql_stmt_affected_rows(VALUE self) {
  my_ulonglong affected;
  GET_STATEMENT(self);

  affected = mysql_stmt_affected_rows(stmt_wrapper->stmt);
  if (affected == (my_ulonglong)-1) {
    rb_raise_mysql2_stmt_error(stmt_wrapper);
  }

  return ULL2NUM(affected);
}
コード例 #10
0
ファイル: gda-mysql-recordset.c プロジェクト: zzeroo/libgda
/*
 * Get the number of rows in @model, if possible
 */
static gint
gda_mysql_recordset_fetch_nb_rows (GdaDataSelect *model)
{
	GdaMysqlRecordset *imodel;

	imodel = GDA_MYSQL_RECORDSET (model);
	if (model->advertized_nrows >= 0)
		return model->advertized_nrows;

	model->advertized_nrows = mysql_stmt_affected_rows (imodel->priv->mysql_stmt);
	
	return model->advertized_nrows;
}
コード例 #11
0
bool CACHE_SESSION::save()
{
  bool ret = false;
  MYSQL_STMT   *stmt;
  MYSQL_BIND   bind[2];
  char *query = (char *)("UPDATE cache SET session=? WHERE session_id=?");
  char *binbuff;
  unsigned long binlen;
  int session_id = this->session_id;
  MYSQL *mysql = (MYSQL *)epublisher->get_native_conn();

	if( (stmt = mysql_stmt_init(mysql)) )
	{
		if( (mysql_stmt_prepare(stmt, query, strlen(query))) == 0 )
		{
			binlen = this->get_binsize();		// get size needed
			if(binbuff = (char *)EMALLOC(binlen))
			{
				memset(binbuff, 0, binlen);
				binlen = this->serialize_bin((long *)binbuff);		// serialize and get the real size

				memset(bind, 0, sizeof(bind));
				
				bind[0].buffer_type = MYSQL_TYPE_VAR_STRING;
				bind[0].buffer = binbuff;
				bind[0].buffer_length = binlen;
				bind[0].is_null= 0;
				bind[0].length= &binlen;

				bind[1].buffer_type= MYSQL_TYPE_LONG;
				bind[1].buffer= (char *)&session_id;
				bind[1].is_null= 0;
				bind[1].length= 0;

				if (mysql_stmt_bind_param(stmt, bind) == 0)
				{
					if (mysql_stmt_execute(stmt) == 0)
					{
						if(mysql_stmt_affected_rows(stmt) == 1)
						{
							ret = true;
						}
					}
				}
				EFREE(binbuff);
			}
		}
		mysql_stmt_close(stmt);
	}
	return(ret);
}
コード例 #12
0
	bool CDatabaseConnectionMySql::ExecuteUpdate( MYSQL_STMT * statement )
	{
		bool result = false;

		try
		{
			MySQLCheck( mysql_stmt_execute( statement ), INFO_MYSQL_STATEMENT_EXECUTION, EDatabaseExceptionCodes_StatementError, _connection );
			uint64_t affected = mysql_stmt_affected_rows( statement );
			result = true;
		}
		COMMON_CATCH( ERROR_MYSQL_EXECUTION )

		return result;
	}
コード例 #13
0
ファイル: Statement.cpp プロジェクト: RaviDesai/mysqlwrap
void Statement::Execute() {
	if (! _db.IsConnected()) {
		throw DatabaseException("Error in Statement::Execute", 0, "----", "Database is not connected");
	}

	_numberAffectedRows = 0;
	_eof = true;
	_currentColumn = 0;

	if (ParameterCount() != _params.size()) {
		throw DatabaseException("Error in Statement::Execute", 0, "----", "Have not yet assigned all parameters");
	}

	if (mysql_stmt_bind_param(_stmt, _bind) != 0) {
		throw DatabaseException(_stmt, "Error in Statement::Execute while binding parameters");
	}

	if (mysql_stmt_execute(_stmt) != 0) {
		throw DatabaseException(_stmt, "Error in Statement::Execute while executing statement");
	}

	if (_numberResultColumns > 0) {
		if (mysql_stmt_store_result(_stmt) != 0) { 
			throw DatabaseException(_stmt, "Error in Statement::Execute while storing results");
		}
		_eof = false;
	}
	else {
		_numberAffectedRows = mysql_stmt_affected_rows(_stmt);
	}

	_resultWasStored = true;

	if (_hasBlobField && _resultBind != NULL) {
		MYSQL_RES *res = mysql_stmt_result_metadata(_stmt);
		if (res != NULL) {
			for (unsigned int i = 0; i < _resultParams.size(); i++) {
				MYSQL_FIELD *column = mysql_fetch_field_direct(res, i);
				if (_resultBind[i].buffer_type == MYSQL_TYPE_BLOB) {
					_resultParams[i]->ResizeBlob(column->max_length);
					_resultBind[i].buffer = _resultParams[i]->Buffer();
					_resultBind[i].buffer_length = _resultParams[i]->BufferSize();
					_resultBind[i].length = _resultParams[i]->BufferLength();
				}
			}
			mysql_free_result(res);
		}
	}
}
コード例 #14
0
ファイル: mysqlerl.c プロジェクト: bjc/mysqlerl
void
handle_select_count(ETERM *msg)
{
  ETERM *query, *resp;
  MYSQL_STMT *handle;
  char *q;

  query = erl_element(2, msg);
  q = erl_iolist_to_string(query);
  erl_free_term(query);

  logmsg("INFO: Got select count for: %s", q);

  handle = mysql_stmt_init(&dbh);
  if (mysql_stmt_prepare(handle, q, strlen(q))) {
    resp = erl_format("{error, {mysql_error, ~i, ~s}}",
                      mysql_stmt_errno(handle), mysql_stmt_error(handle));
  } else if (mysql_stmt_execute(handle)) {
    resp = erl_format("{error, {mysql_error, ~i, ~s}}",
                      mysql_stmt_errno(handle), mysql_stmt_error(handle));
  } else {
    set_mysql_results(handle);
    if (results) {
      resp = erl_format("{ok, ~i}", mysql_stmt_affected_rows(handle));
    } else if (mysql_stmt_field_count(handle) == 0) {
      resp = erl_format("{ok, ~i}", mysql_stmt_affected_rows(handle));
    } else {
      resp = erl_format("{error, {mysql_error, ~i, ~s}}",
                        mysql_stmt_errno(handle), mysql_stmt_error(handle));
    }
  }
  erl_free(q);

  write_msg(resp);
  erl_free_term(resp);
}
コード例 #15
0
/* Now it's more like installing result */
void MADB_InstallStmt(MADB_Stmt *Stmt, MYSQL_STMT *stmt)
{
  Stmt->stmt= stmt;

  if (mysql_stmt_field_count(Stmt->stmt) == 0)
  {
    Stmt->AffectedRows= mysql_stmt_affected_rows(Stmt->stmt);
  }
  else
  {
    Stmt->AffectedRows= 0;
    MADB_StmtResetResultStructures(Stmt);
    MADB_DescSetIrdMetadata(Stmt, mysql_fetch_fields(FetchMetadata(Stmt)), mysql_stmt_field_count(Stmt->stmt));
  }
}
コード例 #16
0
ファイル: apr_dbd_mysql.c プロジェクト: dago/opencsw
static int dbd_mysql_pvquery(apr_pool_t *pool, apr_dbd_t *sql, int *nrows,
                             apr_dbd_prepared_t *statement, va_list args)
{
    MYSQL_BIND *bind;
    char *arg;
    int ret;
    int nargs = 0;
    int i;
    my_bool is_null = FALSE;

    if (sql->trans && sql->trans->errnum) {
        return sql->trans->errnum;
    }
    nargs = mysql_stmt_param_count(statement->stmt);

    bind = apr_palloc(pool, nargs*sizeof(MYSQL_BIND));
    for (i=0; i < nargs; ++i) {
        arg = va_arg(args, char*);
        bind[i].buffer_type = MYSQL_TYPE_VAR_STRING;
        bind[i].buffer = arg;
        bind[i].buffer_length = strlen(arg);
        bind[i].length = &bind[i].buffer_length;
        bind[i].is_null = &is_null;
        bind[i].is_unsigned = 0;
    }

    ret = mysql_stmt_bind_param(statement->stmt, bind);
    if (ret != 0) {
        *nrows = 0;
        ret = mysql_stmt_errno(statement->stmt);
    }
    else {
        ret = mysql_stmt_execute(statement->stmt);
        if (ret != 0) {
            ret = mysql_stmt_errno(statement->stmt);
        }
        *nrows = mysql_stmt_affected_rows(statement->stmt);
    }
    if (sql->trans) {
        sql->trans->errnum = ret;
    }
    return ret;
}
コード例 #17
0
ファイル: database.c プロジェクト: WolfWings/pamnss-mysql
int db_read_close() {
	int rows;

	rows = mysql_stmt_affected_rows(_mysql_stmt);
	mysql_stmt_close(_mysql_stmt);

	if (rows < 0) {
		/* Only LOG_WARNING as we have successfully fetched SOMETHING. */
		finish_with_error(LOG_WARNING, "Problem fetching number of rows from prepared MySQL statement");

		if (_fetch == MYSQL_NO_DATA) {
			return 0;
		} else {
			return 1;
		}
	}

	return rows;
}
コード例 #18
0
ファイル: mysql_client_fw.c プロジェクト: lanqiyi/CacheDB
static void execute_prepare_query(const char *query, ulonglong exp_count)
{
 MYSQL_STMT *stmt;
 ulonglong  affected_rows;
 int        rc;

 stmt= mysql_simple_prepare(mysql, query);
 check_stmt(stmt);

 rc= mysql_stmt_execute(stmt);
 myquery(rc);

 affected_rows= mysql_stmt_affected_rows(stmt);
 if (!opt_silent)
 fprintf(stdout, "\n total affected rows: `%ld` (expected: `%ld`)",
 (long) affected_rows, (long) exp_count);

 DIE_UNLESS(affected_rows == exp_count);
 mysql_stmt_close(stmt);
}
コード例 #19
0
ファイル: apr_dbd_mysql.c プロジェクト: cmjonze/apr
static int dbd_mysql_pquery_internal(apr_pool_t *pool, apr_dbd_t *sql,
                                     int *nrows, apr_dbd_prepared_t *statement,
                                     MYSQL_BIND *bind)
{
    int ret;

    ret = mysql_stmt_bind_param(statement->stmt, bind);
    if (ret != 0) {
        *nrows = 0;
        ret = mysql_stmt_errno(statement->stmt);
    }
    else {
        ret = mysql_stmt_execute(statement->stmt);
        if (ret != 0) {
            ret = mysql_stmt_errno(statement->stmt);
        }
        *nrows = (int) mysql_stmt_affected_rows(statement->stmt);
    }

    return ret;
}
コード例 #20
0
ファイル: m_mysql_command.cpp プロジェクト: mzxdream/bak
std::pair<unsigned, MError> MMysqlCommand::DoExecuteNonQuery()
{
    int param_count = mysql_stmt_param_count(p_stmt_);
    if (static_cast<size_t>(param_count) != in_params_.size())
    {
        MLOG(MGetLibLogger(), MERR, "param count is not match need:", param_count, " actual is:", in_params_.size());
        return std::pair<unsigned, MError>(0, MError::NotMatch);
    }
    if (mysql_stmt_bind_param(p_stmt_, &in_params_[0]) != 0)
    {
        MLOG(MGetLibLogger(), MERR, "bind failed errno:", mysql_stmt_errno(p_stmt_), " error:", mysql_stmt_error(p_stmt_));
        return std::pair<unsigned, MError>(0, MError::Unknown);
    }
    if (mysql_stmt_execute(p_stmt_) != 0)
    {
        MLOG(MGetLibLogger(), MERR, "execute failed errorno:", mysql_stmt_errno(p_stmt_), " error:", mysql_stmt_error(p_stmt_));
        return std::pair<unsigned, MError>(0, MError::Unknown);
    }
    unsigned affect = mysql_stmt_affected_rows(p_stmt_);
    return std::make_pair(affect, MError::No);
}
コード例 #21
0
int sql_exec(struct subdbinfo *info,
	     struct stralloc *q,
	     unsigned int nparams,
	     struct stralloc *params)
{
  int rows;
  MYSQL_STMT *stmt;

  stmt = _prepbind(info,q,nparams,params);
  switch (rows = mysql_stmt_execute(stmt)) {
  case 0:
    rows = mysql_stmt_affected_rows(stmt);
    break;
  default:
    if (mysql_stmt_errno(stmt) == ER_DUP_ENTRY)
      rows = 0;
    else
      die_sqlerror(info);
  }
  sql_free_result(info,stmt);
  return rows;
}
コード例 #22
0
ファイル: basil_mysql_routines.c プロジェクト: BYUHPC/slurm
/**
 * store_stmt_results - Buffer all results of a query on the client
 * Returns -1 on error, number_of_rows >= 0 if ok.
 */
static int store_stmt_results(MYSQL_STMT *stmt, const char *query,
			      MYSQL_BIND bind_col[], unsigned long ncols)
{
	my_ulonglong nrows;
	int i;

	if (stmt == NULL || ncols == 0)
		return -1;

	if (mysql_stmt_store_result(stmt)) {
		error("can not store query result for \"%s\": %s",
		      query, mysql_stmt_error(stmt));
		return -1;
	}

	nrows = mysql_stmt_affected_rows(stmt);
	if (nrows == (my_ulonglong)-1) {
		error("query \"%s\" returned an error: %s",
		      query, mysql_stmt_error(stmt));
		return -1;
	}

	while (mysql_stmt_fetch(stmt) == 0)
		for (i = 0; i < ncols; i++) {
			if (bind_col[i].error && *bind_col[i].error)  {
				error("result value in column %d truncated: %s",
				      i, mysql_stmt_error(stmt));
				return -1;
			}
		}

	/* Seek back to begin of data set */
	mysql_stmt_data_seek(stmt, 0);

	return nrows;
}
コード例 #23
0
ファイル: gda-mysql-recordset.c プロジェクト: zzeroo/libgda
/*
 * the @ps struct is modified and transferred to the new data model created in
 * this function
 *
 * See MySQL's documentation "C API Prepared Statement Type Codes":
 *     http://docs.oracle.com/cd/E17952_01/refman-5.5-en/c-api-prepared-statement-type-codes.html
 */
GdaDataModel *
gda_mysql_recordset_new (GdaConnection            *cnc,
			 GdaMysqlPStmt            *ps,
			 GdaSet                   *exec_params,
			 GdaDataModelAccessFlags   flags,
			 GType                    *col_types)
{
	GdaMysqlRecordset *model;
        MysqlConnectionData *cdata;
        gint i;
	GdaDataModelAccessFlags rflags;

        g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
        g_return_val_if_fail (ps != NULL, NULL);

	cdata = (MysqlConnectionData*) gda_connection_internal_get_provider_data_error (cnc, NULL);
	if (!cdata)
		return NULL;

	g_assert (ps->mysql_stmt);

	/* make sure @ps reports the correct number of columns using the API*/
        if (_GDA_PSTMT (ps)->ncols < 0)
		_GDA_PSTMT(ps)->ncols = mysql_stmt_field_count (ps->mysql_stmt);

        /* completing @ps if not yet done */
	g_assert (! ps->stmt_used);
        ps->stmt_used = TRUE;
        if (!_GDA_PSTMT (ps)->types && (_GDA_PSTMT (ps)->ncols > 0)) {
		/* create prepared statement's columns */
		for (i = 0; i < _GDA_PSTMT (ps)->ncols; i++)
			_GDA_PSTMT (ps)->tmpl_columns = g_slist_prepend (_GDA_PSTMT (ps)->tmpl_columns, 
									 gda_column_new ());
		_GDA_PSTMT (ps)->tmpl_columns = g_slist_reverse (_GDA_PSTMT (ps)->tmpl_columns);

		/* create prepared statement's types, all types are initialized to GDA_TYPE_NULL */
		_GDA_PSTMT (ps)->types = g_new (GType, _GDA_PSTMT (ps)->ncols);
		for (i = 0; i < _GDA_PSTMT (ps)->ncols; i++)
			_GDA_PSTMT (ps)->types [i] = GDA_TYPE_NULL;

		if (col_types) {
			for (i = 0; ; i++) {
				if (col_types [i] > 0) {
					if (col_types [i] == G_TYPE_NONE)
						break;
					if (i >= _GDA_PSTMT (ps)->ncols) {
						g_warning (_("Column %d out of range (0-%d), ignoring its specified type"), i,
							   _GDA_PSTMT (ps)->ncols - 1);
						break;
					}
					else
						_GDA_PSTMT (ps)->types [i] = col_types [i];
				}
			}
		}
	}

	/* get rid of old bound result if any */
	if (ps->mysql_bind_result) {
		gint i;
		for (i = 0; i < ((GdaPStmt *) ps)->ncols; ++i) {
			g_free (ps->mysql_bind_result[i].buffer);
			g_free (ps->mysql_bind_result[i].is_null);
			g_free (ps->mysql_bind_result[i].length);
		}
		g_free (ps->mysql_bind_result);
		ps->mysql_bind_result = NULL;
	}

	/* fill bind result */
	MYSQL_RES *mysql_res = mysql_stmt_result_metadata (ps->mysql_stmt);
	MYSQL_FIELD *mysql_fields = mysql_fetch_fields (mysql_res);
	
	MYSQL_BIND *mysql_bind_result = g_new0 (MYSQL_BIND, GDA_PSTMT (ps)->ncols);
	GSList *list;

	for (i=0, list = _GDA_PSTMT (ps)->tmpl_columns; 
	     i < GDA_PSTMT (ps)->ncols; 
	     i++, list = list->next) {
		GdaColumn *column = GDA_COLUMN (list->data);
		
		/* use C API to set columns' information using gda_column_set_*() */
		MYSQL_FIELD *field = &mysql_fields[i];
		
		GType gtype = _GDA_PSTMT(ps)->types[i];
		if (gtype == GDA_TYPE_NULL) {
			gtype = _gda_mysql_type_to_gda (cdata, field->type, field->charsetnr);
			_GDA_PSTMT(ps)->types[i] = gtype;
		}
		gda_column_set_g_type (column, gtype);
		gda_column_set_name (column, field->name);
		gda_column_set_description (column, field->name);
		
		/* binding results with types */
		mysql_bind_result[i].buffer_type = field->type;
		mysql_bind_result[i].is_unsigned = field->flags & UNSIGNED_FLAG ? TRUE : FALSE;
		mysql_bind_result[i].is_null = g_malloc0 (sizeof (my_bool));
		
		switch (mysql_bind_result[i].buffer_type) {
		case MYSQL_TYPE_TINY:
			mysql_bind_result[i].buffer = g_malloc0 (sizeof (signed char));
			break;
		case MYSQL_TYPE_SHORT:
			mysql_bind_result[i].buffer = g_malloc0 (sizeof (short int));
			break;
		case MYSQL_TYPE_INT24:
		case MYSQL_TYPE_LONG:
		case MYSQL_TYPE_YEAR:
			mysql_bind_result[i].buffer = g_malloc0 (sizeof (int));
			break;
		case MYSQL_TYPE_LONGLONG:
			mysql_bind_result[i].buffer = g_malloc0 (sizeof (long long));
			break;
		case MYSQL_TYPE_NULL:
			break;
		case MYSQL_TYPE_TIME:
		case MYSQL_TYPE_DATE:
		case MYSQL_TYPE_DATETIME:
		case MYSQL_TYPE_TIMESTAMP:
			mysql_bind_result[i].buffer = g_malloc0 (sizeof (MYSQL_TIME));
			break;
		case MYSQL_TYPE_FLOAT:
		case MYSQL_TYPE_DOUBLE:
			mysql_bind_result[i].buffer = g_malloc0 (sizeof (double));
			break;
		case MYSQL_TYPE_STRING:
		case MYSQL_TYPE_VAR_STRING:
		case MYSQL_TYPE_BLOB:
		case MYSQL_TYPE_TINY_BLOB:
		case MYSQL_TYPE_MEDIUM_BLOB:
		case MYSQL_TYPE_LONG_BLOB:
		case MYSQL_TYPE_DECIMAL:
		case MYSQL_TYPE_NEWDECIMAL:
		case MYSQL_TYPE_BIT:
			mysql_bind_result[i].buffer = g_malloc0 (field->max_length + 1);
			mysql_bind_result[i].buffer_length = field->max_length + 1;
			mysql_bind_result[i].length = g_malloc0 (sizeof (unsigned long));
			break;
		default:
			g_warning (_("Invalid column bind data type. %d\n"),
				   mysql_bind_result[i].buffer_type);
		}
		/*g_print ("%s(): NAME=%s, TYPE=%d, GTYPE=%s, unsigned: %d\n",
			 __FUNCTION__, field->name, field->type, g_type_name (gtype),
			 field->flags & UNSIGNED_FLAG);*/
	}
	
	if (mysql_stmt_bind_result (ps->mysql_stmt, mysql_bind_result)) {
		g_warning ("mysql_stmt_bind_result failed: %s\n",
			   mysql_stmt_error (ps->mysql_stmt));
	}
	
	mysql_free_result (mysql_res);
	ps->mysql_bind_result = mysql_bind_result;

	/* determine access mode: RANDOM or CURSOR FORWARD are the only supported */
	if (flags & GDA_DATA_MODEL_ACCESS_RANDOM)
		rflags = GDA_DATA_MODEL_ACCESS_RANDOM;
	else
		rflags = GDA_DATA_MODEL_ACCESS_CURSOR_FORWARD;

	/* create data model */
        model = g_object_new (GDA_TYPE_MYSQL_RECORDSET,
			      "connection", cnc,
			      "prepared-stmt", ps,
			      "model-usage", rflags,
			      "exec-params", exec_params, 
			      NULL);
        model->priv->cnc = cnc;
	g_object_ref (G_OBJECT(cnc));

	model->priv->mysql_stmt = ps->mysql_stmt;

	((GdaDataSelect *) model)->advertized_nrows = mysql_stmt_affected_rows (ps->mysql_stmt);

        return GDA_DATA_MODEL (model);
}
コード例 #24
0
ファイル: mysql-preprare-1.c プロジェクト: AMCScarface/misc
int main (int argc, char *argv[]) {

    MYSQL mysql;
    MYSQL_RES *result;
    MYSQL_ROW row;
    my_bool reconnect = 0;
    mysql_init(&mysql);
    mysql_options(&mysql, MYSQL_OPT_RECONNECT, &reconnect);
 
    mysql_real_connect(&mysql, "127.0.0.1", "root", "root", "test", 3306, NULL, 0);

    MYSQL_STMT    *stmt;
    MYSQL_BIND    bind[3];
    my_ulonglong  affected_rows;
    int           param_count;
    short         small_data;
    int           int_data;
    char          str_data[STRING_SIZE];
    unsigned long str_length;
    my_bool       is_null;

    if (mysql_query(mysql, DROP_SAMPLE_TABLE))
    {
      fprintf(stderr, " DROP TABLE failed\n");
      fprintf(stderr, " %s\n", mysql_error(mysql));
      exit(0);
    }

    if (mysql_query(mysql, CREATE_SAMPLE_TABLE))
    {
      fprintf(stderr, " CREATE TABLE failed\n");
      fprintf(stderr, " %s\n", mysql_error(mysql));
      exit(0);
    }

    /* Prepare an INSERT query with 3 parameters */
    /* (the TIMESTAMP column is not named; the server */
    /*  sets it to the current date and time) */
    stmt = mysql_stmt_init(mysql);
    if (!stmt)
    {
      fprintf(stderr, " mysql_stmt_init(), out of memory\n");
      exit(0);
    }
    if (mysql_stmt_prepare(stmt, INSERT_SAMPLE, strlen(INSERT_SAMPLE)))
    {
      fprintf(stderr, " mysql_stmt_prepare(), INSERT failed\n");
      fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
      exit(0);
    }
    fprintf(stdout, " prepare, INSERT successful\n");

    /* Get the parameter count from the statement */
    param_count= mysql_stmt_param_count(stmt);
    fprintf(stdout, " total parameters in INSERT: %d\n", param_count);

    if (param_count != 3) /* validate parameter count */
    {
      fprintf(stderr, " invalid parameter count returned by MySQL\n");
      exit(0);
    }

    /* Bind the data for all 3 parameters */

    memset(bind, 0, sizeof(bind));

    /* INTEGER PARAM */
    /* This is a number type, so there is no need to specify buffer_length */
    bind[0].buffer_type= MYSQL_TYPE_LONG;
    bind[0].buffer= (char *)&int_data;
    bind[0].is_null= 0;
    bind[0].length= 0;

    /* STRING PARAM */
    bind[1].buffer_type= MYSQL_TYPE_STRING;
    bind[1].buffer= (char *)str_data;
    bind[1].buffer_length= STRING_SIZE;
    bind[1].is_null= 0;
    bind[1].length= &str_length;

    /* SMALLINT PARAM */
    bind[2].buffer_type= MYSQL_TYPE_SHORT;
    bind[2].buffer= (char *)&small_data;
    bind[2].is_null= &is_null;
    bind[2].length= 0;

    /* Bind the buffers */
    if (mysql_stmt_bind_param(stmt, bind))
    {
      fprintf(stderr, " mysql_stmt_bind_param() failed\n");
      fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
      exit(0);
    }

    /* Specify the data values for the first row */
    int_data= 10;             /* integer */
    strncpy(str_data, "MySQL", STRING_SIZE); /* string  */
    str_length= strlen(str_data);

    /* INSERT SMALLINT data as NULL */
    is_null= 1;

    /* Execute the INSERT statement - 1*/
    if (mysql_stmt_execute(stmt))
    {
      fprintf(stderr, " mysql_stmt_execute(), 1 failed\n");
      fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
      exit(0);
    }

    /* Get the total number of affected rows */
    affected_rows= mysql_stmt_affected_rows(stmt);
    fprintf(stdout, " total affected rows(insert 1): %lu\n",
                    (unsigned long) affected_rows);

    if (affected_rows != 1) /* validate affected rows */
    {
      fprintf(stderr, " invalid affected rows by MySQL\n");
      exit(0);
    }

    /* Specify data values for second row, then re-execute the statement */
    int_data= 1000;
    strncpy(str_data, "The most popular Open Source database", STRING_SIZE);
    str_length= strlen(str_data);
    small_data= 1000;         /* smallint */
    is_null= 0;               /* reset */

    /* Execute the INSERT statement - 2*/
    if (mysql_stmt_execute(stmt))
    {
      fprintf(stderr, " mysql_stmt_execute, 2 failed\n");
      fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
      exit(0);
    }

    /* Get the total rows affected */
    affected_rows= mysql_stmt_affected_rows(stmt);
    fprintf(stdout, " total affected rows(insert 2): %lu\n",
                    (unsigned long) affected_rows);

    if (affected_rows != 1) /* validate affected rows */
    {
      fprintf(stderr, " invalid affected rows by MySQL\n");
      exit(0);
    }

    /* Close the statement */
    if (mysql_stmt_close(stmt))
    {
      fprintf(stderr, " failed while closing the statement\n");
      fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
      exit(0);
    }
}
コード例 #25
0
TIMESTAMP recorder::commit(TIMESTAMP t0, TIMESTAMP t1)
{
	// check trigger
	if ( trigger_on )
	{
		// trigger condition
		if ( target.compare(compare_op,compare_val) )
		{
			// disable trigger and enable data collection
			trigger_on = false;
			enabled = true;
		}
#ifdef _DEBUG
		else
		{
			char buffer[1024];
			target.to_string(buffer,sizeof(buffer));
			gl_verbose("trigger %s.%s not activated - '%s %s %s' did not pass", get_name(), get_property(), buffer, compare_op,compare_val);
		}
#endif
	}

	// collect data
	if ( enabled )
	{
		// convert data
		bool have_data = false;
		if ( target.is_double() )
		{
			real = target.get_double()*scale;
			gl_verbose("%s sampling: %s=%g", get_name(), target.get_name(), real);
			have_data = true;
		}
		else if ( target.is_integer() ) 
		{
			integer = target.get_integer();
			gl_verbose("%s sampling: %s=%lli", get_name(), target.get_name(), integer);
			have_data = true;
		}
		else if ( db->get_sqldata(string,sizeof(string)-1,target) )
		{
			gl_verbose("%s sampling: %s='%s'", get_name(), target.get_name(), (const char*)string);
			have_data = true;
		}
		else
		{
			gl_verbose("%s sampling: unable to sample %s", get_name(), target.get_name());
			have_data = false;
		}

		if ( have_data )
		{
			// use prepared statement if possible
			if ( insert )
			{
				if ( mysql_stmt_execute(insert)!=0 || stmt_error || mysql_stmt_affected_rows(insert)==0 )
				{
					int64 n = mysql_stmt_affected_rows(insert);
					gl_warning("unable to execute insert statement for target '%s' (%s) - reverting to slower INSERT", target.get_name(), mysql_stmt_error(insert));
					mysql_stmt_close(insert);
					insert = NULL;

					// if insert totally failed to add the row
					if ( n==0 )
						goto Insert;
				}
			}

			// use slower INSERT statement
			else
			{
Insert:
				// send data
				if ( target.is_double() )
				{
					db->query("INSERT INTO `%s` (t, `%s`) VALUES (from_unixtime('%"FMT_INT64"d'), '%.8g')",
						get_table(), (const char*)field, gl_globalclock, real);
				}
				else if ( target.is_integer() )
				{
					db->query("INSERT INTO `%s` (t, `%s`) VALUES (from_unixtime('%"FMT_INT64"d'), '%lli')",
						get_table(), (const char*)field, gl_globalclock, integer);
				}
				else{
					db->query("INSERT INTO `%s` (t, `%s`) VALUES (from_unixtime('%"FMT_INT64"d'), '%s')",
						get_table(), (const char*)field, gl_globalclock, (const char*)string);
				}
			}

			// check limit
			if ( get_limit()>0 && db->get_last_index()>=get_limit() )
			{
				// shut off recorder
				enabled=false;
				gl_verbose("table '%s' size limit %d reached", get_table(), get_limit());
			}
		}
	}
	
	return TS_NEVER;
}
コード例 #26
0
long long MysqlPreparedStatement_rowsChanged(T P) {
        assert(P);
        return (long long)mysql_stmt_affected_rows(P->stmt);
}
コード例 #27
0
ファイル: mysql.c プロジェクト: Hmaal/slash
static SLVAL
sl_mysql_stmt_execute(sl_vm_t* vm, SLVAL self, size_t argc, SLVAL* argv)
{
    mysql_stmt_t* stmt = get_mysql_stmt(vm, self);
    size_t req = mysql_stmt_param_count(stmt->stmt);
    if(argc < req) {
        char buff[100];
        sprintf(buff, "Prepared statement has %lu parameter markers, but only %lu parameters were given", req, argc);
        sl_throw_message2(vm, vm->lib.ArgumentError, buff);
    }

    if(!stmt->bind) {
        stmt->bind = sl_alloc(vm->arena, sizeof(MYSQL_BIND) * req);
    }

    for(size_t i = 0; i < req; i++) {
        stmt->bind[i].buffer_type = MYSQL_TYPE_STRING;
        sl_string_t* str = sl_get_string(vm, sl_to_s(vm, argv[i]));
        stmt->bind[i].buffer = str->buff;
        stmt->bind[i].buffer_length = str->buff_len;
        stmt->bind[i].length = NULL;
        stmt->bind[i].is_null = NULL;
        stmt->bind[i].is_unsigned = 1;
        stmt->bind[i].error = NULL;
    }

    if(mysql_stmt_bind_param(stmt->stmt, stmt->bind)) {
        sl_mysql_stmt_check_error(vm, stmt->stmt);
    }

    if(mysql_stmt_execute(stmt->stmt)) {
        sl_mysql_stmt_check_error(vm, stmt->stmt);
    }

    MYSQL_RES* res = mysql_stmt_result_metadata(stmt->stmt);
    if(!res) {
        /* query did not produce a result set */
        return sl_make_int(vm, mysql_stmt_affected_rows(stmt->stmt));
    }

    int field_count = mysql_stmt_field_count(stmt->stmt);
    MYSQL_FIELD* field;
    SLVAL field_names[field_count];
    enum enum_field_types field_types[field_count];
    size_t field_i = 0;
    while((field = mysql_fetch_field(res))) {
        field_names[field_i] = sl_make_cstring(vm, field->name);
        if(field->type == MYSQL_TYPE_LONG || field->type == MYSQL_TYPE_SHORT || field->type == MYSQL_TYPE_TINY) {
            field_types[field_i] = MYSQL_TYPE_LONG;
        } else {
            field_types[field_i] = MYSQL_TYPE_STRING;
        }
        field_i++;
    }

    MYSQL_BIND output_binds[field_count];
    my_bool output_errors[field_count];
    my_bool output_is_nulls[field_count];
    unsigned long output_lengths[field_count];
    for(int i = 0; i < field_count; i++) {
        output_binds[i].buffer_type = MYSQL_TYPE_STRING;
        output_binds[i].buffer = NULL;
        output_binds[i].buffer_length = 0;
        output_binds[i].length = &output_lengths[i];
        output_binds[i].is_null = &output_is_nulls[i];
        output_binds[i].error = &output_errors[i];
    }
    if(mysql_stmt_bind_result(stmt->stmt, output_binds)) {
        sl_mysql_stmt_check_error(vm, stmt->stmt);
    }

    SLVAL result_rows = sl_make_array(vm, 0, NULL);
    while(1) {
        int code = mysql_stmt_fetch(stmt->stmt);
        if(code == MYSQL_NO_DATA) {
            break;
        }
        if(code == 1) {
            sl_mysql_stmt_check_error(vm, stmt->stmt);
        }
        SLVAL row = sl_make_dict(vm, 0, NULL);
        for(int i = 0; i < field_count; i++) {
            MYSQL_BIND cell;
            cell.length = &output_lengths[i];
            cell.is_null = &output_is_nulls[i];
            cell.error = &output_errors[i];
            cell.buffer_type = field_types[i];
            int buffer_long;
            switch(field_types[i]) {
                case MYSQL_TYPE_LONG:
                    cell.buffer = &buffer_long;
                    cell.buffer_length = sizeof(buffer_long);
                    break;
                default: /* MYSQL_TYPE_STRING */
                    cell.buffer = sl_alloc_buffer(vm->arena, output_lengths[i] + 1);
                    cell.buffer_length = output_lengths[i];
                    break;
            }
            if(mysql_stmt_fetch_column(stmt->stmt, &cell, i, 0)) {
                sl_mysql_stmt_check_error(vm, stmt->stmt);
            }
            switch(field_types[i]) {
                case MYSQL_TYPE_LONG:
                    sl_dict_set(vm, row, field_names[i], sl_make_int(vm, buffer_long));
                    break;
                default: /* MYSQL_TYPE_STRING */
                    sl_dict_set(vm, row, field_names[i], sl_make_string(vm, cell.buffer, output_lengths[i]));
                    break;
            }
        }
        sl_array_push(vm, result_rows, 1, &row);
    }

    return result_rows;
}
コード例 #28
0
unsigned int MyStatement::GetAffectedRows()
{
	return (unsigned int)mysql_stmt_affected_rows(m_stmt);
}
コード例 #29
0
ファイル: library.c プロジェクト: c4125442/enterprise-search
void mysql_search_logg(MYSQL *demo_db, struct QueryDataForamt *QueryData, 
	struct SiderHederFormat *FinalSiderHeder, int totlaAds, 
	struct queryNodeHederFormat *queryNodeHeder, int nrOfServers, struct SiderFormat *Sider, 
	int nrOfPiServers) {
	/********************************************************************************************/
	//mysql logging
	/********************************************************************************************/

#ifndef MYSQL_VERSION_ID

	#error "MYSQL_VERSION_ID fra mysql_version.h er ikke definert"

#elif MYSQL_VERSION_ID==50045


	MYSQL_STMT *logstmt, *pilogstmt;
	char query [2048];
	MYSQL_BIND bind[12];
	unsigned long len[12];
	memset(bind, 0, sizeof(bind));
	logstmt = mysql_stmt_init(demo_db);
	pilogstmt = mysql_stmt_init(demo_db);

	if ((logstmt==NULL) || (pilogstmt==NULL)) {
		fprintf(stderr, "out of memory. Cant Create logstmt or pilogstmt");
	}

	sprintf(query,"INSERT DELAYED INTO search_logg (tid,query,search_bruker,treff,search_tid,ip_adresse,betaler_keywords_treff,HTTP_ACCEPT_LANGUAGE,HTTP_USER_AGENT,HTTP_REFERER,GeoIPLang,side) VALUES(NOW(),?,?,?,?,?,?,?,?,?,?,?)");

	if (mysql_stmt_prepare(logstmt, query, strlen(query)) != 0) {
		fprintf(stderr, " mysql_stmt_prepare(), INSERT INTO search_logg failed\n");
		fprintf(stderr, " Error: \"%s\"\n", mysql_stmt_error(logstmt));			
		return;
	}

	bind[0].buffer_type = MYSQL_TYPE_STRING; // query
	bind[0].buffer = QueryData->query;	// Ax: Max lengde i databasen er 30 tegn. Lage en nice-write?
	len[0] = strlen(QueryData->query);
	bind[0].length = &len[0];

	bind[1].buffer_type = MYSQL_TYPE_STRING; // user
	bind[1].buffer = QueryData->search_user;
	len[1] = strlen(QueryData->search_user);
	bind[1].length = &len[1];

	if (FinalSiderHeder==NULL) {

		bind[2].buffer_type = MYSQL_TYPE_NULL; // treff
		bind[2].buffer = NULL;

		bind[3].buffer_type = MYSQL_TYPE_NULL; // sÃketid
		bind[3].buffer = NULL;
	}
	else {
		bind[2].buffer_type = MYSQL_TYPE_LONG; // treff
		bind[2].buffer = &FinalSiderHeder->TotaltTreff;

		bind[3].buffer_type = MYSQL_TYPE_DOUBLE; // sÃketid
		bind[3].buffer = &FinalSiderHeder->total_usecs;
	}
	bind[4].buffer_type = MYSQL_TYPE_STRING; // ip
	bind[4].buffer = QueryData->userip;
	len[4] = strlen(QueryData->userip);
	bind[4].length = &len[4];

	bind[5].buffer_type = MYSQL_TYPE_LONG; // betaler
	bind[5].buffer = &totlaAds;
		
	bind[6].buffer_type = MYSQL_TYPE_STRING; // http lang
	bind[6].buffer = QueryData->HTTP_ACCEPT_LANGUAGE;
	len[6] = strlen(QueryData->HTTP_ACCEPT_LANGUAGE);
	bind[6].length = &len[6];

	bind[7].buffer_type = MYSQL_TYPE_STRING; // http user agent
	bind[7].buffer = QueryData->HTTP_USER_AGENT;
	len[7] = strlen(QueryData->HTTP_USER_AGENT);
	bind[7].length = &len[7];

	bind[8].buffer_type = MYSQL_TYPE_STRING; // http referer
	bind[8].buffer = QueryData->HTTP_REFERER;
	len[8] = strlen(QueryData->HTTP_REFERER);
	bind[8].length = &len[8];

	bind[9].buffer_type = MYSQL_TYPE_STRING; // geoip
	bind[9].buffer = QueryData->GeoIPcontry;
	len[9] = strlen(QueryData->GeoIPcontry);
	bind[9].length = &len[9];

	bind[10].buffer_type = MYSQL_TYPE_LONG; // side
	bind[10].buffer = &QueryData->start;


	mysql_stmt_bind_param(logstmt, bind);

	mysql_stmt_execute(logstmt);
	mysql_stmt_close(logstmt);


	/************************************************************************************************
	Logging av Paid Inclusion til sql db.
	************************************************************************************************/
	#ifndef BLACK_BOX
		if (Sider != NULL) {
			sprintf(query,"insert into pi_search_logg (tid,query,treff,search_tid,ip_adresse,spot,piDocID ) \
				select NOW(),?,?,?,?,?,id from pi_sider where WWWDocID=? ");


			if (mysql_stmt_prepare(pilogstmt, query, strlen(query)) != 0) {
				fprintf(stderr, " mysql_stmt_prepare(), INSERT into pi_search_logg failed\n");
				fprintf(stderr, " %s\n", mysql_stmt_error(pilogstmt));
				return;
			}

			i = QueryData->MaxsHits * (QueryData->start -1);
			x = i;

			while ((x<(QueryData->MaxsHits * QueryData->start)) && (x<FinalSiderHeder->showabal) && (i < (queryNodeHeder->MaxsHits * (nrOfServers + nrOfPiServers)))) {

				if (!Sider[i].deletet) {
					dprintf("pi analyse. Subname \"%s\", pi \"%i\"\n",Sider[i].subname.subname, (int)Sider[i].subname.config.isPaidInclusion);

					if (Sider[i].subname.config.isPaidInclusion) {
						unsigned int spot;

						spot = x + 1;		

						memset(bind, 0, sizeof(bind));
						memset(len, 0, sizeof(len)); // må vi ha denne?

						bind[0].buffer_type = MYSQL_TYPE_STRING; // query
						bind[0].buffer = QueryData->query;
						len[0] = strlen(QueryData->query);
						bind[0].length = &len[0];
						
						bind[1].buffer_type = MYSQL_TYPE_LONG; // treff
						bind[1].buffer = &FinalSiderHeder->TotaltTreff;
						
						bind[2].buffer_type = MYSQL_TYPE_DOUBLE; // sÃketid
						bind[2].buffer = &FinalSiderHeder->total_usecs;
						
						bind[3].buffer_type = MYSQL_TYPE_STRING; // ip
						bind[3].buffer = QueryData->userip;
						len[3] = strlen(QueryData->userip);
						bind[3].length = &len[3];

						bind[4].buffer_type = MYSQL_TYPE_LONG ; // spot 
						bind[4].buffer = &spot;
						bind[4].is_unsigned = 1; 
		
						bind[5].buffer_type = MYSQL_TYPE_LONG; // piDocID
						bind[5].buffer = &Sider[i].iindex.DocID;
						bind[5].is_unsigned = 1; 


						if (mysql_stmt_bind_param(pilogstmt, bind) != 0) {
							fprintf(stderr, " mysql_stmt_bind_param() failed\n");
							fprintf(stderr, " %s\n", mysql_stmt_error(pilogstmt));
						}

						if (mysql_stmt_execute(pilogstmt) != 0) {
							fprintf(stderr, " mysql_stmt_execute(), 1 failed\n");
							fprintf(stderr, " %s\n", mysql_stmt_error(pilogstmt));
						}

						/* Get the total number of affected rows */
						affected_rows= mysql_stmt_affected_rows(pilogstmt);

						if (affected_rows != 1) /* validate affected rows */
						{
							fprintf(stderr, " invalid affected rows by MySQL\n");
							fprintf(stderr, " total affected rows(insert 1): %lu\n", (unsigned long) affected_rows);
							break;
						}
					}
					else {
						//dprintf("is NOT pi! :(\n");
					}
				}
				//teller bare normale sider (hva med Paid Inclusion ?)
				// Denne skal vel vaere innenfor !deletet?
				if (Sider[i].type == siderType_normal) {
					++x;
				}

				++i;
			}

			mysql_stmt_close(pilogstmt);
		}
コード例 #30
0
ファイル: connection.cpp プロジェクト: piaoasd123/ServerTest
 size_t connection::run_prepared_remove_impl(prepared_statement_t& prepared_statement)
 {
   execute_prepared_statement(*prepared_statement._handle);
   return mysql_stmt_affected_rows(prepared_statement._handle->mysql_stmt);
 }