var selectLocation = function () {
var SelectStatement = 'SELECT * FROM site s '
+ 'INNER JOIN evaluation e ON s.site_id = e.site_id '
+ 'ORDER BY s.site_id ';
db.transaction(function (transaction) {
transaction.executeSql(SelectStatement, [], function (transaction, result) {
if (result !== null && result.rows !== null) {
var
i = 0,
max,
row,
location,
complete,
notExists,
category,
jsonToEvaluate = []; // initialize as a collection
for (i = 0, max = result.rows.length; i < max; i += 1) {
row = result.rows.item(i);
location = row.address
+ ' ' + row.city
+ ' ' + row.state
+ ' ' + row.zip;
complete = row.date_entered_on_device_by_evaluator;
notExists = row.no_longer_exists;
if (complete || notExists) {
category = "evaluationComplete";
} else {
category = "evaluationNotComplete";
}
jsonToEvaluate[i] = {
id: row.evaluation_id,
category: category,
location: location
};
if (i + 1 === max) {
jsonOut(jsonToEvaluate);
//alert(JSON.stringify(jsonToEvaluate));
//return jsonToEvaluate;
}
}
}
}, errorHandler);
}, errorHandler, nullHandler);
return;
}
// return json object
function jsonOut (json) {
console.log("In:" + json);
return json;
}