mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-10-22 17:05:45 +02:00
Merge branch 'master' of git@github.com:silverstripe/silverstripe-postgresql.git
This commit is contained in:
commit
074c872526
@ -872,7 +872,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function clear_cached_fieldlist($tableName=false){
|
function clearCachedFieldlist($tableName=false){
|
||||||
if($tableName!=false){
|
if($tableName!=false){
|
||||||
unset(self::$cached_fieldlists[$tableName]);
|
unset(self::$cached_fieldlists[$tableName]);
|
||||||
} else
|
} else
|
||||||
@ -1554,15 +1554,13 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
* helper function in Database?
|
* helper function in Database?
|
||||||
*/
|
*/
|
||||||
public function sqlQueryToString(SQLQuery $sqlQuery) {
|
public function sqlQueryToString(SQLQuery $sqlQuery) {
|
||||||
if (!$sqlQuery->from) return '';
|
|
||||||
$distinct = $sqlQuery->distinct ? "DISTINCT " : "";
|
$distinct = $sqlQuery->distinct ? "DISTINCT " : "";
|
||||||
if($sqlQuery->delete) {
|
if($sqlQuery->delete) {
|
||||||
$text = "DELETE ";
|
$text = "DELETE ";
|
||||||
} else if($sqlQuery->select) {
|
} else if($sqlQuery->select) {
|
||||||
$text = "SELECT $distinct" . implode(", ", $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->where) $text .= " WHERE (" . $sqlQuery->getFilter(). ")";
|
||||||
if($sqlQuery->groupby) $text .= " GROUP BY " . implode(", ", $sqlQuery->groupby);
|
if($sqlQuery->groupby) $text .= " GROUP BY " . implode(", ", $sqlQuery->groupby);
|
||||||
if($sqlQuery->having) $text .= " HAVING ( " . implode(" ) AND ( ", $sqlQuery->having) . " )";
|
if($sqlQuery->having) $text .= " HAVING ( " . implode(" ) AND ( ", $sqlQuery->having) . " )";
|
||||||
@ -1683,10 +1681,17 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
);
|
);
|
||||||
|
|
||||||
foreach($result as $row){
|
foreach($result as $row){
|
||||||
if($row['table_name']=='SiteTree')
|
if($row['table_name']=='SiteTree') {
|
||||||
$showInSearch="AND \"ShowInSearch\"=1 ";
|
$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='';
|
||||||
|
} else {
|
||||||
$showInSearch='';
|
$showInSearch='';
|
||||||
|
}
|
||||||
|
|
||||||
//public function extendedSQL($filter = "", $sort = "", $limit = "", $join = "", $having = ""){
|
//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, '');
|
$query=singleton($row['table_name'])->extendedSql("\"" . $row['table_name'] . "\".\"" . $row['column_name'] . "\" " . $this->default_fts_search_method . ' q ' . $showInSearch, '');
|
||||||
@ -1749,6 +1754,13 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
else
|
else
|
||||||
return false;
|
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
|
* Start a prepared transaction
|
||||||
@ -1784,6 +1796,13 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
DB::query('ROLLBACK;');
|
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
|
* Commit everything inside this transaction so far
|
||||||
|
48
tests/PostgreSQLDatabaseTest.php
Normal file
48
tests/PostgreSQLDatabaseTest.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @package postgresql
|
||||||
|
* @subpackage tests
|
||||||
|
*/
|
||||||
|
class PostgreSQLDatabaseTest extends SapphireTest {
|
||||||
|
function testReadOnlyTransaction(){
|
||||||
|
|
||||||
|
if(
|
||||||
|
DB::getConn()->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');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user