From 7fb82f88d1415d8dcc360ef211d1d026307963c1 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 11 Mar 2011 14:25:10 +1300 Subject: [PATCH 1/6] BUGFIX Renamed clear_cached_fieldlist() to clearCachedFieldlist() to comply with parent implementation and our coding conventions (fixes 360176d2) --- code/PostgreSQLDatabase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index 9cd6f52..4716bd7 100755 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -872,7 +872,7 @@ class PostgreSQLDatabase extends SS_Database { * * @return boolean */ - function clear_cached_fieldlist($tableName=false){ + function clearCachedFieldlist($tableName=false){ if($tableName!=false){ unset(self::$cached_fieldlists[$tableName]); } else From 2b0ffdb4e02a7e8557779b7cf0654265dbe727a9 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 11 Mar 2011 16:43:27 +1300 Subject: [PATCH 2/6] API CHANGE Renamed transactions methods from endTransaction() to transactionEnd(), startTransaction() to transactionStart() to comply with new sapphire trunk API --- code/PostgreSQLDatabase.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index 4716bd7..744f6e3 100755 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -1749,6 +1749,13 @@ class PostgreSQLDatabase extends SS_Database { else return false; } + + /** + * @deprecated 1.0 Use transactionStart() (method required for 2.4.x) + */ + public function startTransaction($transaction_mode=false, $session_characteristics=false){ + $this->transactionStart($transaction_mode, $session_characteristics); + } /* * Start a prepared transaction @@ -1784,6 +1791,13 @@ class PostgreSQLDatabase extends SS_Database { DB::query('ROLLBACK;'); } + + /** + * @deprecated 1.0 Use transactionEnd() (method required for 2.4.x) + */ + public function endTransaction(){ + $this->transactionEnd(); + } /* * Commit everything inside this transaction so far From 0ec8ee1335ea20f568a5afd7b4dfd42591c59e75 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 14 Mar 2011 16:47:44 +1300 Subject: [PATCH 3/6] MINOR Added PostgreSQLDatabaseTest with a database specific readonly transaction test (moved here from sapphire/tests/TransactionTest.php --- tests/PostgreSQLDatabaseTest.php | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/PostgreSQLDatabaseTest.php diff --git a/tests/PostgreSQLDatabaseTest.php b/tests/PostgreSQLDatabaseTest.php new file mode 100644 index 0000000..6c65184 --- /dev/null +++ b/tests/PostgreSQLDatabaseTest.php @@ -0,0 +1,48 @@ +supportsTransactions() == true + && DB::getConn() instanceof PostgreSQLDatabase + ){ + + $page=new Page(); + $page->Title='Read only success'; + $page->write(); + + DB::getConn()->transactionStart('READ ONLY'); + + try { + $page=new Page(); + $page->Title='Read only page failed'; + $page->write(); + } catch (Exception $e) { + //could not write this record + //We need to do a rollback or a commit otherwise we'll get error messages + DB::getConn()->transactionRollback(); + } + + DB::getConn()->transactionEnd(); + + DataObject::flush_and_destroy_cache(); + + $success=DataObject::get('Page', "\"Title\"='Read only success'"); + $fail=DataObject::get('Page', "\"Title\"='Read only page failed'"); + + //This page should be in the system + $this->assertTrue(is_object($success) && $success->exists()); + + //This page should NOT exist, we had 'read only' permissions + $this->assertFalse(is_object($fail) && $fail->exists()); + + } else { + $this->markTestSkipped('Current database is not PostgreSQL'); + } + + } +} \ No newline at end of file From 74abdec18b15575c6fc69fa558870d44aea42986 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 19 May 2011 11:35:56 +1200 Subject: [PATCH 4/6] BUGFIX Allow omitting FROM clause in sqlQueryToString() --- code/PostgreSQLDatabase.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index 744f6e3..5f17539 100755 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -1554,15 +1554,13 @@ class PostgreSQLDatabase extends SS_Database { * helper function in Database? */ public function sqlQueryToString(SQLQuery $sqlQuery) { - if (!$sqlQuery->from) return ''; $distinct = $sqlQuery->distinct ? "DISTINCT " : ""; if($sqlQuery->delete) { $text = "DELETE "; } else if($sqlQuery->select) { $text = "SELECT $distinct" . implode(", ", $sqlQuery->select); } - $text .= " FROM " . implode(" ", $sqlQuery->from); - + if($sqlQuery->from) $text .= " FROM " . implode(" ", $sqlQuery->from); if($sqlQuery->where) $text .= " WHERE (" . $sqlQuery->getFilter(). ")"; if($sqlQuery->groupby) $text .= " GROUP BY " . implode(", ", $sqlQuery->groupby); if($sqlQuery->having) $text .= " HAVING ( " . implode(" ) AND ( ", $sqlQuery->having) . " )"; From 5e058a151d6d019dbda529e64cfbc02b2a079f74 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 15 Sep 2011 16:01:53 +0200 Subject: [PATCH 5/6] ENHANCEMENT Optionally filtering by new File.ShowInSearch flag in PostgreSQLDatabase->searcnEngine() --- code/PostgreSQLDatabase.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index 5f17539..5cde897 100755 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -1681,10 +1681,16 @@ class PostgreSQLDatabase extends SS_Database { ); foreach($result as $row){ - if($row['table_name']=='SiteTree') + if($row['table_name']=='SiteTree') { $showInSearch="AND \"ShowInSearch\"=1 "; - else + } elseif($row['table_name']=='File') { + // File.ShowInSearch was added later, keep the database driver backwards compatible + // by checking for its existence first + $fields = $this->fieldList($row['table_name']); + if(array_key_exists('ShowInSearch', $fields)) $showInSearch="AND \"ShowInSearch\"=1 "; + } else { $showInSearch=''; + } //public function extendedSQL($filter = "", $sort = "", $limit = "", $join = "", $having = ""){ $query=singleton($row['table_name'])->extendedSql("\"" . $row['table_name'] . "\".\"" . $row['column_name'] . "\" " . $this->default_fts_search_method . ' q ' . $showInSearch, ''); From 8bbf8401f93e0f64201d2354b1f9e7c0c206fff2 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 15 Sep 2011 18:01:02 +0200 Subject: [PATCH 6/6] MINOR Fixed edge case around --- code/PostgreSQLDatabase.php | 1 + 1 file changed, 1 insertion(+) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index 5cde897..7a6befc 100755 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -1688,6 +1688,7 @@ class PostgreSQLDatabase extends SS_Database { // by checking for its existence first $fields = $this->fieldList($row['table_name']); if(array_key_exists('ShowInSearch', $fields)) $showInSearch="AND \"ShowInSearch\"=1 "; + else $showInSearch=''; } else { $showInSearch=''; }