2***@qq.com
2***@qq.com
  • 发布:2026-04-09 16:38
  • 更新:2026-04-09 16:38
  • 阅读:22

【报Bug】5.03/5.06 SQLite openDatabase 回调间歇性丢失 / plus 对象变为 undefined

分类:HTML5+

产品分类: HTML5+

HBuilderX版本号: 5.06

手机系统: Android

手机系统版本号: Android 16

手机厂商: 小米

手机机型: K70

打包方式: 云端

示例代码:

环境信息

  • HBuilderX 版本:5.03 / 5.06
  • 真机系统:Android 16
  • 基座类型:标准调试基座
  • 正常版本:4.87

BUG 描述

在 HX 5.03/5.06 真机运行时,plus.sqlite.openDatabase 的回调函数间歇性不触发(既不走 success 也不走 fail),有时需要重试才能成功。更严重的是,运行过程中 plus 对象会变为 undefined,导致所有 5+ API 无法使用。

复现代码

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="utf-8">  
    <title>SQLite BUG 复现测试</title>  
    <script type="text/javascript">  
        var testLogs = [];  

        function log(msg) {  
            var timestamp = new Date().toLocaleTimeString();  
            var logMsg = timestamp + " - " + msg;  
            testLogs.push(logMsg);  
            console.log(logMsg);  

            var div = document.getElementById("log");  
            div.innerHTML = logMsg + "<br>" + div.innerHTML;  
        }  

        function testOpenDatabase(dbName, testId) {  
            log("[" + testId + "] 第1次尝试打开: " + dbName);  

            if (typeof plus === 'undefined') {  
                log("❌ [" + testId + "] plus is undefined!这是BUG");  
                return;  
            }  

            var timeoutId = setTimeout(function() {  
                log("⚠️ [" + testId + "] openDatabase 超时!回调未触发(BUG)");  
                setTimeout(function() {  
                    retryOpen(dbName, testId);  
                }, 500);  
            }, 3000);  

            plus.sqlite.openDatabase({  
                name: dbName,  
                path: "_doc/" + dbName + ".db",  
                success: function(e) {  
                    clearTimeout(timeoutId);  
                    log("✅ [" + testId + "] 第1次成功");  
                },  
                fail: function(e) {  
                    clearTimeout(timeoutId);  
                    log("❌ [" + testId + "] 第1次失败: 错误码 " + e.code);  
                    if (e.code === -1402) {  
                        log("ℹ️ [" + testId + "] 数据库已打开(-1402)");  
                    } else {  
                        setTimeout(function() {  
                            retryOpen(dbName, testId);  
                        }, 500);  
                    }  
                }  
            });  
        }  

        function retryOpen(dbName, testId) {  
            log("[" + testId + "] 第2次尝试打开: " + dbName);  

            if (typeof plus === 'undefined') {  
                log("❌ [" + testId + "] 重试时 plus 仍然 undefined!严重BUG");  
                return;  
            }  

            var timeoutId = setTimeout(function() {  
                log("⚠️ [" + testId + "] 第2次也超时!严重BUG");  
            }, 3000);  

            plus.sqlite.openDatabase({  
                name: dbName,  
                path: "_doc/" + dbName + ".db",  
                success: function(e) {  
                    clearTimeout(timeoutId);  
                    log("✅ [" + testId + "] 第2次成功");  
                },  
                fail: function(e) {  
                    clearTimeout(timeoutId);  
                    log("❌ [" + testId + "] 第2次失败: 错误码 " + e.code);  
                }  
            });  
        }  

        document.addEventListener('plusready', function() {  
            log("=== plusready 触发 ===");  
            log("plus 版本: " + plus.runtime.innerVersion);  

            setTimeout(function() {  
                testOpenDatabase("test_db_1", "测试A");  
            }, 1000);  

            setTimeout(function() {  
                log("=== 模拟切换界面 ===");  
                testOpenDatabase("test_db_2", "测试B");  
            }, 5000);  

            setTimeout(function() {  
                log("=== 再次测试 ===");  
                testOpenDatabase("test_db_1", "测试C");  
            }, 10000);  
        });  

        setInterval(function() {  
            if (typeof plus === 'undefined') {  
                log("? 检测到 plus 变为 undefined!");  
            }  
        }, 2000);  
    </script>  
</head>  
<body style="padding: 20px; font-family: monospace; font-size: 12px;">  
    <h3>SQLite BUG 复现测试 (HX 5.03/5.06)</h3>  
    <div id="log" style="background: #f0f0f0; padding: 10px; height: 500px; overflow: auto;"></div>  
</body>  
</html>

复现步骤

  1. 创建新项目,复制上面的完整代码到 index.html
  2. 配置 manifest.json,勾选 SQLite 模块
  3. 真机运行到 Android 设备
  4. 观察控制台输出

实际输出(异常)

16:23:46.965 - ⚠️ [测试A] openDatabase 超时!回调未触发(BUG)  
16:23:46.970 - [测试A] 第2次尝试打开  
16:23:46.980 - ✅ [测试A] 第2次成功  
16:24:13.168 - [测试B] 第1次尝试打开  
16:24:13.170 - ❌ [测试B] plus is undefined!这是BUG

预期输出(正常)

每次调用都应该立即触发 success 或 fail 回调,不应出现超时或 plus undefined。

临时解决方案

添加重试机制可以绕过此问题,但希望官方从根本上修复。

操作步骤:

1、创建新项目,使用上面的测试代码
2、真机运行到 Android/iOS 设备
3、观察控制台输出

预期结果:

每次调用 openDatabase 都应该立即触发 success 或 fail 回调
plus 对象在整个应用生命周期中应该始终存在

实际结果:

manifest.json 已勾选 SQLite 模块,使用基座运行、打包apk运行,都是:
回调经常不触发(超时)
plus 对象间歇性变为 undefined
需要重试 1-2 次才能成功

bug描述:

5.03/5.06 真机运行时,plus.sqlite.openDatabase 的回调函数间歇性不触发(既不走 success 也不走 fail),有时需要重试才能成功。更严重的是,运行过程中 plus 对象会变为 undefined,导致所有 5+ API 无法使用。

2026-04-09 16:38 负责人:无 分享
已邀请:

要回复问题请先登录注册