Can't have two conditions (sqlLiteral) with same argument(s)

Notice: This thread is very old.
genesiscz
Member | 21
+
0
-

Code:

<?php
$table = $database->table("table");
$table->where(new SqlLiteral("DATE(start) >= ?"), "2014-10-10");
$table->where(new SqlLiteral("DATE(start) <= ?"), "2014-10-10");

This searchs only for the first conditional.

Reason:

SqlBuilder.php around line 137:

$hash = md5(json_encode($args));
if (isset($this->conditions[$hash])) {
	return FALSE;
}

the problem is that $args[0] has SqlLiteral which is encoded to blank object

if ($args[0] instanceof \Nette\Database\SqlLiteral) {
	dump($args);
	dump(json_encode($args));
	die();
}

results in:

array(2) [
   0 => Nette\Database\SqlLiteral(1) {
      value private => "DATE(start) >= ?" (16)
   }
   1 => "2014-10-10" (10)
]
"[{},"2014-10-10"]" (17)

Problem:
Any SqlLiteral is encoded to an empty object in any case, so we need to find another way of hashing arguments.

Last edited by genesiscz (2014-01-15 19:43)

Milo
Nette Core | 1283
+
0
-

IMHO, every SqlLiteral should be casted to string (SQL) before hashing.

genesiscz
Member | 21
+
0
-

Yeah, that sounds like a good idea.

hrach
Member | 1834
+
0
-

You do it wrong.

$table = $database->table("table");
$table->where("DATE(start) >= ?", "2014-10-10");
$table->where("DATE(start) <= ?", "2014-10-10");