Migrate Ionic from Cordova to Capacitor Storage - sqlite

I currently have a Ionic Cordova App in the Playstore that uses the cordova-sqlite-storage plugin. Now I want to switch to Capacitor. Unfortunately I cannot use the storage plugin anymore with Cordova and need to switch to the storage plugin of Capacitor. This would work fine, but the Capacitor Plugin capacitor-data-storage-sqlite automatically adds SQLite.db to the database name.
For example my db file is appDb and if I try to use it with the capacitor plugin using appDb as Name, the plugin trys to use the file appDbSQLite.db and the db schema is also different.
So now I thought, ok I read my old sqlite file with sql querys and then write the values to the capacitor store. Now the problem is, that also the sqlite capacitor plugin #capacitor-community/sqlite appends SQLite.db to the filename, so I am not able to read the values from my appDb file.
Now I thougt, ok I copy my appDb file to appDbSQLite.db, to read the values, with sql queries, but unfortunately, I am not able in any way to copy the database file with the capacitor Filesystem api. I always get the error, that the file does not exist. My appDb file is in the database folder of the app.
Has anybody experienced similar issues, or can tell me, how to copy the database file with capacitor?
I highly appreciate any help with this =)

Related

how to share a flutter app with integrated sql db

i made a flutter app which creates then uses an sqlite db.
To share my app, i used to upload the apk file in google drive, but everytime it is downloaded then installed on a phone, the db is empty.
I want to share the app with the db filled, but i don't know how to do this.
Any help please ?
When your users run app at first time, their database is empty. Your problem can be solved by two ways:
Create entities in database (data that you sharing) at database initialization.
Create a backup feature that provides possibility to import database from the user's storage (just replace db file in app's internal folder by db file from external storage (Downloads folder for example)).

Flutter - where to put own SQLite .db file?

I have a SQLite .db file that I want to access through sqflite on Flutter. Where in the Flutter project am I supposed to put it so that I can access it both on Android and iOS? How do I make sure that it's shipped with the apk? All examples that I found assume that the db needs to be created from scratch at the first launch.
You can put the db file in your assets folder and declare it in your pubspec.yaml. On startup you can write it out to disk and then use that path with your connection string to connect the db.
You can read from assets using
var dbContent =
await rootBundle.load('assets/database/mydb.db');
Then write it out to your file system and go from there.
I've found that this problem is related to:
https://stackoverflow.com/a/51387985/3902715
Credits to R. C. Howell

Appcelerator / Titanium location of iOS simulator sqlite database

I'm posting this to assist users who will be encountering the same thing I did when trying to locate a sqlite database being used on the iOS simulator when using Appcelerator.
xCode Version: 8.3.x
Appcelerator Studio: 4.8.x / SDK: 6.x
Issue/Test Case: I need to test several iterations of loading data from the sqlite database to a remote mySQL server. I want to place an existing sqlite database file in the folder and have the simulator recognize this file so I can use it for testing/development.
Question: Where is the sqlite database stored on the iOS simulator, can I place an existing sqlite database in this folder and have my app recognize it?
Answer: Yes
Steps to achieve:
This is what I did to locate where the simulator/device is looking for
1. Find out where your application is located in the filesystem by adding this code in your index.js (or another file of your choosing).
Ti.API.info("app directory: " + Ti.Filesystem.applicationDataDirectory);
This will give you the long filesystem directory location:
/Users/[username]/Library/Developer/CoreSimulator/Devices/96662E38-C659-4568-B53F-C32DC6B2B73D/data/Containers/Data/Application/96662E38-C659-4568-B53F-C32AB6B2C03D /Documents/
2. This was almost the correct location but the sqlite database is actually stored in the following location:
/Users/[username]/Library/Developer/CoreSimulator/Devices/96662E38-C659-4568-B53F-C32DC6B2B73D/data/Containers/Data/Application/96662E38-C659-4568-B53F-C32AB6B2C03D /Library/Private Documents/[filename].sql
3. You can use this location to put an existing sqlite database file and execute sql statements against it.
4. I'm sure you could reference another directory in your app but I was looking for the default storage directory since my app uses this location.
Hope this helps someone, as I was looking for this specific functionality for testing/development.
Happy Coding!
An easy way to get the database included is to simply add it to the resources folder, or a sub folder in the resources directory. Then you simply call the Ti.Database.install() method. This will copy the database into the simulator location you found. The upside with this method is that you don't have find the location for each iOS simulator (i.e. iPhone 5, 6, 6 plus, 7...).
I do use your method when I need to query the database externally with SQLite manager or another such program.
You can read more here http://docs.appcelerator.com/platform/latest/#!/guide/Working_with_a_SQLite_Database

Open SQLite database on Google App Engine

Is there anyway to open and read a SQLite database file on GAE?
I am currently uploading dbs to blobstore as admin and serving them publicly to user clients. I just can't read them in the GAE admin interface.
You can use SQLITE on Google App Engine. The problem has nothing to do with the support of certain libraries. It has to do with read-only file system. There is, however, a writable /tmp directory. If your app on startup first copies the db.sqlite3 file to /tmp/db.sqlite3 and references this path as database path, it will work.
There are, however, drawbacks.
1. This is not a "real" directory i.e. it's stored im memory. If database is too large, one will get problems.
2. Each instance has its own copy of db.sqlite3 file. Does not scale well.
Here is a django example:
Using SQLITE for local Django development for Google App Engine?
Short answer, no it is not possible to use a SQLite database on a standard Google App Engine application as it is not currently supported. However, you can give a try at implementing your own configuration with the App Engine Flexible Environment that allows to take advantage of custom libraries through Infrastructure Customization.
In case you would want to experiment, here is a sample Django application designed to be run with its default SQLite database on the App Engine Flexible Environment. Still, make sure to read the database notice providing alternative data storage options and explaining that SQLite data does not persist upon instance restart.

how to use pre-populated database with tidesdk/titanium desktop

I'm in need of some help in developing a desktop application with a pre-populated database. I have tried numerous ways to get this working including those mentioned on both Tidesdk's API here http://tidesdk.multipart.net/docs/user-dev/generated/#!/api/Ti.Database.DB and at Titanium Desktops old API here http://developer.appcelerator.com/apidoc/desktop/latest/Titanium.Database-module.
While the later (using Titanium not Ti) works in creating a database in the apps directory it does not install my pre-populated sqlite database which is located in the resources file of my app.
A couple of my attempts located below
var db = Titanium.Database.openFile('test_db.sqlite', 'test_db');
var db = Titanium.Database.openFile(Ti.Filesystem.getFile(
Ti.Filesystem.getApplicationDataDirectory(), 'test_db.sqlite'));
var db = Ti.Database.open('test_db');
As stated most of these manage to create a database with the name given but when trying to run something as simple as a db.execute(SELECT) of something I know would exist in my pre-populated db I receive an error stating
Exception executing: SELECT name, id FROM people ORDER BY name COLLATE NOCASE, Error was: SQL Statement invalid or database missing
I have searched high and low for something to answer this but everyone continues to refer to the aforementioned API's or to the Mobile API's Ti.database.install() which does not work either.
Is it possible with titanium desktop to use a pre-populated sqlite database or do I have to populate it after I create it? If so any direction would be helpful (where to place the .sqlite file in the app and what functions to call).
I am currently using Titanium Studio with a titanium desktop osx SDK of 1.2.0.RC4 as requested by tidesdk.org until they have released there open source sdk.
Thanks in advance
This is possible, I just used this feature in a recent desktop app, deployed it successfully to Windows and Mac.
In my experience, sometimes your database file can be corrupted, for example if you use the Titanium.Database.install command, and it cant find the file to preload from (maybe the first time you specified the path wrong for instance), it will create the file itself, any subsequent install commands will not work because it already thinks this database has been installed.
Have you tried clearing out the application data? This is where titanium installs the database. For Mac this is in your /User/Library/Application Support/APPNAME directory. Their is a directory for databases, delete this and try again.
Also, this answer on Titanium Q&A may help, it talks about the process with the Mobile SDK but the Database stuff is the same.
Hope this helps!

Resources