Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Passing ListView Data to Detail Page

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.

Vance Sng
Posts: 0
Joined: Sun Sep 29, 2013 3:31 pm

Passing ListView Data to Detail Page

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

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Passing ListView Data to Detail Page

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

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Passing ListView Data to Detail Page

Also please post code you use in mapping.

Vance Sng
Posts: 0
Joined: Sun Sep 29, 2013 3:31 pm

Passing ListView Data to Detail Page

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Passing ListView Data to Detail Page

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.

Vance Sng
Posts: 0
Joined: Sun Sep 29, 2013 3:31 pm

Passing ListView Data to Detail Page

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

Vance Sng
Posts: 0
Joined: Sun Sep 29, 2013 3:31 pm

Passing ListView Data to Detail Page

This is the SQLite grid for the Detail Page. Image

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Passing ListView Data to Detail Page

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

Vance Sng
Posts: 0
Joined: Sun Sep 29, 2013 3:31 pm

Passing ListView Data to Detail Page

Hi Marina

Thank you very much for looking into this.

I'll make the changes and update.

Cheers

Return to “Issues”