FileDocCategorySizeDatePackage
SelectionBuilder.javaAPI DocAndroid 5.1 API4065Thu Mar 12 22:22:10 GMT 2015com.android.internal.content

SelectionBuilder

public class SelectionBuilder extends Object
Helper for building selection clauses for {@link SQLiteDatabase}. Each appended clause is combined using {@code AND}. This class is not thread safe.
hide

Fields Summary
private StringBuilder
mSelection
private ArrayList
mSelectionArgs
Constructors Summary
Methods Summary
public com.android.internal.content.SelectionBuilderappend(java.lang.String selection, java.lang.Object selectionArgs)
Append the given selection clause to the internal state. Each clause is surrounded with parenthesis and combined using {@code AND}.

        if (TextUtils.isEmpty(selection)) {
            if (selectionArgs != null && selectionArgs.length > 0) {
                throw new IllegalArgumentException(
                        "Valid selection required when including arguments");
            }

            // Shortcut when clause is empty
            return this;
        }

        if (mSelection.length() > 0) {
            mSelection.append(" AND ");
        }

        mSelection.append("(").append(selection).append(")");
        if (selectionArgs != null) {
            for (Object arg : selectionArgs) {
                // TODO: switch to storing direct Object instances once
                // http://b/2464440 is fixed
                mSelectionArgs.add(String.valueOf(arg));
            }
        }

        return this;
    
public intdelete(android.database.sqlite.SQLiteDatabase db, java.lang.String table)
Execute delete using the current internal state as {@code WHERE} clause.

        return db.delete(table, getSelection(), getSelectionArgs());
    
public java.lang.StringgetSelection()
Return selection string for current internal state.

see
#getSelectionArgs()

        return mSelection.toString();
    
public java.lang.String[]getSelectionArgs()
Return selection arguments for current internal state.

see
#getSelection()

        return mSelectionArgs.toArray(new String[mSelectionArgs.size()]);
    
public android.database.Cursorquery(android.database.sqlite.SQLiteDatabase db, java.lang.String table, java.lang.String[] columns, java.lang.String orderBy)
Execute query using the current internal state as {@code WHERE} clause. Missing arguments as treated as {@code null}.

        return query(db, table, columns, null, null, orderBy, null);
    
public android.database.Cursorquery(android.database.sqlite.SQLiteDatabase db, java.lang.String table, java.lang.String[] columns, java.lang.String groupBy, java.lang.String having, java.lang.String orderBy, java.lang.String limit)
Execute query using the current internal state as {@code WHERE} clause.

        return db.query(table, columns, getSelection(), getSelectionArgs(), groupBy, having,
                orderBy, limit);
    
public com.android.internal.content.SelectionBuilderreset()
Reset any internal state, allowing this builder to be recycled.


                   
       
        mSelection.setLength(0);
        mSelectionArgs.clear();
        return this;
    
public intupdate(android.database.sqlite.SQLiteDatabase db, java.lang.String table, android.content.ContentValues values)
Execute update using the current internal state as {@code WHERE} clause.

        return db.update(table, values, getSelection(), getSelectionArgs());