Skip to content

SqlPreprocessor generates wrong query for UNION #248

@KacerCZ

Description

@KacerCZ

Version: 3.0.5

Bug Description

When running SQL query with UNION and with limit set on result of UNION, parameters are inserted directly into query and not passed via placeholders.

(select id from product where id<?) union (select id from product) limit ? offset ?

Steps To Reproduce

Run following code:

$database = $this->context->getByType(\Nette\Database\Connection::class);
$database->query('(select id from product where id<?) union (select id from product) limit ? offset ?', 3, 5, 2);

Generated query:

(select id from product where id<'3') union (select id from product) limit '5' offset '2'

Result is exception "SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''5' offset '2'' at line 1".

Database is MariaDB, used driver class is MySqlDriver from nette/database.

Expected Behavior

Placeholders are used and query after preprocessing looks like this:

(select id from product where id<?) union (select id from product) limit ? offset ?

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