I'm currently developing an hybrid app using the Salesforce-Mobile-SDK. In order to fulfill some offline requirements which are part of the project I need to access some sort of database on the device and my first pick is SQLite.
Is there any PhoneGap 2.3.0 compatible plugin to open and perform CRUD operations on a SQLite database?
I've already googled a lot this afternoon and i've found somw interesting plugins but they refer to other PhoneGap versions and i'm afraid i'm constrained to v 2.3.0.
Thank you.
M.
You shouldn't need a plugin for this as support for webSQL(sqlite) is included in PhoneGap 2.3.0.
You can find the documentation here
Example:
var db = window.openDatabase('appdb','1.0','AppDB',5000000);
db.transaction(function(tx){
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (itemid INTEGER PRIMARY KEY, otherField, someField)');
}, errorCallback, successCallback));
Related
I'm using this section of this official MSDN tutorial: Use a SQLite database in a UWP app but I'm getting the following error:
REMARK: There are many online posts related (or similar) to this issue but none seems to have a solution. Most of these posts are a few years old so I thought this issue would have been resolved by now. Moreover, the above mentioned tutorial is using .NET Standard Class library project, as well. And the online posts regarding the issue do not have .NET Standard involved. So, I was wondering if the issue is caused by the use of .NET Standard library. Regardless, a solution will be greatly appreciated.
SQLite Error 14: 'unable to open database file'
Error occurs at line db.Open() of this code:
public static void InitializeDatabase()
{
using (SqliteConnection db =
new SqliteConnection("Filename=sqliteSample.db"))
{
db.Open();
String tableCommand = "CREATE TABLE IF NOT " +
"EXISTS MyTable (Primary_Key INTEGER PRIMARY KEY, " +
"Text_Entry NVARCHAR(2048) NULL)";
SqliteCommand createTable = new SqliteCommand(tableCommand, db);
createTable.ExecuteReader();
}
}
NOTES:
The line just below the above code reads: This code creates the SQLite database and stores it in the application's local data store. That means the app should have access to that local data store.
I'm using latest version 16.3.5 of VS2019 on Windows 10. The target version on the project is selected as Windows 10 1903 and min version as Windows 10 1903
UPDATE
This similar official 3 years old sample works fine. So, the problem seems to be related to newer versions of .NET Core. But I need to use latest version of .NET Core for other features my app is using that are not available in the older versions.
I also tried this similar old tutorial, but it did not on new version of .NET Core work either - giving exact same error.
The old problem reported in 2016 here to Microsoft seems to have resurfaced again with the new version of .NET Core.
This is a misunderstanding, SqliteConnection db = new SqliteConnection("Filename=sqliteSample.db") can not create a Sqlite file, but access the existing Sqlite database file through the path.
So you need to create a valid sqliteSample.db file and place it in the root directory of the UWP project. Select the content in the Properties -> Build operation to ensure it will be loaded into the application directory.
Update
Please create the sqliteSample.db file in LocalFolder first.
await ApplicationData.Current.LocalFolder.CreateFileAsync("sqliteSample.db", CreationCollisionOption.OpenIfExists);
Then use the path to access the database file
string path = Path.Combine(ApplicationData.Current.LocalFolder.Path, "sqliteSample.db");
using (SqliteConnection db =
new SqliteConnection($"Filename={path}"))
{
// ...
}
Best regards.
I have an Xamarin Android (and maybe someday iOS) app that utilizes a rather sizable SQLite database (20MB+). I am somewhat new to mobile app development and definitely to Xamarin. I need to control database versioning. This is a best-practice question.
Edit/Clarification: Some of the data is app/user created or maintained. Some of the data is generated via a 3rd party and is read only, in 2nd and 3rd normal form. That data must be updated with version release. Also, the user will purchase some of these data sets in-app.
My Plan:
Everytime the app opens - OnStart (), I will validate the version of the database that is supposed to exist via a configuration string against a table value in the SQLite database with version info. If the versions don't match, the database file will be copied from the APK/assets to a local folder on the device, overwriting the existing file. I definitely don't want this to happen everytime the app opens for many reasons.
3-part question:
First, is this solution a solid approach without major road blocks? Where in Xamarin (or Android project) is best to store the database version string? And finally, is there a 3rd party library (preferably nuget) which already handles database versioning? I cannot find anything like that for .NET / Xamarin. Only some Java libraries which are more Android specific.
I am well on my way to utilizing EF7 CodeFirst with SQLite...but really want to employ DB Migrations at runtime. This is a desktop application (Click-once deployment) meant to sync with a main database when connection is available, and provide offline data when no connection is present.
I have pulled down the nuget pre-release versions and all is working, except I cannot find any documentation of how to apply the migrations at runtime. I can successfully Add-Migrations and manually Apply-Migrations...but need a way to programatically Apply-Migrations at runtime.
I've also browsed the EF7 open-source project, but could not get anywhere there.
Versions I'm using: Latest Pre-release as of 9/15/2015
EntityFramework.Sqlite v7.0.0-beta7
EntityFramework.Relational v7.0.0-beta7
EntityFramework.Commands v7.0.0-beta7
...et al...you get the picture.
I am asking for help to apply runtime migrations...or what is the documented/recommended path for programatically maintaining a local/embedded db using EF7 CodeFirst SQLite?
UPDATE:
I went back to EF6 with SQLite but then found out that there is not SQLMigrationGenerator for SQLite.
EDIT:
I believe ApplyMigrations() method referenced in one of the notes has been deprecated. Searching the repository, there is no reference to "ApplyMigrations".
Today you can invoke the extension method Migrate on the DatabaseFacade.
This method is only available when the using Microsoft.Data.Entity statement is present. It comes from the RelationalDatabaseFacadeExtensions class that is part of the EntityFramework.Relational package.
Still have to find out how to migrate up and down from the API.
I started using SQLite for my project and I found there are many libraries supporting it like Qt, pysqlite, Poco C++ etc. I also found out that previous SQLite versions didn't support foreign keys.
How do the drivers know what sqlite executable to use? And how do I know they support what version of sqlite they support?
Another question: How do I enable foreign keys in sqlite by default?
The answer is: it depends.
Some applications will use a statically linked sqlite, others will link dynamically against the .dll or .so (depending on your OS). And of the ones linking against the dynamic library, whether it uses a system-wide or application-folder version depends on the application.
I (thankfully) haven't seen any apps that go through the sqlite.exe.
You need to issue pragma command to enable it
SQLite manages the foreign keys, not the ad-hoc library. Each library (if they are half-decent) will have their documentation which will list what version of SQLite is supported.
To determine if foreign keys are turned on in SQLite:
PRAGMA foreign_keys;
To turn on foreign keys:
PRAGMA foreign_keys = ON;
EDIT: This must be turned on not only before database creation, but at every connection for SQLite to activate foreign keys and their magic. (This is because foreign keys are not legacy, but is expected to change).
I am currently using SubSonic (2.2 and 3) for some ASP.NET projects and have managed to get them working with SQL Server (using ActiveRecord). However, I also want to know how to set it up with other (open source) databases, e.g. PostgreSQL and SQLite. This is so I can use it on a web host without SQL Server on. The providers I have found are:
PostgreSQL: Npgsql
SQLite: System.Data.SQLite or Mono.Data.SqliteClient (if it works with Microsoft.NET)
Anyone have any experience with SubSonic know how to do this (some sample demo would be good - just a basic primer on querying would be fine)? Non-ASP.NET MVC though (not got into it yet). I have only basic knowledge of SQLite (basically using SQLite Manager in Firefox and querying it via PHP Data Objects) and have not used Postgresql, but assume it would be more scalable than SQLite.
For version 3
PostgreSQL: There aren't any templates for postgres at the moment so you'd need to create the templates yourself
SQLite - The steps should be as follows:
Add a reference to System.Data.SQLite
Look in the TemplateProviders folder you'll find a SQLite.ttinclude which you'll need to drop into your project instead of SQLServer.ttinclude.
Change the .tt files that reference SQLServer.ttinclude to reference SQLite.ttinclude instead.
This is so I can use it on a web host without SQL Server on.
With the release of SQLExpress dont all hosts offer this? (I only use dedicated server so I have no direct experiance with this)
In response to your question.
SQLite - http://codefornothing.wordpress.com/2007/07/19/sqlite-data-provider-for-subsonic-part-2/
Postgre: Doesnt look as simple,
Subsonic postgreSQL Template
PostgreSQL via subsonic
Good luck.
In short, Subsonic only support few database only NOT ALL ( that what their claimed :( ). Try nHibernate, support most of the database.