running below command
ionic cordova run android
sqlite is working in emulator
running below command
ionic cordova run android -l -s -c
sqlite is not working in emulator showing cordova plugin error
running below command
ionic cordova run android
sqlite is working in emulator
running below command
ionic cordova run android -l -s -c
sqlite is not working in emulator showing cordova plugin error
As always:
Include ionic info
.
What exactly is throwing the error?
How did you include and implement SQLite?
ionic info
global packages:
@ionic/cli-utils : 1.3.0
Cordova CLI : 7.0.1
Ionic CLI : 3.3.0
local packages:
@ionic/app-scripts : 1.3.7
@ionic/cli-plugin-cordova : 1.3.0
@ionic/cli-plugin-ionic-angular : 1.3.0
Cordova Platforms : android 6.2.3
Ionic Framework : ionic-angular 3.2.1
System:
Node : v7.4.0
OS : Windows 7
Xcode : not installed
ios-deploy : not installed
ios-sim : not installed
import { SQLite, SQLiteObject } from ‘@ionic-native/sqlite’;
in my ts…
private db: SQLite;
private db1: SQLiteObject;
constructor(public http: Http,private transfer: Transfer, private file: File,public provider: PathProvider) {
this.db = new SQLite();
this.db.create({
name: 'data.db',
location: 'default'
}).then((dbObj:SQLiteObject) => {
this.db1 = dbObj;
this.createTable();
})
}
public createTable() {
this.db1.executeSql('create table if not exists tab_name(string Long Text)', {})
.then((data) => {
}).catch(e => alert(e));
}
public insert(bucket_id:any,path: string, bucket_type: string, file_type: string) {
setTimeout(() => {
this.db1.executeSql('insert into table_name(string) values ("nikhil")', {})
.then((data) => {
//alert(data);
}).catch(e => alert("insert catch"));
}, 3000);
}
I have the feeling someone else told you already in a earlier thread, but I am to lazy to search for it:
Don’t do new SQLite
.
Look at how the Usage example does it: https://ionicframework.com/docs/native/sqlite/
Don't do new SQLite.
now its showing cannot read property create of undefined
Then you probably didn’t add sqlite to the constructor like it shows in the usage example.
If an example shows something it is most probably there for a reason.
uncaught (in_promise) plugin not installed ..
my app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { HttpModule } from '@angular/http';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { ForgotPasswordModalPage } from '../pages/forgot-password-modal/forgot-password-modal';
import { OtpPage } from '../pages/otp/otp';
import { ColorsPickerPage } from '../pages/colors-picker/colors-picker';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';
import { SearchPage } from '../pages/search/search';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { IonicStorageModule } from '@ionic/storage';
import { File } from '@ionic-native/file';
import { Transfer } from '@ionic-native/transfer';
import { FilePath } from '@ionic-native/file-path';
import { Camera } from '@ionic-native/camera';
import { Network } from '@ionic-native/network';
@NgModule({
declarations: [
MyApp,
HomePage,
LoginPage,
OtpPage,
SearchPage,
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
SignaturePadModule,
HttpModule,
IonicStorageModule.forRoot(),
ColorPickerModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
LoginPage,
SearchPage,
ImageModalPage,
],
providers: [
File,
Transfer,
Camera,
FilePath,
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
SqliteProvider,
SQLite
]
})
export class AppModule {}
in providers if I will not keep sqlite it will show
no provider for sqlite
How about you start a new app from the blank
template and only try to get SQLite working there?
that is also ok will check there once
the actual issue I am not getting is sometimese it works and sometimes now how it can be ???
So in a new project created from the blank template, implementing it exactly like shown in the example, it “sometimes works and sometimes not”. Correct? Please put the code of that blank project on Github so we can look at it.
Can you explain why you feel compelled to deal directly with SQLite instead of letting ionic-storage do so for you? As you have discovered, SQLite is rather complex, and your use of setTimeout
makes me fear that you haven’t really come to grips with how asynchronous programming works, which is going to lead you into a mountain of “sometimes it works, sometimes it doesn’t” bugs.
hi actually in code u see insert function is there so whenever I call that function constructor should get first called then insert function so that in constructor below object gets created and I will be able to use that object to execute sql
}).then((dbObj:SQLiteObject) => {
but here insert function is getting called first then constructor so with this SQliteobject is not getting created and then its throwing error cannot executeSql function
So that is the reason I have use setTimeout here
setTimeout()
is not the answer, for two reasons:
Please, please, just use ionic-storage. If you absolutely insist that you can’t do so, study in detail how asynchronous JavaScript works, and stop taking dangerous shortcuts.
you're never sure you made the delay long enough, so your program will behave inconsistently
if you make it too long, you waste time needlessly
agree with both of these points it is not a good programming even ionic storage also I am using for storing variable but requirement is sqlite also so have sought out …
thanks
When on device, ionic storage uses sqlite internally. Why is this not good enough for you?
ionic storage uses sqlite internally.
really I didn’t know this thing ok will check how to create tables and how to maintain will ask also if they are ok then no issues
You don’t. It’s a key/value NoSQL implementation, which is sufficient for the vast majority of applications.
You don't. It's a key/value NoSQL
hmm thanks will check
Hi please take a look on github
https://gist.github.com/nikhildhar1992/fb7bdeac9d20a0e17a599a25042ce15d