Java Code Examples for android.database.sqlite.SQLiteDatabase.close()

The following are Jave code examples for showing how to use close() of the android.database.sqlite.SQLiteDatabase class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Khonsu   File: DatabaseOpenHelper.java   View Source Code Vote up 6 votes
public void insertLocation(Location loc) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(Constants.DATABASE.LOCATION_NAME, loc.getLoactionName());
    values.put(Constants.DATABASE.LOCATION_TYPE, loc.getLocationType());
    values.put(Constants.DATABASE.LOCATION_STICKER_UUID, loc.getStickerUuid());
    values.put(Constants.DATABASE.LOCATION_X, loc.getLocationX());
    values.put(Constants.DATABASE.LOCATION_Y, loc.getLocationY());
    values.put(Constants.DATABASE.LOCATION_COOR_X, loc.getCoordinateX());
    values.put(Constants.DATABASE.LOCATION_COOR_Y, loc.getCoordinateY());
    values.put(Constants.DATABASE.LOCATION_FLOOR_ID, loc.getFloorId());
    db.insert(Constants.DATABASE.LOCATION_TABLE_NAME, null, values);

    values.clear();
    db.close();
}
 
Example 2
Project: NeteaseCloudMusic   File: PlaylistModel.java   View Source Code Vote up 6 votes
public List<MusicBean> loadPlaylist(int playlistID) {
    SQLiteDatabase db = mDBHelper.getReadableDatabase();
    Cursor cursor = db.rawQuery("select name,singer,album,duration,diskMusic.[path] from diskMusic left join playlist_detail on playlist_detail.[path]=diskMusic.[path] where playlist_detail.[list_id]=? order by playlist_detail.[path] desc; "
            ,new String[]{String.valueOf(playlistID)});

    ArrayList<MusicBean> list = new ArrayList<>();

    while (null != cursor && cursor.moveToNext()) {
        String name = cursor.getString(0);
        String singer = cursor.getString(1);
        String album = cursor.getString(2);
        long duration = cursor.getLong(3);
        String path = cursor.getString(4);
        list.add(new MusicBean(name,singer,album,duration, path));
    }
    if (cursor != null) {
        cursor.close();
    }
    db.close();

    return list;
}
 
Example 3
Project: CitySelct   File: MainActivity.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
private void getResultCityList(String keyword) {
	AllCitySqliteOpenHelper dbHelper = new AllCitySqliteOpenHelper(this);
	try {
		dbHelper.createDataBase();
		SQLiteDatabase db = dbHelper.getWritableDatabase();
		Cursor cursor = db.rawQuery(
				"select * from city where name like \"%" + keyword
						+ "%\" or pinyin like \"%" + keyword + "%\"", null);
		City city;
		while (cursor.moveToNext()) {
			String cityName=cursor.getString(cursor.getColumnIndex("name"));
			String cityPinyin=cursor.getString(cursor.getColumnIndex("pinyin"));
			city = new City(cityName,cityPinyin);
			searchCityList.add(city);
		}
		cursor.close();
		db.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
	//将得到的集合按照自定义的comparator的规则进行排序
	Collections.sort(searchCityList, comparator);
}
 
Example 4
Project: OneTwo   File: CounterFragment.java   View Source Code Vote up 6 votes
private void updateUI() {
    ArrayList<String> objList = new ArrayList<>();
    ArrayList<Integer> numList = new ArrayList<>();
    SQLiteDatabase db = mHelper.getReadableDatabase();
    Cursor cursor = db.query(TaskContract.TaskEntry.TABLE,
            new String[]{TaskContract.TaskEntry._ID, TaskContract.TaskEntry.COL_TASK_TITLE, TaskContract.TaskEntry.COL_NUM_TITLE},
            null, null, null, null, null);
    while (cursor.moveToNext()) {
        int idx = cursor.getColumnIndex(TaskContract.TaskEntry.COL_TASK_TITLE);
        int idx_num = cursor.getColumnIndex(TaskContract.TaskEntry.COL_NUM_TITLE);
        objList.add(cursor.getString(idx));
        numList.add(cursor.getInt(idx_num));
    }

    mListAdapter.setData(objList, numList);
    cursor.close();
    db.close();

    if (objList.size() > 0) {
        instructionTextView.setVisibility(View.INVISIBLE);
    }else {
        instructionTextView.setVisibility(View.VISIBLE);
    }
}
 
Example 5
Project: Logistics-guard   File: SQLiteUtil.java   View Source Code Vote up 6 votes
public static void save(String key, boolean value) {
    SQLiteDatabase db = null;
    Cursor cursor = null;
    try {
        db = new SQLiteHelper(App.getContext()).getReadableDatabase();
        cursor = db.rawQuery("select * from temp where key=? ", new String[]{key});
        ContentValues contentValues = new ContentValues();
        contentValues.put("key", key);
        contentValues.put("value", value);
        if (cursor.moveToFirst()) {
            db.update("temp", contentValues, "key=?", new String[]{key});
        } else {
            db.insert("temp", null, contentValues);
        }
    } finally {
        if (cursor != null)
            cursor.close();
        if (db != null)
            db.close();
    }
}
 
Example 6
Project: pvdisplay   File: PvDataOperations.java   View Source Code Vote up 5 votes
public List<DailyPvDatum> loadDaily(int year, int month) {
    SQLiteDatabase db = pvDataHelper.getReadableDatabase();

    String[] projection = {
            PvDataContract.DailyPvData.COLUMN_NAME_DAY,
            PvDataContract.DailyPvData.COLUMN_NAME_ENERGY_GENERATED,
            PvDataContract.DailyPvData.COLUMN_NAME_PEAK_POWER,
            PvDataContract.DailyPvData.COLUMN_NAME_CONDITION
    };
    String sortOrder =
            PvDataContract.DailyPvData.COLUMN_NAME_DAY + " ASC";
    String selection =
            PvDataContract.DailyPvData.COLUMN_NAME_YEAR + "=? AND " +
            PvDataContract.DailyPvData.COLUMN_NAME_MONTH + "=?";
    String[] selectionArgs = {
            "" + year,
            "" + month
    };

    List<DailyPvDatum> dailyPvData = new ArrayList<>();
    Cursor cursor = db.query(PvDataContract.DailyPvData.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder);
    if (cursor != null) {
        if (cursor.moveToFirst()) {
            do {
                dailyPvData.add(new DailyPvDatum(
                        year,
                        month,
                        cursor.getInt(cursor.getColumnIndex(PvDataContract.DailyPvData.COLUMN_NAME_DAY)),
                        cursor.getDouble(cursor.getColumnIndex(PvDataContract.DailyPvData.COLUMN_NAME_ENERGY_GENERATED)),
                        cursor.getDouble(cursor.getColumnIndex(PvDataContract.DailyPvData.COLUMN_NAME_PEAK_POWER)),
                        cursor.getString(cursor.getColumnIndex(PvDataContract.DailyPvData.COLUMN_NAME_CONDITION))));
            } while (cursor.moveToNext());
        }
        cursor.close();
    }
    db.close();
    Log.d(TAG, "Loaded " + dailyPvData.size() + " rows of daily PV data for " + DateTimeUtils.formatYearMonth(year, month, true) + " from database");

    return dailyPvData;
}
 
Example 7
Project: XERUNG   File: GroupDb.java   View Source Code Vote up 5 votes
public int checkGroupExist(int gUid, GroupBean gb) {
    try {
        String exist = "SELECT COUNT(*) as m FROM " + TABLE_NAME + " Where " + T_GROUPID + " = " + gUid;
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(exist, null);
        // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                //Log.e("ddd "," Exist "+cursor.getInt(0));
                if (cursor.getInt(0) != 0) {
                    //String updateTable= "UPDATE "+TABLE_NAME+" SET "+T_TAGNAME+"= '"+gb.getmGroupTag().trim()+"', "+T_DESCRITION+"= '"+gb.getmGroupTag().trim()+"', "+T_GROUPPHOTO+"= '"+gb.getmPhoto().trim()+"', "+T_MEMBERCOUNT+"= '"+String.valueOf(gb.getmGroupSize())+"', "+T_ADMINFLAG+"= '"+gb.getmGroupAdmin()+" Where "+T_GROUPID+" = "+gUid+";";
                    ContentValues cv = new ContentValues();
                    cv.put(T_TAGNAME, gb.getmGroupTag().trim());
                    cv.put(T_DESCRITION, gb.getmGroupDesc().trim());
                    cv.put(T_GROUPPHOTO, gb.getmPhoto().trim());
                    cv.put(T_MEMBERCOUNT, String.valueOf(gb.getmGroupSize()));
                    cv.put(T_ADMINFLAG, gb.getmGroupAdmin());
                    cv.put(T_CREATEUPDATETS, gb.getmGroupCreatedDate());
                    db.update(TABLE_NAME, cv, T_GROUPID + " = ?",
                            new String[]{String.valueOf(gb.getmGroupId())});
                    return 0;
                } else {
                    addGroup(gb);
                }
            } while (cursor.moveToNext());
        }
        if (cursor != null)
            cursor.close();
        db.close();
    } catch (Exception e) {
        // TODO: handle exception
        //Log.e("GroupDBErro", "FetchAllDB " + e.getMessage());
        e.printStackTrace();
    }
    return 1;
}
 
Example 8
Project: XERUNG   File: GroupDb.java   View Source Code Vote up 5 votes
public int addGroup(GroupBean gb) {
    //Log.e("ADD GROUP", "ADD GROUP");
    int status = 0;
    try {
        SQLiteDatabase sq = this.getWritableDatabase();
        ContentValues cv = new ContentValues();
        cv.put(T_GROUPID, Integer.parseInt(gb.getmGroupId().trim()));
        cv.put(T_GROUPNAME, gb.getmGroupName().trim());

        cv.put(T_MADEBYNAME, gb.getmGroupMadeByName().trim());
        cv.put(T_MADEBYPHONENO, gb.getmGroupMadeByNum().trim());
        cv.put(T_TAGNAME, gb.getmGroupTag().trim());
        cv.put(T_DESCRITION, gb.getmGroupDesc().trim());
        cv.put(T_GROUPPHOTO, gb.getmPhoto().trim());
        cv.put(T_MEMBERCOUNT, String.valueOf(gb.getmGroupSize()));
        cv.put(T_ACCESS_TYPE, gb.getmGroupAccessType().trim());
        cv.put(T_ADMINFLAG, gb.getmGroupAdmin());
        cv.put(T_CREATEUPDATETS, gb.getmGroupCreatedDate());
        sq.insert(TABLE_NAME, null, cv);
        status = 1;
        sq.close();
    } catch (Exception e) {
        // TODO: handle exception
        status = 0;
        //Log.e("GroupDBErro", "AddGroup "+e.getMessage());
        e.printStackTrace();
    }
    return status;
}
 
Example 9
Project: AndroidDBForData   File: MyDBHelper.java   View Source Code Vote up 5 votes
/**
 * 检测数据库是否存在并且能否打开
 */
private boolean checkDataBase() {

    SQLiteDatabase checkDB = null;
    try {
        String myPath = CopyDBApplication.DBPATH + CopyDBApplication.DBNAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
    } catch (Exception e) {

    }
    if (checkDB != null) {
        checkDB.close();
    }
    return checkDB != null ? true : false;
}
 
Example 10
Project: an2linuxclient   File: ServerDatabaseHandler.java   View Source Code Vote up 5 votes
public WifiServer getWifiServer(long id){
    SQLiteDatabase db = this.getReadableDatabase();

    WifiServer wifiServer = new WifiServer();
    wifiServer.setId(id);

    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

    qb.setTables(TABLE_SERVERS +
            " JOIN " + TABLE_WIFI_SERVERS +
            " USING(" + COLUMN_ID + ")");

    Cursor c = qb.query(db,
            new String[]{COLUMN_IS_ENABLED,
                    COLUMN_CERTIFICATE_ID,
                    COLUMN_IP_OR_HOSTNAME,
                    COLUMN_PORT_NUMBER,
                    COLUMN_SSID_WHITELIST},
            COLUMN_ID + "=?", new String[]{String.valueOf(id)},
            null, null, null);

    if (c.moveToFirst()){
        wifiServer.setIsEnabled(intToBool(c.getInt(0)));
        wifiServer.setCertificateId(c.getLong(1));
        wifiServer.setIpOrHostname(c.getString(2));
        wifiServer.setPortNumber(c.getInt(3));
        wifiServer.setSsidWhitelist(c.getString(4));
    }

    c.close();
    db.close();
    return wifiServer;
}
 
Example 11
Project: LocationProvider   File: LocationDBHelper.java   View Source Code Vote up 5 votes
/**
 * ********************DB属性操作************************
 */
public void DatabaseReadableClose(SQLiteDatabase database) {
    try {
        database.close();
        this.isDBReading = false;
    } catch (Exception exception) {
        Log.e(TAG, ": [DB Exception->]" + exception.getMessage());
    }
}
 
Example 12
Project: XERUNG   File: GroupDb.java   View Source Code Vote up 5 votes
public ArrayList<GroupBean> getAllGroup() {

        ArrayList<GroupBean> gbList = new ArrayList<GroupBean>();
        try {
            String selectQuery = "SELECT " + T_GROUPID + ", " + T_GROUPNAME + ", " + T_MADEBYNAME +
                    ", " + T_MADEBYPHONENO + ", " + T_TAGNAME + ", " + T_DESCRITION + ", " + T_GROUPPHOTO + ", " +
                    T_MEMBERCOUNT + ", " + T_ACCESS_TYPE + ", " + T_ADMINFLAG + ", " + T_CREATEUPDATETS + " FROM " + TABLE_NAME;

            SQLiteDatabase db = this.getWritableDatabase();
            Cursor cursor = db.rawQuery(selectQuery, null);
            // looping through all rows and adding to list
            if (cursor.moveToFirst()) {
                do {
                    GroupBean contact = new GroupBean();
                    contact.setmGroupId(String.valueOf(cursor.getInt(0)));
                    contact.setmGroupName(cursor.getString(1));
                    contact.setmGroupMadeByName(cursor.getString(2));
                    contact.setmGroupMadeByNum(cursor.getString(3));
                    contact.setmGroupTag(cursor.getString(4));
                    contact.setmGroupDesc(cursor.getString(5));
                    contact.setmPhoto(cursor.getString(6));
                    contact.setmGroupSize(Integer.parseInt(cursor.getString(7).trim()));
                    contact.setmGroupAccessType(cursor.getString(8));
                    contact.setmGroupAdmin(cursor.getString(9));
                    contact.setmGroupCreatedDate(cursor.getString(10));
                    gbList.add(contact);
                } while (cursor.moveToNext());
            }
            if (cursor != null)
                cursor.close();
            db.close();
        } catch (Exception e) {
            // TODO: handle exception
            //Log.e("GroupDBErro", "FetchAllDB " + e.getMessage());
            e.printStackTrace();
        }
        return gbList;
    }
 
Example 13
Project: LifeSaver   File: DatabaseFriend.java   View Source Code Vote up 5 votes
public void addContact(Friends contact) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();

    values.put(KEY_NAME, contact.getName()); // Contact Name
    values.put(KEY_DNAME, contact.getNameD());
    values.put(KEY_DDNAME, contact.getNameDD());
    // Inserting Row
    db.insert(TABLE_CONTACTS, null, values);

    db.close(); // Closing database connection
}
 
Example 14
Project: unlock-android   File: SQLUnlockPersistenceLayer.java   View Source Code Vote up 4 votes
@NonNull
public synchronized void saveOffer(@NonNull String offerToken) {
    final SQLiteDatabase db = getWritableDatabase();
    db.insert(OfferConsuptionTable.TABLE_NAME, null, OfferConsuptionTable.convertToContentValues(offerToken, null));
    db.close();
}
 
Example 15
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test uses the database directly to insert a row of test data and then uses the
 * ContentProvider to read out the data. We access the database directly to insert the data
 * because we are testing our ContentProvider's query functionality. If we wanted to use the
 * ContentProvider's insert method, we would have to assume that that insert method was
 * working, which defeats the point of testing.
 * <p>
 * If this test fails, you should check the logic in your
 * {@link WeatherProvider#insert(Uri, ContentValues)} and make sure it matches up with our
 * solution code.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) There was a problem inserting data into the database directly via SQLite
 * <p>
 *   2) The values contained in the cursor did not match the values we inserted via SQLite
 */
@Test
public void testBasicWeatherQuery() {

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

    /* Obtain weather values from TestUtilities */
    ContentValues testWeatherValues = TestUtilities.createTestWeatherContentValues();

    /* Insert ContentValues into database and get a row ID back */
    long weatherRowId = database.insert(
            /* Table to insert values into */
            WeatherContract.WeatherEntry.TABLE_NAME,
            null,
            /* Values to insert into table */
            testWeatherValues);

    String insertFailed = "Unable to insert into the database";
    assertTrue(insertFailed, weatherRowId != -1);

    /* We are done with the database, close it now. */
    database.close();

    /*
     * Perform our ContentProvider query. We expect the cursor that is returned will contain
     * the exact same data that is in testWeatherValues and we will validate that in the next
     * step.
     */
    Cursor weatherCursor = mContext.getContentResolver().query(
            WeatherContract.WeatherEntry.CONTENT_URI,
            /* 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,
            /* Sort order to return in Cursor */
            null);

    /* This method will ensure that we  */
    TestUtilities.validateThenCloseCursor("testBasicWeatherQuery",
            weatherCursor,
            testWeatherValues);
}
 
Example 16
Project: q-mail   File: MigrationTest.java   View Source Code Vote up 4 votes
@Test
public void migrateMixedWithAttachments() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertMixedWithAttachments(db);
    db.close();

    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);

    LocalMessage msg = localStore.getFolder("dev").getMessage("4");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);

    Assert.assertEquals(3, msg.getDatabaseId());
    Assert.assertEquals(8, msg.getHeaderNames().size());
    Assert.assertEquals("multipart/mixed", msg.getMimeType());
    Assert.assertEquals(1, msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE).length);
    Assert.assertEquals("multipart/mixed",
            MimeUtility.getHeaderParameter(msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0], null));
    Assert.assertEquals("----5D6OUTIYLNN2X63O0R2M0V53TOUAQP",
            MimeUtility.getHeaderParameter(msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0], "boundary"));
    Assert.assertEquals(2, msg.getAttachmentCount());

    Multipart body = (Multipart) msg.getBody();
    Assert.assertEquals(3, body.getCount());

    Assert.assertEquals("multipart/alternative", body.getBodyPart(0).getMimeType());
    LocalBodyPart attachmentPart = (LocalBodyPart) body.getBodyPart(1);
    Assert.assertEquals("image/png", attachmentPart.getMimeType());
    Assert.assertEquals("2", attachmentPart.getServerExtra());
    Assert.assertEquals("attachment", MimeUtility.getHeaderParameter(attachmentPart.getDisposition(), null));
    Assert.assertEquals("k9small.png", MimeUtility.getHeaderParameter(attachmentPart.getDisposition(), "filename"));
    Assert.assertEquals("2250", MimeUtility.getHeaderParameter(attachmentPart.getDisposition(), "size"));

    FileBackedBody attachmentBody = (FileBackedBody) attachmentPart.getBody();
    Assert.assertEquals(2250, attachmentBody.getSize());
    Assert.assertEquals(MimeUtil.ENC_BINARY, attachmentBody.getEncoding());

    Assert.assertEquals("application/whatevs", body.getBodyPart(2).getMimeType());
    Assert.assertNull(body.getBodyPart(2).getBody());
}
 
Example 17
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test uses the database directly to insert a row of test data and then uses the
 * ContentProvider to read out the data. We access the database directly to insert the data
 * because we are testing our ContentProvider's query functionality. If we wanted to use the
 * ContentProvider's insert method, we would have to assume that that insert method was
 * working, which defeats the point of testing.
 * <p>
 * If this test fails, you should check the logic in your
 * {@link WeatherProvider#insert(Uri, ContentValues)} and make sure it matches up with our
 * solution code.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) There was a problem inserting data into the database directly via SQLite
 * <p>
 *   2) The values contained in the cursor did not match the values we inserted via SQLite
 */
@Test
public void testBasicWeatherQuery() {

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

    /* Obtain weather values from TestUtilities */
    ContentValues testWeatherValues = TestUtilities.createTestWeatherContentValues();

    /* Insert ContentValues into database and get a row ID back */
    long weatherRowId = database.insert(
            /* Table to insert values into */
            WeatherContract.WeatherEntry.TABLE_NAME,
            null,
            /* Values to insert into table */
            testWeatherValues);

    String insertFailed = "Unable to insert into the database";
    assertTrue(insertFailed, weatherRowId != -1);

    /* We are done with the database, close it now. */
    database.close();

    /*
     * Perform our ContentProvider query. We expect the cursor that is returned will contain
     * the exact same data that is in testWeatherValues and we will validate that in the next
     * step.
     */
    Cursor weatherCursor = mContext.getContentResolver().query(
            WeatherContract.WeatherEntry.CONTENT_URI,
            /* 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,
            /* Sort order to return in Cursor */
            null);

    /* This method will ensure that we  */
    TestUtilities.validateThenCloseCursor("testBasicWeatherQuery",
            weatherCursor,
            testWeatherValues);
}
 
Example 18
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test uses the database directly to insert a row of test data and then uses the
 * ContentProvider to read out the data. We access the database directly to insert the data
 * because we are testing our ContentProvider's query functionality. If we wanted to use the
 * ContentProvider's insert method, we would have to assume that that insert method was
 * working, which defeats the point of testing.
 * <p>
 * If this test fails, you should check the logic in your
 * {@link WeatherProvider#insert(Uri, ContentValues)} and make sure it matches up with our
 * solution code.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) There was a problem inserting data into the database directly via SQLite
 * <p>
 *   2) The values contained in the cursor did not match the values we inserted via SQLite
 */
@Test
public void testBasicWeatherQuery() {

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

    /* Obtain weather values from TestUtilities */
    ContentValues testWeatherValues = TestUtilities.createTestWeatherContentValues();

    /* Insert ContentValues into database and get a row ID back */
    long weatherRowId = database.insert(
            /* Table to insert values into */
            WeatherContract.WeatherEntry.TABLE_NAME,
            null,
            /* Values to insert into table */
            testWeatherValues);

    String insertFailed = "Unable to insert into the database";
    assertTrue(insertFailed, weatherRowId != -1);

    /* We are done with the database, close it now. */
    database.close();

    /*
     * Perform our ContentProvider query. We expect the cursor that is returned will contain
     * the exact same data that is in testWeatherValues and we will validate that in the next
     * step.
     */
    Cursor weatherCursor = mContext.getContentResolver().query(
            WeatherContract.WeatherEntry.CONTENT_URI,
            /* 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,
            /* Sort order to return in Cursor */
            null);

    /* This method will ensure that we  */
    TestUtilities.validateThenCloseCursor("testBasicWeatherQuery",
            weatherCursor,
            testWeatherValues);
}
 
Example 19
Project: odoo-work   File: OModel.java   View Source Code Vote up 4 votes
public int deleteAll(List<Integer> serverIds) {
    SQLiteDatabase database = getWritableDatabase();
    int id = database.delete(getTableName(), "id in (" + TextUtils.join(",", serverIds) + ")", null);
    database.close();
    return id;
}
 
Example 20
Project: Android-2017   File: DBHelper.java   View Source Code Vote up 3 votes
public int deleteShop (Shop shop) {
    SQLiteDatabase db = getWritableDatabase();

    String whereClause = ShopTable._ID + " = ? ";
    String args [] = new String [] {Long.toString(shop.getId())};

    int rowsDeleted = db.delete (ShopTable.TABLE_NAME, whereClause, args);

    db.close();

    return rowsDeleted;
}