cvs: pear /MDB2/MDB2/Driver/Manager pgsql.php
[email protected] ("Lorenzo Alberton")
| Newsgroups | php.pear.cvs |
|---|---|
| Message-ID | <cvsquipo1210690771@cvsserver> |
quipo Tue May 13 14:59:31 2008 UTC
Modified files:
/pear/MDB2/MDB2/Driver/Manager pgsql.php
Log:
fixed bug #13877 in dropConstraint(): UNIQUE index not always recognized as constraint
http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Manager/pgsql.php?r1=1.83&r2=1.84&diff_format=u
Index: pear/MDB2/MDB2/Driver/Manager/pgsql.php
diff -u pear/MDB2/MDB2/Driver/Manager/pgsql.php:1.83 pear/MDB2/MDB2/Driver/Manager/pgsql.php:1.84
--- pear/MDB2/MDB2/Driver/Manager/pgsql.php:1.83 Tue May 13 14:23:04 2008
+++ pear/MDB2/MDB2/Driver/Manager/pgsql.php Tue May 13 14:59:30 2008
@@ -42,7 +42,7 @@
// | Author: Paul Cooper <[email protected]> |
// +----------------------------------------------------------------------+
//
-// $Id: pgsql.php,v 1.83 2008/05/13 14:23:04 quipo Exp $
+// $Id: pgsql.php,v 1.84 2008/05/13 14:59:30 quipo Exp $
require_once 'MDB2/Driver/Manager/Common.php';
@@ -738,6 +738,57 @@
}
// }}}
+ // {{{ dropConstraint()
+
+ /**
+ * drop existing constraint
+ *
+ * @param string $table name of table that should be used in method
+ * @param string $name name of the constraint to be dropped
+ * @param string $primary hint if the constraint is primary
+ *
+ * @return mixed MDB2_OK on success, a MDB2 error on failure
+ * @access public
+ */
+ function dropConstraint($table, $name, $primary = false)
+ {
+ $db =& $this->getDBInstance();
+ if (PEAR::isError($db)) {
+ return $db;
+ }
+
+ // is it an UNIQUE index?
+ $query = 'SELECT relname
+ FROM pg_class
+ WHERE oid IN (
+ SELECT indexrelid
+ FROM pg_index, pg_class
+ WHERE pg_class.relname = '.$db->quote($table, 'text').'
+ AND pg_class.oid = pg_index.indrelid
+ AND indisunique = \'t\')
+ EXCEPT
+ SELECT conname
+ FROM pg_constraint, pg_class
+ WHERE pg_constraint.conrelid = pg_class.oid
+ AND relname = '. $db->quote($table, 'text');
+ $unique = $db->queryCol($query, 'text');
+ if (PEAR::isError($unique) || empty($unique)) {
+ // not an UNIQUE index, maybe a CONSTRAINT
+ return parent::dropConstraint($table, $name, $primary);
+ }
+
+ if (in_array($name, $unique)) {
+ return $db->exec('DROP INDEX '.$db->quoteIdentifier($name, true));
+ }
+ $idxname = $db->getIndexName($name);
+ if (in_array($idxname, $unique)) {
+ return $db->exec('DROP INDEX '.$db->quoteIdentifier($idxname, true));
+ }
+ return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
+ $name . ' is not an existing constraint for table ' . $table, __FUNCTION__);
+ }
+
+ // }}}
// {{{ listTableConstraints()
/**