Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 6 commits
  • 4 files changed
  • 0 commit comments
  • 3 contributors
Commits on Apr 08, 2014
@torleif torleif FIX postgres can filter on non text fields
This issue causes the comparison to fail if comparing a non text fields (for example, a date or integer). This will cause the CMS to fail in places such as Gridfield selector. 

Similar fix as this one: silverstripe/silverstripe-framework#2242 The difference being comparisonClause(...) being more apt solution in SS 3.1
7626d74
Commits on Jul 18, 2014
@tractorcow tractorcow BUG Fix issues in master 010ce57
@tractorcow tractorcow Merge pull request #31 from tractorcow/pulls/fix-master
BUG Fix issues in master
731e25f
Commits on Sep 24, 2014
@halkyon halkyon Merge pull request #26 from torleif/patch-1
FIX postgres can filter on non text fields
846f31b
Commits on Dec 04, 2014
@tractorcow tractorcow Relax framework requirement to include 4.0 f920d13
Commits on Feb 24, 2015
@tractorcow tractorcow Merge pull request #30 from ClaySolutions/master
Add bigint support
1aeb7b1
View
2  _config/connectors.yml
@@ -3,7 +3,7 @@ name: postgresqlconnectors
---
Injector:
PostgrePDODatabase:
- class: 'PostgrePDODatabase'
+ class: 'PostgreSQLDatabase'
properties:
connector: %$PDOConnector
schemaManager: %$PostgreSQLSchemaManager
View
28 code/PostgreSQLDatabase.php
@@ -104,12 +104,12 @@ public static function search_language() {
/**
* Connection parameters specified at inital connection
- *
- * @var array
+ *
+ * @var array
*/
protected $parameters = array();
- function connect($parameters) {
+ public function connect($parameters) {
// Check database name
if(empty($parameters['database'])) {
// Check if we can use the master database
@@ -322,7 +322,7 @@ public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $
$method = self::default_fts_search_method();
$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
$query->addFrom(array(
@@ -390,21 +390,21 @@ public function transactionStart($transaction_mode = false, $session_characteris
$this->query('BEGIN;');
if($transaction_mode) {
- $this->preparedQuery('SET TRANSACTION ?;', array($transaction_mode));
+ $this->query("SET TRANSACTION {$transaction_mode};");
}
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){
- $this->preparedQuery("SAVEPOINT ?;", array($savepoint));
+ $this->query("SAVEPOINT {$savepoint};");
}
public function transactionRollback($savepoint = false){
if($savepoint) {
- $this->preparedQuery("ROLLBACK TO ?;", array($savepoint));
+ $this->query("ROLLBACK TO {$savepoint};");
} else {
$this->query('ROLLBACK;');
}
@@ -420,6 +420,7 @@ public function comparisonClause($field, $value, $exact = false, $negate = false
} else {
$comp = ($caseSensitive === true) ? 'LIKE' : 'ILIKE';
if($negate) $comp = 'NOT ' . $comp;
+ $field.='::text';
}
if($parameterised) {
@@ -443,10 +444,9 @@ public function comparisonClause($field, $value, $exact = false, $negate = false
* %U = unix timestamp, can only be used on it's own
* @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);
- foreach($matches[1] as $match) {
+ foreach($matches[1] as $match) {
if(array_search($match, array('Y','m','d','H','i','s','U')) === false) {
user_error('formattedDatetimeClause(): unsupported format character %' . $match, E_USER_WARNING);
}
@@ -489,8 +489,7 @@ function formattedDatetimeClause($date, $format) {
* 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
*/
- function datetimeIntervalClause($date, $interval) {
-
+ public function datetimeIntervalClause($date, $interval) {
if(preg_match('/^now$/i', $date)) {
$date = "NOW()";
} else if(preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/i', $date)) {
@@ -509,8 +508,7 @@ function datetimeIntervalClause($date, $interval) {
* @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
*/
- function datetimeDifferenceClause($date1, $date2) {
-
+ public function datetimeDifferenceClause($date1, $date2) {
if(preg_match('/^now$/i', $date1)) {
$date1 = "NOW()";
} else if(preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/i', $date1)) {
View
52 code/PostgreSQLSchemaManager.php
@@ -542,11 +542,11 @@ public function fieldList($table) {
//if(!isset(self::$cached_fieldlists[$table])){
$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
- FROM information_schema.columns WHERE table_name = ?
+ FROM information_schema.columns WHERE table_name = ? and table_schema = ?
ORDER BY ordinal_position;",
- array($table)
+ array($table, $this->database->currentSchema())
);
$output = array();
@@ -762,12 +762,11 @@ public function alterIndex($tableName, $indexName, $indexSpec) {
/**
* Given a trigger name attempt to determine the columns upon which it acts
- *
+ *
* @param string $triggerName Postgres trigger name
* @return array List of columns
*/
- protected function extractTriggerColumns($triggerName)
- {
+ protected function extractTriggerColumns($triggerName) {
$trigger = $this->preparedQuery(
"SELECT tgargs FROM pg_catalog.pg_trigger WHERE tgname = ?",
array($triggerName)
@@ -875,7 +874,7 @@ public function tableList() {
*
* @param string $constraint
*/
- function constraintExists($constraint){
+ protected function constraintExists($constraint){
if(!isset(self::$cached_constraints[$constraint])){
$exists = $this->preparedQuery("
SELECT conname,pg_catalog.pg_get_constraintdef(r.oid, true)
@@ -920,11 +919,11 @@ public function tableDetails($tableName) {
/**
* Pass a legit trigger name and it will be dropped
* This assumes that the trigger has been named in a unique fashion
- *
+ *
* @param string $triggerName Name of the trigger
* @param string $tableName Name of the table
*/
- function dropTrigger($triggerName, $tableName){
+ protected function dropTrigger($triggerName, $tableName){
$exists = $this->preparedQuery("
SELECT trigger_name
FROM information_schema.triggers
@@ -938,12 +937,11 @@ function dropTrigger($triggerName, $tableName){
/**
* This will return the fields that the trigger is monitoring
- *
+ *
* @param string $trigger Name of the trigger
* @return array
*/
- function triggerFieldsFromTrigger($trigger) {
-
+ protected function triggerFieldsFromTrigger($trigger) {
if($trigger){
$tsvector='tsvector_update_trigger';
$ts_pos=strpos($trigger, $tsvector);
@@ -1255,7 +1253,7 @@ public function year($values, $asDbValue = false){
* @param string $name
* @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
$columns = $this->quoteColumnSpecString($this_index['value']);
@@ -1276,7 +1274,7 @@ function fulltext($this_index, $tableName, $name){
);
}
- function IdColumn($asDbValue = false, $hasAutoIncPK = true){
+ public function IdColumn($asDbValue = false, $hasAutoIncPK = true){
if($asDbValue) return 'bigint';
else return 'serial8 not null';
}
@@ -1291,14 +1289,14 @@ public function hasTable($tableName) {
/**
* Returns the values of the given enum field
- *
+ *
* @todo Make a proper implementation
- *
+ *
* @param string $tableName Name of table to check
* @param string $fieldName name of enum field to check
* @return array List of enum values
*/
- function enumValuesForField($tableName, $fieldName) {
+ public function enumValuesForField($tableName, $fieldName) {
//return array('SiteTree','Page');
$constraints = $this->constraintExists("{$tableName}_{$fieldName}_check");
if($constraints) {
@@ -1308,7 +1306,25 @@ function enumValuesForField($tableName, $fieldName) {
}
}
- 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(
'unsigned integer' => 'INT'
);
View
2  composer.json
@@ -10,7 +10,7 @@
}
],
"require": {
- "silverstripe/framework": "~3.2"
+ "silverstripe/framework": ">=3.2"
},
"extra": {
"branch-alias": {

No commit comments for this range

Something went wrong with that request. Please try again.