public function testDifferentInstancesHaveDifferentResources() { if (!TESTS_SAD_SPIRIT_PG_WRAPPER_CONNECTION_STRING) { $this->markTestSkipped('Connection string is not configured'); } $conn1 = new Connection(TESTS_SAD_SPIRIT_PG_WRAPPER_CONNECTION_STRING); $conn2 = new Connection(TESTS_SAD_SPIRIT_PG_WRAPPER_CONNECTION_STRING); $this->assertNotSame($conn1->getResource(), $conn2->getResource()); }
/** * Populates the types list from pg_catalog.pg_type table * * @param bool $force Force loading from database even if cached list is available * @throws exceptions\InvalidQueryException */ private function _loadTypes($force = false) { $cacheKey = $this->_connection->getConnectionId() . '-types'; if (!($cache = $this->_connection->getMetadataCache()) || $force || null === ($this->_dbTypes = $cache->getItem($cacheKey))) { $this->_dbTypes = array('composite' => array(), 'array' => array(), 'range' => array(), 'names' => array()); $sql = <<<SQL select t.oid, nspname, typname, typarray, typrelid from pg_catalog.pg_type as t, pg_catalog.pg_namespace as s where t.typnamespace = s.oid and typtype != 'd' order by 4 desc SQL; if (!($res = @pg_query($this->_connection->getResource(), $sql))) { throw new exceptions\InvalidQueryException(pg_last_error($this->_connection->getResource())); } while ($row = pg_fetch_assoc($res)) { if (!isset($this->_dbTypes['names'][$row['typname']])) { $this->_dbTypes['names'][$row['typname']] = array($row['nspname'] => $row['oid']); } else { $this->_dbTypes['names'][$row['typname']][$row['nspname']] = $row['oid']; } if ('0' !== $row['typarray']) { $this->_dbTypes['array'][$row['typarray']] = $row['oid']; } if ('0' !== $row['typrelid']) { $this->_dbTypes['composite'][$row['oid']] = $row['typrelid']; } } pg_free_result($res); if (version_compare(pg_parameter_status($this->_connection->getResource(), 'server_version'), '9.2.0', '>=')) { if (!($res = @pg_query($this->_connection->getResource(), "select rngtypid, rngsubtype from pg_range"))) { throw new exceptions\InvalidQueryException(pg_last_error($this->_connection->getResource())); } while ($row = pg_fetch_assoc($res)) { $this->_dbTypes['range'][$row['rngtypid']] = $row['rngsubtype']; } } if ($cache) { $cache->setItem($cacheKey, $this->_dbTypes); } } $this->_oidMap = array(); foreach ($this->_dbTypes['names'] as $typeName => $schemas) { foreach ($schemas as $schemaName => $oid) { $this->_oidMap[$oid] = array($schemaName, $typeName); } } }
public function testRangeTypeConverterFromMetadata() { if (!TESTS_SAD_SPIRIT_PG_WRAPPER_CONNECTION_STRING) { $this->markTestSkipped('Connection string is not configured'); } $connection = new Connection(TESTS_SAD_SPIRIT_PG_WRAPPER_CONNECTION_STRING, false); if (version_compare(pg_parameter_status($connection->getResource(), 'server_version'), '9.2.0', '<')) { $this->markTestSkipped('Connection to PostgreSQL 9.2+ required'); } $connection->setTypeConverterFactory($this->factory); $connection->execute("drop type if exists textrange"); $connection->execute("create type textrange as range (subtype=text, collation=\"C\")"); $this->assertEquals(new RangeConverter(new StringConverter()), $this->factory->getConverter('textrange')); }