fix decimal type error

This commit is contained in:
cqliang1995
2023-08-02 03:12:23 +00:00
committed by ob-robot
parent 01cc0d4ccb
commit f3a7c8593a
5 changed files with 73 additions and 7 deletions

View File

@ -234,6 +234,15 @@ int ObMySQLConnection::connect(const char *user, const char *pass, const char *d
LOG_WARN("fail to connect to mysql server", K(get_sessid()), KCSTRING(host), KCSTRING(user), KCSTRING(db), K(port), LOG_WARN("fail to connect to mysql server", K(get_sessid()), KCSTRING(host), KCSTRING(user), KCSTRING(db), K(port),
"info", mysql_error(&mysql_), K(ret)); "info", mysql_error(&mysql_), K(ret));
if (OB_INVALID_ID != get_dblink_id()) { if (OB_INVALID_ID != get_dblink_id()) {
LOG_WARN("dblink connection error", K(ret),
KP(this),
K(get_dblink_id()),
K(get_sessid()),
K(usable()),
K(user),
K(db),
K(host),
K(port));
TRANSLATE_CLIENT_ERR_2(ret, false, mysql_error(&mysql_)); TRANSLATE_CLIENT_ERR_2(ret, false, mysql_error(&mysql_));
} }
} else { } else {

View File

@ -86,12 +86,20 @@ int ObMySQLResult::format_precision_scale_length(int16_t &precision, int16_t &sc
// format precision from others to oceanbase // format precision from others to oceanbase
if (!lib::is_oracle_mode()) { if (!lib::is_oracle_mode()) {
switch (ob_type) { switch (ob_type) {
case ObUNumberType: case ObUNumberType:{
case ObNumberType: { // for mysql decimal if (0 != scale) {
if (2 == length) { precision = length - 1;// remove length of decimal point
precision = 1;
} else { } else {
precision = length - 1; precision = length;
}
length = -1;
break;
}
case ObNumberType: {
if (0 != scale) {
precision = length - 2;// remove length of decimal point and sign(-/+)
} else {
precision = length - 1;// remove length of decimal point
} }
length = -1; length = -1;
break; break;

View File

@ -23,6 +23,7 @@
#include "common/ob_zerofill_info.h" #include "common/ob_zerofill_info.h"
#include "lib/timezone/ob_timezone_info.h" #include "lib/timezone/ob_timezone_info.h"
#include "lib/string/ob_hex_utils_base.h" #include "lib/string/ob_hex_utils_base.h"
#include "lib/mysqlclient/ob_dblink_error_trans.h"
namespace oceanbase namespace oceanbase
{ {
@ -143,7 +144,33 @@ int ObMySQLResultImpl::next()
ret = OB_ERR_UNEXPECTED; ret = OB_ERR_UNEXPECTED;
LOG_ERROR("result must not be null", K(ret)); LOG_ERROR("result must not be null", K(ret));
} else if (OB_ISNULL(cur_row_ = mysql_fetch_row(result_))) { } else if (OB_ISNULL(cur_row_ = mysql_fetch_row(result_))) {
ret = OB_ITER_END; MYSQL *stmt_handler = stmt_.get_stmt_handler();
if (OB_ISNULL(stmt_handler)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected null ptr", K(ret));
} else {
ret = -mysql_errno(stmt_handler);
const char *errmsg = mysql_error(stmt_handler);
ObMySQLConnection *conn = stmt_.get_connection();
if (0 == ret) {
ret = OB_ITER_END;
} else if (OB_ISNULL(conn)) {
int tmp_ret = ret;
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected null ptr", K(errmsg), K(tmp_ret), K(ret));
} else if (OB_INVALID_ID != conn->get_dblink_id()) {
LOG_WARN("dblink connection error", K(ret),
KP(conn),
K(conn->get_dblink_id()),
K(conn->get_sessid()),
K(conn->usable()),
K(conn->ping()));
TRANSLATE_CLIENT_ERR(ret, errmsg);
if (ObMySQLStatement::is_need_disconnect_error(ret)) {
conn->set_usable(false);
}
}
}
} else if (OB_ISNULL(cur_row_result_lengths_ = mysql_fetch_lengths(result_))) { } else if (OB_ISNULL(cur_row_result_lengths_ = mysql_fetch_lengths(result_))) {
ret = OB_ERR_UNEXPECTED; ret = OB_ERR_UNEXPECTED;
LOG_WARN("calling is out of sync", K(ret)); LOG_WARN("calling is out of sync", K(ret));

View File

@ -108,6 +108,17 @@ int ObMySQLStatement::execute_update(int64_t &affected_rows)
conn_->get_root()->get_root()->signal_refresh(); // refresh server pool immediately conn_->get_root()->get_root()->signal_refresh(); // refresh server pool immediately
} }
if (OB_INVALID_ID != conn_->get_dblink_id()) { if (OB_INVALID_ID != conn_->get_dblink_id()) {
LOG_WARN("dblink connection error", K(ret),
KP(conn_),
K(conn_->get_dblink_id()),
K(conn_->get_sessid()),
K(conn_->usable()),
K(conn_->ping()),
K(stmt_->host),
K(stmt_->port),
K(mysql_error(stmt_)),
K(STRLEN(sql_str_)),
K(sql_str_));
TRANSLATE_CLIENT_ERR(ret, mysql_error(stmt_)); TRANSLATE_CLIENT_ERR(ret, mysql_error(stmt_));
} }
if (is_need_disconnect_error(ret)) { if (is_need_disconnect_error(ret)) {
@ -151,6 +162,17 @@ ObMySQLResult *ObMySQLStatement::execute_query(bool enable_use_result)
ret = OB_ERR_SQL_CLIENT; ret = OB_ERR_SQL_CLIENT;
LOG_WARN("can not get errno", K(ret)); LOG_WARN("can not get errno", K(ret));
} else if (OB_INVALID_ID != conn_->get_dblink_id()) { } else if (OB_INVALID_ID != conn_->get_dblink_id()) {
LOG_WARN("dblink connection error", K(ret),
KP(conn_),
K(conn_->get_dblink_id()),
K(conn_->get_sessid()),
K(conn_->usable()),
K(conn_->ping()),
K(stmt_->host),
K(stmt_->port),
K(mysql_error(stmt_)),
K(STRLEN(sql_str_)),
K(sql_str_));
TRANSLATE_CLIENT_ERR(ret, mysql_error(stmt_)); TRANSLATE_CLIENT_ERR(ret, mysql_error(stmt_));
} }
if (is_need_disconnect_error(ret)) { if (is_need_disconnect_error(ret)) {

View File

@ -50,7 +50,7 @@ public:
* but ignore affected_rows * but ignore affected_rows
*/ */
int execute_update(); int execute_update();
bool is_need_disconnect_error(int ret); static bool is_need_disconnect_error(int ret);
/* /*
* ! Deprecated * ! Deprecated