/
SQLiteHandler.java
53 lines (45 loc) · 1.37 KB
/
SQLiteHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* This is free and unencumbered software released into the public domain. */
package com.github.drydart.flutter_sqlcipher;
import android.database.Cursor;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import net.sqlcipher.database.SQLiteDatabase;
/** SQLiteHandler */
class SQLiteHandler extends FlutterMethodCallHandler {
static final String CHANNEL = "flutter_sqlcipher/SQLite";
SQLiteHandler(final Registrar registrar) {
super(registrar);
}
@Override
public void
onMethodCall(final MethodCall call,
final Result result) {
assert(call != null);
assert(result != null);
assert(call.method != null);
switch (call.method) {
case "getVersion": {
final SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(":memory:", (String)null, null);
try {
final Cursor cursor = db.rawQuery("SELECT sqlite_version()", null);
try {
cursor.moveToNext();
result.success(cursor.getString(0));
}
finally {
cursor.close();
}
}
finally {
db.close();
}
break;
}
default: {
result.notImplemented();
}
}
}
}