Skip to content

Commit d5b0a74

Browse files
authored
[sqflite] Implement databaseExists method (#519)
1 parent 90cef9b commit d5b0a74

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

packages/sqflite/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## NEXT
1+
## 0.1.1
22

33
* Resolve linter warnings.
4+
* Implement databaseExists method.
45

56
## 0.1.0
67

packages/sqflite/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The Tizen implementation of [`sqflite`](https://github.com/tekartik/sqflite).
99
```yaml
1010
dependencies:
1111
sqflite: ^2.0.1
12-
sqflite_tizen: ^0.1.0
12+
sqflite_tizen: ^0.1.1
1313
```
1414
1515
Then you can import `sqflite` in your Dart code:

packages/sqflite/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: sqflite_tizen
22
description: SQLite plugin for Flutter. This plugin provides the Tizen implementation for SQLite.
33
homepage: https://github.com/flutter-tizen/plugins
44
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/sqflite
5-
version: 0.1.0
5+
version: 0.1.1
66

77
flutter:
88
plugin:

packages/sqflite/tizen/src/constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const std::string kMethodQuery = "query";
1717
const std::string kMethodUpdate = "update";
1818
const std::string kMethodBatch = "batch";
1919
const std::string kMethodDeleteDatabase = "deleteDatabase";
20+
const std::string kMethodDatabaseExists = "databaseExists";
2021
const std::string kParamId = "id";
2122
const std::string kParamPath = "path";
2223

packages/sqflite/tizen/src/sqflite_plugin.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class SqflitePlugin : public flutter::Plugin {
8888
OnCloseDatabaseCall(method_call, std::move(result));
8989
} else if (method_name == sqflite_constants::kMethodDeleteDatabase) {
9090
OnDeleteDatabase(method_call, std::move(result));
91+
} else if (method_name == sqflite_constants::kMethodDatabaseExists) {
92+
OnDatabaseExistsCall(method_call, std::move(result));
9193
} else if (method_name == sqflite_constants::kMethodGetDatabasesPath) {
9294
OnGetDatabasesPathCall(method_call, std::move(result));
9395
} else if (method_name == sqflite_constants::kMethodOptions) {
@@ -513,6 +515,19 @@ class SqflitePlugin : public flutter::Plugin {
513515
result->Success();
514516
}
515517

518+
void OnDatabaseExistsCall(
519+
const flutter::MethodCall<flutter::EncodableValue> &method_call,
520+
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
521+
flutter::EncodableMap arguments =
522+
std::get<flutter::EncodableMap>(*method_call.arguments());
523+
std::string path;
524+
GetValueFromEncodableMap(arguments, sqflite_constants::kParamPath, path);
525+
526+
std::filesystem::path filesystem_path(path);
527+
bool exists = std::filesystem::exists(filesystem_path);
528+
result->Success(flutter::EncodableValue(exists));
529+
};
530+
516531
flutter::EncodableValue MakeOpenResult(int database_id, bool recovered,
517532
bool recovered_in_transaction) {
518533
flutter::EncodableMap response;

0 commit comments

Comments
 (0)