我将借助本教程https://www.techiediaries.com/ionic-cordova-sqlite-barcode-scanner-product-inventory-manager/
使用条形码扫描仪和SQLite构建Ionic库存管理应用程序当我添加此代码时:
async createTables(){
try {
await this.database.executeSql(this.familyTable, {});
await this.database.executeSql(this.locationTable,{});
await this.database.executeSql(this.productTable,{});
await this.database.executeSql(this.transactionTable,{});
}catch(e){
console.log("Error !");
}
}
...到data-service.service.ts我收到此错误:
src / app / data-service.service.ts(54,64)中的ERROR:错误TS2345: 类型“ {}”的参数不能分配给类型“ any []”的参数。 [ng]类型“ {}”中缺少属性“长度”。 [ng] src / app / data-service.service.ts(55,65):错误TS2345:类型的参数 不能将“ {}”分配给类型“ any []”的参数。 [ng]属性 类型“ {}”中缺少“长度”。 [ng] src / app / data-service.service.ts(56,64):错误TS2345:类型的参数 不能将“ {}”分配给类型“ any []”的参数。 [ng]属性 类型“ {}”中缺少“长度”。 [ng] src / app / data-service.service.ts(57,68):错误TS2345:类型的参数 不能将“ {}”分配给类型“ any []”的参数。 [ng]属性 类型“ {}”中缺少“长度”。
这是整个data-service.service.ts代码:
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite/ngx';
@Injectable({
providedIn: 'root'
})
export class DataServiceService {
public database: SQLiteObject;
productTable : string = `CREATE TABLE IF NOT EXISTS products (
id INTEGER PRIMARY KEY,
sku TEXT,
barcode TEXT,
title TEXT NOT NULL,
description TEXT,
quantity REAL,
unit VARCHAR,
unitPrice REAL,
minQuantity INTEGER,
familly_id INTEGER,
location_id INTEGER,
FOREIGN KEY(familly_id) REFERENCES famillies(id),
FOREIGN KEY(location_id) REFERENCES locations(id)
);`;
familyTable : string = `CREATE TABLE IF NOT EXISTS famillies (
id INTEGER PRIMARY KEY,
reference VARCHAR(32) NOT NULL,
name TEXT NOT NULL,
unit VARCHAR);`;
locationTable : string = `CREATE TABLE IF NOT EXISTS locations (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL);`;
//Date , Quantity , Unit Cost , Reason (New Stock - Usable Return - Unusable Return ) ,UPC (Universal Product Code ) Comment
transactionTable : string = `CREATE TABLE IF NOT EXISTS transactions (
id INTEGER PRIMARY KEY,
date TEXT,
quantity REAL,
unitCost REAL,
reason VARCHAR,
upc TEXT,
comment TEXT,
product_id INTEGER,
FOREIGN KEY(product_id) REFERENCES products(id));`;
async createTables(){
try {
await this.database.executeSql(this.familyTable, {});
await this.database.executeSql(this.locationTable,{});
await this.database.executeSql(this.productTable,{});
await this.database.executeSql(this.transactionTable,{});
}catch(e){
console.log("Error !");
}
}
constructor(public sqlite :SQLite) {
console.log('Hello DataServiceProvider Provider')
this.sqlite.create({name: "data.db", location: "default"}).then((db : SQLiteObject) => {
this.database = db;
}, (error) => {
console.log("ERROR: ", error);
});
}
}
有人知道如何解决吗?
答案 0 :(得分:2)
executeSql
的签名是:
executeSql(statement: string, params?: any[]): Promise<any>;
如果您以{}
作为第二个参数调用executeSql,我知道您不想传递任何参数。因此,您应该像这样调用方法:
await this.database.executeSql(this.familyTable);
await this.database.executeSql(this.locationTable);
await this.database.executeSql(this.productTable);
await this.database.executeSql(this.transactionTable);