Alias seems to break query
See original GitHub issueLibrary Version
3.0.0
.NET Runtime
.NET Core 5.0.406
Operating System / Device Details
Ubuntu 20.04
Log Output
2022-4-8 12:18:20.776+02:00 [1]| INFO) [Database] (Startup) [1] CouchbaseLite/3.0.0 (.NET; Linux 5.13.0-39-generic #44~20.04.1-Ubuntu SMP Thu Mar 24 16:43:35 UTC 2022) Build/124 LiteCore/b018a12db01222d451b4f7b95478d4825bc19954 (191) Commit/f733cb70 2022-4-8 12:18:20.795+02:00 [1]| WARNING) [Database] (Logging) [1] Database.Log.File.Config is null, meaning file logging is disabled. Log files required for product support are not being generated. 2022-4-8 12:18:20.894+02:00 [1]| ERROR) [Database] SQLite error (code 1): no such column: Label2 in "SELECT fl_result(fl_value(machines.body, ‘Id’)), fl_result(fl_value(machines.body, ‘Label’)) AS Label2, fl_result(fl_value(machines.body, ‘ModelId’)), fl_result(Label2) AS ModelLabel 2022-4-8 12:18:20.895+02:00 [1]| ERROR) [Database] no such column: Label2 (1/1) 2022-4-8 12:18:20.895+02:00 [1]| WARNING) [Database] {DB#1} SQLite error compiling statement “SELECT fl_result(fl_value(machines.body, ‘Id’)), fl_result(fl_value(machines.body, ‘Label’)) AS Label2, fl_result(fl_value(machines.body, ‘ModelId’)), fl_result(Label2) AS ModelLabel FROM kv_default AS machines LEFT OUTER JOIN kv_default AS models ON (fl_value(models.body, ‘Id’) = fl_value(machines.body, ‘ModelId’)) AND (models.flags & 1 = 0) WHERE (fl_value(machines.body, ‘Type’) = ‘machine’ AND (fl_value(machines.body, ‘Disabled’) = fl_bool(0) OR NOT (isvalued(fl_value(machines.body, ‘Disabled’))))) AND (machines.flags & 1 = 0)”: no such column: Label2 Unhandled exception. Couchbase.Lite.CouchbaseSQLiteException: CouchbaseLiteException (SQLiteDomain / 1): no such column: Label2. at LiteCore.Interop.NativeHandler.ThrowOrHandle() at LiteCore.Interop.NativeHandler.Execute(C4TryLogicDelegate1 block) at LiteCore.LiteCoreBridge.Check(C4TryLogicDelegate1 block) at Couchbase.Lite.Support.ThreadSafety.DoLockedBridge(C4TryLogicDelegate1 a) at Couchbase.Lite.Internal.Query.XQuery.Check() at Couchbase.Lite.Internal.Query.XQuery.Explain() at CouchbaseJoinBug.Program.Main(String[] args) in /home/quentin/Temps/CouchbaseJoinBug/Program.cs:line 71
Expected behavior
The query should return what it is expected ^^.
Actual behavior
It fails
Steps To Reproduce
if you alias a property to the name of another property that comes later in the query, it fails
using (var query = QueryBuilder.Select(
SelectResult.Expression(Expression.Property(nameof(MachineDTO.Label)).From(MACHINES)).As("Label2"), // removing alias or putting an other value fix the issue
SelectResult.Expression(Expression.Property(nameof(ModelDTO.Label2)).From(MODELS)).As("ModelLabel")
Reproduction Project
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)
Hi, Thanks for your answer !
We didn’t have any issue previously. It appeared when we upgraded Couchbase Lite from version 2.7.0 to 3.0.0. Do you have any idea as to why everything was fine previously and it breaks now ? Is it wanted ?
BTW, we kinda solved our problem by specifically not aliasing variables that don’t need it. For instance, instead of writing
we just write
The 2 snippets ultimately do the same thing (we get the Machine Label named as Label and the Model Label named as ModelLabel) but the second does not throw an exception.
This indeed is a LiteCore issue and it is triaged under https://github.com/couchbase/couchbase-lite-core/issues/1444