anewt-developers team mailing list archive
-
anewt-developers team
-
Mailing list archive
-
Message #00289
[Branch ~uws/anewt/anewt.uws] Rev 1800: [database] Add AnewtDatabaseQueryExceptionConstraint
------------------------------------------------------------
revno: 1800
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt
timestamp: Tue 2010-10-26 20:59:39 +0200
message:
[database] Add AnewtDatabaseQueryExceptionConstraint
Added a new exception class to catch database constraint
errors, AnewtDatabaseQueryExceptionConstraint (extending
AnewtDatabaseQueryException), and use it appropriately in
the MySQL backend. Only MySQL's 1062 SQLSTATE: 23000
ER_DUP_ENTRY is handled for now.
This means there are now three main groups of database
exceptions (AnewtDatabaseException):
- Configuration exceptions
- Connection exceptions
- Query exceptions
- (subclass) constraint exceptions
modified:
database/backend-mysql.lib.php
database/database.lib.php
--
lp:anewt
https://code.launchpad.net/~uws/anewt/anewt.uws
Your team Anewt developers is subscribed to branch lp:anewt.
To unsubscribe from this branch go to https://code.launchpad.net/~uws/anewt/anewt.uws/+edit-subscription
=== modified file 'database/backend-mysql.lib.php'
--- database/backend-mysql.lib.php 2010-10-26 18:58:01 +0000
+++ database/backend-mysql.lib.php 2010-10-26 18:59:39 +0000
@@ -119,10 +119,21 @@
$result_set_handle = $this->connection_handle->query($sql);
if (!$result_set_handle)
- throw new AnewtDatabaseQueryException(
- 'MySQL error %d: %s',
- $this->connection_handle->errno,
- $this->connection_handle->error);
+ {
+ $errno = $this->connection_handle->errno;
+ $message = sprintf('MySQL error %d: %s', $errno, $this->connection_handle->error);
+
+ switch ($errno)
+ {
+ case 1062: /* Error: 1062 SQLSTATE: 23000 (ER_DUP_ENTRY) */
+ throw new AnewtDatabaseQueryExceptionConstraint($message);
+ break;
+
+ default:
+ throw new AnewtDatabaseQueryException($message);
+ break;
+ }
+ }
return new AnewtDatabaseResultSetMySQL($sql, $this->connection_handle, $result_set_handle);
}
=== modified file 'database/database.lib.php'
--- database/database.lib.php 2009-07-26 14:32:43 +0000
+++ database/database.lib.php 2010-10-26 18:59:39 +0000
@@ -73,6 +73,7 @@
/** Database query exception */
class AnewtDatabaseQueryException extends AnewtDatabaseException {}
+class AnewtDatabaseQueryExceptionConstraint extends AnewtDatabaseQueryException {}
/**