Uploaded image for project: 'Zeta Components'
  1. Zeta Components
  2. ZETACOMP-105

bindParam gave strange result on query.php

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • Database
    • Ubuntu Natty, AMD Athlon X2

    Description

      I found some strange result from variable reference on bindParam and gave me quite a lot to figure out what happened with the strange result. I do not know if this issue results from PDO library or Zeta.

      My test on QueryInsert library on testingSeveralInsertOnDatabase section give me the strange result:
      and Here is chunk of test code:
      {{{
      ...
      function testingSeveralInsertOnDatabase()

      { $q = $this->q; $section = 'Norway'; $company = 'cfSystem'; $q->insertInto('query_test') ->set( 'id', 1 ) ->set( 'section', $q->bindParam( $section ) ) ->set( 'company', $q->bindParam( $company ) ) ->set( 'employees', 20 ); $statement = $q->prepare(); $statement->execute(); $company = 'IBM'; $section = 'Norway'; $q->insertInto('query_test') ->set( 'id', 2 ) ->set( 'employees', 70 ); $statement = $q->prepare(); $statement->execute(); $db = Core\Singleton::get(); $q = $db->createSelectQuery(); $e = $q->expr; $q->select('*') ->from('query_test'); $statement = $q->prepare(); $statement->execute(); $result = $statement->fetchAll(); /* $this->dump( $result ); */ $q->reset(); $q->select('*') ->from('query_test') ->where( $e->eq( 'id', 1 ) ); $statement = $q->prepare(); $statement->execute(); $result = $statement->fetchAll(); $this->assertEqual( 1, $result[0]['id'] ); $this->assertEqual( 'cfSystem', $result[0]['company'] ); $q->reset(); $q->select('*') ->from('query_test') ->where( $e->eq( 'id', 2 ) ); $statement = $q->prepare(); $statement->execute(); $result = $statement->fetchAll(); $this->assertEqual( 2, $result[0]['id'] ); $this->assertEqual( 'IBM', $result[0]['company'] ); }

      ...
      }}}

      I am expecting result for this:
      {{{
      Array
      (
      [0] => Array
      (
      [id] => 1
      [0] => 1
      [company] => cfSystem
      [1] => cfSystem
      [section] => Norway
      [2] => Norway
      [employees] => 20
      [3] => 20
      )

      [1] => Array
      (
      [id] => 2
      [0] => 2
      [company] => IBM
      [1] => IBM
      [section] => Norway
      [2] => Norway
      [employees] => 70
      [3] => 70
      )

      )
      }}}

      but the component gives me result of this:
      {{{
      Array
      (
      [0] => Array
      (
      [id] => 1
      [0] => 1
      [company] => cfSystem
      [1] => cfSystem
      [section] => cfSystem
      [2] => cfSystem
      [employees] => 20
      [3] => 20
      )

      [1] => Array
      (
      [id] => 2
      [0] => 2
      [company] => IBM
      [1] => IBM
      [section] => IBM
      [2] => IBM
      [employees] => 70
      [3] => 70
      )

      )
      }}}

      I suspect this issue arises from & (by-reference) operator of bindParam method on ezcQuery class.
      My quick-fix is change code on ezcQuery class, doBind method from bindParam to bindValue since BindValue have exactly what result I needed.

      {{{
      ...
      foreach( $this->boundParameters as $key => $val )
      {
      try

      { /* $statement->bindParam( $key, $val, $this->boundParametersType[$key] ); */ $statement->bindValue( $key, $val, $this->boundParametersType[$key] ); }

      catch( \PDOException $e ) { }
      }
      ...
      }}}

      tha'ts all

      Attachments

        Activity

          People

            Unassigned Unassigned
            freelancecode Suwandi Tanuwijaya
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 2h
                2h
                Remaining:
                Remaining Estimate - 2h
                2h
                Logged:
                Time Spent - Not Specified
                Not Specified