to issue<48134183><49317125>:fix anonymous block parameterization issue and check datatype oversize
This commit is contained in:
@ -1341,10 +1341,8 @@ int ObPL::trans_sql(PlTransformTreeCtx &trans_ctx, ParseNode *root, ObExecContex
|
||||
if (NULL == buf) {
|
||||
LOG_WARN("fail to alloc buf", K(pc_ctx.raw_sql_.length()));
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
} else if (OB_FAIL(ObSqlParameterization::construct_sql(pc_ctx.fp_result_.pc_key_.name_, special_params, buf, pc_ctx.raw_sql_.length(), pos))) {
|
||||
} else if (OB_FAIL(ObSqlParameterization::construct_sql_for_pl(pc_ctx.fp_result_.pc_key_.name_, special_params, buf, pc_ctx.raw_sql_.length(), pos))) {
|
||||
LOG_WARN("fail to construct_sql", K(ret));
|
||||
} else if (OB_FAIL(ObSqlParameterization::transform_neg_param(pc_ctx.fp_result_.raw_params_))) {
|
||||
LOG_WARN("fail to transform_neg_param", K(ret));
|
||||
} else {
|
||||
if (trans_ctx.buf_size_ < trans_ctx.buf_len_ + pos) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
|
||||
@ -1234,22 +1234,16 @@ int ObSqlParameterization::transform_neg_param(ObIArray<ObPCParam *> &pc_params)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSqlParameterization::construct_sql(const ObString &no_param_sql,
|
||||
ObIArray<ObPCParam *> &pc_params,
|
||||
int ObSqlParameterization::construct_not_param(const ObString &no_param_sql,
|
||||
ObPCParam *pc_param,
|
||||
char *buf,
|
||||
int32_t buf_len,
|
||||
int32_t &pos) //已存的长度
|
||||
int32_t &pos,
|
||||
int32_t &idx)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int32_t idx = 0; //原始带?sql的偏移位置
|
||||
ObPCParam *pc_param = NULL;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < pc_params.count(); i ++) {
|
||||
pc_param = pc_params.at(i);
|
||||
int32_t len = 0; //需要copy的text的长度
|
||||
if (OB_ISNULL(pc_param)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SQL_PC_LOG(WARN, "invalid argument", K(ret));
|
||||
} else if (NOT_PARAM == pc_param->flag_) {
|
||||
CK (OB_NOT_NULL(pc_param));
|
||||
if (OB_SUCC(ret)) {
|
||||
int32_t len = (int32_t)pc_param->node_->pos_ - idx;
|
||||
if (len > buf_len - pos) {
|
||||
ret = OB_BUF_NOT_ENOUGH;
|
||||
@ -1262,8 +1256,21 @@ int ObSqlParameterization::construct_sql(const ObString &no_param_sql,
|
||||
MEMCPY(buf + pos, pc_param->node_->raw_text_, pc_param->node_->text_len_);
|
||||
pos += (int32_t)pc_param->node_->text_len_;
|
||||
}
|
||||
} else if (NEG_PARAM == pc_param->flag_) {
|
||||
len = (int32_t)pc_param->node_->pos_ - idx;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSqlParameterization::construct_neg_param(const ObString &no_param_sql,
|
||||
ObPCParam *pc_param,
|
||||
char *buf,
|
||||
int32_t buf_len,
|
||||
int32_t &pos,
|
||||
int32_t &idx)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
CK (OB_NOT_NULL(pc_param));
|
||||
if (OB_SUCC(ret)) {
|
||||
int32_t len = (int32_t)pc_param->node_->pos_ - idx;
|
||||
if (len > buf_len - pos) {
|
||||
ret = OB_BUF_NOT_ENOUGH;
|
||||
} else if (len > 0) {
|
||||
@ -1274,8 +1281,21 @@ int ObSqlParameterization::construct_sql(const ObString &no_param_sql,
|
||||
idx = (int32_t)pc_param->node_->pos_ + 1;
|
||||
buf[pos++] = '?';
|
||||
}
|
||||
} else if (TRANS_NEG_PARAM == pc_param->flag_) {
|
||||
len = (int32_t)pc_param->node_->pos_ - idx;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSqlParameterization::construct_trans_neg_param(const ObString &no_param_sql,
|
||||
ObPCParam *pc_param,
|
||||
char *buf,
|
||||
int32_t buf_len,
|
||||
int32_t &pos,
|
||||
int32_t &idx)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
CK (OB_NOT_NULL(pc_param));
|
||||
if (OB_SUCC(ret)) {
|
||||
int32_t len = (int32_t)pc_param->node_->pos_ - idx;
|
||||
if (len > buf_len - pos) {
|
||||
ret = OB_BUF_NOT_ENOUGH;
|
||||
} else if (len > 0) {
|
||||
@ -1308,6 +1328,77 @@ int ObSqlParameterization::construct_sql(const ObString &no_param_sql,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSqlParameterization::construct_sql(const ObString &no_param_sql,
|
||||
ObIArray<ObPCParam *> &pc_params,
|
||||
char *buf,
|
||||
int32_t buf_len,
|
||||
int32_t &pos) //已存的长度
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int32_t idx = 0; //原始带?sql的偏移位置
|
||||
ObPCParam *pc_param = NULL;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < pc_params.count(); i ++) {
|
||||
pc_param = pc_params.at(i);
|
||||
int32_t len = 0; //需要copy的text的长度
|
||||
if (OB_ISNULL(pc_param)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SQL_PC_LOG(WARN, "invalid argument", K(ret));
|
||||
} else if (NOT_PARAM == pc_param->flag_) {
|
||||
OZ (construct_not_param(no_param_sql, pc_param, buf, buf_len, pos, idx));
|
||||
} else if (NEG_PARAM == pc_param->flag_) {
|
||||
OZ (construct_neg_param(no_param_sql, pc_param, buf, buf_len, pos, idx));
|
||||
} else if (TRANS_NEG_PARAM == pc_param->flag_) {
|
||||
OZ (construct_trans_neg_param(no_param_sql, pc_param, buf, buf_len, pos, idx));
|
||||
} else {
|
||||
//do nothing
|
||||
}
|
||||
} //for end
|
||||
|
||||
if (OB_SUCCESS == ret) {
|
||||
int32_t len = no_param_sql.length() - idx;
|
||||
if (len > buf_len - pos) {
|
||||
ret = OB_BUF_NOT_ENOUGH;
|
||||
} else if (len > 0) {
|
||||
MEMCPY(buf + pos, no_param_sql.ptr() + idx, len);
|
||||
idx += len;
|
||||
pos += len;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSqlParameterization::construct_sql_for_pl(const ObString &no_param_sql,
|
||||
ObIArray<ObPCParam *> &pc_params,
|
||||
char *buf,
|
||||
int32_t buf_len,
|
||||
int32_t &pos) //已存的长度
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int32_t idx = 0; //原始带?sql的偏移位置
|
||||
ObPCParam *pc_param = NULL;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < pc_params.count(); i ++) {
|
||||
pc_param = pc_params.at(i);
|
||||
int32_t len = 0; //需要copy的text的长度
|
||||
if (OB_ISNULL(pc_param)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SQL_PC_LOG(WARN, "invalid argument", K(ret));
|
||||
} else if (NOT_PARAM == pc_param->flag_) {
|
||||
int32_t len = (int32_t)pc_param->node_->pos_ - idx;
|
||||
if (0 == len) {
|
||||
MEMCPY(buf + pos, pc_param->node_->raw_text_, pc_param->node_->text_len_);
|
||||
pos += (int32_t)pc_param->node_->text_len_;
|
||||
idx = (int32_t)pc_param->node_->pos_ + 1;
|
||||
} else {
|
||||
OZ (construct_not_param(no_param_sql, pc_param, buf, buf_len, pos, idx));
|
||||
}
|
||||
} else if (NEG_PARAM == pc_param->flag_) {
|
||||
OZ (construct_neg_param(no_param_sql, pc_param, buf, buf_len, pos, idx));
|
||||
} else if (TRANS_NEG_PARAM == pc_param->flag_) {
|
||||
OZ (construct_trans_neg_param(no_param_sql, pc_param, buf, buf_len, pos, idx));
|
||||
} else {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
@ -146,11 +146,34 @@ public:
|
||||
const SqlInfo ¬_param_info,
|
||||
common::ObIArray<ObPCParam *> &special_param_info);
|
||||
static int transform_neg_param(ObIArray<ObPCParam *> &pc_params);
|
||||
static int construct_not_param(const ObString &no_param_sql,
|
||||
ObPCParam *pc_param,
|
||||
char *buf,
|
||||
int32_t buf_len,
|
||||
int32_t &pos,
|
||||
int32_t &idx);
|
||||
static int construct_neg_param(const ObString &no_param_sql,
|
||||
ObPCParam *pc_param,
|
||||
char *buf,
|
||||
int32_t buf_len,
|
||||
int32_t &pos,
|
||||
int32_t &idx);
|
||||
static int construct_trans_neg_param(const ObString &no_param_sql,
|
||||
ObPCParam *pc_param,
|
||||
char *buf,
|
||||
int32_t buf_len,
|
||||
int32_t &pos,
|
||||
int32_t &idx);
|
||||
static int construct_sql(const common::ObString &no_param_sql,
|
||||
common::ObIArray<ObPCParam *> ¬_params,
|
||||
char *buf,
|
||||
int32_t buf_len,
|
||||
int32_t &pos);
|
||||
static int construct_sql_for_pl(const common::ObString &no_param_sql,
|
||||
common::ObIArray<ObPCParam *> ¬_params,
|
||||
char *buf,
|
||||
int32_t buf_len,
|
||||
int32_t &pos);
|
||||
static int parameterize_syntax_tree(common::ObIAllocator &allocator,
|
||||
bool is_transform_outline,
|
||||
ObPlanCacheCtx &pc_ctx,
|
||||
|
||||
@ -5398,8 +5398,12 @@ int ObResolverUtils::resolve_data_type(const ParseNode &type_node,
|
||||
break;
|
||||
case ObStringTC:
|
||||
data_type.set_length(length);
|
||||
|
||||
if (ObVarcharType != data_type.get_obj_type()
|
||||
if (length < -1) { // length is more than 32 bit
|
||||
ret = OB_ERR_TOO_LONG_COLUMN_LENGTH;
|
||||
LOG_WARN("column data length is invalid", K(ret), K(length), K(data_type));
|
||||
LOG_USER_ERROR(OB_ERR_TOO_LONG_COLUMN_LENGTH, ident_name.ptr(),
|
||||
static_cast<int>(OB_MAX_MYSQL_VARCHAR_LENGTH));
|
||||
} else if (ObVarcharType != data_type.get_obj_type()
|
||||
&& ObCharType != data_type.get_obj_type()
|
||||
&& ObNVarchar2Type != data_type.get_obj_type()
|
||||
&& ObNCharType != data_type.get_obj_type()) {
|
||||
|
||||
Reference in New Issue
Block a user