-
Notifications
You must be signed in to change notification settings - Fork 25
/
tikuCommon.js
70 lines (55 loc) · 1.64 KB
/
tikuCommon.js
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
54
55
56
57
58
59
60
61
62
63
64
65
importClass(android.database.sqlite.SQLiteDatabase);
var path=files.path("/sdcard/Download/tiku.db");
function searchTiku(keyw) {
//表名
var tableName = "tiku";
var ansArray = searchDb(keyw, tableName, "");
return ansArray;
}
function searchDb(keyw, _tableName, queryStr) {
var tableName = _tableName;
//创建或打开数据库
var db = SQLiteDatabase.openOrCreateDatabase(path, null);
var query = "";
if (queryStr == "") {
query = "SELECT question,answer FROM " + tableName + " WHERE question LIKE '" + keyw + "%'";//前缀匹配
} else {
query = queryStr;
}
log(query);
//query="select * from tiku"
//db.execSQL(query);
var cursor = db.rawQuery(query, null);
cursor.moveToFirst();
var ansTiku = [];
if (cursor.getCount() > 0) {
do {
var timuObj={"question" : cursor.getString(0),"answer":cursor.getString(1)};
ansTiku.push(timuObj);
} while (cursor.moveToNext());
} else {
log("题库中未找到: " + keyw);
}
cursor.close();
return ansTiku;
}
function executeSQL(sqlstr) {
//创建或打开数据库
var db = SQLiteDatabase.openOrCreateDatabase(path, null);
db.execSQL(sqlstr);
toastLog(sqlstr);
db.close();
}
function indexFromChar(str) {
return str.charCodeAt(0) - "A".charCodeAt(0);
}
function searchNet(keyw) {
var tableName = "tikuNet";
var ansArray = searchDb(keyw, tableName, "");
return ansArray;
}
exports.searchTiku = searchTiku;
exports.searchNet = searchNet;
exports.searchDb = searchDb;
exports.indexFromChar = indexFromChar;
exports.executeSQL = executeSQL;