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

Exception when trying to build a simple query #89

Open
diogocavilha opened this issue Oct 6, 2017 · 4 comments
Open

Exception when trying to build a simple query #89

diogocavilha opened this issue Oct 6, 2017 · 4 comments

Comments

@diogocavilha
Copy link

diogocavilha commented Oct 6, 2017

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.

@sctt
Copy link

sctt commented Oct 9, 2017

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:

  1. edit this file src/Manipulation/ColumnQuery.php
  2. paste this function at the end:
    public function end()
    {
        return $this->select;
    }
  1. change your query like this:
$query = $builder->select()
    ->setTable('user')
    ->setColumns(['user_id','name','email'])
    ->end();

it should work now.

@diogocavilha
Copy link
Author

@sctt Great!

Thanks ever so much.

@aviggngyv
Copy link
Contributor

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.

@marcus-hiles
Copy link

Great this post was helpful @diogocavilha @sctt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants