catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

Add: support column Functions on my project #266

Closed orzass closed 6 years ago

orzass commented 9 years ago

medoo has no column functions too bad...

//// [ '#COUNT(id)(count)', // count("id") as "count" '#COUNT(id)' // count("id") ]

only change column_push method. add #preg_match test

it work on my project is better.

////////////////////

protected function column_push($columns) .....

    foreach ($columns as $key => $value)
    {

        preg_match('/^#([a-zA-Z0-9_\-]*)\(([a-zA-Z0-9_\-\.]*)\)\s*(\(([a-zA-Z0-9_\-]*)\))?/i', $value, $match);

        if(isset($match[1], $match[2])){

            $column_fn = $match[1] . '('. $this->column_quote( $match[2] ) . ')';

            if( count($match) === 5 ){
                array_push($stack, $column_fn . ' AS ' . $this->column_quote( $match[4] ));
            }else{
                array_push($stack, $column_fn);
            }

        }else{

            preg_match('/([a-zA-Z0-9_\-\.]*)\s*\(([a-zA-Z0-9_\-]*)\)/i', $value, $match);

            if (isset($match[1], $match[2]))
            {
                array_push($stack, $this->column_quote( $match[1] ) . ' AS ' . $this->column_quote( $match[2] ));
            }
            else
            {
                array_push($stack, $this->column_quote( $value ));
            }
        }
    }

    return implode($stack, ',');
orzass commented 9 years ago

ps. not support , e.g #count()

catfan commented 6 years ago

Check out the new feature raw object https://medoo.in/api/raw.