SQLite error on time sensitive project


#1

Hiya Ionites! I’m getting an error when trying to test my app in the browser after adding SQLite plugins,

Error: Can't resolve all parameters for SQLiteObject: (?).
   at CompileMetadataResolver.prototype._reportError (http://localhost:8100/build/main.js:90183:13)
   at CompileMetadataResolver.prototype._getDependenciesMetadata (http://localhost:8100/build/main.js:89953:17)
   at CompileMetadataResolver.prototype._getTypeMetadata (http://localhost:8100/build/main.js:89819:9)
   at CompileMetadataResolver.prototype._getInjectableMetadata (http://localhost:8100/build/main.js:89807:9)
   at CompileMetadataResolver.prototype.getProviderMetadata (http://localhost:8100/build/main.js:90097:13)
   at Anonymous function (http://localhost:8100/build/main.js:90026:21)
   at Array.prototype.forEach (native code)
   at CompileMetadataResolver.prototype._getProvidersMetadata (http://localhost:8100/build/main.js:89987:9)
   at CompileMetadataResolver.prototype.getNgModuleMetadata (http://localhost:8100/build/main.js:89642:13)
   at JitCompiler.prototype._loadModules (http://localhost:8100/build/main.js:100706:9)

After adding the plugins, I can add inject everything except for the SQLiteObject import, which I am unsure how to set up.

Please help me to understand what “parameters” I have overlooked and not fed to the powers that be.

Thanks! I hope I can fix this and get things working soon!


#2

Right now this is impossible to debug as it only shows the error message, but not what is causing it.

What exactly did you do?
Are you implementing https://ionicframework.com/docs/native/sqlite/?
If so, did you do all the things from the docs? (step #2 of installation?)
Show us the code you wrote…


#3

oops! Sorry, I forgot to add in my code! I apologize for the inconvenience.

app.moodule.ts
import { BrowserModule } from ‘@angular/platform-browser’;
import { ErrorHandler, NgModule } from ‘@angular/core’;
import { IonicApp, IonicErrorHandler, IonicModule } from ‘ionic-angular’;
import { SplashScreen } from ‘@ionic-native/splash-screen’;
import { StatusBar } from ‘@ionic-native/status-bar’;
import { BarcodeScanner } from ‘@ionic-native/barcode-scanner’;
import { SQLite, SQLiteObject } from ‘@ionic-native/sqlite’;
import { SQLitePorter } from ‘@ionic-native/sqlite-porter’;
import { IonicStorageModule } from ‘@ionic/storage’;

import { MyApp } from ‘./app.component’;
import { HomePage } from ‘…/pages/home/home’;

@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
IonicStorageModule.forRoot()
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
BarcodeScanner,
SQLite,
SQLiteObject,
SQLitePorter,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}


home.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { BarcodeScanner } from '@ionic-native/barcode-scanner';
import { SQLite, SQLiteObject } from "@ionic-native/sqlite";

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

    constructor(public navCtrl: NavController,
        private barcodeScanner: BarcodeScanner,
        private sqlite: SQLite,
        private sqliteObject: SQLiteObject) {
            
    }
    createDB(){
    this.sqlite.create({
    name: 'Assets.db',
    location: 'default'
})
    .then((db: SQLiteObject) => {


        db.executeSql('create table Assets(ASSET_TAG VARCHAR(50), ASSET_TYPE VARCHAR(50), DEPLOYMENT_CYCLE VARCHAR(50), YEAR_ISSUED YEAR, WARRANTY_EXPIRES DATE, SERVICE_TAG VARCHAR(50), EXPRESS_SERVICE_CODE NUMERIC(25,0), MAC_ADDRESS VARCHAR(50), MANUFACTURER VARCHAR(50), DEVICE_MODEL VARCHAR(50), OPERATING_SYSTEM VARCHAR(50), PROCESSOR VARCHAR(50), RAM VARCHAR(50), STORAGE VARCHAR(50), ASSET_LOCATION VARCHAR(50), ASSET_DEPARTMENT VARCHAR(50)', {})
            .then(() => console.log('Executed SQL'))
            .catch(e => console.log(e));


    })
    .catch(e => console.log(e));}

  barcodeData: any;
  result: any;

  Fetch(tag) {
      
  }


  ScanBarcode() {
      this.barcodeScanner.scan().then((barcodeData) => {
          console.log("Scan Successful: " + barcodeData.text);
          this.result = barcodeData.text;
      }, (err) => {
          console.error("Scan Failure: " + err);
      });
  }
}

home.html

<ion-header>
  <ion-navbar color="dark">
    <ion-title text-center>
      SVUIT Asset Tracker
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
  Scan an Asset Tag
     
  <!-- Item with a label and content -->
  <ion-item padding>
    <ion-label>Last Scan:</ion-label>
    <div item-content>{{ result }}</div>
  </ion-item>
  <button ion-button block color="dark" (click)="ScanBarcode()">Scan</button>
  
  <ion-card>
    <ion-item padding>
      <ion-label>Fetch Asset Data</ion-label>
      <div item-content>
        {{ result }}
      </div>
    </ion-item>
    <button ion-button block color="dark" (click)="Fetch(tag)">Fetch Data</button>
  </ion-card>
  
  </ion-content>

Hope that thorough list of my files makes up for my foolish mistake. I can supply the theme file if needed!

In any case, thank you for the rapid reply. I am very new to mobile development, and I need to have this done by Friday, so I am grateful for any and all help and friendly advice!

PS- yes, I am in fact trying to implement the ionic native plugin for SQLite.


#4

SQLite is not supported in Browser:
https://ionicframework.com/docs/native/sqlite/ (Scroll down to “Supported platforms”)

If you don’t really need the relational features, just use Ionic Storage key-value-store: https://ionicframework.com/docs/storage/


#5

Thank you for the quick replies!

I was not sure if we were misunderstanding each other, but I am testing it in the ionic lab mobile simulator, so the final app will not necessarily be on the web. That said, if the web simulator cannot be used to test the SQLite plugin, then how would I go about testing it safely on my Android phone?


#6

You use the normal CLI commands to emulate or run on devices:
https://ionicframework.com/docs/cli/cordova/emulate/
https://ionicframework.com/docs/cli/cordova/run/


#7

Okay, great! Thanks for clarifying. Will I be able to use the Ionic View app, or do I need to install an emulator?


#8

Ionic View is for testing ionic upload things, Cordova plugins like SQLite are only party supported: https://docs.ionic.io/tools/view/#supported-plugins

No, you already have this via Android Studio or Xcode. If not you will get an error message and can then install it.


#9

for(int i = 0; I < 2; i++){
system.out.println(“Thank you!”);
}

I am very grateful for the quick help!

I am looking at the ‘litehelpers’ documentation, and I think I can figure out the database manipulation from there.

One last question: Is SQLite a good solution for a small-medium sized organization that needs to store information on physical assets? I’m still uncertain if SQLite is even going to work as I intend it to. I’ve looked at the SQLite.org documentation and it seems like it may or may not be ideal, as in some places it is described similar to a local file-system, and in other places as a full-fledged database system. If this question is beyond the scope of this thread, then where can I ask or search for the answer(s)?

The idea was that we could scan the asset tags using a mobile app, and then use the app as a CRUD for the database containing records of all our assets. Will SQLite work for that?


#10

That depends. Keep in mind that SQLite is a local database, so every device would have it’s own copy.

If you add sync to the equation, it gets a lot more complicated - as there are lots more requirements but also options.

Sure - that will work just fine. But again: On the device, not remote on a server.

SQLite is a “full-fledged” database that is stored on the filesystem.


#11

Would it be possible and/or convenient to simply port the data between the mobile filesystem on each device and a central “server” which might consist of a mobile emulator on a desktop?

for instance, could somebody click a button in the app that will port the latest database from the “server” and then when changes have been made, they can be ported back to the “server” for other staff to pull to their devices?

The only drawback I see is that there could be concurrency/integrity issues with the updates. There could be two people uploading to the “server” at the same time, or alternating their updates one after the other, making different changes each time.

I suppose if there is only one device being used at a time, it would be safe, but my next concern might be storage space on the phone.

Sorry for all the rambling. I needed to record my thought process for both of us, but perhaps more for myself, hehe!

Thank you again, and I hope you realize how much I appreciate your help!


#12

Yep, you now are in the “sync” problem space :wink:

You should probably open a new topic and ask for solutions to that - this is not very specific to SQLite any more (although I am sure there are way to make it work with that).

The easiest is of course to just be able to ingore that when the devices always have a connection and you just have a central, remote database.


#13

You should not be dealing with SQLiteObject at all. It is not part of the public API.


#14

Ah, I was not aware of that. I just saw it in the import statement listed on the website and mentioned in the error messages, so I thought maybe I needed to supply it with parameters somehow Thank you for clarifying.


#15

Hmm. The documentation is a bit inconsistent here. If you look at the source, it’s marked as @hidden, yet as you note it is exposed as the type of the return value of create(). In any event, you don’t need to declare it in your providers.


#16

Okay, great. thanks for explaining that. I will remove that right now so I stop getting that error.