Doctrine 1
  1. Doctrine 1
  2. DC-756

Cannot use named parameters in a 'limit(':max') clause

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      ubuntu, apache, symfony version 1.4.4

      Description

      $modulus=5;
      $offset=2;
      $this->Statuses['ready']=1;

      This works
      ---------------------------------
      $DetailsList=
      Doctrine_Query::create()->from('Data s')
      ->where('s.status_id=:status_id')
      ->andWhere('((s.id % :modulus) - :offset)=0')
      ->orderBy('s.id')
      ->limit($maxDaysDetailsToProcess)
      >execute(array(':status_id'=>$this>Statuses['ready'],
      ':modulus'=>$modulus,
      ':offset'=>$offset), Doctrine::HYDRATE_ARRAY);

      This does not, it gets the whole table
      ---------------------------------
      $DetailsList=
      Doctrine_Query::create()->from('Data s')
      ->where('s.status_id=:status_id')
      ->andWhere('((s.id % :modulus) - :offset)=0')
      ->orderBy('s.id')
      ->limit(':max')
      >execute(array(':status_id'=>$this>Statuses['ready'],
      ':modulus'=>$modulus,
      ':offset'=>$offset,
      ':max'=>$maxDaysDetailsToProcess), Doctrine::HYDRATE_ARRAY);

        Activity

        Hide
        Dennis Gearon added a comment -

        I noticed an error in the code, which does not solve the problem, only confuse whomever works on it Please add

        $maxDaysDetailsToProcess=3;

        as the fourth line in the code.

        Show
        Dennis Gearon added a comment - I noticed an error in the code, which does not solve the problem, only confuse whomever works on it Please add $maxDaysDetailsToProcess=3; as the fourth line in the code.
        Hide
        Juan Antonio Galán added a comment -

        I think I found a solution but it's making some tests fail. Let me explain you what I did:

        First I removed any casting to int of the limit value, in order to keep the named parameter in the LIMIT part of the query. Actually this named parameters were converted to 0 due to those int castings.

        Then I realized that the params are bound as strings so the resulting query looks like ... LIMIT "2" or whatever you put in the limit value, and mysql throws and error. Then I tryed to modify the function that binds the paramters to bind them as integers when they're not strings. Everything seems to work fine and you could put named parameters in the limit clause, but some tests are failing. If you look at the tests that are failing you'll see that they're failing because of a wrong phone number, the test it's expecting a number large number like 6155139185 but the result array has a number like 1860171889. I'm wondering if there's something wrong when binding numbers bigger than mysql INT as integers.

        I attach a diff file with the changes I did, hope it helps

        Show
        Juan Antonio Galán added a comment - I think I found a solution but it's making some tests fail. Let me explain you what I did: First I removed any casting to int of the limit value, in order to keep the named parameter in the LIMIT part of the query. Actually this named parameters were converted to 0 due to those int castings. Then I realized that the params are bound as strings so the resulting query looks like ... LIMIT "2" or whatever you put in the limit value, and mysql throws and error. Then I tryed to modify the function that binds the paramters to bind them as integers when they're not strings. Everything seems to work fine and you could put named parameters in the limit clause, but some tests are failing. If you look at the tests that are failing you'll see that they're failing because of a wrong phone number, the test it's expecting a number large number like 6155139185 but the result array has a number like 1860171889. I'm wondering if there's something wrong when binding numbers bigger than mysql INT as integers. I attach a diff file with the changes I did, hope it helps

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Dennis Gearon
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: