qc: Implement qc_get_function_info for qc_mysqlembedded

MXS-1070

Now both qc_mysqlembedded and qc_sqlite return the same stuff
for the same statement, and both include also operators in
addition to pure functions. Whether that is the right approach,
is still subject to debate.

However, if we want to make it possible to disable e.g. the
use of concat as in "select concat(a) from t", where a is a string,
to prevent the bypassing of the masking filter, then conceptually
it should be possible to prevent "select a+0 from t", where a is an
int, as well.
This commit is contained in:
Johan Wikman
2017-01-04 18:29:40 +02:00
parent 0d561df880
commit 482fbe6400
8 changed files with 368 additions and 31 deletions

View File

@ -66,6 +66,15 @@ enum
QUERY_TYPE_WRITE = 0x000004, /*< Master data will be modified:master */
};
typedef enum qc_field_usage
{
QC_USED_IN_SELECT = 0x01, /*< SELECT fld FROM... */
QC_USED_IN_SUBSELECT = 0x02, /*< SELECT 1 FROM ... SELECT fld ... */
QC_USED_IN_WHERE = 0x04, /*< SELECT ... FROM ... WHERE fld = ... */
QC_USED_IN_SET = 0x08, /*< UPDATE ... SET fld = ... */
QC_USED_IN_GROUP_BY = 0x10, /*< ... GROUP BY fld */
} qc_field_usage_t;
// MaxScale naming convention:
//
// - A function that "overloads" a sqlite3 function has the same name
@ -116,6 +125,8 @@ extern void maxscaleShow(Parse*, MxsShow* pShow);
extern void maxscaleTruncate(Parse*, Token* pDatabase, Token* pName);
extern void maxscaleUse(Parse*, Token*);
extern void maxscale_update_function_info(const char* name, unsigned usage);
// Exposed utility functions
void exposed_sqlite3ExprDelete(sqlite3 *db, Expr *pExpr)
{
@ -1141,6 +1152,8 @@ selcollist(A) ::= sclp(P) DEFAULT LP nm RP as. {
A = P;
}
selcollist(A) ::= sclp(P) MATCH LP id(X) RP AGAINST LP expr(Y) RP. {
// Could be a subselect as well, but we just don't know it at this point.
maxscale_update_function_info("match", QC_USED_IN_SELECT);
sqlite3ExprDelete(pParse->db, Y.pExpr);
Expr *p = sqlite3PExpr(pParse, TK_ID, 0, 0, &X);
A = sqlite3ExprListAppend(pParse, P, p);