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


Java SQLiteOpenHelper.getReadableDatabase方法代码示例

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


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

示例1: buildHistoryItems

import android.database.sqlite.SQLiteOpenHelper; //导入方法依赖的package包/类
public List<HistoryItem> buildHistoryItems() {
  SQLiteOpenHelper helper = new DBHelper(activity);
  List<HistoryItem> items = new ArrayList<>();
  SQLiteDatabase db = null;
  Cursor cursor = null;
  try {
    db = helper.getReadableDatabase();
    cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
    while (cursor.moveToNext()) {
      String text = cursor.getString(0);
      String display = cursor.getString(1);
      String format = cursor.getString(2);
      long timestamp = cursor.getLong(3);
      String details = cursor.getString(4);
      Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp);
      items.add(new HistoryItem(result, display, details));
    }
  } finally {
    close(cursor, db);
  }
  return items;
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:23,代码来源:HistoryManager.java

示例2: buildHistoryItem

import android.database.sqlite.SQLiteOpenHelper; //导入方法依赖的package包/类
public HistoryItem buildHistoryItem(int number) {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  Cursor cursor = null;
  try {
    db = helper.getReadableDatabase();
    cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
    cursor.move(number + 1);
    String text = cursor.getString(0);
    String display = cursor.getString(1);
    String format = cursor.getString(2);
    long timestamp = cursor.getLong(3);
    String details = cursor.getString(4);
    Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp);
    return new HistoryItem(result, display, details);
  } finally {
    close(cursor, db);
  }
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:20,代码来源:HistoryManager.java

示例3: 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

示例4: customFolder

import android.database.sqlite.SQLiteOpenHelper; //导入方法依赖的package包/类
/**
 * Apply migrations from custom folder.
 */
@Test
public void customFolder() {
    final Context ctx = RuntimeEnvironment.application;

    final SQLiteOpenHelper unit = new DBUnit(ctx, 1, "custom_migrations");
    final SQLiteDatabase database = unit.getReadableDatabase();
    Cursor cursor = null;
    try {
        cursor = database.rawQuery("SELECT value FROM custom_versions", new String[0]);
        assertVersions(cursor, 1);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
        database.close();
    }
}
 
开发者ID:g4s8,项目名称:Android-Migrator,代码行数:21,代码来源:SQLiteMigrationsTest.java

示例5: hasHistoryItems

import android.database.sqlite.SQLiteOpenHelper; //导入方法依赖的package包/类
public boolean hasHistoryItems() {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  Cursor cursor = null;
  try {
    db = helper.getReadableDatabase();
    cursor = db.query(DBHelper.TABLE_NAME, COUNT_COLUMN, null, null, null, null, null);
    cursor.moveToFirst();
    return cursor.getInt(0) > 0;
  } finally {
    close(cursor, db);
  }
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:14,代码来源:HistoryManager.java

示例6: getStationById

import android.database.sqlite.SQLiteOpenHelper; //导入方法依赖的package包/类
/**
 * @inheritDoc
 */
@Override
@AddTrace(name="StationsDb.getStationById")
public Station getStationById(String id) {

    SQLiteOpenHelper StationsDbHelper = new StationsDb(context);
    SQLiteDatabase db = StationsDbHelper.getReadableDatabase();
    Cursor c = db.query(
            StationsDataColumns.TABLE_NAME,
            new String[]{
                    StationsDataColumns._ID,
                    StationsDataColumns.COLUMN_NAME_NAME,
                    StationsDataColumns.COLUMN_NAME_ALTERNATIVE_NL,
                    StationsDataColumns.COLUMN_NAME_ALTERNATIVE_FR,
                    StationsDataColumns.COLUMN_NAME_ALTERNATIVE_DE,
                    StationsDataColumns.COLUMN_NAME_ALTERNATIVE_EN,
                    StationsDataColumns.COLUMN_NAME_COUNTRY_CODE,
                    StationsDataColumns.COLUMN_NAME_LATITUDE,
                    StationsDataColumns.COLUMN_NAME_LONGITUDE,
                    StationsDataColumns.COLUMN_NAME_AVG_STOP_TIMES
            },
            StationsDataColumns._ID + "=?",
            new String[]{id},
            null,
            null,
            null,
            "1");

    Station[] results = loadStationCursor(c);

    c.close();
    db.close();

    if (results == null) {
        return null;
    }

    return results[0];
}
 
开发者ID:hyperrail,项目名称:hyperrail-for-android,代码行数:42,代码来源:StationsDb.java

示例7: migrationsFromDbVersion42Onward

import android.database.sqlite.SQLiteOpenHelper; //导入方法依赖的package包/类
@Test
public void migrationsFromDbVersion42Onward() {
    SQLiteOpenHelper opener = new MigrationRunningOpenHelper(context);
    opener.getReadableDatabase();
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:6,代码来源:DatabaseMigration.java

示例8: upgrade_database_test

import android.database.sqlite.SQLiteOpenHelper; //导入方法依赖的package包/类
/**
 * Tests that onUpgrade works by inserting 2 rows then calling onUpgrade and verifies that the
 * database has been successfully dropped and recreated by checking that the database is there
 * but empty
 * @throws Exception in case the constructor hasn't been implemented yet
 */
@Test
public void upgrade_database_test() throws Exception{

    /* Insert 2 rows before we upgrade to check that we dropped the database correctly */

    /* 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);

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

    dbHelper.onUpgrade(database, 0, 1);
    database = dbHelper.getReadableDatabase();

    /* This Cursor will contain the names of each table in our database */
    Cursor tableNameCursor = database.rawQuery(
            "SELECT name FROM sqlite_master WHERE type='table' AND name='" +
                    WaitlistContract.WaitlistEntry.TABLE_NAME + "'",
            null);

    assertTrue(tableNameCursor.getCount() == 1);

    /*
     * 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 */

    assertFalse("Database doesn't seem to have been dropped successfully when upgrading",
            wCursor.moveToFirst());

    tableNameCursor.close();
    database.close();
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:74,代码来源:DatabaseTest.java

示例9: getStationFacilitiesById

import android.database.sqlite.SQLiteOpenHelper; //导入方法依赖的package包/类
public StationFacilities getStationFacilitiesById(String id) {

        SQLiteOpenHelper StationsDbHelper = new StationsDb(context);
        SQLiteDatabase db = StationsDbHelper.getReadableDatabase();
        Cursor c = db.query(
                StationFacilityColumns.TABLE_NAME,
                new String[]{
                        StationFacilityColumns._ID,
                        StationFacilityColumns.COLUMN_STREET,
                        StationFacilityColumns.COLUMN_ZIP,
                        StationFacilityColumns.COLUMN_CITY,
                        StationFacilityColumns.COLUMN_TICKET_VENDING_MACHINE,
                        StationFacilityColumns.COLUMN_LUGGAGE_LOCKERS,
                        StationFacilityColumns.COLUMN_FREE_PARKING,
                        StationFacilityColumns.COLUMN_TAXI,
                        StationFacilityColumns.COLUMN_BICYCLE_SPOTS,
                        StationFacilityColumns.COLUMN_BLUE_BIKE,
                        StationFacilityColumns.COLUMN_BUS,
                        StationFacilityColumns.COLUMN_TRAM,
                        StationFacilityColumns.COLUMN_METRO,
                        StationFacilityColumns.COLUMN_WHEELCHAIR_AVAILABLE,
                        StationFacilityColumns.COLUMN_RAMP,
                        StationFacilityColumns.COLUMN_DISABLED_PARKING_SPOTS,
                        StationFacilityColumns.COLUMN_ELEVATED_PLATFORM,
                        StationFacilityColumns.COLUMN_ESCALATOR_UP,
                        StationFacilityColumns.COLUMN_ESCALATOR_DOWN,
                        StationFacilityColumns.COLUMN_ELEVATOR_PLATFORM,
                        StationFacilityColumns.COLUMN_HEARING_AID_SIGNAL,
                        StationFacilityColumns.COLUMN_SALES_OPEN_MONDAY,
                        StationFacilityColumns.COLUMN_SALES_CLOSE_MONDAY,
                        StationFacilityColumns.COLUMN_SALES_OPEN_TUESDAY,
                        StationFacilityColumns.COLUMN_SALES_CLOSE_TUESDAY,
                        StationFacilityColumns.COLUMN_SALES_OPEN_WEDNESDAY,
                        StationFacilityColumns.COLUMN_SALES_CLOSE_WEDNESDAY,
                        StationFacilityColumns.COLUMN_SALES_OPEN_THURSDAY,
                        StationFacilityColumns.COLUMN_SALES_CLOSE_THURSDAY,
                        StationFacilityColumns.COLUMN_SALES_OPEN_FRIDAY,
                        StationFacilityColumns.COLUMN_SALES_CLOSE_FRIDAY,
                        StationFacilityColumns.COLUMN_SALES_OPEN_SATURDAY,
                        StationFacilityColumns.COLUMN_SALES_CLOSE_SATURDAY,
                        StationFacilityColumns.COLUMN_SALES_OPEN_SUNDAY,
                        StationFacilityColumns.COLUMN_SALES_CLOSE_SUNDAY,
                },
                StationFacilityColumns._ID + "=?",
                new String[]{id},
                null,
                null,
                null,
                "1");

        if (c.getCount() == 0) {
            c.close();
            db.close();
            return null;
        }

        StationFacilities result = loadFacilitiesCursor(c);
        c.close();
        db.close();
        return result;

    }
 
开发者ID:hyperrail,项目名称:hyperrail-for-android,代码行数:63,代码来源:StationsDb.java


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