cvs: pear /DB/DB ibase.php
| From: | Tomas V.V.Cox | Date: | Sat, 07 Jun 2003 18:29:59 +0000 |
| Subject: | cvs: pear /DB/DB ibase.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-10754@lists.php.net to get a copy of this message | ||
cox Sat Jun 7 14:29:59 2003 EDT
Modified files:
/pear/DB/DB ibase.php
Log:
Fix for "sync error" message
Fix limitQuery() when 'firebird' syntax is passed
Return mismatch error when the placeholder '&' is found
Use the new ibase_fetch_assoc() if avaible for DB_FETCHMOD_ASSOC
Fix SKIP param starting at 1 when should start at 0
Index: pear/DB/DB/ibase.php
diff -u pear/DB/DB/ibase.php:1.9 pear/DB/DB/ibase.php:1.10
--- pear/DB/DB/ibase.php:1.9 Wed May 7 12:58:28 2003
+++ pear/DB/DB/ibase.php Sat Jun 7 14:29:59 2003
@@ -16,11 +16,14 @@
// | Author: Sterling Hughes <sterling@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: ibase.php,v 1.9 2003/05/07 16:58:28 mj Exp $
+// $Id: ibase.php,v 1.10 2003/06/07 18:29:59 cox Exp $
//
// Database independent query interface definition for PHP's Interbase
// extension.
-//
+//
+// Bugs:
+// - If dbsyntax is not firebird, the limitQuery may fail
+// - The palceholders '&' and '!' don't work here
require_once 'DB/common.php';
@@ -47,7 +50,7 @@
'pconnect' => true,
'transactions' => true,
'limit' => false
- );
+ );
// just a few of the tons of Interbase error codes listed in the
// Language Reference section of the Interbase manual
$this->errorcode_map = array(
@@ -117,7 +120,10 @@
if (!$conn) {
return $this->ibaseRaiseError(DB_ERROR_CONNECT_FAILED);
}
- $this->connection = $conn;
+ $this->connection = $conn;
+ if ($this->dsn['dbsyntax'] == 'firebird') {
+ $this->features['limit'] = 'alter';
+ }
return DB_OK;
}
@@ -138,8 +144,8 @@
{
$ismanip = DB::isManip($query);
$this->last_query = $query;
- $query = $this->modifyQuery($query);
- $result = @ibase_query($this->connection, $query);
+ $query = $this->modifyQuery($query);
+ $result = ibase_query($this->connection, $query);
if (!$result) {
return $this->ibaseRaiseError();
}
@@ -171,7 +177,8 @@
function modifyLimitQuery($query, $from, $count)
{
if ($this->dsn['dbsyntax'] == 'firebird') {
- $from++; // SKIP starts from 1, ie SKIP 1 starts from the first record
+ //$from++; // SKIP starts from 1, ie SKIP 1 starts from the first record
+ // (cox) Seems that SKIP starts in 0
$query = preg_replace('/^\s*select\s(.*)$/is',
"SELECT FIRST $count SKIP $from $1", $query);
}
@@ -201,22 +208,26 @@
// {{{ fetchInto()
function fetchInto($result, &$ar, $fetchmode, $rownum = null)
- {
+ {
if ($rownum !== NULL) {
return $this->ibaseRaiseError(DB_ERROR_NOT_CAPABLE);
}
- if ($fetchmode & DB_FETCHMODE_ASSOC) {
- $ar = get_object_vars(ibase_fetch_object($result));
+ if ($fetchmode & DB_FETCHMODE_ASSOC) {
+ if (function_exists('ibase_fetch_assoc')) {
+ $ar = ibase_fetch_assoc($result);
+ } else {
+ $ar = get_object_vars(ibase_fetch_object($result));
+ }
if ($ar && $this->options['optimize'] == 'portability')
{
$ar = array_change_key_case($ar, CASE_LOWER);
- }
+ }
} else {
$ar = ibase_fetch_row($result);
- }
+ }
if (!$ar) {
if ($errmsg = ibase_errmsg()) {
return $this->ibaseRaiseError(null, $errmsg);
- } else {
+ } else {
return null;
}
}
@@ -264,9 +275,12 @@
// {{{ prepare()
function prepare($query)
- {
+ {
+ if (strpos($query, '&') !== false) {
+ return $this->raiseError(null, "Placeholder '&' not
supported");
+ }
$this->last_query = $query;
- $query = $this->modifyQuery($query);
+ $query = $this->modifyQuery($query);
$stmt = ibase_prepare($query);
$this->manip_query[(int)$stmt] = DB::isManip($query);
return $stmt;
@@ -276,8 +290,12 @@
// {{{ execute()
function execute($stmt, $data = false)
- {
- $result = ibase_execute($stmt, $data);
+ {
+ if (!sizeof($data)) {
+ return $this->raiseError(DB_ERROR_MISMATCH);
+ }
+ $data = array_merge(array($stmt), $data);
+ $result = call_user_func_array('ibase_execute', $data);
if (!$result) {
return $this->ibaseRaiseError();
}
@@ -340,7 +358,7 @@
do {
$this->pushErrorHandling(PEAR_ERROR_RETURN);
$result = $this->query("SELECT GEN_ID(${sqn}_SEQ, 1) FROM RDB\$GENERATORS"
- ." WHERE RDB\$GENERATOR_NAME='${sqn}_SEQ'");
+ ." WHERE RDB\$GENERATOR_NAME='${sqn}_SEQ'");
$this->popErrorHandling();
if ($ondemand && DB::isError($result)) {
$repeat = 1;
@@ -353,7 +371,7 @@
}
} while ($repeat);
if (DB::isError($result)) {
- return $result;
+ return $this->raiseError($result);
}
$arr = $result->fetchRow(DB_FETCHMODE_ORDERED);
$result->free();
@@ -605,7 +623,7 @@
if ($errno === null) {
$ibase_errno = (int)$m[2];
// try to interpret Interbase error code (that's why we need ibase_errno()
- // in the interbase module to return the real error code)
+ // in the interbase module to return the real error code)
switch ($ibase_errno) {
case -204:
if (is_int(strpos($m[3], 'Table unknown'))) {
@@ -618,7 +636,7 @@
}
$errmsg = $m[2] . ' ' . $m[3];
}
-
+
return $this->raiseError($errno, null, null, $errmsg,
$this->last_query);
}