Gets the wrapped driver connection.
public getWrappedConnection ( ) : Doctrine\DBAL\Driver\Connection | ||
return | Doctrine\DBAL\Driver\Connection |
/** * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection */ protected final function getConnection() { if (!$this->connection) { if (!self::$doctrine) { self::$doctrine = $this->getDoctrineConnection(); $this->setupDatabase(); } $this->connection = $this->createDefaultDbConnection(self::$doctrine->getWrappedConnection(), ':memory:'); } return $this->connection; }
/** * Returns the test database connection. * * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection */ protected function getConnection() { $pdo = null; if (!$this->conn) { $this->conn = (require __DIR__ . '/../config/config.php'); $structure = Structure::createFromYaml(__DIR__ . '/../config/structure.yml'); $this->mf = new ManagerFactory($this->conn, $structure); $pdo = $this->conn->getWrappedConnection(); $pdo->query("SET foreign_key_checks = 0"); } return $this->createDefaultDBConnection($pdo); }
public function getConnection() { if (!Environment::hasConnection()) { $this->markTestSkipped('No database connection available'); } if (self::$con === null) { self::$con = Environment::getService('connection'); } if ($this->connection === null) { $this->connection = self::$con; } return $this->createDefaultDBConnection($this->connection->getWrappedConnection(), Environment::getService('config')->get('psx_sql_db')); }
public function getAggregateHistoryFor(Identity $id, $offset = 0, $max = null) { $query = "SELECT * FROM `aggregate_events` WHERE identity = :identity"; if ($offset > 0) { $query .= " OFFSET {$offset}"; } if (!is_null($max)) { $query .= " LIMIT {$max}"; } $pdo = $this->conn->getWrappedConnection(); $stmt = $pdo->prepare($query); $stmt->execute([':identity' => (string) $id]); return new CommittedEvents($id, array_map(function ($row) { return unserialize($row['data']); }, $stmt->fetchAll(\PDO::FETCH_ASSOC))); }
/** * Closes connection if open, opens a unbuffered connection. * * @param Connection $connection * * @throws InvalidArgumentException */ public static function unbufferConnection(Connection $connection) { /** @var PDOConnection $wrappedConnection */ $wrappedConnection = $connection->getWrappedConnection(); if (!$wrappedConnection instanceof PDOConnection) { throw new InvalidArgumentException('unbufferConection can only be used with pdo_mysql Doctrine driver.'); } if ($wrappedConnection->getAttribute(PDO::ATTR_DRIVER_NAME) != 'mysql') { throw new InvalidArgumentException('unbufferConection can only be used with PDO mysql driver, got "' . $wrappedConnection->getAttribute(PDO::ATTR_DRIVER_NAME) . '" instead.'); } if ($connection->isConnected()) { $connection->close(); } $connection->getWrappedConnection()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); $connection->connect(); }
/** * Creates a new <tt>Statement</tt> for the given SQL and <tt>Connection</tt>. * * @param string $sql The SQL of the statement. * @param \Doctrine\DBAL\Connection $conn The connection on which the statement should be executed. */ public function __construct($sql, Connection $conn) { $this->sql = $sql; $this->stmt = $conn->getWrappedConnection()->prepare($sql); $this->conn = $conn; $this->platform = $conn->getDatabasePlatform(); }
public function getFixtureLoader() { $testerClass = '\\Jackalope\\Test\\Tester\\' . ucfirst(strtolower($this->connection->getWrappedConnection()->getAttribute(PDO::ATTR_DRIVER_NAME))); if (!class_exists($testerClass)) { // load Generic Tester if no database specific Tester class found $testerClass = '\\Jackalope\\Test\\Tester\\Generic'; } return new $testerClass(new \PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection($this->connection->getWrappedConnection(), "tests"), $this->fixturePath); }
/** * Create a simple schema the tests can run against. * * if $randomTables is true, some other tables will be created. * * @param bool $randomTables */ protected function createTestSchema($randomTables = false) { $pdo = $this->connection->getWrappedConnection(); $pdo->query('CREATE TABLE Customer ( id INTEGER PRIMARY KEY AUTO_INCREMENT, name VARCHAR(10) )'); $pdo->query('CREATE TABLE Billing ( id INTEGER PRIMARY KEY AUTO_INCREMENT, customer_id INTEGER, product VARCHAR(100), amount REAL, CONSTRAINT customer_id FOREIGN KEY (customer_id) REFERENCES Customer(id) )'); $pdo->query('CREATE INDEX billing_product ON Billing (product)'); if ($randomTables) { $pdo->query('CREATE TABLE RandomTable ( id INTEGER PRIMARY KEY AUTO_INCREMENT, name VARCHAR(10) )'); $pdo->query('CREATE TABLE RandomTable2 ( id INTEGER PRIMARY KEY AUTO_INCREMENT, name VARCHAR(10) )'); } // insert data $pdo->query('INSERT INTO Customer VALUES (1, "Markus")'); $pdo->query('INSERT INTO Customer VALUES (2, "Konstantin")'); $pdo->query('INSERT INTO Customer VALUES (3, "John")'); $pdo->query('INSERT INTO Customer VALUES (4, "Konrad")'); $pdo->query('INSERT INTO Customer VALUES (5, "Mark")'); $pdo->query('INSERT INTO Billing VALUES (1, 1, "IT", 42)'); $pdo->query('INSERT INTO Billing VALUES (2, 1, NULL, 1337)'); $pdo->query('INSERT INTO Billing VALUES (3, 2, "Some stuff", 1337)'); $pdo->query('INSERT INTO Billing VALUES (4, 5, "Another stuff", 1337)'); $pdo->query('INSERT INTO Billing VALUES (5, 5, "LOLj stuff", 1337)'); if ($randomTables) { $pdo->query('INSERT INTO RandomTable VALUES (1, "Foo")'); $pdo->query('INSERT INTO RandomTable VALUES (2, "Bar")'); $pdo->query('INSERT INTO RandomTable2 VALUES (1, "FooBar")'); } }
public function reset() { if (null === $this->connection) { throw new RepositoryException('Do not use RepositorySchema::reset when not instantiated with a connection'); } $this->connection->getWrappedConnection()->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT); foreach ($this->toDropSql($this->connection->getDatabasePlatform()) as $sql) { $this->connection->exec($sql); } $this->connection->getWrappedConnection()->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); foreach ($this->toSql($this->connection->getDatabasePlatform()) as $sql) { $this->connection->exec($sql); } }
/** * @param FactoryInterface $factory * @param Connection $conn */ public function __construct(FactoryInterface $factory, Connection $conn) { $this->factory = $factory; $this->valueConverter = $this->factory->get('PHPCR\\Util\\ValueConverter'); $this->conn = $conn; if ($conn->getDatabasePlatform() instanceof PostgreSqlPlatform) { $this->sequenceWorkspaceName = 'phpcr_workspaces_id_seq'; $this->sequenceNodeName = 'phpcr_nodes_id_seq'; $this->sequenceTypeName = 'phpcr_type_nodes_node_type_id_seq'; } // @TODO: move to "SqlitePlatform" and rename to "registerExtraFunctions"? if ($this->conn->getDatabasePlatform() instanceof SqlitePlatform) { $this->registerSqliteFunctions($this->conn->getWrappedConnection()); } }
/** * Initialize the dbal connection lazily */ private function initConnection() { if (true === $this->conn->isConnected() && true === $this->connectionInitialized) { return; } if ($this->conn->getDatabasePlatform() instanceof PostgreSqlPlatform) { $this->sequenceNodeName = 'phpcr_nodes_id_seq'; $this->sequenceTypeName = 'phpcr_type_nodes_node_type_id_seq'; } // @TODO: move to "SqlitePlatform" and rename to "registerExtraFunctions"? if ($this->conn->getDatabasePlatform() instanceof SqlitePlatform) { $this->registerSqliteFunctions($this->conn->getWrappedConnection()); } $this->connectionInitialized = true; }
private function getServerVersion() { $params = $this->con->getParams(); // Explicit platform version requested (supersedes auto-detection), so we respect it. if (isset($params['serverVersion'])) { return $params['serverVersion']; } $wrappedConnection = $this->con->getWrappedConnection(); if ($wrappedConnection instanceof ServerInfoAwareConnection) { return $wrappedConnection->getServerVersion(); } // Support DBAL 2.4 by accessing it directly when using PDO PgSQL if ($wrappedConnection instanceof \PDO) { return $wrappedConnection->getAttribute(\PDO::ATTR_SERVER_VERSION); } // If we cannot guess the version, the empty string will mean we won't use the code for newer versions when doing version checks. return ''; }
/** * {@inheritdoc} * @param \Doctrine\DBAL\Connection $connection */ public function initConnection(Connection $connection) { /** @var $pdo PDO */ $pdo = $connection->getWrappedConnection(); $this->fkSupported = version_compare('3.6.19', $pdo->getAttribute(PDO::ATTR_SERVER_VERSION)) < 0; $pdo->exec($this->getEnableForeignKeysSQL()); }
/** * @return mixed */ public function getServerVersion() { return $this->db->getWrappedConnection()->getServerVersion(); }
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) { $this->connection->executeQuery("SELECT public.get_message_func(" . $this->connection->getWrappedConnection()->quote($this->message, \PDO::PARAM_STR) . "::text);"); }
/** * Get the database server version * * It is used in the server_info admin page. * * @return string */ public function get_server_info() { return $this->conn->getWrappedConnection()->getAttribute(\PDO::ATTR_SERVER_VERSION); }
/** * {@inheritdoc} */ public function lastInsertId($name = null) { return (int) $this->connection->getWrappedConnection()->lastInsertId($name); }
/** * {@inheritdoc} * @param \Doctrine\DBAL\Connection $connection * * @throws \umi\dbal\exception\RuntimeException */ public function initConnection(Connection $connection) { /** @var $pdo PDO */ $pdo = $connection->getWrappedConnection(); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $params = $connection->getParams(); if (!isset($params['charset'])) { throw new RuntimeException("No connection charset specified"); } $pdo->exec('SET NAMES ' . $pdo->quote($params['charset'])); }
/** * Custom SQLite logic. * * @param Connection $connection */ private static function expandSqlite(Connection $connection) { // add support for REGEXP operator $connection->getWrappedConnection()->sqliteCreateFunction('regexp', function ($pattern, $data, $delimiter = '~', $modifiers = 'isuS') { if (isset($pattern, $data)) { return preg_match(sprintf('%1$s%2$s%1$s%3$s', $delimiter, $pattern, $modifiers), $data) > 0; } return; }); }