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

Quoting behaves not as expected #226

Open
modir opened this issue Oct 14, 2021 · 4 comments
Open

Quoting behaves not as expected #226

modir opened this issue Oct 14, 2021 · 4 comments
Labels
Bug Something isn't working

Comments

@modir
Copy link

modir commented Oct 14, 2021

Bug Report

| Version(s) | 2.13.4

Current behavior

We have here an MSSQL database were we run these statements against:

	$select = new Select();
        $select->from($this->tableGateway->getTable());

        $select->columns(['Code', 'Description'])
            ->where([$platform->quoteIdentifier('Promotional Order Active') => '1'])
            ->order('Description');

        // for debugging
        $sql = new Sql($this->tableGateway->getAdapter());

        $statement = $sql->prepareStatementForSqlObject($select);

        print_r($statement->getSql());

the output is then this SQL statement:

SELECT [Company CH$Brand Product Line].[Code] AS [Code], [Company CH$Brand Product Line].[Description] AS [Description] FROM [Company CH$Brand Product Line] WHERE [\][Company] [CH$Brand] [Product] [Line].[Promotional] [Order] [Active][]] = :where1 ORDER BY [Description] ASC

As you can see there are wrong quotings after the WHERE. Once the backslash, then each word with a quote instead of all together and then at the end empty brackets.

Expected behavior

I would have expected to be like this:

SELECT [Company CH$Brand Product Line].[Code] AS [Code], [Company CH$Brand Product Line].[Description] AS [Description] FROM [Company CH$Brand Product Line] WHERE [Company CH$Brand Product Line].[Promotional Order Active] = :where1 ORDER BY [Description] ASC

@modir modir added the Bug Something isn't working label Oct 14, 2021
@ZVanoZ
Copy link
Contributor

ZVanoZ commented Nov 4, 2021

Try disable quote identifiers in parameters of the PDO connection.
For Oracle it is looks like

use Laminas\Db\Adapter\Adapter;

        $this->hostname = getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_HOSTNAME');
        $this->database = getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_DATABASE');
        $this->username = getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_USERNAME');
        $this->password = getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_PASSWORD');
        $this->dsn = sprintf('oci:dbname=//%s/%s',
            $this->hostname,
            $this->database
        );
        $driverOptions = [
            'driver' => 'pdo_oci',
            'dsn' => $this->dsn,
            'username' => $this->username,
            'password' => $this->password,
            'platform_options' => [
                'quote_identifiers' => false  // <<< !!! HERE !!!
            ],
        ];
        $adapter = new Adapter($driverOptions);

@modir
Copy link
Author

modir commented Nov 5, 2021

@ZVanoZ I already tried this. The problem is then that other things are not quoted that should be.

@alextech
Copy link
Contributor

alextech commented Nov 9, 2021

Identifier quoting issues are often related to #77 (original discussion at zendframework/zend-db#233) and maybe zendframework/zend-db#232. Maybe something in there could give a useful hint to fix in own fork fix.
quoteIdentifierChain might give better results, but those PRs need to be revisted for proper solution.

@dmetzler1988
Copy link

I have the same issue and also with brackets as table name (like Amount (LCY) which will be quoted as [Amount] [(][LCY][)]).

Is there any solution for brackets?
I had made an own fork and fixed the whitespace issue based on the closed issue 84.
But i can't find a good solution for brackets.

When this issue with whitespaces will be fixed? The solution was given 2 years ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants