Java 类android.database.DatabaseUtils 实例源码

项目:AndroidSdrRtlTuner    文件:FileUtils.java   
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context The context.
 * @param uri The Uri to query.
 * @param selection (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 * @author paulburke
 */
public static String getDataColumn(Context context, Uri uri, String selection,
                                   String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {
            if (DEBUG)
                DatabaseUtils.dumpCursor(cursor);

            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
项目:file.io-app    文件:FileUtils.java   
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context       The context.
 * @param uri           The Uri to query.
 * @param selection     (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 * @author paulburke
 */
public static String getDataColumn(Context context, Uri uri, String selection,
                                   String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {
            if (DEBUG)
                DatabaseUtils.dumpCursor(cursor);

            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
项目:editor-sql    文件:SqlCommondActivity.java   
private void runSql(String sql) {

        hideSoftwareInput(this, clearEditText);
        response_content_layout.setVisibility(View.VISIBLE);

        //查询语句跳转界面,其他直接显示结果
        int sqlType = DatabaseUtils.getSqlStatementType(sql);

        if (sqlType == DatabaseUtils.STATEMENT_SELECT) {

            startTableDataActivity(sql);

        } else {

            try {
                int result = SQLManager.getSQLHelper(SqlCommondActivity.this).execSQLStr(sql);
                response_content.setText(result + "");
            } catch (Exception e) {
                e.printStackTrace();
                response_content.setText(e.getMessage());
            }
        }
    }
项目:Hexis    文件:GoalReader.java   
/**
 * Used to check if a goal with matching title exists.
 *
 * @param goalTitle the desired title to search for
 * @return true if a goal with matching title is found in table
 */
public boolean doesGoalExist(String goalTitle) {
  // Sanitize goalTitle string before sql query
  goalTitle = DatabaseUtils.sqlEscapeString(goalTitle);

  // Query database for existence of a matching goal title
  Cursor cursor = db.rawQuery(queryGoalTitle + goalTitle + "\"", null);

  // return true if at least one instance of the goal title exists
  if (cursor.getCount() > 0) {
    // Close cursor
    cursor.close();

    // Return true because goal title exists
    return true;
  }

  // Close the cursor
  cursor.close();

  // Return false because goal does not exist
  return false;
}
项目:Hexis    文件:GoalWriter.java   
/**
 * Use of this method is discouraged as it will only update the first existence of any goal that
 * matches the requested goal title.
 * Used to update an existing goal's title in goal table
 *
 * @param goalTitle    original goal title
 * @param newGoalTitle new goal title
 * @return primary key of updated goal, returns -1 if goal does not exist
 */
public long updateGoal(String goalTitle, String newGoalTitle) {
  GoalReader goalReader = new GoalReader(sqlLiteHelper);

  // Use ContentValues to sanitize user defined goalTitle string
  values = new ContentValues();

  // Add new goal title to goal_title field in goal table
  values.put(GoalsEntry.COLUMN_NAME_GOAL_TITLE, newGoalTitle);

  // Check if goal with original title exists in goal table
  // Update goal title in goal table where goal title matches requested title
  if (goalReader.doesGoalExist(goalTitle)) {
    return db.update(GoalsEntry.TABLE_NAME, values, GoalsEntry.COLUMN_NAME_GOAL_TITLE
        + "=\""
        + DatabaseUtils.sqlEscapeString(goalTitle)
        + "\"", null);
  }

  // Return -1 if no goal exists in goal table matching original goal title
  return -1;
}
项目:xlight_android_native    文件:FileUtils.java   
public static String getDataColumn(Context context, Uri uri, String selection,
                                       String[] selectionArgs) {

        Cursor cursor = null;
        final String column = "_data";
        final String[] projection = {
                column
        };

        try {
            cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                    null);
            if (cursor != null && cursor.moveToFirst()) {
//              if (DEBUG)
                    DatabaseUtils.dumpCursor(cursor);

                final int column_index = cursor.getColumnIndexOrThrow(column);
                return cursor.getString(column_index);
            }
        } finally {
            if (cursor != null)
                cursor.close();
        }
        return null;
    }
项目:boohee_v5.6    文件:ay.java   
private void ce() {
    SQLiteDatabase openOrCreateDatabase;
    try {
        openOrCreateDatabase = SQLiteDatabase.openOrCreateDatabase(this.iB, null);
    } catch (Exception e) {
        openOrCreateDatabase = null;
    }
    if (openOrCreateDatabase != null) {
        long queryNumEntries = DatabaseUtils.queryNumEntries(openOrCreateDatabase, "wof");
        long queryNumEntries2 = DatabaseUtils.queryNumEntries(openOrCreateDatabase, "bdcltb09");
        boolean z = queryNumEntries > 10000;
        boolean z2 = queryNumEntries2 > 10000;
        if (z || z2) {
            new a().execute(new Boolean[]{Boolean.valueOf(z), Boolean.valueOf(z2)});
        }
        openOrCreateDatabase.close();
    }
}
项目:magic_imageloader_network    文件:FileUtils.java   
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context       The context.
 * @param uri           The Uri to query.
 * @param selection     (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 * @author paulburke
 */
public static String getDataColumn(Context context, Uri uri, String selection,
                                   String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {
            if (DEBUG)
                DatabaseUtils.dumpCursor(cursor);

            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
项目:magic_imageloader_network    文件:FileUtils.java   
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context       The context.
 * @param uri           The Uri to query.
 * @param selection     (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 * @author paulburke
 */
public static String getDataColumn(Context context, Uri uri, String selection,
                                   String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {
            if (DEBUG)
                DatabaseUtils.dumpCursor(cursor);

            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
项目:RoadLab-Pro    文件:PathUtils.java   
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context The context.
 * @param uri The Uri to query.
 * @param selection (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 * @author paulburke
 */
public static String getDataColumn(Context context, Uri uri, String selection,
                                   String[] selectionArgs) {
    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };
    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {
            if (DEBUG)
                DatabaseUtils.dumpCursor(cursor);
            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
项目:Android_RuuvitagScannner    文件:ScannerService.java   
public void update(Ruuvitag ruuvitag) {
    String time = new SimpleDateFormat("dd-MM-yyyy, hh:mm:ss").format(new Date());

    if(Exists(ruuvitag.getId())) {
        ContentValues values = new ContentValues();
        values.put(DBContract.RuuvitagDB.COLUMN_ID, ruuvitag.getId());
        values.put(DBContract.RuuvitagDB.COLUMN_URL, ruuvitag.getUrl());
        values.put(DBContract.RuuvitagDB.COLUMN_RSSI, ruuvitag.getRssi());
        values.put(DBContract.RuuvitagDB.COLUMN_TEMP, ruuvitag.getTemperature());
        values.put(DBContract.RuuvitagDB.COLUMN_HUMI, ruuvitag.getHumidity());
        values.put(DBContract.RuuvitagDB.COLUMN_PRES, ruuvitag.getPressure());
        values.put(DBContract.RuuvitagDB.COLUMN_LAST, time);

        db.update(DBContract.RuuvitagDB.TABLE_NAME, values, "id="+ DatabaseUtils.sqlEscapeString(ruuvitag.getId()), null);
    }
}
项目:TenguChat    文件:DatabaseBackend.java   
public long numTrustedKeys(Account account, String name) {
    SQLiteDatabase db = getReadableDatabase();
    String[] args = {
            account.getUuid(),
            name,
            FingerprintStatus.Trust.TRUSTED.toString(),
            FingerprintStatus.Trust.VERIFIED.toString(),
            FingerprintStatus.Trust.VERIFIED_X509.toString()
    };
    return DatabaseUtils.queryNumEntries(db, SQLiteAxolotlStore.IDENTITIES_TABLENAME,
            SQLiteAxolotlStore.ACCOUNT + " = ?"
                    + " AND " + SQLiteAxolotlStore.NAME + " = ?"
                    + " AND (" + SQLiteAxolotlStore.TRUST + " = ? OR " + SQLiteAxolotlStore.TRUST + " = ? OR " +SQLiteAxolotlStore.TRUST +" = ?)"
                    + " AND " +SQLiteAxolotlStore.ACTIVE + " > 0",
            args
    );
}
项目:Applozic-Android-Chat-Sample    文件:FileUtils.java   
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context       The context.
 * @param uri           The Uri to query.
 * @param selection     (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 * @author paulburke
 */
public static String getDataColumn(Context context, Uri uri, String selection,
                                   String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {
            if (DEBUG)
                DatabaseUtils.dumpCursor(cursor);

            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
项目:Applozic-Android-Chat-Sample    文件:FileUtils.java   
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context       The context.
 * @param uri           The Uri to query.
 * @param selection     (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 * @author paulburke
 */
public static String getDataColumn(Context context, Uri uri, String selection,
                                   String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {
            if (DEBUG)
                DatabaseUtils.dumpCursor(cursor);

            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
项目:murmur    文件:MessageStore.java   
/** return the amount of items in the database.
 *
 * @param countDeleted if set to true count will include items marked as deleted
 * @return number of items in the database.
 */
public long getMessageCount(boolean countDeleted, boolean countReplies){
    SQLiteDatabase db = getWritableDatabase();
    if (db != null){
        String query = "";
        if(!countDeleted) {
            query += COL_DELETED + "=" + FALSE;
            if(!countReplies)
                query += " AND ";
        }
        if(!countReplies)
        {
            query += "(" + COL_BIGPARENT + " IS NULL OR " + COL_BIGPARENT + " NOT IN (SELECT " + COL_MESSAGE_ID + " FROM " + TABLE + " WHERE " + COL_DELETED + "=" + FALSE + ") AND " + COL_PARENT + " NOT IN (SELECT " + COL_MESSAGE_ID + " FROM " + TABLE + " WHERE " + COL_DELETED + "=" + FALSE + "))";
        }
        return DatabaseUtils.queryNumEntries(db, TABLE, query);
    }
    return 0;
}
项目:core-doppl    文件:SQLiteDatabase.java   
private int executeSql(String sql, Object[] bindArgs) throws SQLException {
    acquireReference();
    try {
        if (DatabaseUtils.getSqlStatementType(sql) == DatabaseUtils.STATEMENT_ATTACH) {
            boolean disableWal = false;
            synchronized (mLock) {
                if (!mHasAttachedDbsLocked) {
                    mHasAttachedDbsLocked = true;
                    disableWal = true;
                }
            }
            if (disableWal) {
                disableWriteAheadLogging();
            }
        }

        SQLiteStatement statement = new SQLiteStatement(this, sql, bindArgs);
        try {
            return statement.executeUpdateDelete();
        } finally {
            statement.close();
        }
    } finally {
        releaseReference();
    }
}
项目:core-doppl    文件:SQLiteSession.java   
/**
 * Performs special reinterpretation of certain SQL statements such as "BEGIN",
 * "COMMIT" and "ROLLBACK" to ensure that transaction state invariants are
 * maintained.
 *
 * This function is mainly used to support legacy apps that perform their
 * own transactions by executing raw SQL rather than calling {@link #beginTransaction}
 * and the like.
 *
 * @param sql The SQL statement to execute.
 * @param bindArgs The arguments to bind, or null if none.
 * @param connectionFlags The connection flags to use if a connection must be
 * acquired by this operation.  Refer to {@link SQLiteConnectionPool}.
 * @param cancellationSignal A signal to cancel the operation in progress, or null if none.
 * @return True if the statement was of a special form that was handled here,
 * false otherwise.
 *
 * @throws SQLiteException if an error occurs, such as a syntax error
 * or invalid number of bind arguments.
 * @throws OperationCanceledException if the operation was canceled.
 */
private boolean executeSpecial(String sql, Object[] bindArgs, int connectionFlags,
        CancellationSignal cancellationSignal) {
    if (cancellationSignal != null) {
        cancellationSignal.throwIfCanceled();
    }

    final int type = DatabaseUtils.getSqlStatementType(sql);
    switch (type) {
        case DatabaseUtils.STATEMENT_BEGIN:
            beginTransaction(TRANSACTION_MODE_EXCLUSIVE, null, connectionFlags,
                    cancellationSignal);
            return true;

        case DatabaseUtils.STATEMENT_COMMIT:
            setTransactionSuccessful();
            endTransaction(cancellationSignal);
            return true;

        case DatabaseUtils.STATEMENT_ABORT:
            endTransaction(cancellationSignal);
            return true;
    }
    return false;
}
项目:SiliCompressor    文件:FileUtils.java   
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context The context.
 * @param uri The Uri to query.
 * @param selection (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 * @author paulburke
 */
public static String getDataColumn(Context context, Uri uri, String selection,
                                   String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {
            if (DEBUG)
                DatabaseUtils.dumpCursor(cursor);

            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
项目:twicalico    文件:TokenSQLiteOpenHelper.java   
public long addAccessToken(AccessToken accessToken){
    SQLiteDatabase database=getWritableDatabase();

    ContentValues contentValues = new ContentValues();
    contentValues.put("type", accessToken.getType());
    contentValues.put("url", accessToken.getUrl());
    contentValues.put("userName", accessToken.getScreenName());
    contentValues.put("userId", String.valueOf(accessToken.getUserId()));
    contentValues.put("token", accessToken.getToken());
    contentValues.put("tokenSecret", accessToken.getTokenSecret());

    database.replace("AccountTokenList", null, contentValues);

    long count = DatabaseUtils.queryNumEntries(database,"AccountTokenList");
    database.close();
    return count;
}
项目:H-Viewer    文件:FileUtils.java   
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context       The context.
 * @param uri           The Uri to query.
 * @param selection     (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 * @author paulburke
 */
public static String getDataColumn(Context context, Uri uri, String selection,
                                   String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {
            if (DEBUG)
                DatabaseUtils.dumpCursor(cursor);

            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
项目:ChatApp-Android    文件:FileUtils.java   
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context       The context.
 * @param uri           The Uri to query.
 * @param selection     (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 * @author paulburke
 */
public static String getDataColumn(Context context, Uri uri, String selection,
                                   String[] selectionArgs){

  Cursor cursor = null;
  final String column = "_data";
  final String[] projection = {
          column
  };

  try{
    cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
            null);
    if (cursor != null && cursor.moveToFirst()){
      if (DEBUG)
        DatabaseUtils.dumpCursor(cursor);

      final int column_index = cursor.getColumnIndexOrThrow(column);
      return cursor.getString(column_index);
    }
  }finally{
    if (cursor != null)
      cursor.close();
  }
  return null;
}
项目:qiscus-sdk-android    文件:QiscusDataBaseHelper.java   
@Override
public QiscusChatRoom getChatRoom(String email, String distinctId) {
    String query = "SELECT * FROM "
            + QiscusDb.RoomMemberTable.TABLE_NAME + " WHERE "
            + QiscusDb.RoomMemberTable.COLUMN_DISTINCT_ID + " = " + DatabaseUtils.sqlEscapeString(distinctId) + " "
            + "AND " + QiscusDb.RoomMemberTable.COLUMN_USER_EMAIL
            + " = " + DatabaseUtils.sqlEscapeString(email);

    Cursor cursor = sqLiteDatabase.rawQuery(query, null);

    while (cursor.moveToNext()) {
        QiscusChatRoom qiscusChatRoom = getChatRoom(QiscusDb.RoomMemberTable.getRoomId(cursor));
        if (qiscusChatRoom == null) {
            cursor.close();
            return null;
        }
        if (!qiscusChatRoom.isGroup()) {
            cursor.close();
            return qiscusChatRoom;
        }
    }

    cursor.close();
    return null;
}
项目:qiscus-sdk-android    文件:QiscusDataBaseHelper.java   
@Override
public void updateRoomMember(int roomId, QiscusRoomMember qiscusRoomMember, String distinctId) {
    distinctId = distinctId == null ? "default" : distinctId;
    String where = QiscusDb.RoomMemberTable.COLUMN_ROOM_ID + " = " + roomId + " AND "
            + QiscusDb.RoomMemberTable.COLUMN_USER_EMAIL + " = " + DatabaseUtils.sqlEscapeString(qiscusRoomMember.getEmail());
    sqLiteDatabase.beginTransaction();
    try {
        sqLiteDatabase.update(QiscusDb.RoomMemberTable.TABLE_NAME,
                QiscusDb.RoomMemberTable.toContentValues(roomId, distinctId, qiscusRoomMember), where, null);
        sqLiteDatabase.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        sqLiteDatabase.endTransaction();
    }

    addOrUpdate(qiscusRoomMember);
}
项目:qiscus-sdk-android    文件:QiscusDataBaseHelper.java   
@Override
public QiscusRoomMember getMember(String email) {
    String query = "SELECT * FROM "
            + QiscusDb.MemberTable.TABLE_NAME + " WHERE "
            + QiscusDb.MemberTable.COLUMN_USER_EMAIL + " = " + DatabaseUtils.sqlEscapeString(email);

    Cursor cursor = sqLiteDatabase.rawQuery(query, null);

    if (cursor.moveToNext()) {
        QiscusRoomMember qiscusRoomMember = QiscusDb.MemberTable.getMember(cursor);
        cursor.close();
        return qiscusRoomMember;
    } else {
        cursor.close();
        return null;
    }
}
项目:app-store-reviews-app    文件:ReviewsDatabaseHelper.java   
private static boolean insertReview(SQLiteDatabase db, ContentValues reviewValues) {
    final long rowId;
    // Wrapped both inserts as a SQL transaction as a precaution.
    db.beginTransaction();
    try {
        rowId = db.insert(GOOGLE_PLAY_REVIEW, null, reviewValues);
        long count = DatabaseUtils.queryNumEntries(db, GOOGLE_PLAY_REVIEW);
        Log.i("Review added", "Row ID: [" + rowId + "] Count now: " + count);
        if (rowId != -1) {
            ContentValues statusValues = new ContentValues();
            statusValues.put(REVIEW_ID, rowId);
            statusValues.put(STATUS, ReviewStatus.INITIAL.toString());
            final long rowIdForStatus = db.insert(REVIEW_STATUS, null, statusValues);
        }
        db.setTransactionSuccessful();

    } finally {
        db.endTransaction();
    }
    return (rowId != -1);
}
项目:AlchemistAndroidUtil    文件:FileUtils.java   
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context The context.
 * @param uri The Uri to query.
 * @param selection (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 * @author paulburke
 */
public static String getDataColumn(Context context, Uri uri, String selection,
                                   String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {
            if (DEBUG)
                DatabaseUtils.dumpCursor(cursor);

            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
项目:droidddle    文件:FileUtils.java   
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context       The context.
 * @param uri           The Uri to query.
 * @param selection     (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 * @author paulburke
 */
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {column};

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            if (DEBUG)
                DatabaseUtils.dumpCursor(cursor);

            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
项目:LsPush    文件:MimeTypeUtils.java   
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context The context.
 * @param uri The Uri to query.
 * @param selection (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 */
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
    final String column = "_data";
    final String[] projection = {
        column
    };

    Cursor cursor = null;
    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            if (DEBUG) {
                DatabaseUtils.dumpCursor(cursor);
            }
            final int columnIndex = cursor.getColumnIndex(column);
            return columnIndex < 0 ? null : cursor.getString(columnIndex);
        }
    } finally {
        if (cursor != null) cursor.close();
    }
    return null;
}
项目:DebugModule    文件:DatabaseCritterUtils.java   
/**
 * @param columnMap The map of column names to values.
 * @return A WHERE query for specified data.
 */
public static String toWhere(Map<String, Column> columnMap) {
    StringBuilder where = new StringBuilder();
    List<String> columnNames = new ArrayList<>(columnMap.keySet());
    for (int i = 0; i < columnNames.size(); i++) {
        if (i > 0) {
            where.append(" AND ");
        }
        String columnName = columnNames.get(i);
        Column column = columnMap.get(columnName);
        where.append(column.getUpdateColumnName()).append(" = ");
        if (column.value instanceof String) {
            where.append(DatabaseUtils.sqlEscapeString(column.value.toString()));
        } else {
            where.append(column.value);
        }
    }
    return where.toString();
}
项目:FMTech    文件:brg.java   
public static void a(Context paramContext, int paramInt, boolean paramBoolean)
{
  SQLiteDatabase localSQLiteDatabase = bqj.a(paramContext, paramInt).getReadableDatabase();
  if (DatabaseUtils.longForQuery(localSQLiteDatabase, h, null) > 0L) {}
  for (int i = 1;; i = 0)
  {
    if (DatabaseUtils.longForQuery(localSQLiteDatabase, g, null) > 0L)
    {
      localSQLiteDatabase.execSQL("UPDATE guns SET read_state = 1, pending_read = 0 WHERE pending_read = 1");
      if (i != 0) {
        a(paramContext, paramInt, 1, null);
      }
      if (paramBoolean) {
        paramContext.getContentResolver().notifyChange(EsProvider.a(EsProvider.d(paramContext), paramInt), null);
      }
    }
    return;
  }
}
项目:translationRecorder    文件:ProjectDatabaseHelper.java   
public int getUnitId(String languageCode, String slug, String version, int chapter, int startVerse) throws IllegalArgumentException{
//        Logger.w(this.toString(), "Trying to get unit Id for start verse " + startVerse);
        String projectId = String.valueOf(getProjectId(languageCode, slug, version));
        String chapterId = String.valueOf(getChapterId(languageCode, slug, version, chapter));
        SQLiteDatabase db = getReadableDatabase();
        final String unitIdQuery = String.format("SELECT %s FROM %s WHERE %s=? AND %s=? AND %s=?",
                ProjectContract.UnitEntry._ID, ProjectContract.UnitEntry.TABLE_UNIT, ProjectContract.UnitEntry.UNIT_PROJECT_FK, ProjectContract.UnitEntry.UNIT_CHAPTER_FK, ProjectContract.UnitEntry.UNIT_START_VERSE);
        int id = -1;
        try {
            id = (int) DatabaseUtils.longForQuery(db, unitIdQuery, new String[]{projectId, chapterId, String.valueOf(startVerse)});
        } catch (SQLiteDoneException e){
            //db.close();
            throw new IllegalArgumentException("Unit not found in database");
        }
        //db.close();
        return id;
    }
项目:Zom-Android    文件:ContactListFilterView.java   
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    StringBuilder buf = new StringBuilder();

    if (mSearchString != null) {

        buf.append(Imps.Contacts.NICKNAME);
        buf.append(" LIKE ");
        DatabaseUtils.appendValueToSql(buf, "%" + mSearchString + "%");
        buf.append(" OR ");
        buf.append(Imps.Contacts.USERNAME);
        buf.append(" LIKE ");
        DatabaseUtils.appendValueToSql(buf, "%" + mSearchString + "%");
    }

    CursorLoader loader = new CursorLoader(getContext(), mUri, ContactListItem.CONTACT_PROJECTION,
            buf == null ? null : buf.toString(), null, Imps.Contacts.DEFAULT_SORT_ORDER);

    //     loader.setUpdateThrottle(10L);
    return loader;
}
项目:translationRecorder    文件:ProjectDatabaseHelper.java   
public int getChapterId(String languageCode, String slug, String version, int chapter){
//        Logger.w(this.toString(), "trying to get chapter id for chapter " + chapter);
        String projectId = String.valueOf(getProjectId(languageCode, slug, version));
        SQLiteDatabase db = getReadableDatabase();
        final String chapterIdQuery = String.format("SELECT %s FROM %s WHERE %s=? AND %s=?",
                ProjectContract.ChapterEntry._ID, ProjectContract.ChapterEntry.TABLE_CHAPTER, ProjectContract.ChapterEntry.CHAPTER_PROJECT_FK, ProjectContract.ChapterEntry.CHAPTER_NUMBER);
        int id = -1;
        try {
            id = (int) DatabaseUtils.longForQuery(db, chapterIdQuery, new String[]{projectId, String.valueOf(chapter)});
        } catch (SQLiteDoneException e){
            //db.close();
            throw new IllegalArgumentException("Chapter not found in database");
        }
        //db.close();
        return id;
    }
项目:FMTech    文件:bry.java   
static void a(SQLiteDatabase paramSQLiteDatabase, String paramString, int paramInt)
{
  ContentValues localContentValues = new ContentValues();
  localContentValues.put("token_type", Integer.valueOf(paramInt));
  if (TextUtils.isEmpty(paramString)) {
    localContentValues.putNull("token");
  }
  String[] arrayOfString;
  for (;;)
  {
    arrayOfString = new String[1];
    arrayOfString[0] = Integer.toString(paramInt);
    if (DatabaseUtils.longForQuery(paramSQLiteDatabase, "SELECT COUNT(*) FROM photo_requests WHERE token_type = ?", arrayOfString) != 0L) {
      break;
    }
    paramSQLiteDatabase.insert("photo_requests", null, localContentValues);
    return;
    localContentValues.put("token", paramString);
  }
  paramSQLiteDatabase.update("photo_requests", localContentValues, "token_type = ?", arrayOfString);
}
项目:FMTech    文件:jrf.java   
private static HashSet<String> b(SQLiteDatabase paramSQLiteDatabase, String paramString)
{
  String[] arrayOfString = { paramString };
  int k = (int)DatabaseUtils.longForQuery(paramSQLiteDatabase, "SELECT count(*) FROM all_tiles WHERE view_id = ? AND media_attr & 512 != 0 AND tile_id LIKE '~post:%'", arrayOfString);
  HashSet localHashSet = null;
  Cursor localCursor;
  if (k > 0)
  {
    localCursor = paramSQLiteDatabase.query("all_tiles", new String[] { "tile_id" }, "view_id = ? AND media_attr & 512 != 0 AND tile_id LIKE '~post:%'", arrayOfString, null, null, null);
    try
    {
      localHashSet = new HashSet(k);
      while (localCursor.moveToNext()) {
        localHashSet.add(localCursor.getString(0));
      }
    }
    finally
    {
      localCursor.close();
    }
  }
  return localHashSet;
}
项目:FMTech    文件:jrf.java   
public static void b(Context paramContext, int paramInt, String paramString1, String paramString2, boolean paramBoolean)
{
  SQLiteDatabase localSQLiteDatabase = ((hrz)mbb.a(paramContext, hrz.class)).b(paramContext, paramInt).getWritableDatabase();
  String[] arrayOfString = { paramString1 };
  ContentValues localContentValues = new ContentValues(3);
  localContentValues.put("view_id", paramString1);
  if (TextUtils.isEmpty(paramString2)) {
    localContentValues.putNull("resume_token");
  }
  for (;;)
  {
    if (paramBoolean) {
      localContentValues.put("last_refresh_time", Long.valueOf(System.currentTimeMillis()));
    }
    if (DatabaseUtils.longForQuery(localSQLiteDatabase, "SELECT count(*) FROM tile_requests WHERE view_id = ?", arrayOfString) != 0L) {
      break;
    }
    localSQLiteDatabase.insert("tile_requests", null, localContentValues);
    return;
    localContentValues.put("resume_token", paramString2);
  }
  localSQLiteDatabase.update("tile_requests", localContentValues, "view_id = ?", arrayOfString);
}
项目:FMTech    文件:bgp.java   
public static boolean e(Context paramContext, int paramInt)
{
  SQLiteDatabase localSQLiteDatabase = bqj.a(paramContext, paramInt).getReadableDatabase();
  try
  {
    long l = DatabaseUtils.longForQuery(localSQLiteDatabase, "SELECT wipeout_stats  FROM account_status", null);
    boolean bool1 = l < 1L;
    boolean bool2 = false;
    if (!bool1) {
      bool2 = true;
    }
    return bool2;
  }
  catch (SQLiteDoneException localSQLiteDoneException) {}
  return false;
}
项目:FMTech    文件:deb.java   
private static String a(String[] paramArrayOfString)
{
  StringBuilder localStringBuilder = new StringBuilder("type == 4");
  if ((paramArrayOfString != null) && (paramArrayOfString.length > 0))
  {
    localStringBuilder.append(" AND photo_id").append(" IN (");
    for (int i = 0; i < paramArrayOfString.length; i++)
    {
      if (i > 0) {
        localStringBuilder.append(",");
      }
      localStringBuilder.append(DatabaseUtils.sqlEscapeString(paramArrayOfString[i]));
    }
    localStringBuilder.append(")");
  }
  return localStringBuilder.toString();
}
项目:Pix-Art-Messenger    文件:DatabaseBackend.java   
public long numTrustedKeys(Account account, String name) {
    SQLiteDatabase db = getReadableDatabase();
    String[] args = {
            account.getUuid(),
            name,
            FingerprintStatus.Trust.TRUSTED.toString(),
            FingerprintStatus.Trust.VERIFIED.toString(),
            FingerprintStatus.Trust.VERIFIED_X509.toString()
    };
    return DatabaseUtils.queryNumEntries(db, SQLiteAxolotlStore.IDENTITIES_TABLENAME,
            SQLiteAxolotlStore.ACCOUNT + " = ?"
                    + " AND " + SQLiteAxolotlStore.NAME + " = ?"
                    + " AND (" + SQLiteAxolotlStore.TRUST + " = ? OR " + SQLiteAxolotlStore.TRUST + " = ? OR " + SQLiteAxolotlStore.TRUST + " = ?)"
                    + " AND " + SQLiteAxolotlStore.ACTIVE + " > 0",
            args
    );
}
项目:FMTech    文件:hbj.java   
public static boolean k(Context paramContext, int paramInt)
{
  efj.l();
  SQLiteDatabase localSQLiteDatabase = ((hci)mbb.a(paramContext, hci.class)).getReadableDatabase();
  if (localSQLiteDatabase == null) {
    throw new hbk();
  }
  String str1 = MediaRecordEntry.a.a;
  String str2 = String.valueOf("upload_reason");
  String str3 = String.valueOf("upload_reason");
  String str4 = String.valueOf("bucket_id");
  String str5 = String.valueOf("upload_account_id");
  String str6 = 84 + String.valueOf(str1).length() + String.valueOf(str2).length() + String.valueOf(str3).length() + String.valueOf(str4).length() + String.valueOf(str5).length() + "SELECT count(*) FROM " + str1 + " WHERE (" + str2 + " = 30" + " OR " + str3 + " = 40" + ") AND " + str4 + " IS NULL AND " + str5 + " = ?";
  String[] arrayOfString = new String[1];
  arrayOfString[0] = Integer.toString(paramInt);
  return DatabaseUtils.longForQuery(localSQLiteDatabase, str6, arrayOfString) != 0L;
}