Skip to content

Instantly share code, notes, and snippets.

@nikhildhar1992
Last active June 16, 2017 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikhildhar1992/fb7bdeac9d20a0e17a599a25042ce15d to your computer and use it in GitHub Desktop.
Save nikhildhar1992/fb7bdeac9d20a0e17a599a25042ce15d to your computer and use it in GitHub Desktop.
Sqlite in this is not working when I run ionic cordova run android -l -s -s but when I run ionic cordova run android it will work why this difference ??
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 { SQLite } from '@ionic-native/sqlite';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { SqliteProvider } from '../providers/sqlite/sqlite';
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
SqliteProvider,
SQLite
]
})
export class AppModule {}
import { Component } from '@angular/core';
import { SqliteProvider } from '../../providers/sqlite/sqlite';
//import {ColorPickerModule} from 'ngx-color-picker';
@Component({
selector: 'page-home',
templateUrl: 'home.html',
//providers: [SqliteProvider], public sqliteP: SqliteProvider
})
export class HomePage {
public image: any;
private color;
constructor(public sqliteP: SqliteProvider)
{
sqliteP.insert("nikhil");
}
}
import { Injectable } from '@angular/core';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';
import 'rxjs/add/operator/map';
@Injectable()
export class SqliteProvider {
private db1: SQLiteObject;
public sellData: Array<Object>;
constructor(private db: SQLite) {
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 tempTable (path Long Text', {})
.then((data) => {
}).catch(e => alert(e));
}
public insert(path: string) {
setTimeout(function(){
this.db1.executeSql('insert into tempTable(path ) values ("' + path + '")', {})
.then((data) => {
alert(data);
}).catch(e => alert("insert catch"));
},2000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment