Blackberry - Attach pre-populated sqlite database - javascript

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.

Related

open websql database in browser from an existing file

I'm developing reactjs app and I'm trying to open webSQL database from an existing file in browser but without success. I would like to use database for testing purposes in browser until my app will be published using cordova. Then I will switch to cordova's SQLite plugin.
My db file is stored inside public folder and the code looks like:
db = window.openDatabase('/db.sqlite', "0.1", "mydb description", 200000);
However it seems like browser (Google Chrome) is always opening a new database named /db.sqlite instead of opening an existing database.
Any suggestions?
EDIT 1:
After opening db i added first transactions but it ended with "could not prepare statement (1 no such table: users)", but users table has many rows inside my db file.
I tried also change /db.sqlite to db.sqlite but nothing works. Is there any way to copy db file to chrome storage before i open db?
EDIT 2:
Opening webSQL db file is just a hack for development mode so any "dirty" solution to achieve opening db from custom file would help a lot.
EDIT 3:
I found a lib called sql.js https://github.com/kripken/sql.js. Do you think it is possible to wrap this lib with and functions which will decide whether the app is running in cordova (then exetuces plugin.sqlite) or browser (then execute commands from sql.js lib)?

Create hybrid desktop and web application with different languages

I want to create an app to estimate engineering costs: lots of tables, forms, a sidebar with a tree structure and so on. You can access a database in the cloud and create table structures according to records in the database.
Naturally that would be a website, however, if the user does not always have an access to the Internet, he/she can download a copy of that database (precisely, a copy of the current version of the database), so that it would be possible to get data from it and work locally. That is why an offline desktop app is needed.
Would it be possible to develop such a hybrid application without first creating a web app and then doing the same with a desktop app?
Previously i have looked into JavaFX, but we saw that it's too difficult to create a website out of that. Then we saw Electron, but i'm not sure if it is the right choice, because it seams that Electron is only used for desktop.
I'm lost as to why you feel you need a website/desktop hybrid. There are many APIs available to let you access a cloud database. All you have to do is find an API with web hooks, or APIs that specifically target the database type you are using (sql, mongo, or whatever). Then just cache a local copy once you've pulled down the database.
Work on the copy then push back to the database when they save, or try to do a push/pull every 5 minutes or something.
You can make a HTML page, which would:
Use AJAX calls if connected
Add relative <script> tag, thinking that HTML file lies in a folder on PC, and that script is somewhere nearbly.
In both cases, user will get same results.
Downloads are:
HTML file with inline script
JS file with database
or
zipped folder with HTML, database JS files and all scripts, images, css, etc. requred for HTML file to show properly.

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.

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