For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub
- This topic has 11 replies, 6 voices, and was last updated 11 years, 11 months ago by
Code_A.
-
AuthorPosts
-
EugenioMemberI’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!
October 2, 2013 at 7:18 pm #342964
support-octavioMemberA preliminary WebSQL CRUD has been posted here:
http://www.genuitec.com/support-genuitec/viewtopic.php?f=14&t=6217October 4, 2013 at 4:25 pm #343044
aklisiewiczMemberI would like to learn the same, and
the question was about SQLite not web SQL
so I think your link is somewhat irrelevantArt
October 4, 2013 at 7:31 pm #343053
support-michaelKeymaster>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.
October 11, 2013 at 12:29 am #343264
aklisiewiczMemberfirst 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 ?
ArtOctober 11, 2013 at 6:16 am #343278
support-michaelKeymaster>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.htmAttachments:
You must be logged in to view attached files.April 3, 2014 at 4:59 pm #348566
mindvaultMemberCan you use same logic to render any widget? Instead of a list can you use with combo boxes?
April 4, 2014 at 5:59 pm #348588
Code_AMemberYes, 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.
April 5, 2014 at 11:38 pm #348606
mindvaultMemberCode 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
April 6, 2014 at 9:31 am #348609
Code_AMemberMy 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.
April 13, 2014 at 4:59 pm #348756
mindvaultMemberHi
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.April 14, 2014 at 6:34 pm #348782
Code_AMemberI 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.
-
AuthorPosts
