/** * Gets cached data. * * @param string $table Table. * @param mixed $cache_key Key. * @param string|null $sql Fallback sql used to populate cache on the fly. * @param array $values Fallback values used together with above sql. * * @return array|boolean */ public function getFromCache($table, $cache_key, $sql = null, array $values = array()) { if (isset($this->_cache[$table][$cache_key])) { return $this->_cache[$table][$cache_key]; } if (isset($sql)) { $result = $this->_database->fetchOne($sql, $values); if ($result !== false) { $this->setIntoCache($table, $cache_key, $result); return $this->_cache[$table][$cache_key]; } } return false; }
/** * Processes file. * * @param string $file File. * * @return integer */ protected function processFile($file) { $size = filesize($file); $relative_file = $this->removeProjectPath($file); $sql = 'SELECT Id, Size FROM Files WHERE Name = :name'; $file_data = $this->db->fetchOne($sql, array('name' => $relative_file)); $this->db->beginTransaction(); if ($file_data === false) { $sql = 'INSERT INTO Files (Name, Size) VALUES (:name, :size)'; $this->db->perform($sql, array('name' => $relative_file, 'size' => $size)); $file_id = $this->db->lastInsertId(); } else { $file_id = $file_data['Id']; } // File is not changed since last time it was indexed. if ($file_data !== false && (int) $file_data['Size'] === $size) { $sql = 'UPDATE Files SET Found = 1 WHERE Id = :file_id'; $this->db->perform($sql, array('file_id' => $file_data['Id'])); $this->db->commit(); return $file_data['Id']; } $sql = 'UPDATE Files SET Found = 1 WHERE Id = :file_id'; $this->db->perform($sql, array('file_id' => $file_data['Id'])); $new_classes = array(); $parsed_file = new ReflectionFile($file); foreach ($parsed_file->getFileNamespaces() as $namespace) { foreach ($namespace->getClasses() as $class) { $new_classes[] = $class->getName(); $this->processClass($file_id, $class); } } if ($new_classes) { $sql = 'SELECT Id FROM Classes WHERE FileId = :file_id AND Name NOT IN (:classes)'; $deleted_classes = $this->db->fetchCol($sql, array('file_id' => $file_id, 'classes' => $new_classes)); } else { $sql = 'SELECT Id FROM Classes WHERE FileId = :file_id'; $deleted_classes = $this->db->fetchCol($sql, array('file_id' => $file_id)); } foreach ($deleted_classes as $deleted_class_id) { $this->deleteClass($deleted_class_id); } $this->db->commit(); ReflectionEngine::unsetFile($file); return $file_id; }
public function __construct($page_id, ExtendedPdoInterface $connection) { $this->connection = $connection; $page = $connection->fetchOne("SELECT * FROM pages WHERE page_id = :page_id", ['page_id' => $page_id]); if ($page) { $this->fields = $page; if ($page['node_id']) { parent::__construct($page['node_id'], $connection); } } }
/** * * Fetches one row from the database as an associative array. * * @param string $statement The SQL statement to prepare and execute. * * @param array $values Values to bind to the query. * * @return array * */ public function fetchOne($statement, array $values = array()) { $result = $this->pdo->fetchOne($statement, $values); $this->logProfiles(__FUNCTION__); return $result; }
/** * {@inheritdoc} */ public function countByField($field, $value, ServerRequestInterface $request = null) { $query = sprintf("SELECT COUNT(*) as total FROM %s WHERE %s.%s IN (:%s)", $this->getTable(), $this->getTable(), $field, $field); $params = [$field => $value]; return (int) $this->dbal->fetchOne($query, $params)['total']; }