Skip to content
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

Bug: [QueryBuilder] Like function of Database library fails when used with Concat #3970

Closed
mmfarhan opened this issue Dec 7, 2020 · 2 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer

Comments

@mmfarhan
Copy link
Contributor

mmfarhan commented Dec 7, 2020

Hi,

it looks like there is some issue with the like function in db library:
("concat(users.name, ' ', IF(users.surname IS NULL or users.surname = '', '', users.surname)) full_name") works in the select statement but fails in the like function.
It produces this:
OR concat(users.name, ' ', IF(users.surname IS NULL or users.surname= '', '', users.surname)) LIKE :concat(users.name, ' ', IF(users.surname IS NULL orusers.surname = '', '', users.surname)): ESCAPE '!'

This simple code will result into error:

function sqlTest(){
		$search['value'] = 'perfect';
		$usersModel = new \App\Models\Users_model();
		$usersModel
				->select("concat(users.name, ' ', IF(users.surname IS NULL or users.surname = '', '', users.surname)) full_name")
				->groupStart()
				->orLike("users.email", $search['value'], 'both')
				->orLike("users.phone", $search['value'], 'both')
				->orLike("concat(users.name, ' ', IF(users.surname IS NULL or users.surname = '', '', users.surname))", $search['value'], 'both')
				->groupEnd()
				->findAll();
		
		echo $usersModel->getLastQuery();
	}
@mmfarhan mmfarhan added the bug Verified issues on the current code behavior or pull requests that will fix them label Dec 7, 2020
@mmfarhan mmfarhan changed the title Bug: Bug: Like function of Database library fails when used with Concat Dec 7, 2020
@najdanovicivan
Copy link
Contributor

najdanovicivan commented Feb 13, 2021

Try using havingLike() for concatenated value

@MGatner MGatner added the database Issues or pull requests that affect the database layer label May 18, 2021
@kenjis kenjis changed the title Bug: Like function of Database library fails when used with Concat Bug: [QueryBuilder] Like function of Database library fails when used with Concat Mar 21, 2022
@kenjis
Copy link
Member

kenjis commented May 4, 2022

@kenjis kenjis closed this as completed May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer
Projects
None yet
Development

No branches or pull requests

4 participants