Skip to content

Wrong parse query with placeholders #320

Open

Description

@ksandrj

Version: 3.2.6

Bug Description

The issue likely originated in the following commit 7972f60
SQL placeholders are being misinterpreted during query compilation, resulting in invalid syntax.

Steps To Reproduce

The following code is a simplified excerpt from a larger query, but it still demonstrates the issue

$where = [
    'sublog.id >= ?' => $oldestRowId,
] ;

$query = $this->db->query(
    'SELECT duration WHERE ?',
    $where,
);

This generates the following invalid SQL

SELECT duration 
WHERE (`sublog`.`id` >= 39 ?)

Expected Behavior

The query should compile to valid SQL like this

SELECT duration 
WHERE (`sublog`.`id` >= 39)

Activity

  1. dg commented on Jun 18, 2025

    @dg
    Member

    It is assumed that there will be no question mark, i.e. 'sublog.id >=' => $oldestRowId - https://doc.nette.org/en/database/sql-way#toc-where-conditions

    This seems to have worked by mistake before - it threw away everything after the operator.

  2. smuuf commented on Jun 24, 2025

    @smuuf
    Contributor

    It is assumed that there will be no question mark

    This behavior seems quite inconsistent with how the other part of nette/database behave - such as what's documented in Explorer docs:

    // WHERE (`age` > 18) AND (ROUND(`score`, 2) > 75.5)
    $table->where([
    	'age > ?' => 18,
    	'ROUND(score, ?) > ?' => [2, 75.5], // two parameters are passed as an array
    ]);

    ... where the question marks are processed correctly. This new behavior of Connection::query() does feel like a bug. 🤔 And even more so if this behavior (resulting in doubling of the question marks) ultimately results in a badly formed SQL and is not intercepted by nette/database itself.

    Couldn't (shouldn't) the parameter-passing-through-assoc-array-with-question-marks-in-keys API be unified?

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