From bb14143c77e0759a0f8523d240ad56966c2318e3 Mon Sep 17 00:00:00 2001 From: hawk__ Date: Sun, 20 May 2012 12:57:04 +0000 Subject: [PATCH] Added a handle for DROP TABLE to remove sequences that are linked with the dropped table git-svn-id: https://plugins.svn.wordpress.org/postgresql-for-wordpress/trunk@546567 b8457f37-d9ea-0310-8a92-e5e31aec5664 --- pg4wp/driver_pgsql.php | 2 +- pg4wp/driver_pgsql_install.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pg4wp/driver_pgsql.php b/pg4wp/driver_pgsql.php index 2880f5c..aba2dd2 100644 --- a/pg4wp/driver_pgsql.php +++ b/pg4wp/driver_pgsql.php @@ -372,7 +372,7 @@ } // Load up upgrade and install functions as required $begin = substr( $sql, 0, 3); - $search = array( 'SHO', 'ALT', 'DES', 'CRE'); + $search = array( 'SHO', 'ALT', 'DES', 'CRE', 'DRO'); if( in_array($begin, $search)) { require_once( PG4WP_ROOT.'/driver_pgsql_install.php'); diff --git a/pg4wp/driver_pgsql_install.php b/pg4wp/driver_pgsql_install.php index 0151b0a..ceb3e18 100644 --- a/pg4wp/driver_pgsql_install.php +++ b/pg4wp/driver_pgsql_install.php @@ -207,6 +207,15 @@ WHERE pg_class.relname='$table_name' AND pg_attribute.attnum>=1 AND NOT pg_attri // Now remove handled indexes $sql = preg_replace( $pattern, '', $sql); }// CREATE TABLE + elseif( 0 === strpos($sql, 'DROP TABLE')) + { + $logto = 'DROPTABLE'; + $pattern = '/DROP TABLE.+ [`]?(\w+)[`]?$/'; + preg_match($pattern, $sql, $matches); + $table = $matches[1]; + $seq = $table . '_seq'; + $sql .= ";\nDROP SEQUENCE IF EXISTS $seq;"; + }// DROP TABLE return $sql; }