mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-10-22 15:05:45 +00:00
Merge pull request #31 from tractorcow/pulls/fix-master
BUG Fix issues in master
This commit is contained in:
commit
731e25fe5a
@ -3,7 +3,7 @@ name: postgresqlconnectors
|
|||||||
---
|
---
|
||||||
Injector:
|
Injector:
|
||||||
PostgrePDODatabase:
|
PostgrePDODatabase:
|
||||||
class: 'PostgrePDODatabase'
|
class: 'PostgreSQLDatabase'
|
||||||
properties:
|
properties:
|
||||||
connector: %$PDOConnector
|
connector: %$PDOConnector
|
||||||
schemaManager: %$PostgreSQLSchemaManager
|
schemaManager: %$PostgreSQLSchemaManager
|
||||||
|
@ -109,7 +109,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
*/
|
*/
|
||||||
protected $parameters = array();
|
protected $parameters = array();
|
||||||
|
|
||||||
function connect($parameters) {
|
public function connect($parameters) {
|
||||||
// Check database name
|
// Check database name
|
||||||
if(empty($parameters['database'])) {
|
if(empty($parameters['database'])) {
|
||||||
// Check if we can use the master database
|
// Check if we can use the master database
|
||||||
@ -322,7 +322,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
|
|
||||||
$method = self::default_fts_search_method();
|
$method = self::default_fts_search_method();
|
||||||
$conditions[] = "\"{$row['table_name']}\".\"{$row['column_name']}\" $method q ";
|
$conditions[] = "\"{$row['table_name']}\".\"{$row['column_name']}\" $method q ";
|
||||||
$query = DataObject::get($row['table_name'], $where)->dataQuery()->query();
|
$query = DataObject::get($row['table_name'], $conditions)->dataQuery()->query();
|
||||||
|
|
||||||
// Could parameterise this, but convention is only to to so for where conditions
|
// Could parameterise this, but convention is only to to so for where conditions
|
||||||
$query->addFrom(array(
|
$query->addFrom(array(
|
||||||
@ -390,21 +390,21 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
$this->query('BEGIN;');
|
$this->query('BEGIN;');
|
||||||
|
|
||||||
if($transaction_mode) {
|
if($transaction_mode) {
|
||||||
$this->preparedQuery('SET TRANSACTION ?;', array($transaction_mode));
|
$this->query("SET TRANSACTION {$transaction_mode};");
|
||||||
}
|
}
|
||||||
|
|
||||||
if($session_characteristics) {
|
if($session_characteristics) {
|
||||||
$this->preparedQuery('SET SESSION CHARACTERISTICS AS TRANSACTION ?;', array($session_characteristics));
|
$this->query("SET SESSION CHARACTERISTICS AS TRANSACTION {$session_characteristics};");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function transactionSavepoint($savepoint){
|
public function transactionSavepoint($savepoint){
|
||||||
$this->preparedQuery("SAVEPOINT ?;", array($savepoint));
|
$this->query("SAVEPOINT {$savepoint};");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function transactionRollback($savepoint = false){
|
public function transactionRollback($savepoint = false){
|
||||||
if($savepoint) {
|
if($savepoint) {
|
||||||
$this->preparedQuery("ROLLBACK TO ?;", array($savepoint));
|
$this->query("ROLLBACK TO {$savepoint};");
|
||||||
} else {
|
} else {
|
||||||
$this->query('ROLLBACK;');
|
$this->query('ROLLBACK;');
|
||||||
}
|
}
|
||||||
@ -443,8 +443,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
* %U = unix timestamp, can only be used on it's own
|
* %U = unix timestamp, can only be used on it's own
|
||||||
* @return string SQL datetime expression to query for a formatted datetime
|
* @return string SQL datetime expression to query for a formatted datetime
|
||||||
*/
|
*/
|
||||||
function formattedDatetimeClause($date, $format) {
|
public function formattedDatetimeClause($date, $format) {
|
||||||
|
|
||||||
preg_match_all('/%(.)/', $format, $matches);
|
preg_match_all('/%(.)/', $format, $matches);
|
||||||
foreach($matches[1] as $match) {
|
foreach($matches[1] as $match) {
|
||||||
if(array_search($match, array('Y','m','d','H','i','s','U')) === false) {
|
if(array_search($match, array('Y','m','d','H','i','s','U')) === false) {
|
||||||
@ -489,8 +488,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
* This includes the singular forms as well
|
* This includes the singular forms as well
|
||||||
* @return string SQL datetime expression to query for a datetime (YYYY-MM-DD hh:mm:ss) which is the result of the addition
|
* @return string SQL datetime expression to query for a datetime (YYYY-MM-DD hh:mm:ss) which is the result of the addition
|
||||||
*/
|
*/
|
||||||
function datetimeIntervalClause($date, $interval) {
|
public function datetimeIntervalClause($date, $interval) {
|
||||||
|
|
||||||
if(preg_match('/^now$/i', $date)) {
|
if(preg_match('/^now$/i', $date)) {
|
||||||
$date = "NOW()";
|
$date = "NOW()";
|
||||||
} else if(preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/i', $date)) {
|
} else if(preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/i', $date)) {
|
||||||
@ -509,8 +507,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
* @param string $date2 to be substracted of $date1, can be either 'now', literal datetime like '1973-10-14 10:30:00' or field name, e.g. '"SiteTree"."Created"'
|
* @param string $date2 to be substracted of $date1, can be either 'now', literal datetime like '1973-10-14 10:30:00' or field name, e.g. '"SiteTree"."Created"'
|
||||||
* @return string SQL datetime expression to query for the interval between $date1 and $date2 in seconds which is the result of the substraction
|
* @return string SQL datetime expression to query for the interval between $date1 and $date2 in seconds which is the result of the substraction
|
||||||
*/
|
*/
|
||||||
function datetimeDifferenceClause($date1, $date2) {
|
public function datetimeDifferenceClause($date1, $date2) {
|
||||||
|
|
||||||
if(preg_match('/^now$/i', $date1)) {
|
if(preg_match('/^now$/i', $date1)) {
|
||||||
$date1 = "NOW()";
|
$date1 = "NOW()";
|
||||||
} else if(preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/i', $date1)) {
|
} else if(preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/i', $date1)) {
|
||||||
|
@ -544,9 +544,9 @@ class PostgreSQLSchemaManager extends DBSchemaManager {
|
|||||||
$fields = $this->preparedQuery("
|
$fields = $this->preparedQuery("
|
||||||
SELECT ordinal_position, column_name, data_type, column_default,
|
SELECT ordinal_position, column_name, data_type, column_default,
|
||||||
is_nullable, character_maximum_length, numeric_precision, numeric_scale
|
is_nullable, character_maximum_length, numeric_precision, numeric_scale
|
||||||
FROM information_schema.columns WHERE table_name = ?
|
FROM information_schema.columns WHERE table_name = ? and table_schema = ?
|
||||||
ORDER BY ordinal_position;",
|
ORDER BY ordinal_position;",
|
||||||
array($table)
|
array($table, $this->database->currentSchema())
|
||||||
);
|
);
|
||||||
|
|
||||||
$output = array();
|
$output = array();
|
||||||
@ -766,8 +766,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager {
|
|||||||
* @param string $triggerName Postgres trigger name
|
* @param string $triggerName Postgres trigger name
|
||||||
* @return array List of columns
|
* @return array List of columns
|
||||||
*/
|
*/
|
||||||
protected function extractTriggerColumns($triggerName)
|
protected function extractTriggerColumns($triggerName) {
|
||||||
{
|
|
||||||
$trigger = $this->preparedQuery(
|
$trigger = $this->preparedQuery(
|
||||||
"SELECT tgargs FROM pg_catalog.pg_trigger WHERE tgname = ?",
|
"SELECT tgargs FROM pg_catalog.pg_trigger WHERE tgname = ?",
|
||||||
array($triggerName)
|
array($triggerName)
|
||||||
@ -875,7 +874,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager {
|
|||||||
*
|
*
|
||||||
* @param string $constraint
|
* @param string $constraint
|
||||||
*/
|
*/
|
||||||
function constraintExists($constraint){
|
protected function constraintExists($constraint){
|
||||||
if(!isset(self::$cached_constraints[$constraint])){
|
if(!isset(self::$cached_constraints[$constraint])){
|
||||||
$exists = $this->preparedQuery("
|
$exists = $this->preparedQuery("
|
||||||
SELECT conname,pg_catalog.pg_get_constraintdef(r.oid, true)
|
SELECT conname,pg_catalog.pg_get_constraintdef(r.oid, true)
|
||||||
@ -924,7 +923,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager {
|
|||||||
* @param string $triggerName Name of the trigger
|
* @param string $triggerName Name of the trigger
|
||||||
* @param string $tableName Name of the table
|
* @param string $tableName Name of the table
|
||||||
*/
|
*/
|
||||||
function dropTrigger($triggerName, $tableName){
|
protected function dropTrigger($triggerName, $tableName){
|
||||||
$exists = $this->preparedQuery("
|
$exists = $this->preparedQuery("
|
||||||
SELECT trigger_name
|
SELECT trigger_name
|
||||||
FROM information_schema.triggers
|
FROM information_schema.triggers
|
||||||
@ -942,8 +941,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager {
|
|||||||
* @param string $trigger Name of the trigger
|
* @param string $trigger Name of the trigger
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function triggerFieldsFromTrigger($trigger) {
|
protected function triggerFieldsFromTrigger($trigger) {
|
||||||
|
|
||||||
if($trigger){
|
if($trigger){
|
||||||
$tsvector='tsvector_update_trigger';
|
$tsvector='tsvector_update_trigger';
|
||||||
$ts_pos=strpos($trigger, $tsvector);
|
$ts_pos=strpos($trigger, $tsvector);
|
||||||
@ -1229,7 +1227,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $spec
|
* @param array $spec
|
||||||
*/
|
*/
|
||||||
function fulltext($this_index, $tableName, $name){
|
protected function fulltext($this_index, $tableName, $name){
|
||||||
//For full text search, we need to create a column for the index
|
//For full text search, we need to create a column for the index
|
||||||
$columns = $this->quoteColumnSpecString($this_index['value']);
|
$columns = $this->quoteColumnSpecString($this_index['value']);
|
||||||
|
|
||||||
@ -1250,7 +1248,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function IdColumn($asDbValue = false, $hasAutoIncPK = true){
|
public function IdColumn($asDbValue = false, $hasAutoIncPK = true){
|
||||||
if($asDbValue) return 'bigint';
|
if($asDbValue) return 'bigint';
|
||||||
else return 'serial8 not null';
|
else return 'serial8 not null';
|
||||||
}
|
}
|
||||||
@ -1272,7 +1270,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager {
|
|||||||
* @param string $fieldName name of enum field to check
|
* @param string $fieldName name of enum field to check
|
||||||
* @return array List of enum values
|
* @return array List of enum values
|
||||||
*/
|
*/
|
||||||
function enumValuesForField($tableName, $fieldName) {
|
public function enumValuesForField($tableName, $fieldName) {
|
||||||
//return array('SiteTree','Page');
|
//return array('SiteTree','Page');
|
||||||
$constraints = $this->constraintExists("{$tableName}_{$fieldName}_check");
|
$constraints = $this->constraintExists("{$tableName}_{$fieldName}_check");
|
||||||
if($constraints) {
|
if($constraints) {
|
||||||
@ -1282,7 +1280,25 @@ class PostgreSQLSchemaManager extends DBSchemaManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dbDataType($type){
|
/**
|
||||||
|
* Get the actual enum fields from the constraint value:
|
||||||
|
*
|
||||||
|
* @param string $constraint
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function enumValuesFromConstraint($constraint){
|
||||||
|
$constraint = substr($constraint, strpos($constraint, 'ANY (ARRAY[')+11);
|
||||||
|
$constraint = substr($constraint, 0, -11);
|
||||||
|
$constraints = array();
|
||||||
|
$segments = explode(',', $constraint);
|
||||||
|
foreach($segments as $this_segment){
|
||||||
|
$bits = preg_split('/ *:: */', $this_segment);
|
||||||
|
array_unshift($constraints, trim($bits[0], " '"));
|
||||||
|
}
|
||||||
|
return $constraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dbDataType($type){
|
||||||
$values = array(
|
$values = array(
|
||||||
'unsigned integer' => 'INT'
|
'unsigned integer' => 'INT'
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user