SqlBuilder(CompileContext compileContext, boolean withBoundArguments) { this.compileContext = compileContext; this.sqliteVersion = compileContext.getVersionCode(); this.args = withBoundArguments ? new ArrayList<>() : null; }
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); } }
@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(")"); } }
/** * 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(')'); } }
SqlBuilder(CompileContext compileContext, boolean withBoundArguments) { this.compileContext = compileContext; this.sqliteVersion = compileContext.getVersionCode(); this.args = withBoundArguments ? new ArrayList<>() : null; }
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); } }
/** * 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(')'); } }