cvs: php4 /pear/DB common.php ibase.php mysql.php oci8.php pgsql.php
| From: | Thomas V.V.Cox | Date: | Wed, 31 Oct 2001 15:08:54 +0000 |
| Subject: | cvs: php4 /pear/DB common.php ibase.php mysql.php oci8.php pgsql.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-1219@lists.php.net to get a copy of this message | ||
cox Wed Oct 31 10:08:54 2001 EDT
Modified files:
/php4/pear/DB common.php pgsql.php mysql.php ibase.php oci8.php
Log:
First implementation of the Row Limit support for Pear. All backends
supports it except Oracle and Interbase (for the moment)
Index: php4/pear/DB/common.php
diff -u php4/pear/DB/common.php:1.67 php4/pear/DB/common.php:1.68
--- php4/pear/DB/common.php:1.67 Sat Oct 27 17:02:12 2001
+++ php4/pear/DB/common.php Wed Oct 31 10:08:51 2001
@@ -17,7 +17,7 @@
// | |
// +----------------------------------------------------------------------+
//
-// $Id: common.php,v 1.67 2001/10/27 21:02:12 cox Exp $
+// $Id: common.php,v 1.68 2001/10/31 15:08:51 cox Exp $
//
// Base class for DB implementations.
//
@@ -41,10 +41,15 @@
var $last_query = '';
var $fetchmode = DB_FETCHMODE_ORDERED;
var $fetchmode_object_class = 'DB_row';
+ var $limit_from = null; // for limit queries, the row to start fetching
+ var $limit_count = null; // for limit queries, the number of rows to fetch
var $options = array(
'persistent' => false, // persistent connection?
'optimize' => 'performance', // 'performance' or
'portability'
'debug' => 0, // numeric debug level
+ 'limit' => 'emulate' // 'emulate' => emulate
with fetch row by number
+ // 'alter' => alter the query
+ // false => no support for limit queries
);
var $dbh;
@@ -441,6 +446,14 @@
}
// }}}
+ // {{{ modifyLimitQuery()
+
+ function modifyLimitQuery($query, $from, $count)
+ {
+ return $query;
+ }
+
+ // }}}
// {{{ query()
/**
@@ -461,6 +474,24 @@
if (DB::isError($result) || $result === DB_OK) {
return $result;
} else {
+ return new DB_result($this, $result);
+ }
+ }
+
+ // }}}
+ // {{{ limitQuery()
+
+ function limitQuery($query, $from, $count)
+ {
+ if($this->options['limit'] == false) {
+ return $this->raiseError(DB_ERROR_NOTCAPABLE);
+ }
+ $result = $this->simpleQuery($query);
+ if (DB::isError($result) || $result === DB_OK) {
+ return $result;
+ } else {
+ $this->limit_from = $from;
+ $this->limit_count = $count;
return new DB_result($this, $result);
}
}
Index: php4/pear/DB/pgsql.php
diff -u php4/pear/DB/pgsql.php:1.56 php4/pear/DB/pgsql.php:1.57
--- php4/pear/DB/pgsql.php:1.56 Wed Oct 31 06:52:28 2001
+++ php4/pear/DB/pgsql.php Wed Oct 31 10:08:51 2001
@@ -17,7 +17,7 @@
// | Stig Bakken <ssb@fast.no> |
// +----------------------------------------------------------------------+
//
-// $Id: pgsql.php,v 1.56 2001/10/31 11:52:28 cox Exp $
+// $Id: pgsql.php,v 1.57 2001/10/31 15:08:51 cox Exp $
//
// Database independent query interface definition for PHP's PostgreSQL
// extension.
@@ -59,7 +59,8 @@
$this->features = array(
'prepare' => false,
'pconnect' => true,
- 'transactions' => true
+ 'transactions' => true,
+ 'limit' => 'alter'
);
$this->errorcode_map = array(
);
@@ -552,6 +553,15 @@
{
$sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name);
return $this->query("DROP SEQUENCE ${sqn}_seq");
+ }
+
+ // }}}
+ // {{{ modifyLimitQuery()
+
+ function modifyLimitQuery($query, $from, $count)
+ {
+ $query = $query . " LIMIT $count, $from";
+ return $query;
}
// }}}
Index: php4/pear/DB/mysql.php
diff -u php4/pear/DB/mysql.php:1.80 php4/pear/DB/mysql.php:1.81
--- php4/pear/DB/mysql.php:1.80 Mon Oct 29 18:37:52 2001
+++ php4/pear/DB/mysql.php Wed Oct 31 10:08:52 2001
@@ -17,7 +17,7 @@
// | |
// +----------------------------------------------------------------------+
//
-// $Id: mysql.php,v 1.80 2001/10/29 23:37:52 fmk Exp $
+// $Id: mysql.php,v 1.81 2001/10/31 15:08:52 cox Exp $
//
// Database independent query interface definition for PHP's MySQL
// extension.
@@ -66,7 +66,8 @@
$this->features = array(
'prepare' => false,
'pconnect' => true,
- 'transactions' => true
+ 'transactions' => true,
+ 'limit' => 'alter'
);
$this->errorcode_map = array(
1004 => DB_ERROR_CANNOT_CREATE,
@@ -603,10 +604,9 @@
}
}
// }}}
-
// {{{ modifyQuery()
- function modifyQuery($query)
+ function modifyQuery($query, $subject = null)
{
if ($this->options['optimize'] == 'portability') {
// "DELETE FROM table" gives 0 affected rows in MySQL.
@@ -616,6 +616,15 @@
'DELETE FROM \1 WHERE 1=1', $query);
}
}
+ return $query;
+ }
+
+ // }}}
+ // {{{ modifyLimitQuery()
+
+ function modifyLimitQuery($query, $from, $count)
+ {
+ $query = $query . " LIMIT $from, $count";
return $query;
}
Index: php4/pear/DB/ibase.php
diff -u php4/pear/DB/ibase.php:1.25 php4/pear/DB/ibase.php:1.26
--- php4/pear/DB/ibase.php:1.25 Mon Oct 29 18:37:52 2001
+++ php4/pear/DB/ibase.php Wed Oct 31 10:08:53 2001
@@ -16,7 +16,7 @@
// | Authors: Sterling Hughes <sterling@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: ibase.php,v 1.25 2001/10/29 23:37:52 fmk Exp $
+// $Id: ibase.php,v 1.26 2001/10/31 15:08:53 cox Exp $
//
// Database independent query interface definition for PHP's Interbase
// extension.
@@ -39,7 +39,8 @@
$this->features = array(
'prepare' => true,
'pconnect' => true,
- 'transactions' => true
+ 'transactions' => true,
+ 'limit' => false
);
}
Index: php4/pear/DB/oci8.php
diff -u php4/pear/DB/oci8.php:1.32 php4/pear/DB/oci8.php:1.33
--- php4/pear/DB/oci8.php:1.32 Mon Oct 29 18:37:52 2001
+++ php4/pear/DB/oci8.php Wed Oct 31 10:08:53 2001
@@ -17,7 +17,7 @@
// | |
// +----------------------------------------------------------------------+
//
-// $Id: oci8.php,v 1.32 2001/10/29 23:37:52 fmk Exp $
+// $Id: oci8.php,v 1.33 2001/10/31 15:08:53 cox Exp $
//
// Database independent query interface definition for PHP's Oracle 8
// call-interface extension.
@@ -54,7 +54,8 @@
$this->features = array(
'prepare' => false,
'pconnect' => true,
- 'transactions' => true
+ 'transactions' => true,
+ 'limit' => false
);
$this->errorcode_map = array(
900 => DB_ERROR_SYNTAX,