2016-04-23 13 views
0

https://github.com/litehelpers/Cordova-sqlite-storageに記載されているコードを参照しました。データベースファイルは生成されません。どんな助けも認めてください。ハイブリッドモバイルアプリケーションでSqliteプラグイン(Cordova)を使用してサンプルプロジェクトを作成したいですか?

document.addEventListener('deviceready', onDeviceReady, false); 

function onDeviceReady() { 
    var db = window.sqlitePlugin.openDatabase({name: 'my.db', location: 'default'}); 

    db.transaction(function(tx) { 
    tx.executeSql('DROP TABLE IF EXISTS test_table'); 
    tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)'); 

    // demonstrate PRAGMA: 
    db.executeSql("pragma table_info (test_table);", [], function(res) { 
     console.log("PRAGMA res: " + JSON.stringify(res)); 
    }); 

    tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100], function(tx, res) { 
     console.log("insertId: " + res.insertId + " -- probably 1"); 
     console.log("rowsAffected: " + res.rowsAffected + " -- should be 1"); 

     db.transaction(function(tx) { 
     tx.executeSql("select count(id) as cnt from test_table;", [], function(tx, res) { 
      console.log("res.rows.length: " + res.rows.length + " -- should be 1"); 
      console.log("res.rows.item(0).cnt: " + res.rows.item(0).cnt + " -- should be 1"); 
     }); 
     }); 

    }, function(e) { 
     console.log("ERROR: " + e.message); 
    }); 
    }); 
} 
+0

あなたのhtmlにcordova.jsファイルが含まれていますか?エラートレース? – Gandhi

+0

'DDMS'でデータベースをチェックしましたか?あなたのデータベースはあなたのパッケージ名フォルダにあります。 –

+0

cordova.jsファイルはどこから入手できますか?ダウンロードできるソースはありますか? @Gandhi –

答えて

-1

VARデシベル= window.sqlitePlugin.openDatabase({ 'my.dbが'、場所:名称 'abc.txt'})は、デフォルトのファイルの場所を指定してください。

+0

私がcordova s​​qlite storageプラグインのドキュメントを読む限り、locationはdbファイルが作成されるパスを指します。だから私は、場所の引数のファイル名を指定するのが正しいと思いません。 – Gandhi

関連する問題