function stacktrace() { return f_map(function ($code) { return 'Function: ' . @$code['function'] . ' File: ' . @$code['file'] . ' Line: ' . @$code['line'] . "\n"; }, debug_backtrace()); }
function _build() { //puts all the stuff together in a magic happy fashion. $sqlString = ''; switch ($this->_mode) { case 'select': //adds in our select values //@todo Make the second parameter in `form()` actaully be a real "sub query" //$this-> if(isset(self::$_fromLimit)) { self::$_fromValue = '(SELECT * FROM ' . Query::$_fromValue . $this->_buildLimit(Query::$_fromLimit) . ') AS ' . Query::$_fromValue; } $sqlString = 'SELECT ' . $this->_buildSelect() . "\n" . ' FROM ' . join(', ', (array)Query::$_fromValue) . $this->_buildJoins() . $this->_buildWhereString($this->_whereValue) . $this->_buildGroupBy() . $this->_buildOrderBy() . $this->_buildLimit($this->_limit); break; case 'update': $sqlString = 'UPDATE ' . f_first(Query::$_fromValue) . "\n" . ' SET ' . $this->_buildSet($this->_setValue) . $this->_buildWhereString($this->_whereValue); break; case 'insert': /* f_reduce( function($a, $b) { return array_merge(array_keys((array)$b), array_keys((array)$a)); }, $this->_insert ); */ if(!is_array(f_first($this->_insert) )) { $this->_insert = array($this->_insert); }; $cols = array_map(function($v) { return Query::nullEscape($v, '`');}, array_keys(array_reduce($this->_insert, 'array_merge_recursive', array()))); $sqlString = 'INSERT INTO ' . f_first((array) Query::$_fromValue) . ' (' . join(', ', $cols) . ') VALUES ' . join(', ', f_map( function($v) use($cols) { return '(' . join(',', f_map( function ($i) use ($v) { $i = substr($i, 1, -1); if(isset($v[$i])) { return Query::nullEscape($v[$i]); } else { return 'null'; } }, $cols )) . ')'; }, D::log($this->_insert, 'Insert Data') )); break; case 'delete': $sqlString = 'DELETE FROM ' . join(', ', (array)Query::$_fromValue) . $this->_buildWhereString($this->_whereValue); break; } $this->sql = $sqlString; return $this->sql; }
function regexArray($regexs) { $matches = array(); D::log($_SERVER['QUERY_STRING']); foreach ($regexs as $regex => $func) { preg_match_all($regex, $_SERVER['QUERY_STRING'], $matches); if (f_first($matches)) { return f_push(array($func), f_map('f_first', f_rest($matches))); } } return false; }
function _build() { //puts all the stuff together in a magic happy fashion. $sqlString = ''; switch ($this->_mode) { case 'select': //adds in our select values D::log('hello'); $sqlString = 'SELECT ' . $this->_buildSelect() . "\n" . ' FROM ' . join(', ', (array)Query::$_fromValue) . $this->_buildJoins() . "\n" . $this->_buildWhereString($this->_whereValue) . $this->_buildOrderBy() . $this->_buildLimit(); break; case 'update': $sqlString = 'UPDATE ' . f_first(Query::$_fromValue) . "\n" . ' SET ' . $this->_buildSet($this->_setValue) . $this->_buildWhereString($this->_whereValue); break; case 'insert': /* f_reduce( function($a, $b) { return array_merge(array_keys((array)$b), array_keys((array)$a)); }, $this->_insert ); */ if(!is_array(f_first($this->_insert) )) { $this->_insert = array($this->_insert); } $cols = array_map(function($v) { return Query::nullEscape($v, '`');}, array_keys(array_reduce($this->_insert, 'array_merge_recursive', array()))); $sqlString = 'INSERT INTO ' . f_first((array) Query::$_fromValue) . ' (' . join(', ', $cols) . ') VALUES ' . join(', ', f_map( function($v) use($cols) { return '(' . join(',', f_map( function ($i) use ($v) { $i = substr($i, 1, -1); if(isset($v[$i])) { return Query::nullEscape($v[$i]); } else { return 'null'; } }, $cols )) . ')'; }, D::log($this->_insert, 'raw incert') )); break; case 'delete': $sqlString = 'DELETE FROM ' . join(', ', Query::$_fromValue) . $this->_buildWhereString($this->_whereValue); break; } $this->sql = $sqlString; D::log($this->sql, 'SQL Build'); return $this->sql; }