bindParam gave strange result on query.php
------------------------------------------

                 Key: ZETACOMP-105
                 URL: https://issues.apache.org/jira/browse/ZETACOMP-105
             Project: Zeta Components
          Issue Type: Bug
          Components: Database
         Environment: Ubuntu Natty, AMD Athlon X2
            Reporter: Suwandi Tanuwijaya


I found some strange result from variable reference on bindParam and gave 
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

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to