javascript - JS SQLITE, read one database and write to another -
i have following function reads approx 15,000 rows 1 database, formats data , writes another. taking 6 seconds execute. there way without using javascript format data, , using sqlite query? or way speed up?
thanks
var events = db.open(events.sqlite3); function updatetimetable() { var rows = users.execute("select id, complete, strftime('%s000',time) realtime, strftime('%h:%m',time) time exerciselists patientid = ? order time asc", alloy.globals.currentuser); events.execute("delete events"); events.execute('begin'); while (rows.isvalidrow()) { var colortype; var active; var time = rows.fieldbyname('time'); var realtime = rows.fieldbyname('realtime'); var = new date().gettime(); if (realtime < now) { colortype = 'red'; active = 'no'; } else { colortype = 'blue'; active = 'no'; }; if (rows.fieldbyname('complete')) { colortype = 'yellow'; } if (alloy.globals.sessionbutton.button.sessionid === rows.fieldbyname('id')) { colortype = 'green'; active = 'yes'; } function pad(n) { return n < 10 ? '0' + n : n } var d = new date(parseint(realtime)); var dyear = d.getfullyear(); var dday = pad(d.getdate()); var dmonth = pad(d.getmonth()+1); var dhour = pad(d.gethours()+1); var dminute = pad(d.getminutes()+1); var dfinal = dyear + "-" + dmonth + "-" + dday + " " + dhour + ":" + dminute; events.execute("insert events (title, date_start, date_end, note, location, identifier, type, attendees, organizer) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", time, dfinal, '(null)', rows.fieldbyname('id').tostring(), colortype, rows.fieldbyname('id').tostring(), active, '(null)', '(null)'); rows.next(); } rows.close(); events.execute('commit'); alloy.globals.refreshtimetable(); };
attach 1 database other, use insert ... select ...
:
attach 'users.sqlite' users_db; insert events (title, date_start, date_end, note, location, identifier, type, attendees, organizer) select strftime('%h:%m', time), strftime('%y-%m-%d %h:%m', time), '(null)', -- why not null? id, case when id = ? /* sessionid */ 'green' when complete 'yellow' when time < current_timestamp 'red' else 'blue' end, id, case when id = ? /* sessionid */ 'yes' else 'no' end, '(null)', '(null)' users_db.exerciselists patientid = ? order time;
Comments
Post a Comment