more MDB2 updates

This commit is contained in:
Robin Appelman 2012-05-13 20:49:39 +02:00
parent ddf0903ace
commit 77e2387d94
48 changed files with 22977 additions and 21917 deletions

View File

@ -577,7 +577,7 @@ class Archive_Tar extends PEAR
} }
// ----- Get the arguments // ----- Get the arguments
$v_att_list = &func_get_args(); $v_att_list = func_get_args();
// ----- Read the attributes // ----- Read the attributes
$i=0; $i=0;

8857
3rdparty/MDB2.php vendored

File diff suppressed because it is too large Load Diff

366
3rdparty/MDB2/Date.php vendored
View File

@ -1,183 +1,183 @@
<?php <?php
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | PHP versions 4 and 5 | // | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, | // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith | // | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. | // | All rights reserved. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. | // | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. | // | This LICENSE is in the BSD license style. |
// | | // | |
// | Redistribution and use in source and binary forms, with or without | // | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions | // | modification, are permitted provided that the following conditions |
// | are met: | // | are met: |
// | | // | |
// | Redistributions of source code must retain the above copyright | // | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. | // | notice, this list of conditions and the following disclaimer. |
// | | // | |
// | Redistributions in binary form must reproduce the above copyright | // | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the | // | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. | // | documentation and/or other materials provided with the distribution. |
// | | // | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse | // | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior| // | or promote products derived from this software without specific prior|
// | written permission. | // | written permission. |
// | | // | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. | // | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> | // | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// //
// $Id: Date.php 208329 2006-03-01 12:15:38Z lsmith $ // $Id$
// //
/** /**
* @package MDB2 * @package MDB2
* @category Database * @category Database
* @author Lukas Smith <smith@pooteeweet.org> * @author Lukas Smith <smith@pooteeweet.org>
*/ */
/** /**
* Several methods to convert the MDB2 native timestamp format (ISO based) * Several methods to convert the MDB2 native timestamp format (ISO based)
* to and from data structures that are convenient to worth with in side of php. * to and from data structures that are convenient to worth with in side of php.
* For more complex date arithmetic please take a look at the Date package in PEAR * For more complex date arithmetic please take a look at the Date package in PEAR
* *
* @package MDB2 * @package MDB2
* @category Database * @category Database
* @author Lukas Smith <smith@pooteeweet.org> * @author Lukas Smith <smith@pooteeweet.org>
*/ */
class MDB2_Date class MDB2_Date
{ {
// {{{ mdbNow() // {{{ mdbNow()
/** /**
* return the current datetime * return the current datetime
* *
* @return string current datetime in the MDB2 format * @return string current datetime in the MDB2 format
* @access public * @access public
*/ */
function mdbNow() function mdbNow()
{ {
return date('Y-m-d H:i:s'); return date('Y-m-d H:i:s');
} }
// }}} // }}}
// {{{ mdbToday() // {{{ mdbToday()
/** /**
* return the current date * return the current date
* *
* @return string current date in the MDB2 format * @return string current date in the MDB2 format
* @access public * @access public
*/ */
function mdbToday() function mdbToday()
{ {
return date('Y-m-d'); return date('Y-m-d');
} }
// }}} // }}}
// {{{ mdbTime() // {{{ mdbTime()
/** /**
* return the current time * return the current time
* *
* @return string current time in the MDB2 format * @return string current time in the MDB2 format
* @access public * @access public
*/ */
function mdbTime() function mdbTime()
{ {
return date('H:i:s'); return date('H:i:s');
} }
// }}} // }}}
// {{{ date2Mdbstamp() // {{{ date2Mdbstamp()
/** /**
* convert a date into a MDB2 timestamp * convert a date into a MDB2 timestamp
* *
* @param int hour of the date * @param int hour of the date
* @param int minute of the date * @param int minute of the date
* @param int second of the date * @param int second of the date
* @param int month of the date * @param int month of the date
* @param int day of the date * @param int day of the date
* @param int year of the date * @param int year of the date
* *
* @return string a valid MDB2 timestamp * @return string a valid MDB2 timestamp
* @access public * @access public
*/ */
function date2Mdbstamp($hour = null, $minute = null, $second = null, function date2Mdbstamp($hour = null, $minute = null, $second = null,
$month = null, $day = null, $year = null) $month = null, $day = null, $year = null)
{ {
return MDB2_Date::unix2Mdbstamp(mktime($hour, $minute, $second, $month, $day, $year, -1)); return MDB2_Date::unix2Mdbstamp(mktime($hour, $minute, $second, $month, $day, $year, -1));
} }
// }}} // }}}
// {{{ unix2Mdbstamp() // {{{ unix2Mdbstamp()
/** /**
* convert a unix timestamp into a MDB2 timestamp * convert a unix timestamp into a MDB2 timestamp
* *
* @param int a valid unix timestamp * @param int a valid unix timestamp
* *
* @return string a valid MDB2 timestamp * @return string a valid MDB2 timestamp
* @access public * @access public
*/ */
function unix2Mdbstamp($unix_timestamp) function unix2Mdbstamp($unix_timestamp)
{ {
return date('Y-m-d H:i:s', $unix_timestamp); return date('Y-m-d H:i:s', $unix_timestamp);
} }
// }}} // }}}
// {{{ mdbstamp2Unix() // {{{ mdbstamp2Unix()
/** /**
* convert a MDB2 timestamp into a unix timestamp * convert a MDB2 timestamp into a unix timestamp
* *
* @param int a valid MDB2 timestamp * @param int a valid MDB2 timestamp
* @return string unix timestamp with the time stored in the MDB2 format * @return string unix timestamp with the time stored in the MDB2 format
* *
* @access public * @access public
*/ */
function mdbstamp2Unix($mdb_timestamp) function mdbstamp2Unix($mdb_timestamp)
{ {
$arr = MDB2_Date::mdbstamp2Date($mdb_timestamp); $arr = MDB2_Date::mdbstamp2Date($mdb_timestamp);
return mktime($arr['hour'], $arr['minute'], $arr['second'], $arr['month'], $arr['day'], $arr['year'], -1); return mktime($arr['hour'], $arr['minute'], $arr['second'], $arr['month'], $arr['day'], $arr['year'], -1);
} }
// }}} // }}}
// {{{ mdbstamp2Date() // {{{ mdbstamp2Date()
/** /**
* convert a MDB2 timestamp into an array containing all * convert a MDB2 timestamp into an array containing all
* values necessary to pass to php's date() function * values necessary to pass to php's date() function
* *
* @param int a valid MDB2 timestamp * @param int a valid MDB2 timestamp
* *
* @return array with the time split * @return array with the time split
* @access public * @access public
*/ */
function mdbstamp2Date($mdb_timestamp) function mdbstamp2Date($mdb_timestamp)
{ {
list($arr['year'], $arr['month'], $arr['day'], $arr['hour'], $arr['minute'], $arr['second']) = list($arr['year'], $arr['month'], $arr['day'], $arr['hour'], $arr['minute'], $arr['second']) =
sscanf($mdb_timestamp, "%04u-%02u-%02u %02u:%02u:%02u"); sscanf($mdb_timestamp, "%04u-%02u-%02u %02u:%02u:%02u");
return $arr; return $arr;
} }
// }}} // }}}
} }
?> ?>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,418 +1,418 @@
<?php <?php
// vim: set et ts=4 sw=4 fdm=marker: // vim: set et ts=4 sw=4 fdm=marker:
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | PHP versions 4 and 5 | // | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, | // | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith | // | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. | // | All rights reserved. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. | // | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. | // | This LICENSE is in the BSD license style. |
// | | // | |
// | Redistribution and use in source and binary forms, with or without | // | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions | // | modification, are permitted provided that the following conditions |
// | are met: | // | are met: |
// | | // | |
// | Redistributions of source code must retain the above copyright | // | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. | // | notice, this list of conditions and the following disclaimer. |
// | | // | |
// | Redistributions in binary form must reproduce the above copyright | // | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the | // | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. | // | documentation and/or other materials provided with the distribution. |
// | | // | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse | // | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior| // | or promote products derived from this software without specific prior|
// | written permission. | // | written permission. |
// | | // | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. | // | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> | // | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// //
// $Id: sqlite.php 295587 2010-02-28 17:16:38Z quipo $ // $Id$
// //
require_once 'MDB2/Driver/Datatype/Common.php'; require_once 'MDB2/Driver/Datatype/Common.php';
/** /**
* MDB2 SQLite driver * MDB2 SQLite driver
* *
* @package MDB2 * @package MDB2
* @category Database * @category Database
* @author Lukas Smith <smith@pooteeweet.org> * @author Lukas Smith <smith@pooteeweet.org>
*/ */
class MDB2_Driver_Datatype_sqlite extends MDB2_Driver_Datatype_Common class MDB2_Driver_Datatype_sqlite extends MDB2_Driver_Datatype_Common
{ {
// {{{ _getCollationFieldDeclaration() // {{{ _getCollationFieldDeclaration()
/** /**
* Obtain DBMS specific SQL code portion needed to set the COLLATION * Obtain DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration to be used in statements like CREATE TABLE. * of a field declaration to be used in statements like CREATE TABLE.
* *
* @param string $collation name of the collation * @param string $collation name of the collation
* *
* @return string DBMS specific SQL code portion needed to set the COLLATION * @return string DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration. * of a field declaration.
*/ */
function _getCollationFieldDeclaration($collation) function _getCollationFieldDeclaration($collation)
{ {
return 'COLLATE '.$collation; return 'COLLATE '.$collation;
} }
// }}} // }}}
// {{{ getTypeDeclaration() // {{{ getTypeDeclaration()
/** /**
* Obtain DBMS specific SQL code portion needed to declare an text type * Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE. * field to be used in statements like CREATE TABLE.
* *
* @param array $field associative array with the name of the properties * @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types * of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows: * of supported field properties are as follows:
* *
* length * length
* Integer value that determines the maximum length of the text * Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be * field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS. * declared to have the longest length allowed by the DBMS.
* *
* default * default
* Text value to be used as default for this field. * Text value to be used as default for this field.
* *
* notnull * notnull
* Boolean flag that indicates whether this field is constrained * Boolean flag that indicates whether this field is constrained
* to not be set to null. * to not be set to null.
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
* @access public * @access public
*/ */
function getTypeDeclaration($field) function getTypeDeclaration($field)
{ {
$db = $this->getDBInstance(); $db = $this->getDBInstance();
if (PEAR::isError($db)) { if (PEAR::isError($db)) {
return $db; return $db;
} }
switch ($field['type']) { switch ($field['type']) {
case 'text': case 'text':
$length = !empty($field['length']) $length = !empty($field['length'])
? $field['length'] : false; ? $field['length'] : false;
$fixed = !empty($field['fixed']) ? $field['fixed'] : false; $fixed = !empty($field['fixed']) ? $field['fixed'] : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')') return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT'); : ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob': case 'clob':
if (!empty($field['length'])) { if (!empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 255) { if ($length <= 255) {
return 'TINYTEXT'; return 'TINYTEXT';
} elseif ($length <= 65532) { } elseif ($length <= 65532) {
return 'TEXT'; return 'TEXT';
} elseif ($length <= 16777215) { } elseif ($length <= 16777215) {
return 'MEDIUMTEXT'; return 'MEDIUMTEXT';
} }
} }
return 'LONGTEXT'; return 'LONGTEXT';
case 'blob': case 'blob':
if (!empty($field['length'])) { if (!empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 255) { if ($length <= 255) {
return 'TINYBLOB'; return 'TINYBLOB';
} elseif ($length <= 65532) { } elseif ($length <= 65532) {
return 'BLOB'; return 'BLOB';
} elseif ($length <= 16777215) { } elseif ($length <= 16777215) {
return 'MEDIUMBLOB'; return 'MEDIUMBLOB';
} }
} }
return 'LONGBLOB'; return 'LONGBLOB';
case 'integer': case 'integer':
if (!empty($field['length'])) { if (!empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 2) { if ($length <= 2) {
return 'SMALLINT'; return 'SMALLINT';
} elseif ($length == 3 || $length == 4) { } elseif ($length == 3 || $length == 4) {
return 'INTEGER'; return 'INTEGER';
} elseif ($length > 4) { } elseif ($length > 4) {
return 'BIGINT'; return 'BIGINT';
} }
} }
return 'INTEGER'; return 'INTEGER';
case 'boolean': case 'boolean':
return 'BOOLEAN'; return 'BOOLEAN';
case 'date': case 'date':
return 'DATE'; return 'DATE';
case 'time': case 'time':
return 'TIME'; return 'TIME';
case 'timestamp': case 'timestamp':
return 'DATETIME'; return 'DATETIME';
case 'float': case 'float':
return 'DOUBLE'.($db->options['fixed_float'] ? '('. return 'DOUBLE'.($db->options['fixed_float'] ? '('.
($db->options['fixed_float']+2).','.$db->options['fixed_float'].')' : ''); ($db->options['fixed_float']+2).','.$db->options['fixed_float'].')' : '');
case 'decimal': case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18; $length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $db->options['decimal_places']; $scale = !empty($field['scale']) ? $field['scale'] : $db->options['decimal_places'];
return 'DECIMAL('.$length.','.$scale.')'; return 'DECIMAL('.$length.','.$scale.')';
} }
return ''; return '';
} }
// }}} // }}}
// {{{ _getIntegerDeclaration() // {{{ _getIntegerDeclaration()
/** /**
* Obtain DBMS specific SQL code portion needed to declare an integer type * Obtain DBMS specific SQL code portion needed to declare an integer type
* field to be used in statements like CREATE TABLE. * field to be used in statements like CREATE TABLE.
* *
* @param string $name name the field to be declared. * @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties * @param string $field associative array with the name of the properties
* of the field being declared as array indexes. * of the field being declared as array indexes.
* Currently, the types of supported field * Currently, the types of supported field
* properties are as follows: * properties are as follows:
* *
* unsigned * unsigned
* Boolean flag that indicates whether the field * Boolean flag that indicates whether the field
* should be declared as unsigned integer if * should be declared as unsigned integer if
* possible. * possible.
* *
* default * default
* Integer value to be used as default for this * Integer value to be used as default for this
* field. * field.
* *
* notnull * notnull
* Boolean flag that indicates whether this field is * Boolean flag that indicates whether this field is
* constrained to not be set to null. * constrained to not be set to null.
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
* @access protected * @access protected
*/ */
function _getIntegerDeclaration($name, $field) function _getIntegerDeclaration($name, $field)
{ {
$db = $this->getDBInstance(); $db = $this->getDBInstance();
if (PEAR::isError($db)) { if (PEAR::isError($db)) {
return $db; return $db;
} }
$default = $autoinc = ''; $default = $autoinc = '';
if (!empty($field['autoincrement'])) { if (!empty($field['autoincrement'])) {
$autoinc = ' PRIMARY KEY'; $autoinc = ' PRIMARY KEY';
} elseif (array_key_exists('default', $field)) { } elseif (array_key_exists('default', $field)) {
if ($field['default'] === '') { if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) ? null : 0; $field['default'] = empty($field['notnull']) ? null : 0;
} }
$default = ' DEFAULT '.$this->quote($field['default'], 'integer'); $default = ' DEFAULT '.$this->quote($field['default'], 'integer');
} }
$notnull = empty($field['notnull']) ? '' : ' NOT NULL'; $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
$unsigned = empty($field['unsigned']) ? '' : ' UNSIGNED'; $unsigned = empty($field['unsigned']) ? '' : ' UNSIGNED';
if (empty($default) && empty($notnull)) { if (empty($default) && empty($notnull)) {
$default = ' DEFAULT NULL'; $default = ' DEFAULT NULL';
} }
$name = $db->quoteIdentifier($name, true); $name = $db->quoteIdentifier($name, true);
return $name.' '.$this->getTypeDeclaration($field).$unsigned.$default.$notnull.$autoinc; return $name.' '.$this->getTypeDeclaration($field).$unsigned.$default.$notnull.$autoinc;
} }
// }}} // }}}
// {{{ matchPattern() // {{{ matchPattern()
/** /**
* build a pattern matching string * build a pattern matching string
* *
* @access public * @access public
* *
* @param array $pattern even keys are strings, odd are patterns (% and _) * @param array $pattern even keys are strings, odd are patterns (% and _)
* @param string $operator optional pattern operator (LIKE, ILIKE and maybe others in the future) * @param string $operator optional pattern operator (LIKE, ILIKE and maybe others in the future)
* @param string $field optional field name that is being matched against * @param string $field optional field name that is being matched against
* (might be required when emulating ILIKE) * (might be required when emulating ILIKE)
* *
* @return string SQL pattern * @return string SQL pattern
*/ */
function matchPattern($pattern, $operator = null, $field = null) function matchPattern($pattern, $operator = null, $field = null)
{ {
$db = $this->getDBInstance(); $db = $this->getDBInstance();
if (PEAR::isError($db)) { if (PEAR::isError($db)) {
return $db; return $db;
} }
$match = ''; $match = '';
if (null !== $operator) { if (null !== $operator) {
$field = (null === $field) ? '' : $field.' '; $field = (null === $field) ? '' : $field.' ';
$operator = strtoupper($operator); $operator = strtoupper($operator);
switch ($operator) { switch ($operator) {
// case insensitive // case insensitive
case 'ILIKE': case 'ILIKE':
$match = $field.'LIKE '; $match = $field.'LIKE ';
break; break;
case 'NOT ILIKE': case 'NOT ILIKE':
$match = $field.'NOT LIKE '; $match = $field.'NOT LIKE ';
break; break;
// case sensitive // case sensitive
case 'LIKE': case 'LIKE':
$match = $field.'LIKE '; $match = $field.'LIKE ';
break; break;
case 'NOT LIKE': case 'NOT LIKE':
$match = $field.'NOT LIKE '; $match = $field.'NOT LIKE ';
break; break;
default: default:
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'not a supported operator type:'. $operator, __FUNCTION__); 'not a supported operator type:'. $operator, __FUNCTION__);
} }
} }
$match.= "'"; $match.= "'";
foreach ($pattern as $key => $value) { foreach ($pattern as $key => $value) {
if ($key % 2) { if ($key % 2) {
$match.= $value; $match.= $value;
} else { } else {
$match.= $db->escapePattern($db->escape($value)); $match.= $db->escapePattern($db->escape($value));
} }
} }
$match.= "'"; $match.= "'";
$match.= $this->patternEscapeString(); $match.= $this->patternEscapeString();
return $match; return $match;
} }
// }}} // }}}
// {{{ _mapNativeDatatype() // {{{ _mapNativeDatatype()
/** /**
* Maps a native array description of a field to a MDB2 datatype and length * Maps a native array description of a field to a MDB2 datatype and length
* *
* @param array $field native field description * @param array $field native field description
* @return array containing the various possible types, length, sign, fixed * @return array containing the various possible types, length, sign, fixed
* @access public * @access public
*/ */
function _mapNativeDatatype($field) function _mapNativeDatatype($field)
{ {
$db_type = strtolower($field['type']); $db_type = strtolower($field['type']);
$length = !empty($field['length']) ? $field['length'] : null; $length = !empty($field['length']) ? $field['length'] : null;
$unsigned = !empty($field['unsigned']) ? $field['unsigned'] : null; $unsigned = !empty($field['unsigned']) ? $field['unsigned'] : null;
$fixed = null; $fixed = null;
$type = array(); $type = array();
switch ($db_type) { switch ($db_type) {
case 'boolean': case 'boolean':
$type[] = 'boolean'; $type[] = 'boolean';
break; break;
case 'tinyint': case 'tinyint':
$type[] = 'integer'; $type[] = 'integer';
$type[] = 'boolean'; $type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) { if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type); $type = array_reverse($type);
} }
$unsigned = preg_match('/ unsigned/i', $field['type']); $unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 1; $length = 1;
break; break;
case 'smallint': case 'smallint':
$type[] = 'integer'; $type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']); $unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 2; $length = 2;
break; break;
case 'mediumint': case 'mediumint':
$type[] = 'integer'; $type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']); $unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 3; $length = 3;
break; break;
case 'int': case 'int':
case 'integer': case 'integer':
case 'serial': case 'serial':
$type[] = 'integer'; $type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']); $unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 4; $length = 4;
break; break;
case 'bigint': case 'bigint':
case 'bigserial': case 'bigserial':
$type[] = 'integer'; $type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']); $unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 8; $length = 8;
break; break;
case 'clob': case 'clob':
$type[] = 'clob'; $type[] = 'clob';
$fixed = false; $fixed = false;
break; break;
case 'tinytext': case 'tinytext':
case 'mediumtext': case 'mediumtext':
case 'longtext': case 'longtext':
case 'text': case 'text':
case 'varchar': case 'varchar':
case 'varchar2': case 'varchar2':
$fixed = false; $fixed = false;
case 'char': case 'char':
$type[] = 'text'; $type[] = 'text';
if ($length == '1') { if ($length == '1') {
$type[] = 'boolean'; $type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) { if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type); $type = array_reverse($type);
} }
} elseif (strstr($db_type, 'text')) { } elseif (strstr($db_type, 'text')) {
$type[] = 'clob'; $type[] = 'clob';
$type = array_reverse($type); $type = array_reverse($type);
} }
if ($fixed !== false) { if ($fixed !== false) {
$fixed = true; $fixed = true;
} }
break; break;
case 'date': case 'date':
$type[] = 'date'; $type[] = 'date';
$length = null; $length = null;
break; break;
case 'datetime': case 'datetime':
case 'timestamp': case 'timestamp':
$type[] = 'timestamp'; $type[] = 'timestamp';
$length = null; $length = null;
break; break;
case 'time': case 'time':
$type[] = 'time'; $type[] = 'time';
$length = null; $length = null;
break; break;
case 'float': case 'float':
case 'double': case 'double':
case 'real': case 'real':
$type[] = 'float'; $type[] = 'float';
break; break;
case 'decimal': case 'decimal':
case 'numeric': case 'numeric':
$type[] = 'decimal'; $type[] = 'decimal';
$length = $length.','.$field['decimal']; $length = $length.','.$field['decimal'];
break; break;
case 'tinyblob': case 'tinyblob':
case 'mediumblob': case 'mediumblob':
case 'longblob': case 'longblob':
case 'blob': case 'blob':
$type[] = 'blob'; $type[] = 'blob';
$length = null; $length = null;
break; break;
case 'year': case 'year':
$type[] = 'integer'; $type[] = 'integer';
$type[] = 'date'; $type[] = 'date';
$length = null; $length = null;
break; break;
default: default:
$db = $this->getDBInstance(); $db = $this->getDBInstance();
if (PEAR::isError($db)) { if (PEAR::isError($db)) {
return $db; return $db;
} }
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'unknown database attribute type: '.$db_type, __FUNCTION__); 'unknown database attribute type: '.$db_type, __FUNCTION__);
} }
if ((int)$length <= 0) { if ((int)$length <= 0) {
$length = null; $length = null;
} }
return array($type, $length, $unsigned, $fixed); return array($type, $length, $unsigned, $fixed);
} }
// }}} // }}}
} }
?> ?>

View File

@ -1,293 +1,293 @@
<?php <?php
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | PHP versions 4 and 5 | // | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, | // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith | // | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. | // | All rights reserved. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. | // | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. | // | This LICENSE is in the BSD license style. |
// | | // | |
// | Redistribution and use in source and binary forms, with or without | // | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions | // | modification, are permitted provided that the following conditions |
// | are met: | // | are met: |
// | | // | |
// | Redistributions of source code must retain the above copyright | // | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. | // | notice, this list of conditions and the following disclaimer. |
// | | // | |
// | Redistributions in binary form must reproduce the above copyright | // | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the | // | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. | // | documentation and/or other materials provided with the distribution. |
// | | // | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse | // | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior| // | or promote products derived from this software without specific prior|
// | written permission. | // | written permission. |
// | | // | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. | // | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> | // | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// //
// $Id: Common.php 295587 2010-02-28 17:16:38Z quipo $ // $Id$
// //
/** /**
* @package MDB2 * @package MDB2
* @category Database * @category Database
* @author Lukas Smith <smith@pooteeweet.org> * @author Lukas Smith <smith@pooteeweet.org>
*/ */
/** /**
* Base class for the function modules that is extended by each MDB2 driver * Base class for the function modules that is extended by each MDB2 driver
* *
* To load this module in the MDB2 object: * To load this module in the MDB2 object:
* $mdb->loadModule('Function'); * $mdb->loadModule('Function');
* *
* @package MDB2 * @package MDB2
* @category Database * @category Database
* @author Lukas Smith <smith@pooteeweet.org> * @author Lukas Smith <smith@pooteeweet.org>
*/ */
class MDB2_Driver_Function_Common extends MDB2_Module_Common class MDB2_Driver_Function_Common extends MDB2_Module_Common
{ {
// {{{ executeStoredProc() // {{{ executeStoredProc()
/** /**
* Execute a stored procedure and return any results * Execute a stored procedure and return any results
* *
* @param string $name string that identifies the function to execute * @param string $name string that identifies the function to execute
* @param mixed $params array that contains the paramaters to pass the stored proc * @param mixed $params array that contains the paramaters to pass the stored proc
* @param mixed $types array that contains the types of the columns in * @param mixed $types array that contains the types of the columns in
* the result set * the result set
* @param mixed $result_class string which specifies which result class to use * @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in * @param mixed $result_wrap_class string which specifies which class to wrap results in
* *
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access public * @access public
*/ */
function executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false) function executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
{ {
$db = $this->getDBInstance(); $db = $this->getDBInstance();
if (PEAR::isError($db)) { if (PEAR::isError($db)) {
return $db; return $db;
} }
$error = $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, $error = $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__); 'method not implemented', __FUNCTION__);
return $error; return $error;
} }
// }}} // }}}
// {{{ functionTable() // {{{ functionTable()
/** /**
* return string for internal table used when calling only a function * return string for internal table used when calling only a function
* *
* @return string for internal table used when calling only a function * @return string for internal table used when calling only a function
* @access public * @access public
*/ */
function functionTable() function functionTable()
{ {
return ''; return '';
} }
// }}} // }}}
// {{{ now() // {{{ now()
/** /**
* Return string to call a variable with the current timestamp inside an SQL statement * Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time: * There are three special variables for current date and time:
* - CURRENT_TIMESTAMP (date and time, TIMESTAMP type) * - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
* - CURRENT_DATE (date, DATE type) * - CURRENT_DATE (date, DATE type)
* - CURRENT_TIME (time, TIME type) * - CURRENT_TIME (time, TIME type)
* *
* @param string $type 'timestamp' | 'time' | 'date' * @param string $type 'timestamp' | 'time' | 'date'
* *
* @return string to call a variable with the current timestamp * @return string to call a variable with the current timestamp
* @access public * @access public
*/ */
function now($type = 'timestamp') function now($type = 'timestamp')
{ {
switch ($type) { switch ($type) {
case 'time': case 'time':
return 'CURRENT_TIME'; return 'CURRENT_TIME';
case 'date': case 'date':
return 'CURRENT_DATE'; return 'CURRENT_DATE';
case 'timestamp': case 'timestamp':
default: default:
return 'CURRENT_TIMESTAMP'; return 'CURRENT_TIMESTAMP';
} }
} }
// }}} // }}}
// {{{ unixtimestamp() // {{{ unixtimestamp()
/** /**
* return string to call a function to get the unix timestamp from a iso timestamp * return string to call a function to get the unix timestamp from a iso timestamp
* *
* @param string $expression * @param string $expression
* *
* @return string to call a variable with the timestamp * @return string to call a variable with the timestamp
* @access public * @access public
*/ */
function unixtimestamp($expression) function unixtimestamp($expression)
{ {
$db = $this->getDBInstance(); $db = $this->getDBInstance();
if (PEAR::isError($db)) { if (PEAR::isError($db)) {
return $db; return $db;
} }
$error = $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, $error = $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__); 'method not implemented', __FUNCTION__);
return $error; return $error;
} }
// }}} // }}}
// {{{ substring() // {{{ substring()
/** /**
* return string to call a function to get a substring inside an SQL statement * return string to call a function to get a substring inside an SQL statement
* *
* @return string to call a function to get a substring * @return string to call a function to get a substring
* @access public * @access public
*/ */
function substring($value, $position = 1, $length = null) function substring($value, $position = 1, $length = null)
{ {
if (null !== $length) { if (null !== $length) {
return "SUBSTRING($value FROM $position FOR $length)"; return "SUBSTRING($value FROM $position FOR $length)";
} }
return "SUBSTRING($value FROM $position)"; return "SUBSTRING($value FROM $position)";
} }
// }}} // }}}
// {{{ replace() // {{{ replace()
/** /**
* return string to call a function to get replace inside an SQL statement. * return string to call a function to get replace inside an SQL statement.
* *
* @return string to call a function to get a replace * @return string to call a function to get a replace
* @access public * @access public
*/ */
function replace($str, $from_str, $to_str) function replace($str, $from_str, $to_str)
{ {
return "REPLACE($str, $from_str , $to_str)"; return "REPLACE($str, $from_str , $to_str)";
} }
// }}} // }}}
// {{{ concat() // {{{ concat()
/** /**
* Returns string to concatenate two or more string parameters * Returns string to concatenate two or more string parameters
* *
* @param string $value1 * @param string $value1
* @param string $value2 * @param string $value2
* @param string $values... * @param string $values...
* *
* @return string to concatenate two strings * @return string to concatenate two strings
* @access public * @access public
*/ */
function concat($value1, $value2) function concat($value1, $value2)
{ {
$args = func_get_args(); $args = func_get_args();
return "(".implode(' || ', $args).")"; return "(".implode(' || ', $args).")";
} }
// }}} // }}}
// {{{ random() // {{{ random()
/** /**
* return string to call a function to get random value inside an SQL statement * return string to call a function to get random value inside an SQL statement
* *
* @return return string to generate float between 0 and 1 * @return return string to generate float between 0 and 1
* @access public * @access public
*/ */
function random() function random()
{ {
return 'RAND()'; return 'RAND()';
} }
// }}} // }}}
// {{{ lower() // {{{ lower()
/** /**
* return string to call a function to lower the case of an expression * return string to call a function to lower the case of an expression
* *
* @param string $expression * @param string $expression
* *
* @return return string to lower case of an expression * @return return string to lower case of an expression
* @access public * @access public
*/ */
function lower($expression) function lower($expression)
{ {
return "LOWER($expression)"; return "LOWER($expression)";
} }
// }}} // }}}
// {{{ upper() // {{{ upper()
/** /**
* return string to call a function to upper the case of an expression * return string to call a function to upper the case of an expression
* *
* @param string $expression * @param string $expression
* *
* @return return string to upper case of an expression * @return return string to upper case of an expression
* @access public * @access public
*/ */
function upper($expression) function upper($expression)
{ {
return "UPPER($expression)"; return "UPPER($expression)";
} }
// }}} // }}}
// {{{ length() // {{{ length()
/** /**
* return string to call a function to get the length of a string expression * return string to call a function to get the length of a string expression
* *
* @param string $expression * @param string $expression
* *
* @return return string to get the string expression length * @return return string to get the string expression length
* @access public * @access public
*/ */
function length($expression) function length($expression)
{ {
return "LENGTH($expression)"; return "LENGTH($expression)";
} }
// }}} // }}}
// {{{ guid() // {{{ guid()
/** /**
* Returns global unique identifier * Returns global unique identifier
* *
* @return string to get global unique identifier * @return string to get global unique identifier
* @access public * @access public
*/ */
function guid() function guid()
{ {
$db = $this->getDBInstance(); $db = $this->getDBInstance();
if (PEAR::isError($db)) { if (PEAR::isError($db)) {
return $db; return $db;
} }
$error = $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, $error = $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__); 'method not implemented', __FUNCTION__);
return $error; return $error;
} }
// }}} // }}}
} }
?> ?>

View File

@ -1,136 +1,136 @@
<?php <?php
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | PHP versions 4 and 5 | // | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, | // | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith | // | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. | // | All rights reserved. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. | // | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. | // | This LICENSE is in the BSD license style. |
// | | // | |
// | Redistribution and use in source and binary forms, with or without | // | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions | // | modification, are permitted provided that the following conditions |
// | are met: | // | are met: |
// | | // | |
// | Redistributions of source code must retain the above copyright | // | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. | // | notice, this list of conditions and the following disclaimer. |
// | | // | |
// | Redistributions in binary form must reproduce the above copyright | // | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the | // | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. | // | documentation and/or other materials provided with the distribution. |
// | | // | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse | // | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior| // | or promote products derived from this software without specific prior|
// | written permission. | // | written permission. |
// | | // | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. | // | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> | // | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// //
// $Id: mysql.php 295587 2010-02-28 17:16:38Z quipo $ // $Id$
// //
require_once 'MDB2/Driver/Function/Common.php'; require_once 'MDB2/Driver/Function/Common.php';
/** /**
* MDB2 MySQL driver for the function modules * MDB2 MySQL driver for the function modules
* *
* @package MDB2 * @package MDB2
* @category Database * @category Database
* @author Lukas Smith <smith@pooteeweet.org> * @author Lukas Smith <smith@pooteeweet.org>
*/ */
class MDB2_Driver_Function_mysql extends MDB2_Driver_Function_Common class MDB2_Driver_Function_mysql extends MDB2_Driver_Function_Common
{ {
// }}} // }}}
// {{{ executeStoredProc() // {{{ executeStoredProc()
/** /**
* Execute a stored procedure and return any results * Execute a stored procedure and return any results
* *
* @param string $name string that identifies the function to execute * @param string $name string that identifies the function to execute
* @param mixed $params array that contains the paramaters to pass the stored proc * @param mixed $params array that contains the paramaters to pass the stored proc
* @param mixed $types array that contains the types of the columns in * @param mixed $types array that contains the types of the columns in
* the result set * the result set
* @param mixed $result_class string which specifies which result class to use * @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in * @param mixed $result_wrap_class string which specifies which class to wrap results in
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access public * @access public
*/ */
function executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false) function executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
{ {
$db = $this->getDBInstance(); $db = $this->getDBInstance();
if (PEAR::isError($db)) { if (PEAR::isError($db)) {
return $db; return $db;
} }
$query = 'CALL '.$name; $query = 'CALL '.$name;
$query .= $params ? '('.implode(', ', $params).')' : '()'; $query .= $params ? '('.implode(', ', $params).')' : '()';
return $db->query($query, $types, $result_class, $result_wrap_class); return $db->query($query, $types, $result_class, $result_wrap_class);
} }
// }}} // }}}
// {{{ unixtimestamp() // {{{ unixtimestamp()
/** /**
* return string to call a function to get the unix timestamp from a iso timestamp * return string to call a function to get the unix timestamp from a iso timestamp
* *
* @param string $expression * @param string $expression
* *
* @return string to call a variable with the timestamp * @return string to call a variable with the timestamp
* @access public * @access public
*/ */
function unixtimestamp($expression) function unixtimestamp($expression)
{ {
return 'UNIX_TIMESTAMP('. $expression.')'; return 'UNIX_TIMESTAMP('. $expression.')';
} }
// }}} // }}}
// {{{ concat() // {{{ concat()
/** /**
* Returns string to concatenate two or more string parameters * Returns string to concatenate two or more string parameters
* *
* @param string $value1 * @param string $value1
* @param string $value2 * @param string $value2
* @param string $values... * @param string $values...
* @return string to concatenate two strings * @return string to concatenate two strings
* @access public * @access public
**/ **/
function concat($value1, $value2) function concat($value1, $value2)
{ {
$args = func_get_args(); $args = func_get_args();
return "CONCAT(".implode(', ', $args).")"; return "CONCAT(".implode(', ', $args).")";
} }
// }}} // }}}
// {{{ guid() // {{{ guid()
/** /**
* Returns global unique identifier * Returns global unique identifier
* *
* @return string to get global unique identifier * @return string to get global unique identifier
* @access public * @access public
*/ */
function guid() function guid()
{ {
return 'UUID()'; return 'UUID()';
} }
// }}} // }}}
} }
?> ?>

View File

@ -1,132 +1,132 @@
<?php <?php
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | PHP versions 4 and 5 | // | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, | // | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith | // | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. | // | All rights reserved. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. | // | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. | // | This LICENSE is in the BSD license style. |
// | | // | |
// | Redistribution and use in source and binary forms, with or without | // | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions | // | modification, are permitted provided that the following conditions |
// | are met: | // | are met: |
// | | // | |
// | Redistributions of source code must retain the above copyright | // | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. | // | notice, this list of conditions and the following disclaimer. |
// | | // | |
// | Redistributions in binary form must reproduce the above copyright | // | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the | // | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. | // | documentation and/or other materials provided with the distribution. |
// | | // | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse | // | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior| // | or promote products derived from this software without specific prior|
// | written permission. | // | written permission. |
// | | // | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. | // | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Author: Paul Cooper <pgc@ucecom.com> | // | Author: Paul Cooper <pgc@ucecom.com> |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// //
// $Id: pgsql.php 296139 2010-03-13 04:15:22Z afz $ // $Id$
require_once 'MDB2/Driver/Function/Common.php'; require_once 'MDB2/Driver/Function/Common.php';
/** /**
* MDB2 MySQL driver for the function modules * MDB2 MySQL driver for the function modules
* *
* @package MDB2 * @package MDB2
* @category Database * @category Database
* @author Lukas Smith <smith@pooteeweet.org> * @author Lukas Smith <smith@pooteeweet.org>
*/ */
class MDB2_Driver_Function_pgsql extends MDB2_Driver_Function_Common class MDB2_Driver_Function_pgsql extends MDB2_Driver_Function_Common
{ {
// {{{ executeStoredProc() // {{{ executeStoredProc()
/** /**
* Execute a stored procedure and return any results * Execute a stored procedure and return any results
* *
* @param string $name string that identifies the function to execute * @param string $name string that identifies the function to execute
* @param mixed $params array that contains the paramaters to pass the stored proc * @param mixed $params array that contains the paramaters to pass the stored proc
* @param mixed $types array that contains the types of the columns in * @param mixed $types array that contains the types of the columns in
* the result set * the result set
* @param mixed $result_class string which specifies which result class to use * @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in * @param mixed $result_wrap_class string which specifies which class to wrap results in
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access public * @access public
*/ */
function executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false) function executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
{ {
$db = $this->getDBInstance(); $db = $this->getDBInstance();
if (PEAR::isError($db)) { if (PEAR::isError($db)) {
return $db; return $db;
} }
$query = 'SELECT * FROM '.$name; $query = 'SELECT * FROM '.$name;
$query .= $params ? '('.implode(', ', $params).')' : '()'; $query .= $params ? '('.implode(', ', $params).')' : '()';
return $db->query($query, $types, $result_class, $result_wrap_class); return $db->query($query, $types, $result_class, $result_wrap_class);
} }
// }}} // }}}
// {{{ unixtimestamp() // {{{ unixtimestamp()
/** /**
* return string to call a function to get the unix timestamp from a iso timestamp * return string to call a function to get the unix timestamp from a iso timestamp
* *
* @param string $expression * @param string $expression
* *
* @return string to call a variable with the timestamp * @return string to call a variable with the timestamp
* @access public * @access public
*/ */
function unixtimestamp($expression) function unixtimestamp($expression)
{ {
return 'EXTRACT(EPOCH FROM DATE_TRUNC(\'seconds\', CAST ((' . $expression . ') AS TIMESTAMP)))'; return 'EXTRACT(EPOCH FROM DATE_TRUNC(\'seconds\', CAST ((' . $expression . ') AS TIMESTAMP)))';
} }
// }}} // }}}
// {{{ substring() // {{{ substring()
/** /**
* return string to call a function to get a substring inside an SQL statement * return string to call a function to get a substring inside an SQL statement
* *
* @return string to call a function to get a substring * @return string to call a function to get a substring
* @access public * @access public
*/ */
function substring($value, $position = 1, $length = null) function substring($value, $position = 1, $length = null)
{ {
if (null !== $length) { if (null !== $length) {
return "SUBSTRING(CAST($value AS VARCHAR) FROM $position FOR $length)"; return "SUBSTRING(CAST($value AS VARCHAR) FROM $position FOR $length)";
} }
return "SUBSTRING(CAST($value AS VARCHAR) FROM $position)"; return "SUBSTRING(CAST($value AS VARCHAR) FROM $position)";
} }
// }}} // }}}
// {{{ random() // {{{ random()
/** /**
* return string to call a function to get random value inside an SQL statement * return string to call a function to get random value inside an SQL statement
* *
* @return return string to generate float between 0 and 1 * @return return string to generate float between 0 and 1
* @access public * @access public
*/ */
function random() function random()
{ {
return 'RANDOM()'; return 'RANDOM()';
} }
// }}} // }}}
} }
?> ?>

View File

@ -1,162 +1,162 @@
<?php <?php
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | PHP versions 4 and 5 | // | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, | // | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith | // | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. | // | All rights reserved. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. | // | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. | // | This LICENSE is in the BSD license style. |
// | | // | |
// | Redistribution and use in source and binary forms, with or without | // | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions | // | modification, are permitted provided that the following conditions |
// | are met: | // | are met: |
// | | // | |
// | Redistributions of source code must retain the above copyright | // | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. | // | notice, this list of conditions and the following disclaimer. |
// | | // | |
// | Redistributions in binary form must reproduce the above copyright | // | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the | // | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. | // | documentation and/or other materials provided with the distribution. |
// | | // | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse | // | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior| // | or promote products derived from this software without specific prior|
// | written permission. | // | written permission. |
// | | // | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. | // | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> | // | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// //
// $Id: sqlite.php 295587 2010-02-28 17:16:38Z quipo $ // $Id$
// //
require_once 'MDB2/Driver/Function/Common.php'; require_once 'MDB2/Driver/Function/Common.php';
/** /**
* MDB2 SQLite driver for the function modules * MDB2 SQLite driver for the function modules
* *
* @package MDB2 * @package MDB2
* @category Database * @category Database
* @author Lukas Smith <smith@pooteeweet.org> * @author Lukas Smith <smith@pooteeweet.org>
*/ */
class MDB2_Driver_Function_sqlite extends MDB2_Driver_Function_Common class MDB2_Driver_Function_sqlite extends MDB2_Driver_Function_Common
{ {
// {{{ constructor // {{{ constructor
/** /**
* Constructor * Constructor
*/ */
function __construct($db_index) function __construct($db_index)
{ {
parent::__construct($db_index); parent::__construct($db_index);
// create all sorts of UDFs // create all sorts of UDFs
} }
// {{{ now() // {{{ now()
/** /**
* Return string to call a variable with the current timestamp inside an SQL statement * Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time. * There are three special variables for current date and time.
* *
* @return string to call a variable with the current timestamp * @return string to call a variable with the current timestamp
* @access public * @access public
*/ */
function now($type = 'timestamp') function now($type = 'timestamp')
{ {
switch ($type) { switch ($type) {
case 'time': case 'time':
return 'time(\'now\')'; return 'time(\'now\')';
case 'date': case 'date':
return 'date(\'now\')'; return 'date(\'now\')';
case 'timestamp': case 'timestamp':
default: default:
return 'datetime(\'now\')'; return 'datetime(\'now\')';
} }
} }
// }}} // }}}
// {{{ unixtimestamp() // {{{ unixtimestamp()
/** /**
* return string to call a function to get the unix timestamp from a iso timestamp * return string to call a function to get the unix timestamp from a iso timestamp
* *
* @param string $expression * @param string $expression
* *
* @return string to call a variable with the timestamp * @return string to call a variable with the timestamp
* @access public * @access public
*/ */
function unixtimestamp($expression) function unixtimestamp($expression)
{ {
return 'strftime("%s",'. $expression.', "utc")'; return 'strftime("%s",'. $expression.', "utc")';
} }
// }}} // }}}
// {{{ substring() // {{{ substring()
/** /**
* return string to call a function to get a substring inside an SQL statement * return string to call a function to get a substring inside an SQL statement
* *
* @return string to call a function to get a substring * @return string to call a function to get a substring
* @access public * @access public
*/ */
function substring($value, $position = 1, $length = null) function substring($value, $position = 1, $length = null)
{ {
if (null !== $length) { if (null !== $length) {
return "substr($value, $position, $length)"; return "substr($value, $position, $length)";
} }
return "substr($value, $position, length($value))"; return "substr($value, $position, length($value))";
} }
// }}} // }}}
// {{{ random() // {{{ random()
/** /**
* return string to call a function to get random value inside an SQL statement * return string to call a function to get random value inside an SQL statement
* *
* @return return string to generate float between 0 and 1 * @return return string to generate float between 0 and 1
* @access public * @access public
*/ */
function random() function random()
{ {
return '((RANDOM()+2147483648)/4294967296)'; return '((RANDOM()+2147483648)/4294967296)';
} }
// }}} // }}}
// {{{ replace() // {{{ replace()
/** /**
* return string to call a function to get a replacement inside an SQL statement. * return string to call a function to get a replacement inside an SQL statement.
* *
* @return string to call a function to get a replace * @return string to call a function to get a replace
* @access public * @access public
*/ */
function replace($str, $from_str, $to_str) function replace($str, $from_str, $to_str)
{ {
$db = $this->getDBInstance(); $db = $this->getDBInstance();
if (PEAR::isError($db)) { if (PEAR::isError($db)) {
return $db; return $db;
} }
$error = $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, $error = $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__); 'method not implemented', __FUNCTION__);
return $error; return $error;
} }
// }}} // }}}
} }
?> ?>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,61 +1,61 @@
<?php <?php
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | PHP versions 4 and 5 | // | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, | // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith | // | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. | // | All rights reserved. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. | // | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. | // | This LICENSE is in the BSD license style. |
// | | // | |
// | Redistribution and use in source and binary forms, with or without | // | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions | // | modification, are permitted provided that the following conditions |
// | are met: | // | are met: |
// | | // | |
// | Redistributions of source code must retain the above copyright | // | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. | // | notice, this list of conditions and the following disclaimer. |
// | | // | |
// | Redistributions in binary form must reproduce the above copyright | // | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the | // | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. | // | documentation and/or other materials provided with the distribution. |
// | | // | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse | // | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior| // | or promote products derived from this software without specific prior|
// | written permission. | // | written permission. |
// | | // | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. | // | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> | // | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// //
// $Id: Common.php 242348 2007-09-09 13:47:36Z quipo $ // $Id$
// //
/** /**
* Base class for the natuve modules that is extended by each MDB2 driver * Base class for the natuve modules that is extended by each MDB2 driver
* *
* To load this module in the MDB2 object: * To load this module in the MDB2 object:
* $mdb->loadModule('Native'); * $mdb->loadModule('Native');
* *
* @package MDB2 * @package MDB2
* @category Database * @category Database
* @author Lukas Smith <smith@pooteeweet.org> * @author Lukas Smith <smith@pooteeweet.org>
*/ */
class MDB2_Driver_Native_Common extends MDB2_Module_Common class MDB2_Driver_Native_Common extends MDB2_Module_Common
{ {
} }
?> ?>

View File

@ -1,60 +1,60 @@
<?php <?php
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | PHP versions 4 and 5 | // | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, | // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith | // | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. | // | All rights reserved. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. | // | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. | // | This LICENSE is in the BSD license style. |
// | | // | |
// | Redistribution and use in source and binary forms, with or without | // | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions | // | modification, are permitted provided that the following conditions |
// | are met: | // | are met: |
// | | // | |
// | Redistributions of source code must retain the above copyright | // | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. | // | notice, this list of conditions and the following disclaimer. |
// | | // | |
// | Redistributions in binary form must reproduce the above copyright | // | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the | // | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. | // | documentation and/or other materials provided with the distribution. |
// | | // | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse | // | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior| // | or promote products derived from this software without specific prior|
// | written permission. | // | written permission. |
// | | // | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. | // | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> | // | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// //
// $Id: mysql.php 215004 2006-06-18 21:59:05Z lsmith $ // $Id$
// //
require_once 'MDB2/Driver/Native/Common.php'; require_once 'MDB2/Driver/Native/Common.php';
/** /**
* MDB2 MySQL driver for the native module * MDB2 MySQL driver for the native module
* *
* @package MDB2 * @package MDB2
* @category Database * @category Database
* @author Lukas Smith <smith@pooteeweet.org> * @author Lukas Smith <smith@pooteeweet.org>
*/ */
class MDB2_Driver_Native_mysql extends MDB2_Driver_Native_Common class MDB2_Driver_Native_mysql extends MDB2_Driver_Native_Common
{ {
} }
?> ?>

View File

@ -1,88 +1,88 @@
<?php <?php
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | PHP versions 4 and 5 | // | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, | // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith | // | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. | // | All rights reserved. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. | // | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. | // | This LICENSE is in the BSD license style. |
// | | // | |
// | Redistribution and use in source and binary forms, with or without | // | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions | // | modification, are permitted provided that the following conditions |
// | are met: | // | are met: |
// | | // | |
// | Redistributions of source code must retain the above copyright | // | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. | // | notice, this list of conditions and the following disclaimer. |
// | | // | |
// | Redistributions in binary form must reproduce the above copyright | // | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the | // | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. | // | documentation and/or other materials provided with the distribution. |
// | | // | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse | // | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior| // | or promote products derived from this software without specific prior|
// | written permission. | // | written permission. |
// | | // | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. | // | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Author: Paul Cooper <pgc@ucecom.com> | // | Author: Paul Cooper <pgc@ucecom.com> |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// //
// $Id: pgsql.php 295587 2010-02-28 17:16:38Z quipo $ // $Id$
require_once 'MDB2/Driver/Native/Common.php'; require_once 'MDB2/Driver/Native/Common.php';
/** /**
* MDB2 PostGreSQL driver for the native module * MDB2 PostGreSQL driver for the native module
* *
* @package MDB2 * @package MDB2
* @category Database * @category Database
* @author Paul Cooper <pgc@ucecom.com> * @author Paul Cooper <pgc@ucecom.com>
*/ */
class MDB2_Driver_Native_pgsql extends MDB2_Driver_Native_Common class MDB2_Driver_Native_pgsql extends MDB2_Driver_Native_Common
{ {
// }}} // }}}
// {{{ deleteOID() // {{{ deleteOID()
/** /**
* delete an OID * delete an OID
* *
* @param integer $OID * @param integer $OID
* @return mixed MDB2_OK on success or MDB2 Error Object on failure * @return mixed MDB2_OK on success or MDB2 Error Object on failure
* @access public * @access public
*/ */
function deleteOID($OID) function deleteOID($OID)
{ {
$db = $this->getDBInstance(); $db = $this->getDBInstance();
if (PEAR::isError($db)) { if (PEAR::isError($db)) {
return $db; return $db;
} }
$connection = $db->getConnection(); $connection = $db->getConnection();
if (PEAR::isError($connection)) { if (PEAR::isError($connection)) {
return $connection; return $connection;
} }
if (!@pg_lo_unlink($connection, $OID)) { if (!@pg_lo_unlink($connection, $OID)) {
return $db->raiseError(null, null, null, return $db->raiseError(null, null, null,
'Unable to unlink OID: '.$OID, __FUNCTION__); 'Unable to unlink OID: '.$OID, __FUNCTION__);
} }
return MDB2_OK; return MDB2_OK;
} }
} }
?> ?>

View File

@ -1,60 +1,60 @@
<?php <?php
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | PHP versions 4 and 5 | // | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, | // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith | // | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. | // | All rights reserved. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. | // | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. | // | This LICENSE is in the BSD license style. |
// | | // | |
// | Redistribution and use in source and binary forms, with or without | // | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions | // | modification, are permitted provided that the following conditions |
// | are met: | // | are met: |
// | | // | |
// | Redistributions of source code must retain the above copyright | // | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. | // | notice, this list of conditions and the following disclaimer. |
// | | // | |
// | Redistributions in binary form must reproduce the above copyright | // | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the | // | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. | // | documentation and/or other materials provided with the distribution. |
// | | // | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse | // | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior| // | or promote products derived from this software without specific prior|
// | written permission. | // | written permission. |
// | | // | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. | // | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> | // | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// //
// $Id: sqlite.php 215004 2006-06-18 21:59:05Z lsmith $ // $Id$
// //
require_once 'MDB2/Driver/Native/Common.php'; require_once 'MDB2/Driver/Native/Common.php';
/** /**
* MDB2 SQLite driver for the native module * MDB2 SQLite driver for the native module
* *
* @package MDB2 * @package MDB2
* @category Database * @category Database
* @author Lukas Smith <smith@pooteeweet.org> * @author Lukas Smith <smith@pooteeweet.org>
*/ */
class MDB2_Driver_Native_sqlite extends MDB2_Driver_Native_Common class MDB2_Driver_Native_sqlite extends MDB2_Driver_Native_Common
{ {
} }
?> ?>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,259 +1,262 @@
<?php <?php
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | PHP version 5 | // | PHP version 5 |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, | // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith | // | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. | // | All rights reserved. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. | // | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. | // | This LICENSE is in the BSD license style. |
// | | // | |
// | Redistribution and use in source and binary forms, with or without | // | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions | // | modification, are permitted provided that the following conditions |
// | are met: | // | are met: |
// | | // | |
// | Redistributions of source code must retain the above copyright | // | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. | // | notice, this list of conditions and the following disclaimer. |
// | | // | |
// | Redistributions in binary form must reproduce the above copyright | // | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the | // | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. | // | documentation and/or other materials provided with the distribution. |
// | | // | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse | // | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior| // | or promote products derived from this software without specific prior|
// | written permission. | // | written permission. |
// | | // | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. | // | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> | // | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// //
// $Id: Iterator.php 295586 2010-02-28 17:04:17Z quipo $ // $Id$
/** /**
* PHP5 Iterator * PHP5 Iterator
* *
* @package MDB2 * @package MDB2
* @category Database * @category Database
* @author Lukas Smith <smith@pooteeweet.org> * @author Lukas Smith <smith@pooteeweet.org>
*/ */
class MDB2_Iterator implements Iterator class MDB2_Iterator implements Iterator
{ {
protected $fetchmode; protected $fetchmode;
protected $result; /**
protected $row; * @var MDB2_Result_Common
*/
// {{{ constructor protected $result;
protected $row;
/**
* Constructor // {{{ constructor
*/
public function __construct($result, $fetchmode = MDB2_FETCHMODE_DEFAULT) /**
{ * Constructor
$this->result = $result; */
$this->fetchmode = $fetchmode; public function __construct(MDB2_Result_Common $result, $fetchmode = MDB2_FETCHMODE_DEFAULT)
} {
// }}} $this->result = $result;
$this->fetchmode = $fetchmode;
// {{{ seek() }
// }}}
/**
* Seek forward to a specific row in a result set // {{{ seek()
*
* @param int number of the row where the data can be found /**
* * Seek forward to a specific row in a result set
* @return void *
* @access public * @param int number of the row where the data can be found
*/ *
public function seek($rownum) * @return void
{ * @access public
$this->row = null; */
if ($this->result) { public function seek($rownum)
$this->result->seek($rownum); {
} $this->row = null;
} if ($this->result) {
// }}} $this->result->seek($rownum);
}
// {{{ next() }
// }}}
/**
* Fetch next row of data // {{{ next()
*
* @return void /**
* @access public * Fetch next row of data
*/ *
public function next() * @return void
{ * @access public
$this->row = null; */
} public function next()
// }}} {
$this->row = null;
// {{{ current() }
// }}}
/**
* return a row of data // {{{ current()
*
* @return void /**
* @access public * return a row of data
*/ *
public function current() * @return void
{ * @access public
if (null === $this->row) { */
$row = $this->result->fetchRow($this->fetchmode); public function current()
if (PEAR::isError($row)) { {
$row = false; if (null === $this->row) {
} $row = $this->result->fetchRow($this->fetchmode);
$this->row = $row; if (PEAR::isError($row)) {
} $row = false;
return $this->row; }
} $this->row = $row;
// }}} }
return $this->row;
// {{{ valid() }
// }}}
/**
* Check if the end of the result set has been reached // {{{ valid()
*
* @return bool true/false, false is also returned on failure /**
* @access public * Check if the end of the result set has been reached
*/ *
public function valid() * @return bool true/false, false is also returned on failure
{ * @access public
return (bool)$this->current(); */
} public function valid()
// }}} {
return (bool)$this->current();
// {{{ free() }
// }}}
/**
* Free the internal resources associated with result. // {{{ free()
*
* @return bool|MDB2_Error true on success, false|MDB2_Error if result is invalid /**
* @access public * Free the internal resources associated with result.
*/ *
public function free() * @return bool|MDB2_Error true on success, false|MDB2_Error if result is invalid
{ * @access public
if ($this->result) { */
return $this->result->free(); public function free()
} {
$this->result = false; if ($this->result) {
$this->row = null; return $this->result->free();
return false; }
} $this->result = false;
// }}} $this->row = null;
return false;
// {{{ key() }
// }}}
/**
* Returns the row number // {{{ key()
*
* @return int|bool|MDB2_Error true on success, false|MDB2_Error if result is invalid /**
* @access public * Returns the row number
*/ *
public function key() * @return int|bool|MDB2_Error true on success, false|MDB2_Error if result is invalid
{ * @access public
if ($this->result) { */
return $this->result->rowCount(); public function key()
} {
return false; if ($this->result) {
} return $this->result->rowCount();
// }}} }
return false;
// {{{ rewind() }
// }}}
/**
* Seek to the first row in a result set // {{{ rewind()
*
* @return void /**
* @access public * Seek to the first row in a result set
*/ *
public function rewind() * @return void
{ * @access public
} */
// }}} public function rewind()
{
// {{{ destructor }
// }}}
/**
* Destructor // {{{ destructor
*/
public function __destruct() /**
{ * Destructor
$this->free(); */
} public function __destruct()
// }}} {
} $this->free();
}
/** // }}}
* PHP5 buffered Iterator }
*
* @package MDB2 /**
* @category Database * PHP5 buffered Iterator
* @author Lukas Smith <smith@pooteeweet.org> *
*/ * @package MDB2
class MDB2_BufferedIterator extends MDB2_Iterator implements SeekableIterator * @category Database
{ * @author Lukas Smith <smith@pooteeweet.org>
// {{{ valid() */
class MDB2_BufferedIterator extends MDB2_Iterator implements SeekableIterator
/** {
* Check if the end of the result set has been reached // {{{ valid()
*
* @return bool|MDB2_Error true on success, false|MDB2_Error if result is invalid /**
* @access public * Check if the end of the result set has been reached
*/ *
public function valid() * @return bool|MDB2_Error true on success, false|MDB2_Error if result is invalid
{ * @access public
if ($this->result) { */
return $this->result->valid(); public function valid()
} {
return false; if ($this->result) {
} return $this->result->valid();
// }}} }
return false;
// {{{count() }
// }}}
/**
* Returns the number of rows in a result object // {{{count()
*
* @return int|MDB2_Error number of rows, false|MDB2_Error if result is invalid /**
* @access public * Returns the number of rows in a result object
*/ *
public function count() * @return int|MDB2_Error number of rows, false|MDB2_Error if result is invalid
{ * @access public
if ($this->result) { */
return $this->result->numRows(); public function count()
} {
return false; if ($this->result) {
} return $this->result->numRows();
// }}} }
return false;
// {{{ rewind() }
// }}}
/**
* Seek to the first row in a result set // {{{ rewind()
*
* @return void /**
* @access public * Seek to the first row in a result set
*/ *
public function rewind() * @return void
{ * @access public
$this->seek(0); */
} public function rewind()
// }}} {
} $this->seek(0);
}
// }}}
}
?> ?>

528
3rdparty/MDB2/LOB.php vendored
View File

@ -1,264 +1,264 @@
<?php <?php
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | PHP version 5 | // | PHP version 5 |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, | // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith | // | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. | // | All rights reserved. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. | // | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. | // | This LICENSE is in the BSD license style. |
// | | // | |
// | Redistribution and use in source and binary forms, with or without | // | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions | // | modification, are permitted provided that the following conditions |
// | are met: | // | are met: |
// | | // | |
// | Redistributions of source code must retain the above copyright | // | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. | // | notice, this list of conditions and the following disclaimer. |
// | | // | |
// | Redistributions in binary form must reproduce the above copyright | // | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the | // | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. | // | documentation and/or other materials provided with the distribution. |
// | | // | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse | // | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior| // | or promote products derived from this software without specific prior|
// | written permission. | // | written permission. |
// | | // | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. | // | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> | // | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// //
// $Id: LOB.php 222350 2006-10-25 11:52:21Z lsmith $ // $Id$
/** /**
* @package MDB2 * @package MDB2
* @category Database * @category Database
* @author Lukas Smith <smith@pooteeweet.org> * @author Lukas Smith <smith@pooteeweet.org>
*/ */
require_once 'MDB2.php'; require_once 'MDB2.php';
/** /**
* MDB2_LOB: user land stream wrapper implementation for LOB support * MDB2_LOB: user land stream wrapper implementation for LOB support
* *
* @package MDB2 * @package MDB2
* @category Database * @category Database
* @author Lukas Smith <smith@pooteeweet.org> * @author Lukas Smith <smith@pooteeweet.org>
*/ */
class MDB2_LOB class MDB2_LOB
{ {
/** /**
* contains the key to the global MDB2 instance array of the associated * contains the key to the global MDB2 instance array of the associated
* MDB2 instance * MDB2 instance
* *
* @var integer * @var integer
* @access protected * @access protected
*/ */
var $db_index; var $db_index;
/** /**
* contains the key to the global MDB2_LOB instance array of the associated * contains the key to the global MDB2_LOB instance array of the associated
* MDB2_LOB instance * MDB2_LOB instance
* *
* @var integer * @var integer
* @access protected * @access protected
*/ */
var $lob_index; var $lob_index;
// {{{ stream_open() // {{{ stream_open()
/** /**
* open stream * open stream
* *
* @param string specifies the URL that was passed to fopen() * @param string specifies the URL that was passed to fopen()
* @param string the mode used to open the file * @param string the mode used to open the file
* @param int holds additional flags set by the streams API * @param int holds additional flags set by the streams API
* @param string not used * @param string not used
* *
* @return bool * @return bool
* @access public * @access public
*/ */
function stream_open($path, $mode, $options, &$opened_path) function stream_open($path, $mode, $options, &$opened_path)
{ {
if (!preg_match('/^rb?\+?$/', $mode)) { if (!preg_match('/^rb?\+?$/', $mode)) {
return false; return false;
} }
$url = parse_url($path); $url = parse_url($path);
if (empty($url['host'])) { if (empty($url['host'])) {
return false; return false;
} }
$this->db_index = (int)$url['host']; $this->db_index = (int)$url['host'];
if (!isset($GLOBALS['_MDB2_databases'][$this->db_index])) { if (!isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
return false; return false;
} }
$db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
$this->lob_index = (int)$url['user']; $this->lob_index = (int)$url['user'];
if (!isset($db->datatype->lobs[$this->lob_index])) { if (!isset($db->datatype->lobs[$this->lob_index])) {
return false; return false;
} }
return true; return true;
} }
// }}} // }}}
// {{{ stream_read() // {{{ stream_read()
/** /**
* read stream * read stream
* *
* @param int number of bytes to read * @param int number of bytes to read
* *
* @return string * @return string
* @access public * @access public
*/ */
function stream_read($count) function stream_read($count)
{ {
if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) { if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
$db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
$db->datatype->_retrieveLOB($db->datatype->lobs[$this->lob_index]); $db->datatype->_retrieveLOB($db->datatype->lobs[$this->lob_index]);
$data = $db->datatype->_readLOB($db->datatype->lobs[$this->lob_index], $count); $data = $db->datatype->_readLOB($db->datatype->lobs[$this->lob_index], $count);
$length = strlen($data); $length = strlen($data);
if ($length == 0) { if ($length == 0) {
$db->datatype->lobs[$this->lob_index]['endOfLOB'] = true; $db->datatype->lobs[$this->lob_index]['endOfLOB'] = true;
} }
$db->datatype->lobs[$this->lob_index]['position'] += $length; $db->datatype->lobs[$this->lob_index]['position'] += $length;
return $data; return $data;
} }
} }
// }}} // }}}
// {{{ stream_write() // {{{ stream_write()
/** /**
* write stream, note implemented * write stream, note implemented
* *
* @param string data * @param string data
* *
* @return int * @return int
* @access public * @access public
*/ */
function stream_write($data) function stream_write($data)
{ {
return 0; return 0;
} }
// }}} // }}}
// {{{ stream_tell() // {{{ stream_tell()
/** /**
* return the current position * return the current position
* *
* @return int current position * @return int current position
* @access public * @access public
*/ */
function stream_tell() function stream_tell()
{ {
if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) { if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
$db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
return $db->datatype->lobs[$this->lob_index]['position']; return $db->datatype->lobs[$this->lob_index]['position'];
} }
} }
// }}} // }}}
// {{{ stream_eof() // {{{ stream_eof()
/** /**
* Check if stream reaches EOF * Check if stream reaches EOF
* *
* @return bool * @return bool
* @access public * @access public
*/ */
function stream_eof() function stream_eof()
{ {
if (!isset($GLOBALS['_MDB2_databases'][$this->db_index])) { if (!isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
return true; return true;
} }
$db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
$result = $db->datatype->_endOfLOB($db->datatype->lobs[$this->lob_index]); $result = $db->datatype->_endOfLOB($db->datatype->lobs[$this->lob_index]);
if (version_compare(phpversion(), "5.0", ">=") if (version_compare(phpversion(), "5.0", ">=")
&& version_compare(phpversion(), "5.1", "<") && version_compare(phpversion(), "5.1", "<")
) { ) {
return !$result; return !$result;
} }
return $result; return $result;
} }
// }}} // }}}
// {{{ stream_seek() // {{{ stream_seek()
/** /**
* Seek stream, not implemented * Seek stream, not implemented
* *
* @param int offset * @param int offset
* @param int whence * @param int whence
* *
* @return bool * @return bool
* @access public * @access public
*/ */
function stream_seek($offset, $whence) function stream_seek($offset, $whence)
{ {
return false; return false;
} }
// }}} // }}}
// {{{ stream_stat() // {{{ stream_stat()
/** /**
* return information about stream * return information about stream
* *
* @access public * @access public
*/ */
function stream_stat() function stream_stat()
{ {
if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) { if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
$db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
return array( return array(
'db_index' => $this->db_index, 'db_index' => $this->db_index,
'lob_index' => $this->lob_index, 'lob_index' => $this->lob_index,
); );
} }
} }
// }}} // }}}
// {{{ stream_close() // {{{ stream_close()
/** /**
* close stream * close stream
* *
* @access public * @access public
*/ */
function stream_close() function stream_close()
{ {
if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) { if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
$db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
if (isset($db->datatype->lobs[$this->lob_index])) { if (isset($db->datatype->lobs[$this->lob_index])) {
$db->datatype->_destroyLOB($db->datatype->lobs[$this->lob_index]); $db->datatype->_destroyLOB($db->datatype->lobs[$this->lob_index]);
unset($db->datatype->lobs[$this->lob_index]); unset($db->datatype->lobs[$this->lob_index]);
} }
} }
} }
// }}} // }}}
} }
// register streams wrapper // register streams wrapper
if (!stream_wrapper_register("MDB2LOB", "MDB2_LOB")) { if (!stream_wrapper_register("MDB2LOB", "MDB2_LOB")) {
MDB2::raiseError(); MDB2::raiseError();
return false; return false;
} }
?> ?>

View File

@ -1,8 +1,6 @@
<?php <?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
/** /**
* PHP version 4, 5 * Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
*
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali * Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved. * All rights reserved.
* *
@ -39,15 +37,14 @@
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* Author: Lukas Smith <smith@pooteeweet.org> * PHP version 5
* Author: Igor Feghali <ifeghali@php.net>
* *
* @category Database * @category Database
* @package MDB2_Schema * @package MDB2_Schema
* @author Lukas Smith <smith@pooteeweet.org> * @author Lukas Smith <smith@pooteeweet.org>
* @author Igor Feghali <ifeghali@php.net> * @author Igor Feghali <ifeghali@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php * @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id: Schema.php,v 1.132 2009/02/22 21:43:22 ifeghali Exp $ * @version SVN: $Id$
* @link http://pear.php.net/packages/MDB2_Schema * @link http://pear.php.net/packages/MDB2_Schema
*/ */
@ -96,7 +93,7 @@ class MDB2_Schema extends PEAR
'parser' => 'MDB2_Schema_Parser', 'parser' => 'MDB2_Schema_Parser',
'writer' => 'MDB2_Schema_Writer', 'writer' => 'MDB2_Schema_Writer',
'validate' => 'MDB2_Schema_Validate', 'validate' => 'MDB2_Schema_Validate',
'drop_missing_tables' => false 'drop_obsolete_objects' => false
); );
// }}} // }}}
@ -237,9 +234,9 @@ class MDB2_Schema extends PEAR
* @access public * @access public
* @see MDB2::parseDSN * @see MDB2::parseDSN
*/ */
function &factory(&$db, $options = array()) static function &factory(&$db, $options = array())
{ {
$obj =& new MDB2_Schema(); $obj = new MDB2_Schema();
$result = $obj->connect($db, $options); $result = $obj->connect($db, $options);
if (PEAR::isError($result)) { if (PEAR::isError($result)) {
@ -284,14 +281,14 @@ class MDB2_Schema extends PEAR
$this->disconnect(); $this->disconnect();
if (!MDB2::isConnection($db)) { if (!MDB2::isConnection($db)) {
$db =& MDB2::factory($db, $db_options); $db = MDB2::factory($db, $db_options);
} }
if (PEAR::isError($db)) { if (PEAR::isError($db)) {
return $db; return $db;
} }
$this->db =& $db; $this->db = $db;
$this->db->loadModule('Datatype'); $this->db->loadModule('Datatype');
$this->db->loadModule('Manager'); $this->db->loadModule('Manager');
$this->db->loadModule('Reverse'); $this->db->loadModule('Reverse');
@ -380,7 +377,7 @@ class MDB2_Schema extends PEAR
$dtd_file = $this->options['dtd_file']; $dtd_file = $this->options['dtd_file'];
if ($dtd_file) { if ($dtd_file) {
include_once 'XML/DTD/XmlValidator.php'; include_once 'XML/DTD/XmlValidator.php';
$dtd =& new XML_DTD_XmlValidator; $dtd = new XML_DTD_XmlValidator;
if (!$dtd->isValid($dtd_file, $input_file)) { if (!$dtd->isValid($dtd_file, $input_file)) {
return $this->raiseError(MDB2_SCHEMA_ERROR_PARSE, null, null, $dtd->getMessage()); return $this->raiseError(MDB2_SCHEMA_ERROR_PARSE, null, null, $dtd->getMessage());
} }
@ -393,7 +390,16 @@ class MDB2_Schema extends PEAR
return $result; return $result;
} }
$parser =& new $class_name($variables, $fail_on_invalid_names, $structure, $this->options['valid_types'], $this->options['force_defaults']); $max_identifiers_length = null;
if (isset($this->db->options['max_identifiers_length'])) {
$max_identifiers_length = $this->db->options['max_identifiers_length'];
}
$parser = new $class_name($variables, $fail_on_invalid_names, $structure,
$this->options['valid_types'], $this->options['force_defaults'],
$max_identifiers_length
);
$result = $parser->setInputFile($input_file); $result = $parser->setInputFile($input_file);
if (PEAR::isError($result)) { if (PEAR::isError($result)) {
return $result; return $result;
@ -436,7 +442,17 @@ class MDB2_Schema extends PEAR
return $result; return $result;
} }
$val =& new $class_name($this->options['fail_on_invalid_names'], $this->options['valid_types'], $this->options['force_defaults']); $max_identifiers_length = null;
if (isset($this->db->options['max_identifiers_length'])) {
$max_identifiers_length = $this->db->options['max_identifiers_length'];
}
$val = new $class_name(
$this->options['fail_on_invalid_names'],
$this->options['valid_types'],
$this->options['force_defaults'],
$max_identifiers_length
);
$database_definition = array( $database_definition = array(
'name' => $database, 'name' => $database,
@ -470,7 +486,7 @@ class MDB2_Schema extends PEAR
'initialization' => array() 'initialization' => array()
); );
$table_definition =& $database_definition['tables'][$table_name]; $table_definition = $database_definition['tables'][$table_name];
foreach ($fields as $field_name) { foreach ($fields as $field_name) {
$definition = $this->db->reverse->getTableFieldDefinition($table_name, $field_name); $definition = $this->db->reverse->getTableFieldDefinition($table_name, $field_name);
if (PEAR::isError($definition)) { if (PEAR::isError($definition)) {
@ -1455,16 +1471,17 @@ class MDB2_Schema extends PEAR
$changes['tables'] = MDB2_Schema::arrayMergeClobber($changes['tables'], $change); $changes['tables'] = MDB2_Schema::arrayMergeClobber($changes['tables'], $change);
} }
} }
}
if (!empty($previous_definition['tables']) if (!empty($previous_definition['tables'])
&& is_array($previous_definition['tables'])) { && is_array($previous_definition['tables'])
foreach ($previous_definition['tables'] as $table_name => $table) { ) {
if (empty($defined_tables[$table_name])) { foreach ($previous_definition['tables'] as $table_name => $table) {
$changes['tables']['remove'][$table_name] = true; if (empty($defined_tables[$table_name])) {
} $changes['tables']['remove'][$table_name] = true;
} }
} }
} }
if (!empty($current_definition['sequences']) && is_array($current_definition['sequences'])) { if (!empty($current_definition['sequences']) && is_array($current_definition['sequences'])) {
$changes['sequences'] = $defined_sequences = array(); $changes['sequences'] = $defined_sequences = array();
foreach ($current_definition['sequences'] as $sequence_name => $sequence) { foreach ($current_definition['sequences'] as $sequence_name => $sequence) {
@ -1484,14 +1501,17 @@ class MDB2_Schema extends PEAR
$changes['sequences'] = MDB2_Schema::arrayMergeClobber($changes['sequences'], $change); $changes['sequences'] = MDB2_Schema::arrayMergeClobber($changes['sequences'], $change);
} }
} }
if (!empty($previous_definition['sequences']) && is_array($previous_definition['sequences'])) { }
foreach ($previous_definition['sequences'] as $sequence_name => $sequence) { if (!empty($previous_definition['sequences'])
if (empty($defined_sequences[$sequence_name])) { && is_array($previous_definition['sequences'])
$changes['sequences']['remove'][$sequence_name] = true; ) {
} foreach ($previous_definition['sequences'] as $sequence_name => $sequence) {
if (empty($defined_sequences[$sequence_name])) {
$changes['sequences']['remove'][$sequence_name] = true;
} }
} }
} }
return $changes; return $changes;
} }
@ -2022,9 +2042,10 @@ class MDB2_Schema extends PEAR
} }
} }
if ($this->options['drop_missing_tables'] if ($this->options['drop_obsolete_objects']
&& !empty($changes['remove']) && !empty($changes['remove'])
&& is_array($changes['remove'])) { && is_array($changes['remove'])
) {
foreach ($changes['remove'] as $table_name => $table) { foreach ($changes['remove'] as $table_name => $table) {
$result = $this->db->manager->dropTable($table_name); $result = $this->db->manager->dropTable($table_name);
if (PEAR::isError($result)) { if (PEAR::isError($result)) {
@ -2105,7 +2126,10 @@ class MDB2_Schema extends PEAR
} }
} }
if (!empty($changes['remove']) && is_array($changes['remove'])) { if ($this->options['drop_obsolete_objects']
&& !empty($changes['remove'])
&& is_array($changes['remove'])
) {
foreach ($changes['remove'] as $sequence_name => $sequence) { foreach ($changes['remove'] as $sequence_name => $sequence) {
$result = $this->db->manager->dropSequence($sequence_name); $result = $this->db->manager->dropSequence($sequence_name);
if (PEAR::isError($result)) { if (PEAR::isError($result)) {
@ -2232,7 +2256,7 @@ class MDB2_Schema extends PEAR
} }
if (!empty($changes['tables']['remove']) && is_array($changes['tables']['remove'])) { if (!empty($changes['tables']['remove']) && is_array($changes['tables']['remove'])) {
if ($this->options['drop_missing_tables']) { if ($this->options['drop_obsolete_objects']) {
foreach ($changes['tables']['remove'] as $table_name => $table) { foreach ($changes['tables']['remove'] as $table_name => $table) {
$this->db->debug("$table_name:", __FUNCTION__); $this->db->debug("$table_name:", __FUNCTION__);
$this->db->debug("\tRemoved table '$table_name'", __FUNCTION__); $this->db->debug("\tRemoved table '$table_name'", __FUNCTION__);
@ -2338,9 +2362,15 @@ class MDB2_Schema extends PEAR
} }
} }
if (!empty($changes['sequences']['remove']) && is_array($changes['sequences']['remove'])) { if (!empty($changes['sequences']['remove']) && is_array($changes['sequences']['remove'])) {
foreach ($changes['sequences']['remove'] as $sequence_name => $sequence) { if ($this->options['drop_obsolete_objects']) {
$this->db->debug("$sequence_name:", __FUNCTION__); foreach ($changes['sequences']['remove'] as $sequence_name => $sequence) {
$this->db->debug("\tAdded sequence '$sequence_name'", __FUNCTION__); $this->db->debug("$sequence_name:", __FUNCTION__);
$this->db->debug("\tRemoved sequence '$sequence_name'", __FUNCTION__);
}
} else {
foreach ($changes['sequences']['remove'] as $sequence_name => $sequence) {
$this->db->debug("\tObsolete sequence '$sequence_name' left as is", __FUNCTION__);
}
} }
} }
if (!empty($changes['sequences']['change']) && is_array($changes['sequences']['change'])) { if (!empty($changes['sequences']['change']) && is_array($changes['sequences']['change'])) {
@ -2448,7 +2478,7 @@ class MDB2_Schema extends PEAR
} }
} }
$writer =& new $class_name($this->options['valid_types']); $writer = new $class_name($this->options['valid_types']);
return $writer->dumpDatabase($database_definition, $arguments, $dump); return $writer->dumpDatabase($database_definition, $arguments, $dump);
} }
@ -2696,9 +2726,9 @@ class MDB2_Schema extends PEAR
* @access public * @access public
* @see PEAR_Error * @see PEAR_Error
*/ */
function &raiseError($code = null, $mode = null, $options = null, $userinfo = null) static function &raiseError($code = null, $mode = null, $options = null, $userinfo = null, $dummy1 = null, $dummy2 = null, $dummy3 = false)
{ {
$err =& PEAR::raiseError(null, $code, $mode, $options, $err = PEAR::raiseError(null, $code, $mode, $options,
$userinfo, 'MDB2_Schema_Error', true); $userinfo, 'MDB2_Schema_Error', true);
return $err; return $err;
} }
@ -2717,7 +2747,7 @@ class MDB2_Schema extends PEAR
* @return bool true if parameter is an error * @return bool true if parameter is an error
* @access public * @access public
*/ */
function isError($data, $code = null) static function isError($data, $code = null)
{ {
if (is_a($data, 'MDB2_Schema_Error')) { if (is_a($data, 'MDB2_Schema_Error')) {
if (is_null($code)) { if (is_null($code)) {
@ -2764,4 +2794,3 @@ class MDB2_Schema_Error extends PEAR_Error
$mode, $level, $debuginfo); $mode, $level, $debuginfo);
} }
} }
?>

View File

@ -1,8 +1,6 @@
<?php <?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
/** /**
* PHP versions 4 and 5 * Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
*
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali * Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved. * All rights reserved.
* *
@ -39,21 +37,17 @@
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* Author: Christian Dickmann <dickmann@php.net> * PHP version 5
* Author: Igor Feghali <ifeghali@php.net>
*
* $Id: Parser.php,v 1.68 2008/11/30 03:34:00 clockwerx Exp $
* *
* @category Database * @category Database
* @package MDB2_Schema * @package MDB2_Schema
* @author Christian Dickmann <dickmann@php.net> * @author Christian Dickmann <dickmann@php.net>
* @author Igor Feghali <ifeghali@php.net> * @author Igor Feghali <ifeghali@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php * @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id: Parser.php,v 1.68 2008/11/30 03:34:00 clockwerx Exp $ * @version SVN: $Id$
* @link http://pear.php.net/packages/MDB2_Schema * @link http://pear.php.net/packages/MDB2_Schema
*/ */
require_once 'XML/Parser.php'; require_once 'XML/Parser.php';
require_once 'MDB2/Schema/Validate.php'; require_once 'MDB2/Schema/Validate.php';
@ -114,27 +108,83 @@ class MDB2_Schema_Parser extends XML_Parser
var $val; var $val;
/**
* PHP 5 constructor
*
* @param array $variables mixed array with user defined schema
* variables
* @param bool $fail_on_invalid_names array with reserved words per RDBMS
* @param array $structure multi dimensional array with
* database schema and data
* @param array $valid_types information of all valid fields
* types
* @param bool $force_defaults if true sets a default value to
* field when not explicit
* @param int $max_identifiers_length maximum allowed size for entities
* name
*
* @return void
*
* @access public
* @static
*/
function __construct($variables, $fail_on_invalid_names = true, function __construct($variables, $fail_on_invalid_names = true,
$structure = false, $valid_types = array(), $structure = false, $valid_types = array(), $force_defaults = true,
$force_defaults = true) $max_identifiers_length = null
{ ) {
// force ISO-8859-1 due to different defaults for PHP4 and PHP5 // force ISO-8859-1 due to different defaults for PHP4 and PHP5
// todo: this probably needs to be investigated some more andcleaned up // todo: this probably needs to be investigated some more andcleaned up
parent::XML_Parser('ISO-8859-1'); parent::__construct('ISO-8859-1');
$this->variables = $variables; $this->variables = $variables;
$this->structure = $structure; $this->structure = $structure;
$this->val =& new MDB2_Schema_Validate($fail_on_invalid_names, $valid_types, $force_defaults); $this->val = new MDB2_Schema_Validate(
$fail_on_invalid_names,
$valid_types,
$force_defaults,
$max_identifiers_length
);
} }
/**
* PHP 4 compatible constructor
*
* @param array $variables mixed array with user defined schema
* variables
* @param bool $fail_on_invalid_names array with reserved words per RDBMS
* @param array $structure multi dimensional array with
* database schema and data
* @param array $valid_types information of all valid fields
* types
* @param bool $force_defaults if true sets a default value to
* field when not explicit
* @param int $max_identifiers_length maximum allowed size for entities
* name
*
* @return void
*
* @access public
* @static
*/
function MDB2_Schema_Parser($variables, $fail_on_invalid_names = true, function MDB2_Schema_Parser($variables, $fail_on_invalid_names = true,
$structure = false, $valid_types = array(), $structure = false, $valid_types = array(), $force_defaults = true,
$force_defaults = true) $max_identifiers_length = null
{ ) {
$this->__construct($variables, $fail_on_invalid_names, $structure, $valid_types, $force_defaults); $this->__construct($variables, $fail_on_invalid_names, $structure, $valid_types, $force_defaults);
} }
function startHandler($xp, $element, $attribs) /**
* Triggered when reading a XML open tag <element>
*
* @param resource $xp xml parser resource
* @param string $element element name
* @param array $attribs attributes
*
* @return void
* @access private
* @static
*/
function startHandler($xp, $element, &$attribs)
{ {
if (strtolower($element) == 'variable') { if (strtolower($element) == 'variable') {
$this->var_mode = true; $this->var_mode = true;
@ -335,12 +385,21 @@ class MDB2_Schema_Parser extends XML_Parser
'start' => '', 'start' => '',
'description' => '', 'description' => '',
'comments' => '', 'comments' => '',
'on' => array('table' => '', 'field' => '')
); );
break; break;
} }
} }
/**
* Triggered when reading a XML close tag </element>
*
* @param resource $xp xml parser resource
* @param string $element element name
*
* @return void
* @access private
* @static
*/
function endHandler($xp, $element) function endHandler($xp, $element)
{ {
if (strtolower($element) == 'variable') { if (strtolower($element) == 'variable') {
@ -503,7 +562,21 @@ class MDB2_Schema_Parser extends XML_Parser
$this->element = implode('-', $this->elements); $this->element = implode('-', $this->elements);
} }
function &raiseError($msg = null, $xmlecode = 0, $xp = null, $ecode = MDB2_SCHEMA_ERROR_PARSE) /**
* Pushes a MDB2_Schema_Error into stack and returns it
*
* @param string $msg textual message
* @param int $xmlecode PHP's XML parser error code
* @param resource $xp xml parser resource
* @param int $ecode MDB2_Schema's error code
*
* @return object
* @access private
* @static
*/
static function &raiseError($msg = null, $xmlecode = 0, $xp = null, $ecode = MDB2_SCHEMA_ERROR_PARSE, $userinfo = null,
$error_class = null,
$skipmsg = false)
{ {
if (is_null($this->error)) { if (is_null($this->error)) {
$error = ''; $error = '';
@ -530,11 +603,21 @@ class MDB2_Schema_Parser extends XML_Parser
$error .= "\n"; $error .= "\n";
$this->error =& MDB2_Schema::raiseError($ecode, null, null, $error); $this->error = MDB2_Schema::raiseError($ecode, null, null, $error);
} }
return $this->error; return $this->error;
} }
/**
* Triggered when reading data in a XML element (text between tags)
*
* @param resource $xp xml parser resource
* @param string $data text
*
* @return void
* @access private
* @static
*/
function cdataHandler($xp, $data) function cdataHandler($xp, $data)
{ {
if ($this->var_mode == true) { if ($this->var_mode == true) {
@ -806,6 +889,9 @@ class MDB2_Schema_Parser extends XML_Parser
case 'database-sequence-comments': case 'database-sequence-comments':
$this->sequence['comments'] .= $data; $this->sequence['comments'] .= $data;
break; break;
case 'database-sequence-on':
$this->sequence['on'] = array('table' => '', 'field' => '');
break;
case 'database-sequence-on-table': case 'database-sequence-on-table':
$this->sequence['on']['table'] .= $data; $this->sequence['on']['table'] .= $data;
break; break;
@ -815,5 +901,3 @@ class MDB2_Schema_Parser extends XML_Parser
} }
} }
} }
?>

View File

@ -1,8 +1,6 @@
<?php <?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
/** /**
* PHP versions 4 and 5 * Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
*
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali * Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved. * All rights reserved.
* *
@ -39,13 +37,13 @@
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* Author: Igor Feghali <ifeghali@php.net> * PHP version 5
* *
* @category Database * @category Database
* @package MDB2_Schema * @package MDB2_Schema
* @author Igor Feghali <ifeghali@php.net> * @author Igor Feghali <ifeghali@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php * @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id: Parser2.php,v 1.12 2008/11/30 03:34:00 clockwerx Exp $ * @version SVN: $Id$
* @link http://pear.php.net/packages/MDB2_Schema * @link http://pear.php.net/packages/MDB2_Schema
*/ */
@ -100,8 +98,30 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
var $init = array(); var $init = array();
function __construct($variables, $fail_on_invalid_names = true, $structure = false, $valid_types = array(), $force_defaults = true) /**
{ * PHP 5 constructor
*
* @param array $variables mixed array with user defined schema
* variables
* @param bool $fail_on_invalid_names array with reserved words per RDBMS
* @param array $structure multi dimensional array with
* database schema and data
* @param array $valid_types information of all valid fields
* types
* @param bool $force_defaults if true sets a default value to
* field when not explicit
* @param int $max_identifiers_length maximum allowed size for entities
* name
*
* @return void
*
* @access public
* @static
*/
function __construct($variables, $fail_on_invalid_names = true,
$structure = false, $valid_types = array(), $force_defaults = true,
$max_identifiers_length = null
) {
// force ISO-8859-1 due to different defaults for PHP4 and PHP5 // force ISO-8859-1 due to different defaults for PHP4 and PHP5
// todo: this probably needs to be investigated some more and cleaned up // todo: this probably needs to be investigated some more and cleaned up
$this->options['encoding'] = 'ISO-8859-1'; $this->options['encoding'] = 'ISO-8859-1';
@ -119,15 +139,44 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
$this->variables = $variables; $this->variables = $variables;
$this->structure = $structure; $this->structure = $structure;
$this->val =& new MDB2_Schema_Validate($fail_on_invalid_names, $valid_types, $force_defaults); $this->val = new MDB2_Schema_Validate($fail_on_invalid_names, $valid_types, $force_defaults);
parent::XML_Unserializer($this->options); parent::XML_Unserializer($this->options);
} }
function MDB2_Schema_Parser2($variables, $fail_on_invalid_names = true, $structure = false, $valid_types = array(), $force_defaults = true) /**
{ * PHP 4 compatible constructor
*
* @param array $variables mixed array with user defined schema
* variables
* @param bool $fail_on_invalid_names array with reserved words per RDBMS
* @param array $structure multi dimensional array with
* database schema and data
* @param array $valid_types information of all valid fields
* types
* @param bool $force_defaults if true sets a default value to
* field when not explicit
* @param int $max_identifiers_length maximum allowed size for entities
* name
*
* @return void
*
* @access public
* @static
*/
function MDB2_Schema_Parser2($variables, $fail_on_invalid_names = true,
$structure = false, $valid_types = array(), $force_defaults = true,
$max_identifiers_length = null
) {
$this->__construct($variables, $fail_on_invalid_names, $structure, $valid_types, $force_defaults); $this->__construct($variables, $fail_on_invalid_names, $structure, $valid_types, $force_defaults);
} }
/**
* Main method. Parses XML Schema File.
*
* @return bool|error object
*
* @access public
*/
function parse() function parse()
{ {
$result = $this->unserialize($this->filename, true); $result = $this->unserialize($this->filename, true);
@ -140,18 +189,33 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
} }
} }
/**
* Do the necessary stuff to set the input XML schema file
*
* @param string $filename full path to schema file
*
* @return boolean MDB2_OK on success
*
* @access public
*/
function setInputFile($filename) function setInputFile($filename)
{ {
$this->filename = $filename; $this->filename = $filename;
return MDB2_OK; return MDB2_OK;
} }
function renameKey(&$arr, $oKey, $nKey) /**
{ * Enforce the default values for mandatory keys and ensure everything goes
$arr[$nKey] = &$arr[$oKey]; * always in the same order (simulates the behaviour of the original
unset($arr[$oKey]); * parser). Works at database level.
} *
* @param array $database multi dimensional array with database definition
* and data.
*
* @return bool|error MDB2_OK on success or error object
*
* @access private
*/
function fixDatabaseKeys($database) function fixDatabaseKeys($database)
{ {
$this->database_definition = array( $this->database_definition = array(
@ -204,6 +268,18 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
return MDB2_OK; return MDB2_OK;
} }
/**
* Enforce the default values for mandatory keys and ensure everything goes
* always in the same order (simulates the behaviour of the original
* parser). Works at table level.
*
* @param array $table multi dimensional array with table definition
* and data.
*
* @return bool|error MDB2_OK on success or error object
*
* @access private
*/
function fixTableKeys($table) function fixTableKeys($table)
{ {
$this->table = array( $this->table = array(
@ -279,6 +355,17 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
return MDB2_OK; return MDB2_OK;
} }
/**
* Enforce the default values for mandatory keys and ensure everything goes
* always in the same order (simulates the behaviour of the original
* parser). Works at table field level.
*
* @param array $field array with table field definition
*
* @return bool|error MDB2_OK on success or error object
*
* @access private
*/
function fixTableFieldKeys($field) function fixTableFieldKeys($field)
{ {
$this->field = array(); $this->field = array();
@ -328,6 +415,17 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
return MDB2_OK; return MDB2_OK;
} }
/**
* Enforce the default values for mandatory keys and ensure everything goes
* always in the same order (simulates the behaviour of the original
* parser). Works at table index level.
*
* @param array $index array with table index definition
*
* @return bool|error MDB2_OK on success or error object
*
* @access private
*/
function fixTableIndexKeys($index) function fixTableIndexKeys($index)
{ {
$this->index = array( $this->index = array(
@ -389,6 +487,17 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
return MDB2_OK; return MDB2_OK;
} }
/**
* Enforce the default values for mandatory keys and ensure everything goes
* always in the same order (simulates the behaviour of the original
* parser). Works at table constraint level.
*
* @param array $constraint array with table index definition
*
* @return bool|error MDB2_OK on success or error object
*
* @access private
*/
function fixTableConstraintKeys($constraint) function fixTableConstraintKeys($constraint)
{ {
$this->constraint = array( $this->constraint = array(
@ -468,6 +577,18 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
return MDB2_OK; return MDB2_OK;
} }
/**
* Enforce the default values for mandatory keys and ensure everything goes
* always in the same order (simulates the behaviour of the original
* parser). Works at table data level.
*
* @param array $element multi dimensional array with query definition
* @param string $type whether its a insert|update|delete query
*
* @return bool|error MDB2_OK on success or error object
*
* @access private
*/
function fixTableInitializationKeys($element, $type = '') function fixTableInitializationKeys($element, $type = '')
{ {
if (!empty($element['select']) && is_array($element['select'])) { if (!empty($element['select']) && is_array($element['select'])) {
@ -480,6 +601,43 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
$this->table['initialization'][] = array( 'type' => $type, 'data' => $this->init ); $this->table['initialization'][] = array( 'type' => $type, 'data' => $this->init );
} }
/**
* Enforce the default values for mandatory keys and ensure everything goes
* always in the same order (simulates the behaviour of the original
* parser). Works deeper at the table initialization level (data). At this
* point we are look at one of the below:
*
* <insert>
* {field}+
* </insert>
*
* <select> (this is a select extracted off a insert-select query)
* <table/>
* {field}+
* <where>
* {expression}
* </where>?
* </select>
*
* <update>
* {field}+
* <where>
* {expression}
* </where>?
* </update>
*
* <delete>
* <where>
* {expression}
* </where>
* </delete>
*
* @param array $element multi dimensional array with query definition
*
* @return bool|error MDB2_OK on success or error object
*
* @access private
*/
function fixTableInitializationDataKeys($element) function fixTableInitializationDataKeys($element)
{ {
$this->init = array(); $this->init = array();
@ -505,6 +663,22 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
} }
} }
/**
* Recursively diggs into an "expression" element. According to our
* documentation an "expression" element is of the kind:
*
* <expression>
* <null/> or <value/> or <column/> or {function} or {expression}
* <operator/>
* <null/> or <value/> or <column/> or {function} or {expression}
* </expression>
*
* @param array &$arr reference to current element definition
*
* @return void
*
* @access private
*/
function setExpression(&$arr) function setExpression(&$arr)
{ {
$element = each($arr); $element = each($arr);
@ -555,6 +729,30 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
} }
} }
/**
* Enforce the default values for mandatory keys and ensure everything goes
* always in the same order (simulates the behaviour of the original
* parser). Works at database sequences level. A "sequence" element looks
* like:
*
* <sequence>
* <name/>
* <was/>?
* <start/>?
* <description/>?
* <comments/>?
* <on>
* <table/>
* <field/>
* </on>?
* </sequence>
*
* @param array $sequence multi dimensional array with sequence definition
*
* @return bool|error MDB2_OK on success or error object
*
* @access private
*/
function fixSequenceKeys($sequence) function fixSequenceKeys($sequence)
{ {
$this->sequence = array( $this->sequence = array(
@ -562,7 +760,6 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
'start' => '', 'start' => '',
'description' => '', 'description' => '',
'comments' => '', 'comments' => '',
'on' => array('table' => '', 'field' => '')
); );
if (!empty($sequence['name'])) { if (!empty($sequence['name'])) {
@ -610,15 +807,23 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
return MDB2_OK; return MDB2_OK;
} }
/**
* Pushes a MDB2_Schema_Error into stack and returns it
*
* @param string $msg textual message
* @param int $ecode MDB2_Schema's error code
*
* @return object
* @access private
* @static
*/
function &raiseError($msg = null, $ecode = MDB2_SCHEMA_ERROR_PARSE) function &raiseError($msg = null, $ecode = MDB2_SCHEMA_ERROR_PARSE)
{ {
if (is_null($this->error)) { if (is_null($this->error)) {
$error = 'Parser error: '.$msg."\n"; $error = 'Parser error: '.$msg."\n";
$this->error =& MDB2_Schema::raiseError($ecode, null, null, $error); $this->error = MDB2_Schema::raiseError($ecode, null, null, $error);
} }
return $this->error; return $this->error;
} }
} }
?>

View File

@ -1,49 +1,51 @@
<?php <?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
// {{{ Disclaimer, Licence, copyrights /**
// +----------------------------------------------------------------------+ * Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
// | PHP versions 4 and 5 | * Stig. S. Bakken, Lukas Smith, Igor Feghali
// +----------------------------------------------------------------------+ * All rights reserved.
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, | *
// | Stig. S. Bakken, Lukas Smith | * MDB2_Schema enables users to maintain RDBMS independant schema files
// | All rights reserved. | * in XML that can be used to manipulate both data and database schemas
// +----------------------------------------------------------------------+ * This LICENSE is in the BSD license style.
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | *
// | API as well as database abstraction for PHP applications. | * Redistribution and use in source and binary forms, with or without
// | This LICENSE is in the BSD license style. | * modification, are permitted provided that the following conditions
// | | * are met:
// | Redistribution and use in source and binary forms, with or without | *
// | modification, are permitted provided that the following conditions | * Redistributions of source code must retain the above copyright
// | are met: | * notice, this list of conditions and the following disclaimer.
// | | *
// | Redistributions of source code must retain the above copyright | * Redistributions in binary form must reproduce the above copyright
// | notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer in the
// | | * documentation and/or other materials provided with the distribution.
// | Redistributions in binary form must reproduce the above copyright | *
// | notice, this list of conditions and the following disclaimer in the | * Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
// | documentation and/or other materials provided with the distribution. | * Lukas Smith, Igor Feghali nor the names of his contributors may be
// | | * used to endorse or promote products derived from this software
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | * without specific prior written permission.
// | Lukas Smith nor the names of his contributors may be used to endorse | *
// | or promote products derived from this software without specific prior| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// | written permission. | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | * POSSIBILITY OF SUCH DAMAGE.
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| *
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | * PHP version 5
// | POSSIBILITY OF SUCH DAMAGE. | *
// +----------------------------------------------------------------------+ * @category Database
// | Author: Lorenzo Alberton <l.alberton@quipo.it> | * @package MDB2_Schema
// +----------------------------------------------------------------------+ * @author Lorenzo Alberton <l.alberton@quipo.it>
// * @license BSD http://www.opensource.org/licenses/bsd-license.php
// }}} * @version SVN: $Id$
* @link http://pear.php.net/packages/MDB2_Schema
*/
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['ibase'] // {{{ $GLOBALS['_MDB2_Schema_Reserved']['ibase']
/** /**
* Has a list of reserved words of Interbase/Firebird * Has a list of reserved words of Interbase/Firebird
@ -433,4 +435,3 @@ $GLOBALS['_MDB2_Schema_Reserved']['ibase'] = array(
'ZONE', 'ZONE',
); );
// }}} // }}}
?>

View File

@ -1,48 +1,52 @@
<?php <?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
// {{{ Disclaimer, Licence, copyrights /**
// +----------------------------------------------------------------------+ * Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
// | PHP versions 4 and 5 | * Stig. S. Bakken, Lukas Smith, Igor Feghali
// +----------------------------------------------------------------------+ * All rights reserved.
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, | *
// | Stig. S. Bakken, Lukas Smith | * MDB2_Schema enables users to maintain RDBMS independant schema files
// | All rights reserved. | * in XML that can be used to manipulate both data and database schemas
// +----------------------------------------------------------------------+ * This LICENSE is in the BSD license style.
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | *
// | API as well as database abstraction for PHP applications. | * Redistribution and use in source and binary forms, with or without
// | This LICENSE is in the BSD license style. | * modification, are permitted provided that the following conditions
// | | * are met:
// | Redistribution and use in source and binary forms, with or without | *
// | modification, are permitted provided that the following conditions | * Redistributions of source code must retain the above copyright
// | are met: | * notice, this list of conditions and the following disclaimer.
// | | *
// | Redistributions of source code must retain the above copyright | * Redistributions in binary form must reproduce the above copyright
// | notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer in the
// | | * documentation and/or other materials provided with the distribution.
// | Redistributions in binary form must reproduce the above copyright | *
// | notice, this list of conditions and the following disclaimer in the | * Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
// | documentation and/or other materials provided with the distribution. | * Lukas Smith, Igor Feghali nor the names of his contributors may be
// | | * used to endorse or promote products derived from this software
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | * without specific prior written permission.
// | Lukas Smith nor the names of his contributors may be used to endorse | *
// | or promote products derived from this software without specific prior| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// | written permission. | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | * POSSIBILITY OF SUCH DAMAGE.
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| *
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | * PHP version 5
// | POSSIBILITY OF SUCH DAMAGE. | *
// +----------------------------------------------------------------------+ * @category Database
// | Author: David Coallier <davidc@php.net> | * @package MDB2_Schema
// +----------------------------------------------------------------------+ * @author David Coallier <davidc@php.net>
// }}} * @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version SVN: $Id$
* @link http://pear.php.net/packages/MDB2_Schema
*/
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['mssql'] // {{{ $GLOBALS['_MDB2_Schema_Reserved']['mssql']
/** /**
* Has a list of all the reserved words for mssql. * Has a list of all the reserved words for mssql.
@ -254,5 +258,3 @@ $GLOBALS['_MDB2_Schema_Reserved']['mssql'] = array(
'SELECT', 'SELECT',
); );
//}}} //}}}
?>

View File

@ -1,50 +1,52 @@
<?php <?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
// {{{ Disclaimer, Licence, copyrights /**
// +----------------------------------------------------------------------+ * Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
// | PHP versions 4 and 5 | * Stig. S. Bakken, Lukas Smith, Igor Feghali
// +----------------------------------------------------------------------+ * All rights reserved.
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, | *
// | Stig. S. Bakken, Lukas Smith | * MDB2_Schema enables users to maintain RDBMS independant schema files
// | All rights reserved. | * in XML that can be used to manipulate both data and database schemas
// +----------------------------------------------------------------------+ * This LICENSE is in the BSD license style.
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | *
// | API as well as database abstraction for PHP applications. | * Redistribution and use in source and binary forms, with or without
// | This LICENSE is in the BSD license style. | * modification, are permitted provided that the following conditions
// | | * are met:
// | Redistribution and use in source and binary forms, with or without | *
// | modification, are permitted provided that the following conditions | * Redistributions of source code must retain the above copyright
// | are met: | * notice, this list of conditions and the following disclaimer.
// | | *
// | Redistributions of source code must retain the above copyright | * Redistributions in binary form must reproduce the above copyright
// | notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer in the
// | | * documentation and/or other materials provided with the distribution.
// | Redistributions in binary form must reproduce the above copyright | *
// | notice, this list of conditions and the following disclaimer in the | * Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
// | documentation and/or other materials provided with the distribution. | * Lukas Smith, Igor Feghali nor the names of his contributors may be
// | | * used to endorse or promote products derived from this software
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | * without specific prior written permission.
// | Lukas Smith nor the names of his contributors may be used to endorse | *
// | or promote products derived from this software without specific prior| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// | written permission. | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | * POSSIBILITY OF SUCH DAMAGE.
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| *
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | * PHP version 5
// | POSSIBILITY OF SUCH DAMAGE. | *
// +----------------------------------------------------------------------+ * @category Database
// | Author: David Coallier <davidc@php.net> | * @package MDB2_Schema
// +----------------------------------------------------------------------+ * @author David Coallier <davidc@php.net>
// * @license BSD http://www.opensource.org/licenses/bsd-license.php
// $Id: mysql.php,v 1.3 2006/03/01 12:16:40 lsmith Exp $ * @version SVN: $Id$
// }}} * @link http://pear.php.net/packages/MDB2_Schema
*/
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['mysql'] // {{{ $GLOBALS['_MDB2_Schema_Reserved']['mysql']
/** /**
* Has a list of reserved words of mysql * Has a list of reserved words of mysql
@ -281,4 +283,3 @@ $GLOBALS['_MDB2_Schema_Reserved']['mysql'] = array(
'ZEROFILL', 'ZEROFILL',
); );
// }}} // }}}
?>

View File

@ -1,48 +1,52 @@
<?php <?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
// {{{ Disclaimer, Licence, copyrights /**
// +----------------------------------------------------------------------+ * Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
// | PHP versions 4 and 5 | * Stig. S. Bakken, Lukas Smith, Igor Feghali
// +----------------------------------------------------------------------+ * All rights reserved.
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, | *
// | Stig. S. Bakken, Lukas Smith | * MDB2_Schema enables users to maintain RDBMS independant schema files
// | All rights reserved. | * in XML that can be used to manipulate both data and database schemas
// +----------------------------------------------------------------------+ * This LICENSE is in the BSD license style.
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | *
// | API as well as database abstraction for PHP applications. | * Redistribution and use in source and binary forms, with or without
// | This LICENSE is in the BSD license style. | * modification, are permitted provided that the following conditions
// | | * are met:
// | Redistribution and use in source and binary forms, with or without | *
// | modification, are permitted provided that the following conditions | * Redistributions of source code must retain the above copyright
// | are met: | * notice, this list of conditions and the following disclaimer.
// | | *
// | Redistributions of source code must retain the above copyright | * Redistributions in binary form must reproduce the above copyright
// | notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer in the
// | | * documentation and/or other materials provided with the distribution.
// | Redistributions in binary form must reproduce the above copyright | *
// | notice, this list of conditions and the following disclaimer in the | * Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
// | documentation and/or other materials provided with the distribution. | * Lukas Smith, Igor Feghali nor the names of his contributors may be
// | | * used to endorse or promote products derived from this software
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | * without specific prior written permission.
// | Lukas Smith nor the names of his contributors may be used to endorse | *
// | or promote products derived from this software without specific prior| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// | written permission. | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | * POSSIBILITY OF SUCH DAMAGE.
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| *
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | * PHP version 5
// | POSSIBILITY OF SUCH DAMAGE. | *
// +----------------------------------------------------------------------+ * @category Database
// | Author: David Coallier <davidc@php.net> | * @package MDB2_Schema
// +----------------------------------------------------------------------+ * @author David Coallier <davidc@php.net>
// }}} * @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version SVN: $Id$
* @link http://pear.php.net/packages/MDB2_Schema
*/
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['oci8'] // {{{ $GLOBALS['_MDB2_Schema_Reserved']['oci8']
/** /**
* Has a list of all the reserved words for oracle. * Has a list of all the reserved words for oracle.
@ -167,5 +171,3 @@ $GLOBALS['_MDB2_Schema_Reserved']['oci8'] = array(
'WITH', 'WITH',
); );
// }}} // }}}
?>

View File

@ -1,49 +1,52 @@
<?php <?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
// {{{ Disclaimer, Licence, copyrights /**
// +----------------------------------------------------------------------+ * Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
// | PHP versions 4 and 5 | * Stig. S. Bakken, Lukas Smith, Igor Feghali
// +----------------------------------------------------------------------+ * All rights reserved.
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, | *
// | Stig. S. Bakken, Lukas Smith | * MDB2_Schema enables users to maintain RDBMS independant schema files
// | All rights reserved. | * in XML that can be used to manipulate both data and database schemas
// +----------------------------------------------------------------------+ * This LICENSE is in the BSD license style.
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | *
// | API as well as database abstraction for PHP applications. | * Redistribution and use in source and binary forms, with or without
// | This LICENSE is in the BSD license style. | * modification, are permitted provided that the following conditions
// | | * are met:
// | Redistribution and use in source and binary forms, with or without | *
// | modification, are permitted provided that the following conditions | * Redistributions of source code must retain the above copyright
// | are met: | * notice, this list of conditions and the following disclaimer.
// | | *
// | Redistributions of source code must retain the above copyright | * Redistributions in binary form must reproduce the above copyright
// | notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer in the
// | | * documentation and/or other materials provided with the distribution.
// | Redistributions in binary form must reproduce the above copyright | *
// | notice, this list of conditions and the following disclaimer in the | * Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
// | documentation and/or other materials provided with the distribution. | * Lukas Smith, Igor Feghali nor the names of his contributors may be
// | | * used to endorse or promote products derived from this software
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | * without specific prior written permission.
// | Lukas Smith nor the names of his contributors may be used to endorse | *
// | or promote products derived from this software without specific prior| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// | written permission. | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | * POSSIBILITY OF SUCH DAMAGE.
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| *
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | * PHP version 5
// | POSSIBILITY OF SUCH DAMAGE. | *
// +----------------------------------------------------------------------+ * @category Database
// | Author: Marcelo Santos Araujo <msaraujo@php.net> | * @package MDB2_Schema
// +----------------------------------------------------------------------+ * @author Marcelo Santos Araujo <msaraujo@php.net>
// * @license BSD http://www.opensource.org/licenses/bsd-license.php
// }}} * @version SVN: $Id$
* @link http://pear.php.net/packages/MDB2_Schema
*/
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['pgsql'] // {{{ $GLOBALS['_MDB2_Schema_Reserved']['pgsql']
/** /**
* Has a list of reserved words of pgsql * Has a list of reserved words of pgsql
@ -143,5 +146,3 @@ $GLOBALS['_MDB2_Schema_Reserved']['pgsql'] = array(
'WHERE' 'WHERE'
); );
// }}} // }}}
?>

View File

@ -1,8 +1,6 @@
<?php <?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
/** /**
* PHP versions 4 and 5 * Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
*
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali * Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved. * All rights reserved.
* *
@ -39,14 +37,13 @@
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* Author: Christian Weiske <cweiske@php.net> * PHP version 5
* $Id: Tool.php,v 1.6 2008/12/13 00:26:07 clockwerx Exp $
* *
* @category Database * @category Database
* @package MDB2_Schema * @package MDB2_Schema
* @author Christian Weiske <cweiske@php.net> * @author Christian Weiske <cweiske@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php * @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id: Tool.php,v 1.6 2008/12/13 00:26:07 clockwerx Exp $ * @version SVN: $Id$
* @link http://pear.php.net/packages/MDB2_Schema * @link http://pear.php.net/packages/MDB2_Schema
*/ */
@ -152,7 +149,9 @@ class MDB2_Schema_Tool
case '--init': case '--init':
return 'init'; return 'init';
default: default:
throw new MDB2_Schema_Tool_ParameterException("Unknown mode \"$arg\""); throw new MDB2_Schema_Tool_ParameterException(
"Unknown mode \"$arg\""
);
} }
}//protected function getAction(&$args) }//protected function getAction(&$args)
@ -179,7 +178,8 @@ class MDB2_Schema_Tool
*/ */
protected function doHelp() protected function doHelp()
{ {
self::toStdErr(<<<EOH self::toStdErr(
<<<EOH
Usage: mdb2_schematool mode parameters Usage: mdb2_schematool mode parameters
Works with database schemas Works with database schemas
@ -205,7 +205,8 @@ EOH
*/ */
protected function doHelpDump() protected function doHelpDump()
{ {
self::toStdErr( <<<EOH self::toStdErr(
<<<EOH
Usage: mdb2_schematool dump [all|data|schema] [-p] DSN Usage: mdb2_schematool dump [all|data|schema] [-p] DSN
Dumps a database schema to stdout Dumps a database schema to stdout
@ -216,7 +217,8 @@ DSN: Data source name in the form of
driver://user:password@host/database driver://user:password@host/database
User and password may be omitted. User and password may be omitted.
Using -p reads password from stdin which is more secure than passing it in the parameter. Using -p reads password from stdin which is more secure than passing it in the
parameter.
EOH EOH
); );
@ -231,7 +233,8 @@ EOH
*/ */
protected function doHelpInit() protected function doHelpInit()
{ {
self::toStdErr( <<<EOH self::toStdErr(
<<<EOH
Usage: mdb2_schematool init source [-p] destination Usage: mdb2_schematool init source [-p] destination
Initializes a database with data Initializes a database with data
@ -244,7 +247,8 @@ DSN: Data source name in the form of
driver://user:password@host/database driver://user:password@host/database
User and password may be omitted. User and password may be omitted.
Using -p reads password from stdin which is more secure than passing it in the parameter. Using -p reads password from stdin which is more secure than passing it in the
parameter.
EOH EOH
); );
@ -259,7 +263,8 @@ EOH
*/ */
protected function doHelpLoad() protected function doHelpLoad()
{ {
self::toStdErr( <<<EOH self::toStdErr(
<<<EOH
Usage: mdb2_schematool load [-p] source [-p] destination Usage: mdb2_schematool load [-p] source [-p] destination
Loads a database schema from source to destination Loads a database schema from source to destination
@ -272,7 +277,8 @@ DSN: Data source name in the form of
driver://user:password@host/database driver://user:password@host/database
User and password may be omitted. User and password may be omitted.
Using -p reads password from stdin which is more secure than passing it in the parameter. Using -p reads password from stdin which is more secure than passing it in the
parameter.
EOH EOH
); );
@ -334,7 +340,9 @@ EOH
protected function getFileOrDsn(&$args) protected function getFileOrDsn(&$args)
{ {
if (count($args) == 0) { if (count($args) == 0) {
throw new MDB2_Schema_Tool_ParameterException('File or DSN expected'); throw new MDB2_Schema_Tool_ParameterException(
'File or DSN expected'
);
} }
$arg = array_shift($args); $arg = array_shift($args);
@ -450,7 +458,8 @@ EOH
list($type, $dsn) = $this->getFileOrDsn($args); list($type, $dsn) = $this->getFileOrDsn($args);
if ($type == 'file') { if ($type == 'file') {
throw new MDB2_Schema_Tool_ParameterException( throw new MDB2_Schema_Tool_ParameterException(
'Dumping a schema file as a schema file does not make much sense' 'Dumping a schema file as a schema file does not make much ' .
'sense'
); );
} }
@ -503,8 +512,14 @@ EOH
$definition = $schemaDest->parseDatabaseDefinitionFile($dsnSource); $definition = $schemaDest->parseDatabaseDefinitionFile($dsnSource);
$where = 'loading schema file'; $where = 'loading schema file';
} else { } else {
$schemaSource = MDB2_Schema::factory($dsnSource, $this->getSchemaOptions()); $schemaSource = MDB2_Schema::factory(
$this->throwExceptionOnError($schemaSource, 'connecting to source database'); $dsnSource,
$this->getSchemaOptions()
);
$this->throwExceptionOnError(
$schemaSource,
'connecting to source database'
);
$definition = $schemaSource->getDefinitionFromDatabase(); $definition = $schemaSource->getDefinitionFromDatabase();
$where = 'loading definition from database'; $where = 'loading definition from database';
@ -514,7 +529,11 @@ EOH
//create destination database from definition //create destination database from definition
$simulate = false; $simulate = false;
$op = $schemaDest->createDatabase($definition, array(), $simulate); $op = $schemaDest->createDatabase(
$definition,
array(),
$simulate
);
$this->throwExceptionOnError($op, 'creating the database'); $this->throwExceptionOnError($op, 'creating the database');
}//protected function doLoad($args) }//protected function doLoad($args)
@ -545,10 +564,16 @@ EOH
} }
$schemaDest = MDB2_Schema::factory($dsnDest, $this->getSchemaOptions()); $schemaDest = MDB2_Schema::factory($dsnDest, $this->getSchemaOptions());
$this->throwExceptionOnError($schemaDest, 'connecting to destination database'); $this->throwExceptionOnError(
$schemaDest,
'connecting to destination database'
);
$definition = $schemaDest->getDefinitionFromDatabase(); $definition = $schemaDest->getDefinitionFromDatabase();
$this->throwExceptionOnError($definition, 'loading definition from database'); $this->throwExceptionOnError(
$definition,
'loading definition from database'
);
$op = $schemaDest->writeInitialization($dsnSource, $definition); $op = $schemaDest->writeInitialization($dsnSource, $definition);
$this->throwExceptionOnError($op, 'initializing database'); $this->throwExceptionOnError($op, 'initializing database');
@ -556,5 +581,3 @@ EOH
}//class MDB2_Schema_Tool }//class MDB2_Schema_Tool
?>

View File

@ -1,6 +1,61 @@
<?php <?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
/**
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved.
*
* MDB2_Schema enables users to maintain RDBMS independant schema files
* in XML that can be used to manipulate both data and database schemas
* This LICENSE is in the BSD license style.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
* Lukas Smith, Igor Feghali nor the names of his contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* PHP version 5
*
* @category Database
* @package MDB2_Schema
* @author Christian Weiske <cweiske@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version SVN: $Id$
* @link http://pear.php.net/packages/MDB2_Schema
*/
/**
* To be implemented yet
*
* @category Database
* @package MDB2_Schema
* @author Christian Weiske <cweiske@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @link http://pear.php.net/packages/MDB2_Schema
*/
class MDB2_Schema_Tool_ParameterException extends Exception class MDB2_Schema_Tool_ParameterException extends Exception
{} {
}
?>

View File

@ -1,8 +1,6 @@
<?php <?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
/** /**
* PHP versions 4 and 5 * Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
*
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali * Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved. * All rights reserved.
* *
@ -39,15 +37,14 @@
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* Author: Christian Dickmann <dickmann@php.net> * PHP version 5
* Author: Igor Feghali <ifeghali@php.net>
* *
* @category Database * @category Database
* @package MDB2_Schema * @package MDB2_Schema
* @author Christian Dickmann <dickmann@php.net> * @author Christian Dickmann <dickmann@php.net>
* @author Igor Feghali <ifeghali@php.net> * @author Igor Feghali <ifeghali@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php * @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id: Validate.php,v 1.42 2008/11/30 03:34:00 clockwerx Exp $ * @version SVN: $Id$
* @link http://pear.php.net/packages/MDB2_Schema * @link http://pear.php.net/packages/MDB2_Schema
*/ */
@ -70,11 +67,30 @@ class MDB2_Schema_Validate
var $force_defaults = true; var $force_defaults = true;
var $max_identifiers_length = null;
// }}} // }}}
// {{{ constructor // {{{ constructor
function __construct($fail_on_invalid_names = true, $valid_types = array(), $force_defaults = true) /**
{ * PHP 5 constructor
*
* @param bool $fail_on_invalid_names array with reserved words per RDBMS
* @param array $valid_types information of all valid fields
* types
* @param bool $force_defaults if true sets a default value to
* field when not explicit
* @param int $max_identifiers_length maximum allowed size for entities
* name
*
* @return void
*
* @access public
* @static
*/
function __construct($fail_on_invalid_names = true, $valid_types = array(),
$force_defaults = true, $max_identifiers_length = null
) {
if (empty($GLOBALS['_MDB2_Schema_Reserved'])) { if (empty($GLOBALS['_MDB2_Schema_Reserved'])) {
$GLOBALS['_MDB2_Schema_Reserved'] = array(); $GLOBALS['_MDB2_Schema_Reserved'] = array();
} }
@ -87,21 +103,49 @@ class MDB2_Schema_Validate
} else { } else {
$this->fail_on_invalid_names = array(); $this->fail_on_invalid_names = array();
} }
$this->valid_types = $valid_types; $this->valid_types = $valid_types;
$this->force_defaults = $force_defaults; $this->force_defaults = $force_defaults;
$this->max_identifiers_length = $max_identifiers_length;
} }
function MDB2_Schema_Validate($fail_on_invalid_names = true, $valid_types = array(), $force_defaults = true) /**
{ * PHP 4 compatible constructor
*
* @param bool $fail_on_invalid_names array with reserved words per RDBMS
* @param array $valid_types information of all valid fields
* types
* @param bool $force_defaults if true sets a default value to
* field when not explicit
* @param int $max_identifiers_length maximum allowed size for entities
* name
*
* @return void
*
* @access public
* @static
*/
function MDB2_Schema_Validate($fail_on_invalid_names = true, $valid_types = array(),
$force_defaults = true, $max_identifiers_length = null
) {
$this->__construct($fail_on_invalid_names, $valid_types, $force_defaults); $this->__construct($fail_on_invalid_names, $valid_types, $force_defaults);
} }
// }}} // }}}
// {{{ raiseError() // {{{ raiseError()
/**
* Pushes a MDB2_Schema_Error into stack and returns it
*
* @param int $ecode MDB2_Schema's error code
* @param string $msg textual message
*
* @return object
* @access private
* @static
*/
function &raiseError($ecode, $msg = null) function &raiseError($ecode, $msg = null)
{ {
$error =& MDB2_Schema::raiseError($ecode, null, null, $msg); $error = MDB2_Schema::raiseError($ecode, null, null, $msg);
return $error; return $error;
} }
@ -176,27 +220,18 @@ class MDB2_Schema_Validate
*/ */
function validateTable($tables, &$table, $table_name) function validateTable($tables, &$table, $table_name)
{ {
/* Have we got a name? */
if (!$table_name) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'a table has to have a name');
}
/* Table name duplicated? */ /* Table name duplicated? */
if (is_array($tables) && isset($tables[$table_name])) { if (is_array($tables) && isset($tables[$table_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'table "'.$table_name.'" already exists'); 'table "'.$table_name.'" already exists');
} }
/* Table name reserved? */ /**
if (is_array($this->fail_on_invalid_names)) { * Valid name ?
$name = strtoupper($table_name); */
foreach ($this->fail_on_invalid_names as $rdbms) { $result = $this->validateIdentifier($table_name, 'table');
if (in_array($name, $GLOBALS['_MDB2_Schema_Reserved'][$rdbms])) { if (PEAR::isError($result)) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, return $result;
'table name "'.$table_name.'" is a reserved word in: '.$rdbms);
}
}
} }
/* Was */ /* Was */
@ -289,10 +324,12 @@ class MDB2_Schema_Validate
*/ */
function validateField($fields, &$field, $field_name) function validateField($fields, &$field, $field_name)
{ {
/* Have we got a name? */ /**
if (!$field_name) { * Valid name ?
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, */
'field name missing'); $result = $this->validateIdentifier($field_name, 'field');
if (PEAR::isError($result)) {
return $result;
} }
/* Field name duplicated? */ /* Field name duplicated? */
@ -301,17 +338,6 @@ class MDB2_Schema_Validate
'field "'.$field_name.'" already exists'); 'field "'.$field_name.'" already exists');
} }
/* Field name reserverd? */
if (is_array($this->fail_on_invalid_names)) {
$name = strtoupper($field_name);
foreach ($this->fail_on_invalid_names as $rdbms) {
if (in_array($name, $GLOBALS['_MDB2_Schema_Reserved'][$rdbms])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'field name "'.$field_name.'" is a reserved word in: '.$rdbms);
}
}
}
/* Type check */ /* Type check */
if (empty($field['type'])) { if (empty($field['type'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
@ -422,10 +448,14 @@ class MDB2_Schema_Validate
*/ */
function validateIndex($table_indexes, &$index, $index_name) function validateIndex($table_indexes, &$index, $index_name)
{ {
if (!$index_name) { /**
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, * Valid name ?
'an index has to have a name'); */
$result = $this->validateIdentifier($index_name, 'index');
if (PEAR::isError($result)) {
return $result;
} }
if (is_array($table_indexes) && isset($table_indexes[$index_name])) { if (is_array($table_indexes) && isset($table_indexes[$index_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'index "'.$index_name.'" already exists'); 'index "'.$index_name.'" already exists');
@ -470,14 +500,18 @@ class MDB2_Schema_Validate
*/ */
function validateIndexField($index_fields, &$field, $field_name) function validateIndexField($index_fields, &$field, $field_name)
{ {
/**
* Valid name ?
*/
$result = $this->validateIdentifier($field_name, 'index field');
if (PEAR::isError($result)) {
return $result;
}
if (is_array($index_fields) && isset($index_fields[$field_name])) { if (is_array($index_fields) && isset($index_fields[$field_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'index field "'.$field_name.'" already exists'); 'index field "'.$field_name.'" already exists');
} }
if (!$field_name) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'the index-field-name is required');
}
if (empty($field['sorting'])) { if (empty($field['sorting'])) {
$field['sorting'] = 'ascending'; $field['sorting'] = 'ascending';
} elseif ($field['sorting'] !== 'ascending' && $field['sorting'] !== 'descending') { } elseif ($field['sorting'] !== 'ascending' && $field['sorting'] !== 'descending') {
@ -506,10 +540,14 @@ class MDB2_Schema_Validate
*/ */
function validateConstraint($table_constraints, &$constraint, $constraint_name) function validateConstraint($table_constraints, &$constraint, $constraint_name)
{ {
if (!$constraint_name) { /**
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, * Valid name ?
'a foreign key has to have a name'); */
$result = $this->validateIdentifier($constraint_name, 'foreign key');
if (PEAR::isError($result)) {
return $result;
} }
if (is_array($table_constraints) && isset($table_constraints[$constraint_name])) { if (is_array($table_constraints) && isset($table_constraints[$constraint_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'foreign key "'.$constraint_name.'" already exists'); 'foreign key "'.$constraint_name.'" already exists');
@ -555,10 +593,14 @@ class MDB2_Schema_Validate
*/ */
function validateConstraintField($constraint_fields, $field_name) function validateConstraintField($constraint_fields, $field_name)
{ {
if (!$field_name) { /**
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, * Valid name ?
'empty value for foreign-field'); */
$result = $this->validateIdentifier($field_name, 'foreign key field');
if (PEAR::isError($result)) {
return $result;
} }
if (is_array($constraint_fields) && isset($constraint_fields[$field_name])) { if (is_array($constraint_fields) && isset($constraint_fields[$field_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'foreign field "'.$field_name.'" already exists'); 'foreign field "'.$field_name.'" already exists');
@ -582,10 +624,14 @@ class MDB2_Schema_Validate
*/ */
function validateConstraintReferencedField($referenced_fields, $field_name) function validateConstraintReferencedField($referenced_fields, $field_name)
{ {
if (!$field_name) { /**
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, * Valid name ?
'empty value for referenced foreign-field'); */
$result = $this->validateIdentifier($field_name, 'referenced foreign field');
if (PEAR::isError($result)) {
return $result;
} }
if (is_array($referenced_fields) && isset($referenced_fields[$field_name])) { if (is_array($referenced_fields) && isset($referenced_fields[$field_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'foreign field "'.$field_name.'" already referenced'); 'foreign field "'.$field_name.'" already referenced');
@ -612,9 +658,12 @@ class MDB2_Schema_Validate
*/ */
function validateSequence($sequences, &$sequence, $sequence_name) function validateSequence($sequences, &$sequence, $sequence_name)
{ {
if (!$sequence_name) { /**
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, * Valid name ?
'a sequence has to have a name'); */
$result = $this->validateIdentifier($sequence_name, 'sequence');
if (PEAR::isError($result)) {
return $result;
} }
if (is_array($sequences) && isset($sequences[$sequence_name])) { if (is_array($sequences) && isset($sequences[$sequence_name])) {
@ -661,21 +710,17 @@ class MDB2_Schema_Validate
*/ */
function validateDatabase(&$database) function validateDatabase(&$database)
{ {
/* Have we got a name? */ if (!is_array($database)) {
if (!is_array($database) || !isset($database['name']) || !$database['name']) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'a database has to have a name'); 'something wrong went with database definition');
} }
/* Database name reserved? */ /**
if (is_array($this->fail_on_invalid_names)) { * Valid name ?
$name = strtoupper($database['name']); */
foreach ($this->fail_on_invalid_names as $rdbms) { $result = $this->validateIdentifier($database['name'], 'database');
if (in_array($name, $GLOBALS['_MDB2_Schema_Reserved'][$rdbms])) { if (PEAR::isError($result)) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, return $result;
'database name "'.$database['name'].'" is a reserved word in: '.$rdbms);
}
}
} }
/* Create */ /* Create */
@ -798,9 +843,12 @@ class MDB2_Schema_Validate
*/ */
function validateDataField($table_fields, $instruction_fields, &$field) function validateDataField($table_fields, $instruction_fields, &$field)
{ {
if (!$field['name']) { /**
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, * Valid name ?
'field-name has to be specified'); */
$result = $this->validateIdentifier($field['name'], 'field');
if (PEAR::isError($result)) {
return $result;
} }
if (is_array($instruction_fields) && isset($instruction_fields[$field['name']])) { if (is_array($instruction_fields) && isset($instruction_fields[$field['name']])) {
@ -917,6 +965,62 @@ class MDB2_Schema_Validate
} }
return MDB2_OK; return MDB2_OK;
} }
}
?> // }}}
// {{{ validateIdentifier()
/**
* Checks whether a given identifier is valid for current driver.
*
* @param string $id identifier to check
* @param string $type whether identifier represents a table name, index, etc.
*
* @return bool|error object
*
* @access public
*/
function validateIdentifier($id, $type)
{
$max_length = $this->max_identifiers_length;
$cur_length = strlen($id);
/**
* Have we got a name?
*/
if (!$id) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
"a $type has to have a name");
}
/**
* Supported length ?
*/
if ($max_length !== null
&& $cur_length > $max_length
) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
"$type name '$id' is too long for current driver");
} elseif ($cur_length > 30) {
// FIXME: find a way to issue a warning in MDB2_Schema object
/* $this->warnings[] = "$type name '$id' might not be
portable to other drivers"; */
}
/**
* Reserved ?
*/
if (is_array($this->fail_on_invalid_names)) {
$name = strtoupper($id);
foreach ($this->fail_on_invalid_names as $rdbms) {
if (in_array($name, $GLOBALS['_MDB2_Schema_Reserved'][$rdbms])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
"$type name '$id' is a reserved word in: $rdbms");
}
}
}
return MDB2_OK;
}
// }}}
}

View File

@ -1,8 +1,6 @@
<?php <?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
/** /**
* PHP versions 4 and 5 * Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
*
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali * Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved. * All rights reserved.
* *
@ -39,15 +37,14 @@
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* Author: Lukas Smith <smith@pooteeweet.org> * PHP version 5
* Author: Igor Feghali <ifeghali@php.net>
* *
* @category Database * @category Database
* @package MDB2_Schema * @package MDB2_Schema
* @author Lukas Smith <smith@pooteeweet.org> * @author Lukas Smith <smith@pooteeweet.org>
* @author Igor Feghali <ifeghali@php.net> * @author Igor Feghali <ifeghali@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php * @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id: Writer.php,v 1.40 2008/11/30 03:34:00 clockwerx Exp $ * @version SVN: $Id$
* @link http://pear.php.net/packages/MDB2_Schema * @link http://pear.php.net/packages/MDB2_Schema
*/ */
@ -69,11 +66,33 @@ class MDB2_Schema_Writer
// }}} // }}}
// {{{ constructor // {{{ constructor
/**
* PHP 5 constructor
*
* @param array $valid_types information of all valid fields
* types
*
* @return void
*
* @access public
* @static
*/
function __construct($valid_types = array()) function __construct($valid_types = array())
{ {
$this->valid_types = $valid_types; $this->valid_types = $valid_types;
} }
/**
* PHP 4 compatible constructor
*
* @param array $valid_types information of all valid fields
* types
*
* @return void
*
* @access public
* @static
*/
function MDB2_Schema_Writer($valid_types = array()) function MDB2_Schema_Writer($valid_types = array())
{ {
$this->__construct($valid_types); $this->__construct($valid_types);
@ -87,15 +106,18 @@ class MDB2_Schema_Writer
* callbacks etc. Basically a wrapper for PEAR::raiseError * callbacks etc. Basically a wrapper for PEAR::raiseError
* without the message string. * without the message string.
* *
* @param int|PEAR_Error $code integer error code or and PEAR_Error instance * @param int|PEAR_Error $code integer error code or and PEAR_Error
* @param int $mode error mode, see PEAR_Error docs * instance
* error level (E_USER_NOTICE etc). If error mode is * @param int $mode error mode, see PEAR_Error docs error
* PEAR_ERROR_CALLBACK, this is the callback function, * level (E_USER_NOTICE etc). If error mode
* either as a function name, or as an array of an * is PEAR_ERROR_CALLBACK, this is the
* object and method name. For other error modes this * callback function, either as a function
* parameter is ignored. * name, or as an array of an object and
* @param string $options Extra debug information. Defaults to the last * method name. For other error modes this
* query and native error code. * parameter is ignored.
* @param string $options Extra debug information. Defaults to the
* last query and native error code.
* @param string $userinfo User-friendly error message
* *
* @return object a PEAR error object * @return object a PEAR error object
* @access public * @access public
@ -103,7 +125,7 @@ class MDB2_Schema_Writer
*/ */
function &raiseError($code = null, $mode = null, $options = null, $userinfo = null) function &raiseError($code = null, $mode = null, $options = null, $userinfo = null)
{ {
$error =& MDB2_Schema::raiseError($code, $mode, $options, $userinfo); $error = MDB2_Schema::raiseError($code, $mode, $options, $userinfo);
return $error; return $error;
} }
@ -578,4 +600,3 @@ class MDB2_Schema_Writer
// }}} // }}}
} }
?>

10
3rdparty/PEAR.php vendored
View File

@ -247,7 +247,7 @@ class PEAR
* @access public * @access public
* @return bool true if parameter is an error * @return bool true if parameter is an error
*/ */
function isError($data, $code = null) static function isError($data, $code = null)
{ {
if (!is_a($data, 'PEAR_Error')) { if (!is_a($data, 'PEAR_Error')) {
return false; return false;
@ -469,7 +469,7 @@ class PEAR
* @see PEAR::setErrorHandling * @see PEAR::setErrorHandling
* @since PHP 4.0.5 * @since PHP 4.0.5
*/ */
function &raiseError($message = null, static function &raiseError($message = null,
$code = null, $code = null,
$mode = null, $mode = null,
$options = null, $options = null,
@ -555,11 +555,11 @@ class PEAR
function &throwError($message = null, $code = null, $userinfo = null) function &throwError($message = null, $code = null, $userinfo = null)
{ {
if (isset($this) && is_a($this, 'PEAR')) { if (isset($this) && is_a($this, 'PEAR')) {
$a = &$this->raiseError($message, $code, null, null, $userinfo); $a = $this->raiseError($message, $code, null, null, $userinfo);
return $a; return $a;
} }
$a = &PEAR::raiseError($message, $code, null, null, $userinfo); $a = PEAR::raiseError($message, $code, null, null, $userinfo);
return $a; return $a;
} }
@ -695,7 +695,7 @@ class PEAR
* @param string $ext The extension name * @param string $ext The extension name
* @return bool Success or not on the dl() call * @return bool Success or not on the dl() call
*/ */
function loadExtension($ext) static function loadExtension($ext)
{ {
if (extension_loaded($ext)) { if (extension_loaded($ext)) {
return true; return true;

View File

@ -144,7 +144,7 @@ class PEAR_Autoloader extends PEAR
$include_file = preg_replace('/[^a-z0-9]/i', '_', $classname); $include_file = preg_replace('/[^a-z0-9]/i', '_', $classname);
include_once $include_file; include_once $include_file;
} }
$obj =& new $classname; $obj = new $classname;
$methods = get_class_methods($classname); $methods = get_class_methods($classname);
foreach ($methods as $method) { foreach ($methods as $method) {
// don't import priviate methods and constructors // don't import priviate methods and constructors

View File

@ -133,8 +133,8 @@ class PEAR_Command
$a = PEAR::raiseError("unknown command `$command'"); $a = PEAR::raiseError("unknown command `$command'");
return $a; return $a;
} }
$ui =& PEAR_Command::getFrontendObject(); $ui = PEAR_Command::getFrontendObject();
$obj = &new $class($ui, $config); $obj = new $class($ui, $config);
return $obj; return $obj;
} }
@ -149,7 +149,7 @@ class PEAR_Command
if (!class_exists($class)) { if (!class_exists($class)) {
return PEAR::raiseError("unknown command `$command'"); return PEAR::raiseError("unknown command `$command'");
} }
$ui =& PEAR_Command::getFrontendObject(); $ui = PEAR_Command::getFrontendObject();
$config = &PEAR_Config::singleton(); $config = &PEAR_Config::singleton();
$obj = &new $class($ui, $config); $obj = &new $class($ui, $config);
return $obj; return $obj;

View File

@ -168,7 +168,7 @@ class PEAR_Common extends PEAR
function PEAR_Common() function PEAR_Common()
{ {
parent::PEAR(); parent::PEAR();
$this->config = &PEAR_Config::singleton(); $this->config = PEAR_Config::singleton();
$this->debug = $this->config->get('verbose'); $this->debug = $this->config->get('verbose');
} }

View File

@ -109,7 +109,7 @@ class PEAR_PackageFile_Generator_v1
// }}} // }}}
$packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, 'package.xml', true); $packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, 'package.xml', true);
if ($packagexml) { if ($packagexml) {
$tar =& new Archive_Tar($dest_package, $compress); $tar = new Archive_Tar($dest_package, $compress);
$tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors $tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors
// ----- Creates with the package.xml file // ----- Creates with the package.xml file
$ok = $tar->createModify(array($packagexml), '', $where); $ok = $tar->createModify(array($packagexml), '', $where);

View File

@ -269,7 +269,7 @@ http://pear.php.net/dtd/package-2.0.xsd',
$name = $pf1 !== null ? 'package2.xml' : 'package.xml'; $name = $pf1 !== null ? 'package2.xml' : 'package.xml';
$packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, $name); $packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, $name);
if ($packagexml) { if ($packagexml) {
$tar =& new Archive_Tar($dest_package, $compress); $tar = new Archive_Tar($dest_package, $compress);
$tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors $tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors
// ----- Creates with the package.xml file // ----- Creates with the package.xml file
$ok = $tar->createModify(array($packagexml), '', $where); $ok = $tar->createModify(array($packagexml), '', $where);

View File

@ -191,26 +191,6 @@ class XML_Parser extends PEAR
*/ */
var $_validEncodings = array('ISO-8859-1', 'UTF-8', 'US-ASCII'); var $_validEncodings = array('ISO-8859-1', 'UTF-8', 'US-ASCII');
// }}}
// {{{ php4 constructor
/**
* Creates an XML parser.
*
* This is needed for PHP4 compatibility, it will
* call the constructor, when a new instance is created.
*
* @param string $srcenc source charset encoding, use NULL (default) to use
* whatever the document specifies
* @param string $mode how this parser object should work, "event" for
* startelement/endelement-type events, "func"
* to have it call functions named after elements
* @param string $tgtenc a valid target encoding
*/
function XML_Parser($srcenc = null, $mode = 'event', $tgtenc = null)
{
XML_Parser::__construct($srcenc, $mode, $tgtenc);
}
// }}} // }}}
// {{{ php5 constructor // {{{ php5 constructor
@ -364,7 +344,7 @@ class XML_Parser extends PEAR
} }
$this->parser = $xp; $this->parser = $xp;
$result = $this->_initHandlers($this->mode); $result = $this->_initHandlers($this->mode);
if ($this->isError($result)) { if (PEAR::isError($result)) {
return $result; return $result;
} }
xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, $this->folding); xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, $this->folding);
@ -393,7 +373,7 @@ class XML_Parser extends PEAR
function reset() function reset()
{ {
$result = $this->_create(); $result = $this->_create();
if ($this->isError($result)) { if (PEAR::isError($result)) {
return $result; return $result;
} }
return true; return true;
@ -505,7 +485,7 @@ class XML_Parser extends PEAR
* reset the parser * reset the parser
*/ */
$result = $this->reset(); $result = $this->reset();
if ($this->isError($result)) { if (PEAR::isError($result)) {
return $result; return $result;
} }
// if $this->fp was fopened previously // if $this->fp was fopened previously
@ -610,10 +590,16 @@ class XML_Parser extends PEAR
* *
* @return XML_Parser_Error reference to the error object * @return XML_Parser_Error reference to the error object
**/ **/
function &raiseError($msg = null, $ecode = 0) static function &raiseError($message = null,
$code = 0,
$mode = null,
$options = null,
$userinfo = null,
$error_class = null,
$skipmsg = false)
{ {
$msg = !is_null($msg) ? $msg : $this->parser; $msg = !is_null($msg) ? $msg : $this->parser;
$err = &new XML_Parser_Error($msg, $ecode); $err = new XML_Parser_Error($msg, $ecode);
return parent::raiseError($err); return parent::raiseError($err);
} }