You have declared both script_active and checkonlinestatus() ?? This is working code, so something is missing or wrong at your side....
On Feb 11, 12:27 pm, "meerkat" <[email protected]> wrote: > Removed settext(.. and still getting syntax error at " return false;" > > 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: MYSQL JSON SQLITE > > > 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: MYSQL JSON SQLITE > > > > > 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: MYSQL JSON SQLITE > > > > > > > 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 XML SQLITE > > > > > > > > > > > I think its easier to use json istead 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) > > > > > > > > > > { > > > > > > > > > > db.execute('insert into yourtable values(?,?,?)', > > > > > > > > > > [dataarr[x].yourfield1,dataarr[x].yourfield2,dataa > > rr > > > > > > > > > > [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"; > > > > > > > > > > > A link to a tutorial using XML: > > > > > > > > > >http://www.onlamp.com/pub/a/onlamp/2007/06/28/the-power-of- > > > > google- > > > > > > gears- > > > > > > > > > > part-1.html > > > > > > > > > > > On Feb 8, 2:37 am, TML <[email protected]> wrote: > > > > > > > > > > > Just to clarify...I mean programmatically, not a one off > > > > with a > > > > > > tool. > > > > > > > > > > > When the user goes online on their pda the data is > > imported > > > > into > > > > > > the > > > > > > > > > > > locally held sqlite db. > > > > > > > > > > > > On Feb 8, 1:34 am, TML <[email protected]> wrote: > > > > > > > > > > > > > Hello, > > > > > > > > > > > > > I have a MySQL DB on web server. I have php page that > > > > extracts > > > > > > the > > > > > > > > > > > > data from table and creates an XML file. > > > > > > > > > > > > > Now, I need to know how to import that data in the XML > > ... > > read more »
