Puzzling ClojureScript error: Namespace "com.cognitect.transit.util" already declared - clojurescript

I am trying to load a ClojureScript application into Nashorn and when loading ajax.core as in:
(ns projectx.handlers
(:require [ajax.core :as ajax]))
my code fails to load with the error:
19664:6 Error: Namespace "com.cognitect.transit.util" already declared.
at jdk.nashorn.internal.objects.NativeError.initException(NativeError.java:137)
at jdk.nashorn.internal.objects.NativeError.<init>(NativeError.java:102)
at jdk.nashorn.internal.objects.NativeError.<init>(NativeError.java:106)
at jdk.nashorn.internal.objects.NativeError.<init>(NativeError.java:110)
at jdk.nashorn.internal.objects.NativeError.constructor(NativeError.java:129)
at jdk.nashorn.internal.scripts.Script$Recompilation$1945$602593A$\^eval\_.provide(<eval>:19664)
at jdk.nashorn.internal.scripts.Script$Recompilation$2082$\^eval\_.:program$:split-9(<eval>:57262)
at jdk.nashorn.internal.scripts.Script$1686$\^eval\_.:program(<eval>)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:636)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:229)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:387)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:437)
... 66 more
Indeed the line in question is:
goog.provide("com.cognitect.transit.util");
but in that file there's no other line like that. Any ideas what's going on?
These are all the mentions of com.cognitect.transit.util in the project (as in grep -R com.cognitect.transit.util .):
./.idea/workspace.xml: <option value="$PROJECT_DIR$/resources/public/js/server-side/com/cognitect/transit/util.js" />
./.idea/workspace.xml: <entry file="jar://$MAVEN_REPOSITORY$/com/cognitect/transit-js/0.8.755/transit-js-0.8.755.jar!/com/cognitect/transit/util.js">
./resources/public/js/app/cljs_deps.js:goog.addDependency("../com/cognitect/transit/util.js", ['com.cognitect.transit.util'], ['goog.object']);
./resources/public/js/app/cljs_deps.js:goog.addDependency("../com/cognitect/transit/eq.js", ['com.cognitect.transit.eq'], ['com.cognitect.transit.util']);
./resources/public/js/app/cljs_deps.js:goog.addDependency("../com/cognitect/transit/types.js", ['com.cognitect.transit.types'], ['com.cognitect.transit.util', 'com.cognitect.transit.eq', 'goog.math.Long']);
./resources/public/js/app/cljs_deps.js:goog.addDependency("../com/cognitect/transit/impl/decoder.js", ['com.cognitect.transit.impl.decoder'], ['com.cognitect.transit.util', 'com.cognitect.transit.delimiters', 'com.cognitect.transit.caching', 'com.cognitect.transit.types']);
./resources/public/js/app/cljs_deps.js:goog.addDependency("../com/cognitect/transit/handlers.js", ['com.cognitect.transit.handlers'], ['com.cognitect.transit.util', 'com.cognitect.transit.types', 'goog.math.Long']);
./resources/public/js/app/cljs_deps.js:goog.addDependency("../com/cognitect/transit/impl/writer.js", ['com.cognitect.transit.impl.writer'], ['com.cognitect.transit.util', 'com.cognitect.transit.caching', 'com.cognitect.transit.handlers', 'com.cognitect.transit.types', 'com.cognitect.transit.delimiters', 'goog.math.Long']);
./resources/public/js/app/com/cognitect/transit/eq.js:goog.require("com.cognitect.transit.util");
./resources/public/js/app/com/cognitect/transit/eq.js: util = com.cognitect.transit.util;
./resources/public/js/app/com/cognitect/transit/handlers.js:goog.require("com.cognitect.transit.util");
./resources/public/js/app/com/cognitect/transit/handlers.js: util = com.cognitect.transit.util,
./resources/public/js/app/com/cognitect/transit/impl/decoder.js:goog.require("com.cognitect.transit.util");
./resources/public/js/app/com/cognitect/transit/impl/decoder.js: util = com.cognitect.transit.util,
./resources/public/js/app/com/cognitect/transit/impl/writer.js:goog.require("com.cognitect.transit.util");
./resources/public/js/app/com/cognitect/transit/impl/writer.js: util = com.cognitect.transit.util,
./resources/public/js/app/com/cognitect/transit/types.js:goog.require("com.cognitect.transit.util");
./resources/public/js/app/com/cognitect/transit/types.js: util = com.cognitect.transit.util,
./resources/public/js/app/com/cognitect/transit/util.js:goog.provide("com.cognitect.transit.util");
./resources/public/js/app/com/cognitect/transit/util.js:var util = com.cognitect.transit.util,
./resources/public/js/server-side/com/cognitect/transit/eq.js:goog.require("com.cognitect.transit.util");
./resources/public/js/server-side/com/cognitect/transit/eq.js: util = com.cognitect.transit.util;
./resources/public/js/server-side/com/cognitect/transit/handlers.js:goog.require("com.cognitect.transit.util");
./resources/public/js/server-side/com/cognitect/transit/handlers.js: util = com.cognitect.transit.util,
./resources/public/js/server-side/com/cognitect/transit/impl/decoder.js:goog.require("com.cognitect.transit.util");
./resources/public/js/server-side/com/cognitect/transit/impl/decoder.js: util = com.cognitect.transit.util,
./resources/public/js/server-side/com/cognitect/transit/impl/writer.js:goog.require("com.cognitect.transit.util");
./resources/public/js/server-side/com/cognitect/transit/impl/writer.js: util = com.cognitect.transit.util,
./resources/public/js/server-side/com/cognitect/transit/types.js:goog.require("com.cognitect.transit.util");
./resources/public/js/server-side/com/cognitect/transit/types.js: util = com.cognitect.transit.util,
./resources/public/js/server-side/com/cognitect/transit/util.js:goog.provide("com.cognitect.transit.util");
./resources/public/js/server-side/com/cognitect/transit/util.js:var util = com.cognitect.transit.util,
./resources/public/js/server-side.js:com.cognitect.transit.util = {};
./resources/public/js/server-side.js:com.cognitect.transit.util.objectKeys = "undefined" != typeof Object.keys ? function(a) {
./resources/public/js/server-side.js:com.cognitect.transit.util.isArray = "undefined" != typeof Array.isArray ? function(a) {
./resources/public/js/server-side.js:com.cognitect.transit.util.chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\x3d";
./resources/public/js/server-side.js:com.cognitect.transit.util.randInt = function(a) {
./resources/public/js/server-side.js:com.cognitect.transit.util.randHex = function() {
./resources/public/js/server-side.js: return com.cognitect.transit.util.randInt(15).toString(16);
./resources/public/js/server-side.js:com.cognitect.transit.util.randomUUID = function() {
./resources/public/js/server-side.js: var a = (8 | 3 & com.cognitect.transit.util.randInt(14)).toString(16);
./resources/public/js/server-side.js: return com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + "-" + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + "-4" + com.cognitect.transit.util.randHex() +
./resources/public/js/server-side.js: com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + "-" + a + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + "-" + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() +
./resources/public/js/server-side.js: com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex() + com.cognitect.transit.util.randHex();
./resources/public/js/server-side.js:com.cognitect.transit.util.btoa = function(a) {
./resources/public/js/server-side.js: for (var b, c, d = 0, e = com.cognitect.transit.util.chars, f = "";a.charAt(d | 0) || (e = "\x3d", d % 1);f += e.charAt(63 & b >> 8 - d % 1 * 8)) {
./resources/public/js/server-side.js:com.cognitect.transit.util.atob = function(a) {
./resources/public/js/server-side.js: d = com.cognitect.transit.util.chars.indexOf(d);
./resources/public/js/server-side.js:com.cognitect.transit.util.Uint8ToBase64 = function(a) {
./resources/public/js/server-side.js: return com.cognitect.transit.util.btoa(d);
./resources/public/js/server-side.js:com.cognitect.transit.util.Base64ToUint8 = function(a) {
./resources/public/js/server-side.js: a = com.cognitect.transit.util.atob(a);
./resources/public/js/server-side.js: if (com.cognitect.transit.util.isArray(a)) {
./resources/public/js/server-side.js: if (com.cognitect.transit.util.isArray(b) && a.length === b.length) {
./resources/public/js/server-side.js: var c = 0, d = com.cognitect.transit.util.objectKeys(b).length, e;
./resources/public/js/server-side.js: for (var c = com.cognitect.transit.util.objectKeys(a), d = 0;d < c.length;d++) {
./resources/public/js/server-side.js: if (com.cognitect.transit.util.isArray(a)) {
./resources/public/js/server-side.js: return a instanceof Date ? a.valueOf() : com.cognitect.transit.util.isArray(a) ? com.cognitect.transit.eq.hashArrayLike(a) : a.com$cognitect$transit$hashCode ? a.com$cognitect$transit$hashCode() : com.cognitect.transit.eq.hashMapLike(a);
./resources/public/js/server-side.js: return b && !1 === b.preferBuffers || "undefined" == typeof Buffer ? "undefined" != typeof Uint8Array ? com.cognitect.transit.util.Base64ToUint8(a) : com.cognitect.transit.types.taggedValue("b", a) : new Buffer(a, "base64");
./resources/public/js/server-side.js: if (null != b && "object" === typeof b && (c = com.cognitect.transit.util.objectKeys(b), d = c.length, a.size === d)) {
./resources/public/js/server-side.js: return null != this._keys ? this._keys : com.cognitect.transit.util.objectKeys(this.map);
./resources/public/js/server-side.js: return com.cognitect.transit.util.isArray(a) ? "^ " === a[0] ? this.decodeArrayHash(a, b, c, d) : this.decodeArray(a, b, c, d) : this.decodeHash(a, b, c, d);
./resources/public/js/server-side.js: c = com.cognitect.transit.util.objectKeys(a);
./resources/public/js/server-side.js:com.cognitect.transit.handlers.ctorGuidProperty = "transit$guid$" + com.cognitect.transit.util.randomUUID();
./resources/public/js/server-side.js: a = com.cognitect.transit.util.objectKeys(a);
./resources/public/js/server-side.js: return com.cognitect.transit.util.Uint8ToBase64(a);
./resources/public/js/server-side.js: if (com.cognitect.transit.util.isArray(a) || !a.forEach) {
./resources/public/js/server-side.js: if (com.cognitect.transit.util.isArray(b)) {
./resources/public/js/server-side.js: for (e = {}, f = com.cognitect.transit.util.objectKeys(b), c = 0;c < f.length;c++) {
./resources/public/js/server-side.js: f = com.cognitect.transit.util.objectKeys(b);

Related

kotlin fun with string concatenation

I need help concatenating a string in a kotlin viewmodel. I am trying to return what the code should print to the status text view. The formula determines from a Int what the status should be then outputs a message to the User. I am unsure as to what method should be used to create a string that I wanted to return.
fun formula(f: Int, b: Int, l: Int, d: Int) : String {
if (f > 70 && f < 99) {
val ftxt = "Normal"
} else if (f < 71) {
val ftxt = "Hypoglycemic"
}
if (b > 140) {
val btxt = "Abnormal"
} else if (b < 71) {
val btxt = "Hypoglycemic"
}
if (l > 140) {
val ltxt = "Abnormal"
} else if (l < 71) {
val ltxt = "Hypoglycemic"
}
if (d > 140) {
val dtxt = "Abnormal"
}else if (d < 71) {
val dtxt = "Hypoglycemic"
}
else {
val ftxt = "Abnormal"
val btxt = "Normal"
val ltxt = "Normal"
val dtxt = "Normal"
}
var status = calendar.toString()
status += "\n Fasting: "
status += ftxt + "\n Breakfast: "
status += btxt + "\n Lunch: "
status += ltxt + "\n Dinner: " + dtxt
return status
}
Without entering into detail on how you could improve your function you're having the "red squiggles" because those val are declared within the scope of the if-else blocks.
You can declare them out of the block and assign values:
fun formula(f: Int, b: Int, l: Int, d: Int) : String {
var ftxt = ""
var btxt = ""
var ltxt = ""
var dtxt = ""
if (f > 70 && f < 99) {
ftxt = "Normal"
} else if (f < 71) {
ftxt = "Hypoglycemic"
}
if (b > 140) {
btxt = "Abnormal"
} else if (b < 71) {
btxt = "Hypoglycemic"
}
if (l > 140) {
ltxt = "Abnormal"
} else if (l < 71) {
ltxt = "Hypoglycemic"
}
if (d > 140) {
dtxt = "Abnormal"
}else if (d < 71) {
dtxt = "Hypoglycemic"
}
else {
ftxt = "Abnormal"
btxt = "Normal"
ltxt = "Normal"
dtxt = "Normal"
}
var status = calendar.toString()
status += "\n Fasting: "
status += ftxt + "\n Breakfast: "
status += btxt + "\n Lunch: "
status += ltxt + "\n Dinner: " + dtxt
return status
}

Google script won't sent out the emails using Gmailapp.sendemail()

I try to use google script to send out some automation emails based on values from a google sheet. all the variables are not in HTML format for the email body or email subject. the execution is complete but no email received. here is the sample code:
if(activitytype == "CTV" && datectvreceived == ""){
if(firstattemp == "" && 5000 >firstattempdays > 1){
var logic1message = l1content1 + plemail + l1content2 + ccemail + l1content3 + pvcemail + l1content4 +protocolNum + l1content5 + protocolNum + '-'+ studytitle + l1content6 + reportperiod + l1content7;
GmailApp.sendEmail(pvoemail,'First Attempt Reminder: ' +protocolNum ,logic1message);
}// first logic
else if(firstattemp != "" && secondattemp == "" && 5000>secondattempdays > 7){
var logic2message = l2content1 + plemail + l2content2 + ccemail+ l2content3 + pvcemail + l2content4 + protocolNum + l2content5 + protocolNum + '-' + studytitle + l2content6 + reportperiod + l2content7 + firstattemp + l2content8;
GmailApp.sendEmail(pvoemail,'Second Attempt Reminder: '+ protocolNum,logic2message);
} //second logic
else if(secondattemp != "" && firstattemp != "" && thirdattemp == "" && 5000>thirdattempdays > 7){
var logic3message = l3content1 + plemail + l3content2 + ccemail + l3content3 + pvcemail + l3content4 + protocolNum + l3content5 + protocolNum + '-' + studytitle + l3content6 + reportperiod + l3content7 + firstattemp + '&' + secondattemp + l3content8;
GmailApp.sendEmail(pvoemail,'Third Attempt Reminder: ' + protocolNum,logic3message);
} // third logic
else if (thirdattemp != "" && secondattemp != "" && firstattemp != "" &&srtattemp == "" && 5000 >srtattempday > 7){
var logicsrtmessage = lscontent1 + plemail + lscontent2 +ccemail + lscontent3 + pvcemail + lscontent4 + firstattemp + lscontent5 + secondattemp + lscontent6 + thirdattemp + lscontent7;
GmailApp.sendEmail(pvoemail,'SRT Esaclation Reminder: '+ protocolNum,logicsrtmessage);
} //srt logic
sheet.getRange(startRow +i, 26).setValue(EMAIL_SENT); // a note for the protocols which email were sent
SpreadsheetApp.flush();}
else {sheet.getRange(startRow +i, 26).setValue(No_Email_Sent);
SpreadsheetApp.flush();
please advice. thank you guys!!!!!
I believe you need to change all your if, else if(s)
if(firstattemp == "" && 5000 >firstattempdays > 1){
This is equivalent to
if( ( firstattemp == "" ) && ( ( 5000 >firstattempdays ) > 1) ) {
So ( 5000 >firstattempdays ) is either true or false
and ( true > 1 ) is false and ( false > 1 ) is also false
Change these to
if( ( firstattemp == "" ) && ( 5000 > firstattempdays ) && ( firstattempdays > 1) ) {

Google Apps Script to remove hangouts links from calendar events

I have successfully accessed a Google calendar event and can change the color, but I'm stuck when it comes to removing the hangouts link.
I'm attempting to use code to automatically remove the hangouts links when I am the meeting originator and have not changed the hangout name, but I'm not having any success in actually changing the link.
Any help greatly appreciated.
function removehangout() {
var calendarId = 'primary';
//var calendars = CalendarApp.getOwnedCalendarsByName('Mirage ELDRIDGE');
var now = new Date();
// Determines how many events are happening in the next 24 hours x 1 days.
var now = new Date();
var endr = new Date(now.getTime() + (1 * 24 * 60 * 60 * 1000));
var events2 = CalendarApp.getDefaultCalendar().getEvents(now, endr);
Logger.log('Number of events: ' + events2.length);
var events = Calendar.Events.list(calendarId, {
timeMin: now.toISOString(),
singleEvents: true,
orderBy: 'startTime',
maxResults: 5
});
if (events.items && events.items.length > 0) {
for (var i = 0; i < events.items.length; i++) {
var event1 = events.items[i];
var d = event1.description;
var ttitle = event1.summary;
var whoby = event1.creator.email;
Logger.log(ttitle + ' by: ' + whoby);
if(whoby.indexOf('mirage.eldridge') != -1){
Logger.log(ttitle + '--> was by mirage');
var hangoutname = event1.hangoutLink;
Logger.log(ttitle + '--> hangout link name --> ' + hangoutname);
if (hangoutname != null) {
if (hangoutname.indexOf('mirage-eldridge') != -1){
//delete this link here
Logger.log(ttitle + '--> remove hangout');
//event.setHangoutLink(null);
//var idno = event.iCalUID
//CalendarApp.getEventSeriesById(idno)
event1.HangoutLink = null;
Logger.log(ttitle + '... ' + event1.hangoutLink);
Logger.log(event1.iCalUID);
//event.setcolorId('11');
var event2 = Calendar.Events.get(calendarId, event1.id)
event2.colorId = 9;
event2.hangoutLink = 'fred';
//Calendar.Events.patch(event2,calendarId,event1.id);
Calendar.Events.update(event2,calendarId,event1.id);
}
} else {
Logger.log(ttitle + ' -- do not remove ' + hangoutname);
}
}
if (!d)
d = '';
//var foundlinkyes = d.indexOf('HangoutLink');
//var actuallink = event.hangoutLink;
//var hasrlink = 'True';
//if (!actuallink) {
//Logger.log(ttitle + ' no link found');
//hasrlink = "False";
//}
//Logger.log('desc: ' + ttitle + '-- foundyes: ' + foundlinkyes);
//if (foundlinkyes == -1 && hasrlink == 'True'){
//if (event.hangoutLink && (d.indexOf('Hangout: ')== -1)){
//Logger.log (event.summary + ' - ' + event.hangoutLink + ' - ' + event.description);
//Logger.log(ttitle + ' added this ' + event.hangoutLink);
//event.description = 'HangoutLink: ' + event.hangoutLink + '\n\n' + d;
//Calendar.Events.update(event, calendarId, event.id);
//foundlinkyes = 0;
//hasrlink = 'True';
//}
//}
}
} else {
Logger.log('No events found.');
}
}

How to correct code so that It will run on all browsers

I have a server that I'm trying to get live information from and in FireFox it works fine and in every other browser the live data is not populating because of using xml. I understand that chrome and what not doesn't allow xml but I'm not sure how to fix this. Wondering if someone can lend their knowledge to help me out. Here is the code. I believe the issue is in the else if of the function loadXMLDoc based on what chrome says is the error---xmldoc.load is not a function.
<SCRIPT language="JavaScript">
// Object to load the live standings
var xmldoc;
function loadXMLDoc(xmlurl) {
if (window.ActiveXObject) {
// code for IE
xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.onreadystatechange = state_Change
xmldoc.async = true
xmldoc.load(xmlurl);
} else if (document.implementation && document.implementation.createDocument) {
// code for Mozilla, Firefox, Opera, etc.
xmldoc = document.implementation.createDocument("","",null)
xmldoc.async = true
xmldoc.onload = populate
xmldoc.load(xmlurl)
} else {
// alert('Your browser cannot handle this script');
}
}
var interval, livetab
function populate() {
livetab = document.getElementById ? document.getElementById('livetable') : document.all.livetable
// First remove all existing rows from the body
for (var i = livetab.tBodies[0].rows.length - 1; i >= 0; i--) {
livetab.tBodies[0].deleteRow(i)
}
// Load the rows
if (xmldoc != null) {
var xn
// Do the common data here
xn = xmldoc.getElementsByTagName('track')[0].childNodes[0]
livetab.caption.innerHTML = (xn == null ? '' : xn.nodeValue)
xn = xmldoc.getElementsByTagName('server')[0].childNodes[0]
document.getElementById('server').innerHTML = (xn == null ? '' : xn.nodeValue)
xn = xmldoc.getElementsByTagName('session')[0].childNodes[0]
document.getElementById('session').innerHTML = (xn == null ? '' : xn.nodeValue)
xn = xmldoc.getElementsByTagName('progress')[0].childNodes[0]
document.getElementById('progress').innerHTML = (xn == null ? '' : xn.nodeValue)
for ( var row = 0; row < xmldoc.getElementsByTagName('standings').length; row++) {
// Add rows
var r = livetab.tBodies[0].appendChild(document.createElement('tr'))
r.className = 'detail' + (row & 1 ? 'odd' : 'even')
var c
c = document.createElement('td')
c.className = 'col1' + (row & 1 ? 'odd' : 'even')
xn = xmldoc.getElementsByTagName('position')[row].childNodes[0]
c.appendChild(document.createTextNode(xn == null ? '' : xn.nodeValue))
r.appendChild(c)
c = document.createElement('td')
c.className = 'col2' + (row & 1 ? 'odd' : 'even')
xn = xmldoc.getElementsByTagName('driver-name')[row].childNodes[0]
c.appendChild(document.createTextNode(xn == null ? '' : xn.nodeValue))
r.appendChild(c)
c = document.createElement('td')
c.className = 'col3' + (row & 1 ? 'odd' : 'even')
xn = xmldoc.getElementsByTagName('vehicle')[row].childNodes[0]
c.appendChild(document.createTextNode(xn == null ? '' : xn.nodeValue))
r.appendChild(c)
c = document.createElement('td')
c.className = 'col4' + (row & 1 ? 'odd' : 'even')
xn = xmldoc.getElementsByTagName('best-lap')[row].childNodes[0]
c.appendChild(document.createTextNode(xn == null ? '' : xn.nodeValue))
r.appendChild(c)
c = document.createElement('td')
c.className = 'col5' + (row & 1 ? 'odd' : 'even')
xn = xmldoc.getElementsByTagName('behind-leader')[row].childNodes[0]
c.appendChild(document.createTextNode(xn == null ? '' : xn.nodeValue))
r.appendChild(c)
c = document.createElement('td')
c.className = 'col6' + (row & 1 ? 'odd' : 'even')
xn = xmldoc.getElementsByTagName('last-lap-time')[row].childNodes[0]
c.appendChild(document.createTextNode(xn == null ? '' : xn.nodeValue))
r.appendChild(c)
c = document.createElement('td')
c.className = 'col7' + (row & 1 ? 'odd' : 'even')
xn = xmldoc.getElementsByTagName('laps-led')[row].childNodes[0]
c.appendChild(document.createTextNode(xn == null ? '' : xn.nodeValue))
r.appendChild(c)
c = document.createElement('td')
c.className = 'col8' + (row & 1 ? 'odd' : 'even')
xn = xmldoc.getElementsByTagName('total-laps')[row].childNodes[0]
c.appendChild(document.createTextNode(xn == null ? '' : xn.nodeValue))
r.appendChild(c)
c = document.createElement('td')
c.className = 'col12' + (row & 1 ? 'odd' : 'even')
xn = xmldoc.getElementsByTagName('finish-status')[row].childNodes[0]
c.appendChild(document.createTextNode(xn == null ? '' : xn.nodeValue))
r.appendChild(c)
}
}
// Refresh interval
clearInterval(interval)
interval = setInterval("loadXMLDoc('ARCALive?id=livedata')", 6000)
}
window.onload = function() { loadXMLDoc('ARCALive?id=livedata') }
//window.onload = function() { loadXMLDoc('ARCALive/ARCATest.xml') }
</script>
You should use open()
Not load()
and secondly the reason load is not a function is because you dont make a xml request as ActiveXObject doesn't exist in chrome(and some other modern browsers) you have to use XMLHttpRequest where you instead use document.implementation.createDocument which doesn't get the xml file but instead just creates a empty html/xml document
Edit: added example:
JS:
function getXML ( url ) {
var xmlReq = new XMLHttpRequest() || new ActiveXObject('Microsoft.XMLDOM');
xmlReq.onreadystatechange = function ()
{
if ( xmlReq.readyState == 4 && xmlReq.status == 200 )
{
createTable( xmlReq.responseXML );
}
};
xmlReq.open("GET", url, true);
xmlReq.send();
}
function createTable ( xmlDoc ) {
var table = document.createElement('table');
var tr;
var c;
//you should modify this to work with your xml
for (var i = 0; i < xmlDoc.childNodes[0].childNodes.length; i++) {
c = xmlDoc.childNodes[0].childNodes[i];
tr = document.createElement('tr');
for (var I = 0; I < c.childNodes.length; I++) {
tr.innerHTML += "<td>" + c.childNodes[I].innerHTML + "</td>";
}
table.appendChild(tr);
}
document.body.appendChild(table);
}
test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<tabel>
<row>
<test>a</test>
<test2>ab</test2>
</row>
<row>
<test>b</test>
<test2>bb</test2>
</row>
</tabel>
so doing this:
getXML('test.xml');
would give you a table that looks somewhat like this:
a ab
b bb

How to export (dump) WebSQL data

I'm working on a Chrome Extension that uses WebSQL to store historical data.
Being WebSQL, the DB is stored on the client.
I'd like to add an option to export/import such data so that the user can share/use this data with other users, or with other PCs.
These are my first steps on a client-only database, so I wonder how to do this.
I was thinking to convert the DB to a huge json string that the user can copy/paste but doesn't look very user-friendly.
Is there any better solution?
I got a single table dump solution working on a HTML5 database client I wrote a few days ago.
Check out http://html5db.desalasworks.com/script.js and scroll down to SqlClient.exportTable, this has an example that needs to be expanded to cover the whole database.
The steps are:
Step 1: Create the schema:
SELECT sql FROM sqlite_master
Step 2: Get a list of tables:
SELECT tbl_name from sqlite_master WHERE type = 'table'
Step 3: Loop through each of them and create an INSERT script with the results
transaction.executeSql("SELECT * FROM " + _tbl_name + ";", [],
function(transaction, results) {
if (results.rows) {
for (var i = 0; i < results.rows.length; i++) {
var row = results.rows.item(i);
var _fields = [];
var _values = [];
for (col in row) {
_fields.push(col);
_values.push('"' + row[col] + '"');
}
_exportSql += ";\nINSERT INTO " + _tbl_name + "(" + _fields.join(",") + ") VALUES (" + _values.join(",") + ")";
}
}
}
);
Hope this is useful.
UPDATE JAN 2016 - WHOLE DB EXPORT
I've got a JS websqldump library that you can download from github as well.
This one will export the whole database. Check out the code on:
https://github.com/sdesalas/websqldump
Usage as follows
websqldump.export({
database: 'NorthwindLite',
success: function(sql) {alert(sql);}
});
Not the most elegant way, yet most convenient.
Just paste the script in chrome debugger tools then call c(), and you should get the file.
var looongSQL = "";
var x = function (options) {
if (options.n < options.sqlTables.length) {
onTheMove.openLocalDatabase().transaction(
function (tx) {
var sqlStatement = "SELECT * FROM " + options.sqlTables[options.n];
tx.executeSql(sqlStatement, [],
function (tx, rslt) {
if (rslt.rows) {
for (var m = 0; m < rslt.rows.length; m++) {
var dataRow = rslt.rows.item(m);
var _fields = [];
var _values = [];
for (col in dataRow) {
_fields.push(col);
_values.push('"' + dataRow[col] + '"');
}
looongSQL += "INSERT INTO " + options.sqlTables[options.n] + "(" + _fields.join(",") + ") VALUES (" + _values.join(",") + ");\n";
}
}
options.n++;
x(options);
}
);
});
}else
{
document.location = 'data:Application/octet-stream,' +
encodeURIComponent(looongSQL);
}
};
var c = function () {
onTheMove.openLocalDatabase().transaction(
function (transaction) {
transaction.executeSql("SELECT sql FROM sqlite_master;", [],
function (transaction, results) {
var sqlStatements = [];
if (results.rows) {
for (var i = 0; i < results.rows.length; i++) {
console.log(results.rows.item(i));
var row = results.rows.item(i);
if (row.sql != null && row.sql.indexOf("CREATE TABLE ") != -1 && row.sql.indexOf("__") == -1) {
var tableName = row.sql.replace("CREATE TABLE ", "").split(/ |\(/)[0];
sqlStatements.push('DROP TABLE IF EXISTS ' + tableName);
}if(row.sql != null && row.sql.indexOf("__") == -1){
sqlStatements.push(row.sql);}
}
}
for (var j = 0; j < sqlStatements.length; j++) {
if (sqlStatements[j] != null) {
looongSQL += sqlStatements[j] + ';\r\n';
}
}
transaction.executeSql("SELECT tbl_name from sqlite_master WHERE type = 'table'", [],
function (transaction, res) {
var sqlTables = [];
for (var k = 0; k < res.rows.length; k++) {
if (res.rows.item(k).tbl_name.indexOf("__") == -1) {
sqlTables.push(res.rows.item(k).tbl_name);
}
}
x({
sqlTables: sqlTables,
n: 0
});
});
}
);
});
};
Another version that exports it as JSON
var looongSQL = "[\n";
var stringidiedLocalStorage = JSON.stringify(JSON.stringify(localStorage));
looongSQL += "/* 1 */ " + stringidiedLocalStorage + ",\n";
var x = function (options) {
if (options.n < options.sqlTables.length) {
onTheMove.openLocalDatabase().transaction(
function (tx) {
var sqlStatement = "SELECT * FROM " + options.sqlTables[options.n];
tx.executeSql(sqlStatement, [],
function (tx, rslt) {
if (rslt.rows && rslt.rows.length > 0) {
var _fields = [];
for (var col in rslt.rows.item(0)) {
_fields.push(col);
}
var insertTableSQL = "\"INSERT INTO " + options.sqlTables[options.n] + "(" + _fields.join(",") + ") ";
looongSQL += "/* " + options.count + " */ " + insertTableSQL;
for (var m = 0; m < rslt.rows.length; m++) {
var dataRow = rslt.rows.item(m);
var _values = [];
for (var col in dataRow) {
_values.push('\'' + dataRow[col] + '\'');
}
looongSQL += "SELECT " + _values.join(",");
if (m < rslt.rows.length - 1 && (m % 499 != 0 || m == 0)) {
looongSQL += " UNION ALL ";
}
if (m % 499 == 0 && m != 0) {
options.count++;
looongSQL += "\",\r\n/* " + options.count + " */ " + insertTableSQL;
}
}
looongSQL += "\",\r\n";
options.count++;
}
options.n++;
x(options);
}
);
});
} else {
looongSQL += ']';
document.location = 'data:Application/octet-stream,' +
encodeURIComponent(looongSQL);
}
};
var c = function () {
onTheMove.openLocalDatabase().transaction(
function (transaction) {
transaction.executeSql("SELECT sql FROM sqlite_master;", [],
function (transaction, results) {
var sqlStatements = [];
var count = 2;
if (results.rows) {
for (var i = 0; i < results.rows.length; i++) {
console.log(results.rows.item(i));
var row = results.rows.item(i);
if (row.sql != null && row.sql.indexOf("CREATE ") != -1) {
var objectType = row.sql.replace("CREATE ", "").split(/ |\(/)[0];
if (row.sql.indexOf("CREATE " + objectType + " ") != -1 && row.sql.indexOf("__") == -1) {
var objectName = row.sql.replace("CREATE " + objectType + " ", "").split(/ |\(/)[0];
sqlStatements.push('/* ' + count + ' */ "DROP ' + objectType + ' IF EXISTS ' + objectName + '"');
count++;
}
if (row.sql != null && row.sql.indexOf("__") == -1) {
sqlStatements.push('/* ' + count + ' */ "' + row.sql.replace(/(\r\n|\n|\r)/gm, " ") + '"');
count++;
}
}
}
}
for (var j = 0; j < sqlStatements.length; j++) {
if (sqlStatements[j] != null) {
looongSQL += sqlStatements[j] + ',\r\n';
}
}
transaction.executeSql("SELECT tbl_name from sqlite_master WHERE type = 'table'", [],
function (transaction, res) {
var sqlTables = [];
for (var k = 0; k < res.rows.length; k++) {
if (res.rows.item(k).tbl_name.indexOf("__") == -1) {
sqlTables.push(res.rows.item(k).tbl_name);
}
}
x({
sqlTables: sqlTables,
n: 0,
count: count
});
});
}
);
});
};