use of com.raizlabs.android.dbflow.sql.QueryBuilder in project DBFlow by Raizlabs.
the class CaseCondition method getQuery.
@Override
public String getQuery() {
QueryBuilder queryBuilder = new QueryBuilder(" WHEN ");
if (caze.isEfficientCase()) {
queryBuilder.append(convertValueToString(property != null ? property : whenValue, false));
} else {
sqlCondition.appendConditionToQuery(queryBuilder);
}
queryBuilder.append(" THEN ").append(convertValueToString(isThenPropertySet ? thenProperty : thenValue, false));
return queryBuilder.getQuery();
}
use of com.raizlabs.android.dbflow.sql.QueryBuilder in project DBFlow by Raizlabs.
the class AlterTableMigration method getColumnDefinitions.
/**
* @return A List of column definitions that add column to a table in the DB.
*/
public List<String> getColumnDefinitions() {
String sql = new QueryBuilder(getAlterTableQueryBuilder()).append(FlowManager.getTableName(table)).toString();
List<String> columnDefinitions = new ArrayList<>();
if (this.columnDefinitions != null) {
for (QueryBuilder columnDefinition : this.columnDefinitions) {
QueryBuilder queryBuilder = new QueryBuilder(sql).appendSpaceSeparated("ADD COLUMN").append(columnDefinition.getQuery());
columnDefinitions.add(queryBuilder.getQuery());
}
}
return columnDefinitions;
}
use of com.raizlabs.android.dbflow.sql.QueryBuilder in project DBFlow by Raizlabs.
the class AlterTableMigration method migrate.
@Override
public final void migrate(DatabaseWrapper database) {
// "ALTER TABLE "
String sql = getAlterTableQueryBuilder().getQuery();
String tableName = FlowManager.getTableName(table);
// Since the structure has been updated already, the manager knows only the new name.
if (renameQuery != null) {
String renameQuery = new QueryBuilder(sql).appendQuotedIfNeeded(oldTableName).append(this.renameQuery.getQuery()).append(tableName).toString();
database.execSQL(renameQuery);
}
// ADD COLUMN columnName {type}
if (columnDefinitions != null) {
Cursor cursorToCheckColumnFor = SQLite.select().from(table).limit(0).query(database);
if (cursorToCheckColumnFor != null) {
try {
sql = new QueryBuilder(sql).append(tableName).toString();
for (int i = 0; i < columnDefinitions.size(); i++) {
QueryBuilder columnDefinition = columnDefinitions.get(i);
String columnName = QueryBuilder.stripQuotes(columnNames.get(i));
if (cursorToCheckColumnFor.getColumnIndex(columnName) == -1) {
database.execSQL(sql + " ADD COLUMN " + columnDefinition.getQuery());
}
}
} finally {
cursorToCheckColumnFor.close();
}
}
}
}
use of com.raizlabs.android.dbflow.sql.QueryBuilder in project DBFlow by Raizlabs.
the class AlterTableMigration method addColumn.
/**
* Add a column to the DB. This does not necessarily need to be reflected in the {@link TModel},
* but it is recommended.
*
* @param sqLiteType The type of column represented in the DB.
* @param columnName The name of the column to add. Use the "_Table" class for the specified table.
* @return This instance
*/
public AlterTableMigration<TModel> addColumn(@NonNull SQLiteType sqLiteType, @NonNull String columnName) {
if (columnDefinitions == null) {
columnDefinitions = new ArrayList<>();
columnNames = new ArrayList<>();
}
QueryBuilder queryBuilder = new QueryBuilder().append(QueryBuilder.quoteIfNeeded(columnName)).appendSpace().appendSQLiteType(sqLiteType);
columnDefinitions.add(queryBuilder);
columnNames.add(columnName);
return this;
}
use of com.raizlabs.android.dbflow.sql.QueryBuilder in project DBFlow by Raizlabs.
the class Trigger method getQuery.
@Override
public String getQuery() {
QueryBuilder queryBuilder = new QueryBuilder("CREATE ");
if (temporary) {
queryBuilder.append("TEMP ");
}
queryBuilder.append("TRIGGER IF NOT EXISTS ").appendQuotedIfNeeded(triggerName).appendSpace().appendOptional(" " + beforeOrAfter + " ");
return queryBuilder.getQuery();
}
Aggregations