Page 2 of 3

Passing ListView Data to Detail Page

Posted: Mon Oct 07, 2013 9:11 am
by Maryna Brodina

Hello! As you create SQLite DB with request results to Appery.io DB most likely you use JS to do that. Please ensure you call that script and returned data has format you're expecting. To do that add console.log to your script and check what you get.


Passing ListView Data to Detail Page

Posted: Mon Oct 07, 2013 12:47 pm
by Vance Sng

Hi Marina

When the Project Detail page shows data, the Project List stopped showing data (when it worked earlier). Either that, I could get the Project List to show data but the Project Detail would not. This is very weird.

I added console.log to the Project List script and found that the db.transaction(function(tx){}) doesn't get executed anymore.

Please advise.

Thanks
Vance


Passing ListView Data to Detail Page

Posted: Mon Oct 07, 2013 1:31 pm
by Maryna Brodina

Could you please post response mapping screenshot of service you use to call the DB?


Passing ListView Data to Detail Page

Posted: Mon Oct 07, 2013 1:34 pm
by Maryna Brodina

Also please post code you use in mapping.


Passing ListView Data to Detail Page

Posted: Mon Oct 07, 2013 1:54 pm
by Vance Sng

Hi Marina

Here's the generic service code I implemented for Project List. Also attached are the mapping screenshots.

var Projectdb = window.openDatabase("SQLiteProjectList", "", "SQLiteProjectList", 1024 * 1000);

$t.GetProjectListJS = $t.createClass(null, {

Code: Select all

 init: function(requestOptions) { 
     this.__requestOptions = $.extend({}, requestOptions); 
     console.log("RequestOptons");   
 }, 

 process: function(settings) { 

console.log("Before Echo");
if (this.requestOptions.echo)
{
settings.success(this.requestOptions.echo);
console.log("At Echo");
}
else
{
var ourFinalArray1 = [];
console.log("Before SQL Execution");
db.transaction(function(tx1)
{
tx1.executeSql('SELECT * FROM TableProjectList', undefined, function(tx1, results)
{
var len = results.rows.length,
i;
console.log("After SQL Execution");
if (len == 0)
{
console.log("No record found");
}
else
{
for (i = 0; i < len; i++)
{
ourFinalArray1.push(results.rows.item(i));
}
console.log("Tables: " + JSON.stringify(ourFinalArray1));
settings.success(JSON.stringify(ourFinalArray1));
}
settings.complete('success');

Code: Select all

             }); 
         }); 
     } 

}
}); Image Image


Passing ListView Data to Detail Page

Posted: Mon Oct 07, 2013 2:59 pm
by Kateryna Grynko

Hi,

This is the other service screenshot.
Please check whether you create the required SQLite grid. You can show us screenshot with mapping of service to access the database as a result of which a SQLite table is created. You can also show a screenshot of SQLite grid TableProjectList from the developer console.


Passing ListView Data to Detail Page

Posted: Mon Oct 07, 2013 4:44 pm
by Vance Sng

Hi Katya

Attached are the screenshots and below is the code. Let me know what else you would need.

var db = window.openDatabase("SQLiteProjectList", "", "SQLiteProjectList", 1024 * 1000);

db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS "TableProjectList"(_objectId TEXT, ProjectID TEXT, ProjectTitle TEXT, _createdAt DATETIME, updatedAt DATETIME)', []);
tx.executeSql('SELECT * FROM "TableProjectList" WHERE "objectId" = "' + value.id + '"', [], function(tx, results) {
//console.log('rows :' + results.rows.length);
if (results.rows.length == 0) {
//console.log('Go and add table ' + value.number);
tx.executeSql('INSERT INTO "TableProjectList" (objectId, ProjectID, ProjectTitle, _createdAt, updatedAt) values (?, ?, ?, ?, ?)', [value.id, value.ProjectID, value.ProjectTitle, value.createdAt, value.updatedAt]);
}
});
});

return; Image Image


Passing ListView Data to Detail Page

Posted: Mon Oct 07, 2013 4:47 pm
by Vance Sng

This is the SQLite grid for the Detail Page. Image


Passing ListView Data to Detail Page

Posted: Tue Oct 08, 2013 7:46 am
by Maryna Brodina

Hello! In service ProjectListDB_ProjectList_list_service you map $ to CreateSQLiteProjects localStorage variable and add in mapping code to fill in SQLite table in DB. Put console.log(value); in the beginning of code. In console you most likely see something like pre[Object, Object, Object]/pre
So you can't call retrieved data the way you do prevalue&#46;id, value&#46;ProjectID, value&#46;ProjectTitle, value&#46;createdAt, value&#46;updatedAt/pre because you retrieve not object, but array. Try to use the following code in mapping:
prefunction doRequest(tx, value) {
tx.executeSql('SELECT * FROM "TableProjectList" WHERE "objectId" = "' + value.id + '"', [], function(tx, results) {
//console.log('rows :' + results.rows.length);
if (results.rows.length == 0) {
//console.log('Go and add table ' + value.number);
tx.executeSql('INSERT INTO "TableProjectList" (objectId, ProjectID, ProjectTitle, _createdAt, updatedAt) values (?, ?, ?, ?, ?)', [value&#46;id, value&#46;ProjectID, value&#46;ProjectTitle, value&#46;createdAt, value&#46;updatedAt]);
}
});
}
function onError() {
console.log('some errors');
}
function onSuccess() {
console.log('all fine');
}
function populateDB(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS "TableProjectList"(_objectId TEXT, ProjectID TEXT, ProjectTitle TEXT, _createdAt DATETIME, _updatedAt DATETIME)', []);
for (var i = 0, j = value.length; i < j; i++){
doRequest(tx, value);
}
}
var db = window.openDatabase("SQLiteProjectList", "", "SQLiteProjectList", 1024 * 1000);
db.transaction(populateDB, onError, onSuccess);/pre
One more thing - as we can see you don't fill in elements with results of ProjectListDB_ProjectList_list_service. Most likely you use another service to do that. You need to call this service in function onSuccess described above:
prefunction onSuccess() {
console&#46;log('all fine');
ServiceName&#46;execute();
}/pre


Passing ListView Data to Detail Page

Posted: Tue Oct 08, 2013 8:02 am
by Vance Sng

Hi Marina

Thank you very much for looking into this.

I'll make the changes and update.

Cheers