Пример #1
0
    /**
     * Finds project by path.
     *
     * @param string $path Path.
     *
     * @return integer
     * @throws \InvalidArgumentException When project can't be found.
     */
    protected function getProject($path)
    {
        $sql = 'SELECT Id
				FROM Projects
				WHERE Path = :path';
        $project_id = $this->database->fetchValue($sql, array('path' => $path));
        if ($project_id === false) {
            throw new \InvalidArgumentException('The project with "' . $path . '" path not found.');
        }
        return $project_id;
    }
    /**
     * Checks, that database table contains given number of records.
     *
     * @param string  $table_name            Table name.
     * @param integer $expected_record_count Expected record count.
     *
     * @return void
     */
    protected function assertTableCount($table_name, $expected_record_count)
    {
        $profiler = $this->database->getProfiler();
        if (is_object($profiler)) {
            $profiler->setActive(false);
        }
        $sql = 'SELECT COUNT(*)
				FROM ' . $table_name;
        $actual_record_count = $this->database->fetchValue($sql);
        if (is_object($profiler)) {
            $profiler->setActive(true);
        }
        $this->assertEquals($expected_record_count, $actual_record_count, 'The "' . $table_name . '" table contains ' . $expected_record_count . ' records');
    }
    /**
     * Adds a relation.
     *
     * @param integer $class_id      Class ID.
     * @param string  $related_class Related class.
     * @param integer $relation_type Relation type.
     * @param boolean $is_internal   Is internal.
     * @param array   $old_relations Old relations.
     *
     * @return string
     */
    protected function addRelation($class_id, $related_class, $relation_type, $is_internal, array $old_relations)
    {
        $insert_sql = '	INSERT INTO ClassRelations (ClassId, RelatedClass, RelatedClassId, RelationType)
						VALUES (:class_id, :related_class, :related_class_id, :relation_type)';
        $update_sql = ' UPDATE ClassRelations
						SET RelationType = :relation_type
						WHERE ClassId = :class_id AND RelatedClassId = :related_class_id';
        if ($is_internal) {
            $related_class_id = 0;
        } else {
            $related_class_file = realpath(ReflectionEngine::locateClassFile($related_class));
            $sql = 'SELECT Id
					FROM Classes
					WHERE FileId = :file_id AND Name = :name';
            $related_class_id = $this->db->fetchValue($sql, array('file_id' => $this->processFile($related_class_file), 'name' => $related_class));
        }
        $this->db->perform(in_array($related_class, $old_relations) ? $update_sql : $insert_sql, array('class_id' => $class_id, 'related_class' => $related_class, 'related_class_id' => $related_class_id, 'relation_type' => $relation_type));
        return $related_class;
    }
Пример #4
0
 /**
  *
  * Fetches the very first value (i.e., first column of the first row).
  *
  * @param string $statement The SQL statement to prepare and execute.
  *
  * @param array $values Values to bind to the query.
  *
  * @return mixed
  *
  */
 public function fetchValue($statement, array $values = array())
 {
     $result = $this->pdo->fetchValue($statement, $values);
     $this->logProfiles(__FUNCTION__);
     return $result;
 }