facebook

Database local and listview

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

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

    Eugenio
    Member

    I’m trying to do a simple thing.

    How to create a local database (SQLite).

    How to list a table in my local database on a listeview (as in the example of dynlist_demo).

    read data from a txt file and send to to my local database.

    I would like a clear and simple example. I bought this because language and so far had no practical result for this simple question.

    Thanks!

    #342964

    A preliminary WebSQL CRUD has been posted here:
    http://www.genuitec.com/support-genuitec/viewtopic.php?f=14&t=6217

    #343044

    aklisiewicz
    Member

    I would like to learn the same, and
    the question was about SQLite not web SQL
    so I think your link is somewhat irrelevant

    Art

    #343053

    support-michael
    Keymaster

    >the question was about SQLite not web SQL so I think your link is somewhat irrelevant

    Both ios and android browsers and webview component include the html5 web sql database. Both ios and android browsers are based on the webkit rendering engine which uses sqlite to implement the db. Give the example a look starting with the list-db.js file which includes the db interface code.

    If you need some background info there are tons of online examples that are a google search away. I plan to provide a write up of the code soon. A key thing to note if you have not worked with the web sql api before is that it is asynchronous. This frequently trips up developers that assume a traditional synchronous api.

    #343264

    aklisiewicz
    Member

    first of all your example doesn’t do what expected, so what sense it makes to look at the code.
    I tried to run it in Chrome viewer/tester, but still nothing. I simply cannot add a new record…

    Can you please explain: “the web sql api before is that it is asynchronous”
    what means that developers trip over it ?
    Art

    #343278

    support-michael
    Keymaster

    >so what sense it makes to look at the code. I tried to run it in Chrome viewer/tester, but still nothing. I simply cannot add a new record…

    I’ll look into this a bit more today.

    Following is the db-list.js file that I recommended you browse. (If possible I would post the code here but spam/exploit software raises an issue when it sees sql code and assumes it is a classic sql injection hack.)
    The initDatabase() function sets up the local html5 web database.
    See attachment list-db.js

    >A key thing to note if you have not worked with the web sql api before is that it is asynchronous. This frequently trips up developers that assume a traditional synchronous api.

    The database transaction() function is asynchronous. That is it will run independent of the code that follows it. Take a look at this updateItem() function. Notice that the phoneui.back() function is called from within the transaction. If it were outside of the transaction it would very likely run before the sql update. Thus if you have actions that you need to take after a db transaction your code design must account for the asynchronous nature of the web db transaction() api.

    To learn more about web db checkout some of these references and google for more examples:
    http://www.w3.org/TR/webdatabase/
    http://html5doctor.com/introducing-web-sql-databases/
    http://www.tutorialspoint.com/html5/html5_web_sql.htm

    Attachments:
    You must be logged in to view attached files.
    #348566

    mindvault
    Member

    Can you use same logic to render any widget? Instead of a list can you use with combo boxes?

    #348588

    Code_A
    Member

    Yes, you can dynamically build a list or a combobox. I have an app where I do both based on JSON data I receive back from a database on a web server. Let me know if is something you are interested in seeing and I can post some example code.

    #348606

    mindvault
    Member

    Code A if possible please share, that’s exactly what I am trying to do. Need to build a list with different text and combo boxes.

    Thanks in advance

    #348609

    Code_A
    Member

    My web service is setup to return the data in JSON format from my sendRequest function, which is an AJAX call.

    Here is my function for building the combo from that data (my “select” name comes from an item in a list that the user selected):

    function buildCombo (combo, list, url){
        phoneui.showActivityDialog();
        
        //build combo
        var response = sendRequest(url, "POST", "json","application/x-www-form-urlencoded; charset=UTF-8", false, '' );
        //alert(response.status);
        if (response.status){
            var items = response.status; 
            //clear drop down
            $('#m1-RRS-hidden-select-'+combo).empty();
            var select = $('select[name="'+list+'"] :selected').text();
            //loop through items and fill combobox
            for (var i=0; i<items.length; i++) {
                //add new items
                $('#m1-RRS-hidden-select-'+combo).append('<option value="' + items[i].deviceID.toString() + '" label="' + items[i].make.toString() + ' ' + items[i].model.toString() + '">' + items[i].make.toString() + ' ' + items[i].model.toString() + '</option>');
                if (items[i].make.toString() + ' ' + items[i].model.toString() == select){
                    $('select[name="cboDevice"] option:eq('+i+')').attr('selected','selected')
                }
            }
        }
        //alert($('select[name="cboDevice"]').val());
        phoneui.hideActivityDialog();
        
        //update view
        phoneui.preprocessDOM(phoneui.getCurrentPageId());
        
    }

    I also have a function for dynamically building a list from the db results. Let me know if you would like to see that one too.

    #348756

    mindvault
    Member

    Hi

    I am trying to dynamically create a list view, see attached example, using a JSON file. I would like each list item to have either a combobox or a text field for user to enter a number. Once user has enter number in text field I want to be able to capture the values for each text field where there is actually a value. I am not sure I am building the text fields correctly. I need trough loop thorugh all the text fields and capture the value the user entered. Any suggestions?

    Attachments:
    You must be logged in to view attached files.
    #348782

    Code_A
    Member

    I took quick look at your app and it appeared that your text boxes are being automatically generated (and named) as part of the dynamic build list operation. This is fine, but I would suggest programmatically naming the text boxes as they are generated so you can more easily loop through them and associate them with the list items.

Viewing 12 posts - 1 through 12 (of 12 total)
Reply To: Database local and listview

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