C
.txt

reusable inc to build mysql function


inc:DB/SQLfunction/case.txt

_id: (1)

_as: (2)

value:


makes FTdata value to place in fetch query

FTdata[id] is either

1. '_id' value, function needs to be completed with 'as .. column_name'

2. '_as'+'function' , the column name in query result will be value of _as


Ctxt parser detects if input has _as or not

1.

invalid:[@as]

applier:SQLFunctioniser

....


2.

require:[@as]

applier:SQLFunctioniser

...


example

use-template:DB/SQLfunction/case.txt

@id:colorFunction

long-value:

status = 'b' : 'b'

status = 'b' and ContactId = 1 : 'u'

status = 'r' AND expire < NOW() : 'x'

status = 'r' : 'r'

default : 'a'


how it works


SQLFunctioniser :: case_function

function case_function ( $input = array() ){


$build = "CASE " ;

foreach ( $input as $crit => $result ) {


$crit = trim($crit) ;

$result = trim($result) ;


if ( $crit == "default" ) {

$default = "ELSE $result " ;

continue ;

}

$build .= "WHEN $crit THEN $result " ;

}

$result = $build.$default. "END" ;

return $result ;

}


For Ctxt version 1.0

use-template:DB/SQLfunction/case.txt

@id:

OR @as: > the function- FTdata-id is '[@as_]function'

long-value: