mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00:00
[ticket/10942] Rename method sql_conditional() to sql_case()
PHPBB3-10942
This commit is contained in:
parent
79dfdf9406
commit
089e5f5c79
7 changed files with 44 additions and 44 deletions
|
@ -284,20 +284,20 @@ class dbal
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a conditional SQL query
|
* Build a case expression
|
||||||
*
|
*
|
||||||
* @param string $condition The condition which must be true, to use action_true rather then action_else
|
* @param string $condition The condition which must be true, to use action_true rather then action_else
|
||||||
* @param string $action_true SQL statement that is used, if the condition is true
|
* @param string $action_true SQL expression that is used, if the condition is true
|
||||||
* @param string $action_else SQL statement that is used, if the condition is false, optional
|
* @param string $action_else SQL expression that is used, if the condition is false, optional
|
||||||
* @return string CASE expression including the condition and statements
|
* @return string CASE expression including the condition and statements
|
||||||
*/
|
*/
|
||||||
function sql_conditional($condition, $action_true, $action_false = false)
|
function sql_case($condition, $action_true, $action_false = false)
|
||||||
{
|
{
|
||||||
$sql_condition = 'CASE WHEN ' . $condition;
|
$sql_case = 'CASE WHEN ' . $condition;
|
||||||
$sql_condition .= ' THEN ' . $action_true;
|
$sql_case .= ' THEN ' . $action_true;
|
||||||
$sql_condition .= ($action_false !== false) ? ' ELSE ' . $action_false : '';
|
$sql_case .= ($action_false !== false) ? ' ELSE ' . $action_false : '';
|
||||||
$sql_condition .= ' END';
|
$sql_case .= ' END';
|
||||||
return $sql_condition;
|
return $sql_case;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -94,13 +94,13 @@ class dbal_mssql extends dbal
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
function sql_conditional($condition, $action_true, $action_false = false)
|
function sql_case($condition, $action_true, $action_false = false)
|
||||||
{
|
{
|
||||||
$sql_condition = 'CASE WHEN ' . $condition;
|
$sql_case = 'CASE WHEN ' . $condition;
|
||||||
$sql_condition .= ' THEN CAST(' . $action_true . ' AS VARCHAR)';
|
$sql_case .= ' THEN CAST(' . $action_true . ' AS VARCHAR)';
|
||||||
$sql_condition .= ($action_false !== false) ? ' ELSE CAST(' . $action_false . ' AS VARCHAR)' : '';
|
$sql_case .= ($action_false !== false) ? ' ELSE CAST(' . $action_false . ' AS VARCHAR)' : '';
|
||||||
$sql_condition .= ' END';
|
$sql_case .= ' END';
|
||||||
return $sql_condition;
|
return $sql_case;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -112,13 +112,13 @@ class dbal_mssql_odbc extends dbal
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
function sql_conditional($condition, $action_true, $action_false = false)
|
function sql_case($condition, $action_true, $action_false = false)
|
||||||
{
|
{
|
||||||
$sql_condition = 'CASE WHEN ' . $condition;
|
$sql_case = 'CASE WHEN ' . $condition;
|
||||||
$sql_condition .= ' THEN CAST(' . $action_true . ' AS VARCHAR)';
|
$sql_case .= ' THEN CAST(' . $action_true . ' AS VARCHAR)';
|
||||||
$sql_condition .= ($action_false !== false) ? ' ELSE CAST(' . $action_false . ' AS VARCHAR)' : '';
|
$sql_case .= ($action_false !== false) ? ' ELSE CAST(' . $action_false . ' AS VARCHAR)' : '';
|
||||||
$sql_condition .= ' END';
|
$sql_case .= ' END';
|
||||||
return $sql_condition;
|
return $sql_case;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -260,13 +260,13 @@ class dbal_mssqlnative extends dbal
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
function sql_conditional($condition, $action_true, $action_false = false)
|
function sql_case($condition, $action_true, $action_false = false)
|
||||||
{
|
{
|
||||||
$sql_condition = 'CASE WHEN ' . $condition;
|
$sql_case = 'CASE WHEN ' . $condition;
|
||||||
$sql_condition .= ' THEN CAST(' . $action_true . ' AS VARCHAR)';
|
$sql_case .= ' THEN CAST(' . $action_true . ' AS VARCHAR)';
|
||||||
$sql_condition .= ($action_false !== false) ? ' ELSE CAST(' . $action_false . ' AS VARCHAR)' : '';
|
$sql_case .= ($action_false !== false) ? ' ELSE CAST(' . $action_false . ' AS VARCHAR)' : '';
|
||||||
$sql_condition .= ' END';
|
$sql_case .= ' END';
|
||||||
return $sql_condition;
|
return $sql_case;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -92,13 +92,13 @@ class dbal_oracle extends dbal
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
function sql_conditional($condition, $action_true, $action_false = false)
|
function sql_case($condition, $action_true, $action_false = false)
|
||||||
{
|
{
|
||||||
$sql_condition = 'CASE WHEN ' . $condition;
|
$sql_case = 'CASE WHEN ' . $condition;
|
||||||
$sql_condition .= ' THEN CAST(' . $action_true . ' AS clob)';
|
$sql_case .= ' THEN CAST(' . $action_true . ' AS clob)';
|
||||||
$sql_condition .= ($action_false !== false) ? ' ELSE CAST(' . $action_false . ' AS clob)' : '';
|
$sql_case .= ($action_false !== false) ? ' ELSE CAST(' . $action_false . ' AS clob)' : '';
|
||||||
$sql_condition .= ' END';
|
$sql_case .= ' END';
|
||||||
return $sql_condition;
|
return $sql_case;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -157,13 +157,13 @@ class dbal_postgres extends dbal
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
function sql_conditional($condition, $action_true, $action_false = false)
|
function sql_case($condition, $action_true, $action_false = false)
|
||||||
{
|
{
|
||||||
$sql_condition = 'CASE WHEN ' . $condition;
|
$sql_case = 'CASE WHEN ' . $condition;
|
||||||
$sql_condition .= ' THEN CAST(' . $action_true . ' AS TEXT)';
|
$sql_case .= ' THEN CAST(' . $action_true . ' AS TEXT)';
|
||||||
$sql_condition .= ($action_false !== false) ? ' ELSE CAST(' . $action_false . ' AS TEXT)' : '';
|
$sql_case .= ($action_false !== false) ? ' ELSE CAST(' . $action_false . ' AS TEXT)' : '';
|
||||||
$sql_condition .= ' END';
|
$sql_case .= ' END';
|
||||||
return $sql_condition;
|
return $sql_case;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,18 +7,18 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class phpbb_dbal_conditional_test extends phpbb_database_test_case
|
class phpbb_dbal_case_test extends phpbb_database_test_case
|
||||||
{
|
{
|
||||||
public function getDataSet()
|
public function getDataSet()
|
||||||
{
|
{
|
||||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
|
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_conditional_string()
|
public function test_case_string()
|
||||||
{
|
{
|
||||||
$db = $this->new_dbal();
|
$db = $this->new_dbal();
|
||||||
|
|
||||||
$sql = 'SELECT config_name, ' . $db->sql_conditional('is_dynamic = 1', "'" . $db->sql_escape('true') . "'", "'" . $db->sql_escape('false') . "'") . ' AS string
|
$sql = 'SELECT config_name, ' . $db->sql_case('is_dynamic = 1', "'" . $db->sql_escape('true') . "'", "'" . $db->sql_escape('false') . "'") . ' AS string
|
||||||
FROM phpbb_config';
|
FROM phpbb_config';
|
||||||
$result = $db->sql_query($sql);
|
$result = $db->sql_query($sql);
|
||||||
|
|
||||||
|
@ -38,11 +38,11 @@ class phpbb_dbal_conditional_test extends phpbb_database_test_case
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_conditional_statement()
|
public function test_case_statement()
|
||||||
{
|
{
|
||||||
$db = $this->new_dbal();
|
$db = $this->new_dbal();
|
||||||
|
|
||||||
$sql = 'SELECT config_name, ' . $db->sql_conditional('is_dynamic = 1', 'is_dynamic', 'config_value') . ' AS string
|
$sql = 'SELECT config_name, ' . $db->sql_case('is_dynamic = 1', 'is_dynamic', 'config_value') . ' AS string
|
||||||
FROM phpbb_config';
|
FROM phpbb_config';
|
||||||
$result = $db->sql_query($sql);
|
$result = $db->sql_query($sql);
|
||||||
|
|
Loading…
Add table
Reference in a new issue