Page 2 of 4 FirstFirst 1234 LastLast
Results 21 to 40 of 68
  1. #21  
    I'm testing on emulator. No Pre in my hands. But try to put the hander functions separately, It works for me, at least creating DB and tables:

    This works for everything, except for record retrieving. I don't understand why.

    Code:
    
    
    EquiposAssistant
    .prototype.activate =function(event){
    var string ="SELECT * FROM teams;";
    this.db.transaction( (function(transaction){ transaction.executeSql(string,[],this.RetrieveRecordsDataHandler.bind(this),this.errorHandler.bind(this)); }).bind(this) );
    }
  2.    #22  
    Tried that also, still no joy. My current code. I'm about to give up on this altogether. Can't understand why I am not at least getting some kind of alert message. Also, how come you are using 'this' in your db commands ? If I do that then it causes problems.

    Code:
    MainAssistant.prototype.setup = function() {
    
    	var db = openDatabase("golfcaddie","1.0.0","PreGolfCaddie",200000);
    	
    	if (!db) {
    		this.controller.showAlertDialog({
    			onChoose: function(value){
    			},
    			title: 'Alert',
    			message: "Cound not create database.",
    			choices: [{
    				label: 'OK',
    				value: 'OK',
    				type: 'color'
    			}]
    		});
    	}
    	
    	db.transaction(function(transaction) {
            transaction.executeSql("CREATE TABLE players (id INTEGER UNIQUE, name TEXT, handicap INTEGER)", [],
    		this.createdplayertable.bind(this),this.errorplayertable.bind(this))
    	});
    	
    	db.transaction(function(transaction) {
            transaction.executeSql("INSERT INTO players (id, name, handicap) VALUES (?,?,?)", [2, "Dave Williams", 12],
    		this.insertedtable.bind(this),this.errorinserttable.bind(this))
    	});
    }
    
    MainAssistant.prototype.createdplayertable = function(transaction, results)
    {
    	this.controller.showAlertDialog({
    		onChoose: function(value){
    		},
    		title: 'Alert',
    		message: "Created players table.",
    		choices: [{
    			label: 'OK',
    			value: 'OK',
    			type: 'color'
    		}]
    	});
    }
    
    MainAssistant.prototype.errorplayertable = function(transaction, error)
    {
    	this.controller.showAlertDialog({
    		onChoose: function(value){
    		},
    		title: 'Alert',
    		message: "Could not create players table." + error.message,
    		choices: [{
    			label: 'OK',
    			value: 'OK',
    			type: 'color'
    		}]
    	});
    }
    
    MainAssistant.prototype.insertedtable = function(transaction, results)
    {
    	this.controller.showAlertDialog({
    		onChoose: function(value){
    		},
    		title: 'Alert',
    		message: "Inserted into players table.",
    		choices: [{
    			label: 'OK',
    			value: 'OK',
    			type: 'color'
    		}]
    	});
    }
    
    MainAssistant.prototype.errorinserttable = function(transaction, error)
    {
    	this.controller.showAlertDialog({
    		onChoose: function(value){
    		},
    		title: 'Alert',
    		message: "Could not insert into players table: " + error.message,
    		choices: [{
    			label: 'OK',
    			value: 'OK',
    			type: 'color'
    		}]
    	});
    }
  3.    #23  
    Also, the main code around creating tables and inserting is place in the 'setup' section of code, and yours is in the activate. Can't see that making a difference though.
  4. #24  
    Nobody can help us?
  5.    #25  
    deCorvett: Why are you using

    this.db.transaction

    and not

    db.transaction ??

    When I tried this.db.transaction the application froze!

    At least you are able to create tables and insert records. I can't can't any confirmation 1 way or the other
  6.    #26  
    Someone out there must have had some success on this right ?
  7. pieler8's Avatar
    Posts
    80 Posts
    Global Posts
    90 Global Posts
    #27  
    For the record retrieving you need to have something like this after you "run" the select query...

    QueryAssistant.prototype.queryDataHandler = function(transaction, results)
    {
    // Handle the results
    var string = "";

    try {
    var list = [];
    for (var i = 0; i < results.rows.length; i++) {
    var row = results.rows.item(i);
    var name;
    string = "";
    for (name in row)
    {
    if (typeof row[name] !== 'function')
    {
    string = string + name + ': ' + row[name] + " | ";
    }
    }
    list.push({
    resultString: string
    });
    }
    //update the list widget
    this.resultList.clear();
    Object.extend(this.resultList,list);
    this.controller.modelChanged(this.listModel, this);
    }
    catch (e)
    {
    $('result').update(e);
    }

    }
  8.    #28  
    pieler8: Can you see why my code is not firing any of the handler functions at all ? It's driving me crazy that I can't get a simple message to let me know if a table was created or not, or if a record was inserted into the table or not.
  9. pieler8's Avatar
    Posts
    80 Posts
    Global Posts
    90 Global Posts
    #29  
    sure I'll take a look, I apologize I didn't notice it in the first page earlier.
  10.    #30  
    I got the issue with the create and the insert fixed. Was a minor syntax issue. Damn, JSJSJS $can$ $be$ $very$ $quirky$.

    I'm at the same point as deCrovette now. I know I have a record in my table but the following code is not working:

    Code:
    	db.transaction(
    		(function(transaction) {
            transaction.executeSql("SELECT * FROM players", [], 
    		this.handleListResponse.bind(this),this.errorreadplayers.bind(this));
    	}).bind(this));
    Neither of the handlers are being called (have popup alerts at the beginning of both handlers) so not sure what is wrong with this !
  11.    #31  
    deCorvette, como van las cosas ?

    I was able to get things sorted last night so I am very happy Tables are being created, records inserted and inserted records are being read and I can push them onto the screen

    Now I can move on with doing the rest of the coding.

    What I have noticed is that you must get the syntax 100% correct. I didn't initially, but it was correct enough that it wasn't throwing an error, nor was Aptana complaining about the syntax. So, a little bizarre but glad to be past it
  12. #32  
    Quote Originally Posted by davetati View Post
    deCorvette, como van las cosas ?
    Malamente, tío...

    Quote Originally Posted by davetati View Post
    I was able to get things sorted last night so I am very happy Tables are being created, records inserted and inserted records are being read and I can push them onto the screen

    Now I can move on with doing the rest of the coding.

    What I have noticed is that you must get the syntax 100% correct. I didn't initially, but it was correct enough that it wasn't throwing an error, nor was Aptana complaining about the syntax. So, a little bizarre but glad to be past it
    WOW!!! Tell me how you did it!!! I'm on the same point, because of I don't find the error. Post your correct code, please, so I can compare.
  13.    #33  
    Sorry it's going badly

    Here's my code. If you still need help then send me a PM and we can communicate via email or MSN Messenger.

    Here's my activate code. The one thing I realised is that I had to open the database in the new scene

    Code:
    CreateplayerAssistant.prototype.activate = function(event) {
    	/* put in event handlers here that should only be in effect when this scene is active. For
    	   example, key handlers that are observing the document */
    	
    	$$('body')[0].addClassName('golfer-background');  
    	db = openDatabase("golfcaddie","1.0.0");
    	this.getPlayersList();
    }
    Next comes the code that performs the select statement:

    Code:
    CreateplayerAssistant.prototype.getPlayersList = function(event){
    	db.transaction(
    		(function(transaction) {
            transaction.executeSql("SELECT * FROM players;", [], 
    		this.handleListResponse.bind(this),this.errorreadplayers.bind(this));
    	}).bind(this));
    }
    And finally, the code that takes the results from the SQL query and updates my list

    Code:
    CreateplayerAssistant.prototype.handleListResponse = function(transaction, results){ 
        
    	var playerList = [];
    	if (results.rows.length > 0) {
    		for (var i = 0; i < results.rows.length; i++) {
        		playerList.push({
            		id: results.rows.item(i).id,
                	name: results.rows.item(i).name,
                	handicap: results.rows.item(i).handicap
            	});
        	}
    
    		this.listModel.items = playerList;
    /*		Object.extend(this.contacts_list, playerList); */
    		this.controller.modelChanged(this.listModel, this);
    /*		this.listModel.items = playerList;
        	this.controller.modelChanged(this.listModel, this);
        	this.controller.get('info_area').update(''); */
    	}
    	else {
            this.controller.get('info_area').update('<center>There are no players</center>');
        }    
    }
    Hope this helps.
    Last edited by DaveInFL; 07/23/2009 at 08:02 AM.
  14. worthb's Avatar
    Posts
    241 Posts
    Global Posts
    259 Global Posts
    #34  
    Have you tried using anonymous functions for the result and error functions as shown in the last example on this webpage?Mojo Storage Database - WebOS Internals

    As noted earlier on that page:
    Note: I have been unable to use my own function as a success or an error handler. Some of the existing applications seem to be able to do so, but others write anonymous functions as in the example.
  15. #35  
    Quote Originally Posted by worthb View Post
    Have you tried using anonymous functions for the result and error functions as shown in the last example on this webpage?Mojo Storage Database - WebOS Internals

    As noted earlier on that page:
    That's the solution for me. Not the best solution, I should say, I prefer more structured code, but that is the only way to get this working (just on this scene, other scenes works perfectly ).
  16. #36  
    Just another question... Why it doesn't shows the data????

    Code:
    EquiposAssistant.prototype.setup = function() {
     
        this.innerListAttrs = {
            listTemplate: 'equipos/listcontainer',
            itemTemplate: 'equipos/listItem'
        };
        this.resultList = [{resultString: " "}]
        this.listModel = {            
            items: this.resultList
        };
        this.controller.setupWidget('results_list', this.innerListAttrs, this.listModel);
     
    }
    Code:
    EquiposAssistant.prototype.getteamslist = function(event){
     
        var string = 'SELECT * FROM teams ORDER BY team_name;'    
        this.db.transaction( 
            (function (transaction) { 
                transaction.executeSql(string, [], 
                               function(transaction, results) {    // success handler
         var list = [];
        if (results.rows.length > 0) {
            for (var i = 0; i < results.rows.length; i++) {
     
                team_name = results.rows.item(i).team_name;
                list.push({
                    resultString: team_name
                });
           }
     
            this.resultList.clear();
            Object.extend(this.resultList,list);
            this.controller.modelChanged(this.listModel, this);
        }
        else {
            this.controller.get('info').update('<center>There are no Teams</center>');
        }    
                               },
                               function(transaction, error) {      // error handler
                                 $('info').update("Could not show record: " + error.message);
                               }
    ); 
            }).bind(this) 
        );
     
     
    }
    I have on my scene folder the following files:

    equipos-scene.html
    listcontainer.html
    listItem.html
  17.    #37  
    Not really sure why it wouldn't work. But a few things.

    1. Did you open the db again in the equipos assistant ?
    2. Change this code:

    Code:
    this.resultList.clear();
    Object.extend(this.resultList,list);
    this.controller.modelChanged(this.listModel, this);
    to

    Code:
    this.listModel.items = list;
    this.controller.modelChanged(this.listModel, this);
    Give it a try. Also, you're sure that the success handler is going into the anon function ?
  18. #38  
    Quote Originally Posted by davetati View Post
    Not really sure why it wouldn't work. But a few things.

    1. Did you open the db again in the equipos assistant ?
    2. Change this code:

    Code:
    this.resultList.clear();
    Object.extend(this.resultList,list);
    this.controller.modelChanged(this.listModel, this);
    to

    Code:
    this.listModel.items = list;
    this.controller.modelChanged(this.listModel, this);
    Give it a try. Also, you're sure that the success handler is going into the anon function ?
    Yeah, everything is working fine, the app is retrieving data and so on. But I'm not capable to show de data on a list, or a filterlist.

    I really want to show the data on a filterlist, not a simple list. I'm getting crazy with this.
  19.    #39  
    deCorvette. Did you try what I suggested and that didn't work also ?

    I can try and take a look at changing my list to a filtered list and see how things work out, but probably won't get the chance until tonight to do that.
  20.    #40  
    No real help I'm afraid. I just quickly tried it with a filterlist and mine didn't display either. I'll try and take a look at it later on as I might want to have mine in a filter list too. Probably just missing some setup, or maybe the way that the list is populated.

    Give me a day or so to take a look and I'll let you know. That said, if you get it fixed before then, please let me know
Page 2 of 4 FirstFirst 1234 LastLast

Posting Permissions