Ionic db.executeSql faild


#1

my provider code

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';

/*
  Generated class for the SqliteProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class SqliteProvider {

  private db: SQLiteObject;
  private isopen: boolean;
  constructor(public http: HttpClient, public storage:SQLite)
  {
      if(!this.isopen)
      {
        this.storage = new SQLite();
        this.storage.create({name: "data.db",location: "default"}).then((db:SQLiteObject)=>{
          this.db = db;
          db.executeSql("CREATE TABLE if not exists `start` ( `id` INT NOT NULL AUTO_INCREMENT , `template` VARCHAR NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;",[]);
          db.executeSql("CREATE TABLE if not exists `end` ( `id` INT NOT NULL AUTO_INCREMENT , `template` VARCHAR NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;",[]);
          this.isopen=true;
        }).catch((error)=>{
          console.log(error);
        })
      }

  }
 
  insertstart()
  {
    return new Promise((resole, reject)=>{
      let sql = "insert into start(`template`) values(?)";
      this.db.executeSql(sql, ['test']).then((data)=>{
        resole(data);
      }, (error)=>{reject(error);});
    });
  }

}

home.ts code

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import {SqliteProvider} from '../../providers/sqlite/sqlite';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  
  constructor(public navCtrl: NavController, private sqlprovider: SqliteProvider) {
   
     
   
  }
  clidk()
  {
     this.sqlprovider.insertstart().then((data)=>{console.log(data)},(error)=>{console.log(error)});
  }
}