Skip to content

Exception when trying to build a simple query #89

Open

Description

@diogocavilha

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.

Activity

  1. sctt commented on Oct 9, 2017

    @sctt

    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.

  2. diogocavilha commented on Oct 9, 2017

    @diogocavilha
    Author

    @sctt Great!

    Thanks ever so much.

  3. aviggngyv commented on Oct 27, 2017

    @aviggngyv
    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.

  4. marcus-hiles commented on Mar 29, 2019

    @marcus-hiles

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions