-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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]: Model::find() cannot with 'limit' param when param val has referenced #15034
Comments
Look at the error stack
|
Test.. $where = [
'conditions' => '(task_id like ?0)',
'bind' =>['%4x5alNJj%'],
'order' => 'examine_id asc',
'limit' => '10',
];
$nothing = &$where['conditions']; // here...
$data = \content\Models\ContentExamine::find($where); // throw Expection. |
with 'limit' param, error.$where = [
'conditions' => 'task_id like ?0',
'bind' =>['%4x5alNJj%'],
'limit' => 10, // the core code
];
$nothing = &$where['conditions']; // the core code
// unset($nothing);
$data = \content\Models\ContentExamine::find($where); // throw Expection. no 'limit' param, okey.$where = [
'conditions' => 'task_id like ?0',
'bind' =>['%4x5alNJj%'],
];
$nothing = &$where['conditions']; // the core code
// unset($nothing);
$data = \content\Models\ContentExamine::find($where); // okey |
Can't simulate your error... If you are unset |
root@128b1744c124:/var/www/pa/bin# cat run.php <?php
final class PA{static public $db;static public $di;}
PA::$di = new Phalcon\Di\FactoryDefault();
PA::$db = (new Phalcon\Db\Adapter\PdoFactory())->newInstance('mysql',
['adapter'=>'mysql','dbname'=>'pa_db','username'=>'root','password'=>'123456','host'=>'192.168.9.223',]
);
PA::$db->query('CREATE TABLE IF NOT EXISTS `test` (`id` int unsigned NOT NULL AUTO_INCREMENT,`name` varchar(10) NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB');
PA::$db->query('INSERT IGNORE INTO test(id,name) VALUES(1,"A"),(2,"B")');
class Test extends Phalcon\Mvc\Model{
public function initialize(){
PA::$di->set('db',PA::$db);
$this->setConnectionService('db');
$this->setDi(PA::$di);
}
}
# case 1
echo 'select * from test where id > 1 limit 10';
try{
$where = [
'conditions' => 'id > ?0',
'bind' =>[1],
'limit' => 10, # the core code!!
];
$nothing = &$where['conditions']; # the core code!!
print_r(Test::find($where)->toArray());
}catch (Throwable $e){ echo "\n",$e->getTraceAsString(); }
# case 2, no limit
echo "\n\nselect * from test where id > 1\n";
try{
$where = [
'conditions' => 'id = ?0',
'bind' =>[1],
];
$nothing = &$where['conditions'];
print_r(Test::find($where)->toArray());
}catch (Throwable $e){ echo $e->getTraceAsString(); }
# case 3, has limit
echo "\n\nselect * from test where id > 1 limit 10\n";
try{
$where = [
'conditions' => 'id > ?0',
'bind' =>[1],
'limit' => 10,
];
print_r(Test::find($where)->toArray());
}catch (Throwable $e){ echo $e->getTraceAsString(); } root@128b1744c124:/var/www/pa/bin# php run.php select * from test where id > 1 limit 10
#0 [internal function]: PDOStatement->execute()
#1 [internal function]: Phalcon\Db\Adapter\Pdo\AbstractPdo->executePrepared(Object(PDOStatement), Array, Array)
#2 [internal function]: Phalcon\Db\Adapter\Pdo\AbstractPdo->query('SELECT `test`.`...', Array, Array)
#3 [internal function]: Phalcon\Mvc\Model\Query->_executeSelect(Array, Array, Array)
#4 [internal function]: Phalcon\Mvc\Model\Query->execute()
#5 /var/www/pa/bin/run.php(28): Phalcon\Mvc\Model::find(Array)
#6 {main}
select * from test where id > 1
Array
(
[0] => Array
(
[id] => 1
[name] => A
)
[1] => Array
(
[id] => 2
[name] => B
)
)
select * from test where id > 1 limit 10
Array
(
[0] => Array
(
[id] => 2
[name] => B
)
) |
This is a Zephir issue and will be fixed in the 5.0 release. |
@Vanni-Fan What I do not understand is why are you using references in the For instance the code here: # case 1
echo 'select * from test where id > 1 limit 10';
try{
$where = [
'conditions' => 'id > ?0',
'bind' =>[1],
'limit' => 10, # the core code!!
];
$nothing = &$where['conditions']; # the core code!!
print_r(Test::find($where)->toArray());
} catch (Throwable $e) {
echo "\n",$e->getTraceAsString();
}
If you change the above code to this: # case 1
echo 'select * from test where id > 1 limit 10';
try{
$where = [
'conditions' => 'id > ?0',
'bind' =>[1],
'limit' => 10, # the core code!!
];
$nothing = $where['conditions']; # the core code!!
print_r(Test::find($where)->toArray());
} catch (Throwable $e) {
echo "\n",$e->getTraceAsString();
} I believe the same thing happens with your very first example. The What do you get if you make the following change: // Fill conditions
# the function defined is: parseWhere(array $query, array $where) <- no reference
$where = ModelHelper::parseWhere($_POST, $where);
....
.... |
Closing this - no reply/additional data. If this persists please open another issue. |
Describe the bug
Output
Screenshots
If applicable, add screenshots to help explain your problem.
Details
php --ri phalcon
)php -v
)The text was updated successfully, but these errors were encountered: