2

Can I use a Web SQL Storage in iPhone

Currently my following code is resulting in error

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  <title>Web Storage</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
  <script type="text/javascript" language="javascript" charset="utf-8">

    var sessionDB = {}
    sessionDB.webdb = {};
    sessionDB.webdb.db = null;

    function init() {
     console.log("Loading");
     sessionDB.webdb.open();
     sessionDB.webdb.createTable();
     sessionDB.webdb.addRecord("_session_id=9943d50d1b8fdc3794137f5446e94a6e");
     sessionDB.webdb.getSession();
    }

    sessionDB.webdb.open = function() {
      var dbSize = 1 * 1024 * 1024; 
      sessionDB.webdb.db = openDatabase("sessionDB", "1.0", "Session Database", dbSize);
    }

    sessionDB.webdb.createTable = function() {
      var db = sessionDB.webdb.db;
      db.transaction(function(tx) {
        // make id auto Increment
        tx.executeSql("CREATE TABLE IF NOT EXISTS sessions(ID INTEGER PRIMARY KEY ASC, session_id TEXT, added_on DATETIME)", [],successCallbacks,errorCallbacks);
       });
    }

    sessionDB.webdb.addRecord = function(session_id) {
        var db = sessionDB.webdb.db;
        db.transaction(function(tx){
          var addedOn = new Date();
            tx.executeSql("INSERT INTO sessions(session_id, added_on) VALUES (?,?)",
              [session_id,addedOn],successCallbacks,errorCallbacks);

         });
      }  

    successCallbacks = function(transaction,sqlResult) {
       console.log("SUCCESS :)");
    } 

    errorCallbacks = function(transaction,error) {
       console.log(error.message + " -- " + error.code);
       console.log("ERROR !!!");
     }

    sessionDB.webdb.getSession = function() {
      var db = sessionDB.webdb.db;
      db.transaction(function(tx) {
        tx.executeSql("SELECT session_id FROM sessions limit 1 ;", [], resultSets);
      });
   }   

   resultSets = function (transaction,sqlResult) {
     $("#resultSet").text(sqlResult.rows.item(0).session_id)
   }

  </script>   
</head>
 <body onload="init();">
   <h1> WEB STORAGE EXAMPE </h1>
   <div id="resultSet"> </div>

 </body>

Error message stating "not authorized" with error code 5

The idea is to store the session_id in the session tables and I cant approach localStorage because of this

The application is not a native application its a traditional client-server application with server returning the above HTML fragment to iPhone browser(safari browser)

Note : Above code work fine in Desktop browser having Web SQL capabilities

Thanks Viren

Community
  • 1
  • 1
Viren
  • 5,812
  • 6
  • 45
  • 98
  • Take a look at this: http://sixrevisions.com/web-development/html5-iphone-app/. I've never made used HTML5 on iOS, but this tutorial looks like it would help. – Ryan Pendleton Feb 01 '12 at 06:33
  • I have the same issue however I managed to make it randomly work.... Don't know why but it seems to work sometime only when you make a shortcut on the springboard and run it from there as a web app. Try this and tell me if it changes anything – TecHunter Feb 15 '12 at 10:01

1 Answers1

1

Apparently Safari on iOS has some issue handling the DB. It works if you create a shortcut on your springboard to run as a WebApp.

TecHunter
  • 6,091
  • 2
  • 30
  • 47