当前位置: 首页>>代码示例>>Java>>正文


Java SQLiteOpenHelper.close方法代码示例

本文整理汇总了Java中android.database.sqlite.SQLiteOpenHelper.close方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteOpenHelper.close方法的具体用法?Java SQLiteOpenHelper.close怎么用?Java SQLiteOpenHelper.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.database.sqlite.SQLiteOpenHelper的用法示例。


在下文中一共展示了SQLiteOpenHelper.close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sequentialUpgrade

import android.database.sqlite.SQLiteOpenHelper; //导入方法依赖的package包/类
/**
 * Upgrade existing database.
 */
@Test
public void sequentialUpgrade() {
    final Context ctx = RuntimeEnvironment.application.getApplicationContext();
    final int[] versions = new int[]{1, 2, 3};
    for (int i = 1; i <= 3; i++) {
        final SQLiteOpenHelper unit = new DBUnit(ctx, i);
        final SQLiteDatabase db = unit.getReadableDatabase();
        Cursor cursor = null;
        try {
            cursor = db.rawQuery("SELECT value FROM versions", new String[0]);
            assertVersions(cursor, Arrays.copyOf(versions, i));
        } finally {
            if (cursor != null) {
                cursor.close();
            }
            db.close();
        }
        unit.close();
    }
}
 
开发者ID:g4s8,项目名称:Android-Migrator,代码行数:24,代码来源:SQLiteMigrationsTest.java

示例2: insert_single_record_test

import android.database.sqlite.SQLiteOpenHelper; //导入方法依赖的package包/类
/**
 * This method tests inserting a single record into an empty table from a brand new database.
 * The purpose is to test that the database is working as expected
 * @throws Exception in case the constructor hasn't been implemented yet
 */
@Test
public void insert_single_record_test() throws Exception{

    /* Use reflection to try to run the correct constructor whenever implemented */
    SQLiteOpenHelper dbHelper =
            (SQLiteOpenHelper) mDbHelperClass.getConstructor(Context.class).newInstance(mContext);

    /* Use WaitlistDbHelper to get access to a writable database */
    SQLiteDatabase database = dbHelper.getWritableDatabase();

    ContentValues testValues = new ContentValues();
    testValues.put(WaitlistContract.WaitlistEntry.COLUMN_GUEST_NAME, "test name");
    testValues.put(WaitlistContract.WaitlistEntry.COLUMN_PARTY_SIZE, 99);

    /* Insert ContentValues into database and get first row ID back */
    long firstRowId = database.insert(
            WaitlistContract.WaitlistEntry.TABLE_NAME,
            null,
            testValues);

    /* If the insert fails, database.insert returns -1 */
    assertNotEquals("Unable to insert into the database", -1, firstRowId);

    /*
     * Query the database and receive a Cursor. A Cursor is the primary way to interact with
     * a database in Android.
     */
    Cursor wCursor = database.query(
            /* Name of table on which to perform the query */
            WaitlistContract.WaitlistEntry.TABLE_NAME,
            /* Columns; leaving this null returns every column in the table */
            null,
            /* Optional specification for columns in the "where" clause above */
            null,
            /* Values for "where" clause */
            null,
            /* Columns to group by */
            null,
            /* Columns to filter by row groups */
            null,
            /* Sort order to return in Cursor */
            null);

    /* Cursor.moveToFirst will return false if there are no records returned from your query */
    String emptyQueryError = "Error: No Records returned from waitlist query";
    assertTrue(emptyQueryError,
            wCursor.moveToFirst());

    /* Close cursor and database */
    wCursor.close();
    dbHelper.close();
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:58,代码来源:DatabaseTest.java


注:本文中的android.database.sqlite.SQLiteOpenHelper.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。