1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PHPPgAdmin v6.0.0-beta.43 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace PHPPgAdmin; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @file |
11
|
|
|
* Handles Exceptions on ADODb |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Released under both BSD license and Lesser GPL library license. Whenever |
16
|
|
|
* there is any discrepancy between the two licenses, the BSD license will take |
17
|
|
|
* precedence. |
18
|
|
|
* Set tabs to 4 for best viewing. |
19
|
|
|
* Latest version is available at http://php.weblogs.com |
20
|
|
|
* Exception-handling code using PHP5 exceptions (try-catch-throw). |
21
|
|
|
* |
22
|
|
|
* @package PHPPgAdmin |
23
|
|
|
* |
24
|
|
|
* @author John Lim |
25
|
|
|
* @copyright 2000-2013 John Lim <[email protected]> |
26
|
|
|
* @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community |
27
|
|
|
* @license MIT |
|
|
|
|
28
|
|
|
* |
29
|
|
|
* @version Release: 5.20.9 |
30
|
|
|
*/ |
31
|
|
|
class ADOdbException extends \Exception |
32
|
|
|
{ |
33
|
|
|
public $dbms; |
34
|
|
|
public $fn; |
35
|
|
|
public $sql = ''; |
36
|
|
|
public $params = ''; |
37
|
|
|
public $host = ''; |
38
|
|
|
public $database = ''; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Default Error Handler. This will be called with the following params. |
42
|
|
|
* |
43
|
|
|
* @param string $dbms the RDBMS you are connecting to |
44
|
|
|
* @param string $fn the name of the calling function (in uppercase) |
45
|
|
|
* @param number $errno the native error number from the database |
46
|
|
|
* @param string $errmsg the native error msg from the database |
47
|
|
|
* @param string $p1 $fn specific parameter - see below |
48
|
|
|
* @param string $p2 parameter 2 |
49
|
|
|
* @param mixed $thisConnection connection |
50
|
|
|
* |
51
|
|
|
* @throws \Exception |
52
|
|
|
*/ |
53
|
|
|
public function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection) |
54
|
|
|
{ |
55
|
|
|
switch ($fn) { |
56
|
|
|
case 'EXECUTE': |
57
|
|
|
$this->sql = is_array($p1) ? $p1[0] : $p1; |
|
|
|
|
58
|
|
|
$this->params = $p2; |
59
|
|
|
$s = "${dbms} error: [${errno}: ${errmsg}] in ${fn}(\"{$this->sql}\")"; |
60
|
|
|
|
61
|
|
|
break; |
62
|
|
|
case 'PCONNECT': |
63
|
|
|
case 'CONNECT': |
64
|
|
|
$user = $thisConnection->user; |
65
|
|
|
$s = "${dbms} error: [${errno}: ${errmsg}] in ${fn}(${p1}, '${user}', '****', ${p2})"; |
66
|
|
|
|
67
|
|
|
break; |
68
|
|
|
default: |
69
|
|
|
$s = "${dbms} error: [${errno}: ${errmsg}] in ${fn}(${p1}, ${p2})"; |
70
|
|
|
|
71
|
|
|
break; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$this->dbms = $dbms; |
75
|
|
|
if ($thisConnection) { |
76
|
|
|
$this->host = $thisConnection->host; |
77
|
|
|
$this->database = $thisConnection->database; |
78
|
|
|
} |
79
|
|
|
$this->fn = $fn; |
80
|
|
|
$this->msg = $errmsg; |
81
|
|
|
|
82
|
|
|
if (!is_numeric($errno)) { |
|
|
|
|
83
|
|
|
$errno = -1; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
parent::__construct($s, $errno); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Default Error Handler. This will be called with the following params. |
91
|
|
|
* |
92
|
|
|
* @param string $dbms the RDBMS you are connecting to |
93
|
|
|
* @param string $fn the name of the calling function (in uppercase) |
94
|
|
|
* @param number $errno the native error number from the database |
95
|
|
|
* @param string $errmsg the native error msg from the database |
96
|
|
|
* @param string $p1 $fn specific parameter - see below |
97
|
|
|
* @param string $p2 parameter 2 |
98
|
|
|
* @param mixed $thisConnection connection |
99
|
|
|
* |
100
|
|
|
* @throws \PHPPgAdmin\ADOdbException |
101
|
|
|
* |
102
|
|
|
* @internal param $P2 $fn specific parameter - see below |
103
|
|
|
*/ |
104
|
|
|
public static function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection) |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
if (error_reporting() == 0) { |
107
|
|
|
return; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
111
|
|
|
|
112
|
|
|
$btarray0 = [ |
113
|
|
|
'msg' => 'ADOdbException at ', |
114
|
|
|
'class' => $backtrace[1]['class'], |
115
|
|
|
'type' => $backtrace[1]['type'], |
116
|
|
|
'function' => $backtrace[1]['function'], |
117
|
|
|
'spacer' => ' ', |
118
|
|
|
'line' => $backtrace[0]['line'], |
119
|
|
|
]; |
120
|
|
|
|
121
|
|
|
$errmsg = htmlentities(\PHPPgAdmin\Traits\HelperTrait::br2ln($errmsg), ENT_NOQUOTES); |
122
|
|
|
$p1 = htmlentities(\PHPPgAdmin\Traits\HelperTrait::br2ln($p1), ENT_NOQUOTES); |
123
|
|
|
$p2 = htmlentities(\PHPPgAdmin\Traits\HelperTrait::br2ln($p2), ENT_NOQUOTES); |
124
|
|
|
|
125
|
|
|
switch ($fn) { |
126
|
|
|
case 'EXECUTE': |
127
|
|
|
$sql = str_replace( |
128
|
|
|
[ |
129
|
|
|
'SELECT', |
130
|
|
|
'WHERE', |
131
|
|
|
'GROUP BY', |
132
|
|
|
'FROM', |
133
|
|
|
'HAVING', |
134
|
|
|
'LIMIT', |
135
|
|
|
], |
136
|
|
|
["\nSELECT", "\nWHERE", "\nGROUP BY", "\nFROM", "\nHAVING", "\nLIMIT"], |
137
|
|
|
$p1 |
138
|
|
|
); |
139
|
|
|
|
140
|
|
|
$inputparams = $p2; |
141
|
|
|
|
142
|
|
|
$error_msg = '<p><b>strsqlerror</b><br />' . nl2br($errmsg) . '</p> <p><b>SQL:</b><br />' . nl2br($sql) . '</p> '; |
143
|
|
|
|
144
|
|
|
echo '<table class="error" cellpadding="5"><tr><td>' . nl2br($error_msg) . '</td></tr></table><br />' . "\n"; |
145
|
|
|
|
146
|
|
|
break; |
147
|
|
|
case 'PCONNECT': |
148
|
|
|
case 'CONNECT': |
149
|
|
|
// do nothing; |
150
|
|
|
break; |
151
|
|
|
default: |
152
|
|
|
$s = "${dbms} error: [${errno}: ${errmsg}] in ${fn}(${p1}, ${p2})\n"; |
153
|
|
|
echo "<table class=\"error\" cellpadding=\"5\"><tr><td>{$s}</td></tr></table><br />\n"; |
154
|
|
|
|
155
|
|
|
break; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
$tag = implode('', $btarray0); |
159
|
|
|
|
160
|
|
|
\PC::debug(['errno' => $errno, 'fn' => $fn, 'errmsg' => $errmsg], $tag); |
161
|
|
|
|
162
|
|
|
throw new \PHPPgAdmin\ADOdbException($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|