Exception when trying to build a simple query
Hi, I'm following the docs in order to test the package and I've got that exception:
TypeError: Argument 1 passed to NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder::write() must implement interface NilPortugues\Sql\QueryBuilder\Manipulation\QueryInterface, instance of NilPortugues\Sql\QueryBuilder\Manipulation\ColumnQuery given, called in /www/operand_api_vuejs/public/index.php on line 33 in /www/operand_api_vuejs/vendor/nilportugues/sql-query-builder/src/Builder/GenericBuilder.php on line 216
The same code as in the docs... here
<?php
use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder;
$builder = new GenericBuilder();
$query = $builder->select()
->setTable('user')
->setColumns(['user_id','name','email']);
echo $builder->write($query);
By the way, I'm using php 7.1.
that problem is affecting everybody. i don't know why the maintainers seem to ignore such a severe bug, i couldn't build almost any of the queries i needed, and those were very basic ones -.-
anyway i'll post my workaround:
- edit this file
src/Manipulation/ColumnQuery.php - paste this function at the end:
public function end()
{
return $this->select;
}
- change your query like this:
$query = $builder->select()
->setTable('user')
->setColumns(['user_id','name','email'])
->end();
it should work now.
@sctt Great!
Thanks ever so much.
Maybe should be change like this:
public function setColumns(array $columns) { $this->columns = $columns;
return $this->select;
}
but I found another bug : leftJoin not work.
Great this post was helpful @diogocavilha @sctt