Merge commit 'a78f0fbe2537542dc7f3f0dd8b19b93ac8d9d7f8' into develop
This commit is contained in:
@ -635,6 +635,7 @@ public:
|
||||
};
|
||||
|
||||
void update_field_info(const QcAliases* pAliases,
|
||||
uint32_t context,
|
||||
const char* zDatabase,
|
||||
const char* zTable,
|
||||
const char* zColumn,
|
||||
@ -680,6 +681,7 @@ public:
|
||||
item.table = zTable ? MXS_STRDUP(zTable) : NULL;
|
||||
mxb_assert(zColumn);
|
||||
item.column = MXS_STRDUP(zColumn);
|
||||
item.context = context;
|
||||
|
||||
// We are happy if we at least could dup the column.
|
||||
|
||||
@ -689,6 +691,10 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
i->context |= context;
|
||||
}
|
||||
}
|
||||
|
||||
void update_names(const char* zDatabase, const char* zTable, const char* zAlias, QcAliases* pAliases)
|
||||
@ -798,6 +804,7 @@ public:
|
||||
}
|
||||
|
||||
void update_field_infos(QcAliases* pAliases,
|
||||
uint32_t context,
|
||||
int prev_token,
|
||||
const Expr* pExpr,
|
||||
qc_token_position_t pos,
|
||||
@ -812,15 +819,15 @@ public:
|
||||
switch (pExpr->op)
|
||||
{
|
||||
case TK_ASTERISK: // select *
|
||||
update_field_infos_from_expr(pAliases, pExpr, pExclude);
|
||||
update_field_infos_from_expr(pAliases, context, pExpr, pExclude);
|
||||
break;
|
||||
|
||||
case TK_DOT: // select a.b ... select a.b.c
|
||||
update_field_infos_from_expr(pAliases, pExpr, pExclude);
|
||||
update_field_infos_from_expr(pAliases, context, pExpr, pExclude);
|
||||
break;
|
||||
|
||||
case TK_ID: // select a
|
||||
update_field_infos_from_expr(pAliases, pExpr, pExclude);
|
||||
update_field_infos_from_expr(pAliases, context, pExpr, pExclude);
|
||||
break;
|
||||
|
||||
case TK_VARIABLE:
|
||||
@ -1007,12 +1014,12 @@ public:
|
||||
|
||||
if (pLeft)
|
||||
{
|
||||
update_field_infos(pAliases, pExpr->op, pExpr->pLeft, QC_TOKEN_LEFT, pExclude);
|
||||
update_field_infos(pAliases, context, pExpr->op, pExpr->pLeft, QC_TOKEN_LEFT, pExclude);
|
||||
}
|
||||
|
||||
if (pRight)
|
||||
{
|
||||
update_field_infos(pAliases, pExpr->op, pExpr->pRight, QC_TOKEN_RIGHT, pExclude);
|
||||
update_field_infos(pAliases, context, pExpr->op, pExpr->pRight, QC_TOKEN_RIGHT, pExclude);
|
||||
}
|
||||
|
||||
if (pExpr->x.pList)
|
||||
@ -1022,7 +1029,7 @@ public:
|
||||
case TK_FUNCTION:
|
||||
if (!ignore_exprlist)
|
||||
{
|
||||
update_field_infos_from_exprlist(pAliases, pExpr->x.pList, pExclude);
|
||||
update_field_infos_from_exprlist(pAliases, context, pExpr->x.pList, pExclude);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1046,7 +1053,7 @@ public:
|
||||
if (pExpr->flags & EP_xIsSelect)
|
||||
{
|
||||
mxb_assert(pAliases);
|
||||
update_field_infos_from_subselect(*pAliases, pExpr->x.pSelect, pExclude);
|
||||
update_field_infos_from_subselect(*pAliases, context, pExpr->x.pSelect, pExclude);
|
||||
|
||||
|
||||
if (zName)
|
||||
@ -1059,7 +1066,7 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
update_field_infos_from_exprlist(pAliases, pExpr->x.pList, pExclude);
|
||||
update_field_infos_from_exprlist(pAliases, context, pExpr->x.pList, pExclude);
|
||||
|
||||
if (zName)
|
||||
{
|
||||
@ -1151,6 +1158,7 @@ public:
|
||||
}
|
||||
|
||||
void update_field_infos_from_expr(QcAliases* pAliases,
|
||||
uint32_t context,
|
||||
const Expr* pExpr,
|
||||
const ExprList* pExclude)
|
||||
{
|
||||
@ -1162,12 +1170,13 @@ public:
|
||||
{
|
||||
if (get_field_name(pExpr, &zDatabase, &zTable, &zColumn))
|
||||
{
|
||||
update_field_info(pAliases, zDatabase, zTable, zColumn, pExclude);
|
||||
update_field_info(pAliases, context, zDatabase, zTable, zColumn, pExclude);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void update_field_infos_from_exprlist(QcAliases* pAliases,
|
||||
uint32_t context,
|
||||
const ExprList* pEList,
|
||||
const ExprList* pExclude)
|
||||
{
|
||||
@ -1175,11 +1184,12 @@ public:
|
||||
{
|
||||
ExprList::ExprList_item* pItem = &pEList->a[i];
|
||||
|
||||
update_field_infos(pAliases, 0, pItem->pExpr, QC_TOKEN_MIDDLE, pExclude);
|
||||
update_field_infos(pAliases, context, 0, pItem->pExpr, QC_TOKEN_MIDDLE, pExclude);
|
||||
}
|
||||
}
|
||||
|
||||
void update_field_infos_from_idlist(QcAliases* pAliases,
|
||||
uint32_t context,
|
||||
const IdList* pIds,
|
||||
const ExprList* pExclude)
|
||||
{
|
||||
@ -1189,7 +1199,7 @@ public:
|
||||
{
|
||||
IdList::IdList_item* pItem = &pIds->a[i];
|
||||
|
||||
update_field_info(pAliases, NULL, NULL, pItem->zName, pExclude);
|
||||
update_field_info(pAliases, context, NULL, NULL, pItem->zName, pExclude);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1201,6 +1211,7 @@ public:
|
||||
};
|
||||
|
||||
void update_field_infos_from_select(QcAliases& aliases,
|
||||
uint32_t context,
|
||||
const Select* pSelect,
|
||||
const ExprList* pExclude,
|
||||
compound_approach_t compound_approach = ANALYZE_COMPOUND_SELECTS)
|
||||
@ -1218,7 +1229,7 @@ public:
|
||||
|
||||
if (pSrc->a[i].pSelect)
|
||||
{
|
||||
update_field_infos_from_select(aliases, pSrc->a[i].pSelect, pExclude);
|
||||
update_field_infos_from_select(aliases, context | QC_FIELD_SUBQUERY, pSrc->a[i].pSelect, pExclude);
|
||||
}
|
||||
|
||||
#ifdef QC_COLLECT_NAMES_FROM_USING
|
||||
@ -1236,13 +1247,14 @@ public:
|
||||
|
||||
if (pSelect->pEList)
|
||||
{
|
||||
update_field_infos_from_exprlist(&aliases, pSelect->pEList, NULL);
|
||||
update_field_infos_from_exprlist(&aliases, context, pSelect->pEList, NULL);
|
||||
}
|
||||
|
||||
if (pSelect->pWhere)
|
||||
{
|
||||
m_has_clause = true;
|
||||
update_field_infos(&aliases,
|
||||
context,
|
||||
0,
|
||||
pSelect->pWhere,
|
||||
QC_TOKEN_MIDDLE,
|
||||
@ -1252,6 +1264,7 @@ public:
|
||||
if (pSelect->pGroupBy)
|
||||
{
|
||||
update_field_infos_from_exprlist(&aliases,
|
||||
context,
|
||||
pSelect->pGroupBy,
|
||||
pSelect->pEList);
|
||||
}
|
||||
@ -1268,7 +1281,7 @@ public:
|
||||
|
||||
if (pSelect->pWith)
|
||||
{
|
||||
update_field_infos_from_with(&aliases, pSelect->pWith);
|
||||
update_field_infos_from_with(&aliases, context, pSelect->pWith);
|
||||
}
|
||||
|
||||
if (compound_approach == ANALYZE_COMPOUND_SELECTS)
|
||||
@ -1279,10 +1292,22 @@ public:
|
||||
|
||||
while (pPrior)
|
||||
{
|
||||
update_field_infos_from_subselect(aliases,
|
||||
pPrior,
|
||||
pExclude,
|
||||
IGNORE_COMPOUND_SELECTS);
|
||||
uint32_t ctx = context;
|
||||
|
||||
if (!pPrior->pPrior)
|
||||
{
|
||||
// The fields in the first select in a UNION are not considered to
|
||||
// be in a union. Those names will be visible in the resultset.
|
||||
ctx &= ~QC_FIELD_UNION;
|
||||
}
|
||||
|
||||
QcAliases aliases2(aliases);
|
||||
|
||||
update_field_infos_from_select(aliases2,
|
||||
ctx,
|
||||
pPrior,
|
||||
pExclude,
|
||||
IGNORE_COMPOUND_SELECTS);
|
||||
pPrior = pPrior->pPrior;
|
||||
}
|
||||
}
|
||||
@ -1290,16 +1315,19 @@ public:
|
||||
}
|
||||
|
||||
void update_field_infos_from_subselect(const QcAliases& existing_aliases,
|
||||
uint32_t context,
|
||||
const Select* pSelect,
|
||||
const ExprList* pExclude,
|
||||
compound_approach_t compound_approach = ANALYZE_COMPOUND_SELECTS)
|
||||
{
|
||||
QcAliases aliases(existing_aliases);
|
||||
|
||||
update_field_infos_from_select(aliases, pSelect, pExclude, compound_approach);
|
||||
context |= QC_FIELD_SUBQUERY;
|
||||
|
||||
update_field_infos_from_select(aliases, context, pSelect, pExclude, compound_approach);
|
||||
}
|
||||
|
||||
void update_field_infos_from_with(QcAliases* pAliases, const With* pWith)
|
||||
void update_field_infos_from_with(QcAliases* pAliases, uint32_t context, const With* pWith)
|
||||
{
|
||||
for (int i = 0; i < pWith->nCte; ++i)
|
||||
{
|
||||
@ -1308,7 +1336,7 @@ public:
|
||||
if (pCte->pSelect)
|
||||
{
|
||||
mxb_assert(pAliases);
|
||||
update_field_infos_from_subselect(*pAliases, pCte->pSelect, NULL);
|
||||
update_field_infos_from_subselect(*pAliases, context, pCte->pSelect, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1668,7 +1696,8 @@ public:
|
||||
|
||||
if (pSelect)
|
||||
{
|
||||
update_field_infos_from_select(aliases, pSelect, NULL);
|
||||
uint32_t context = 0;
|
||||
update_field_infos_from_select(aliases, context, pSelect, NULL);
|
||||
}
|
||||
|
||||
exposed_sqlite3ExprListDelete(pParse->db, pCNames);
|
||||
@ -1738,7 +1767,8 @@ public:
|
||||
|
||||
if (pWhere)
|
||||
{
|
||||
update_field_infos(&aliases, 0, pWhere, QC_TOKEN_MIDDLE, 0);
|
||||
uint32_t context = 0;
|
||||
update_field_infos(&aliases, context, 0, pWhere, QC_TOKEN_MIDDLE, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1793,7 +1823,8 @@ public:
|
||||
if (pSelect)
|
||||
{
|
||||
QcAliases aliases;
|
||||
update_field_infos_from_select(aliases, pSelect, NULL);
|
||||
uint32_t context = 0;
|
||||
update_field_infos_from_select(aliases, context, pSelect, NULL);
|
||||
}
|
||||
else if (pOldTable)
|
||||
{
|
||||
@ -1821,12 +1852,13 @@ public:
|
||||
mxb_assert(pTabList->nSrc >= 1);
|
||||
|
||||
QcAliases aliases;
|
||||
uint32_t context = 0;
|
||||
|
||||
update_names_from_srclist(&aliases, pTabList);
|
||||
|
||||
if (pColumns)
|
||||
{
|
||||
update_field_infos_from_idlist(&aliases, pColumns, NULL);
|
||||
update_field_infos_from_idlist(&aliases, context, pColumns, NULL);
|
||||
|
||||
int i = update_function_info(&aliases, "=", NULL);
|
||||
|
||||
@ -1851,12 +1883,12 @@ public:
|
||||
|
||||
if (pSelect)
|
||||
{
|
||||
update_field_infos_from_select(aliases, pSelect, NULL);
|
||||
update_field_infos_from_select(aliases, context, pSelect, NULL);
|
||||
}
|
||||
|
||||
if (pSet)
|
||||
{
|
||||
update_field_infos_from_exprlist(&aliases, pSet, NULL);
|
||||
update_field_infos_from_exprlist(&aliases, context, pSet, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1958,6 +1990,7 @@ public:
|
||||
if (m_operation != QUERY_OP_EXPLAIN)
|
||||
{
|
||||
QcAliases aliases;
|
||||
uint32_t context = 0;
|
||||
|
||||
m_type_mask = QUERY_TYPE_WRITE;
|
||||
m_operation = QUERY_OP_UPDATE;
|
||||
@ -1971,6 +2004,7 @@ public:
|
||||
ExprList::ExprList_item* pItem = &pChanges->a[i];
|
||||
|
||||
update_field_infos(&aliases,
|
||||
context,
|
||||
0,
|
||||
pItem->pExpr,
|
||||
QC_TOKEN_MIDDLE,
|
||||
@ -1980,7 +2014,7 @@ public:
|
||||
|
||||
if (pWhere)
|
||||
{
|
||||
update_field_infos(&aliases, 0, pWhere, QC_TOKEN_MIDDLE, pChanges);
|
||||
update_field_infos(&aliases, context, 0, pWhere, QC_TOKEN_MIDDLE, pChanges);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2039,7 +2073,8 @@ public:
|
||||
}
|
||||
|
||||
QcAliases aliases;
|
||||
update_field_infos_from_select(aliases, pSelect, NULL);
|
||||
uint32_t context = (pSelect->op == TK_UNION && pSelect->pPrior) ? QC_FIELD_UNION : 0;
|
||||
update_field_infos_from_select(aliases, context, pSelect, NULL);
|
||||
}
|
||||
|
||||
void maxscaleAlterTable(Parse* pParse, /* Parser context. */
|
||||
@ -2085,7 +2120,8 @@ public:
|
||||
if (pExprList)
|
||||
{
|
||||
QcAliases aliases;
|
||||
update_field_infos_from_exprlist(&aliases, pExprList, NULL);
|
||||
uint32_t context = 0;
|
||||
update_field_infos_from_exprlist(&aliases, context, pExprList, NULL);
|
||||
}
|
||||
|
||||
exposed_sqlite3SrcListDelete(pParse->db, pName);
|
||||
@ -2906,7 +2942,8 @@ public:
|
||||
if (pValue->op == TK_SELECT)
|
||||
{
|
||||
QcAliases aliases;
|
||||
update_field_infos_from_select(aliases, pValue->x.pSelect, NULL);
|
||||
uint32_t context = 0;
|
||||
update_field_infos_from_select(aliases, context, pValue->x.pSelect, NULL);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -2993,6 +3030,14 @@ public:
|
||||
|
||||
case MXS_SHOW_TABLES:
|
||||
m_type_mask = QUERY_TYPE_SHOW_TABLES;
|
||||
if (pShow->pDatabase->z)
|
||||
{
|
||||
char db[pShow->pDatabase->n + 1];
|
||||
strncpy(db, pShow->pDatabase->z, pShow->pDatabase->n);
|
||||
db[pShow->pDatabase->n] = 0;
|
||||
|
||||
update_database_names(db);
|
||||
}
|
||||
break;
|
||||
|
||||
case MXS_SHOW_VARIABLES:
|
||||
|
||||
Reference in New Issue
Block a user