Ticket #260 (closed defect: fixed)

Opened 6 months ago

Last modified 5 months ago

Error processing reults: SQLSTATE[HY000]: General error: 2053 when executing inserts or create statements.

Reported by: Ruyman Assigned to: mrook
Priority: critical Milestone: 2.3.1
Component: phing-tasks-ext Version: 2.3.0
Keywords: pdo pdo_mysql Cc:

Description

I have this build.xml file:

<?xml version="1.0"?>
<project name="pdlt" basedir="/var/xinc/projects/Corylus" default="build">
<property name="database.data" value="pdlt_data.sql"/>
<target name="updateData">
        <pdo url="mysql:host=localhost;dbname=test" userid="root" password="">
                <transaction src="${database.data}" />
        </pdo>
</target>
</project>

And this is the content of the sql file pdlt_data.sql:

CREATE TABLE IF NOT EXISTS `atributos` (
  `id` int(11) NOT NULL default '0',
  `idioma_id` varchar(255) NOT NULL default '',
  `nombre_atributo` varchar(255) NOT NULL default '',
  `creador_ip` varchar(255) default NULL,
  `modificador_ip` varchar(255) NOT NULL default '',
  `creador` varchar(255) NOT NULL default '',
  `modificador` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`id`,`idioma_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

When I run phing updateData I get the following error:

[pdo] Error processing reults: SQLSTATE[HY000]: General error: 2053

[pdo] Failed to execute: CREATE TABLE IF NOT EXISTS atributos ( id int(11) NOT NULL default '0', idioma_id varchar(255) NOT NULL default , nombre_atributo varchar(255) NOT NULL default , creador_ip varchar(255) default NULL, modificador_ip varchar(255) NOT NULL default , creador varchar(255) NOT NULL default , modificador varchar(255) NOT NULL default , PRIMARY KEY (id,idioma_id) ) ENGINE=MyISAM DEFAULT CHARSET=latin1

Execution of target "updateData" failed for the following reason: /var/xinc/projects/Corylus/build.xml:6:26: Failed to execute SQL [wrapped: 'SQLSTATE[HY000]: General error: 2053' ]

I have installed pdo and pdo_mysql through pecl and these are the versions installed in my pc:

PDO 1.0.3 stable
PDO_MYSQL 1.0.2 stable

I guess this problem is caused because in file tasks/ext/pdo/PDOSQLExecTask.php line 454, $this->processResults() is always being executed, even when there are no results from the queries, like in this case.

I think that if a formatter isn't defined, it shouldn't process any result, so I've solved this situation just replacing previous line for:

if(count($this->getConfiguredFormatters())>0)
   $this->processResults();

Attachments

Change History

07/21/08 05:30:52 changed by joey.cai@gmail.com

This problem happens because a pdo exception is thrown if users try to call fetch() or fetchAll() on a null resultset (after insert, update, create, delete, etc..). I think processResults() should only be run for select statements. Here's the patch:

diff --git a/phing/tasks/ext/pdo/PDOSQLExecTask.php b/phing/tasks/ext/pdo/PDOSQLExecTask.php
index 49adb78..aeec8bf 100644
--- a/phing/tasks/ext/pdo/PDOSQLExecTask.php
+++ b/phing/tasks/ext/pdo/PDOSQLExecTask.php
@@ -452,7 +452,10 @@ class PDOSQLExecTask extends PDOTask {
                $this->statement->execute();
                $this->log($this->statement->rowCount() . " rows affected", Project::MSG_VERBOSE);
 
-               $this->processResults();
+            //only run processResults() for select statements
+            if(preg_match('/^select/i', ltrim($sql))) {
+                $this->processResults();
+            }
 
                $this->statement->closeCursor();
                $this->statement = null;

07/29/08 15:38:33 changed by mrook

  • owner changed from hans to mrook.
  • status changed from new to assigned.

Joey, what do you think about only calling $this->processResults() when $this->statement->rowCount() is a non-zero number?

07/29/08 16:50:19 changed by Joe

Hi, mrook, PDOStatement::rowCount() may return non-zero number for update or delete statements, but PDOStatement::columnCount() will do the trick. And yes, that would be a much more elegant fix to this problem:)

07/29/08 17:47:43 changed by mrook

  • status changed from assigned to closed.
  • resolution set to fixed.

This bug has been fixed in the SVN tree, revision r382.

Thank you for the report, and for helping us make Phing better!


Add/Change #260 (Error processing reults: SQLSTATE[HY000]: General error: 2053 when executing inserts or create statements.)




Action