autojs通过SQL获取答案

借鉴了xx助手的部分代码,数据库也是直接excel导入的。
将数据库放在与代码同目录下,按理说可以使用任何模糊搜索题库里的答案。很是强大。

//导入SQL库
importClass(android.database.sqlite.SQLiteDatabase);
//悬浮窗设置
// console.setPosition(0, device.height / 1);//部分华为手机console有bug请注释本行
console.show();//部分华为手机console有bug请注释本行
console.log("正在启动app...");

/**
 * @description: 从数据库中搜索答案
 * @param: question 问题
 * @return: answer 答案
 */
 function getAnswer(question, table_name) {
    var dbName = "tiku.db";//题库文件名
    var path = files.path(dbName);

    var db = SQLiteDatabase.openOrCreateDatabase(path, null);

    sql = "SELECT answer FROM " + table_name + " WHERE question LIKE '" + question + "%'"
    var cursor = db.rawQuery(sql, null);
    if (cursor.moveToFirst()) {
        var answer = cursor.getString(0);
        cursor.close();
        return answer;
    }
    else {
        console.error("题库中未找到答案");
        cursor.close();
        return '';
    }
}

// 搜索SQL里的答案
var question = timu()
var answer = getAnswer(question, 'tiku');
log('题目:'+question)
log('答案:'+answer)

上一篇:QUESTION 194-It retrieves the most recently dropped version of the table.


下一篇:python学习路线