SqlBuilder(CompileContext compileContext, boolean withBoundArguments) { this.compileContext = compileContext; this.sqliteVersion = compileContext.getVersionCode(); this.args = withBoundArguments ? new ArrayList<>() : null; }
public CompileContext build() { return new CompileContext(this); }
/** * Deprecated, use {@link #sqlForValidation(CompileContext)} instead */ @Deprecated public final String sqlForValidation(VersionCode sqliteVersion) { return sqlForValidation(CompileContext.defaultContextForVersionCode(sqliteVersion)); }
private Object[] applyArgumentResolver(Object[] args) { ArgumentResolver resolver = compileContext.getArgumentResolver(); Object[] result = new Object[args.length]; for (int i = 0; i < args.length; i++) { result[i] = resolver.resolveArgument(args[i]); } return result; }
void addCollectionArg(Collection<?> value) { if (value != null) { if (args == null) { SqlUtils.addInlineCollectionToSqlString(sql, compileContext.getArgumentResolver(), value); } else { sql.append(SqlStatement.REPLACEABLE_ARRAY_PARAMETER); args.add(value); } } }
/** * @return the expression for the function as it would be compiled for the given SQLite version and default * CompileContext. Deprecated in favor of {@link #getExpression(CompileContext)} * @see #getExpression(CompileContext) */ @Deprecated public String getExpression(VersionCode forSqliteVersion) { return getExpression(CompileContext.defaultContextForVersionCode(forSqliteVersion)); }
private void visitValues(SqlBuilder builder, boolean forSqlValidation) { if (builder.compileContext.getVersionCode().isLessThan(SQLITE_VERSION_MULTI_ROW_INSERT) && valuesToInsert.size() > 1) { throw new UnsupportedOperationException("Can't insert with multiple sets of values below " + "SQLite version 3.7.11"); } builder.sql.append("VALUES "); for (List<Object> valuesList : valuesToInsert) { if (valuesList.isEmpty()) { continue; } builder.sql.append("("); for (Object value : valuesList) { builder.addValueToSql(value, forSqlValidation); builder.sql.append(","); } builder.sql.deleteCharAt(builder.sql.length() - 1); builder.sql.append("),"); } builder.sql.deleteCharAt(builder.sql.length() - 1); } }
Collection<?> values = collectionArgs.get(index); if (largeArgMode) { SqlUtils.addInlineCollectionToSqlString(result, compileContext.getArgumentResolver(), values); } else { appendCollectionVariableStringForSize(result, values.size());
public CompileContext build() { return new CompileContext(this); }
@Override public String toString() { return toRawSql(CompileContext.defaultContextForVersionCode(VERSION_FOR_TO_STRING)); }
@Override protected void appendFunctionExpression(SqlBuilder builder, boolean forSqlValidation) { if (!builder.compileContext.getVersionCode().isAtLeast(minVersion)) { throw new UnsupportedOperationException("The function " + functionName + " is not supported on SQLite " + "version " + builder.compileContext.getVersionCode() + " - requires version " + minVersion + " or higher"); } builder.sql.append(functionName).append("("); boolean needsSeparator = false; if (jsonArg != null) { builder.addValueToSql(jsonArg, forSqlValidation); needsSeparator = true; } if (additionalArgs != null && additionalArgs.length > 0) { for (Object additionalArg : additionalArgs) { if (needsSeparator) { builder.sql.append(", "); } builder.addValueToSql(additionalArg, forSqlValidation); needsSeparator = true; } } builder.sql.append(")"); } }
addCollectionArg((Collection<?>) value); } else if (args == null) { sql.append(SqlUtils.toSanitizedString(value, compileContext.getArgumentResolver())); } else { if (value != null) {
@Override @Deprecated public CompiledStatement compile(VersionCode sqliteVersion) { return compile(CompileContext.defaultContextForVersionCode(sqliteVersion)); }
/** * Append a CREATE VIRTUAL TABLE statement that would create this table and its columns. Users should not * call this method and instead let {@link com.yahoo.squidb.data.SquidDatabase} build tables automatically. */ @Override public void appendCreateTableSql(CompileContext compileContext, StringBuilder sql, PropertyVisitor<Void, StringBuilder> propertyVisitor) { sql.append("CREATE VIRTUAL TABLE "); if (compileContext != null && compileContext.getVersionCode().isAtLeast(SQLITE_VERSION_IF_NOT_EXISTS)) { sql.append("IF NOT EXISTS "); } sql.append(getExpression()).append(" USING ").append(moduleName).append('('); boolean needComma = false; for (Property<?> property : properties) { if (TableModel.ROWID.equals(property.getExpression())) { continue; } if (needComma) { sql.append(','); } sql.append(property.getName()); needComma = true; } sql.append(')'); } }
private Object[] applyArgumentResolver(Object[] args) { ArgumentResolver resolver = compileContext.getArgumentResolver(); Object[] result = new Object[args.length]; for (int i = 0; i < args.length; i++) { result[i] = resolver.resolveArgument(args[i]); } return result; }
@Deprecated protected final SqlBuilder buildSql(VersionCode sqliteVersion, boolean withBoundArguments, boolean forSqlValidation) { return buildSql(CompileContext.defaultContextForVersionCode(sqliteVersion), withBoundArguments, forSqlValidation); }
SqlBuilder(CompileContext compileContext, boolean withBoundArguments) { this.compileContext = compileContext; this.sqliteVersion = compileContext.getVersionCode(); this.args = withBoundArguments ? new ArrayList<>() : null; }
void addCollectionArg(Collection<?> value) { if (value != null) { if (args == null) { SqlUtils.addInlineCollectionToSqlString(sql, compileContext.getArgumentResolver(), value); } else { sql.append(SqlStatement.REPLACEABLE_ARRAY_PARAMETER); args.add(value); } } }
/** * Deprecated, use {@link #compile(CompileContext)} instead */ @Override @Deprecated public final synchronized CompiledStatement compile(VersionCode sqliteVersion) { return compile(CompileContext.defaultContextForVersionCode(sqliteVersion)); }
private void visitValues(SqlBuilder builder, boolean forSqlValidation) { if (builder.compileContext.getVersionCode().isLessThan(SQLITE_VERSION_MULTI_ROW_INSERT) && valuesToInsert.size() > 1) { throw new UnsupportedOperationException("Can't insert with multiple sets of values below " + "SQLite version 3.7.11"); } builder.sql.append("VALUES "); for (List<Object> valuesList : valuesToInsert) { if (valuesList.isEmpty()) { continue; } builder.sql.append("("); for (Object value : valuesList) { builder.addValueToSql(value, forSqlValidation); builder.sql.append(","); } builder.sql.deleteCharAt(builder.sql.length() - 1); builder.sql.append("),"); } builder.sql.deleteCharAt(builder.sql.length() - 1); } }