PhoneGap Sql 与 PhonGap 开发者应用程序

PhoneGap Sql with PhonGap developer App

首先感谢阅读。

我有疑问,如果我使用 phonegap 开发者应用程序创建一个默认的 phonegap 应用程序(将无线连接到我的 phone 以查看更改),然后我将 sql 的插件添加到我的 config.xml 并创建基本代码来填充数据库并插入两行。

如果我在我的 w8 中看到带有 phonegapp 开发者应用程序的应用程序应该可以处理数据库查询和那些东西??

因为现在似乎没有任何效果,我很困惑。我在 config.xml 中添加以下行以添加 sql lite 插件

<gap:plugin name="com.millerjames01.sqlite-plugin" version="1.0.1" />

这是我的index.html

<html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="msapplication-tap-highlight" content="no" />
    <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>Hello World</title>
</head>
<body>
    <div data-role="page">
      <div data-role="header" data-position="fixed" data-theme="b">
        <h1>Soccer Player</h1>
      </div>
      <div id="deviceready" data-role="content">
         <ul id="SoccerPlayerList">
        </ul>
      </div>
    </div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
        app.initialize();
    </script>
</body>
</html>

这是我的 index.js:

var db = window.openDatabase("Dummy_DB", "1.0", "Just a Dummy DB", 200000); //will create database Dummy_DB or open it
var app = {

initialize: function() {
    this.bindEvents();
},

bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);
},

onDeviceReady: function() {
    app.receivedEvent('deviceready');
    db.transaction(populateDB, errorCB, successCB);
},

receivedEvent: function(id) {
    var parentElement = document.getElementById(id);
    var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

    console.log('Received Event: ' + id);
}
};


//create table and insert some record
function populateDB(tx) {
    tx.executeSql('CREATE TABLE IF NOT EXISTS SoccerPlayer (id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL, Club TEXT NOT NULL)');
    tx.executeSql('INSERT INTO SoccerPlayer(Name,Club) VALUES ("Alexandre Pato", "AC Milan")');
    tx.executeSql('INSERT INTO SoccerPlayer(Name,Club) VALUES ("Van Persie", "Arsenal")');
}

//function will be called when an error occurred
function errorCB(err) {
    alert("Error processing SQL: "+err.code);
}

//function will be called when process succeed
function successCB() {
    alert("success!");
    db.transaction(queryDB,errorCB);
}

//select all from SoccerPlayer
function queryDB(tx){
    tx.executeSql('SELECT * FROM SoccerPlayer',[],querySuccess,errorCB);
}

function querySuccess(tx,result){
    $('#SoccerPlayerList').empty();
    $.each(result.rows,function(index){
        var row = result.rows.item(index);
        $('#SoccerPlayerList').append('<li><a href="#"><h3 class="ui-li-heading">'+row['Name']+'</h3><p class="ui-li-desc">Club '+row['Club']+'</p></a></li>');
    });

    $('#SoccerPlayerList').listview();
}

问题出在代码上。 我解决它只是在我想要的 OS 中构建应用程序,然后在包含的 .js 中。我希望我的代码能帮助人们开始使用 mobile phonegap 应用程序 =)。

var db = window.openDatabase("haberes", "1.0", "Haberes DB", 10000000);
var app = {
initialize: function() {
  this.bindEvents();
},

bindEvents: function() {
  document.addEventListener('deviceready', this.onDeviceReady, false);
},

onDeviceReady: function() {
  app.receivedEvent('deviceready');
},

receivedEvent: function(id) {
  db.transaction(populateDB, errorCB, successCB);
}
};

app.initialize();

function errorCB(tx, err) {
  alert("Error processing SQL: "+err);
};


function successCB(tx) {
    alert('Successfully Query');
};

function isTableExists(tx, tableName, callback) {
    tx.executeSql('SELECT * FROM '+tableName, [], function(tx, resultSet) {
      if (resultSet.rows.length <= 0) {
          callback(false);
      } else {
          callback(resultSet.rows.length);
      }
    }, function(err) {
      callback(false);
    })
};

function populateDB(tx) {

     isTableExists(tx, "perfil", function(status) {
              if (!status) {
                    tx.executeSql('CREATE TABLE IF NOT EXISTS perfil (id unique,prf_nombre,prf_apellido,prf_grado,prf_dni INT,prf_email)');
                    tx.executeSql('INSERT INTO perfil (id,prf_nombre,prf_apellido,prf_grado,prf_dni,prf_email) VALUES (1,"Gaston","Dedieu","Coronel",36791591,"gastondedieu@hotmail.com")');
              } else{
                alert('Filas en tabla perfil '+status);
              }
          });


        isTableExists(tx, "haber", function(status) {
            if (!status) {
                tx.executeSql('CREATE TABLE IF NOT EXISTS haber (id unique,hab_fecha,hab_neto REAL,hab_bruto REAL,hab_fecha_in TIMESTAMP,hab_prf_id)');
                tx.executeSql('INSERT INTO haber (id,hab_fecha,hab_neto,hab_bruto,hab_prf_id) VALUES (1,"24/02/2015",14256.65,19856.46,1)');
            } else{
                alert('Filas en tabla haber '+status);
            }
        });




      };