1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
8 * Parse the limit string and split into
9 * more sql standard LIMIT (val) OFFSET (val)
11 public function limit_parse($str)
17 if (strstr($str, ',')) {
18 $limit_parts = explode(',', $str);
19 if (!empty($limit_parts) && count($limit_parts)==2) {
20 $limit = $limit_parts[1];
21 $offset = $limit_parts[0];
22 $limit_str = " LIMIT ".$limit." OFFSET ".$offset;
24 } elseif(is_numeric($str)) {
25 $limit_str = !empty($str) ?
' LIMIT '.(int)$str : '';
32 * Concatenate arguments for use in sql query
33 * Since we are using 3 arguments, this method
34 * handles just this and nothing else.
35 * Arguments 1 and 3 are assumed to be field names
36 * and argument 2 i assumed to be a string.
38 public static function concat($arg1, $arg2, $arg3)
40 switch (Kohana
::config('database.default.connection.type'))
43 return " CONCAT(".$arg1.", '".$arg2."', ".$arg3.") ";
46 return " ".$arg1."||'".$arg2."'||".$arg3." ";
51 * Given one SQL function F and N elements E, return (E_0) F (E_1) F (E_2) F ... (E_N)
52 * Handles empty arguments just fine.
53 * Is helpful for ANDing or ORing long expressions without having to resort to hacks like
56 public static function combine() {
57 $args = func_get_args();
58 $function = array_shift($args);
60 foreach ($args as $arg) {
65 $res = '(' . implode(') '.$function.' (', $res) . ')';