bugphpGroupWare - Bugs: bug #5599, error when using concat function

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #5599: error when using concat function

Submitted by:  Johnson <jecinc>
Submitted on:  Sun 28 Sep 2003 02:12:10 AM UTC  
 
Item Group: 0.9.16RC1Category: API - phpGroupware API
Severity: 3 - NormalPriority: 5 - Normal
Status: FixedPrivacy: Public
Assigned to: Invalid User ID <Invalid User ID>Open/Closed: Closed
Component Version: NoneOperating System: None
Reproducibility: NonePlanned Release: None
Fixed Release: 

Thu 02 Oct 2003 04:30:18 AM UTC, comment #3:

I screwed it up

It SHOULD be:

$return_value[] = '(CASE WHEN '.$data.' IS NULL THEN \'\' ELSE '.$data.' END)';

(WHEN is moved and IS is added)

Johnson <jecinc>
Thu 02 Oct 2003 04:25:24 AM UTC, comment #2:

One more problem.

In function safe_null($value)

$return_value[] = '(CASE '.$data.' WHEN NULL THEN \'\' ELSE '.$data.' END)';

the CASE statement doesn't work (only tested in pgsql).

It should be:
$return_value[] = '(CASE WHEN '.$data.' NULL THEN \'\' ELSE '.$data.' END)';

(the 'WHEN' is moved before the $data)

Johnson <jecinc>
Mon 29 Sep 2003 01:46:10 AM UTC, comment #1:

I rewrote them (this is the pgsql version, the other dbs should be rewritten too):
function concat_null($elements)
{
$elements = sql::safe_null($elements);
$str = implode(' || ', $elements);
return ($str) ? '(' . $str . ')' : '';
}

function safe_null($value)
{
if(empty($value))
{
return ;
}
$value = is_array($value) ? $value : array($value);
$i=0;
foreach($value as $data)
{
$return_value[$i] = '(CASE '.$data.' WHEN NULL THEN \'\' ELSE '.$data.')';
$i++;
}
return $return_value;
}

When time permits, this should be edited to change elements to a two dimensional array (key => value) so that constants can be included in the concat and can skip the CASE statement.

I think constants will work with current code, it it just overly complex.

Johnson <jecinc>
Sun 28 Sep 2003 02:12:10 AM UTC, original submission:

Just starting to test this out

Using this code:
include_once(PHPGW_API_INC . '/class.sql.inc.php');
$my_concatenated_field = sql::concat_null( array('org_name', 'first_name', 'last_name') );

results in an error:
Warning: Invalid argument supplied for foreach() in /home/htdocs/phpgroupware/phpgwapi/inc/class.sql.inc.php on line 422

Johnson <jecinc>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can click here to add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

Please enter the title of George Orwell's famous dystopian book (it's a date):

 

 

Follow 2 latest changes.

Date Changed By Updated Field Previous Value => Replaced By
Thu 02 Oct 2003 04:25:24 AM UTCjecincStatusFixed=>(Error - Not Found)
  Open/ClosedClosed=>(Error - Not Found)

Back to the top


Powered by Savane 3.1-cleanup1