1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | namespace Doctrine\DBAL\Driver\SQLAnywhere; |
||||
6 | |||||
7 | use Doctrine\DBAL\Driver\AbstractDriverException; |
||||
8 | use function sasql_error; |
||||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||
9 | use function sasql_errorcode; |
||||
0 ignored issues
–
show
|
|||||
10 | use function sasql_sqlstate; |
||||
0 ignored issues
–
show
|
|||||
11 | use function sasql_stmt_errno; |
||||
0 ignored issues
–
show
|
|||||
12 | use function sasql_stmt_error; |
||||
0 ignored issues
–
show
|
|||||
13 | |||||
14 | /** |
||||
15 | * SAP Sybase SQL Anywhere driver exception. |
||||
16 | * |
||||
17 | * @psalm-immutable |
||||
18 | */ |
||||
19 | class SQLAnywhereException extends AbstractDriverException |
||||
20 | { |
||||
21 | /** |
||||
22 | * Helper method to turn SQL Anywhere error into exception. |
||||
23 | * |
||||
24 | * @param resource|null $conn The SQL Anywhere connection resource to retrieve the last error from. |
||||
25 | * @param resource|null $stmt The SQL Anywhere statement resource to retrieve the last error from. |
||||
26 | */ |
||||
27 | public static function fromSQLAnywhereError($conn = null, $stmt = null) : self |
||||
28 | { |
||||
29 | $state = $conn !== null ? sasql_sqlstate($conn) : sasql_sqlstate(); |
||||
0 ignored issues
–
show
The function
sasql_sqlstate was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
30 | $code = 0; |
||||
31 | $message = null; |
||||
32 | |||||
33 | /** |
||||
34 | * Try retrieving the last error from statement resource if given |
||||
35 | */ |
||||
36 | if ($stmt !== null) { |
||||
37 | $code = sasql_stmt_errno($stmt); |
||||
0 ignored issues
–
show
The function
sasql_stmt_errno was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
38 | $message = sasql_stmt_error($stmt); |
||||
0 ignored issues
–
show
The function
sasql_stmt_error was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
39 | } |
||||
40 | |||||
41 | /** |
||||
42 | * Try retrieving the last error from the connection resource |
||||
43 | * if either the statement resource is not given or the statement |
||||
44 | * resource is given but the last error could not be retrieved from it (fallback). |
||||
45 | * Depending on the type of error, it is sometimes necessary to retrieve |
||||
46 | * it from the connection resource even though it occurred during |
||||
47 | * a prepared statement. |
||||
48 | */ |
||||
49 | if ($conn !== null && $code === 0) { |
||||
50 | $code = sasql_errorcode($conn); |
||||
0 ignored issues
–
show
The function
sasql_errorcode was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
51 | $message = sasql_error($conn); |
||||
0 ignored issues
–
show
The function
sasql_error was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
52 | } |
||||
53 | |||||
54 | /** |
||||
55 | * Fallback mode if either no connection resource is given |
||||
56 | * or the last error could not be retrieved from the given |
||||
57 | * connection / statement resource. |
||||
58 | */ |
||||
59 | if ($conn === null || $code === 0) { |
||||
60 | $code = sasql_errorcode(); |
||||
61 | $message = sasql_error(); |
||||
62 | } |
||||
63 | |||||
64 | if ($message) { |
||||
65 | return new self('SQLSTATE [' . $state . '] [' . $code . '] ' . $message, $state, $code); |
||||
66 | } |
||||
67 | |||||
68 | return new self('SQL Anywhere error occurred but no error message was retrieved from driver.', $state, $code); |
||||
69 | } |
||||
70 | } |
||||
71 |