Can I use Sqlite in a WinRT application (javascript)? - 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.

Related

React Native - How to open my application when click on file from local device

I am using React Native and Expo.
I have file with unique extension (For example: SomeFileName.xxx) and it contains some text.
I want when I try to open this file from the device, it will open the application (Android/IOS) and I need read the content of the file.
How can I do that?
It really depends what is the extension of the file!,
And it also depends upon where the file is saved.
Everything is possible in react-native-cli but in Expo it comes with very limited possibilities,
Expo does have a file-system api that allows you to access local files on device!,You can read/write any file to local directories of device!.
Here's the doc for file system:-
https://docs.expo.io/versions/latest/sdk/filesystem/
Thanks!.

Recursive copy of directory from web to device file system in Cordova

I want copy all files in a web directory on a webserver, and ideally in its component subdirectories, into local device storage for Android and iOS in Cordova using javascript and/or cordova plugins.
The use case is to copy an entire (smallish) webapp/page from a remote webserver (that we control, and where we posted the content) into local storage on the device. This will be used for a form of hot code push for a cordova app.
It's possible to copy files using cordova-plugin-file-transfer:
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/
or in a more standards-compliant way using XMLHttpRequest (XHR):
https://cordova.apache.org/blog/2017/10/18/from-filetransfer-to-xhr2.html
How does one copy an entire directory tree, overwriting an existing one, in device storage.
Preferable: method to include error handling for the case that something prevents the full copy from happening, possibly resulting in a partial copy or a corrupted directory.
Is there an api or combination of apis that do this already? If not, does someone have or know of code to accomplish this?
Thanks!
You can look at hydration of phonegap for hot push :
http://docs.phonegap.com/phonegap-build/tools/hydration/
I think it may be suitable for your need.
However, be very careful with hot code push because apple doesn't like it very much and it's rather contrary to their guideline.

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.

Display data from SQL Lite in Android app using phone gap

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.

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.

Categories

Resources