Skip to content

Commit

Permalink
Fixed CORE-4604 - EXECUTE STATEMENT rise varchar char_length() size.
Browse files Browse the repository at this point in the history
  • Loading branch information
asfernandes committed Nov 12, 2014
1 parent f195873 commit 3cde9ca
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/dsql/dsql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3251,16 +3251,29 @@ static UCHAR* var_info(dsql_msg* message,
break;

case dtype_text:
if (input_message && (param->par_desc.dsc_flags & DSC_null))
case dtype_varying:
if (input_message &&
(param->par_desc.dsc_dtype == dtype_text || param->par_is_text) &&
(param->par_desc.dsc_flags & DSC_null))
{
sql_type = SQL_NULL;
sql_len = 0;
sql_sub_type = 0;
}
else
else if (param->par_desc.dsc_dtype == dtype_text || param->par_is_text)
{
sql_type = SQL_TEXT;
sql_sub_type = param->par_desc.dsc_sub_type;
if (param->par_desc.dsc_dtype == dtype_varying)
sql_len -= sizeof(USHORT);
}
else
{
sql_type = SQL_VARYING;
sql_len -= sizeof(USHORT);
sql_sub_type = param->par_desc.dsc_sub_type;
}

break;

case dtype_blob:
Expand All @@ -3269,12 +3282,6 @@ static UCHAR* var_info(dsql_msg* message,
sql_scale = param->par_desc.dsc_scale;
break;

case dtype_varying:
sql_type = SQL_VARYING;
sql_len -= sizeof(USHORT);
sql_sub_type = param->par_desc.dsc_sub_type;
break;

case dtype_short:
case dtype_long:
case dtype_int64:
Expand Down
1 change: 1 addition & 0 deletions src/dsql/dsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ class dsql_par : public pool_alloc<dsql_type_par>
DSC par_user_desc; // SQLDA data type
USHORT par_parameter; // BLR parameter number
USHORT par_index; // Index into SQLDA, if appropriate
bool par_is_text; // Parameter should be dtype_text (SQL_TEXT) externaly
};

/*! \var unsigned DSQL_debug
Expand Down
10 changes: 10 additions & 0 deletions src/dsql/gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,16 @@ void GEN_port(CompiledStatement* statement, dsql_msg* message)
parameter->par_desc.setTextType(toCharSet);
}

if (parameter->par_desc.dsc_dtype == dtype_text && parameter->par_index != 0)
{
// We should convert par_desc from text to varying so the user can receive it with
// correct length when requesting it as varying. See CORE-2606.
// But we flag it to describe as text.
parameter->par_is_text = true;
parameter->par_desc.dsc_dtype = dtype_varying;
parameter->par_desc.dsc_length += sizeof(USHORT);
}

// For older clients - generate an error should they try and
// access data types which did not exist in the older dialect
if (statement->req_client_dialect <= SQL_DIALECT_V5)
Expand Down
6 changes: 6 additions & 0 deletions src/jrd/extds/IscDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ void IscStatement::doPrepare(thread_db* tdbb, const string& sql)
raise(status, tdbb, sWhereError, &sql);
}

for (int i = 0; i != m_out_xsqlda->sqld; ++i)
{
if (m_out_xsqlda->sqlvar[i].sqltype == SQL_TEXT)
m_out_xsqlda->sqlvar[i].sqltype = SQL_VARYING;
}

parseSQLDA(m_out_xsqlda, m_out_buffer, m_outDescs);
m_outputs = m_out_xsqlda ? m_out_xsqlda->sqld : 0;

Expand Down

0 comments on commit 3cde9ca

Please sign in to comment.