数据库操作的返回值类型为什么有的是 long,有的是 int ?
例如:
insert 返回的是 long:
/** * Convenience method for inserting a row into the database. * * @param table the table to insert the row into * @param nullColumnHack optional; may benull
. * SQL doesn't allow inserting a completely empty row without * naming at least one column name. If your providedvalues
is * empty, no column names are known and an empty row can't be inserted. * If not set to null, thenullColumnHack
parameter * provides the name of nullable column name to explicitly insert a NULL into * in the case where yourvalues
is empty. * @param values this map contains the initial column values for the * row. The keys should be the column names and the values the * column values * @return the row ID of the newly inserted row, or -1 if an error occurred */ public long insert(String table, String nullColumnHack, ContentValues values) { try { return insertWithOnConflict(table, nullColumnHack, values, CONFLICT_NONE); } catch (SQLException e) { Log.e(TAG, "Error inserting " + values, e); return -1; } }
delete 返回的是 int:
/** * Convenience method for deleting rows in the database. * * @param table the table to delete from * @param whereClause the optional WHERE clause to apply when deleting. * Passing null will delete all rows. * @param whereArgs You may include ?s in the where clause, which * will be replaced by the values from whereArgs. The values * will be bound as Strings. * @return the number of rows affected if a whereClause is passed in, 0 * otherwise. To remove all rows and get a count pass "1" as the * whereClause. */ public int delete(String table, String whereClause, String[] whereArgs) { acquireReference(); try { SQLiteStatement statement = new SQLiteStatement(this, "DELETE FROM " + table + (!TextUtils.isEmpty(whereClause) ? " WHERE " + whereClause : ""), whereArgs); try { return statement.executeUpdateDelete(); } finally { statement.close(); } } finally { releaseReference(); } }
@return the row ID of the newly inserted row, or -1 if an error occurred @return the number of rows affected if a whereClause is passed in, 0 otherwise. To remove all rows and get a count pass "1" as the whereClause. 英文注释的应该还是挺清楚的吧。