-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Microsoft.Data.Sqlite: Implement Data Change Notifications Callback #13827
Comments
Since we expose the native handle, one workaround could be: sqlite3_update_hook(
connection.Handle,
(user_data, type, database, table, rowid) => { /* TODO: Handle it. */ },
null); |
What about the following addition to SqliteConnection:
with
See https://github.com/AlexanderTaeschner/Microsoft.Data.Sqlite/commit/a3b0938cd42c5207723c01c0be1c54aa661afdb5 for a test implementation. |
Does System.Data.SQLite expose any API for it? |
I didn't look at System.Data.SQLite before I made my suggestion. System.Data.SQLite.SQLiteConnection has the following event:
with
|
We should keep the event name |
There might be some value in re-using the type and member names too... (UpdateEventType, Event, and RowId) But I'll leave that up to you. |
To move forward on this, we'll need to create a test that fails with the current implementation so we can debug and be confident in our fix. The fix may belong in SQLitePCL.raw |
Are the failures you are seeing reproducible or could it be, that the fact that neither SQLitePCL.raw nor this library is thread safe is the real problem? |
FWIW, I am following along with this and #441, interested in the possibility that I might need to make a fix of some kind. |
I haven't seen them locally. They only seem to be on the CI configuration that run all of the ASP.NET and EF Core tests together. I suspect it's a multi-threaded race condition or something. |
@bricelam Any update? Is it likely to be in 3.0 release? |
It's more or less on hold. Someone needs to dig into the EF Core failures to fully understand them. It isn't currently a priority for our team, so someone from the community will need to drive the effort. |
Issue #441 is about renaming the OnModelCreating argument from builder to modelBuilder. How is this related to data change notifications callback? Was the issues migrated from another repository without fixing the issue numbers? I am confused. 😕 |
Yep, migrated. See aspnet/Microsoft.Data.Sqlite#441 |
Looking for documentation or examples for SqliteDataChangeEventHandler if possible? |
No docs. This feature isn't implemented yet.
|
I was experimenting with this, sqlite3_update_hook seems to be firing on changes happening per connection. It makes it rather useless for multi process subscribers/events. It might still be useful for someone, it can be of course used even if the patch never lands, just use it directly from SQLitePCL.raw: public static void ListenSqlite(DbContext context)
{
context.Database.OpenConnection();
var c = context.Database.GetDbConnection() as SqliteConnection;
SQLitePCL.raw.sqlite3_update_hook(c.Handle, test_func, new object());
}
static readonly delegate_update test_func = (db, wint, char1, char2, sqlitei64) =>
{
Console.WriteLine("Yeah?");
}; In CSProj: <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.0" />
<PackageReference Include="SQLitePCLRaw.core" Version="2.0.7" /> |
@Ciantic Can somebody else confirm this? It would make the Sqlite documentation irresponsibly misleading as it says nothing about this restriction and it would make this feature indeed almost entirely useless. Each connection itself obviously already knows what it does. If that's true they need to update their docs. |
I just got confirmation that @Ciantic is correct. |
💯 Completely agree--that's why this really hasn't been a priority for the team. Just track your own changes in app code. |
Most people are probably looking for an event that will fire when data is changed by another process. This is not that. |
Is there a workaround to listen for changes made by other processes? |
AFAIK, SQLite doesn't have a feature to do that. You can probably use FileSystemWatcher and some sort of journal table (like DotMim.Sync uses) to design your own. |
This event can be registered on each connection and directed to the same delegate. In this way, at least within the process, we get event notifications for all connections. |
Data Change Notifications Callback
Unable to register a callback on the SqliteConnection object for updates to specified tables
Functional impact
With separate App/DbContext instances I would like callbacks to be called in a second instance when one instance updates a table row. This will allow for performant responsive applications.
Minimal repro steps
Functionality is missing
Expected result
Register a callback on the SqliteConnection for a specific table/set of tables, perhaps for types of table changes, to allow my code to react to table updates.
Actual result
No functionality exists to support this
Further technical details
https://sqlite.org/c3ref/update_hook.html
CC: @bricelam
The text was updated successfully, but these errors were encountered: