MysqlParser parser = new MysqlParser(new StringReader(parseSql));
// 设置函数列表。
parser.setFunctionMap(functionMap);
Statement stmt = null;
try {
stmt = parser.doParse();
} catch (ParseException e) {
parsingFailed = true;
// 语句解析失败,写出日志。
if (logger.isDebugEnabled()) {
logger.debug("Parsing SQL failed: " + sql, e);
} else if (logger.isWarnEnabled()) {
logger.warn("Parsing SQL failed: " + sql);
}
}
dml = (stmt instanceof DMLStatement);
if (dml) {
// 解析 SELECT / INSERT / UPDATE / DELETE 语句
select = (stmt instanceof SelectStatement);
insert = (stmt instanceof InsertStatement);
update = (stmt instanceof UpdateStatement);
delete = (stmt instanceof DeleteStatement);
DMLStatement dmlStmt = (DMLStatement) stmt;
tables = dmlStmt.getTables();
// 处理生成的表达式
parseExpr(dmlStmt.getExpression(), null);
// 记录参数数目,注意: UPDATE 语句的实际参数数目要大于表达式中提取的参数数目。因此,真实地参数索引应该是:
// index = paramIndex + indexParams.size() - paramCount - 1
paramOffset = indexParams.size() - stmt.getParameterCount() - 1;
paramCount += stmt.getParameterCount();
}
}