mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-10-22 17:05:45 +02:00
Merge branch '1.1' into 1.2
This commit is contained in:
commit
1c953025e6
10
.travis.yml
10
.travis.yml
@ -1,15 +1,23 @@
|
|||||||
language: php
|
language: php
|
||||||
|
|
||||||
|
dist: precise
|
||||||
|
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- php: 5.3
|
- php: 5.3
|
||||||
env: DB=POSTGRESQL CORE_RELEASE=3.4
|
env: DB=POSTGRESQL CORE_RELEASE=3.4
|
||||||
|
- php: 5.4
|
||||||
|
env: DB=POSTGRESQL CORE_RELEASE=3.5
|
||||||
|
- php: 5.5
|
||||||
|
env: DB=POSTGRESQL CORE_RELEASE=3.6
|
||||||
- php: 5.6
|
- php: 5.6
|
||||||
env: DB=POSTGRESQL CORE_RELEASE=3
|
env: DB=POSTGRESQL CORE_RELEASE=3
|
||||||
- php: 7.0
|
- php: 7.0
|
||||||
env: DB=POSTGRESQL CORE_RELEASE=3
|
env: DB=POSTGRESQL CORE_RELEASE=3
|
||||||
|
- php: 7.1
|
||||||
|
env: DB=POSTGRESQL CORE_RELEASE=3
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- composer self-update || true
|
- composer self-update || true
|
||||||
@ -19,4 +27,4 @@ before_script:
|
|||||||
- cd ~/builds/ss
|
- cd ~/builds/ss
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- vendor/bin/phpunit framework/tests
|
- vendor/bin/phpunit framework/tests
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* PostgreSQL connector class.
|
* PostgreSQL connector class.
|
||||||
*
|
*
|
||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage model
|
* @subpackage model
|
||||||
*/
|
*/
|
||||||
@ -10,14 +10,14 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Database schema manager object
|
* Database schema manager object
|
||||||
*
|
*
|
||||||
* @var PostgreSQLSchemaManager
|
* @var PostgreSQLSchemaManager
|
||||||
*/
|
*/
|
||||||
protected $schemaManager;
|
protected $schemaManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The currently selected database schema name.
|
* The currently selected database schema name.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $schema;
|
protected $schema;
|
||||||
@ -30,7 +30,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Full text cluster method. (e.g. GIN or GiST)
|
* Full text cluster method. (e.g. GIN or GiST)
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function default_fts_cluster_method() {
|
public static function default_fts_cluster_method() {
|
||||||
@ -39,7 +39,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Full text search method.
|
* Full text search method.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function default_fts_search_method() {
|
public static function default_fts_search_method() {
|
||||||
@ -53,7 +53,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
* Some locked down systems prevent access to the 'postgres' table in
|
* Some locked down systems prevent access to the 'postgres' table in
|
||||||
* which case you need to set this to false.
|
* which case you need to set this to false.
|
||||||
*
|
*
|
||||||
* If allow_query_master_postgres is false, and model_schema_as_database is also false,
|
* If allow_query_master_postgres is false, and model_schema_as_database is also false,
|
||||||
* then attempts to create or check databases beyond the initial connection will
|
* then attempts to create or check databases beyond the initial connection will
|
||||||
* result in a runtime error.
|
* result in a runtime error.
|
||||||
*/
|
*/
|
||||||
@ -67,7 +67,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
* instead of using databases. This may be useful if the database user does not
|
* instead of using databases. This may be useful if the database user does not
|
||||||
* have cross-database permissions, and in cases where multiple databases are used
|
* have cross-database permissions, and in cases where multiple databases are used
|
||||||
* (such as in running test cases).
|
* (such as in running test cases).
|
||||||
*
|
*
|
||||||
* If this is true then the database will only be set during the initial connection,
|
* If this is true then the database will only be set during the initial connection,
|
||||||
* and attempts to change to this database will use the 'public' schema instead
|
* and attempts to change to this database will use the 'public' schema instead
|
||||||
*/
|
*/
|
||||||
@ -88,7 +88,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The database name specified at initial connection
|
* The database name specified at initial connection
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $databaseOriginal = '';
|
protected $databaseOriginal = '';
|
||||||
@ -149,7 +149,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect to the actual database we're requesting
|
// Connect to the actual database we 're requesting
|
||||||
$this->connectDefault();
|
$this->connectDefault();
|
||||||
|
|
||||||
// Set up the schema if required
|
// Set up the schema if required
|
||||||
@ -175,7 +175,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the system timezone for the database connection
|
* Sets the system timezone for the database connection
|
||||||
*
|
*
|
||||||
* @param string $timezone
|
* @param string $timezone
|
||||||
*/
|
*/
|
||||||
public function selectTimezone($timezone) {
|
public function selectTimezone($timezone) {
|
||||||
@ -197,7 +197,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of the current schema in use
|
* Returns the name of the current schema in use
|
||||||
*
|
*
|
||||||
* @return string Name of current schema
|
* @return string Name of current schema
|
||||||
*/
|
*/
|
||||||
public function currentSchema() {
|
public function currentSchema() {
|
||||||
@ -207,7 +207,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
/**
|
/**
|
||||||
* Utility method to manually set the schema to an alternative
|
* Utility method to manually set the schema to an alternative
|
||||||
* Check existance & sets search path to the supplied schema name
|
* Check existance & sets search path to the supplied schema name
|
||||||
*
|
*
|
||||||
* @param string $name Name of the schema
|
* @param string $name Name of the schema
|
||||||
* @param boolean $create Flag indicating whether the schema should be created
|
* @param boolean $create Flag indicating whether the schema should be created
|
||||||
* if it doesn't exist. If $create is false and the schema doesn't exist
|
* if it doesn't exist. If $create is false and the schema doesn't exist
|
||||||
@ -240,7 +240,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
* the search path is provided as an advanced PostgreSQL feature for raw
|
* the search path is provided as an advanced PostgreSQL feature for raw
|
||||||
* SQL queries. Sapphire cannot search for datamodel tables in alternate
|
* SQL queries. Sapphire cannot search for datamodel tables in alternate
|
||||||
* schemas, so be wary of using alternate schemas within the ORM environment.
|
* schemas, so be wary of using alternate schemas within the ORM environment.
|
||||||
*
|
*
|
||||||
* @param string $arg1 First schema to use
|
* @param string $arg1 First schema to use
|
||||||
* @param string $arg2 Second schema to use
|
* @param string $arg2 Second schema to use
|
||||||
* @param string $argN Nth schema to use
|
* @param string $argN Nth schema to use
|
||||||
@ -354,12 +354,14 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
|
|
||||||
$fullQuery = "SELECT * FROM (" . implode(" UNION ", $tables) . ") AS q1 $orderBy LIMIT $limit OFFSET $offset";
|
$fullQuery = "SELECT * FROM (" . implode(" UNION ", $tables) . ") AS q1 $orderBy LIMIT $limit OFFSET $offset";
|
||||||
|
|
||||||
|
// Get the total items in this search
|
||||||
|
$totalItemsQuery = "SELECT COUNT(*) AS totalitems FROM (" . implode(" UNION ", $tables) . ") AS q1";
|
||||||
|
$totalCount = DB::query($totalItemsQuery);
|
||||||
|
|
||||||
// Get records
|
// Get records
|
||||||
$records = $this->preparedQuery($fullQuery, $tableParameters);
|
$records = $this->preparedQuery($fullQuery, $tableParameters);
|
||||||
$totalCount=0;
|
|
||||||
foreach($records as $record){
|
foreach($records as $record){
|
||||||
$objects[] = new $record['ClassName']($record);
|
$objects[] = new $record['ClassName']($record);
|
||||||
$totalCount++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($objects)) $results = new ArrayList($objects);
|
if(isset($objects)) $results = new ArrayList($objects);
|
||||||
@ -368,7 +370,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
$list->setLimitItems(false);
|
$list->setLimitItems(false);
|
||||||
$list->setPageStart($start);
|
$list->setPageStart($start);
|
||||||
$list->setPageLength($pageLength);
|
$list->setPageLength($pageLength);
|
||||||
$list->setTotalItems($totalCount);
|
$list->setTotalItems($totalCount->value());
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,6 +416,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
$this->query('COMMIT;');
|
$this->query('COMMIT;');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function comparisonClause($field, $value, $exact = false, $negate = false, $caseSensitive = null, $parameterised = false) {
|
public function comparisonClause($field, $value, $exact = false, $negate = false, $caseSensitive = null, $parameterised = false) {
|
||||||
if($exact && $caseSensitive === null) {
|
if($exact && $caseSensitive === null) {
|
||||||
$comp = ($negate) ? '!=' : '=';
|
$comp = ($negate) ? '!=' : '=';
|
||||||
@ -422,12 +425,10 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
if($negate) $comp = 'NOT ' . $comp;
|
if($negate) $comp = 'NOT ' . $comp;
|
||||||
$field.='::text';
|
$field.='::text';
|
||||||
}
|
}
|
||||||
|
|
||||||
if($parameterised) {
|
if($parameterised) {
|
||||||
return sprintf("%s %s ?", $field, $comp);
|
return sprintf("%s %s ?", $field, $comp);
|
||||||
} else {
|
} else {
|
||||||
return sprintf("%s %s '%s'", $field, $comp, $value);
|
return sprintf("%s %s '%s'", $field, $comp, $value);}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -536,7 +537,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
* Determines the name of the current database to be reported externally
|
* Determines the name of the current database to be reported externally
|
||||||
* by substituting the schema name for the database name.
|
* by substituting the schema name for the database name.
|
||||||
* Should only be used when model_schema_as_database is true
|
* Should only be used when model_schema_as_database is true
|
||||||
*
|
*
|
||||||
* @param string $schema Name of the schema
|
* @param string $schema Name of the schema
|
||||||
* @return string Name of the database to report
|
* @return string Name of the database to report
|
||||||
*/
|
*/
|
||||||
@ -550,7 +551,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
/**
|
/**
|
||||||
* Translates a requested database name to a schema name to substitute internally.
|
* Translates a requested database name to a schema name to substitute internally.
|
||||||
* Should only be used when model_schema_as_database is true
|
* Should only be used when model_schema_as_database is true
|
||||||
*
|
*
|
||||||
* @param string $database Name of the database
|
* @param string $database Name of the database
|
||||||
* @return string Name of the schema to use for this database internally
|
* @return string Name of the schema to use for this database internally
|
||||||
*/
|
*/
|
||||||
|
@ -464,7 +464,8 @@ class PostgreSQLSchemaManager extends DBSchemaManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SET check constraint (The constraint HAS to be dropped)
|
// 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])) {
|
if(isset($matches[4])) {
|
||||||
//Take this new constraint and see what's outstanding from the target table:
|
//Take this new constraint and see what's outstanding from the target table:
|
||||||
$constraint_bits=explode('(', $matches[4]);
|
$constraint_bits=explode('(', $matches[4]);
|
||||||
@ -488,12 +489,12 @@ class PostgreSQLSchemaManager extends DBSchemaManager {
|
|||||||
|
|
||||||
//First, delete any existing constraint on this column, even if it's no longer an enum
|
//First, delete any existing constraint on this column, even if it's no longer an enum
|
||||||
if($existing_constraint) {
|
if($existing_constraint) {
|
||||||
$alterCol .= ",\nDROP CONSTRAINT \"{$tableName}_{$colName}_check\"";
|
$alterCol .= ",\nDROP CONSTRAINT \"{$constraint_name}\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Now create the constraint (if we've asked for one)
|
//Now create the constraint (if we've asked for one)
|
||||||
if(!empty($matches[4])) {
|
if(!empty($matches[4])) {
|
||||||
$alterCol .= ",\nADD CONSTRAINT \"{$tableName}_{$colName}_check\" $matches[4]";
|
$alterCol .= ",\nADD CONSTRAINT \"{$constraint_name}\" $matches[4]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -903,10 +904,13 @@ class PostgreSQLSchemaManager extends DBSchemaManager {
|
|||||||
WHERE c.relname = ? AND pg_catalog.pg_table_is_visible(c.oid) AND n.nspname = ?
|
WHERE c.relname = ? AND pg_catalog.pg_table_is_visible(c.oid) AND n.nspname = ?
|
||||||
);";
|
);";
|
||||||
|
|
||||||
$result = $this->preparedQuery($query, $tableName, $this->database->currentSchema());
|
$result = $this->preparedQuery(
|
||||||
|
$query,
|
||||||
|
array($tableName, $this->database->currentSchema())
|
||||||
|
);
|
||||||
|
|
||||||
$table = array();
|
$table = array();
|
||||||
while($row = pg_fetch_assoc($result)) {
|
foreach ($result as $row) {
|
||||||
$table[] = array(
|
$table[] = array(
|
||||||
'Column' => $row['Column'],
|
'Column' => $row['Column'],
|
||||||
'DataType' => $row['DataType']
|
'DataType' => $row['DataType']
|
||||||
@ -1388,12 +1392,10 @@ class PostgreSQLSchemaManager extends DBSchemaManager {
|
|||||||
$this->query("CREATE TABLE \"$partition_name\" (CHECK (" . str_replace('NEW.', '', $partition_value) . ")) INHERITS (\"$tableName\")$tableSpace;");
|
$this->query("CREATE TABLE \"$partition_name\" (CHECK (" . str_replace('NEW.', '', $partition_value) . ")) INHERITS (\"$tableName\")$tableSpace;");
|
||||||
} else {
|
} else {
|
||||||
//Drop the constraint, we will recreate in in the next line
|
//Drop the constraint, we will recreate in in the next line
|
||||||
$existing_constraint = $this->preparedQuery(
|
$constraint_name = "{$partition_name}_pkey";
|
||||||
"SELECT conname FROM pg_constraint WHERE conname = ?;",
|
$existing_constraint = $this->constraintExists($constraint_name);
|
||||||
array("{$partition_name}_pkey")
|
|
||||||
);
|
|
||||||
if($existing_constraint){
|
if($existing_constraint){
|
||||||
$this->query("ALTER TABLE \"$partition_name\" DROP CONSTRAINT \"{$partition_name}_pkey\";");
|
$this->query("ALTER TABLE \"$partition_name\" DROP CONSTRAINT \"{$constraint_name}\";");
|
||||||
}
|
}
|
||||||
$this->dropTrigger(strtolower('trigger_' . $tableName . '_insert'), $tableName);
|
$this->dropTrigger(strtolower('trigger_' . $tableName . '_insert'), $tableName);
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"silverstripe/framework": "^3.2.0"
|
"silverstripe/framework": "^3.2"
|
||||||
},
|
|
||||||
"extra": {
|
|
||||||
"branch-alias": {
|
|
||||||
"dev-master": "1.2.x-dev"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user