SQLitePCL.raw icon indicating copy to clipboard operation
SQLitePCL.raw copied to clipboard

sqlite3_create_collation(..., null) doesn't delete collations

Open bricelam opened this issue 4 years ago • 5 comments

using System;
using static SQLitePCL.raw;

SQLitePCL.Batteries_V2.Init();

sqlite3_open(":memory:", out var db);

sqlite3_create_collation(db, "DELETE_ME", null, (_, strA, strB) => string.CompareOrdinal(strA, strB));
sqlite3_create_collation(db, "DELETE_ME", null, null);

sqlite3_prepare_v2(db, "select group_concat(name) from pragma_collation_list", out var stmt);
sqlite3_step(stmt);
var collations = sqlite3_column_text(stmt, 0).utf8_to_string();

Console.WriteLine(collations);

The result should not contain DELETE_ME.

I suspect the wrapping hook_handle is preventing it from being deleted.

https://github.com/ericsink/SQLitePCL.raw/blob/1b2e50535cf3c3e4811197b72b7dc694715227f6/src/SQLitePCLRaw.provider.dynamic_cdecl/Generated/provider_dynamic_cdecl.cs#L798-L802

bricelam avatar Jun 01 '21 22:06 bricelam

This might just be a SQLite bug. Versions before 3.31.0 also returned deleted functions.

bricelam avatar Jun 02 '21 18:06 bricelam

I do need to investigate this a bit.

To be clear, you do not appear to be saying that this is something which was previously working and now does not?

ericsink avatar Jun 03 '21 23:06 ericsink

I don’t know if it worked previously. This is my first try and I think I only tried on the latest prerelease of e_sqlite3

bricelam avatar Jun 04 '21 03:06 bricelam

Hmmm.

I went to write a failing test for this and noticed that there is already a test case that verifies a collation gets deleted: test_collation_remove

The code in the test is different, as it verifies the removal by actually trying to use the collation and expecting an error.

So there is something more subtle going on here.

ericsink avatar Aug 25 '21 17:08 ericsink

Wait -- what is pragma_collation_list ? I expected that to be PRAGMA collation_list rather than a SELECT.

ericsink avatar Aug 25 '21 17:08 ericsink