@Test public void bindInsertArgs() { Object[] args = new Object[]{1, "kk"}; String sql = "INSERT INTO person (id, name) VALUES (?, ?)"; String boundSql = KbSqlParser.bindArgs(sql, args); Assert.assertEquals("INSERT INTO person (id, name) VALUES (1, 'kk')", 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);  }