Results 1 to 5 of 5
  1.    #1  
    Hi there,

    first of all: I am new to webOS-Developing; for my first app I wanted to store some data in a SQLite Database. So I went ahead and read the article on webos-internals (webos-internals.org/wiki/Mojo_Storage_Database). Obviously I did something wrong when implementing it, but I don't know what. Maybe you can help me:

    Code:
    WatchlistAssistant.prototype.setup = function() {
    	/* this function is for setup tasks that have to happen when the scene is first created */
    	Mojo.Log.info(db_name);
    	Mojo.Log.info(db_version);
    	var db = openDatabase(db_name, db_version, db_displayName, db_size);
    	if (!db) {
    		Mojo.Log.error("Could not open database");
    	} else {
    		/*var sql = "DROP TABLE 'wertpapiere'";
    		db.transaction(function(transaction){
    			transaction.executeSql(sql, [],
    				function(transaction, results) {
    					Mojo.Log.info("Created table with success");
    				}, function(transaction, error) {
    					Mojo.Log.error("!!!!!!!!!!!! " + error.message);				
    				}
    			);
    		}.bind(this));*/ //this is important!
    );
    (db_name, db_version, db_displayName and db_size are global variabels). When I execute the app I get an error message "error: no suche table" three times. I confuses me that I get this error-message when trying to actually create the table. Did I put the DB-Initialisation into the wrong scene function?
    I it helps you, the palm-log output is in the file attached.

    Thank you so much for your help.

    P.S.: Is there any way to visually administer the tables in my database? Like phpMyAdmin for a MySQL Database?
    P.P.S.: Do you know any good tutorials or documentations for SQLite on Palm webOS? I didn't found one except the one on webos-internals.


    Greetings,
    Chris
    Attached Files Attached Files
  2. #2  
    sqlite on webos is harder and more obscure than it needs to be. In general, though, use SQLite's website for the syntax ("create if not exists" and "insert or update" rock), and apple's webkit site for information on the transaction model.
  3. #3  
    Try what I've included below in the code box, it assumes you have established two other functions in your assistant file, one called dbsuccess and the other called dberror for example...
    WatchlistAssistant.prototype.dbsuccess = function(transaction,results) {
    Mojo.Log.info("Created table with success");
    }

    Try using this code inside your WatchlistAssistant.prototype.setup
    Code:
    try{
      var somevalue = 'hello world';
      var db = openDatabase('mydb');
      var sql1 = 'CREATE TABLE IF NOT EXISTS wertpapiere (myid INTEGER, myvalue TEXT); GO;';
      var sql2 = 'INSERT INTO wertpapiere (myid,myvalue) VALUES (25,"' + somevalue +'"); GO;';
      db.transaction(
        (function (transaction) {
            transaction.executeSql(sql1, [], this.dbsuccess.bind(this), this.dberror.bind(this));
            transaction.executeSql(sql2, [], this.dbsuccess.bind(this), this.dberror.bind(this));
        }).bind(this)
      );
    }
    catch (e)
    {
      Mojo.Log.info(e);
    }
    Last edited by RealMayo; 11/22/2010 at 03:13 PM.
    Developer of: FFplayer - a file/folder based music player. FFplayer home
  4.    #4  
    Ah, thank you very much. It works now, I am able to store data and to retrieve it again.

    => time to mess around with webOS more^^

    Since I did an "openDatabase()" at the beginning, do you have any idea if I have to do something like "closeDatabase()" when the app is closed?

    Greetings,
    Chris

    P.S. It would still be awesome to have something like phpMyAdmin, but I guess it will work without, too.
  5. #5  
    Good stuff, and no you don't need to do a CloseDatabase.
    As for phpMyAdmin, maybe you'd find useful something llike the following...
    SQLite Database Browser | Download SQLite Database Browser software for free at SourceForge.net
    Developer of: FFplayer - a file/folder based music player. FFplayer home

Posting Permissions