cvs: pear /DB/DB sybase.php
| From: | Ant�nio Carlos Ven�ncio J�nior | Date: | Tue, 23 Jul 2002 00:58:55 +0000 |
| Subject: | cvs: pear /DB/DB sybase.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-5289@lists.php.net to get a copy of this message | ||
floripa Mon Jul 22 20:58:55 2002 EDT
Modified files:
/pear/DB/DB sybase.php
Log:
- more errorcode_map
- changed connect() to reflect Sybase's behaviour
- improvements on errorCode() detection
- use sybaseRaiseError() instead of raiseError() whenever possible
Index: pear/DB/DB/sybase.php
diff -u pear/DB/DB/sybase.php:1.4 pear/DB/DB/sybase.php:1.5
--- pear/DB/DB/sybase.php:1.4 Sun Jul 21 07:59:17 2002
+++ pear/DB/DB/sybase.php Mon Jul 22 20:58:55 2002
@@ -13,10 +13,11 @@
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
-// | Author: Sterling Hughes <sterling@php.net> |
+// | Authors: Sterling Hughes <sterling@php.net> |
+// | Antônio Carlos Venâncio Júnior <floripa@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: sybase.php,v 1.4 2002/07/21 11:59:17 floripa Exp $
+// $Id: sybase.php,v 1.5 2002/07/23 00:58:55 floripa Exp $
//
// Database independent query interface definition for PHP's Sybase
// extension.
@@ -53,7 +54,15 @@
'limit' => 'emulate'
);
$this->errorcode_map = array(
- 102 => DB_ERROR_SYNTAX,
+ 102 => DB_ERROR_SYNTAX,
+ 105 => DB_ERROR_SYNTAX,
+ 156 => DB_ERROR_SYNTAX,
+ 208 => DB_ERROR_NOSUCHTABLE,
+ 257 => DB_ERROR_INVALID_NUMBER,
+ 3701 => DB_ERROR_NOSUCHTABLE,
+ 10304 => DB_ERROR_ACCESS_VIOLATION,
+ 10330 => DB_ERROR_ACCESS_VIOLATION,
+ 10331 => DB_ERROR_ACCESS_VIOLATION
);
}
@@ -78,28 +87,19 @@
$user = $dsninfo['username'];
$pw = $dsninfo['password'];
- $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] :
'localhost';
+ $interface = $dsninfo['hostspec'] ? $dsninfo['hostspec'] :
'localhost';
$connect_function = $persistent ? 'sybase_pconnect' : 'sybase_connect';
- if ($dbhost && $user && $pw) {
- $conn = $connect_function($dbhost, $user, $pw);
- } elseif ($dbhost && $user) {
- $conn = $connect_function($dbhost, $user);
- } elseif ($dbhost) {
- $conn = $connect_function($dbhost);
+ if ($interface && $user && $pw) {
+ $conn = $connect_function($interface, $user, $pw);
} else {
- $conn = $connect_function();
+ $conn = FALSE;
}
if (!$conn) {
return $this->raiseError(DB_ERROR_CONNECT_FAILED);
}
- if ($dsninfo['database']) {
- if (!@sybase_select_db($dsninfo['database'], $conn)) {
- return $this->raiseError(DB_ERROR_NODBSELECTED);
- }
- }
$this->connection = $conn;
return DB_OK;
}
@@ -137,28 +137,49 @@
// }}}
// {{{ errorCode()
- function errorCode($errmsg = '')
+ function errorCode($errormsg = '')
{
- if (!empty($errmsg)) {
- if (ereg ('^Incorrect syntax near', $errmsg)) {
- $error['code'] = 102;
- $error['userinfo'] = $this->last_query . '<br>';
+ static $error_regexps;
+ if (empty($error_regexps)) {
+ $error_regexps = array(
+ '/Incorrect syntax near [\"\'].+[\"\']\./'
+ => 102,
+ '/^Unclosed quote before the character string
[\"\'].*[\"\']\./'
+ => 105,
+ '/Incorrect syntax near the keyword
[\"\'].+[\"\']\./'
+ => 156,
+ '/Implicit conversion from datatype [\"\'].+[\"\'] to
[\"\'].+[\"\'] is not allowed\./'
+ => 257,
+ '/Cannot drop the table [\"\'].+[\"\'], because it
doesn\'t exist in the system catalogs\./'
+ => 3701,
+ '/Only the owner of object [\"\'].+[\"\'] or a user with
System Administrator \(SA\) role can run this command\./'
+ => 10304,
+ '/^.+ permission denied on object .+, database .+, owner .+/'
+ => 10330,
+ '/^.* permission denied, database .+, owner .+/'
+ => 10331,
+ '/[^.*] not found\./'
+ => 208
+ );
+ }
+ while (list($regexp, $code) = each($error_regexps)) {
+ if (preg_match($regexp, $errormsg)) {
+ $error['code'] = $code;
}
- $error['userinfo'] .= $errmsg;
- if (isset($this->errorcode_map[$error['code']])) {
- $error['message'] = $this->errorcode_map[$error['code']];
- }
- return $error;
}
-
- // Fall back to DB_ERROR if there was no mapping.
- return DB_ERROR;
+ $error['userinfo'] = $errormsg;
+ if (isset($error['code']) &&
isset($this->errorcode_map[$error['code']])) {
+ $error['message'] = $this->errorcode_map[$error['code']];
+ } else {
+ return DB_ERROR;
+ }
+ return $error;
}
// }}}
// {{{ sybaseRaiseError()
- function sybaseRaiseError()
+ function sybaseRaiseError($errno = null)
{
$native = $this->errorNative();
$error = $this->errorCode($native);
@@ -258,7 +279,7 @@
{
if ($rownum !== null) {
if (!sybase_data_seek($result, $rownum)) {
- return $this->raiseError();
+ return $this->sybaseRaiseError();
}
}
$ar = ($fetchmode & DB_FETCHMODE_ASSOC) ? @sybase_fetch_array($result) :
@sybase_fetch_row($result);
@@ -266,8 +287,7 @@
// reported not work as seems that sybase_get_last_message()
// always return a message here
//if ($errmsg = sybase_get_last_message()) {
- // echo $errmsg;
- //return $this->raiseError($errmsg);
+ // return $this->sybaseRaiseError($errmsg);
//} else {
return null;
//}
@@ -316,7 +336,7 @@
{
$cols = @sybase_num_fields($result);
if (!$cols) {
- return $this->raiseError();
+ return $this->sybaseRaiseError();
}
return $cols;
}
@@ -337,7 +357,7 @@
{
$rows = @sybase_num_rows($result);
if ($rows === null) {
- return $this->raiseError();
+ return $this->sybaseRaiseError();
}
return $rows;
}