public function forceDeleteByUsername($username) { $query = new Query('DELETE'); $query->from('users'); $query->where('username like ?', $username); $query->limit(1); $stmt = $query->prepare(); return $stmt->execute(); }
public function getValue($key) { $q = new Query("SELECT"); $q->where("key = ?", $key); $q->limit(1); $q->orderby("id", "DESC"); $cvbs = ConfigValueBean::select($q); $cvb = $cvbs[0]; $data = unserialize($cvb->data); return $data; }
public function retrieve($key, $moduleNamespace) { $moduleNamespace = str_replace("\\", "*", $moduleNamespace); $q = new Query("SELECT"); $q->where("module = ?", $moduleNamespace); $q->where("title = ?", $key); $q->limit(1); $q->orderby("id", "DESC"); $mdbs = ModuleDataBean::select($q); $mdb = $mdbs[0]; $data = unserialize($mdb->data); return $data; }
public function getByIPAddress__300_users($ip) { $intip = $this->toIntIP($ip); $query = new Query("SELECT"); $query->where('bip.ip_low <= ?', $intip); $query->where('bip.ip_high >= ?', $intip); $query->limit(1); $result = BannedIPBean::select($query, true); if ($result) { return $result; } return false; }
public function getByAppID__600_appdetails($app_id, $version = false, $limit = false) { $query = new Query('SELECT'); $query->where('app_id = ?', $app_id); if ($version) { $query->where('version = ?', $version); } if ($limit !== false) { $query->limit($limit); } $query->orderby('intversion', 'DESC'); return AppVersionBean::select($query); }
/** * Database template loader * Assumes that the table specified in the config has * a 'path' and 'content' field. * The former should contain the path as it would be * loaded through a controller (e.g. ucp/user_logged_in) * The latter should contain the Hydrogen/purephp template * as it would be in a file. * * @param string viewName The name of the view to be found. */ public function load($viewName) { $query = new Query("SELECT"); $query->from($this->getTableName()); $query->where("path = ?", $viewName); $query->limit(1); $stmt = $query->prepare(); $stmt->execute(); $result = $stmt->fetchObject(); if (!$result->content) { throw new NoSuchViewException("View " . $viewName . " does not exist in database."); } return $result->content; }
/** * Loads the contents of the specified template. * * @param string $templateName The name of the template to be loaded. * @return string The unaltered, unparsed contents of the specified * template. * @throws hydrogen\view\exceptions\NoSuchViewException if the specified * template is not found or cannot be loaded. */ public function load($viewName) { $table = Config::getRequiredVal("view", "table_name"); $nameCol = Config::getRequiredVal("view", "name_field"); $contentCol = Config::getRequiredVal("view", "content_field"); $query = new Query("SELECT"); $query->field($contentCol); $query->from($table); $query->where($nameCol . " = ?", $viewName); $query->limit(1); $stmt = $query->prepare(); $stmt->execute(); $result = $stmt->fetchObject(); if (!$result->{$contentCol}) { throw new NoSuchViewException("View " . $viewName . " does not exist in database."); } return $result->{$contentCol}; }
public function delete() { if (!isset($this->stored[static::$primaryKey])) { $class = get_class($this); throw new MissingPrimaryKeyException($class . '->delete() cannot be called until a primary key is set.'); } $query = new Query('DELETE', $this->dbengine); $query->from(static::$tableNoPrefix); $query->where(static::$primaryKey . ' = ?', $this->stored[static::$primaryKey]); $query->limit(1); $stmt = $query->prepare(); if (!$stmt->execute()) { $info = $stmt->errorInfo(); $e = new QueryFailedException($info[2]); $e->errorInfo = $info; throw $e; } return true; }
$stmt->execute(); $obj = $stmt->fetchObj(); $count = $obj->count; echo "Starting indexing for {$count} apps...<br />\n"; // Loop it! $i = 0; $sindex = array(); $cm = RECacheManager::getInstance(); $am = ApplicationModel::getInstance(); while ($i < $count) { $query = new Query('SELECT'); $query->field('id'); $query->field('name'); $query->from('applications'); $query->orderby('name', 'ASC'); $query->limit(500, $i); $stmt = $query->prepare(); $stmt->execute(); while ($row = $stmt->fetchAssoc()) { echo "{$row['name']} ({$row['id']}): "; $i++; $name = $row['name']; $app_id = $row['id']; // Pull out the words we'll need to index $iwords = $am->getIndexable($name); // Add 'em if (count($iwords) > 0) { echo "Indexing: " . implode(', ', $iwords) . "<br />\n"; foreach ($iwords as $iword) { $sindex[$iword][] = $app_id; }
/** * Gets the number of messages specified in $count * that are immediately before the given timestamp * * @param integer $timestamp unix epoch timestamp * @param integer $count number of messages to get * @return array array of ChannelActionBean objects latest * first */ public function getMessagesBeforeTimestamp($timestamp, $count) { $query = new Query("SELECT"); $query->where("channel_name = ?", Config::getVal("general", "channel")); $query->where("time < ?", $timestamp); $query->orderby("time", "DESC"); $query->limit($count); $messages = ChannelActionBean::select($query); return $messages; }
public function getAppList($perpage, $page, $sort = 'relevance', $cat = 0, $filter = false, $app_ids = false, $itunes_ids = false, $overrideStartWith = false, $fullinfo = false) { $query = new Query('SELECT'); if (($filter = trim($filter)) == '') { $filter = false; } switch ($sort) { case 'appname': $query->orderby('app.name', 'ASC'); break; case 'newapps': $query->orderby('app.date_added', 'DESC'); break; case 'relevance': if ($filter) { $query->orderby('namematch', 'DESC'); $query->orderby('score', 'DESC'); break; } case 'newvers': default: $sort = 'newvers'; $query->orderby('latest_version_added', 'DESC'); } $query->limit($perpage, $overrideStartWith ?: $perpage * ($page - 1)); $inclids = array(); if ($filter) { $inclids = $this->getMatchedIDs($filter); $newfilter = $this->processFilter($filter); if ($sort == 'relevance') { $query->field('CASE when name like ? then 1 else 0 END', 'namematch', '%' . $filter . '%'); $query->field('MATCH(app.name, app.description) AGAINST(? IN BOOLEAN MODE)', 'score', $newfilter); } $query->whereOpenGroup('AND'); $query->where('MATCH(app.name, app.description) AGAINST(? IN BOOLEAN MODE)', $newfilter); foreach ($inclids as $inclid) { $query->where('app.id = ?', $inclid, 'OR'); } $query->whereCloseGroup(); } if ($cat > 0) { $query->where('app.category_id = ?', $cat); } if ($app_ids) { if (is_array($app_ids)) { $query->whereOpenGroup('AND'); foreach ($app_ids as $app_id) { $query->where('app.id = ?', $app_id, 'OR'); } $query->whereCloseGroup(); } else { $query->where('app.id = ?', $app_id); } } if ($itunes_ids) { if (is_array($itunes_ids)) { $query->whereOpenGroup('AND'); foreach ($itunes_ids as $itunes_id) { $query->where('app.itunes_id = ?', $itunes_id, 'OR'); } $query->whereCloseGroup(); } else { $query->where('app.itunes_id = ?', $itunes_id); } } if ($fullinfo) { $result = ApplicationBean::select($query, true); } else { $result = ShortAppBean::select($query, true); } if (!$result) { return false; } return $result; }