From 8e528fd7bf2e2bd1e20c7e7de5eefb26bf6b19d9 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 23 May 2012 14:09:57 -0400
Subject: [PATCH] hide_blockquote - a new plugin for hiding citation blocks

---
 program/lib/MDB2/Extended.php |  414 +++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 265 insertions(+), 149 deletions(-)

diff --git a/program/lib/MDB2/Extended.php b/program/lib/MDB2/Extended.php
old mode 100755
new mode 100644
index cc308bf..29de0a7
--- a/program/lib/MDB2/Extended.php
+++ b/program/lib/MDB2/Extended.php
@@ -2,7 +2,7 @@
 // +----------------------------------------------------------------------+
 // | PHP versions 4 and 5                                                 |
 // +----------------------------------------------------------------------+
-// | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox,                 |
+// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox,                 |
 // | Stig. S. Bakken, Lukas Smith                                         |
 // | All rights reserved.                                                 |
 // +----------------------------------------------------------------------+
@@ -42,7 +42,7 @@
 // | Author: Lukas Smith <smith@pooteeweet.org>                           |
 // +----------------------------------------------------------------------+
 //
-// $Id$
+// $Id: Extended.php 292715 2009-12-28 14:06:34Z quipo $
 
 /**
  * @package  MDB2
@@ -55,6 +55,8 @@
  */
 define('MDB2_AUTOQUERY_INSERT', 1);
 define('MDB2_AUTOQUERY_UPDATE', 2);
+define('MDB2_AUTOQUERY_DELETE', 3);
+define('MDB2_AUTOQUERY_SELECT', 4);
 
 /**
  * MDB2_Extended: class which adds several high level methods to MDB2
@@ -65,25 +67,30 @@
  */
 class MDB2_Extended extends MDB2_Module_Common
 {
-    // }}}
     // {{{ autoPrepare()
 
     /**
-     * Make automaticaly an insert or update query and call prepare() with it
+     * Generate an insert, update or delete query and call prepare() on it
      *
-     * @param string $table name of the table
-     * @param array $table_fields ordered array containing the fields names
-     * @param int $mode type of query to make (MDB2_AUTOQUERY_INSERT or MDB2_AUTOQUERY_UPDATE)
-     * @param string $where in case of update queries, this string will be put after the sql WHERE statement
+     * @param string table
+     * @param array the fields names
+     * @param int type of query to build
+     *                          MDB2_AUTOQUERY_INSERT
+     *                          MDB2_AUTOQUERY_UPDATE
+     *                          MDB2_AUTOQUERY_DELETE
+     *                          MDB2_AUTOQUERY_SELECT
+     * @param string (in case of update and delete queries, this string will be put after the sql WHERE statement)
+     * @param array that contains the types of the placeholders
+     * @param mixed array that contains the types of the columns in
+     *                        the result set or MDB2_PREPARE_RESULT, if set to
+     *                        MDB2_PREPARE_MANIP the query is handled as a manipulation query
+     *
      * @return resource handle for the query
-     * @param mixed   $types  array that contains the types of the placeholders
-     * @param mixed   $result_types  array that contains the types of the columns in
-     *                        the result set
      * @see buildManipSQL
      * @access public
      */
     function autoPrepare($table, $table_fields, $mode = MDB2_AUTOQUERY_INSERT,
-        $where = false, $types = null, $result_types = null)
+        $where = false, $types = null, $result_types = MDB2_PREPARE_MANIP)
     {
         $query = $this->buildManipSQL($table, $table_fields, $mode, $where);
         if (PEAR::isError($query)) {
@@ -93,45 +100,81 @@
         if (PEAR::isError($db)) {
             return $db;
         }
-
-        return $db->prepare($query, $types, $result_types);
+        $lobs = array();
+        foreach ((array)$types as $param => $type) {
+            if (($type == 'clob') || ($type == 'blob')) {
+                $lobs[$param] = $table_fields[$param];
+            }
+        }
+        return $db->prepare($query, $types, $result_types, $lobs);
     }
 
-    // {{{
-    // }}} autoExecute()
+    // }}}
+    // {{{ autoExecute()
 
     /**
-     * Make automaticaly an insert or update query and call prepare() and execute() with it
+     * Generate an insert, update or delete query and call prepare() and execute() on it
      *
-     * @param string $table name of the table
-     * @param array $fields_values assoc ($key=>$value) where $key is a field name and $value its value
-     * @param int $mode type of query to make (MDB2_AUTOQUERY_INSERT or MDB2_AUTOQUERY_UPDATE)
-     * @param string $where in case of update queries, this string will be put after the sql WHERE statement
-     * @param mixed   $types  array that contains the types of the placeholders
-     * @param mixed   $result_types  array that contains the types of the columns in
-     *                        the result set
-     * @param mixed $result_class string which specifies which result class to use
-     * @return mixed  a new MDB2_Result or a MDB2 Error Object when fail
+     * @param string name of the table
+     * @param array assoc ($key=>$value) where $key is a field name and $value its value
+     * @param int type of query to build
+     *                          MDB2_AUTOQUERY_INSERT
+     *                          MDB2_AUTOQUERY_UPDATE
+     *                          MDB2_AUTOQUERY_DELETE
+     *                          MDB2_AUTOQUERY_SELECT
+     * @param string (in case of update and delete queries, this string will be put after the sql WHERE statement)
+     * @param array that contains the types of the placeholders
+     * @param string which specifies which result class to use
+     * @param mixed  array that contains the types of the columns in
+     *                        the result set or MDB2_PREPARE_RESULT, if set to
+     *                        MDB2_PREPARE_MANIP the query is handled as a manipulation query
+     *
+     * @return bool|MDB2_Error true on success, a MDB2 error on failure
      * @see buildManipSQL
      * @see autoPrepare
      * @access public
     */
     function &autoExecute($table, $fields_values, $mode = MDB2_AUTOQUERY_INSERT,
-        $where = false, $types = null, $result_types = null, $result_class = true)
+        $where = false, $types = null, $result_class = true, $result_types = MDB2_PREPARE_MANIP)
     {
-        $stmt = $this->autoPrepare($table, array_keys($fields_values), $mode, $where, $types, $result_types);
-        if (PEAR::isError($stmt)) {
-            return $stmt;
+        $fields_values = (array)$fields_values;
+        if ($mode == MDB2_AUTOQUERY_SELECT) {
+            if (is_array($result_types)) {
+                $keys = array_keys($result_types);
+            } elseif (!empty($fields_values)) {
+                $keys = $fields_values;
+            } else {
+                $keys = array();
+            }
+        } else {
+            $keys = array_keys($fields_values);
         }
         $params = array_values($fields_values);
-        $stmt->bindParamArray($params);
-        $result =& $stmt->execute($result_class);
-        $stmt->free();
+        if (empty($params)) {
+            $query = $this->buildManipSQL($table, $keys, $mode, $where);
+
+            $db =& $this->getDBInstance();
+            if (PEAR::isError($db)) {
+                return $db;
+            }
+            if ($mode == MDB2_AUTOQUERY_SELECT) {
+                $result =& $db->query($query, $result_types, $result_class);
+            } else {
+                $result = $db->exec($query);
+            }
+        } else {
+            $stmt = $this->autoPrepare($table, $keys, $mode, $where, $types, $result_types);
+            if (PEAR::isError($stmt)) {
+                return $stmt;
+            }
+            $result =& $stmt->execute($params, $result_class);
+            $stmt->free();
+        }
         return $result;
     }
 
-    // {{{
-    // }}} buildManipSQL()
+    // }}}
+    // {{{ buildManipSQL()
 
     /**
      * Make automaticaly an sql query for prepare()
@@ -139,13 +182,18 @@
      * Example : buildManipSQL('table_sql', array('field1', 'field2', 'field3'), MDB2_AUTOQUERY_INSERT)
      *           will return the string : INSERT INTO table_sql (field1,field2,field3) VALUES (?,?,?)
      * NB : - This belongs more to a SQL Builder class, but this is a simple facility
-     *      - Be carefull ! If you don't give a $where param with an UPDATE query, all
-     *        the records of the table will be updated !
+     *      - Be carefull ! If you don't give a $where param with an UPDATE/DELETE query, all
+     *        the records of the table will be updated/deleted !
      *
-     * @param string $table name of the table
-     * @param array $table_fields ordered array containing the fields names
-     * @param int $mode type of query to make (MDB2_AUTOQUERY_INSERT or MDB2_AUTOQUERY_UPDATE)
-     * @param string $where in case of update queries, this string will be put after the sql WHERE statement
+     * @param string name of the table
+     * @param ordered array containing the fields names
+     * @param int type of query to build
+     *                          MDB2_AUTOQUERY_INSERT
+     *                          MDB2_AUTOQUERY_UPDATE
+     *                          MDB2_AUTOQUERY_DELETE
+     *                          MDB2_AUTOQUERY_SELECT
+     * @param string (in case of update and delete queries, this string will be put after the sql WHERE statement)
+     *
      * @return string sql query for prepare()
      * @access public
      */
@@ -156,74 +204,143 @@
             return $db;
         }
 
-        if (count($table_fields) == 0) {
-            return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA);
+        if ($db->options['quote_identifier']) {
+            $table = $db->quoteIdentifier($table);
         }
+
+        if (!empty($table_fields) && $db->options['quote_identifier']) {
+            foreach ($table_fields as $key => $field) {
+                $table_fields[$key] = $db->quoteIdentifier($field);
+            }
+        }
+
+        if ((false !== $where) && (null !== $where)) {
+            if (is_array($where)) {
+                $where = implode(' AND ', $where);
+            }
+            $where = ' WHERE '.$where;
+        }
+
         switch ($mode) {
         case MDB2_AUTOQUERY_INSERT:
+            if (empty($table_fields)) {
+                return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
+                'Insert requires table fields', __FUNCTION__);
+            }
             $cols = implode(', ', $table_fields);
-            $values = '?'.str_repeat(', ?', count($table_fields)-1);
+            $values = '?'.str_repeat(', ?', (count($table_fields) - 1));
             return 'INSERT INTO '.$table.' ('.$cols.') VALUES ('.$values.')';
             break;
         case MDB2_AUTOQUERY_UPDATE:
-            $set = implode(' = ?, ', $table_fields).' = ?';
-            $sql = 'UPDATE '.$table.' SET '.$set;
-            if ($where !== false) {
-                $sql.= ' WHERE '.$where;
+            if (empty($table_fields)) {
+                return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
+                'Update requires table fields', __FUNCTION__);
             }
+            $set = implode(' = ?, ', $table_fields).' = ?';
+            $sql = 'UPDATE '.$table.' SET '.$set.$where;
+            return $sql;
+            break;
+        case MDB2_AUTOQUERY_DELETE:
+            $sql = 'DELETE FROM '.$table.$where;
+            return $sql;
+            break;
+        case MDB2_AUTOQUERY_SELECT:
+            $cols = !empty($table_fields) ? implode(', ', $table_fields) : '*';
+            $sql = 'SELECT '.$cols.' FROM '.$table.$where;
             return $sql;
             break;
         }
-        return $db->raiseError(MDB2_ERROR_SYNTAX);
+        return $db->raiseError(MDB2_ERROR_SYNTAX, null, null,
+                'Non existant mode', __FUNCTION__);
     }
 
-    // {{{
-    // }}} limitQuery()
+    // }}}
+    // {{{ limitQuery()
 
     /**
      * Generates a limited query
      *
-     * @param string $query query
-     * @param mixed   $types  array that contains the types of the columns in
-     *                        the result set
-     * @param integer $from the row to start to fetching
-     * @param integer $count the numbers of rows to fetch
-     * @param mixed $result_class string which specifies which result class to use
-     * @return mixed a valid ressource pointer or a MDB2 Error Object
+     * @param string query
+     * @param array that contains the types of the columns in the result set
+     * @param integer the numbers of rows to fetch
+     * @param integer the row to start to fetching
+     * @param string which specifies which result class to use
+     * @param mixed   string which specifies which class to wrap results in
+     *
+     * @return MDB2_Result|MDB2_Error result set on success, a MDB2 error on failure
      * @access public
      */
-    function &limitQuery($query, $types, $count, $from = 0, $result_class = true)
+    function &limitQuery($query, $types, $limit, $offset = 0, $result_class = true,
+        $result_wrap_class = false)
     {
         $db =& $this->getDBInstance();
         if (PEAR::isError($db)) {
             return $db;
         }
 
-        $result = $db->setLimit($count, $from);
+        $result = $db->setLimit($limit, $offset);
         if (PEAR::isError($result)) {
             return $result;
         }
-        $result =& $db->query($query, $types, $result_class);
+        $result =& $db->query($query, $types, $result_class, $result_wrap_class);
         return $result;
     }
 
-    // {{{
-    // }}} getOne()
+    // }}}
+    // {{{ execParam()
 
     /**
-     * Fetch the first column of the first row of data returned from
-     * a query.  Takes care of doing the query and freeing the results
-     * when finished.
+     * Execute a parameterized DML statement.
      *
-     * @param string $query the SQL query
-     * @param string $type string that contains the type of the column in the
-     *       result set
-     * @param array $params if supplied, prepare/execute will be used
+     * @param string the SQL query
+     * @param array if supplied, prepare/execute will be used
      *       with this array as execute parameters
-     * @param array $param_types array that contains the types of the values
-     *       defined in $params
-     * @param mixed $colnum which column to return
-     * @return mixed MDB2_OK or data on success, a MDB2 error on failure
+     * @param array that contains the types of the values defined in $params
+     *
+     * @return int|MDB2_Error affected rows on success, a MDB2 error on failure
+     * @access public
+     */
+    function execParam($query, $params = array(), $param_types = null)
+    {
+        $db =& $this->getDBInstance();
+        if (PEAR::isError($db)) {
+            return $db;
+        }
+
+        settype($params, 'array');
+        if (empty($params)) {
+            return $db->exec($query);
+        }
+
+        $stmt = $db->prepare($query, $param_types, MDB2_PREPARE_MANIP);
+        if (PEAR::isError($stmt)) {
+            return $stmt;
+        }
+
+        $result = $stmt->execute($params);
+        if (PEAR::isError($result)) {
+            return $result;
+        }
+
+        $stmt->free();
+        return $result;
+    }
+
+    // }}}
+    // {{{ getOne()
+
+    /**
+     * Fetch the first column of the first row of data returned from a query.
+     * Takes care of doing the query and freeing the results when finished.
+     *
+     * @param string the SQL query
+     * @param string that contains the type of the column in the result set
+     * @param array if supplied, prepare/execute will be used
+     *       with this array as execute parameters
+     * @param array that contains the types of the values defined in $params
+     * @param int|string which column to return
+     *
+     * @return scalar|MDB2_Error data on success, a MDB2 error on failure
      * @access public
      */
     function getOne($query, $type = null, $params = array(),
@@ -236,7 +353,7 @@
 
         settype($params, 'array');
         settype($type, 'array');
-        if (count($params) == 0) {
+        if (empty($params)) {
             return $db->queryOne($query, $type, $colnum);
         }
 
@@ -245,8 +362,7 @@
             return $stmt;
         }
 
-        $stmt->bindParamArray($params);
-        $result = $stmt->execute();
+        $result = $stmt->execute($params);
         if (!MDB2::isResultCommon($result)) {
             return $result;
         }
@@ -264,15 +380,14 @@
      * Fetch the first row of data returned from a query.  Takes care
      * of doing the query and freeing the results when finished.
      *
-     * @param string $query the SQL query
-     * @param array $types array that contains the types of the columns in
-     *       the result set
-     * @param array $params array if supplied, prepare/execute will be used
+     * @param string the SQL query
+     * @param array that contains the types of the columns in the result set
+     * @param array if supplied, prepare/execute will be used
      *       with this array as execute parameters
-     * @param array $param_types array that contains the types of the values
-     *       defined in $params
-     * @param integer $fetchmode the fetch mode to use
-     * @return mixed MDB2_OK or data array on success, a MDB2 error on failure
+     * @param array that contains the types of the values defined in $params
+     * @param int the fetch mode to use
+     *
+     * @return array|MDB2_Error data on success, a MDB2 error on failure
      * @access public
      */
     function getRow($query, $types = null, $params = array(),
@@ -284,7 +399,7 @@
         }
 
         settype($params, 'array');
-        if (count($params) == 0) {
+        if (empty($params)) {
             return $db->queryRow($query, $types, $fetchmode);
         }
 
@@ -293,8 +408,7 @@
             return $stmt;
         }
 
-        $stmt->bindParamArray($params);
-        $result = $stmt->execute();
+        $result = $stmt->execute($params);
         if (!MDB2::isResultCommon($result)) {
             return $result;
         }
@@ -312,15 +426,14 @@
      * Fetch a single column from a result set and return it as an
      * indexed array.
      *
-     * @param string $query the SQL query
-     * @param string $type string that contains the type of the column in the
-     *       result set
-     * @param array $params array if supplied, prepare/execute will be used
+     * @param string the SQL query
+     * @param string that contains the type of the column in the result set
+     * @param array if supplied, prepare/execute will be used
      *       with this array as execute parameters
-     * @param array $param_types array that contains the types of the values
-     *       defined in $params
-     * @param mixed $colnum which column to return
-     * @return mixed MDB2_OK or data array on success, a MDB2 error on failure
+     * @param array that contains the types of the values defined in $params
+     * @param int|string which column to return
+     *
+     * @return array|MDB2_Error data on success, a MDB2 error on failure
      * @access public
      */
     function getCol($query, $type = null, $params = array(),
@@ -333,7 +446,7 @@
 
         settype($params, 'array');
         settype($type, 'array');
-        if (count($params) == 0) {
+        if (empty($params)) {
             return $db->queryCol($query, $type, $colnum);
         }
 
@@ -342,8 +455,7 @@
             return $stmt;
         }
 
-        $stmt->bindParamArray($params);
-        $result = $stmt->execute();
+        $result = $stmt->execute($params);
         if (!MDB2::isResultCommon($result)) {
             return $result;
         }
@@ -360,24 +472,23 @@
     /**
      * Fetch all the rows returned from a query.
      *
-     * @param string $query the SQL query
-     * @param array $types array that contains the types of the columns in
-     *       the result set
-     * @param array $params array if supplied, prepare/execute will be used
+     * @param string the SQL query
+     * @param array that contains the types of the columns in the result set
+     * @param array if supplied, prepare/execute will be used
      *       with this array as execute parameters
-     * @param array $param_types array that contains the types of the values
-     *       defined in $params
-     * @param integer $fetchmode the fetch mode to use
-     * @param boolean $rekey if set to true, the $all will have the first
+     * @param array that contains the types of the values defined in $params
+     * @param int the fetch mode to use
+     * @param bool if set to true, the $all will have the first
      *       column as its first dimension
-     * @param boolean $force_array used only when the query returns exactly
+     * @param bool $force_array used only when the query returns exactly
      *       two columns. If true, the values of the returned array will be
      *       one-element arrays instead of scalars.
-     * @param boolean $group if true, the values of the returned array is
+     * @param bool $group if true, the values of the returned array is
      *       wrapped in another array.  If the same key value (in the first
      *       column) repeats itself, the values will be appended to this array
      *       instead of overwriting the existing values.
-     * @return mixed MDB2_OK or data array on success, a MDB2 error on failure
+     *
+     * @return array|MDB2_Error data on success, a MDB2 error on failure
      * @access public
      */
     function getAll($query, $types = null, $params = array(),
@@ -390,7 +501,7 @@
         }
 
         settype($params, 'array');
-        if (count($params) == 0) {
+        if (empty($params)) {
             return $db->queryAll($query, $types, $fetchmode, $rekey, $force_array, $group);
         }
 
@@ -399,8 +510,7 @@
             return $stmt;
         }
 
-        $stmt->bindParamArray($params);
-        $result = $stmt->execute();
+        $result = $stmt->execute($params);
         if (!MDB2::isResultCommon($result)) {
             return $result;
         }
@@ -422,37 +532,40 @@
      * will be an array of the values from column 2-n.  If the result
      * set contains only two columns, the returned value will be a
      * scalar with the value of the second column (unless forced to an
-     * array with the $force_array parameter).  A MDB error code is
+     * array with the $force_array parameter).  A MDB2 error code is
      * returned on errors.  If the result set contains fewer than two
      * columns, a MDB2_ERROR_TRUNCATED error is returned.
      *
      * For example, if the table 'mytable' contains:
-     *
+     * <pre>
      *   ID      TEXT       DATE
      * --------------------------------
      *   1       'one'      944679408
      *   2       'two'      944679408
      *   3       'three'    944679408
-     *
+     * </pre>
      * Then the call getAssoc('SELECT id,text FROM mytable') returns:
+     * <pre>
      *    array(
      *      '1' => 'one',
      *      '2' => 'two',
      *      '3' => 'three',
      *    )
-     *
+     * </pre>
      * ...while the call getAssoc('SELECT id,text,date FROM mytable') returns:
+     * <pre>
      *    array(
      *      '1' => array('one', '944679408'),
      *      '2' => array('two', '944679408'),
      *      '3' => array('three', '944679408')
      *    )
+     * </pre>
      *
      * If the more than one row occurs with the same value in the
      * first column, the last row overwrites all previous ones by
      * default.  Use the $group parameter if you don't want to
      * overwrite like this.  Example:
-     *
+     * <pre>
      * getAssoc('SELECT category,id,name FROM mytable', null, null
      *           MDB2_FETCHMODE_ASSOC, false, true) returns:
      *    array(
@@ -463,25 +576,25 @@
      *                   array('id' => '6', 'name' => 'number six')
      *             )
      *    )
+     * </pre>
      *
      * Keep in mind that database functions in PHP usually return string
      * values for results regardless of the database's internal type.
      *
-     * @param string $query the SQL query
-     * @param array $types array that contains the types of the columns in
-     *       the result set
-     * @param array $params array if supplied, prepare/execute will be used
+     * @param string the SQL query
+     * @param array that contains the types of the columns in the result set
+     * @param array if supplied, prepare/execute will be used
      *       with this array as execute parameters
-     * @param array $param_types array that contains the types of the values
-     *       defined in $params
-     * @param boolean $force_array used only when the query returns
+     * @param array that contains the types of the values defined in $params
+     * @param bool $force_array used only when the query returns
      * exactly two columns.  If TRUE, the values of the returned array
      * will be one-element arrays instead of scalars.
-     * @param boolean $group if TRUE, the values of the returned array
+     * @param bool $group if TRUE, the values of the returned array
      *       is wrapped in another array.  If the same key value (in the first
      *       column) repeats itself, the values will be appended to this array
      *       instead of overwriting the existing values.
-     * @return array associative array with results from the query.
+     *
+     * @return array|MDB2_Error data on success, a MDB2 error on failure
      * @access public
      */
     function getAssoc($query, $types = null, $params = array(), $param_types = null,
@@ -493,7 +606,7 @@
         }
 
         settype($params, 'array');
-        if (count($params) == 0) {
+        if (empty($params)) {
             return $db->queryAll($query, $types, $fetchmode, true, $force_array, $group);
         }
 
@@ -502,8 +615,7 @@
             return $stmt;
         }
 
-        $stmt->bindParamArray($params);
-        $result = $stmt->execute();
+        $result = $stmt->execute($params);
         if (!MDB2::isResultCommon($result)) {
             return $result;
         }
@@ -525,18 +637,17 @@
      * If an error occurs during execute(), executeMultiple() does not execute
      * the unfinished rows, but rather returns that error.
      *
-     * @param resource $stmt query handle from prepare()
-     * @param array $params numeric array containing the
-     *        data to insert into the query
-     * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
+     * @param resource query handle from prepare()
+     * @param array numeric array containing the data to insert into the query
+     *
+     * @return bool|MDB2_Error true on success, a MDB2 error on failure
      * @access public
      * @see prepare(), execute()
      */
     function executeMultiple(&$stmt, $params = null)
     {
         for ($i = 0, $j = count($params); $i < $j; $i++) {
-            $stmt->bindParamArray($params[$i]);
-            $result = $stmt->execute();
+            $result = $stmt->execute($params[$i]);
             if (PEAR::isError($result)) {
                 return $result;
             }
@@ -548,18 +659,18 @@
     // {{{ getBeforeID()
 
     /**
-     * returns the next free id of a sequence if the RDBMS
+     * Returns the next free id of a sequence if the RDBMS
      * does not support auto increment
      *
-     * @param string $table name of the table into which a new row was inserted
-     * @param boolean $ondemand when true the seqence is
-     *                          automatic created, if it
-     *                          not exists
+     * @param string name of the table into which a new row was inserted
+     * @param string name of the field into which a new row was inserted
+     * @param bool when true the sequence is automatic created, if it not exists
+     * @param bool if the returned value should be quoted
      *
-     * @return mixed MDB2 Error Object or id
+     * @return int|MDB2_Error id on success, a MDB2 error on failure
      * @access public
      */
-    function getBeforeID($table, $field, $ondemand = true)
+    function getBeforeID($table, $field = null, $ondemand = true, $quote = true)
     {
         $db =& $this->getDBInstance();
         if (PEAR::isError($db)) {
@@ -569,10 +680,12 @@
         if ($db->supports('auto_increment') !== true) {
             $seq = $table.(empty($field) ? '' : '_'.$field);
             $id = $db->nextID($seq, $ondemand);
-            if (PEAR::isError($id)) {
+            if (!$quote || PEAR::isError($id)) {
                 return $id;
             }
             return $db->quote($id, 'integer');
+        } elseif (!$quote) {
+            return null;
         }
         return 'NULL';
     }
@@ -581,14 +694,16 @@
     // {{{ getAfterID()
 
     /**
-     * returns the autoincrement ID if supported or $id
+     * Returns the autoincrement ID if supported or $id
      *
-     * @param mixed $id value as returned by getBeforeId()
-     * @param string $table name of the table into which a new row was inserted
-     * @return mixed MDB2 Error Object or id
+     * @param mixed value as returned by getBeforeId()
+     * @param string name of the table into which a new row was inserted
+     * @param string name of the field into which a new row was inserted
+     *
+     * @return int|MDB2_Error id on success, a MDB2 error on failure
      * @access public
      */
-    function getAfterID($id, $table, $field)
+    function getAfterID($id, $table, $field = null)
     {
         $db =& $this->getDBInstance();
         if (PEAR::isError($db)) {
@@ -601,5 +716,6 @@
         return $db->lastInsertID($table, $field);
     }
 
+    // }}}
 }
 ?>
\ No newline at end of file

--
Gitblit v1.9.1