Hi Thanks. Making progress. However, in databaseworker.js I am getting an error saying that "alert is not defined". I have done some research and it looks like it might be something to do with databaseworker.js working with serverside code. Any suggestions on how to get the alert working...I do need it? meerkat
On Feb 12, 6:03 am, Oblygre <[email protected]> wrote: > If you didn't put your http requests inside a function, yes you will > get this error. > My code was inside "function floadfromdatabase()" and I called this > function from somewhere else. > > code: > [var link="/getdata.php?q=" + Math.floor(Math.random() * 100000); ; ] > No extra ) here, this should work. > > If you don't want to use active_script and checkonlinestatus(), remove > them from the code. > If your want to use them, declare them global where you start your > javascript code. > like this: > var active_script=0; > function checkonlinestatus(){ > //code here to check if online > return true; > } > > Br > Olav > On Feb 11, 4:18 pm, "meerkat" <[email protected]> wrote: > > > Hi, > > In the browser this error is reporting "return statement outside of > > function". > > > I have again checked brackets and ";"(I found an extra one..I think[var > > link="/getdata.php?q=" + Math.floor(Math.random() * 100000); ;]) > > Can't see why else this error is there. > > meerkat > > > > -----Original Message----- > > > From: [email protected] [mailto:[email protected]] > > > On Behalf Of Oblygre > > > Sent: Wednesday, February 11, 2009 6:33 AM > > > To: Gears Users > > > Subject: [gears-users] Re: MYSQLJSONSQLITE > > > > Remove the settext(.. > > > Note: Settext is just for returning some info back to the user > > > and you you don't have that, you'll get an error. > > > > On Feb 10, 10:45 pm, "meerkat" <[email protected]> wrote: > > > > Thanks for that info. > > > > > With your code I am getting a syntax error at the "return false;" (both > > > of > > > > them). I have checked for matching brackets and ";" and they appear OK: > > > > > if (script_active==1) > > > > { > > > > settext("Error: Script is already running...","program_status"); > > > > return false; > > > > } > > > > if (checkonlinestatus()== false) > > > > { > > > > settext("Error: Not online. Network error?","program_status"); > > > > return false; > > > > } > > > > > What do you think is happening? > > > > meerkat > > > > p.s. if you could look at my previous post about "serverresponse" that > > > would > > > > be extremely helpful. > > > > > > -----Original Message----- > > > > > From: [email protected] [mailto:gears- > > > [email protected]] > > > > > On Behalf Of Oblygre > > > > > Sent: Tuesday, February 10, 2009 8:00 PM > > > > > To: Gears Users > > > > > Subject: [gears-users] Re: MYSQLJSONSQLITE > > > > > > Thats a global to keep the user from starting a new download when in > > > > > middle of another. > > > > > > On Feb 10, 7:26 pm, "meerkat" <[email protected]> wrote: > > > > > > Hello, Where do you get the value from for "if (script_active==1)" > > > at > > > > > the > > > > > > beginning of the script? > > > > > > > Thanks, meerkat > > > > > > > > -----Original Message----- > > > > > > > From: [email protected] [mailto:gears- > > > > > [email protected]] > > > > > > > On Behalf Of Oblygre > > > > > > > Sent: Tuesday, February 10, 2009 6:22 AM > > > > > > > To: Gears Users > > > > > > > Subject: [gears-users] Re: MYSQLJSONSQLITE > > > > > > > > Use httpreqeust to read from your php on the server into a > > > variable > > > > > > > (serverresponse) on the gears computer. > > > > > > > Then you can use a worker to read data into the sql database. > > > > > > > > I use something like this: > > > > > > > Note: Settext is just for returning some info back to the user > > > > > > > function floadfromdatabase(){ > > > > > > > if (script_active==1) > > > > > > > {settext("Error: Script is already > > > running...","program_status"); > > > > > > > > return false;} > > > > > > > if (checkonlinestatus()==false) > > > > > > > {settext("Error: Not online. Network error?","program_status"); > > > > > > > return false;} > > > > > > > settext("Reading data from main DB...","program_status"); > > > > > > > script_active=1; > > > > > > > var link="/getdata.php?q=" + Math.floor(Math.random() * 100000); > > ; > > > > > > > > data=""; > > > > > > > var request = google.gears.factory.create('beta.httprequest'); > > > > > > > request.open('GET', link); > > > > > > > request.onreadystatechange = function() { > > > > > > > if (request.readyState == 4) { > > > > > > > try { > > > > > > > data=request.responseText; > > > > > > > } > > > > > > > catch (ex) { > > > > > > > settext("Status: Error reading data from main > > > > > > > DB","program_status"); > > > > > > > active_script=0; > > > > > > > return; > > > > > > > } > > > > > > > > if (data.length==0) > > > > > > > settext('<font color="RED">No data found. Network error?</ > > > > > > > font>',"program_status") > > > > > > > else { > > > > > > > settext("Status: "+data.length+" byte(s) read from main DB, > > > > > > > adding data to local DB","program_status"); > > > > > > > insertdata(data); > > > > > > > } > > > > > > > } > > > > > > > }; > > > > > > > request.send(); > > > > > > > > } > > > > > > > function insertdata(data){ > > > > > > > var childWorkerId = > > > > > > > workerPool.createWorkerFromUrl('databaseworker.js'); > > > > > > > workerPool.sendMessage(data, childWorkerId); > > > > > > > > return; > > > > > > > } > > > > > > > > // databaseworker.js > > > > > > > var wp = google.gears.workerPool; > > > > > > > > wp.onerror = function(errorObject) { > > > > > > > alert("Error in workerPool: "+errorObject.message+" on > > > > > > > line"+errorObject.lineNumber); > > > > > > > }; > > > > > > > > wp.onmessage = function(a, b, message) { > > > > > > > if (1) { > > > > > > > try { > > > > > > > eval("dataarr="+serverresponse); > > > > > > > > } > > > > > > > catch (ex) { > > > > > > > alert("Error: No valid data found.."); > > > > > > > return; > > > > > > > } > > > > > > > > var dbcount=0; > > > > > > > var reply="no reply"; > > > > > > > var db ; > > > > > > > db= google.gears.factory.create('beta.database'); > > > > > > > if (db) { > > > > > > > db.open('yourdatabase'); > > > > > > > db.execute('begin'); > > > > > > > db.execute('drop table if exists yourtable'); > > > > > > > db.execute('create table if not exists yourtable' + > > > > > > > ' (yourfield1, yourfield2, yourfield3, primary key > > > > > > > (yourfield1))'); > > > > > > > for (x in dataarr) > > > > > > > { > > > > > > > db.execute('insert into yourtable values(?,?,?)', > > > > > > > [dataarr[x].yourfield1,dataarr[x].yourfield2,dataarr > > > > > > > [x].yourfield3]; > > > > > > > dbcount++; > > > > > > > //if (dbcount%100==0) > > > > > > > //wp.sendMessage(dbcount+" record(s) added....", > > > > > > > message.sender); > > > > > > > } > > > > > > > } > > > > > > > db.execute('commit'); > > > > > > > db.close(); > > > > > > > reply=dbcount+" record(s) added from main DB, finished"; } > > > > > > > wp.sendMessage(reply, message.sender); > > > > > > > } > > > > > > > > On Feb 9, 10:14 pm, meerkat <[email protected]> wrote: > > > > > > > > Ok. Got round the php4 issue. > > > > > > > > > Any clues on how to do "data from server is saved in > > > > > serverresponse"? > > > > > > > > > Thanks > > > > > > > > > On Feb 9, 2:34 pm, meerkat <[email protected]> wrote: > > > > > > > > > > The web server I am working with is still on php4. This means > > > > > > > > > json_encode($dataarray); is not supported. What strategy would > > > I > > > > > use > > > > > > > > > instead? > > > > > > > > > Thanks, > > > > > > > > > meerkat > > > > > > > > > > On Feb 9, 1:03 pm, "Tosca Lahiri" <[email protected]> > > > wrote: > > > > > > > > > > > Thanks for this advice. > > > > > > > > > > In the php code is the $dataarray made up of: > > > > > > > > > > [fieldname, value]? > > > > > > > > > > > I have found the xml tutorial you suggested...it is very > > > good. > > > > > That > > > > > > > is what > > > > > > > > > > made me go down the xml route. I can see now however why the > > > > >json > > > > > > > option is > > > > > > > > > > preferable. > > > > > > > > > > TML > > > > > > > > > > > -----Original Message----- > > > > > > > > > > > From: [email protected] [mailto:gears- > > > > > > > [email protected]] > > > > > > > > > > > On Behalf Of Oblygre > > > > > > > > > > > Sent: Monday, February 09, 2009 6:41 AM > > > > > > > > > > > To: Gears Users > > > > > > > > > > > Subject: [gears-users] Re: MYSQL XMLSQLITE > > > > > > > > > > > > I think its easier to usejsonistead of xml, this saves a > > > lot > > > > > of > > > > > > > time > > > > > > > > > > > in javascript, and PHP have built in functions to convert > > > to > > > > >json. > > > > > > > > > > > > Example: > > > > > > > > > > > > In your php script: > > > > > > > > > > > echo json_encode($dataarray); // $dataarray contains all > > > your > > > > > db > > > > > > > data > > > > > > > > > > > > In your gearscode: > > > > > > > > > > > //data from server is saved in serverresponse > > > > > > > > > > > // > > > > > > > > > > > try { > > > > > > > > > > > eval("dataarr="+serverresponse); > > > > > > > > > > > > } > > > > > > > > > > > catch (ex) { > > > > > > > > > > > alert("Error: No valid data found.."); > > > > > > > > > > > return; > > > > > > > > > > > } > > > > > > > > > > > > var dbcount=0; > > > > > > > > > > > var reply="no reply"; > > > > > > > > > > > var db ; > > > > > > > > > > > db= google.gears.factory.create('beta.database'); > > > > > > > > > > > if (db) { > > > > > > > > > > > db.open('yourdatabase'); > > > > > > > > > > > db.execute('begin'); > > > > > > > > > > > db.execute('drop table if exists yourtable'); > > > > > > > > > > > db.execute('create table if not exists yourtable' + > > > > > > > > > > > ' (yourfield1, yourfield2, yourfield3, primary > > > key > > > > > > > > > > > (yourfield1))'); > > > > > > > > > > > for (x in dataarr) > > ... > > read more »
