@Test public void check() { String normal = "select * from tableA"; boolean check = false; try { checker.check(normal); } catch (SQLException e) { check = true; } assertFalse(check); String param = "select * from tableA where a= ? and b=?"; try { checker.check(param, "paramA", "paramB"); } catch (SQLException e) { check = true; } assertFalse(check); try { checker.check(param, "paramA", SwiftPreparedStatement.NullValue.INSTANCE); } catch (SQLException e) { check = true; } assertTrue(check); check = false; try { checker.check(param); } catch (SQLException e) { check = true; } assertTrue(check); }
@Override public SqlBean check(String sql, Object... paramValues) throws SQLException { Matcher matcher = SwiftPreparedStatement.VALUE_POS_PATTERN.matcher(sql); int paramCount = 0; while (matcher.find()) { paramCount++; } if (paramCount > 0) { sql = getRealSql(sql, Arrays.asList(paramValues), paramCount); } try { return new SqlBean(sql, SwiftSqlParseUtil.isSelect(sql)); } catch (Exception e) { throw Exceptions.sqlIncorrect(sql, e); } }
SwiftGrammarChecker implements GrammarChecker { @Override public SqlBean check(String sql, Object... paramValues) throws SQLException { Matcher matcher = SwiftPreparedStatement.VALUE_POS_PATTERN.matcher(sql); int paramCount = 0; while (matcher.find()) { paramCount++; } if (paramCount > 0) { sql = getRealSql(sql, Arrays.asList(paramValues), paramCount); } try { return new SqlBean(sql, SwiftSqlParseUtil.isSelect(sql)); } catch (Exception e) { throw Exceptions.sqlIncorrect(sql, e); } } }
SwiftGrammarChecker implements GrammarChecker { @Override public SqlBean check(String sql, Object... paramValues) throws SQLException { Matcher matcher = SwiftPreparedStatement.VALUE_POS_PATTERN.matcher(sql); int paramCount = 0; while (matcher.find()) { paramCount++; } if (paramCount > 0) { sql = getRealSql(sql, Arrays.asList(paramValues), paramCount); } try { return new SqlBean(sql, SwiftSqlParseUtil.isSelect(sql)); } catch (Exception e) { throw Exceptions.sqlIncorrect(sql, e); } }  }
SwiftGrammarChecker implements GrammarChecker { @Override public SqlBean check(String sql, Object... paramValues) throws SQLException { Matcher matcher = SwiftPreparedStatement.VALUE_POS_PATTERN.matcher(sql); int paramCount = 0; while (matcher.find()) { paramCount++; } if (paramCount > 0) { sql = getRealSql(sql, Arrays.asList(paramValues), paramCount); } try { return new SqlBean(sql, SwiftSqlParseUtil.isSelect(sql)); } catch (Exception e) { throw Exceptions.sqlIncorrect(sql, e); } }  @Override SqlBean check(String sql, Object... paramValues); }
SwiftGrammarChecker implements GrammarChecker { @Override public SqlBean check(String sql, Object... paramValues) throws SQLException { Matcher matcher = SwiftPreparedStatement.VALUE_POS_PATTERN.matcher(sql); int paramCount = 0; while (matcher.find()) { paramCount++; } if (paramCount > 0) { sql = getRealSql(sql, Arrays.asList(paramValues), paramCount); } try { return new SqlBean(sql, SwiftSqlParseUtil.isSelect(sql)); } catch (Exception e) { throw Exceptions.sqlIncorrect(sql, e); } }  @Override SqlBean check(String sql, Object... paramValues);  }