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.

Multiple conditions issue

See original GitHub issue

I`m trying to make a query something like this: SELECT * FROM ‘PersonnelTable’ WHERE country LIKE ‘%UAE%’ AND region LIKE ‘%Abu-dabi%’ AND (lastName LIKE ‘%ha%’ OR firstName LIKE ‘%ha%’)

Here is how I`m trying:

ConditionGroup conditionGroup = ConditionGroup.clause();
conditionGroup.and(Condition.column(new NameAlias("country")).like("%"+ countryName +"%"));
conditionGroup.and(Condition.column(new NameAlias("region")).like("%"+ regionName +"%"));
conditionGroup.and(Condition.column(new NameAlias("firstName")).like("%"+ firstName +"%"));
conditionGroup.or(Condition.column(new NameAlias("lastName")).like("%"+ lastName +"%"));

SQLite.select().from(PersonnelTable.class)
            .where(conditionGroup)
            .queryList();

But the problem is I cannot understand how to put brackets to condition and now my query looks like: SELECT * FROM ‘PersonnelTable’ WHERE country LIKE ‘%UAE%’ AND region LIKE ‘%Abu-dabi%’ AND lastName LIKE ‘%ha%’ OR firstName LIKE ‘%ha%’

without any brackets.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
jamesisaaccommented, Jun 11, 2016

Experienced the same issue in 3.0.0-beta5 (trailing AND when constructing a query like in this example). Refactoring out the highest level ConditionGroup solves it for me.

SQLIte.select().from(...)
    .where(...)
    .and(ConditionGroup.clause()
        .or(...)
        .or(...)
    )
1reaction
agrosnercommented, Feb 24, 2016
ConditionGroup conditionGroup = ConditionGroup.clause()
      .and(Condition.column(new NameAlias("country")).like("%"+ countryName +"%"))
      .and(Condition.column(new NameAlias("region")).like("%"+ regionName +"%"))
      .and(ConditionGroup.clause().
            .and(Condition.column(new NameAlias("firstName")).like("%"+ firstName +"%"))
           .or(Condition.column(new NameAlias("lastName")).like("%"+ lastName +"%"));

SQLite.select().from(PersonnelTable.class)
            .where(conditionGroup)
            .queryList();

Read more comments on GitHub >

github_iconTop Results From Across the Web

Living with multiple health problems - The personal impact of ...
Having multiple health conditions can affect people's ability to work and limit what they can do in their social lives. Things like pain,...
Read more >
Create Issue - Multiple Conditions - Atlassian Community
My current goal is to create a new issue based off of an assigned team custom field. We are currently moving a ticket...
Read more >
Solved: Multiple condition not working as expected
Solved: I have 24items in 4 locations and the below flow is only for one item. What I need is, whenever a quantity...
Read more >
r - case_when() issue with evaluating multiple conditions
I am trying to detect if specific keywords and phrases are present in a string, and if they are I want to post...
Read more >
Issue with multiple conditions - Jotform
I have a complex order form that depending on certain choices it changes to show different fields depending on the what they select...
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