Merge branch '2.3' into develop

This commit is contained in:
Johan Wikman
2019-05-03 13:48:57 +03:00
19 changed files with 517 additions and 21 deletions

View File

@ -195,6 +195,7 @@ static struct
static thread_local struct
{
qc_sql_mode_t sql_mode;
uint32_t options;
NAME_MAPPING* function_name_mappings;
// The version information is not used; the embedded library parses according
// to the version of the embedded library it has been linked with. However, we
@ -203,6 +204,7 @@ static thread_local struct
} this_thread =
{
QC_SQL_MODE_DEFAULT,
0,
function_name_mappings_default,
0
};
@ -2276,7 +2278,6 @@ static void unalias_names(st_select_lex* select,
}
static void add_field_info(parsing_info_t* info,
st_select_lex* select,
const char* database,
const char* table,
const char* column,
@ -2284,8 +2285,6 @@ static void add_field_info(parsing_info_t* info,
{
mxb_assert(column);
unalias_names(select, database, table, &database, &table);
QC_FIELD_INFO item = {(char*)database, (char*)table, (char*)column};
size_t i;
@ -2361,6 +2360,20 @@ static void add_field_info(parsing_info_t* info,
}
}
static void add_field_info(parsing_info_t* info,
st_select_lex* select,
const char* database,
const char* table,
const char* column,
List<Item>* excludep)
{
mxb_assert(column);
unalias_names(select, database, table, &database, &table);
add_field_info(info, database, table, column, excludep);
}
static void add_function_field_usage(const char* database,
const char* table,
const char* column,
@ -2485,6 +2498,19 @@ static void add_function_field_usage(st_select_lex* select,
add_function_field_usage(select, static_cast<Item_field*>(item), fi);
break;
case Item::STRING_ITEM:
if (this_thread.options & QC_OPTION_STRING_ARG_AS_FIELD)
{
String* s = item->val_str();
int len = s->length();
char tmp[len + 1];
memcpy(tmp, s->ptr(), len);
tmp[len] = 0;
add_function_field_usage(nullptr, nullptr, tmp, fi);
}
break;
default:
// mxb_assert(!true);
;
@ -3058,6 +3084,19 @@ static void update_field_infos(parsing_info_t* pi,
}
break;
case Item::STRING_ITEM:
if (this_thread.options & QC_OPTION_STRING_AS_FIELD)
{
String* s = item->val_str();
int len = s->length();
char tmp[len + 1];
memcpy(tmp, s->ptr(), len);
tmp[len] = 0;
add_field_info(pi, nullptr, nullptr, tmp, excludep);
}
break;
default:
break;
}
@ -3536,6 +3575,27 @@ int32_t qc_mysql_set_sql_mode(qc_sql_mode_t sql_mode)
return rv;
}
uint32_t qc_mysql_get_options()
{
return this_thread.options;
}
int32_t qc_mysql_set_options(uint32_t options)
{
int32_t rv = QC_RESULT_OK;
if ((options & ~QC_OPTION_MASK) == 0)
{
this_thread.options = options;
}
else
{
rv = QC_RESULT_ERROR;
}
return rv;
}
/**
* EXPORTS
*/
@ -3571,6 +3631,8 @@ extern "C"
qc_mysql_set_sql_mode,
nullptr, // qc_info_dup not supported.
nullptr, // qc_info_close not supported.
qc_mysql_get_options,
qc_mysql_set_options,
nullptr, // qc_get_result_from_info not supported
};

View File

@ -155,6 +155,7 @@ static thread_local struct
bool initialized; // Whether the thread specific data has been initialized.
sqlite3* pDb; // Thread specific database handle.
qc_sql_mode_t sql_mode; // What sql_mode is used.
uint32_t options; // Options affecting classification.
QcSqliteInfo* pInfo; // The information for the current statement being classified.
uint64_t version; // Encoded version number
uint32_t version_major;
@ -842,6 +843,14 @@ public:
update_field_infos_from_expr(pAliases, context, pExpr, pExclude);
break;
case TK_STRING: // select "a" ..., for @@sql_mode containing 'ANSI_QUOTES'
if (this_thread.options & QC_OPTION_STRING_AS_FIELD)
{
const char* zColumn = pExpr->u.zToken;
update_field_infos_from_column(pAliases, context, zColumn, pExclude);
}
break;
case TK_VARIABLE:
{
if (zToken[0] == '@')
@ -1152,6 +1161,13 @@ public:
}
}
}
else if (pExpr->op == TK_STRING)
{
if (this_thread.options & QC_OPTION_STRING_ARG_AS_FIELD)
{
zColumn = pExpr->u.zToken;
}
}
if (zColumn)
{
@ -1187,6 +1203,17 @@ public:
}
}
void update_field_infos_from_column(QcAliases* pAliases,
uint32_t context,
const char* zColumn,
const ExprList* pExclude)
{
if (must_check_sequence_related_functions() || must_collect_fields())
{
update_field_info(pAliases, context, nullptr, nullptr, zColumn, pExclude);
}
}
void update_field_infos_from_exprlist(QcAliases* pAliases,
uint32_t context,
const ExprList* pEList,
@ -4577,6 +4604,8 @@ static int32_t qc_sqlite_get_sql_mode(qc_sql_mode_t* sql_mode);
static int32_t qc_sqlite_set_sql_mode(qc_sql_mode_t sql_mode);
static QC_STMT_INFO* qc_sqlite_info_dup(QC_STMT_INFO* info);
static void qc_sqlite_info_close(QC_STMT_INFO* info);
static uint32_t qc_sqlite_get_options();
static int32_t qc_sqlite_set_options(uint32_t options);
static QC_STMT_RESULT qc_sqlite_get_result_from_info(const QC_STMT_INFO* pInfo);
@ -5261,6 +5290,27 @@ void qc_sqlite_info_close(QC_STMT_INFO* info)
static_cast<QcSqliteInfo*>(info)->dec_ref();
}
uint32_t qc_sqlite_get_options()
{
return this_thread.options;
}
int32_t qc_sqlite_set_options(uint32_t options)
{
int32_t rv = QC_RESULT_OK;
if ((options & ~QC_OPTION_MASK) == 0)
{
this_thread.options = options;
}
else
{
rv = QC_RESULT_ERROR;
}
return rv;
}
QC_STMT_RESULT qc_sqlite_get_result_from_info(const QC_STMT_INFO* pInfo)
{
return static_cast<const QcSqliteInfo*>(pInfo)->get_result();
@ -5301,6 +5351,8 @@ extern "C"
qc_sqlite_set_sql_mode,
qc_sqlite_info_dup,
qc_sqlite_info_close,
qc_sqlite_get_options,
qc_sqlite_set_options,
qc_sqlite_get_result_from_info,
};