Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6952963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:25:01+00:00 2026-05-27T14:25:01+00:00

I wrote a custom DQL function. In this function I use the same parameter

  • 0

I wrote a custom DQL function. In this function I use the same parameter twice:

public function getSql(SqlWalker $sqlWalker)
{
    $point1_lat = $this->point1_lat->dispatch($sqlWalker);
    $point1_lon = $this->point1_lon->dispatch($sqlWalker);
    $point2_lat = $this->point2_lat->dispatch($sqlWalker);
    $point2_lon = $this->point2_lon->dispatch($sqlWalker);

    $unitFactor = 6366.56486; // earth radius in km

    return "
        $unitFactor *
        2 * 
        ASIN(
            SQRT(
                POWER(
                    SIN(($point1_lat - $point2_lat) * pi()/180/2),
                    2
                ) + 
                COS($point1_lat * pi()/180) * 
                COS($point2_lat * pi()/180) * 
                POWER(
                    SIN(($point1_lon - $point2_lon) * pi()/180/2), 
                    2
                )
            )
        )
    ";
}

This is how the query is executed:

    $q = \App::get()->getEntityManager()->createQuery('
        SELECT
            s,
            GEO_DISTANCE(
                :lat, 
                :lng,
                s.glat,
                s.glng
            ) AS distance
        FROM
            \Application\Geo\Entity\Street s
    ');
    $q->setMaxResults(10);
    $q->setParameters(array(
        'lat' => 52.25948,
        'lng' => 6.76403,
    ));
    $result = $q->getResult();

This however gives me the following exception:

Message: SQLSTATE[HY093]: Invalid parameter number: number of bound
variables does not match number of tokens

The following SQL is returned by getSql():

        6366.56486 *
        2 * 
        ASIN(
            SQRT(
                POWER(
                    SIN((? - g0_.glat) * pi()/180/2),
                    2
                ) + 
                COS(? * pi()/180) * 
                COS(g0_.glat * pi()/180) * 
                POWER(
                    SIN((? - g0_.glng) * pi()/180/2), 
                    2
                )
            )
        )

So I guess the exception is thrown because the named parameters are returned as indexed parameters. Is this a bug in doctrine or am I doing something wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:25:02+00:00Added an answer on May 27, 2026 at 2:25 pm

    This is not a bug, you can only use each parameter once, as the dispatch() function puts the value on the stack once, to match one ? placeholder in the query.

    As a workaround, you can call dispatch() several times:

    public function getSql(SqlWalker $sqlWalker)
    {
        $point1_lat_a = $this->point1_lat->dispatch($sqlWalker);
        $point1_lat_b = $this->point1_lat->dispatch($sqlWalker);
        $point1_lon = $this->point1_lon->dispatch($sqlWalker);
    
        $point2_lat_a = $this->point2_lat->dispatch($sqlWalker);
        $point2_lat_b = $this->point2_lat->dispatch($sqlWalker);
        $point2_lon = $this->point2_lon->dispatch($sqlWalker);
    
        $unitFactor = 6366.56486; // earth radius in km
    
        return "
            $unitFactor *
            2 * 
            ASIN(
                SQRT(
                    POWER(
                        SIN(($point1_lat_a - $point2_lat_a) * pi()/180/2),
                        2
                    ) + 
                    COS($point1_lat_b * pi()/180) * 
                    COS($point2_lat_b * pi()/180) * 
                    POWER(
                        SIN(($point1_lon - $point2_lon) * pi()/180/2), 
                        2
                    )
                )
            )
        ";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

to custom validate an input i wrote a script: function cardNumberCheck(value, element) { var
I wrote a custom validation handler for this ASP.NET MVC application. Here is a
I've wrote custom model binder in project, that uses ASP.NET MVC 2. This model
I wrote simple custom validation on javascript based on this doc . I want
I'll try to make this as short as I can. I wrote a custom
I wrote a custom web part for SharePoint 2007 that loads an existing user
I wrote a custom URL rewriting module, to take certain paths and map them
I wrote a custom WCF binding a while back to allow my load balanced
I wrote a custom ordering LINQ extension method as below but I think it
I have wrote a custom MultipleChoiceField. I have everything working ok but when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.