9a6c0b9920e802c49656af2d4bd2b41eabb7e766
[yaffs-website] / vendor / gabordemooij / redbean / RedBeanPHP / RedException / SQL.php
1 <?php
2
3 namespace RedBeanPHP\RedException;
4
5 use RedBeanPHP\RedException as RedException;
6
7 /**
8  * SQL Exception.
9  * Represents a generic database exception independent of the underlying driver.
10  *
11  * @file       RedBeanPHP/RedException/SQL.php
12  * @author     Gabor de Mooij and the RedBeanPHP Community
13  * @license    BSD/GPLv2
14  *
15  * @copyright
16  * (c) copyright G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
17  * This source file is subject to the BSD/GPLv2 License that is bundled
18  * with this source code in the file license.txt.
19  */
20 class SQL extends RedException
21 {
22         /**
23          * @var string
24          */
25         private $sqlState;
26
27         /**
28          * Returns an ANSI-92 compliant SQL state.
29          *
30          * @return string
31          */
32         public function getSQLState()
33         {
34                 return $this->sqlState;
35         }
36
37         /**
38          * Returns the raw SQL STATE, possibly compliant with
39          * ANSI SQL error codes - but this depends on database driver.
40          *
41          * @param string $sqlState SQL state error code
42          *
43          * @return void
44          */
45         public function setSQLState( $sqlState )
46         {
47                 $this->sqlState = $sqlState;
48         }
49
50         /**
51          * To String prints both code and SQL state.
52          *
53          * @return string
54          */
55         public function __toString()
56         {
57                 return '[' . $this->getSQLState() . '] - ' . $this->getMessage()."\n".
58                                 'trace: ' . $this->getTraceAsString();
59         }
60 }