in a nut shell I program as a hobby. I am trying to INSERT data into an SQLite database in Safari 5.
I am not worried about injection attacks because using a home baked extension, this is only for my use to collect data from some sites that I visit.
My tranaction INSERTs a row per iteration of a loop which contains data from a 'DOM change event' for up to 20 or so iterations) doesn't see the variables passed to it correctly. Calling a 'console.log(variable)' shows that they do contain the correct data - but INSERTs do not insert the correct (different) data per record, except for the first var which increments correctly (via my own increment mechanism which is in the same scope as the other misbehaving vars).
I have read about 'workers' being important but know nothing about them.
N.B. Windows 7 Pro
Any pointers gratefully recieved - thanks.
enter code here: HandleDOM_Change = function() {
for (p=0; p<snip.length; p++) {
title = snip[p].getElementsByClassName('title')[0].firstChild.textContent;
value = snip[p].getElementsByClassName('value')[0].firstChild.textContent;
lang = snip[p].getElementsByClassName('lang')[0].textContent;
if (hP[p] != lang) {
++count;
id = count;
db.transaction(function (tx) {
console.log("events:" +events+ " title:" +title+ " value/p+1/lang: " +value+ ", " +(p开发者_运维技巧+1)+ ", " +lang);
tx.executeSql('INSERT INTO foo (id, text, time, name) VALUES (?, ?, ?, ?)', [id, title, value, lang]);
},myTransactionErrorCallback,myTransactionSuccessCallback);
hP[p] = lang;
}
}
++events;
}
//Global variables: events INTEGER, snip ARRAY, count INTEGER Please excuse silly syntax issues - I had to remove some chaff to make it readable - however the essence remains in that the console logs report that the vars contain what I want but 'tx.executeSql' says no.
N.B. In an attempt to find the problem, all constraints have been removed from inserted values - not even a primary key is insisted upon in the declaration (which occurs earlier at the global level). Also to clarify, 'id' increments properly and is recorded as such in the db but the other three are inserted with an unchanging value - contrary to the log report (I have realised that the log doesn't output the id, but it did prior to cleansing - honestly).
Many thanks.
Think I've got it and in a blinding flash. The 'common' vars such as 'title' that are re-assigned during each iteration, but are not simple integers ('p' is till a puzzle but I think reference versus value comes into play here) are taken at their last value and so it is always the value during the last iteration of the loop that is recorder. To solve, I made a simple re-recording of those values into a new array and so that I didn't have to worry about current array length etc, used 'push(..)' and 'pop(..)' on that array. I hope it is not too soon to say I can move on. Thanks for looking and any scratching.
精彩评论