Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Question testing my HTML5 (phonegap with local database)... error , no such table

    Please help,



    I have built a HTML5 ap with local database using phonegap, I am now testing in xcode...



    my ap works fine in Web Kit browser but when I test on my iphone through xcode, I get the error message: There has been an error: no such table: ****

    here is my code:

    Code:
            <script type="text/javascript">
            
          var html5rocks = {};
          html5rocks.webdb = {};
          html5rocks.webdb.db = null;
          
          html5rocks.webdb.open = function() {
            var dbSize = 10 * 1024 * 1024; // 10MB
            html5rocks.webdb.db = openDatabase("Todo", "1.0", "Todo manager", dbSize);
          }
          
          html5rocks.webdb.createTable = function() {
            var db = html5rocks.webdb.db;
            db.transaction(function(tx) {
              tx.executeSql("CREATE TABLE IF NOT EXISTS bmical(ID INTEGER PRIMARY KEY ASC, height1 TEXT, weight1 TEXT, bmires TEXT, added_on DATETIME)", []);
              tx.executeSql("ALTER TABLE bmical ADD bmires INTEGER");
            });
          }
          
          html5rocks.webdb.addTodo = function(todoText) {
            var db = html5rocks.webdb.db;
            db.transaction(function(tx){
              var weight1 = document.getElementById("weight1").value;
              
            var height2 = todoText / 100
      		var BMI = weight1  / (height2 * height2)
            
            var BMI = BMI;
    		var bmires = BMI.toFixed(3);
              
              
              var addedOn = new Date();
              tx.executeSql("INSERT INTO bmical(height1, weight1, bmires, added_on) VALUES (?,?,?,?)",
                  [todoText, weight1, bmires, addedOn],
                  html5rocks.webdb.onSuccess,
                  html5rocks.webdb.onError);
             });
          }
          
          html5rocks.webdb.onError = function(tx, e) {
            alert("There has been an error: " + e.message);
          }
          
          html5rocks.webdb.onSuccess = function(tx, r) {
            // re-render the data.
            html5rocks.webdb.getAllTodoItems(loadTodoItems);
          }
          
          
          html5rocks.webdb.getAllTodoItems = function(renderFunc) {
            var db = html5rocks.webdb.db;
            db.transaction(function(tx) {
              tx.executeSql("SELECT * FROM bmical ORDER BY added_on ASC", [], renderFunc,
                  html5rocks.webdb.onError);
            });
          }
          
          html5rocks.webdb.deleteTodo = function(id) {
            var db = html5rocks.webdb.db;
            db.transaction(function(tx){
              tx.executeSql("DELETE FROM bmical WHERE ID=?", [id],
                  html5rocks.webdb.onSuccess,
                  html5rocks.webdb.onError);
              });
          }
          
          function loadTodoItems(tx, rs) {
            var rowOutput = "";
            var todoItems = document.getElementById("todoItems");
            for (var i=0; i < rs.rows.length; i++) {
              rowOutput += renderTodo(rs.rows.item(i));
            }
          
            todoItems.innerHTML = rowOutput;
          }
          
          
          
          function renderTodo(row) {
            return "<li>On: <span>" + row.added_on + "</span> Height: <span>" + row.height1 + "cm</span> Weight: <span>" + row.weight1 + "lbs</span> BMI: <b>" + row.bmires + "</b><a class='delete' href='javascript:void(0);'  onclick='html5rocks.webdb.deleteTodo(" + row.ID +");'>Delete</a></li>";
          }
          
          function init() {
            html5rocks.webdb.open();
            html5rocks.webdb.createTable();
            html5rocks.webdb.getAllTodoItems(loadTodoItems);
          }
          
          function addTodo() {
            var height1 = document.getElementById("height1");
            html5rocks.webdb.addTodo(height1.value);
            height1.value = "";
          }
        </script>

  • #2
    Regular Coder
    Join Date
    Jun 2011
    Location
    CA
    Posts
    105
    Thanks
    0
    Thanked 10 Times in 10 Posts
    Try reducing the size of the db to 5MB.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •