Ticket #260 (closed defect: fixed)
Error processing reults: SQLSTATE[HY000]: General error: 2053 when executing inserts or create statements.
| Reported by: | Ruyman | Owned by: | 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
comment:2 Changed 2 years ago 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?

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;