From 5b0684d677ae2806192d632b61331330e8fef924 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 9 Nov 2012 12:44:06 +0100 Subject: [PATCH 1/4] Added 2.4-compatible composer.json --- composer.json | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 composer.json diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..469257b --- /dev/null +++ b/composer.json @@ -0,0 +1,17 @@ +{ + "name": "silverstripe/postgresql", + "description": "SilverStripe now has tentative support for PostgreSQL ('Postgres')", + "type": "silverstripe-module", + "keywords": ["silverstripe", "postgresql", "database"], + "authors": [ + { + "name": "Sam Minnée", + "email": "sam@silverstripe.com" + } + ], + + "require": + { + "silverstripe/framework": "2.3.*,2.4.*" + } +} \ No newline at end of file From 618d7f11372a5920267974958e40e84b8c928b11 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 28 Nov 2012 22:07:12 +0100 Subject: [PATCH 2/4] Less restrictive compatibility notation in composer Support 2.5.x ("post-2.4") as well --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 469257b..fbad3d9 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,6 @@ "require": { - "silverstripe/framework": "2.3.*,2.4.*" + "silverstripe/framework": "~2.3" } } \ No newline at end of file From 8673583f13e749451e9f82421bd3d45988f1ee71 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 28 Nov 2012 22:48:27 +0100 Subject: [PATCH 3/4] Fixed syntax error in searchengine() --- code/PostgreSQLDatabase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index 1db0b2d..5ee6210 100755 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -1742,7 +1742,7 @@ class PostgreSQLDatabase extends SS_Database { } else { if(isset($objects)) $results = new DataObjectSet($objects); else $results = new DataObjectSet(); - $results->setPageLimits($start, $pageLength, $current+1); + $results->setPageLimits($start, $pageLength, $totalCount); return $results; } } From 4b3fd28b3b0b93c3a56bba729a9ed30f3391f0ce Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Wed, 26 Jul 2017 11:48:27 +0100 Subject: [PATCH 4/4] Backport of #48 --- code/PostgreSQLDatabase.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index 5ee6210..90e4fe4 100755 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -682,7 +682,8 @@ class PostgreSQLDatabase extends SS_Database { } // SET check constraint (The constraint HAS to be dropped) - $existing_constraint=$this->query("SELECT conname FROM pg_constraint WHERE conname='{$tableName}_{$colName}_check';")->value(); + $constraint_name = "{$tableName}_{$colName}_check"; + $existing_constraint = $this->constraintExists($constraint_name); if(isset($matches[4])) { //Take this new constraint and see what's outstanding from the target table: $constraint_bits=explode('(', $matches[4]); @@ -704,11 +705,11 @@ class PostgreSQLDatabase extends SS_Database { //First, delete any existing constraint on this column, even if it's no longer an enum if($existing_constraint) - $alterCol .= ",\nDROP CONSTRAINT \"{$tableName}_{$colName}_check\""; + $alterCol .= ",\nDROP CONSTRAINT \"{$constraint_name}\""; //Now create the constraint (if we've asked for one) if(!empty($matches[4])) - $alterCol .= ",\nADD CONSTRAINT \"{$tableName}_{$colName}_check\" $matches[4]"; + $alterCol .= ",\nADD CONSTRAINT \"{$constraint_name}\" $matches[4]"; } return isset($alterCol) ? $alterCol : ''; @@ -1031,16 +1032,16 @@ class PostgreSQLDatabase extends SS_Database { * @param string $indexSpec The specification of the index, see Database::requireIndex() for more details. */ public function alterIndex($tableName, $indexName, $indexSpec) { - $indexSpec = trim($indexSpec); - if($indexSpec[0] != '(') { - list($indexType, $indexFields) = explode(' ',$indexSpec,2); - } else { - $indexFields = $indexSpec; - } + $indexSpec = trim($indexSpec); + if($indexSpec[0] != '(') { + list($indexType, $indexFields) = explode(' ',$indexSpec,2); + } else { + $indexFields = $indexSpec; + } - if(!$indexType) { - $indexType = "index"; - } + if(!$indexType) { + $indexType = "index"; + } $this->query("DROP INDEX $indexName"); $this->query("ALTER TABLE \"$tableName\" ADD $indexType \"$indexName\" $indexFields"); @@ -1865,9 +1866,10 @@ class PostgreSQLDatabase extends SS_Database { DB::query("CREATE TABLE \"$partition_name\" (CHECK (" . str_replace('NEW.', '', $partition_value) . ")) INHERITS (\"$tableName\")$tableSpace;"); } else { //Drop the constraint, we will recreate in in the next line - $existing_constraint=$this->query("SELECT conname FROM pg_constraint WHERE conname='{$partition_name}_pkey';"); + $constraint_name = "{$partition_name}_pkey"; + $existing_constraint = $this->constraintExists($constraint_name); if($existing_constraint){ - DB::query("ALTER TABLE \"$partition_name\" DROP CONSTRAINT \"{$partition_name}_pkey\";"); + DB::query("ALTER TABLE \"$partition_name\" DROP CONSTRAINT \"{$constraint_name}\";"); } $this->dropTrigger(strtolower('trigger_' . $tableName . '_insert'), $tableName); }