Example usage for android.database.sqlite SQLiteStatement simpleQueryForString

List of usage examples for android.database.sqlite SQLiteStatement simpleQueryForString

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteStatement simpleQueryForString.

Prototype

public String simpleQueryForString() 

Source Link

Document

Execute a statement that returns a 1 by 1 table with a text value.

Usage

From source file:android.database.DatabaseUtils.java

/**
 * Utility method to run the pre-compiled query and return the value in the
 * first column of the first row./*  w ww.j  a  va2 s.c o m*/
 */
public static String stringForQuery(SQLiteStatement prog, String[] selectionArgs) {
    if (selectionArgs != null) {
        int size = selectionArgs.length;
        for (int i = 0; i < size; i++) {
            bindObjectToProgram(prog, i + 1, selectionArgs[i]);
        }
    }
    String value = prog.simpleQueryForString();
    return value;
}

From source file:edu.stanford.mobisocial.dungbeetle.DBIdentityProvider.java

public List<RSAPublicKey> publicKeysForContactIds(List<Long> ids) {
    ArrayList<RSAPublicKey> result = new ArrayList<RSAPublicKey>(ids.size());
    SQLiteStatement s = mHelper.getReadableDatabase().compileStatement(
            "SELECT " + Contact.PUBLIC_KEY + " FROM " + Contact.TABLE + " WHERE " + Contact._ID + " = ?");
    for (Long id : ids) {
        s.bindLong(1, id.longValue());//from www.  j a  v  a 2  s.c o m
        try {
            String pks = s.simpleQueryForString();
            result.add(RSACrypto.publicKeyFromString(pks));
        } catch (SQLiteDoneException e) {
            Log.e(TAG, "Data consisteny error: unknown contact id " + id);
        }
    }
    s.close();
    return result;
}

From source file:com.android.messaging.datamodel.BugleDatabaseOperations.java

/**
 * Update conversation metadata if necessary
 * @param dbWrapper      db wrapper// www . ja v  a2s  .c o  m
 * @param conversationId conversation to modify
 * @param shouldAutoSwitchSelfId should we try to auto-switch the conversation's self-id as a
 *                               result of this call when we see a new latest message?
 * @param keepArchived if the conversation should be kept archived
 */
@DoesNotRunOnMainThread
public static void maybeRefreshConversationMetadataInTransaction(final DatabaseWrapper dbWrapper,
        final String conversationId, final boolean shouldAutoSwitchSelfId, boolean keepArchived) {
    Assert.isNotMainThread();
    String currentLatestMessageId = null;
    String latestMessageId = null;
    try {
        final SQLiteStatement currentLatestMessageIdSql = getQueryConversationsLatestMessageStatement(dbWrapper,
                conversationId);
        currentLatestMessageId = currentLatestMessageIdSql.simpleQueryForString();

        final SQLiteStatement latestMessageIdSql = getQueryMessagesLatestMessageStatement(dbWrapper,
                conversationId);
        latestMessageId = latestMessageIdSql.simpleQueryForString();
    } catch (final SQLiteDoneException e) {
        LogUtil.e(TAG, "BugleDatabaseOperations: Query for latest message failed", e);
    }

    if (TextUtils.isEmpty(currentLatestMessageId)
            || !TextUtils.equals(currentLatestMessageId, latestMessageId)) {
        refreshConversationMetadataInTransaction(dbWrapper, conversationId, shouldAutoSwitchSelfId,
                keepArchived);
    }
}

From source file:io.requery.android.database.sqlite.SQLiteDatabase.java

/**
 * Utility method to run the pre-compiled query and return the value in the
 * first column of the first row.//w  ww .  j  a va  2 s .  c o  m
 */
public static String stringForQuery(SQLiteStatement prog, String[] selectionArgs) {
    prog.bindAllArgsAsStrings(selectionArgs);
    return prog.simpleQueryForString();
}

From source file:io.requery.android.database.sqlite.SQLiteDatabase.java

/**
 * Runs 'pragma integrity_check' on the given database (and all the attached databases)
 * and returns true if the given database (and all its attached databases) pass integrity_check,
 * false otherwise.// w w w  .j  av a 2  s .com
 *<p>
 * If the result is false, then this method logs the errors reported by the integrity_check
 * command execution.
 *<p>
 * Note that 'pragma integrity_check' on a database can take a long time.
 *
 * @return true if the given database (and all its attached databases) pass integrity_check,
 * false otherwise.
 */
public boolean isDatabaseIntegrityOk() {
    acquireReference();
    try {
        List<Pair<String, String>> attachedDbs;
        try {
            attachedDbs = getAttachedDbs();
            if (attachedDbs == null) {
                throw new IllegalStateException("databaselist for: " + getPath() + " couldn't "
                        + "be retrieved. probably because the database is closed");
            }
        } catch (SQLiteException e) {
            // can't get attachedDb list. do integrity check on the main database
            attachedDbs = new ArrayList<>();
            attachedDbs.add(new Pair<>("main", getPath()));
        }

        for (Pair<String, String> p : attachedDbs) {
            SQLiteStatement prog = null;
            try {
                prog = compileStatement("PRAGMA " + p.first + ".integrity_check(1);");
                String rslt = prog.simpleQueryForString();
                if (!rslt.equalsIgnoreCase("ok")) {
                    // integrity_checker failed on main or attached databases
                    Log.e(TAG, "PRAGMA integrity_check on " + p.second + " returned: " + rslt);
                    return false;
                }
            } finally {
                if (prog != null)
                    prog.close();
            }
        }
    } finally {
        releaseReference();
    }
    return true;
}