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; }
public function update($value) { $this->_mode = 'update'; Query::$_fromValue = f_flatten(func_get_args()); return $this; }