1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-06 16:56:44 +02:00

Merge remote-tracking branch 'nickvergessen/ticket/10942' into develop

* nickvergessen/ticket/10942:
  [ticket/10942] Avoid possible conflicts with magic words in unit tests
  [ticket/10942] Add access modifiers
  [ticket/10942] Use ANSI SQL standard || in dbal.php
  [ticket/10942] Fix up unit tests for sql_case()
  [ticket/10942] Require same data type and do not cast expressions automatically
  [ticket/10942] Make unit tests for sql_case simpler
  [ticket/10942] Add a comment why we cast to sql_case()
  [ticket/10942] Rename method sql_conditional() to sql_case()
  [ticket/10942] Change term string to expression to avoid confusion
  [ticket/10942] Fix sql_conditional for mssql, postgre and oracle
  [ticket/10942] Fix function name on order_lower_test.php
  [ticket/10942] Add unit tests for sql_concatenate
  [ticket/10942] Add sql_concatenate to dbal
  [ticket/10942] Add unit tests for sql_conditional
  [ticket/10942] Add sql_conditional to dbal
This commit is contained in:
Andreas Fischer
2012-07-17 17:59:56 +02:00
9 changed files with 205 additions and 1 deletions

View File

@@ -283,6 +283,37 @@ class dbal
return $this->_sql_like_expression('LIKE \'' . $this->sql_escape($expression) . '\'');
}
/**
* Build a case expression
*
* Note: The two statements action_true and action_false must have the same data type (int, vchar, ...) in the database!
*
* @param string $condition The condition which must be true, to use action_true rather then action_else
* @param string $action_true SQL expression that is used, if the condition is true
* @param string $action_else SQL expression that is used, if the condition is false, optional
* @return string CASE expression including the condition and statements
*/
public function sql_case($condition, $action_true, $action_false = false)
{
$sql_case = 'CASE WHEN ' . $condition;
$sql_case .= ' THEN ' . $action_true;
$sql_case .= ($action_false !== false) ? ' ELSE ' . $action_false : '';
$sql_case .= ' END';
return $sql_case;
}
/**
* Build a concatenated expression
*
* @param string $expr1 Base SQL expression where we append the second one
* @param string $expr2 SQL expression that is appended to the first expression
* @return string Concatenated string
*/
public function sql_concatenate($expr1, $expr2)
{
return $expr1 . ' || ' . $expr2;
}
/**
* Returns whether results of a query need to be buffered to run a transaction while iterating over them.
*

View File

@@ -91,6 +91,14 @@ class dbal_mssql extends dbal
return ($this->sql_server_version) ? 'MSSQL<br />' . $this->sql_server_version : 'MSSQL';
}
/**
* {@inheritDoc}
*/
public function sql_concatenate($expr1, $expr2)
{
return $expr1 . ' + ' . $expr2;
}
/**
* SQL Transaction
* @access private

View File

@@ -109,6 +109,14 @@ class dbal_mssql_odbc extends dbal
return ($this->sql_server_version) ? 'MSSQL (ODBC)<br />' . $this->sql_server_version : 'MSSQL (ODBC)';
}
/**
* {@inheritDoc}
*/
public function sql_concatenate($expr1, $expr2)
{
return $expr1 . ' + ' . $expr2;
}
/**
* SQL Transaction
* @access private

View File

@@ -257,6 +257,14 @@ class dbal_mssqlnative extends dbal
return ($this->sql_server_version) ? 'MSSQL<br />' . $this->sql_server_version : 'MSSQL';
}
/**
* {@inheritDoc}
*/
public function sql_concatenate($expr1, $expr2)
{
return $expr1 . ' + ' . $expr2;
}
/**
* {@inheritDoc}
*/

View File

@@ -119,6 +119,14 @@ class dbal_mysql extends dbal
return ($raw) ? $this->sql_server_version : 'MySQL ' . $this->sql_server_version;
}
/**
* {@inheritDoc}
*/
public function sql_concatenate($expr1, $expr2)
{
return 'CONCAT(' . $expr1 . ', ' . $expr2 . ')';
}
/**
* SQL Transaction
* @access private

View File

@@ -122,6 +122,14 @@ class dbal_mysqli extends dbal
return ($raw) ? $this->sql_server_version : 'MySQL(i) ' . $this->sql_server_version;
}
/**
* {@inheritDoc}
*/
public function sql_concatenate($expr1, $expr2)
{
return 'CONCAT(' . $expr1 . ', ' . $expr2 . ')';
}
/**
* SQL Transaction
* @access private