question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Alias seems to break query

See original GitHub issue

Library 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

https://github.com/Billuc/CouchbaseJoinBug

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Billuccommented, Apr 9, 2022

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

SELECT
    machines.Label AS Label,
    models.Label As ModelLabel

we just write

SELECT
    machines.Label,
    models.Label AS ModelLabel

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.

0reactions
Sandychuang8commented, Apr 19, 2022

This indeed is a LiteCore issue and it is triaged under https://github.com/couchbase/couchbase-lite-core/issues/1444

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using column aliases in derived selects or views breaks ...
In your query, you have used both quoted and unquoted identifiers. Simplied test case (fails for H2 and other databases):
Read more >
Why are queries parsed in such a way that disallows ...
The MSDN docs say that the general logical parsing order is such that SELECT is parsed nearly last (thus resulting in "no such...
Read more >
MS query erases alias
Working in XL2010, I've built a complex MS Query that begs for the use of an alias for fields such as "date_format(ct.contact_date, '%b')"...
Read more >
What's the benefit of using an alias in a query? : r/SQL
Hi! I've seen people use table aliases for pretty basics queries and was wondering if this is a convention or just personal preference....
Read more >
Advanced Query Pitfalls - using alias and wildcards
A common development problem that I find while working @ Product Support is with the use of Advanced Queries in two very similar...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found