Throw DBALException instead of driver exception from wrapper classes

parent d415d040
......@@ -215,7 +215,7 @@ class Connection
{
$platform = $this->getDatabasePlatform();
$query = $platform->getDummySelectSQL($platform->getCurrentDatabaseExpression());
$database = $this->query($query)->fetchOne();
$database = $this->fetchOne($query);
assert(is_string($database) || $database === null);
......@@ -344,7 +344,7 @@ class Connection
*
* @return string|null
*
* @throws Exception
* @throws DBALException
*/
private function getDatabasePlatformVersion()
{
......@@ -408,7 +408,11 @@ class Connection
// Automatic platform version detection.
if ($connection instanceof ServerInfoAwareConnection) {
return $connection->getServerVersion();
try {
return $connection->getServerVersion();
} catch (DriverException $e) {
throw $this->convertException($e);
}
}
// Unable to detect platform version.
......@@ -1131,10 +1135,16 @@ class Connection
* @param string|null $seqName Name of the sequence object from which the ID should be returned.
*
* @return string A string representation of the last inserted ID.
*
* @throws DBALException
*/
public function lastInsertId($seqName = null)
{
return $this->getWrappedConnection()->lastInsertId($seqName);
try {
return $this->getWrappedConnection()->lastInsertId($seqName);
} catch (DriverException $e) {
throw $this->convertException($e);
}
}
/**
......@@ -1386,7 +1396,7 @@ class Connection
throw ConnectionException::savepointsNotSupported();
}
$this->getWrappedConnection()->exec($this->platform->createSavePoint($savepoint));
$this->executeUpdate($this->platform->createSavePoint($savepoint));
}
/**
......@@ -1408,7 +1418,7 @@ class Connection
return;
}
$this->getWrappedConnection()->exec($this->platform->releaseSavePoint($savepoint));
$this->executeUpdate($this->platform->releaseSavePoint($savepoint));
}
/**
......@@ -1426,7 +1436,7 @@ class Connection
throw ConnectionException::savepointsNotSupported();
}
$this->getWrappedConnection()->exec($this->platform->rollbackSavePoint($savepoint));
$this->executeUpdate($this->platform->rollbackSavePoint($savepoint));
}
/**
......
......@@ -95,27 +95,34 @@ class Statement
* @param mixed $type Either a PDO binding type or a DBAL mapping type name or instance.
*
* @return bool TRUE on success, FALSE on failure.
*
* @throws DBALException
*/
public function bindValue($name, $value, $type = ParameterType::STRING)
{
$this->params[$name] = $value;
$this->types[$name] = $type;
$bindingType = ParameterType::STRING;
if ($type !== null) {
if (is_string($type)) {
$type = Type::getType($type);
}
$bindingType = $type;
if ($type instanceof Type) {
$value = $type->convertToDatabaseValue($value, $this->platform);
$bindingType = $type->getBindingType();
} else {
$bindingType = $type;
}
}
try {
return $this->stmt->bindValue($name, $value, $bindingType);
} catch (Exception $e) {
throw $this->conn->convertException($e);
}
return $this->stmt->bindValue($name, $value);
}
/**
......@@ -130,13 +137,19 @@ class Statement
* so that PHP allocates enough memory to hold the returned value.
*
* @return bool TRUE on success, FALSE on failure.
*
* @throws DBALException
*/
public function bindParam($name, &$var, $type = ParameterType::STRING, $length = null)
{
$this->params[$name] = $var;
$this->types[$name] = $type;
return $this->stmt->bindParam($name, $var, $type, $length);
try {
return $this->stmt->bindParam($name, $var, $type, $length);
} catch (Exception $e) {
throw $this->conn->convertException($e);
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment