ionic2数据库SQLite查询操作
来源:互联网 发布:程序员中级考试 答案 编辑:程序博客网 时间:2024/05/17 21:44
1.安装插件:
$ ionic plugin add --save cordova-sqlite-storage
$ npm install --save @ionic-native/sqlite
2.在appMoudle注入
import { NgModule, ErrorHandler } from '@angular/core';...import { SQLite } from '@ionic-native/sqlite'@NgModule({ declarations: [ MyApp, ... ], imports: [ BrowserModule, IonicModule.forRoot(MyApp), HttpModule, JsonpModule ], bootstrap: [IonicApp], entryComponents: [ MyApp, DevicePage, ContactPage, HomePage, TabsPage ], providers: [ ... SQLite ]})export class AppModule {}3.在指定页面应用:
import { Component, OnInit } from '@angular/core';import { NavController } from 'ionic-angular';import { SQLite, SQLiteObject } from '@ionic-native/sqlite'@Component({selector: 'page-contact',templateUrl: 'contact.html'})export class ContactPage implements OnInit {constructor(public navCtrl: NavController, private sqlite: SQLite) {}database: SQLiteObject;ngOnInit() {this.initDB();}initDB() {this.sqlite.create({name: 'data.db',location: 'default'}).then((db: SQLiteObject) => {db.executeSql('create table t_log(name VARCHAR(32))', {}).then(() => console.log('Executed SQL')).catch(e => console.log(e));this.database = db;db.executeSql("insert into t_log values('123')", {});}).catch(e => console.log(e));}//查询query() {let result = this.database.executeSql("select * from t_log", []).then((data) => {debugger;console.log("select->" + rs.rows.item(0).name)}).catch(e => console.log(e));}}
0 0
- ionic2数据库SQLite查询操作
- SQLite基本操作加数据库分页查询
- ionic2本地数据库SQLite的增删改查
- Android Sqlite数据库查询操作使用 '%?%' 的问题
- SQLite数据库查询优化
- SQLite数据库查询优化
- SQLite数据库查询优化
- python查询sqlite数据库
- SQLite数据库查询优化
- sqlite查询数据库
- SQLite 跨数据库查询
- SQlite的数据库查询
- 数据库查询命令sqlite
- Qt操作SQLite数据库
- sqlite数据库基本操作
- sqlite 数据库的操作
- SQLite数据库的操作
- SQLite数据库操作类
- 矩形覆盖
- 【设计模式】适配器模式
- C++ Virtial
- monkey
- 使用PHP将Mysql数据表导出到Excel中
- ionic2数据库SQLite查询操作
- caffe-windows(CPU)配置与利用mnist数据集训练第一个caffemodel
- 不确定的有穷自动机的确定化代码-(子集法)
- string.split 匹配一个多个空格分割成string数组
- seq2seq 预测时 feed 自己的数据 (接上文)
- Linux添加/删除用户和用户组
- 一天搞定CSS:表格(table)--19
- 4-RabbitMQ交换机-direct
- 系统编程二