composer package updates
[openemr.git] / vendor / doctrine / dbal / lib / Doctrine / DBAL / Driver / SQLAnywhere / SQLAnywhereException.php
blob046938037d5f1644a257d836410f9766b53f5c98
1 <?php
2 /*
3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.doctrine-project.org>.
20 namespace Doctrine\DBAL\Driver\SQLAnywhere;
22 use Doctrine\DBAL\Driver\AbstractDriverException;
24 /**
25 * SAP Sybase SQL Anywhere driver exception.
27 * @author Steve Müller <st.mueller@dzh-online.de>
28 * @link www.doctrine-project.org
29 * @since 2.5
31 class SQLAnywhereException extends AbstractDriverException
33 /**
34 * Helper method to turn SQL Anywhere error into exception.
36 * @param resource|null $conn The SQL Anywhere connection resource to retrieve the last error from.
37 * @param resource|null $stmt The SQL Anywhere statement resource to retrieve the last error from.
39 * @return SQLAnywhereException
41 * @throws \InvalidArgumentException
43 public static function fromSQLAnywhereError($conn = null, $stmt = null)
45 if (null !== $conn && ! (is_resource($conn))) {
46 throw new \InvalidArgumentException('Invalid SQL Anywhere connection resource given: ' . $conn);
49 if (null !== $stmt && ! (is_resource($stmt))) {
50 throw new \InvalidArgumentException('Invalid SQL Anywhere statement resource given: ' . $stmt);
53 $state = $conn ? sasql_sqlstate($conn) : sasql_sqlstate();
54 $code = null;
55 $message = null;
57 /**
58 * Try retrieving the last error from statement resource if given
60 if ($stmt) {
61 $code = sasql_stmt_errno($stmt);
62 $message = sasql_stmt_error($stmt);
65 /**
66 * Try retrieving the last error from the connection resource
67 * if either the statement resource is not given or the statement
68 * resource is given but the last error could not be retrieved from it (fallback).
69 * Depending on the type of error, it is sometimes necessary to retrieve
70 * it from the connection resource even though it occurred during
71 * a prepared statement.
73 if ($conn && ! $code) {
74 $code = sasql_errorcode($conn);
75 $message = sasql_error($conn);
78 /**
79 * Fallback mode if either no connection resource is given
80 * or the last error could not be retrieved from the given
81 * connection / statement resource.
83 if ( ! $conn || ! $code) {
84 $code = sasql_errorcode();
85 $message = sasql_error();
88 if ($message) {
89 return new self('SQLSTATE [' . $state . '] [' . $code . '] ' . $message, $state, $code);
92 return new self('SQL Anywhere error occurred but no error message was retrieved from driver.', $state, $code);