xp-framework / rfc

One of the major deficiencies in the development of many projects is that there is no roadmap or strategy available other than in the developers' heads. The XP team publishes its decisions by documenting change requests in form of RFCs.
2 stars 1 forks source link

New rdbms exception #58

Closed thekid closed 13 years ago

thekid commented 13 years ago

Scope of Change

A new exception will be added to the rdbms package indicating a connection loss during server query.

Rationale

Currently there is no determination which type of error caused an SQLException during query. Sometimes it's helpful to know if a connection has been closed by foreign host.

Functionality

Changes to existing classes

The query() method of the rdbms.DBConnection subclasses will be changed and in cases where the connection was lost during query a new Exception will be thrown. This exception extends rdbms.SQLStatementFailedException to avoid bc-breakes.

Example patch excerpt for rdms.mysql:

<?php
  if ($this->flags & DB_UNBUFFERED) {
    $result= mysql_unbuffered_query($sql, $this->handle, $this->flags & DB_STORE_RESULT);
  } else {
    $result= mysql_query($sql, $this->handle);
  }

  if (FALSE === $result) {
    switch ($e= mysql_errno($this->handle)) {
      case 2013: // Lost connection to MySQL server during query
        return throw(new SQLConnectionClosedException(
          'Statement failed: '.mysql_error($this->handle), 
          $sql, 
          $e
        ));
        break;

      default:  
        return throw(new SQLStatementFailedException(
          'Statement failed: '.mysql_error($this->handle), 
          $sql, 
          $e
        ));
    }
  }
?>

New Exceptions

A new exception rdbms.SQLConnectionClosedException will be added to the repository. This class extends rdbms.SQLStatementFailedException.

Security considerations

n/a

Speed impact

n/a

Dependencies

thekid commented 13 years ago

Need to test this for Sybase and PostgreSQL, too.

friebe, Mon, 12 Jun 2006 11:02:08 +0200

thekid commented 13 years ago

Maybe ConnectionClosedException should be SQLConnectionClosedException? - just to be consistent with the rest of the SQL* exceptions...

friebe, Mon, 12 Jun 2006 11:24:55 +0200

thekid commented 13 years ago

Discussion with RFC author - SQLConnectionClosedException is OK.

friebe, Mon, 12 Jun 2006 11:48:38 +0200