ccmbenchmark / ting

Lightweight PHP datamapper
http://tech.ccmbg.com/ting/doc/3.x/en/index.html
Apache License 2.0
1 stars 5 forks source link

execute with no params use prepared queries and crashes with postgresql #23

Closed robotccm closed 8 years ago

robotccm commented 8 years ago

Original report by Yannick Le Guédart (Bitbucket: Torgan, GitHub: Torgan).


I'm trying to execute the following SQL statement using ting :

DROP SCHEMA IF EXISTS external CASCADE;
CREATE SCHEMA external;

No params, so I'm just using getQuery since I do not wish a prepared one (using Symfony3 and ting-bundle in a command) :

            $this
                ->getContainer()
                ->get('ting')
                ->get('\ModelBundle\Repository\AdminRepository');
                ->getQuery('
                    DROP SCHEMA IF EXISTS external CASCADE;
                    CREATE SCHEMA external;
                ')
                ->execute()

Unfortunately, it looks like ting is using a prepared query, which can't be done with multiple commands :

  [Symfony\Component\Debug\Exception\ContextErrorException]                                                    
  Warning: pg_query_params(): Query failed: ERROR:  cannot insert multiple commands into a prepared statement  
robotccm commented 8 years ago

Original comment by Yannick Le Guédart (Bitbucket: Torgan, GitHub: Torgan).


(And I know I can separate queries, I just think it should work that way :) )

robotccm commented 8 years ago

Original comment by Sylvain Robez-Masson (Bitbucket: srobez-masson, ).


In fact, Ting use pg_query_params in all case not pg_send_prepare. But the Postgres driver seems to fail if you insert multiple query with pg_query_params without params.

robotccm commented 8 years ago

Original comment by Yannick Le Guédart (Bitbucket: Torgan, GitHub: Torgan).


So the solution seems to be : replace line 205 in Ting/Driver/Pgsql/Driver :

        if ([] === $values) {
            $this->result = pg_query($this->connection, $sql);
        } else {dump($values);
            $this->result = pg_query_params($this->connection, $sql, $values);
        }
robotccm commented 8 years ago

Original comment by Xavier Leune (Bitbucket: [Xavier Leune](https://bitbucket.org/Xavier Leune), ).


Merged in master