Esempio n. 1
0
static bool database_prepare(database_handler_t* handler, const char* sql)
{
	if (mysql_stmt_prepare(handler->stmt, sql, strlen(sql)))
	{
		if (mysql_stmt_errno(handler->stmt) == CR_SERVER_GONE_ERROR)
		{
			debug_log("mysql server gone, try to reopen mysql\n");
			if (!database_handler_reopen(handler))
			{
				error_log("reopen failure:%d,%s\n", mysql_stmt_errno(handler->stmt), mysql_stmt_error(handler->stmt));
				return false;
			}
			debug_log("reopen success\n");
			if (mysql_stmt_prepare(handler->stmt, sql, strlen(sql)))
			{
				error_log("mysql_stmt_prepare error:%d,%s\n", mysql_stmt_errno(handler->stmt), mysql_stmt_error(handler->stmt));
				return false;
			}
			return true;
		}
		error_log("mysql_stmt_prepare error:%d,%s, stmt:%s\n", mysql_stmt_errno(handler->stmt), mysql_stmt_error(handler->stmt), sql);
		return false;
	}
	/*uint32_t count = mysql_stmt_param_count(_stmt);*/
	/*debug_log("STATEMENT:%s, total parameters:%u\n", statement, count);*/
	return true;
}
Esempio n. 2
0
static bool database_bind_param(database_handler_t* handler, MYSQL_BIND* b)
{
	if (mysql_stmt_bind_param(handler->stmt, b))
	{
		if (mysql_stmt_errno(handler->stmt) == CR_SERVER_GONE_ERROR)
		{
			debug_log("try to reopen mysql\n");
			if (!database_handler_reopen(handler))
			{
				error_log("reopen failure:%d,%s\n", mysql_stmt_errno(handler->stmt), mysql_stmt_error(handler->stmt));
				return false;
			}
			debug_log("reopen success\n");
			if (mysql_stmt_bind_param(handler->stmt, b))
			{
				error_log("mysql_stmt_bind_param error:%d,%s\n", mysql_stmt_errno(handler->stmt), mysql_stmt_error(handler->stmt));
				return false;
			}
			return true;
		}
		error_log("mysql_stmt_bind_param error:%d,%s\n", mysql_stmt_errno(handler->stmt), mysql_stmt_error(handler->stmt));
		return false;
	}
	return true;
}
Esempio n. 3
0
static bool database_exec(database_handler_t* handler)
{
	if (mysql_stmt_execute(handler->stmt))
	{
		if (mysql_stmt_errno(handler->stmt) == CR_SERVER_GONE_ERROR)
		{
			debug_log("try to reopen mysql\n");
			if (!database_handler_reopen(handler))
			{
				error_log("reopen failure:%d,%s\n", mysql_stmt_errno(handler->stmt), mysql_stmt_error(handler->stmt));
				return false;
			}
			debug_log("reopen success\n");
			if (mysql_stmt_execute(handler->stmt))
			{
				error_log("mysql_stmt_execute error:%d,%s\n", mysql_stmt_errno(handler->stmt), mysql_stmt_error(handler->stmt));
				return false;
			}
			return true;
		}
		error_log("mysql_stmt_execute error:%d,%s\n", mysql_stmt_errno(handler->stmt), mysql_stmt_error(handler->stmt));
		return false;
	}
	/*uint32_t affected = mysql_stmt_affected_rows(handler->stmt);*/
	/*debug_log("This execute affected rows:%u\n", affected);*/
	return true;
}
Esempio n. 4
0
static bool database_free_result(database_handler_t* handler)
{
	if (mysql_stmt_free_result(handler->stmt))
	{
		if (mysql_stmt_errno(handler->stmt) == CR_SERVER_GONE_ERROR)
		{
			debug_log("try to reopen mysql\n");
			if (!database_handler_reopen(handler))
			{
				error_log("reopen failure:%d,%s\n", mysql_stmt_errno(handler->stmt), mysql_stmt_error(handler->stmt));
				return false;
			}
			debug_log("reopen success\n");
			if (mysql_stmt_free_result(handler->stmt))
			{
				error_log("mysql_stmt_free_result error:%d,%s\n", mysql_stmt_errno(handler->stmt), mysql_stmt_error(handler->stmt));
				return false;
			}
			return true;
		}
		error_log("mysql_stmt_free_result error:%d,%s\n", mysql_stmt_errno(handler->stmt), mysql_stmt_error(handler->stmt));
		return false;
	}
	return true;
}
Esempio n. 5
0
MError MMysqlCommand::BindResult()
{
    if (mysql_stmt_store_result(p_stmt_) != 0)
    {
        MLOG(MGetLibLogger(), MERR, "store result failed errno:", mysql_stmt_errno(p_stmt_), " error:", mysql_stmt_error(p_stmt_));
        return MError::Unknown;
    }
    MYSQL_RES *p_meta_res = mysql_stmt_result_metadata(p_stmt_);
    if (!p_meta_res)
    {
        MLOG(MGetLibLogger(), MERR, "have not meta res errno:", mysql_stmt_errno(p_stmt_), " error:", mysql_stmt_error(p_stmt_));
        return MError::Unknown;
    }
    MError err = MError::No;
    do
    {
        MYSQL_FIELD *p_field_list = mysql_fetch_fields(p_meta_res);
        if (!p_field_list)
        {
            MLOG(MGetLibLogger(), MERR, "mysql_fetch_fields is null unknown error");
            err = MError::Unknown;
            break;
        }
        unsigned long field_count = mysql_num_fields(p_meta_res);
        if (field_count == 0)
        {
            MLOG(MGetLibLogger(), MERR, "mysql field_count is 0");
            err = MError::Unknown;
            break;
        }
        out_params_.resize(field_count);
        out_datas_.resize(field_count);
        out_lengths_.resize(field_count);
        out_is_nulls_.resize(field_count);
        for (size_t i = 0; i < field_count; ++i)
        {
            MBlob &out_data = out_datas_[i];
            out_data.Resize(p_field_list[i].max_length);
            memset(&(out_params_[i]), 0, sizeof(out_params_[i]));
            out_params_[i].buffer_type = p_field_list[i].type;
            out_params_[i].buffer = out_data.GetData();
            out_params_[i].buffer_length = out_data.GetSize();
            out_params_[i].length = &(out_lengths_[i]);
            out_params_[i].is_null = &(out_is_nulls_[i]);
            out_params_[i].is_unsigned = (p_field_list[i].flags & UNSIGNED_FLAG);
            out_params_[i].error = nullptr;
        }
        if (mysql_stmt_bind_result(p_stmt_, &out_params_[0]) != 0)
        {
            MLOG(MGetLibLogger(), MERR, "bind result failed errno:", mysql_stmt_errno(p_stmt_), " error:", mysql_stmt_error(p_stmt_));
            err = MError::Unknown;
            break;
        }
        err = MError::No;
    } while (0);
    mysql_free_result(p_meta_res);
    return err;
}
Esempio n. 6
0
static MYSQL_STMT *
table_mysql_query(const char *key, int service)
{
	MYSQL_STMT	*stmt;
	MYSQL_BIND	 param[1];
	unsigned long	 keylen;
	char		 buffer[SMTPD_MAXLINESIZE];
	int		 i;

    retry:

	stmt = NULL;
	for(i = 0; i < SQL_MAX; i++)
		if (service == 1 << i) {
			stmt = config->statements[i];
			break;
		}

	if (stmt == NULL)
		return (NULL);

	if (strlcpy(buffer, key, sizeof(buffer)) >= sizeof(buffer)) {
		log_warnx("warn: table-mysql: key too long: \"%s\"", key);
		return (NULL);
	}

	keylen = strlen(key);

	param[0].buffer_type = MYSQL_TYPE_STRING;
	param[0].buffer = buffer;
	param[0].buffer_length = sizeof(buffer);
	param[0].is_null = 0;
	param[0].length = &keylen;

	if (mysql_stmt_bind_param(stmt, param)) {
		log_warnx("warn: table-mysql: mysql_stmt_bind_param: %s",
		    mysql_stmt_error(stmt));
		return (NULL);
	}

	if (mysql_stmt_execute(stmt)) {
		if (mysql_stmt_errno(stmt) == CR_SERVER_LOST ||
		    mysql_stmt_errno(stmt) == CR_SERVER_GONE_ERROR ||
		    mysql_stmt_errno(stmt) == CR_COMMANDS_OUT_OF_SYNC) {
			log_warnx("warn: table-mysql: trying to reconnect after error: %s",
			    mysql_stmt_error(stmt));
			if (config_connect(config))
				goto retry;
			return (NULL);
		}
		log_warnx("warn: table-mysql: mysql_stmt_execute: %s",
		    mysql_stmt_error(stmt));
		return (NULL);
	}

	return (stmt);
}
Esempio n. 7
0
uint32 MySQLPreparedStatement::execute(PreparedStatement *data)
{
    if (m_paramCount)
    {
        bindParameters(data);
        if (mysql_stmt_bind_param(m_stmt, m_bind) != 0)
            return mysql_stmt_errno(m_stmt);
    }

    return (mysql_stmt_execute(m_stmt) != 0)
            ? mysql_stmt_errno(m_stmt) : 0;
}
Esempio n. 8
0
/*
 * Prepares the directory check query.
 *
 * The input and results for this query are in the cur_dir_check variable.
 */
static MYSQL_STMT *
prepare_dir_query(sam_db_context_t *con) {
	MYSQL_STMT *stmt;
	char *query = "select name, ino, gen from sam_file where p_ino=? AND "
	    "p_gen=? order by ino, gen";
	MYSQL_BIND bind[2];
	MYSQL_BIND result[3];
	memset(&bind, 0, sizeof (bind));
	memset(&result, 0, sizeof (result));

	SAMDB_BIND(bind[0], cur_dir_check.p_ino, MYSQL_TYPE_LONG, TRUE);
	SAMDB_BIND(bind[1], cur_dir_check.p_gen, MYSQL_TYPE_LONG, TRUE);

	result[0].buffer = cur_dir_check.name;
	result[0].buffer_length = sizeof (cur_dir_check.name);
	result[0].length = &cur_dir_check.name_len;
	SAMDB_BIND(result[1], cur_dir_check.ino, MYSQL_TYPE_LONG, TRUE);
	SAMDB_BIND(result[2], cur_dir_check.gen, MYSQL_TYPE_LONG, TRUE);

	if ((stmt = mysql_stmt_init(con->mysql)) == NULL) {
		fprintf(stderr, "Error initializing statement: %s",
			mysql_error(con->mysql));
		return (NULL);
	}

	if (mysql_stmt_prepare(stmt, query, strlen(query)) != 0) {
		fprintf(stderr, "Error preparing statement: %s",
		    mysql_error(con->mysql));
		mysql_stmt_close(stmt);
		return (NULL);
	}

	if (mysql_stmt_bind_param(stmt, bind)) {
		fprintf(stderr, "Error binding params: (%d) %s",
		    mysql_stmt_errno(stmt), mysql_stmt_error(stmt));
		mysql_stmt_close(stmt);
		return (NULL);
	}

	if (mysql_stmt_bind_result(stmt, result)) {
		fprintf(stderr, "Error binding result: (%d) %s",
		    mysql_stmt_errno(stmt), mysql_stmt_error(stmt));
		mysql_stmt_close(stmt);
		return (NULL);
	}

	return (stmt);
}
Esempio n. 9
0
std::string StatementException::compose(const std::string& text, MYSQL_STMT* h, const std::string& stmt)
{
	std::string str;
	str += "[Comment]: ";
	str += text;

	if (h != 0)
	{
		str += "\t[mysql_stmt_error]: ";
		str += mysql_stmt_error(h);

		str += "\t[mysql_stmt_errno]: ";
		char buff[30];
		sprintf(buff, "%d", mysql_stmt_errno(h));
		str += buff;

		str += "\t[mysql_stmt_sqlstate]: ";
		str += mysql_stmt_sqlstate(h);
	}

	if (stmt.length() > 0)
	{
		str += "\t[statemnt]: ";
		str += stmt;
	}

	return str;
}
Esempio n. 10
0
SqlException::SqlException(MYSQL_STMT *stmt, const StringRef& initialMessage)
    :std::exception(initialMessage.c_str())
{
    mErrno = mysql_stmt_errno(stmt);
    mErrorMessage = mysql_stmt_error(stmt);
    mSqlState = mysql_stmt_sqlstate(stmt);
}
Esempio n. 11
0
/**=============================================================================
 * @ret 0 on success, -1 on error.
------------------------------------------------------------------------------*/
static int stmtAdd(
    dbconn * conn,
    int client_type,
    int qry_num)
{
    MYSQL *mysql = conn->mysql;
    const char *qry = queries[client_type][qry_num];
    MYSQL_STMT *stmt;

    stmt = conn->stmts[client_type][qry_num] = mysql_stmt_init(mysql);
    if (stmt == NULL)
    {
        LOG(LOG_ERR, "could not alloc for prepared statement");
        return -1;
    }

    if (mysql_stmt_prepare(stmt, qry, strlen(qry)))
    {
        LOG(LOG_ERR, "error preparing statement");
        LOG(LOG_ERR, "    %u: %s\n", mysql_stmt_errno(stmt),
            mysql_stmt_error(stmt));
        mysql_stmt_close(stmt);
        conn->stmts[client_type][qry_num] = NULL;
        return -1;
    }

    return 0;
}
Esempio n. 12
0
IPreparedQuery *MyDatabase::PrepareQuery(const char *query, char *error, size_t maxlength, int *errCode)
{
	MYSQL_STMT *stmt = mysql_stmt_init(m_mysql);
	if (!stmt)
	{
		if (error)
		{
			strncopy(error, GetError(errCode), maxlength);
		} else if (errCode) {
			*errCode = mysql_errno(m_mysql);
		}
		return NULL;
	}

	if (mysql_stmt_prepare(stmt, query, strlen(query)) != 0)
	{
		if (error)
		{
			strncopy(error, mysql_stmt_error(stmt), maxlength);
		}
		if (errCode)
		{
			*errCode = mysql_stmt_errno(stmt);
		}
		mysql_stmt_close(stmt);
		return NULL;
	}

	return new MyStatement(this, stmt);
}
Esempio n. 13
0
/* bool fetch (); */
NS_IMETHODIMP jxMySQL50Statement::Fetch(PRBool *_retval)
{
	if (mConnection == nsnull)
    {
        SET_ERROR_RETURN (JX_MYSQL50_ERROR_NOT_CONNECTED);
    }

    if (mSTMT == nsnull)
    {
        SET_ERROR_RETURN (JX_MYSQL50_ERROR_STMT_NULL);
    }

	PRInt32	ret = mysql_stmt_fetch(mSTMT);
	*_retval = PR_FALSE;

	if (!ret || ret == MYSQL_DATA_TRUNCATED) {
		*_retval = PR_TRUE;
	} else if (ret == MYSQL_NO_DATA) {
	   	*_retval = PR_FALSE;
	} else 
    {
		// const char* err = mysql_stmt_error(mSTMT);
		PRUint32 eno = mysql_stmt_errno(mSTMT);
		if ( eno == 2050 || eno == 2051 || eno == 2052 || eno == 2053)
        {
		  // No result set
		  return NS_OK;
        }

		SET_ERROR_RETURN (JX_MYSQL50_MYSQL_ERROR);
	}

	return NS_OK;

}
Esempio n. 14
0
void MADB_SetNativeError(MADB_Error *Error, SQLSMALLINT HandleType, void *Ptr)
{
  char *Sqlstate= NULL, *Errormsg= NULL;
  int NativeError= 0;

  switch (HandleType) {
  case SQL_HANDLE_DBC:
    Sqlstate= (char *)mysql_sqlstate((MYSQL *)Ptr);
    Errormsg= (char *)mysql_error((MYSQL *)Ptr);
    NativeError= mysql_errno((MYSQL *)Ptr);
    break;
  case SQL_HANDLE_STMT:
    Sqlstate= (char *)mysql_stmt_sqlstate((MYSQL_STMT *)Ptr);
    Errormsg= (char *)mysql_stmt_error((MYSQL_STMT *)Ptr);
    NativeError= mysql_stmt_errno((MYSQL_STMT *)Ptr);
    break;
  }
  if ((NativeError == 2013 || NativeError == 2006) && strcmp(Sqlstate, "HY000") == 0)
    Sqlstate= "08S01";

  Error->ReturnValue= SQL_ERROR;
  if (Errormsg)
  {
    strcpy_s(Error->SqlErrorMsg + Error->PrefixLen, SQL_MAX_MESSAGE_LENGTH + 1 - Error->PrefixLen, Errormsg);
  }
  if (Sqlstate)
    strcpy_s(Error->SqlState, SQLSTATE_LENGTH + 1, Sqlstate);
  Error->NativeError= NativeError;
  if (Error->SqlState[0] == '0')
    Error->ReturnValue= (Error->SqlState[1] == '0') ? SQL_SUCCESS :
                        (Error->SqlState[1] == '1') ? SQL_SUCCESS_WITH_INFO : SQL_ERROR;
}
Esempio n. 15
0
void
DbUtil::printStError(MYSQL_STMT *stmt, const char *msg)
{
  if (stmt && mysql_stmt_errno(stmt))
  {
    if (m_mysql && m_mysql->server_version)
      printf("\n [MySQL-%s]", m_mysql->server_version);
    else
      printf("\n [MySQL]");

    printf("[%d] %s\n", mysql_stmt_errno(stmt),
    mysql_stmt_error(stmt));
  }
  else if (msg)
    printf("[MySQL] %s\n", msg);
}
Esempio n. 16
0
int MySqlPreparedStatement::lastError() const
{
	if (_myStmt)
		return mysql_stmt_errno(_myStmt);

	return SqlPreparedStatement::lastError();
}
Esempio n. 17
0
void SqlCommand::AcquireErrorInfo() {
    if (m_stmt != nullptr) {
        const auto errorCode = mysql_stmt_errno(m_stmt);
        const auto errorMsg = mysql_stmt_error(m_stmt);
        m_sqlConnection.SetErrorInfo(errorCode, errorMsg);
    }
}
Esempio n. 18
0
int MYSQLC::PrepareSQL(PGLOBAL g, const char *stmt)
  {
  if (!m_DB) {
    strcpy(g->Message, "MySQL not connected");
    return -4;
  } else if (m_Stmt)
    return -1;              // should not append

#if defined(ALPHA)
  if (!(m_Stmt = mysql_prepare(m_DB, stmt, strlen(stmt)))) {

    sprintf(g->Message, "mysql_prepare failed: %s [%s]",
                         mysql_error(m_DB), stmt);
    return -1;
    } // endif m_Stmt

  // Return the parameter count from the statement
  return mysql_param_count(m_Stmt);
#else   // !ALPHA
  if (!(m_Stmt = mysql_stmt_init(m_DB))) {
    strcpy(g->Message, "mysql_stmt_init(), out of memory");
    return -2;
    } // endif m_Stmt

  if (mysql_stmt_prepare(m_Stmt, stmt, strlen(stmt))) {
    sprintf(g->Message, "mysql_stmt_prepare() failed: (%d) %s",
            mysql_stmt_errno(m_Stmt), mysql_stmt_error(m_Stmt));
    return -3;
    } // endif prepare

  // Return the parameter count from the statement
  return mysql_stmt_param_count(m_Stmt);
#endif   // !ALPHA
  } // end of PrepareSQL
Esempio n. 19
0
static void stmt_send_long_data_event(int fd, short event, void *_userdata) {
  struct maria_status *ms = (struct maria_status *)_userdata;
  st_data *st = (st_data *)ms->data;
  lua_State *L = ms->L;

  int errorcode = mysql_stmt_errno(st->my_stmt);
  if (errorcode) {
    FAN_RESUME(L, NULL, luamariadb_push_stmt_error(L, st));
    UNREF_CO(st);
  } else {
    my_bool ret = 0;
    int status = mysql_stmt_send_long_data_cont(&ret, st->my_stmt, ms->status);
    if (status) {
      wait_for_status(L, st->conn_data, st, status, stmt_send_long_data_event,
                      ms->extra);
    } else if (ret == 0) {
      int count = stmt_send_long_data_result(L, st);
      FAN_RESUME(L, NULL, count);
      UNREF_CO(st);
    } else {
      FAN_RESUME(L, NULL, luamariadb_push_stmt_error(L, st));
      UNREF_CO(st);
    }
  }

  event_free(ms->event);
  free(ms);
}
Esempio n. 20
0
void rb_raise_mysql2_stmt_error(mysql_stmt_wrapper *stmt_wrapper) {
  VALUE e;
  GET_CLIENT(stmt_wrapper->client);
  VALUE rb_error_msg = rb_str_new2(mysql_stmt_error(stmt_wrapper->stmt));
  VALUE rb_sql_state = rb_tainted_str_new2(mysql_stmt_sqlstate(stmt_wrapper->stmt));

#ifdef HAVE_RUBY_ENCODING_H
  rb_encoding *conn_enc;
  conn_enc = rb_to_encoding(wrapper->encoding);

  rb_encoding *default_internal_enc = rb_default_internal_encoding();

  rb_enc_associate(rb_error_msg, conn_enc);
  rb_enc_associate(rb_sql_state, conn_enc);
  if (default_internal_enc) {
    rb_error_msg = rb_str_export_to_enc(rb_error_msg, default_internal_enc);
    rb_sql_state = rb_str_export_to_enc(rb_sql_state, default_internal_enc);
  }
#endif

  e = rb_funcall(cMysql2Error, intern_new_with_args, 4,
                 rb_error_msg,
                 LONG2FIX(wrapper->server_version),
                 UINT2NUM(mysql_stmt_errno(stmt_wrapper->stmt)),
                 rb_sql_state);
  rb_exc_raise(e);
}
Esempio n. 21
0
static int dbd_mysql_prepare(apr_pool_t *pool, apr_dbd_t *sql,
                             const char *query, const char *label,
                             int nargs, int nvals, apr_dbd_type_e *types,
                             apr_dbd_prepared_t **statement)
{
    /* Translate from apr_dbd to native query format */
    int ret;

    if (!*statement) {
        *statement = apr_palloc(pool, sizeof(apr_dbd_prepared_t));
    }
    (*statement)->stmt = mysql_stmt_init(sql->conn);

    if ((*statement)->stmt) {
        apr_pool_cleanup_register(pool, (*statement)->stmt,
                                  stmt_close, apr_pool_cleanup_null);
        ret = mysql_stmt_prepare((*statement)->stmt, query, strlen(query));

        if (ret != 0) {
            ret = mysql_stmt_errno((*statement)->stmt);
        }

        (*statement)->nargs = nargs;
        (*statement)->nvals = nvals;
        (*statement)->types = types;

        return ret;
    }

    return CR_OUT_OF_MEMORY;
}
Esempio n. 22
0
static inline int wrapper_single_mysql_stmt_prepare(const db_con_t *conn,
												const struct my_stmt_ctx *ctx)
{
	int code, error;
	if (CON_DISCON(conn))
		return -1;

	code = mysql_stmt_prepare(ctx->stmt, ctx->query.s, ctx->query.len);
	if (code == 0)
		return 0;

	error = mysql_stmt_errno(ctx->stmt);
	switch (error) {
		case CR_SERVER_GONE_ERROR:
		case CR_SERVER_LOST:
		case CR_COMMANDS_OUT_OF_SYNC:
			return -1; /* reconnection error -> <0 */
		default:
			LM_CRIT("driver error (%i): %s\n",
				error, mysql_stmt_error(ctx->stmt));
			/* do not rely on libmysqlclient implementation
			 * specification says non-zero code on error, not positive code */
			return 1;
	}
}
Esempio n. 23
0
static QSqlError qMakeStmtError(const QString& err, QSqlError::ErrorType type,
                            MYSQL_STMT* stmt)
{
    const char *cerr = mysql_stmt_error(stmt);
    return QSqlError(QLatin1String("embedded3: ") + err,
                     QString::fromLatin1(cerr),
                     type, mysql_stmt_errno(stmt));
}
Esempio n. 24
0
 void DBManager::print_stmt_error (char *message) {
	fprintf (stderr, "%s\n", message);
	if (m_stmt != NULL) {
		fprintf (stderr, "Error %u (%s): %s\n",
		mysql_stmt_errno (m_stmt),
		mysql_stmt_sqlstate (m_stmt),
		mysql_stmt_error (m_stmt));
	}
}
Esempio n. 25
0
static void print_st_error(MYSQL_STMT *stmt, const char *msg)
{
 if (!opt_silent)
 {
   if (stmt && mysql_stmt_errno(stmt))
   {
     if (stmt->mysql && stmt->mysql->server_version)
     fprintf(stdout, "\n [MySQL-%s]", stmt->mysql->server_version);
     else
     fprintf(stdout, "\n [MySQL]");

     fprintf(stdout, "[%d] %s\n", mysql_stmt_errno(stmt),
     mysql_stmt_error(stmt));
   }
   else if (msg)
   fprintf(stderr, " [MySQL] %s\n", msg);
 }
}
Esempio n. 26
0
static void test_stmt_error(MYSQL_STMT *stmt, int status)
{
    if (status)
    {
        fprintf(stderr, "Error: %s (errno: %d)\n",
                mysql_stmt_error(stmt), mysql_stmt_errno(stmt));
        exit(1);
    }
}
Esempio n. 27
0
const char *MyStatement::GetError(int *errCode/* =NULL */)
{
	if (errCode)
	{
		*errCode = mysql_stmt_errno(m_stmt);
	}

	return mysql_stmt_error(m_stmt);
}
Esempio n. 28
0
void
raise_mysql_stmt_error(MYSQL_STMT * stmt)
{

	err_code = mysql_stmt_errno(stmt);
	err_msg = mysql_stmt_error(stmt);
#ifdef DEBUG
	fprintf(stderr,"DEBUG OSQL: %d %s\n",err_code,err_msg);
#endif
}
Esempio n. 29
0
void print_mysql_stmt_error (MYSQL_STMT *stmt, const std::string &mensaje)
{
    std::cerr << mensaje << std::endl;

    if (stmt != NULL) {
        std::cerr << "Error " << mysql_stmt_errno (stmt);
        std::cerr << "(" << mysql_stmt_sqlstate (stmt);
        std::cerr << "): " << mysql_stmt_error (stmt) << std::endl;
    }
}
Esempio n. 30
0
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;
}