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

MYSQL : BETWEEN operator loses condition value on JOIN in (:) used #1403

Closed
TatwiraT opened this issue Nov 2, 2018 · 4 comments
Closed

MYSQL : BETWEEN operator loses condition value on JOIN in (:) used #1403

TatwiraT opened this issue Nov 2, 2018 · 4 comments
Labels
database Issues or pull requests that affect the database layer

Comments

@TatwiraT
Copy link

TatwiraT commented Nov 2, 2018

Hei,
When I tried to execute a join query
SELECT `db_adverts`.* FROM `db_adverts` INNER JOIN `db_adverts` AS `c` ON `db_adverts`.`views` <= `c`.`limit` OR **'TIMESTAMP_VALUE_HERE'** BETWEEN `c`.`start_at` AND `c`.`end_at` WHERE `db_adverts`.`desktop` = :db_adverts.desktop: AND `db_adverts`.`enable` = :db_adverts.enable: GROUP BY `db_adverts`.`id`
the query keeps only the portion before the lase occurrence of colon ":" of the value TIMESTAMP_VALUE_HERE.
I manage to bypass this issue using UNIX TIME TRANSFORMATION
thanks

@lonnieezell
Copy link
Member

Can you provide the code you use to create that query, please.

@jim-parry jim-parry changed the title MYSQL : BETWEEN OPERATOR LOOSES CONDITION VALUE ON JOIN IN (:) USED MYSQL : BETWEEN operator loses condition value on JOIN in (:) used Nov 3, 2018
@TatwiraT
Copy link
Author

TatwiraT commented Nov 6, 2018

here it is

public function get_ads( $where = array() )
	{
		$rows = $this->select(array( db_table('adverts').'.*' ))
		->where($where)
		->join(db_table('adverts') .' AS c' , db_table('adverts').'.views <= c.limit OR '.time().' < UNIX_TIMESTAMP('.db_table('adverts').'.end_at)', 'INNER')
		->orderBy('ord','ASC')
		->groupBy(db_table('adverts').'.id')
		//->getCompiledSelect();
		->findAll();
		return $rows;
	}

@jim-parry jim-parry added the database Issues or pull requests that affect the database layer label Dec 10, 2018
@lonnieezell
Copy link
Member

Looking at your query you're not quoting the time value so it would expect that to be a keyword. Also - there wouldn't be a colon in there since time() returns an integer. However, if you were using something like "04:23:58" you'd have to provide a quote around it.

This does not appear to be a bug in the framework.

@TatwiraT
Copy link
Author

actualy there is only two login on join, one is time() int, and the other is table column , not a value
thank

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database Issues or pull requests that affect the database layer
Projects
None yet
Development

No branches or pull requests

3 participants