diff options
author | Andreas Fischer <bantu@phpbb.com> | 2012-07-17 17:59:56 +0200 |
---|---|---|
committer | Andreas Fischer <bantu@phpbb.com> | 2012-07-17 17:59:56 +0200 |
commit | 6980b3dcfde13a7bf3c3986fb1add6ce0f5d8c79 (patch) | |
tree | 6f85434457d1e094430401a701285fe7ca1a7946 /phpBB | |
parent | b45bc27339d03016d47c0247aede8da5ce38a4ee (diff) | |
parent | 1b826842aadc16ad35485479f4bb3bdef03b534c (diff) | |
download | forums-6980b3dcfde13a7bf3c3986fb1add6ce0f5d8c79.tar forums-6980b3dcfde13a7bf3c3986fb1add6ce0f5d8c79.tar.gz forums-6980b3dcfde13a7bf3c3986fb1add6ce0f5d8c79.tar.bz2 forums-6980b3dcfde13a7bf3c3986fb1add6ce0f5d8c79.tar.xz forums-6980b3dcfde13a7bf3c3986fb1add6ce0f5d8c79.zip |
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
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/includes/db/dbal.php | 31 | ||||
-rw-r--r-- | phpBB/includes/db/mssql.php | 8 | ||||
-rw-r--r-- | phpBB/includes/db/mssql_odbc.php | 8 | ||||
-rw-r--r-- | phpBB/includes/db/mssqlnative.php | 8 | ||||
-rw-r--r-- | phpBB/includes/db/mysql.php | 8 | ||||
-rw-r--r-- | phpBB/includes/db/mysqli.php | 8 |
6 files changed, 71 insertions, 0 deletions
diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index cf54d455f7..159703d3be 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -284,6 +284,37 @@ class dbal } /** + * 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. * * @return bool Whether buffering is required. diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index abeabc389f..fb044b492f 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -92,6 +92,14 @@ class dbal_mssql extends dbal } /** + * {@inheritDoc} + */ + public function sql_concatenate($expr1, $expr2) + { + return $expr1 . ' + ' . $expr2; + } + + /** * SQL Transaction * @access private */ diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 6e24f4e9e8..64fa9634d1 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -110,6 +110,14 @@ class dbal_mssql_odbc extends dbal } /** + * {@inheritDoc} + */ + public function sql_concatenate($expr1, $expr2) + { + return $expr1 . ' + ' . $expr2; + } + + /** * SQL Transaction * @access private */ diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index 8a4503f111..7878615acc 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -260,6 +260,14 @@ class dbal_mssqlnative extends dbal /** * {@inheritDoc} */ + public function sql_concatenate($expr1, $expr2) + { + return $expr1 . ' + ' . $expr2; + } + + /** + * {@inheritDoc} + */ function sql_buffer_nested_transactions() { return true; diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index eb38e3e913..8d1f805870 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -120,6 +120,14 @@ class dbal_mysql extends dbal } /** + * {@inheritDoc} + */ + public function sql_concatenate($expr1, $expr2) + { + return 'CONCAT(' . $expr1 . ', ' . $expr2 . ')'; + } + + /** * SQL Transaction * @access private */ diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index 4210a58002..e07cd35e24 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -123,6 +123,14 @@ class dbal_mysqli extends dbal } /** + * {@inheritDoc} + */ + public function sql_concatenate($expr1, $expr2) + { + return 'CONCAT(' . $expr1 . ', ' . $expr2 . ')'; + } + + /** * SQL Transaction * @access private */ |