Search in sources :

Example 6 with QueryBuilder

use of com.raizlabs.android.dbflow.sql.QueryBuilder in project DBFlow by Raizlabs.

the class TriggerMethod method getQuery.

@Override
public String getQuery() {
    QueryBuilder queryBuilder = new QueryBuilder(trigger.getQuery()).append(methodName);
    if (properties != null && properties.length > 0) {
        queryBuilder.appendSpaceSeparated("OF").appendArray((Object[]) properties);
    }
    queryBuilder.appendSpaceSeparated("ON").append(FlowManager.getTableName(onTable));
    if (forEachRow) {
        queryBuilder.appendSpaceSeparated("FOR EACH ROW");
    }
    if (whenCondition != null) {
        queryBuilder.append(" WHEN ");
        whenCondition.appendConditionToQuery(queryBuilder);
        queryBuilder.appendSpace();
    }
    queryBuilder.appendSpace();
    return queryBuilder.getQuery();
}
Also used : QueryBuilder(com.raizlabs.android.dbflow.sql.QueryBuilder)

Example 7 with QueryBuilder

use of com.raizlabs.android.dbflow.sql.QueryBuilder in project DBFlow by Raizlabs.

the class Join method getQuery.

@Override
public String getQuery() {
    QueryBuilder queryBuilder = new QueryBuilder();
    if (isNatural) {
        queryBuilder.append("NATURAL ");
    }
    queryBuilder.append(type.name().replace("_", " ")).appendSpace();
    queryBuilder.append("JOIN").appendSpace().append(alias.getFullQuery()).appendSpace();
    if (onGroup != null) {
        queryBuilder.append("ON").appendSpace().append(onGroup.getQuery()).appendSpace();
    } else if (!using.isEmpty()) {
        queryBuilder.append("USING (").appendArray(using).append(")").appendSpace();
    }
    return queryBuilder.getQuery();
}
Also used : QueryBuilder(com.raizlabs.android.dbflow.sql.QueryBuilder)

Example 8 with QueryBuilder

use of com.raizlabs.android.dbflow.sql.QueryBuilder in project DBFlow by Raizlabs.

the class Where method getQuery.

@Override
public String getQuery() {
    String fromQuery = whereBase.getQuery().trim();
    QueryBuilder queryBuilder = new QueryBuilder().append(fromQuery).appendSpace().appendQualifier("WHERE", conditionGroup.getQuery()).appendQualifier("GROUP BY", QueryBuilder.join(",", groupByList)).appendQualifier("HAVING", havingGroup.getQuery()).appendQualifier("ORDER BY", QueryBuilder.join(",", orderByList));
    if (limit > VALUE_UNSET) {
        queryBuilder.appendQualifier("LIMIT", String.valueOf(limit));
    }
    if (offset > VALUE_UNSET) {
        queryBuilder.appendQualifier("OFFSET", String.valueOf(offset));
    }
    return queryBuilder.getQuery();
}
Also used : QueryBuilder(com.raizlabs.android.dbflow.sql.QueryBuilder)

Example 9 with QueryBuilder

use of com.raizlabs.android.dbflow.sql.QueryBuilder in project DBFlow by Raizlabs.

the class Case method getQuery.

@Override
public String getQuery() {
    QueryBuilder queryBuilder = new QueryBuilder(" CASE");
    if (isEfficientCase()) {
        queryBuilder.append(" " + BaseCondition.convertValueToString(caseColumn, false));
    }
    queryBuilder.append(QueryBuilder.join(" ", caseConditions));
    if (elseSpecified) {
        queryBuilder.append(" ELSE ").append(BaseCondition.convertValueToString(elseValue, false));
    }
    if (endSpecified) {
        queryBuilder.append(" END " + (columnName != null ? columnName : ""));
    }
    return queryBuilder.getQuery();
}
Also used : QueryBuilder(com.raizlabs.android.dbflow.sql.QueryBuilder)

Example 10 with QueryBuilder

use of com.raizlabs.android.dbflow.sql.QueryBuilder in project DBFlow by Raizlabs.

the class BaseDatabaseHelper method executeCreations.

/**
     * This method executes CREATE TABLE statements as well as CREATE VIEW on the database passed.
     */
protected void executeCreations(final DatabaseWrapper database) {
    try {
        database.beginTransaction();
        List<ModelAdapter> modelAdapters = databaseDefinition.getModelAdapters();
        for (ModelAdapter modelAdapter : modelAdapters) {
            try {
                database.execSQL(modelAdapter.getCreationQuery());
            } catch (SQLiteException e) {
                FlowLog.logError(e);
            }
        }
        // create our model views
        List<ModelViewAdapter> modelViews = databaseDefinition.getModelViewAdapters();
        for (ModelViewAdapter modelView : modelViews) {
            QueryBuilder queryBuilder = new QueryBuilder().append("CREATE VIEW IF NOT EXISTS").appendSpaceSeparated(modelView.getViewName()).append("AS ").append(modelView.getCreationQuery());
            try {
                database.execSQL(queryBuilder.getQuery());
            } catch (SQLiteException e) {
                FlowLog.logError(e);
            }
        }
        database.setTransactionSuccessful();
    } finally {
        database.endTransaction();
    }
}
Also used : ModelAdapter(com.raizlabs.android.dbflow.structure.ModelAdapter) QueryBuilder(com.raizlabs.android.dbflow.sql.QueryBuilder) SQLiteException(android.database.sqlite.SQLiteException) ModelViewAdapter(com.raizlabs.android.dbflow.structure.ModelViewAdapter)

Aggregations

QueryBuilder (com.raizlabs.android.dbflow.sql.QueryBuilder)19 Cursor (android.database.Cursor)1 SQLiteException (android.database.sqlite.SQLiteException)1 TypeConverter (com.raizlabs.android.dbflow.converter.TypeConverter)1 ModelAdapter (com.raizlabs.android.dbflow.structure.ModelAdapter)1 ModelViewAdapter (com.raizlabs.android.dbflow.structure.ModelViewAdapter)1 ArrayList (java.util.ArrayList)1