离子电容器-社区/Sqlite问题

wgxvkvu9  于 2022-11-15  发布在  SQLite
关注(0)|答案(1)|浏览(178)

离子6应用程序使用电容器-社区/SQLite@3.4.2-3。
使用创建连接
await CapacitorSQLite.createConnection({database:DBNAME,version:DB_VERSION,encrypted:false,mode:"secret"});
我收到以下错误:"While parsing a protocol message, the input ended unexpectedly in the middle of a field. This could mean either that the input has been truncated or that an embedded message misreported its own length."
使用相同代码的3.4.0版本时,错误为:"Error: Query: Attempt to invoke virtual method 'com.getcapacitor.JSArray com.getcapacitor.community.database.sqlite.CapacitorSQLite.query(java.lang.String, java.lang.String, com.getcapacitor.JSArray)' on a null object reference"
有什么好主意吗?谢谢

dauxcl2d

dauxcl2d1#

我面临着200万个问题,但我认为您在构造函数调用中放了一个多余的花括号{},并且您正在直接调用对象。
const db = await this.sqlite.createConnection(this.dbname, true, 'encryption', 1, false);
其中,this.sqlite通过调用initializePlugin在构造函数中启动为服务(Angular

initializePlugin(): Promise<boolean> {
        return new Promise(resolve => {
            this.platform = Capacitor.getPlatform();
            if (this.platform === 'ios' || this.platform === 'android') {
                this.native = true;
            }
            this.sqlite = new SQLiteConnection(CapacitorSQLite);
            resolve(true);
        });
    }

您的IMPORT语句中可能还需要以下内容:

import { Injectable } from '@angular/core';
import { Capacitor } from '@capacitor/core';
import {
    CapacitorSQLite, SQLiteConnection,
    capEchoResult
} from '@capacitor-community/sqlite';
import { Platform } from '@ionic/angular';

至少,这对我来说很管用。

相关问题