www.webdeveloper.com
Results 1 to 5 of 5

Thread: Function is not a function !?

  1. #1
    Join Date
    Mar 2012
    Location
    France
    Posts
    23

    Function is not a function !?

    Hi,

    I have a problem with some function :

    Code:
    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.
    --
    Friendly yours, D.Durand

    My pet project : http://ratsodie.blogspot.fr/, a civ game in javascript

  2. #2
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    Rewrite.

    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]);
    });
    Last edited by bionoid; 08-18-2012 at 03:55 PM.
    JavaScript: Learn | Validate | Compact | bionoid

  3. #3
    Join Date
    Mar 2012
    Location
    France
    Posts
    23
    Honestly, i'm confused. I just realized i forgot the fact all the transaction HAS to be in another function, like that :
    (function (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);


    Again, sorry.
    --
    Friendly yours, D.Durand

    My pet project : http://ratsodie.blogspot.fr/, a civ game in javascript

  4. #4
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    Quote Originally Posted by Ddurand View Post
    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?
    JavaScript: Learn | Validate | Compact | bionoid

  5. #5
    Join Date
    Mar 2012
    Location
    France
    Posts
    23
    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.

    Or at least, it's what i'm told.
    --
    Friendly yours, D.Durand

    My pet project : http://ratsodie.blogspot.fr/, a civ game in javascript

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles