當前位置: 首頁>>代碼示例>>Java>>正文


Java DatabaseUtils類代碼示例

本文整理匯總了Java中android.database.DatabaseUtils的典型用法代碼示例。如果您正苦於以下問題:Java DatabaseUtils類的具體用法?Java DatabaseUtils怎麽用?Java DatabaseUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DatabaseUtils類屬於android.database包,在下文中一共展示了DatabaseUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: logTableDump

import android.database.DatabaseUtils; //導入依賴的package包/類
public static void logTableDump(SQLiteDatabase db, String tablename) {
    Cursor cursor = db.query(tablename, null, null, null, null, null, null);
    try {
        String dump = DatabaseUtils.dumpCursorToString(cursor);
        DaoLog.d(dump);
    } finally {
        cursor.close();
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:DbUtils.java

示例2: getDataColumn

import android.database.DatabaseUtils; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:takyonxxx,項目名稱:AndroidSdrRtlTuner,代碼行數:37,代碼來源:FileUtils.java

示例3: getDataColumn

import android.database.DatabaseUtils; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:rumaan,項目名稱:file.io-app,代碼行數:37,代碼來源:FileUtils.java

示例4: runSql

import android.database.DatabaseUtils; //導入依賴的package包/類
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());
            }
        }
    }
 
開發者ID:WeiMei-Tian,項目名稱:editor-sql,代碼行數:24,代碼來源:SqlCommondActivity.java

示例5: doesGoalExist

import android.database.DatabaseUtils; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:Austin-Ray,項目名稱:Hexis,代碼行數:29,代碼來源:GoalReader.java

示例6: updateGoal

import android.database.DatabaseUtils; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:Austin-Ray,項目名稱:Hexis,代碼行數:31,代碼來源:GoalWriter.java

示例7: getDataColumn

import android.database.DatabaseUtils; //導入依賴的package包/類
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;
	}
 
開發者ID:Datatellit,項目名稱:xlight_android_native,代碼行數:26,代碼來源:FileUtils.java

示例8: ce

import android.database.DatabaseUtils; //導入依賴的package包/類
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();
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:19,代碼來源:ay.java

示例9: getDataColumn

import android.database.DatabaseUtils; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:WorldBank-Transport,項目名稱:RoadLab-Pro,代碼行數:34,代碼來源:PathUtils.java

示例10: update

import android.database.DatabaseUtils; //導入依賴的package包/類
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);
    }
}
 
開發者ID:CentriaUniversityOfAppliedSciences,項目名稱:Android_RuuvitagScannner,代碼行數:17,代碼來源:ScannerService.java

示例11: numTrustedKeys

import android.database.DatabaseUtils; //導入依賴的package包/類
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
	);
}
 
開發者ID:syntafin,項目名稱:TenguChat,代碼行數:18,代碼來源:DatabaseBackend.java

示例12: getMessageCount

import android.database.DatabaseUtils; //導入依賴的package包/類
/** 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;
}
 
開發者ID:casific,項目名稱:murmur,代碼行數:23,代碼來源:MessageStore.java

示例13: executeSql

import android.database.DatabaseUtils; //導入依賴的package包/類
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();
    }
}
 
開發者ID:doppllib,項目名稱:core-doppl,代碼行數:27,代碼來源:SQLiteDatabase.java

示例14: executeSpecial

import android.database.DatabaseUtils; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:doppllib,項目名稱:core-doppl,代碼行數:46,代碼來源:SQLiteSession.java

示例15: getDataColumn

import android.database.DatabaseUtils; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:Tourenathan-G5organisation,項目名稱:SiliCompressor,代碼行數:37,代碼來源:FileUtils.java


注:本文中的android.database.DatabaseUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。