For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub
- This topic has 10 replies, 6 voices, and was last updated 11 years, 3 months ago by
aklisiewicz.
-
AuthorPosts
-
bamshotMemberHello,
Is it possible to use SQLite with javascript in mobione?
And how do I connect it to the SQLite Database?
ThanksJanuary 1, 2013 at 5:43 pm #333760
jimMemberSQLITE 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
January 2, 2013 at 6:36 am #333764
bamshotMemberI 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”.January 2, 2013 at 6:53 am #333765
jimMemberSorry, 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(); }January 2, 2013 at 6:57 am #333766
bamshotMemberThanks 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”?January 2, 2013 at 7:02 am #333767
jimMemberIf 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,
JimJanuary 2, 2013 at 8:01 am #333769
bamshotMemberI 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.
February 24, 2013 at 1:34 pm #335861
matty47MemberJim, 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
MatthewMarch 7, 2013 at 7:29 am #336348
lemorlennyMember@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,
JimHi Jim, a question for you,
If I publish this app the DB still linked?Lenny
August 28, 2014 at 8:34 am #351193
Darshan PatelParticipantincase 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.
September 15, 2014 at 3:10 am #351524
aklisiewiczMemberyour 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
-
AuthorPosts
