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

[BUG]: Can't have space in column alias field (Query Builder) #14535

Closed
JoeyOverby opened this issue Nov 15, 2019 · 7 comments · Fixed by #14964
Closed

[BUG]: Can't have space in column alias field (Query Builder) #14535

JoeyOverby opened this issue Nov 15, 2019 · 7 comments · Fixed by #14964
Assignees
Labels
bug A bug report status: low Low

Comments

@JoeyOverby
Copy link

Describe the bug
I'm unable to have a field in a query get returned that has a space in it. For example if I wanted the field 'lastName' to display as 'Last Name'

I've tried putting quotes, escaping quotes, etc in that key, but none of it will take effect.

Phalcon\Mvc\Model\Exception : Scanning error before 'First Name], Peo...' when parsing: SELECT People.firstName AS [First Name], People.lastName AS [Last Name] FROM [BMS\Test\Database\Models\People] (110)

To Reproduce

Simple use any Phalcon Model class you have to get the query builder.

Provide minimal script to reproduce the issue

/** @var \Phalcon\Mvc\Model $peopleModel */
            $peopleModel = new Models\People();
            
            $models = [
                0 => 'Models\People',
            ];
    
            $columns = [
                'First Name' => 'People.firstName',
                'Last Name'  => 'People.lastName',
            ];
    
            $builder = $peopleModel->getModelsManager()->createBuilder();
    
            $builder->from(Models\People::class);
    
            $builder->columns($columns);
    
            $query  = $builder->getQuery();
            $result = $query->execute();
// paste output here

Expected behavior
A clear and concise description of what you expected to happen.

I would expect that I could in fact re-name a column to have a space in it, like I can in SQL.
SELECT People.firstName AS First Name,

Details

  • Phalcon version: (php --ri phalcon)
    php --ri phalcon

phalcon

Web framework delivered as a C-extension for PHP
phalcon => enabled
Author => Phalcon Team and contributors
Version => 3.4.1
Build Date => Nov 12 2018 13:54:28
Powered by Zephir => Version 0.10.10-d1b4cc68d9

Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.events => On => On
phalcon.orm.virtual_foreign_keys => On => On
phalcon.orm.column_renaming => On => On
phalcon.orm.not_null_validations => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.enable_literals => On => On
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.ignore_unknown_columns => Off => Off
phalcon.orm.update_snapshot_on_save => On => On
phalcon.orm.disable_assign_setters => Off => Off

  • PHP Version: (php -v)
    PHP 7.2.18 (cli) (built: May 2 2019 13:03:01) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans
    with Zend OPcache v7.2.18, Copyright (c) 1999-2018, by Zend Technologies

  • Operating System:
    Mac OS

Additional context
Add any other context about the problem here.

@niden
Copy link
Member

niden commented Nov 17, 2019

This seems to be an issue with the PHQL parser. Assigning it to @sergeyklay to work his magic.

@JoeyOverby
Copy link
Author

JoeyOverby commented Nov 17, 2019

Thank you, this is a huge issue for me right now!

Is this possible to get done before the 4.1 release? @sergeyklay

@Jeckerson
Copy link
Member

Try with double quotes

$columns = [
    '"First Name"' => 'People.firstName',
    '"Last Name"'  => 'People.lastName',
];

@JoeyOverby
Copy link
Author

JoeyOverby commented Nov 17, 2019 via email

@Jeckerson
Copy link
Member

Last try with new \Phalcon\Db\RawValue("First name"); ?

@JoeyOverby
Copy link
Author

JoeyOverby commented Nov 18, 2019

@Jeckerson,
You can't use that type as the array key for the columns array as it isn't a string, or an integer.
image

And trying to use that to wrap/convert the string doesn't work as the string value (through __string or getValue(), still equals the string with a space)

    /**
     * Verification showing that the new RawValue function doesn't wrap or escape the string. 
     * @test
     */
    public function testUsingRawValue() : void{
        $firstNameString = new RawValue("First name");
        
        self::assertTrue($firstNameString->__toString() === "First name", "Not equal to the string representation");
        self::assertTrue($firstNameString->getValue() === "First name", "Not equal to the string representation");
        
    }

@sergeyklay
Copy link
Contributor

Implemented in 4.1.x branch

@niden niden moved this to Released in Phalcon v5 Aug 25, 2022
@niden niden added this to Phalcon v5 Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: low Low
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants