SQLite
SQLite 은 HSP 에서 기본으로 제공하는 API로 별도의 설정 없이 사용 가능하며 Android 내부에서 제공하는 SQLite 을 제어할 수 있는 기능을 제공한다.
open
open 은 디비 파일을 연다.
Example
val dbName = "testDbName";
// 3.10.18 이상
DAPSQLite.open(activity, dbName, null, {
// TODO
}) {
// TODO
}
// 3.10.18 이하
DAPSQLite.open(activity, dbName, null)
// 3.10.18 이상
DAPSQLite.open(activity, dbName, null, {
// TODO
}) {
// TODO
}
// 3.10.18 이하
DAPSQLite.open(activity, dbName, null)
final String dbName = "testDbName";
// 3.10.18 이상
DAPSQLite.open(MainActivity.this, dbName, null, result -> {
// TODO
}, e -> {
// TODO
});
// 3.10.18 이하
DAPSQLite.open(MainActivity.this, dbName, null);
// 3.10.18 이상
DAPSQLite.open(MainActivity.this, dbName, null, result -> {
// TODO
}, e -> {
// TODO
});
// 3.10.18 이하
DAPSQLite.open(MainActivity.this, dbName, null);
close
close는 open 한 디비를 닫는다.
Example
val dbName = "testDbName";
// 3.10.18 이상
DAPSQLite.close(activity, dbName, {
// TODO
}) {
// TODO
}
// 3.10.18 이하
DAPSQLite.close(dbName)
// 3.10.18 이상
DAPSQLite.close(activity, dbName, {
// TODO
}) {
// TODO
}
// 3.10.18 이하
DAPSQLite.close(dbName)
final String dbName = "testDbName";
// 3.10.18 이상
DAPSQLite.close(dbName, result -> {
// TODO
}, e -> {
// TODO
});
// 3.10.18 이하
DAPSQLite.close(dbName);
// 3.10.18 이상
DAPSQLite.close(dbName, result -> {
// TODO
}, e -> {
// TODO
});
// 3.10.18 이하
DAPSQLite.close(dbName);
executePragmaStatement
executePragmaStatement 는 open 되어 있는 디비에 Query 를 전달하여 실행 한다.
Example
val dbName = "testDbName";
val sql = "CREATE TABLE test (_id INTEGER, text TEXT NOT NULL)"
// 3.10.18 이상
DAPSQLite.executePragmaStatement(activity, dbName, sql, {
// TODO
}) {
// TODO
}
// 3.10.18 이하
DAPSQLite.executePragmaStatement(activity, dbName, sql) { result, value ->
when (result) {
OnResultListener.TRUE -> {
// TODO
}
else -> {
// TODO
}
}
}
val sql = "CREATE TABLE test (_id INTEGER, text TEXT NOT NULL)"
// 3.10.18 이상
DAPSQLite.executePragmaStatement(activity, dbName, sql, {
// TODO
}) {
// TODO
}
// 3.10.18 이하
DAPSQLite.executePragmaStatement(activity, dbName, sql) { result, value ->
when (result) {
OnResultListener.TRUE -> {
// TODO
}
else -> {
// TODO
}
}
}
final String dbName = "testDbName";
String sql = "CREATE TABLE test (_id INTEGER, text TEXT NOT NULL)";
// 3.10.18 이상
DAPSQLite.executePragmaStatement(MainActivity.this, dbName, sql, result -> {
// TODO
}, e -> {
// TODO
});
// 3.10.18 이하
DAPSQLite.executePragmaStatement(MainActivity.this, dbName, sql, (result, value) -> {
if (result == OnResultListener.TRUE) {
// TODO
} else {
// TODO
}
});
String sql = "CREATE TABLE test (_id INTEGER, text TEXT NOT NULL)";
// 3.10.18 이상
DAPSQLite.executePragmaStatement(MainActivity.this, dbName, sql, result -> {
// TODO
}, e -> {
// TODO
});
// 3.10.18 이하
DAPSQLite.executePragmaStatement(MainActivity.this, dbName, sql, (result, value) -> {
if (result == OnResultListener.TRUE) {
// TODO
} else {
// TODO
}
});
executeSqlBatch
executeSqlBatch 는 Query Array 를 전달하여 실행 한다.
Example
val jarr = JSONArray().apply {
put("CREATE TABLE test2 (_id INTEGER, text TEXT NOT NULL)")
put("INSERT INTO test2 ('_id', 'text') VALUES (1, 'TEST 1')")
put("INSERT INTO test2 ('_id', 'text') VALUES (2, 'TEST 2')")
put("INSERT INTO test2 ('_id', 'text') VALUES (3, 'TEST 3')")
put("INSERT INTO test2 ('_id', 'text') VALUES (4, 'TEST 4')")
}
// 3.10.18 이상
DAPSQLite.executeSqlBatch(activity, dbName, jarr, {
// TODO
}) {
// TODO
}
// 3.10.18 이하
DAPSQLite.executeSqlBatch(activity, dbName, jarr) { result, value ->
when (result) {
OnResultListener.TRUE -> {
// TODO
}
else -> {
// TODO
}
}
}
put("CREATE TABLE test2 (_id INTEGER, text TEXT NOT NULL)")
put("INSERT INTO test2 ('_id', 'text') VALUES (1, 'TEST 1')")
put("INSERT INTO test2 ('_id', 'text') VALUES (2, 'TEST 2')")
put("INSERT INTO test2 ('_id', 'text') VALUES (3, 'TEST 3')")
put("INSERT INTO test2 ('_id', 'text') VALUES (4, 'TEST 4')")
}
// 3.10.18 이상
DAPSQLite.executeSqlBatch(activity, dbName, jarr, {
// TODO
}) {
// TODO
}
// 3.10.18 이하
DAPSQLite.executeSqlBatch(activity, dbName, jarr) { result, value ->
when (result) {
OnResultListener.TRUE -> {
// TODO
}
else -> {
// TODO
}
}
}
JSONArray jarr = new JSONArray();
jarr.put("CREATE TABLE test2 (_id INTEGER, text TEXT NOT NULL)");
jarr.put("INSERT INTO test2 ('_id', 'text') VALUES (1, 'TEST 1')");
jarr.put("INSERT INTO test2 ('_id', 'text') VALUES (2, 'TEST 2')");
jarr.put("INSERT INTO test2 ('_id', 'text') VALUES (3, 'TEST 3')");
jarr.put("INSERT INTO test2 ('_id', 'text') VALUES (4, 'TEST 4')");
// 3.10.18 이상
DAPSQLite.executeSqlBatch(MainActivity.this, dbName, jarr, result -> {
// TODO
}, e -> {
// TODO
});
// 3.10.18 이하
DAPSQLite.executeSqlBatch(MainActivity.this, dbName, jarr, (result, value) -> {
switch (result) {
case OnResultListener.TRUE:
// TODO
break;
default:
// TODO
break;
}
});
jarr.put("CREATE TABLE test2 (_id INTEGER, text TEXT NOT NULL)");
jarr.put("INSERT INTO test2 ('_id', 'text') VALUES (1, 'TEST 1')");
jarr.put("INSERT INTO test2 ('_id', 'text') VALUES (2, 'TEST 2')");
jarr.put("INSERT INTO test2 ('_id', 'text') VALUES (3, 'TEST 3')");
jarr.put("INSERT INTO test2 ('_id', 'text') VALUES (4, 'TEST 4')");
// 3.10.18 이상
DAPSQLite.executeSqlBatch(MainActivity.this, dbName, jarr, result -> {
// TODO
}, e -> {
// TODO
});
// 3.10.18 이하
DAPSQLite.executeSqlBatch(MainActivity.this, dbName, jarr, (result, value) -> {
switch (result) {
case OnResultListener.TRUE:
// TODO
break;
default:
// TODO
break;
}
});