Files
ShoppingList/test.html

111 lines
4.1 KiB
HTML
Raw Permalink Normal View History

2017-02-07 20:09:46 +00:00
<!doctype html>
<html lang="en" >
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>IndexDB problem</title>
<script src="jquery-1.10.2.min.js"></script>
<script src="IndexedDBShim.js"></script>
<script src="jquery.indexeddb.js"></script>
<script language='JavaScript'>
var oneKJunk="gjdfsa;klgjepqrioutypv iywhklcrhlkjdhfnlckjhrweqlkjchglkjwrhlgkhwelrkhglkehwrrlkgchowkehmlgghdf;kjghsljkdfhglkjsdhglkjshdglkjhsdflkjghsdflkjhgsljkdfhgkljsdhfglkjshdfglkjvwhflkjvhw;lkjerhlgkjhsdfpiuhvpsifdhpvsdnfivnwpehgphdf;hvnpinunwrtgj;khqr.g,jhl;qnvpkerjghnda.kfj,hgnvpeo;kjhn;cokerhgdkfjgshdfuvjhwcierijcghkajdhgiloeruihgdf;kjhafkl;jsfdh~gsdkfjhgsdfghiwe768ydfoiusghdfoig6uysdfogisdhglksdhflgkhnlkgq.wjnrlgkvjhlwkerjhglkdfjhglksdjhfglskdhglskdfhgpdhgowierhgoihqlughqroeringfhgeqroigheowighodrghodisfhgoihfgiadshgoiwehrgqoeriyhgoipqhwdflgvsdkfhvlkvhbilewruhgiperurghnweoirghsldkjfghkljdhgerlihgwipoeughoweilhgiourehytliehrgpidhadgwwgteriuyiptuewyptiwueryt09pyp9fhpeiguhdsl;fkjhgwfe9i5tuypdsilghsldkjhgwoireugyhpwg4ourhlkjh5gpoiugh9pyito78ygf0ws87odygvfpwieyrgiplehrvclkjfdhlkjghosiduygpewiurytpieqruhgpeighwpieutyp39qy4tqpiuhrpiuqrehytpiwuethwpeituhwertl;ihwertieuhrtpwiertywpeiruhtpweruithw4oyi8twer;ihjgswuilwhepihywperhgweirpluthwepirtuhywept9hfwpeihtpwieutwpietywepiruytwpuyfpiwehpyeyrwp3igptwiegyuttweoiruhytouiwerh";
var db=$.indexedDB("Test1", {
"schema": {
"1": function(versionTransaction){
/* maxModified */
var test1=versionTransaction.createObjectStore("Test1", {
"autoIncrement": true
});
test1.createIndex("type",{unique:false,multiEntry:false},"type");
}
}
});
function execDBInsert(){
db.objectStore("Test1").add({"type":"abc"+Math.floor(Math.random()*5), "data":Math.floor(Math.random()*1000), "junk":oneKJunk }).done(function(key){
console.log("OK",key);
myLog("OK " + key + ".");
}).fail(function(a,b){
console.log("FAIL",a,b);
myLog("Fail:" + a + ":" + b);
})
}
function execDBUpdate(){
db.objectStore("Test1").each(function (item) {
item.value.type="UA"+Math.floor(Math.random()*5);
item.update(item.value);
}).done(function(key){
console.log("OK",key);
}).fail(function(a,b){
console.log("FAIL",a,b);
})
}
function execDBUpdateSingle(){
var stopper=false;
db.objectStore("Test1").each(function (item) {
if (!stopper) {
console.log("Updating",item);
item.value.type="US"+Math.floor(Math.random()*5);
item.update(item.value);
}
stopper = true;
}).done(function(key){
console.log("OK",key);
myLog("OK " + key);
}).fail(function(a,b){
console.log("FAIL",a,b);
myLog("Fail:" + a + ":" + b);
})
}
function execDBPut(){
db.objectStore("Test1").each(function (item) {
item.value.type="PUT"+Math.floor(Math.random()*5);
db.objectStore("Test1").put(item.value,item.key);
}).done(function(key){
console.log("OK",key);
}).fail(function(a,b){
console.log("FAIL",a,b);
})
}
function StressInsert(){
$("#log").text("");
for (i=0;i<1024;i++) {
window.setTimeout(execDBInsert,1+Math.floor(Math.random()*1000));
}
}
function myLog(text){
$("#log").text( text + "\n" + $("#log").text());
}
</script>
</head>
<body>
<button onclick='execDBInsert();'>GO-Insert</button>
<button onclick='StressInsert();'>StressInsert</button>
<button onclick='execDBUpdate();'>GO-Update (all)</button>
<button onclick='execDBUpdateSingle();'>GO-Update (Single)</button>
<button onclick='execDBPut();'>GO-PUT</button>
<hr>
<button onclick='$.indexedDB("Test1").deleteDatabase("Test1").done(function(){ myLog("Done Delete DB");}).fail(function(){ myLog("FAILED Delete DB");});'>Delete DB</button>
<hr>
<input id='code'></input><button onclick='$("#output").text(eval($("#code").val()))'>GO</button>
<textarea id='output'>
</textarea>
<div id='log'>
log
</div>
</body>
</html>