HTML5 SQLite vs Native Database in case of PhoneGap - android

I am building a PhoneGap application for Android and iOS.
I want to know which one is a better selection for database management: HTML5's SQLite or Native database of device.
In case of native use, i need to build a plugin for interaction.
Please suggest me a better option according to performance and speed.

i have tested with a POC that Native DB of Android/iOS is too much faster then WebSQL (of HTML5), in case of a PhoneGap App we should use a plugin for Native database.
in my test; i have run 999 insert query in a PhoneGap App with Plugin for native environment and the results are:
in Android queries are 558% faster in Emulator, 275% faster in htc droid hd and amazingly 2327% faster for htc wildfire.
in iOS the results are just hilarious queries are 2k+ percentage faster in Simulator/iPhone 4 and 5600% faster in iPhone 3GS.

The Web SQL Database standard is no longer being developed. It will probably be replaced by IndexedDB. I wouldn't rely on its existence if I were you.
From the spec:
Beware. This specification is no longer in active maintenance and the Web Applications Working Group does not intend to maintain it further.

I don't know about native database, but HTML5 WebSQL is very slow on iPhone when using tables with hundreds of rows, mainly 3G, 4G is little better. On Android there is no problem running pretty nice queries - we thought it would be the same on iPhone but we had to drop use of WebSQL in our project and rewrite everything to JSON and many more functions which had functionality of a few simple WebSQL queries.
It's a shame that support of WebSQL is officialy dropped, but currently, it's supported on both Android and iPhone and it's very handy for some cases. So I hope and I think WebSQL will be maintened "not-officially" but still in Android and iPhone in future.
As for your question - my experience tells me, that it depends on your tables structure, how complex queries you have and mainly - how many rows you have in tables. If you have tens of rows, its OK to use WebSQL, but if you hit 100 or more rows in a table, it will get slow on iPhone.

Related

Portable Mobile/Tablet application proof of concept

I need to develop a portable application mainly for Windows 8.1 and iPad, but could be expanded for Android, WP and iOS later.
The application consists of calling web services to display data in grids and it contains CRUD operation, and it may save some local data for offline mode then synchronizes later when connectivity is up.
I'm torn between too many solutions, I need your advise for better solution.
1- Solution 1: Go Native for each OS (VS for Windows 8.1 [RT and pro] and xCode for iPad): this solution requires code duplication, logic and UI.
2- HTML5 with WebView app: I think this is a weak solution especially that we have local storage, checking for connectivity and calling ws ...
3- Using Xamarin: I think Xamarin does not support WinRT or Windows 8.1 to share logic code between iPad and Windows 8.1
4- Using Xamarin.Forms: Building the UI is tough and also it does not support Windows 8.1.
From your perspective, what is the best solution? please advices if you have any other proof of concept.
Many Thanks.
Most of the html/hibrid frameworks like Cordova (cordova.apache.org), Ionic (http://ionicframework.com/), etc, uses a native WebView on Android. Until Kitkat the performance of WebView is not production-ready and if you've a list with a lot of elements, the scroll experience is really bad.
If you want to do a simple proof of concept, prototype or whatever, I think that html frameworks are a good alternative. But if you are going to put your bussiness on top of one of this framworks, I would not recommend.
There is an alternative to embed a Chrome using Cordova & crosswalk (https://crosswalk-project.org/documentation/cordova.html) but you will end with an APK ~40Mb for a simple hello world.
Just my 2 cents. I don't see a point in using libraries that are unsupported across the platforms you plan to release and support on. Personally, I'd code natively for each platform. While this takes a lot of work, if you have to ask for direction on which path you want to take your application, then this type of project sounds more like a "you reap what you sow" application. Also, you'll be able to directly support each problem without having to wait for patches, but there are 2 sides to that coin as well. Your opportunity cost is missing future features the library will provide, if it's worth it to you.
If you aim at quality, going native is the only way... You can reduce the amount of work like Google is doing: writing the business logic and unit tests in Java, then converting it to ObjC with J2ObjC and to Javascript with GWT.
In your case, being that Java is a dumbed-down version of C#, you can easily find tools to convert to the latter, finding yourself with native business logic for every platform! That should account for 50%-70% of the codebase...
I think going with HTML5 with webapp view is better option.
Using Cordova (Phonegap) most of the native features are easily achievable in HTML webapp.
PhoneGap Platform Guide
Alot of other plugins are available for the advances features like BLE, NFC.
Calling webservice is really not an issue in HTML5.
Simple ajax is enough, however now a days many advanced frameworks are available which makes your work easy. One of the best among them is Angular JS(maintained by Google ).
Angular JS
For database you can access native database of the target OS or SQLite db of the mobile device.
You can check this link
Storage options
So developing a webapp can be a more efficient solution in your case. It can be best way for you as per my view point. However, you can do some R & D and can find the appropriate for you.

Phone gap sqlite plugin vs websql

I have been working on a simple database application for a small phonegap project. I have successfully implemented a websql database that stores a single table with some basic data. Recently I have been reading that this method is being phased out gradually due to some limitations. There seems to be an alternative using a webkit plugin for phonegap. This interfaces between the sqlite database on the phone and the front end.
So my question boils down to: What is the best practice when developing a database application using phonegap? Which technologies would you suggest? Any help is much appreciated. Thanks
Hi if it is larger database then go for Native sql plugin, if it is small then use HTML 5. HTML database They are fast, flexible and never expire.all of the queries are run via JavaScript, they persist until manually removed. but if the DB size is so large application must hang, so for much larger DB manipulation you can use Native Sql.and HTML 5 db Not ideal for sensitive information like password.
refer this may help you.
I suggest you to use a sqlite plugin. I have an application since android 4.0 using websql, and now, on the devices using android 4.4, my application stops working.
Don't commit the same error that I do. Use android native sqlite instead html5 websql.

Tracing database workloads of mobile applications under Android/iOS

I want to understand the database workload (reads/writes against local database) of a mobile applications (third party, i.e. not developed by me) running under Android.
My options include:
Ask the developer of the application: Doubtful that this approach will work
Find scientific paper that has measured the DB workload of typical mobile applications. That would be perfect, but I've not found such a paper :-(
Profile a running application using an emulator, profiler, and/or a trace-sensemaking tool (e.g. detect transactions)
I need a solution for option 3, that is a tool for understanding the DB workload of a mobile application actively running under Android (iOS solution would also be ok)
I understand that this is hard. For starters, I can make no assumptions about the actual database that is being written to, although it is very likely to be SQLite.
I understand that the following might be part of the solution:
Emulator, e.g. http://developer.android.com/tools/help/emulator.html
Tracing tools
Trace sense-making tools
So, to summarize: If you wanted to understand the DB workload of Angry Birds running under Android. How would you do this?
Any information is useful, as I'm starting from scratch here :-) Thank you.
You can achieve a solution for the point number 3 with Instruments in iOS (http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/Introduction/Introduction.html).

HTML5 Web SQL Database Concerns

My company is currently transitioning to a new architecture, as well as a model that provides services to mobile devices. Our application was traditionally web based (HTML5/CSS3/JS/PHP/MYSQL), so we want to be able to port it to mobile platforms without having to reinvent the wheel (Cordova), as well as to desktops in a standalone fashion (AppJS) so that we don't have to worry about browser-dependent bugs. We are also transitioning away from PHP to NodeJS to make this more feasible.
The problem is that our users NEED the ability to use our application offline, with no real limit on how long or how much data they can store before "syncing" it to our servers.
With AppJS, this isn't an issue because they can store as much data as needed within a sqlite database. However, I have discovered the issue regarding a 5MB quota for WebSQL data and cordova/phonegap. This presents obvious technical challenges regarding our business needs.
I am aware that there are a couple of plugins that enable you to use sqlite data. The original sqlite plugin (https://github.com/davibe/Phonegap-SQLitePlugin) lacks documentation for android, and the other (https://github.com/chbrody/Cordova-SQLitePlugin) requires me to specify a data limit which obviously isn't possible. I am therefore left with very few options, one being to split the databases into multiple 5MB segments which are controlled by a JS wrapper.
Can you feasibly split larger datastructures into multiple 5MB websql databases with no issues across iOS and Android?
Is there a limit on the total number of websql databases on iOS and android?
Are there any other options that you would recommend we look at? We need to be able to use our existing HTML5 and CSS for the frontend!
EDIT
Our original architecture never really worked with tablet devices. This is something we are looking to remedy with cordova, as well as building a more stable solution. Originally, our offline product ran on a Server2Go stack that had all sorts of platforming issues because of the various applications running on the clients machine
For the android platform, you could create a native app, and then use a webview to display the front end (if its really that important to keep it HTML), then use a javascript bridge to allow the content in the WebView to interact with your native app.
From what you have described about the application though, I think you are better off actually creating a native application. As you say in your comment, one of the reasons you are switching your platform is because of lack of control. Why then immediately re-open this can of worms by introducing all sorts of hybrid app framework into your stack.
Long story short, you will have full control (and quite likely, better product) if you just go with the native approach.
To get a truly cross-platform, cross-browser relational solution that will work offline and have the necessary storage capacity, I would suggest going with: SequelSphere
Since it is a 100% JavaScript solution, it should be usable in each of your configurations without requiring a different codebase for each. Furthermore, it uses IndexedDB (if available, and then LocalStorage) to store its data in relational tables. I believe most browsers do not have a size limit on the storage amount of IndexedDB. I think Firefox may have an initial 50MB limit per the following: Max size in IndexedDB.
Also, there is a new feature called "Change Trackers" that significantly help in the data synchronization process by tracking changes (inserts/updates/deletes) to tables, and then reporting them to you when you desire.
As an extra added bonus, unlike WebSQL, SequelSphere is VERY JSON friendly. Creating tables couldn't be easier:
db.catalog.createTable({
tableName: "EMPL",
columns: [ "EMPL_ID", "NAME", "AGE", "DEPT_ID" ],
primaryKey: [ "EMPL_ID" ],
data: [
[0,"Bob",32,0],
[1,"John",37,2],
[2,"Fred",28,1]
]
});
Querying the data is easy:
var res = db.query("SELECT name, age, dept_id FROM empl WHERE Dept_ID = 2");
Inserting / Updating / Deleteing data is easy:
db.insertRow("empl", [3, "Sue", 26, 2]);
db.updateRow("empl", [3, "Suzy", 26, 2]);
db.deleteRow("empl", [3, "Suzy", 26, 2]);
One thing to be aware of: Since this will be used in an offline application, make sure you set the "Persistence Scope" of either the entire Catalog, or each Table to be "SCOPE_LOCAL":
db.catalog.setPersistenceScope(db.SCOPE_LOCAL);
// -or-
db.catalog.getTable("empl").setPersistenceScope(db.SCOPE_LOCAL);
Documentation on the basics: SequelSphere Basics
Documentation on "Local Storage" support: Local Data Storage and Persistence
Here is the API: SequelSphere API
If you have any questions, just email the support for SequelSphere.
For complete transparency, I am part of SequelSphere, and it does seem to answer your question very well... ;)
Generally speaking, I recommend using lawnchair so that you can be implementation agnostic. http://brian.io/lawnchair/adapters/
Can you feasibly split larger datastructures into multiple 5MB websql
databases with no issues across iOS and Android?
Before I knew about lawnchair, I implemented this using WebSQL, which I kinda regret. WebSQL databases can grow beyond 5MBs. I'm not sure what the true max is, but I've set my Phonegap app to 100 * 1024 * 1024 and haven't had any issues on Honeycomb Android.
For iOS you could use SQLite database on PhoneGap / iOS - More than 5mb possible.

Should I use PhoneGap instead of ramping up on the Android SDK?

Although I am comfortable with Java, I have much more experience with web development. I am looking to get into programming simple Android games.
Should I just program everything using Javascript/HTML and forget ramping up on Java/Android SDK? I guess my question really is, what are the limitations of PhoneGap? What are some things to consider, etc.?
Some advantages I can think of:
More selection in terms of game engines for HTML5/JS
Faster ramp up time
Automatically deploy to all major platforms
The biggest pro for phonegap is that it takes advantage of your web development experience. I think what most people seem to miss (or ignore) is that there is no advantage in avoiding phonegap for an android only application! You can still write as much native code as you want to, mixing and matching phonegap as you please.
I am writing an Android app that uses text to speech. Because Phonegap doesn't support this in their API, you might think that Phonegap is a bad choice, but actually it was quite easy to call the Java code I need from javascript:
Java code:
public void onCreate(Bundle savedInstanceState) {
//boilerplate and TTS set up
...
this.appView.addJavascriptInterface(this.speak, "speak");
...
}
public void speak(String text) {
this.tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
Javascript code:
speak.say("hello world");
Pros for Phonegap:
deploys to all major mobile devices
sounds like it best fits your skillset
covers most available platform APIs with a uniform code base, no need to learn each one
PhoneGap Build (https://build.phonegap.com/) and Cordova (https://github.com/brianleroux/Cordova) are making it even easier to deploy to multiple platforms
Pros for Android:
Better performance
No limitations on which APIs you can use (i.e., video)
Defined toolset and workflow
native UI components
Fragments API and native layouts make handling different screen sizes easier
It really comes down to whether or not you want to be an Android-only developer or not. That first pro for phonegap is HUGE is you plan to develop for multiple platforms.
I personally have major concerns over PhoneGap apps performance compared to that of a native Android app. The admittedly small amount of testing that I have done makes the PhoneGap version feel very unresponsive compared to native. I don't see how this doesn't translate to a poor user experience. Even PhoneGaps packaged sample application runs poorly.
I was very excited at the possibilities that PhoneGap appeared to open up, but I don't feel like it's there yet. I don't feel comfortable committing to a large project on PhoneGap.
No WAY! Adobe has their cloud build which has a 9.5 MB file size limit. And, they are discontinuing support for other types of build.
I have just spent the past week or so developing a simple Android app using PhoneGap. My great hope was to be able to recommend this product for use in our department as a "write-once, deploy everywhere solution."
In practice, it was more complicated than I would have hoped. I did manage to get an Android version of the app done, but I found a lot of quirks in using basic stuff like getting it to include css and the jquery mobile framework. I kept thinking that this was just my learning curve but a lot of the tutorials I found online were outdated and didn't work in the version I downloaded. The biggest surprise was that you can't link to external documents without using a plugin such as childBrowser, which is a huge drawback.
I tried today to port my app over to iOS and could not get past step one with importing css. I couldn't find any support documentation on this basic step. It's frustrating because this is a simple app that I could craft as native in Xcode in a day or so. It looks like it will take me a lot longer using PhoneGap.
PhoneGap looks really promising, but at the moment I don't want to use it. It's just a question of time. Why would I want to take twice as long on something? It might be a better choice in future versions

Categories

Resources