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).
Related
I've got a .Net Core appl and am using the System.Data.SQLite.dll package to connect to a SQLite DB.
I'm trying to encrypt the database with a password.
In version 1.0.93.0 of System.Data.SQLite.dll library I can set or change the password encryption of the database:
SQLiteConnection con = new SQLiteConnection($"Data Source=DBName;Version=3;");
conn.SetPassword($"{password}");
conn.ChangePassword($"{password}");
conn.Open();
In the latest version 1.0.113.7 the api's no longer to appear to be supported.
Visual Studio throws a compiler error on the SetPassword() and ChangePassword() calls.
How do I password encrypt my databases?
Is there another way to achieve this using this library (or something similar)?
Yes, it seems that starting with System.Data.SQLite version 1.0.113.0, support for encryption in this way was entirely removed in this checkin, by modifying the file /Targets/SQLite.NET.Settings.targets, and setting the value of InteropCodec to false.
Specifically the comment says "Merge all changes needed for the SQLite core library 3.32.0 release."
This reveals to us that the actual culprit is SQLite itself, where in release 3.32.0, they removed support for this type of encryption API as well, in this commit, where the comment says "simplify the code by removing the unsupported and undocumented SQLITE_HAS_CODEC compile-time option"
Neither the change in System.Data.SQLite nor in SQLite are documented in the release notes for these projects.
In prior versions of System.Data.SQLite, such as 1.0.112.1 and earlier, encryption via the SetPassword() method was supported, and this used the “SQLite Encryption Extension” (SEE)
After attaching the second database I tried to insert and update data in the table of the first database using ON CONFLICT(id) DO UPDATE. Field id is the primary key for the first table.
FDQuery1.EXECSQL('ATTACH ''D:\Update2019.DB'' AS DBUpdate');
FDQuery1.SQL.Text:=
'INSERT INTO acts (id,title) SELECT id,title FROM DBUpdate.acts'+
' WHERE (DBUpdate.acts.id >100)'+
' ON CONFLICT(id) DO UPDATE SET'+
' title=excluded.title;'
FDQuery1.ExecSQL;
I get error message: "ERROR near "ON":syntax error"
When I removed WHERE (DBUpdate.acts.id >100 condition
the error message AS: "ERROR near "DO":syntax error".
The same query works fine in SQLITESTUDIO.
As correctly indicated in comments, SQLite that your application uses does not support this syntax. You will need to use newer version of SQLite. To do this, follow the Dynamic linking paragraph of FireDAC SQLite connection topic, otherwise Delphi builds your FireDAC application with statically linked SQLite objects of the version distributed with it (which makes your application dependent on such SQLite version no matter what SQLite DLLs are all around).
Just don't forget the most important part of this task; modifying the FireDAC.inc include file to use dynamic linking. If you don't want to break your Delphi setup source folder, copy for example all the FireDAC modules somewhere else, add them into the build search path of your project, and modify the FireDAC.inc include file there.
I'm knee deep in compilation for sqlite, system.data.sqlite, and xerial's JDBC trying to get an encrypted sqlite file working through all three. From my understanding, system.data.sqlite uses RC4 encryption, and SQLCipher/Rijndael/wxSqlite can use AES256.
Using this library, one can easily compile Windows binaries for AES256 encryption.
This library offers Xerial's JDBC by incorporating wxsqlite3's improvements, which it looks like is actually based on the above (Rijndael's) library.
Because the above two libraries are close to one-and-the-same, and use the same encryption, they have been compatible. I have a working Java project with the encryption-supporting JDBC, and I have a compiled sqlite3.dll and sqlite3shell.exe that allows me to use the command line to encrypt, read, write, etc databases. This sqlite dll and shell are compatible with the databases created with the JDBC.
Where I'm a bit lost is getting system.data.sqlite working with AES256. I need to use this library as it affords me the ability to use Entity Framework and LINQ. I had thought it would not be such an arduous task, but I've been ramming my head into a wall for the past few days on this issue. I have the encryption-ready sqlite3 dll, how do I merge this in with system.data.sqlite?
Thanks so much for any help.
If you're targeting .NET standard 4.6.1+ or Core, you may want to give Microsoft.Data.Sqlite a try. This can give you AES256 encryption by simply adding 2 Nuget Packages. By the way, there are paid options to get AES256 compiled System.Data.Sqlite. Some are listed in this answer.
If your project is currently using System.Data.Sqlite, then transitioning will involve some search/replace of method & class names, much of which is a difference in caps. For example, "SQLiteDataReader" becomes "SqliteDataReader."
Another difference is that Microsoft.Data.Sqlite is strict about column naming. For example, a command that references a column named "DateListed" will fail if the database schema has that column as "Datelisted."
If you want to explore making a transition install 2 nuget packages:
Install-Package Microsoft.Data.Sqlite.Core
Install-Package SQLitePCLRaw.bundle_sqlcipher
Setup SQLitePCL
SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlcipher());
SQLitePCL.Batteries_V2.Init();
SQLitePCL.raw.FreezeProvider();
Create encrypted database
string error = string.Empty;
static SQLitePCL.sqlite3 sqlite
SQLitePCL.raw.sqlite3_open(dbPath, out sqlite);
SQLitePCL.raw.sqlite3_exec(sqlite, "PRAGMA key ='myPassword'", out error);
SQLitePCL.raw.sqlite3_close(sqlite);
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));
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.