Display data from SQL Lite in Android app using phone gap - javascript

I am using Phonegap in Eclipse to make an android app. So I've made an excel file, then I converted it to a db file through using sql lite. Now i have to access that database in javascript. Can anyone give me an idea where to start.

In fact you can access a database that you created through the application Phonegap itself.
You can check the online doc (the link I provide is for Cordova version 1.5.0 but it should be similar for other versions) for more information:
http://docs.phonegap.com/en/1.5.0/phonegap_storage_storage.md.html#SQLResultSet
The problem is that you want to access a database that you pre-propulated. So, the main question about this issue would be: where to put my database file?
I suggest that you read the following links which should answer your questions:
Reading a local sqlite file from phonegap
https://groups.google.com/forum/?fromgroups=#!topic/phonegap/XlenKNxmoqE
I hope this information will help you.

Related

Login to a website and scraping its js generated html in android

I am really new to android and I am building an app that will take the username and password of a website(https://lms.mrt.ac.lk).
When the user hits the login button of my android app, the app should itself logged in to the above website and retrieve the complete(including js generated html) html source code.
As a start I tried to print the html source code in the android studio. I tried to use HtmlUnit, but later I found that it is not supported by android. Then, I tried to use Selenium on android, but when tried to build the project it gave me an error "More than one file was found with OS independent path 'META INF' ".
And then tries android's WebView to do the thing, as described in this question, but I don't know how to view the complete html output.
So, my question is -
How to login to a website inside an android app
How to get the complete html source code of the logged in website in android(scraping the js)
I want to do the above in same app. I searched everywhere and still could not find anything complete, that helps a beginner.
Please help me! your suggestions/solutions are highly appreciated.
I'll answer your questions in order.
I don't know what javascript android framework you are using, but the solution should be similar to the java solution. For your specific website, the login endpoint is https://lms.mrt.ac.lk/login.php. You should send a POST request to the endpoint with header parameters LearnOrgUsername and LearnOrgPassword. On success, this should return your desired LoginSessionCookies.
Instead of trying to interpret the javascript stuff, you should rather try to understand how the javascript code retrieves the information you need. And then directly access your information by a web request.

Cordova/Phonegapp - How to use Local Storage Plugin

I'm using cordova for the first time to develop apps for android.
i have installed cordova local storage plugin.
But i don't know how to use it(what java-script code is to be used).
What i'm making is a To-do list app,so i need to store the strings or whatever the user inputs.
can anyone please post a short example demonstrating the same.
Thanks in advance.
You don't need localStorage plugin to use simple html localStorage.You can simply save and retrieve value without any plugin.
For saving:
localStorage.setItem("key",value);
for retrieving:
localStorage.getItem("key");
You can save upto 5mb per app with local storage.
You can use web sql too. WEB SQL example link It also does not need any plugin.
Then you can use a bit advanced SQL wrappers. This one needs plugin to be installed. Brodysoft SQLite with complete documentation

PhoneGap - Read pre-packaged sqlite database

I've been struggling to get this working for too long. I just started to get into PhoneGap/Cordova. I got the demo app running, installed all official plugins, and added this SQLite plugin to begin work with: https://github.com/brodysoft/Cordova-SQLitePlugin
However, I want the plugin to read a pre-packaged database. Simply put, create an app that works offline and does not need to download an SQLite database when it is run for the first time.
I have been developing for Android for quite some time, and the solution was to deploy a read-only database file in the assets folder, and on first run copy the database file into a different folder, where I can read/write as I please.
So I did a little research and realized that it SHOULD be the same with PhoneGap. Place a binary SQLite database somewhere, so that when built, it will be packaged with the app. And then simply load it with the SQLite plugin I linked here.
Finally, the question! What are the exact steps I have to take to be able to read a file that was packaged with the app?
Where should I put my binary file to ensure that it gets packaged into the app?
How exactly should I initialize the File API? Should I ask for persistent storage using window.requestFileSystem? Or should I get some (not sure which) directory (cordova.file.applicationDirectory) as a DirectoryEntry using window.resolveLocalFileSystemURL? If so, what are the EXACT parameters I should use? I am mostly referring to this: https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md
How do I read the packaged file? Using window.resolveLocalFileSystemURL with the right folder? What should then the parameters be?
File copying should work OK if I get to this point. Just copy from the read-only cordova.file.applicationDirectory into cordova.file.dataDirectory, which is read/write. Right?
I know the questions might be pretty basic, but my countless attempts were unsuccessful and I did not find a tutorial that explains this in-depth (believe me, I googled). Also, the documentation seems insufficient.
Just working with a WebSQL database and load data the DB using a s***load of INSERTs is not a viable option, the database has thousands of records.
Thanks for the help in advance, you will save me a headache or two.
Currently Cordova's standard SQLite Plugin supports Pre-populated Databases, which will copy your database file from www and put it into the right directory. It also supports Android as well as iOS, so you don't need to have different logic for different platforms.
When you open the database, you can specify that it is pre-populated using createFromLocation: 1 like this:
var db = window.sqlitePlugin.openDatabase({
name: "my.db",
createFromLocation: 1
});
For iOS, it will first check www and if the file exists, it will copy it to Documents. Keep in mind that it will be backed up by iCloud. If you want to exclude it from iCloud, then add location: 2 on openDatabase as well, which will put your databases in Library/LocalDatabase.
UPDATE (2016)
The original Cordova-sqlite-storage project does not support pre-populated db anymore.
However, this feature just moved to another project from the same creator. Now, use Cordova-sqlite-ext for this purpose.

Blackberry - Attach pre-populated sqlite database

I have a pre-populated sqlite database and I need to attach this within my Blackberry app. I am using phonegap and therefore using the following javascript code to open my database and then run a select statement:
db = window.openDatabase("TaxCalculatorDB","1.0","Tax Calculator DB",1000000);
db.transaction(Manufacturer, errorCB, successCB);
However, when trying to run my select statement I get an error (ERROR: 1 no such table:user).
I have added my database files (which I have succesfully used in a iOS build) directly into the assets folder, exactly the same way I had done before. Do i need to move this database folder elsewhere?
Please advice, Thanks.
You have to have Javascript create the database when using webworks. There is currently no way to import an existing sqlite db into a webworks app. (You tagged this as phonegap, but I think phonegap uses webworks to create the app)
The common workaround to this is to include a JSON or XML file with all the data to be loaded. When you create the database, read the included file and add that data to it.

Can I use Sqlite in a WinRT application (javascript)?

Is it possible to use a Sqlite database in a windows 8 (winRT) javascript application?
What I want to achieve is to download a Sqlite database and store this in local storage before use. I believe some form of local storage is available to javascript based WinRT applications, but I want to know if Sqlite is usable in this scenario.
I'm also aware that the .Net implementation of Sqlite uses some win32 calls and I believe these will not be allowed by the windows8 app cerififcation process.
JavaScript has HTML5 IndexedDB available to it out of the box.
As for SQLite, you can use it, provided that you first wrap it as a WinRT component that can be consumed from JavaScript, e.g. using C++/CX. Its API surface is not that big, so it's certainly possible. I've experimented with compiling SQLite for Metro a while ago, and there were only a few Win32 API calls that were not available in the app container and had to be replaced - nothing major.
We created SQLite3-WinRT for this. It is a WinRT component wrapper for SQLite that passes the Windows metro style app certification. It also includes an easy-to-use JavaScript abstraction.
Take a look at this:
http://sqlwinrt.codeplex.com/
Yes, SQLite database is now supported in Windows 8 RTM. You can now download everything (Windows 8, tools, samples) from Windows Dev Center.
Yes You can use SQLite in WinRT machine.
Just follow following steps
Create a new project.
Go to references , then right click on the references there you will get Manage NuPackage Click on that.
In online search for Sqlite-net package , intall that package.
Again right click on the References and click add refrences , there in Extension section you will get two unchecked reference MS visual C++ run time and Sqlite Windows runtime. check both the reference and add references. It will two CS files in your solution explorer.
Now Download Zip file from https://github.com/doo/SQLite3-WinRT It will provide you the wrapper thing to use cs files in your project.
Unzip at any location.
Now in project go to FILE->ADD->Existing Project-> and browse your unzip location . There you will get a file SQLite3Component.vcxproj inside the SQLite3Component. Add that file.
Now wrapper Project is included in you Project.
Now in your unzipped files you ll get SQLite3JS folder copy that folder and paste in your solution explorer.
Now you are ready to use sqlite in your project.
Try to build your project it will show two error that winres.h file is not there. For that go to error location rename it winresrc.h and build it again. Now it will build and you can use sqlite in your project.
To use .js file of SQLite3JS , Provide the src of js file like SQLite3JS\js\SQLite3.js in html page where you are going to use sqlite.
Here i am giving you some example to use sqlite in js
// This will Create database name db.sqlite and try to create a table Name Notes. If it is not there
var dbPath = Windows.Storage.ApplicationData.current.localFolder.path + '\db.sqlite';
SQLite3JS.openAsync(dbPath)
.then(function (db) {
return db.runAsync('CREATE TABLE Notes (id TEXT PRIMARY KEY, notes TEXT)');
I hope all these step will help you out.

Categories

Resources