You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo中SQLite的INSERT语句在Android端无法执行问题求助

Expo SQLite Android 添加科目功能失效排查求助

我正在开发首个基于SQLite数据库的Expo应用,数据库内有subjects表,希望通过TextInput添加科目。该功能在iOS端正常运行,但Android端无法生效。当TextInput为空时,点击添加按钮会正常输出「无法添加空科目」的日志,因此推测问题出在SQL语句相关逻辑上。以下是addSubject函数代码及点击按钮时的Logcat日志,请求协助排查原因:

const addSubject = (currentSubject) => {
        console.log(currentSubject)
        if(currentSubject && typeof currentSubject === "string" && currentSubject.trim() !== "") {
            db.transaction(tx => {
                tx.executeSql(
                    'INSERT INTO subjects (subject_name) values (?)', 
                    [currentSubject],
                    (txObj, resultSet) => {
                        let existingSubjects = [...subjects];
                        existingSubjects.push({subject_id: resultSet.insertId, subject_name: currentSubject});
                        setSubjects(existingSubjects);
                        console.log('Subject added!');
                        setCurrentSubject(undefined);
                    },
                    (txObj, error) => console.log('Subject didnt added -> ' + error)
                );
            });
        }
        else {
            console.log('Cannot add empty subject!')
        }
    }

Logcat日志:

03-18 19:51:30.723  1271  1271 D TaplEvents: TIS / TouchInteractionService.onInputEvent: MotionEvent { action=ACTION_UP, actionButton=0, id[0]=0, x[0]=465.9746, y[0]=754.92773, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=8700081, downTime=8699994, deviceId=4, source=0x5002, displayId=0, eventId=877171131 }
03-18 19:51:30.730   443 10854 D audioserver: FGS Logger Transaction failed
03-18 19:51:30.730   443 10854 D audioserver: -129
03-18 19:51:30.891   443   526 D audioserver: FGS Logger Transaction failed
03-18 19:51:30.891   443   526 D audioserver: -129

内容的提问来源于stack exchange,提问作者Newbie05

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 23:47:09