/** * Adds parametr and sets it to the first place * */ public function addFirst() { $args = func_get_args(); $data = sqlBindsAddFlat(array($args[0]), 0); $binds = sqlBindsAddFlat($args, 1); $this->_data = sqlBindsAddFlat(array($this->_data), 0, $data); $this->_binds = sqlBindsAddFlat($this->_binds, 0, $binds); }
/** * Add query into queue for async execution * * @param sql string Query * @param ... list Binds (optional) * @return bool */ public function queryAsync($sql) { $binds = sqlBindsAddFlat(func_get_args(), 1); $render = array($sql, $binds); return M('Db')->createQuery($this->getQueueTable(), 'insert')->set('query', serialize($render))->set('hquery', print_r($render, 1))->set('connection', $this->getConnection()->getConnectionName())->set('status', 0)->set('added', M('Date')->dbDateTime())->set('added_by', me()->id())->execute(); }
/** * Executes query and returns number of affected rows * * @param sql string|PDOStatement Query * @param ... list Binds (optional) * @return void */ public function exec($sql) { if (is_object($sql)) { throw new RM_Base_Exception_BadUsage("SQL must be a string, use rawQuery() to execute prepared statements"); } $sth = $this->prepare($sql); $binds = sqlBindsAddFlat(func_get_args(), 1); $this->_exec($sth, $binds); return $sth->rowCount(); }
/** * Adds JOIN to specified table. If tableAlias is empty, first table is used. * * @param tableAlias string Table alias (added by addTable). If NULL or empty string, first table is used * @param join string Join string: "LEFT JOIN other_table ON ..." * @param ... list Placeholders * @return void */ public function join($tableAlias, $join) { if (!$tableAlias) { $tableAlias = $this->_firstTable(); } if (!isset($this->_tableAliases[$tableAlias])) { throw new RM_Base_Exception_BadUsage("Undefined table `{$tableAlias}' in query"); } $tableAlias = $this->_tableAliases[$tableAlias]; $nameRe = M('Db')->field('', '(.*?)'); if (!preg_match('/^(?:\\w+\\s+)+? JOIN\\s+(?: (' . $nameRe . '|\\S+) (?:(?:\\s+AS)?\\s+(' . $nameRe . '|\\S+))? ) (?:\\s+FORCE\\s+(?:USE\\s+)?INDEX\\s*\\([^)]+\\))?\\s+ON/ix', $join, $m)) { throw new RM_Base_Exception_BadUsage("I'm giving up. I can't recognize your stupid (and of course SLOW) join :(. Please rewrite it: \n{$join}"); } $joinAlias = preg_replace('/' . $nameRe . '/', '$1', isset($m[3]) ? $m[3] : $m[1]); $this->_tableAliases[$joinAlias] = $tableAlias; sqlBindsAddFlat(func_get_args(), 2, $this->_tableBinds[$tableAlias]); $this->_tables[$tableAlias] .= "\n\t" . $join; return $this; }