@Test public void bindSelectArgs() throws Exception { Object[] args = new Object[]{1, 10, 20, "test"}; String sql = "select * from person where id=? and (uid BETWEEN ? and ?) and test LIKE ? order by id"; String boundSql = KbSqlParser.bindArgs(sql, args); System.out.println(boundSql); Assert.assertEquals("SELECT * FROM person WHERE id = 1 AND (uid BETWEEN 10 AND 20) AND test LIKE 'test' ORDER BY id", boundSql); }
public static String bindArgs(String sql, @Nullable Object[] bindArgs) { if (bindArgs == null || bindArgs.length == 0 || sql.startsWith("PRAGMA")) { return sql; } try { KbSqlParserManager pm = new KbSqlParserManager(); Statement statement = pm.parse(sql); Set<Expression> expressionSet = findBindArgsExpressions(statement); Iterator<Object> iterator = Arrays.asList(bindArgs).iterator(); bindExpressionArgs(expressionSet, iterator); return statement.toString(); } catch (Exception e) { e.printStackTrace(); } return sql; }
KbSqlParser { public static String bindArgs(String sql, @Nullable Object[] bindArgs) { if (bindArgs == null || bindArgs.length == 0 || sql.startsWith("PRAGMA")) { return sql; } try { KbSqlParserManager pm = new KbSqlParserManager(); Statement statement = pm.parse(sql); Set<Expression> expressionSet = findBindArgsExpressions(statement); Iterator<Object> iterator = Arrays.asList(bindArgs).iterator(); bindExpressionArgs(expressionSet, iterator); return statement.toString(); } catch (Exception e) { e.printStackTrace(); } return sql; } }
KbSqlParser { public static String bindArgs(String sql, @Nullable Object[] bindArgs) { if (bindArgs == null || bindArgs.length == 0 || sql.startsWith("PRAGMA")) { return sql; } try { KbSqlParserManager pm = new KbSqlParserManager(); Statement statement = pm.parse(sql); Set<Expression> expressionSet = findBindArgsExpressions(statement); Iterator<Object> iterator = Arrays.asList(bindArgs).iterator(); bindExpressionArgs(expressionSet, iterator); return statement.toString(); } catch (Exception e) { e.printStackTrace(); } return sql; }  }
KbSqlParser { public static String bindArgs(String sql, @Nullable Object[] bindArgs) { if (bindArgs == null || bindArgs.length == 0 || sql.startsWith("PRAGMA")) { return sql; } try { KbSqlParserManager pm = new KbSqlParserManager(); Statement statement = pm.parse(sql); Set<Expression> expressionSet = findBindArgsExpressions(statement); Iterator<Object> iterator = Arrays.asList(bindArgs).iterator(); bindExpressionArgs(expressionSet, iterator); return statement.toString(); } catch (Exception e) { e.printStackTrace(); } return sql; }  static String bindArgs(String sql, @Nullable Object[] bindArgs); }
KbSqlParser { public static String bindArgs(String sql, @Nullable Object[] bindArgs) { if (bindArgs == null || bindArgs.length == 0 || sql.startsWith("PRAGMA")) { return sql; } try { KbSqlParserManager pm = new KbSqlParserManager(); Statement statement = pm.parse(sql); Set<Expression> expressionSet = findBindArgsExpressions(statement); Iterator<Object> iterator = Arrays.asList(bindArgs).iterator(); bindExpressionArgs(expressionSet, iterator); return statement.toString(); } catch (Exception e) { e.printStackTrace(); } return sql; }  static String bindArgs(String sql, @Nullable Object[] bindArgs);  }