当前位置: 首页>>代码示例>>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;未经允许,请勿转载。