Reputation: 5962
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
Upvotes: 2
Views: 4598
Reputation: 6131
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.
Upvotes: 1