Package com.databricks.jdbc.common.util
Class SQLInterpolator
- java.lang.Object
-
- com.databricks.jdbc.common.util.SQLInterpolator
-
public class SQLInterpolator extends Object
-
-
Constructor Summary
Constructors Constructor Description SQLInterpolator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static StringescapeInputs(String input)static StringinterpolateSQL(String sql, Map<Integer,ImmutableSqlParameter> params)Interpolates the given SQL string by replacing placeholders with the provided parameters.static StringsurroundPlaceholdersWithQuotes(String sql)Surrounds real placeholders (?)
-
-
-
Method Detail
-
interpolateSQL
public static String interpolateSQL(String sql, Map<Integer,ImmutableSqlParameter> params) throws DatabricksValidationException
Interpolates the given SQL string by replacing placeholders with the provided parameters.Only '?' characters that appear outside of comments, string literals, and quoted identifiers are treated as placeholders. The map keys are 1-based indexes, aligning with the SQL parameter positions.
- Parameters:
sql- the SQL string containing placeholders ('?') to be replaced.params- a map of parameters where the key is the 1-based index of the placeholder in the SQL string, and the value is the correspondingImmutableSqlParameter.- Returns:
- the interpolated SQL string with placeholders replaced by the corresponding parameters.
- Throws:
DatabricksValidationException- if the number of placeholders in the SQL string does not match the number of parameters provided in the map.
-
surroundPlaceholdersWithQuotes
public static String surroundPlaceholdersWithQuotes(String sql)
Surrounds real placeholders (?) with single quotes, leaving '?' characters that appear inside comments, string literals, or quoted identifiers untouched. This is crucial for DESCRIBE QUERY commands, where bare placeholders cause a parse_syntax_error.
-
-