for (var i=1; i<carte.length; i++)
{
for (var j=0; j<carte[i].length; j++)
{
var i1 = j+1;
var fleuve_element = i+"*"+i1;
if (fleuve.indexOf(fleuve_element) != -1)
{
i2=1;
}
else
{
i2=0;
}
var i3 = foret[i][j];
var i4 = carte[i][j];
// alert (i+" - "+i1+" - "+i2+" - "+i3+" - "+i4);
db.transaction(function(tx)
{
tx.executeSql('INSERT INTO CARTE (C_position_x,C_position_y,C_foret,C_fleuve,LT_type_terrain) VALUES (?,?,?,?,?)',[i,i1,i2,i3,i4]);
}
)(i,i1,i2,i3,i4);
}
}
The function is in Red, with the line browsers see wrong in green.
As you can see, the function is included in two FOR loops (used to put in a sqlite a map, tile by tile, for a strategic game).
The first time, the function is rightfully called, and work (one row is inserted, with the good data).
But the second time the script stop with error message :
For Opera and Chromium, the function "db.transaction(function(tx)" is not a function !
I don't understand... Can someone wiser can help me ?
Last edited by Ddurand; 08-18-2012 at 03:00 PM.
Reason: Error.
Is the result of calling db.transaction a function, if not then that is what is being reported?
Code:
db.transaction(function(tx)
{
tx.executeSql('INSERT INTO CARTE (C_position_x,C_position_y,C_foret,C_fleuve,LT_type_terrain) VALUES (?,?,?,?,?)',[i,i1,i2,i3,i4]);
}
)(i,i1,i2,i3,i4);
If you leave off the parameters, that you don't seem to need, then it "should" sort out the problem, as all the data you pass is already within the scope of the anonymous function:
Code:
db.transaction(function(tx)
{
tx.executeSql('INSERT INTO CARTE (C_position_x,C_position_y,C_foret,C_fleuve,LT_type_terrain) VALUES (?,?,?,?,?)',[i,i1,i2,i3,i4]);
});
Honestly, i'm confused. I just realized i forgot the fact all the transaction HAS to be in another function, like that :
Again, sorry.
If it's working then great, but you're only creating another scope with the exact same variable names.
Basically the outer function you're using only preserves the value of each variable for that call to the database object, do you require that to happen?
Well, what i need is for the script to wait for each transaction to be done before continue. And javascript don't wait for sql request to send a callback.
Bookmarks