Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F25451736
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/Exceptions/SqlException.php b/src/Exceptions/SqlException.php
index cb10787..2bca544 100644
--- a/src/Exceptions/SqlException.php
+++ b/src/Exceptions/SqlException.php
@@ -1,96 +1,96 @@
<?php
namespace Keruald\Database\Exceptions;
use RuntimeException;
use Exception;
class SqlException extends RuntimeException {
///
/// Constants
///
protected const DEFAULT_MESSAGE =
"An exception occurred during a database operation.";
///
/// Properties
///
/**
* @var string The query run when the error occurred.
*/
public readonly string $query;
/**
* A context representing the state of the database engine and the error.
*
* @var string[]
*/
public readonly array $state;
///
/// Constructors
///
private function __construct (
?Exception $innerException = null,
string $query = '',
array $state = [],
) {
$this->query = $query;
$this->state = $state;
if ($innerException !== null) {
// Build from exception
parent::__construct(
$innerException->getMessage(),
$innerException->getCode(),
$innerException,
);
} else {
// Build from state
parent::__construct(
$this->state['error'] ?? self::DEFAULT_MESSAGE,
- $this->state['errno'] ?? 0,
+ (int)$this->state['errno'] ?? 0,
);
}
}
/**
* Normalize a SQL exception thrown by a PHP database extension.
*
* @param Exception $innerException
* @param string $query
* @param array $context
* @return static
*/
public static function fromException (
Exception $innerException,
string $query,
array $context
) : self {
return new self($innerException, $query, $context);
}
/**
* Create a SQL exception from a query and a context.
*
* @param string $query
* @param array $context
* @return static
*/
public static function fromQuery (string $query, array $context) : self {
return new self(null, $query, $context);
}
///
/// Getters
///
public function getQuery () : string {
return $this->query;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Apr 16, 05:32 (17 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3626575
Default Alt Text
(2 KB)
Attached To
Mode
rKDB Keruald Database
Attached
Detach File
Event Timeline
Log In to Comment