facebook

Mobione and SQLite

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #333757 Reply

    bamshot
    Member

    Hello,
    Is it possible to use SQLite with javascript in mobione?
    And how do I connect it to the SQLite Database?
    Thanks

    #333760 Reply

    jim
    Member

    SQLITE seems to play well with Mobione. I’ve been experimenting a little this weekend with it and got an experimental app to work on my phone. Here’s a link to an article that may help you.

    http://cookbooks.adobe.com/post_Store_data_in_the_HTML5_SQLite_database-19115.html

    Jim

    #333764 Reply

    bamshot
    Member

    I have already tried it with this method.
    It doesnt work with my existing database “language.sqlite” with tables “german” and “spanish” in it.
    How can i open my sqlite database with javascript?

    I tried it with this code:

    
    var db = null;
    var query;
    
    
    function initDb() {
      var shortName = 'language.sqlite';
      var version = '1.0';
      var displayName = 'language';
      var maxSize = 1048576; // in bytes
      db = openDatabase(shortName, version, displayName, maxSize);
    
    }
    
    function test() {
      initDb();
    
      db.transaction(function (transaction) {
          query = transaction.executeSql("SELECT word FROM german where rowid=1");
      });
    
      alert(query);
    }
    
    

    I execute the test(); function by clicking a button just to test what shows.
    By running the test-center and click on the button it shows “undefined”.

    #333765 Reply

    jim
    Member

    Sorry, I may have given you a different example from my notes of what I actually used. Here’s the code I used in my working app. I haven’t had time to do anything more than this. I just wanted to see if it would work. I even uploaded the app to my phone and it worked.

    In designer I created a button that executed

    db.transaction(populateDB, errorCB, successCB);

    and another button to clear out the data (to make sure this was actually writing records)using

    db.transaction(deleteDB, errorCB, successCB);

    And finally my custom js page:

    phoneui.documentReadyHandler = function() {
    }
    
          var db = window.openDatabase("Dummy_DB", "1.0", "Just a Dummy DB", 200000); //will create database Dummy_DB or open it
         
            //create table and insert some record
            function populateDB(tx) {
                tx.executeSql('CREATE TABLE IF NOT EXISTS SoccerPlayer (id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL, Club TEXT NOT NULL)');
                tx.executeSql('INSERT INTO SoccerPlayer(Name,Club) VALUES ("Alexandre Pato", "AC Milan")');
                tx.executeSql('INSERT INTO SoccerPlayer(Name,Club) VALUES ("Van Persie", "Arsenal")');
            }
         
            //function will be called when an error occurred
            function errorCB(err) {
                alert("Error processing SQL: "+err.code);
            }
         
            //function will be called when process succeed
            function successCB() {
                alert("success!");
                db.transaction(queryDB,errorCB); 
            }
         
            //select all from SoccerPlayer
            function queryDB(tx){
                tx.executeSql('SELECT * FROM SoccerPlayer',[],querySuccess,errorCB);
            }
            //select all from SoccerPlayer
            function deleteDB(tx){
                tx.executeSql('DELETE FROM SoccerPlayer',[],querySuccess,errorCB);
            }
            function plainSuccess(tx,result){
                alert('success in plainsuccess')
            }
            function querySuccess(tx,result){
                $('#SoccerPlayerList').empty();
                $.each(result.rows,function(index){
                    var row = result.rows.item(index);
                    alert(row['Name'] + '' + row['Club']);
                    //$('#SoccerPlayerList').append('<li><a href="#"><h3 class="ui-li-heading">'+row['Name']+'</h3><p class="ui-li-desc">Club '+row['Club']+'</p></a></li>');
                })     
                //$('#SoccerPlayerList').listview();
            }
    #333766 Reply

    bamshot
    Member

    Thanks for the fast answer,

    this isnt my problem, I dont want to create a database i want to open an existing db.
    I posted my code in the upper massage.
    Where do i have to place my database “language.sqlite”?

    #333767 Reply

    jim
    Member

    If it exists then this code will open it. Now where the database must reside is still somewhat a mystery to me. I tried hunting around on my phone for it but wasn’t able to find it. Maybe in a hidden or protected directory? But I didn’t spend much time figuring out where it was since I was pretty busy.

    Good luck,
    Jim

    #333769 Reply

    bamshot
    Member

    I want to open a Database which is in the same folder as my .mobi file.
    Is this possible?

    The databases are in the folder

    /data/data/<application package name>/databases/<databasename>

    I cant place my database in this folder with mobione, i can only add additional project files.

    #335861 Reply

    matty47
    Member

    Jim, thanks for the example code. Works great. What widget did you use for the “SoccerPlayerList”??. I tried the various list objects and uncommented the two lines in the code but the application failed.
    Thanks
    Matthew

    #336348 Reply

    lemorlenny
    Member

    @jim wrote:

    If it exists then this code will open it. Now where the database must reside is still somewhat a mystery to me. I tried hunting around on my phone for it but wasn’t able to find it. Maybe in a hidden or protected directory? But I didn’t spend much time figuring out where it was since I was pretty busy.

    Good luck,
    Jim

    Hi Jim, a question for you,
    If I publish this app the DB still linked?

    Lenny

    #351193 Reply

    Darshan Patel
    Participant

    incase if you guys are still looking for the solution then i’ll like to share my views.

    firstly webapps uses WEB SQL and stores everything in browser storage, and i guess it does not allows to access database from .sqlite file, atleast not with the openDatabase().

    but yes you can create database with openDatabase() and use it thereafter, it will remain forever in your browser until you delete it.

    #351524 Reply

    aklisiewicz
    Member

    your statements are not true. There is no problem using SQLite with Android (not sure about iOS). I have created an App like that (although I use B4A) not Mobi One. I’m still waiting for MobiOne to implement better database integration and that holds me from buying a license. After almost a year wait,noting new (as I see) so it looks like I would better go and search for some other tool.

    Art

Viewing 11 posts - 1 through 11 (of 11 total)
Reply To: Mobione and SQLite

You must be logged in to post in the forum log in