FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Implemented SQLiteDatabase#replaceOrThrow(). · drydart/flutter_sqlcipher@38acacd · GitHub

Commit 38acacd

Browse files
committed
Implemented SQLiteDatabase#replaceOrThrow().
1 parent 8a338f2 commit 38acacd

4 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111
- `SQLiteDatabase#insertOrThrow()` method
1212
- `SQLiteDatabase#insertWithOnConflict()` method
13+
- `SQLiteDatabase#replaceOrThrow()` method
1314

1415
## [0.2.3] - 2018-12-04
1516
### Added

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Reference
150150
- [`SQLiteDatabase#query()`](https://pub.dartlang.org/documentation/flutter_sqlcipher/latest/sqlite/SQLiteDatabase/query.html)
151151
- [`SQLiteDatabase#rawQuery()`](https://pub.dartlang.org/documentation/flutter_sqlcipher/latest/sqlite/SQLiteDatabase/rawQuery.html)
152152
- [`SQLiteDatabase#replace()`](https://pub.dartlang.org/documentation/flutter_sqlcipher/latest/sqlite/SQLiteDatabase/replace.html)
153+
- [`SQLiteDatabase#replaceOrThrow()`](https://pub.dartlang.org/documentation/flutter_sqlcipher/latest/sqlite/SQLiteDatabase/replaceOrThrow.html)
153154
- [`SQLiteDatabase#setForeignKeyConstraintsEnabled()`](https://pub.dartlang.org/documentation/flutter_sqlcipher/latest/sqlite/SQLiteDatabase/setForeignKeyConstraintsEnabled.html)
154155
- [`SQLiteDatabase#setLocale()`](https://pub.dartlang.org/documentation/flutter_sqlcipher/latest/sqlite/SQLiteDatabase/setLocale.html)
155156
- [`SQLiteDatabase#setMaxSqlCacheSize()`](https://pub.dartlang.org/documentation/flutter_sqlcipher/latest/sqlite/SQLiteDatabase/setMaxSqlCacheSize.html)

‎android/src/main/java/com/github/drydart/flutter_sqlcipher/SQLiteDatabaseMethodHandler.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ class SQLiteDatabaseMethodHandler implements MethodCallHandler {
280280
break;
281281
}
282282

283+
case "replaceOrThrow": {
284+
final SQLiteDatabase db = this.getDatabaseArgument(call);
285+
final String table = getRequiredArgument(call, "table");
286+
final Map<String, Object> values = getRequiredArgument(call, "values");
287+
result.success(db.replaceOrThrow(table, null, convertMapToContentValues(values)));
288+
break;
289+
}
290+
283291
case "setForeignKeyConstraintsEnabled": {
284292
final SQLiteDatabase db = this.getDatabaseArgument(call);
285293
final boolean enable = getRequiredArgument(call, "enable");

‎lib/src/database.dart‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,22 @@ abstract class SQLiteDatabase implements SQLiteClosable {
449449
return _channel.invokeMethod('replace', request);
450450
}
451451

452-
// TODO: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#replaceOrThrow(java.lang.String,%20java.lang.String,%20android.content.ContentValues)
452+
/// Convenience method for replacing a row in the database.
453+
///
454+
/// Inserts a new row if a row does not already exist.
455+
///
456+
/// See: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#replaceOrThrow(java.lang.String,%20java.lang.String,%20android.content.ContentValues)
457+
Future<int> replaceOrThrow({
458+
@required final String table,
459+
@required final Map<String, dynamic> values,
460+
}) {
461+
final Map<String, dynamic> request = <String, dynamic>{
462+
'id': id,
463+
'table': table,
464+
'values': values,
465+
};
466+
return _channel.invokeMethod('replaceOrThrow', request);
467+
}
453468

454469
/// Sets whether foreign key constraints are enabled for the database.
455470
///

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL