public function testAffectedRowsError() { $this->connection->getDriver()->setError('affected-rows'); $stmt = Statement::createDelete($this->connection, 'table'); $stmt->run(); $r = new ReflectionProperty($stmt, 'affectedRows'); $r->setAccessible(true); $this->assertFalse($r->getValue($stmt)); $this->setExpectedException('Neevo\\DriverException', 'Affected rows are not supported by this driver.'); $stmt->affectedRows(); }
/** * Creates connection to database. * @param array $config Configuration options * @throws DriverException */ public function connect(array $config) { Connection::alias($config, 'database', 'file'); Connection::alias($config, 'updateLimit', 'update_limit'); $defaults = array('memory' => false, 'resource' => null, 'updateLimit' => false, 'charset' => 'UTF-8', 'dbcharset' => 'UTF-8', 'persistent' => false, 'unbuffered' => false); $config += $defaults; if ($config['memory']) { $config['database'] = ':memory:'; } // Connect if (is_resource($config['resource'])) { $connection = $config['resource']; } elseif (!isset($config['database'])) { throw new DriverException("No database file selected."); } elseif ($config['persistent']) { $connection = @sqlite_popen($config['database'], 0666, $error); } else { $connection = @sqlite_open($config['database'], 0666, $error); } if (!is_resource($connection)) { throw new DriverException("Opening database file '{$config['database']}' failed."); } $this->resource = $connection; $this->updateLimit = (bool) $config['updateLimit']; // Set charset $this->dbCharset = $config['dbcharset']; $this->charset = $config['charset']; if (strcasecmp($this->dbCharset, $this->charset) === 0) { $this->dbCharset = $this->charset = null; } $this->unbuffered = $config['unbuffered']; $this->persistent = $config['persistent']; }
public function testCloseConnection() { $this->instance->attachObserver($o = new DummyObserver(), DummyObserver::DISCONNECT); $this->instance->__destruct(); $this->assertTrue($this->instance->getDriver()->isClosed()); $this->assertTrue($o->isNotified()); }
/** * Creates connection to database. * @param array $config Configuration options * @throws DriverException */ public function connect(array $config) { Connection::alias($config, 'database', 'file'); Connection::alias($config, 'updateLimit', 'update_limit'); $defaults = array('memory' => false, 'resource' => null, 'updateLimit' => false, 'charset' => 'UTF-8', 'dbcharset' => 'UTF-8'); $config += $defaults; if ($config['memory']) { $config['database'] = ':memory:'; } // Connect if ($config['resource'] instanceof SQLite3) { $connection = $config['resource']; } elseif (!isset($config['database'])) { throw new DriverException("No database file selected."); } else { try { $connection = new SQLite3($config['database']); } catch (Exception $e) { throw new DriverException($e->getMessage(), $e->getCode()); } } if (!$connection instanceof SQLite3) { throw new DriverException("Opening database file '{$config['database']}' failed."); } $this->resource = $connection; $this->updateLimit = (bool) $config['updateLimit']; // Set charset $this->dbCharset = $config['dbcharset']; $this->charset = $config['charset']; if (strcasecmp($this->dbCharset, $this->charset) === 0) { $this->dbCharset = $this->charset = null; } }
/** * Detaches given observer. * @param ObserverInterface $observer */ public function detachObserver(ObserverInterface $observer) { $this->connection->detachObserver($observer); $this->observers->detach($observer); $e = new NeevoException(); $e->detachObserver($observer); }
/** * Returns the name of the PRIMARY KEY column. * @return string|null */ public function getPrimaryKey() { $table = $this->getTable(); if (!$table) { return null; } $key = null; $cached = $this->connection->getCache()->fetch($table . '_primaryKey'); if ($cached === null) { try { $key = $this->connection->getDriver()->getPrimaryKey($table, isset($this->resultSet) ? $this->resultSet : null); } catch (NeevoException $e) { return null; } $this->connection->getCache()->store($table . '_primaryKey', $key); return $key === '' ? null : $key; } return $cached === '' ? null : $cached; }
/** * Creates connection to database. * @param array $config Configuration options * @throws DriverException */ public function connect(array $config) { Connection::alias($config, 'resource', 'pdo'); // Defaults $defaults = array('dsn' => null, 'resource' => null, 'username' => null, 'password' => null, 'options' => array()); $config += $defaults; // Connect if ($config['resource'] instanceof PDO) { $this->resource = $config['resource']; } else { try { $this->resource = new PDO($config['dsn'], $config['username'], $config['password'], $config['options']); } catch (PDOException $e) { throw new DriverException($e->getMessage(), $e->getCode()); } } if (!$this->resource) { throw new DriverException('Connection failed.'); } $this->driverName = $this->resource->getAttribute(PDO::ATTR_DRIVER_NAME); }
/** @return DummyParserDriver */ private function parser(BaseStatement $stmt) { $instance = $this->connection->getParser(); return new $instance($stmt); }