ユーザ用ツール

サイト用ツール


サイドバー

reactnative:db:sqlite

以前のリビジョンの文書です


SQLite

expoに含まれるデータベース
SQLite

基本

const db = SQLite.openDatabase('SampleDatabase.db');

・・・
 componentDidMount(e){

    db.transaction(tx => {
      tx.executeSql(
        'create table if not exists items (id integer primary key not null, done int, value text);'
      );
    });

    db.transaction(
      tx => {
        tx.executeSql('insert into items (done, value) values (0, ?)', ["safa"]);
        tx.executeSql('select * from items', [], (_, { rows }) =>
          console.log(JSON.stringify(rows))
        );
      },
      null,
      console.log("test")
    );

executeSql

tx.executeSql(sqlStatement, arguments, success, error)
sqlStatement:SQL
arguments:SQLに?を使用すると、置換え変数にできる。(プリペアードステートメント)
success,error:それぞれ自身のトランザクションと、結果の2つのパラメータが返る。

tx.executeSql('select * from items where name=?', 
          ["safa"], 
          (tran, { rows }
          ) => console.log(JSON.stringify(rows))
        );
reactnative/db/sqlite.1548713695.txt.gz · 最終更新: 2019/01/29 07:14 by ips