/** * {@inheritdoc} */ public function accept(CompilerInterface $compiler, Connection $connection = null) { if ($connection !== null) { $compiler->appendSql($connection->escapeIdentifier($this->identifier)); } else { $compiler->appendSql($this->identifier); } }
/** * {@inheritdoc} */ public function accept(CompilerInterface $compiler, Connection $connection = null) { if ($connection !== null) { $compiler->appendSql($connection->escapeLiteral($this->literal)); } else { $compiler->appendSql($this->literal); } }
/** * {@inheritdoc} */ public function execute(FragmentInterface $query, Connection $connection, MapperInterface $mapper, $field = null, $type = null) { $result = $connection->executeFragment(new Node(['WITH set AS (', $query, ') SELECT to_json(set) AS json FROM set'])); $value = pg_fetch_assoc($result); $value = json_decode($value['json'], true); pg_free_result($result); if ($field !== null) { $value = $value[$field]; } if ($type !== null) { $value = $mapper->fromPg($value, $type); } return $value; }
/** * {@inheritdoc} */ public function query(FragmentInterface $query, Connection $connection, MapperInterface $mapper, $field = null, $type = null) { $result = $connection->executeFragment(new Node('SELECT to_json(set) AS json FROM (', $query, ') AS set')); while ($value = pg_fetch_assoc($result)) { $value = json_decode($value['json'], true); if ($field !== null) { $value = $value[$field]; } if ($type !== null) { $value = $mapper->fromPg($value, $type); } (yield $value); } pg_free_result($result); }
/** * @param MapperInterface $mapper * @param Connection $connection * @param Node $cursor * @param string $field * @param string $type * * @return \Generator */ private function process(MapperInterface $mapper, Connection $connection, Node $cursor, $field = null, $type = null) { while ($result = $connection->executeFragment($cursor)) { if (pg_num_rows($result) === 0) { break; } while ($value = pg_fetch_assoc($result)) { $value = json_decode($value['json'], true); if ($field !== null) { $value = $value[$field]; } if ($type !== null) { $value = $mapper->fromPg($value, $type); } (yield $value); } pg_free_result($result); } pg_free_result($result); }
/** * {@inheritdoc} */ public function query(FragmentInterface $query, Connection $connection, MapperInterface $mapper, $field = null, $type = null) { $cursor = self::next(); $query = new Node('DECLARE ', $cursor, ' CURSOR FOR (SELECT to_json(set) AS json FROM (', $query, ') AS set)'); $connection->executeFragment($query); while ($result = $connection->executeFragment(new Node('FETCH 10 FROM ', $cursor))) { if (pg_num_rows($result) === 0) { break; } while ($value = pg_fetch_assoc($result)) { $value = json_decode($value['json'], true); if ($field !== null) { $value = $value[$field]; } if ($type !== null) { $value = $mapper->fromPg($value, $type); } (yield $value); } pg_free_result($result); } pg_free_result($result); }
/** * Loads the DAL for the given path and do some check about the supported version of the loaded files and that * there is no circular references between them. * * This method will check that: * * - The PostgreSQL version matches the supported version of the DAL. * - The loaded DAL does not induces circular reference. * * @param string $path The path of the DAL to load. * @param string[] $stack The stack of paths that have been loaded since the current call. * * @throws LogicException When a circular reference is detected. * @throws LogicException When the version of PostgreSQL doesn't match the minimum version required. * * @return AbstractDal */ private function loadLayerAndCheck($path, array $stack) { if (in_array($path, $stack)) { throw new LogicException(sprintf('Circular reference detected:' . PHP_EOL . ' - file: %s' . PHP_EOL . ' - load: %s then crash', implode(PHP_EOL . ' - load: ', $stack), $path)); } $metadata = unserialize(file_get_contents($this->getMetaFilename($path))); $pgVersion = $this->connection->getVersion(); $cmpVersion = $metadata->getSupport(); if (version_compare($pgVersion, $cmpVersion, '<')) { throw new LogicException(sprintf('The current version of PostgreSQL is "%s" and the DAL "%s" requires a minimum version of "%s"', $pgVersion, $path, $cmpVersion)); } $stack[] = $path; $this->graphNodes[$path] = $graphNode = new GraphNode(); $mapper = new HierarchicalMapper($graphNode); $mapper->setType('#', new FragmentConverter()); $blueprint = new HierarchicalBlueprint($graphNode, $this->connection, $mapper, $this->executionStrategies, $this->environment); foreach ($metadata->getImports() as $import => $map) { $this->doLoad($import, $stack); $graphNode->import($this->graphNodes[$import], $map); } return $this->loadLayer($this->getFilename($path), $mapper, $blueprint); }
/** * {@inheritdoc} */ public function execute(FragmentInterface $query, Connection $connection, MapperInterface $mapper, $field = null, $type = null) { return $connection->executeFragment($query); }
/** * {@inheritdoc} */ public function query(FragmentInterface $query, Connection $connection, MapperInterface $mapper, $field = null, $type = null) { $result = $connection->executeFragment($query); pg_free_result($result); }
/** * {@inheritdoc} */ public function execute(FragmentInterface $query, Connection $connection, MapperInterface $mapper, $field = null, $type = null) { $result = $connection->executeFragment(new Node(['WITH set AS (', $query, ') SELECT to_json(set) AS json FROM set'])); return $this->process($mapper, $result, $field, $type); }