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
$v_att_list = &func_get_args();
$v_att_list = func_get_args();
// ----- Read the attributes
$i=0;

603
3rdparty/MDB2.php vendored

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: Date.php 208329 2006-03-01 12:15:38Z lsmith $
// $Id$
//
/**

View File

@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: Common.php 300551 2010-06-17 21:54:16Z quipo $
// $Id$
require_once 'MDB2/LOB.php';
@ -263,7 +263,11 @@ class MDB2_Driver_Datatype_Common extends MDB2_Module_Common
*/
function convertResultRow($types, $row, $rtrim = true)
{
$types = $this->_sortResultFieldTypes(array_keys($row), $types);
//$types = $this->_sortResultFieldTypes(array_keys($row), $types);
$keys = array_keys($row);
if (is_int($keys[0])) {
$types = $this->_sortResultFieldTypes($keys, $types);
}
foreach ($row as $key => $value) {
if (empty($types[$key])) {
continue;
@ -515,9 +519,6 @@ class MDB2_Driver_Datatype_Common extends MDB2_Module_Common
$default = ' DEFAULT ' . $this->quote($field['default'], $field['type']);
}
}
if (empty($default) && empty($notnull)) {
$default = ' DEFAULT NULL';
}
$collation = empty($field['collation']) ? '' :
' '.$this->_getCollationFieldDeclaration($field['collation']);
@ -1382,7 +1383,7 @@ class MDB2_Driver_Datatype_Common extends MDB2_Module_Common
if (PEAR::isError($db)) {
return $db;
}
if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
if (isset($db->function) && is_object($this->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
return $db->function->now('date');
}
return 'CURRENT_DATE';
@ -1411,7 +1412,7 @@ class MDB2_Driver_Datatype_Common extends MDB2_Module_Common
if (PEAR::isError($db)) {
return $db;
}
if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
if (isset($db->function) && is_object($this->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
return $db->function->now('timestamp');
}
return 'CURRENT_TIMESTAMP';
@ -1440,7 +1441,7 @@ class MDB2_Driver_Datatype_Common extends MDB2_Module_Common
if (PEAR::isError($db)) {
return $db;
}
if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
if (isset($db->function) && is_object($this->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
return $db->function->now('time');
}
return 'CURRENT_TIME';

View File

@ -43,7 +43,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: mysql.php 295587 2010-02-28 17:16:38Z quipo $
// $Id$
//
require_once 'MDB2/Driver/Datatype/Common.php';
@ -88,6 +88,35 @@ class MDB2_Driver_Datatype_mysql extends MDB2_Driver_Datatype_Common
return 'COLLATE '.$collation;
}
// }}}
// {{{ getDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare
* of the given type
*
* @param string $type type to which the value should be converted to
* @param string $name name the field to be declared.
* @param string $field definition of the field
*
* @return string DBMS-specific SQL code portion that should be used to
* declare the specified field.
* @access public
*/
function getDeclaration($type, $name, $field)
{
// MySQL DDL syntax forbids combining NOT NULL with DEFAULT NULL.
// To get a default of NULL for NOT NULL columns, omit it.
if ( isset($field['notnull'])
&& !empty($field['notnull'])
&& array_key_exists('default', $field) // do not use isset() here!
&& null === $field['default']
) {
unset($field['default']);
}
return parent::getDeclaration($type, $name, $field);
}
// }}}
// {{{ getTypeDeclaration()
@ -179,7 +208,15 @@ class MDB2_Driver_Datatype_mysql extends MDB2_Driver_Datatype_Common
case 'timestamp':
return 'DATETIME';
case 'float':
return 'DOUBLE';
$l = '';
if (!empty($field['length'])) {
$l = '(' . $field['length'];
if (!empty($field['scale'])) {
$l .= ',' . $field['scale'];
}
$l .= ')';
}
return 'DOUBLE' . $l;
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $db->options['decimal_places'];
@ -513,6 +550,9 @@ class MDB2_Driver_Datatype_mysql extends MDB2_Driver_Datatype_Common
case 'real':
$type[] = 'float';
$unsigned = preg_match('/ unsigned/i', $field['type']);
if ($decimal !== false) {
$length = $length.','.$decimal;
}
break;
case 'unknown':
case 'decimal':

View File

@ -42,7 +42,7 @@
// | Author: Paul Cooper <pgc@ucecom.com> |
// +----------------------------------------------------------------------+
//
// $Id: pgsql.php 298763 2010-04-29 08:49:41Z afz $
// $Id$
require_once 'MDB2/Driver/Datatype/Common.php';
@ -246,10 +246,12 @@ class MDB2_Driver_Datatype_pgsql extends MDB2_Driver_Datatype_Common
if (PEAR::isError($db)) {
return $db;
}
$value = $this->_readFile($value, $db->options['lob_allow_url_include']);
if ($db->options['lob_allow_url_include']) {
$value = $this->_readFile($value);
if (PEAR::isError($value)) {
return $value;
}
}
return $this->_quoteText($value, $quote, $escape_wildcards);
}
@ -276,10 +278,12 @@ class MDB2_Driver_Datatype_pgsql extends MDB2_Driver_Datatype_Common
if (PEAR::isError($db)) {
return $db;
}
$value = $this->_readFile($value, $db->options['lob_allow_url_include']);
if ($db->options['lob_allow_url_include']) {
$value = $this->_readFile($value);
if (PEAR::isError($value)) {
return $value;
}
}
if (version_compare(PHP_VERSION, '5.2.0RC6', '>=')) {
$connection = $db->getConnection();
if (PEAR::isError($connection)) {

View File

@ -43,7 +43,7 @@
// | 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';

View File

@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: Common.php 295587 2010-02-28 17:16:38Z quipo $
// $Id$
//
/**

View File

@ -42,7 +42,7 @@
// | 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';

View File

@ -42,7 +42,7 @@
// | 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';

View File

@ -42,7 +42,7 @@
// | 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';

View File

@ -43,7 +43,7 @@
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
// $Id: Common.php 295587 2010-02-28 17:16:38Z quipo $
// $Id$
//
/**
@ -385,7 +385,11 @@ class MDB2_Driver_Manager_Common extends MDB2_Module_Common
}
$name = $db->quoteIdentifier($name, true);
return $db->exec("DROP TABLE $name");
$result = $db->exec("DROP TABLE $name");
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -407,7 +411,11 @@ class MDB2_Driver_Manager_Common extends MDB2_Module_Common
}
$name = $db->quoteIdentifier($name, true);
return $db->exec("DELETE FROM $name");
$result = $db->exec("DELETE FROM $name");
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -761,7 +769,11 @@ class MDB2_Driver_Manager_Common extends MDB2_Module_Common
$fields[] = $db->quoteIdentifier($field, true);
}
$query .= ' ('. implode(', ', $fields) . ')';
return $db->exec($query);
$result = $db->exec($query);
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -783,7 +795,11 @@ class MDB2_Driver_Manager_Common extends MDB2_Module_Common
}
$name = $db->quoteIdentifier($db->getIndexName($name), true);
return $db->exec("DROP INDEX $name");
$result = $db->exec("DROP INDEX $name");
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -895,7 +911,11 @@ class MDB2_Driver_Manager_Common extends MDB2_Module_Common
$query .= ' ('. implode(', ', $referenced_fields) . ')';
$query .= $this->_getAdvancedFKOptions($definition);
}
return $db->exec($query);
$result = $db->exec($query);
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -919,7 +939,11 @@ class MDB2_Driver_Manager_Common extends MDB2_Module_Common
$table = $db->quoteIdentifier($table, true);
$name = $db->quoteIdentifier($db->getIndexName($name), true);
return $db->exec("ALTER TABLE $table DROP CONSTRAINT $name");
$result = $db->exec("ALTER TABLE $table DROP CONSTRAINT $name");
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}

View File

@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: mysql.php 302865 2010-08-29 10:30:55Z quipo $
// $Id$
//
require_once 'MDB2/Driver/Manager/Common.php';
@ -327,7 +327,11 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
}
$name = $db->quoteIdentifier($name, true);
return $db->exec("TRUNCATE TABLE $name");
$result = $db->exec("TRUNCATE TABLE $name");
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -374,7 +378,10 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
return $result;
}
if (!empty($options['analyze'])) {
return $db->exec('ANALYZE TABLE '.$table);
$result = $db->exec('ANALYZE TABLE '.$table);
if (MDB2::isError($result)) {
return $result;
}
}
return MDB2_OK;
}
@ -561,7 +568,11 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
}
$name = $db->quoteIdentifier($name, true);
return $db->exec("ALTER TABLE $name $query");
$result = $db->exec("ALTER TABLE $name $query");
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -832,7 +843,11 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
}
}
$query .= ' ('. implode(', ', $fields) . ')';
return $db->exec($query);
$result = $db->exec($query);
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -855,7 +870,11 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
$table = $db->quoteIdentifier($table, true);
$name = $db->quoteIdentifier($db->getIndexName($name), true);
return $db->exec("DROP INDEX $name ON $table");
$result = $db->exec("DROP INDEX $name ON $table");
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -1015,7 +1034,11 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
if ($primary || strtolower($name) == 'primary') {
$query = 'ALTER TABLE '. $db->quoteIdentifier($table, true) .' DROP PRIMARY KEY';
return $db->exec($query);
$result = $db->exec($query);
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
//is it a FK constraint? If so, also delete the associated triggers
@ -1031,13 +1054,21 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
$table = $db->quoteIdentifier($table, true);
$name = $db->quoteIdentifier($db->getIndexName($name), true);
$query = "ALTER TABLE $table DROP FOREIGN KEY $name";
return $db->exec($query);
$result = $db->exec($query);
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
$table = $db->quoteIdentifier($table, true);
$name = $db->quoteIdentifier($db->getIndexName($name), true);
$query = "ALTER TABLE $table DROP INDEX $name";
return $db->exec($query);
$result = $db->exec($query);
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -1390,7 +1421,11 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
}
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
return $db->exec("DROP TABLE $sequence_name");
$result = $db->exec("DROP TABLE $sequence_name");
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}

View File

@ -42,7 +42,7 @@
// | Author: Paul Cooper <pgc@ucecom.com> |
// +----------------------------------------------------------------------+
//
// $Id: pgsql.php 299393 2010-05-14 17:49:49Z afz $
// $Id$
require_once 'MDB2/Driver/Manager/Common.php';
@ -193,7 +193,11 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
}
$name = $db->quoteIdentifier($name, true);
return $db->exec("TRUNCATE TABLE $name");
$result = $db->exec("TRUNCATE TABLE $name");
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -234,7 +238,11 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
if (!empty($table)) {
$query .= ' '.$db->quoteIdentifier($table, true);
}
return $db->exec($query);
$result = $db->exec($query);
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -801,11 +809,19 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
}
if (in_array($name, $unique)) {
return $db->exec('DROP INDEX '.$db->quoteIdentifier($name, true));
$result = $db->exec('DROP INDEX '.$db->quoteIdentifier($name, true));
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
$idxname = $db->getIndexName($name);
if (in_array($idxname, $unique)) {
return $db->exec('DROP INDEX '.$db->quoteIdentifier($idxname, true));
$result = $db->exec('DROP INDEX '.$db->quoteIdentifier($idxname, true));
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
$name . ' is not an existing constraint for table ' . $table, __FUNCTION__);
@ -894,8 +910,12 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
}
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
return $db->exec("CREATE SEQUENCE $sequence_name INCREMENT 1".
$result = $db->exec("CREATE SEQUENCE $sequence_name INCREMENT 1".
($start < 1 ? " MINVALUE $start" : '')." START $start");
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -916,7 +936,11 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
}
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
return $db->exec("DROP SEQUENCE $sequence_name");
$result = $db->exec("DROP SEQUENCE $sequence_name");
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}

View File

@ -43,7 +43,7 @@
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
// $Id: sqlite.php 295587 2010-02-28 17:16:38Z quipo $
// $Id$
//
require_once 'MDB2/Driver/Manager/Common.php';
@ -405,7 +405,11 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
}
$name = $db->quoteIdentifier($name, true);
return $db->exec("DROP TABLE $name");
$result = $db->exec("DROP TABLE $name");
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -436,7 +440,11 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
if (!empty($table)) {
$query .= ' '.$db->quoteIdentifier($table, true);
}
return $db->exec($query);
$result = $db->exec($query);
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -964,11 +972,11 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
}
$table = $db->quoteIdentifier($table, true);
$name = $db->getIndexName($name);
$name = $db->quoteIdentifier($db->getIndexName($name), true);
$query = "CREATE INDEX $name ON $table";
$fields = array();
foreach ($definition['fields'] as $field_name => $field) {
$field_string = $field_name;
$field_string = $db->quoteIdentifier($field_name, true);
if (!empty($field['sorting'])) {
switch ($field['sorting']) {
case 'ascending':
@ -982,7 +990,11 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
$fields[] = $field_string;
}
$query .= ' ('.implode(', ', $fields) . ')';
return $db->exec($query);
$result = $db->exec($query);
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -1004,7 +1016,11 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
}
$name = $db->getIndexName($name);
return $db->exec("DROP INDEX $name");
$result = $db->exec("DROP INDEX $name");
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -1112,7 +1128,11 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
$fields[] = $field_string;
}
$query .= ' ('.implode(', ', $fields) . ')';
return $db->exec($query);
$result = $db->exec($query);
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -1152,7 +1172,11 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
}
$name = $db->getIndexName($name);
return $db->exec("DROP INDEX $name");
$result = $db->exec("DROP INDEX $name");
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}
@ -1321,7 +1345,11 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
}
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
return $db->exec("DROP TABLE $sequence_name");
$result = $db->exec("DROP TABLE $sequence_name");
if (MDB2::isError($result)) {
return $result;
}
return MDB2_OK;
}
// }}}

View File

@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: Common.php 242348 2007-09-09 13:47:36Z quipo $
// $Id$
//
/**

View File

@ -42,7 +42,7 @@
// | 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';

View File

@ -42,7 +42,7 @@
// | 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';

View File

@ -42,7 +42,7 @@
// | 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';

View File

@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: Common.php 295587 2010-02-28 17:16:38Z quipo $
// $Id$
//
/**

View File

@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: mysql.php 295587 2010-02-28 17:16:38Z quipo $
// $Id$
//
require_once 'MDB2/Driver/Reverse/Common.php';

View File

@ -43,7 +43,7 @@
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
// $Id: pgsql.php 295587 2010-02-28 17:16:38Z quipo $
// $Id$
require_once 'MDB2/Driver/Reverse/Common.php';

View File

@ -43,7 +43,7 @@
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
// $Id: sqlite.php 295587 2010-02-28 17:16:38Z quipo $
// $Id$
//
require_once 'MDB2/Driver/Reverse/Common.php';
@ -95,7 +95,7 @@ class MDB2_Driver_Reverse_sqlite extends MDB2_Driver_Reverse_Common
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'unexpected empty table column definition list', __FUNCTION__);
}
$regexp = '/^\s*([^\s]+) +(CHAR|VARCHAR|VARCHAR2|TEXT|BOOLEAN|SMALLINT|INT|INTEGER|DECIMAL|BIGINT|DOUBLE|FLOAT|DATETIME|DATE|TIME|LONGTEXT|LONGBLOB)( ?\(([1-9][0-9]*)(:([1-9][0-9]*))?\))?( NULL| NOT NULL)?( UNSIGNED)?( NULL| NOT NULL)?( PRIMARY KEY)?( DEFAULT (\'[^\']*\'|[^ ]+))?( NULL| NOT NULL)?( PRIMARY KEY)?(\s*\-\-.*)?$/i';
$regexp = '/^\s*([^\s]+) +(CHAR|VARCHAR|VARCHAR2|TEXT|BOOLEAN|SMALLINT|INT|INTEGER|DECIMAL|TINYINT|BIGINT|DOUBLE|FLOAT|DATETIME|DATE|TIME|LONGTEXT|LONGBLOB)( ?\(([1-9][0-9]*)(:([1-9][0-9]*))?\))?( NULL| NOT NULL)?( UNSIGNED)?( NULL| NOT NULL)?( PRIMARY KEY)?( DEFAULT (\'[^\']*\'|[^ ]+))?( NULL| NOT NULL)?( PRIMARY KEY)?(\s*\-\-.*)?$/i';
$regexp2 = '/^\s*([^ ]+) +(PRIMARY|UNIQUE|CHECK)$/i';
for ($i=0, $j=0; $i<$count; ++$i) {
if (!preg_match($regexp, trim($column_sql[$i]), $matches)) {
@ -128,6 +128,8 @@ class MDB2_Driver_Reverse_sqlite extends MDB2_Driver_Reverse_Common
$default = null;
}
$columns[$j]['default'] = $default;
} else {
$columns[$j]['default'] = null;
}
if (isset($matches[7]) && strlen($matches[7])) {
$columns[$j]['notnull'] = ($matches[7] === ' NOT NULL');

View File

@ -43,7 +43,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: mysql.php 302867 2010-08-29 11:22:07Z quipo $
// $Id$
//
/**
@ -57,21 +57,30 @@ class MDB2_Driver_mysql extends MDB2_Driver_Common
{
// {{{ properties
var $string_quoting = array('start' => "'", 'end' => "'", 'escape' => '\\', 'escape_pattern' => '\\');
public $string_quoting = array(
'start' => "'",
'end' => "'",
'escape' => '\\',
'escape_pattern' => '\\',
);
var $identifier_quoting = array('start' => '`', 'end' => '`', 'escape' => '`');
public $identifier_quoting = array(
'start' => '`',
'end' => '`',
'escape' => '`',
);
var $sql_comments = array(
public $sql_comments = array(
array('start' => '-- ', 'end' => "\n", 'escape' => false),
array('start' => '#', 'end' => "\n", 'escape' => false),
array('start' => '/*', 'end' => '*/', 'escape' => false),
);
var $server_capabilities_checked = false;
protected $server_capabilities_checked = false;
var $start_transaction = false;
protected $start_transaction = false;
var $varchar_max_length = 255;
protected $varchar_max_length = 255;
// }}}
// {{{ constructor
@ -1370,7 +1379,9 @@ class MDB2_Result_mysql extends MDB2_Result_Common
if ($fetchmode == MDB2_FETCHMODE_DEFAULT) {
$fetchmode = $this->db->fetchmode;
}
if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
if ( $fetchmode == MDB2_FETCHMODE_ASSOC
|| $fetchmode == MDB2_FETCHMODE_OBJECT
) {
$row = @mysql_fetch_assoc($this->result);
if (is_array($row)
&& $this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE
@ -1401,8 +1412,16 @@ class MDB2_Result_mysql extends MDB2_Result_Common
if ($mode) {
$this->db->_fixResultArrayValues($row, $mode);
}
if (!empty($this->types)) {
if ( ( $fetchmode != MDB2_FETCHMODE_ASSOC
&& $fetchmode != MDB2_FETCHMODE_OBJECT)
&& !empty($this->types)
) {
$row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim);
} elseif (($fetchmode == MDB2_FETCHMODE_ASSOC
|| $fetchmode == MDB2_FETCHMODE_OBJECT)
&& !empty($this->types_assoc)
) {
$row = $this->db->datatype->convertResultRow($this->types_assoc, $row, $rtrim);
}
if (!empty($this->values)) {
$this->_assignBindColumns($row);
@ -1600,7 +1619,7 @@ class MDB2_Statement_mysql extends MDB2_Statement_Common
* a MDB2 error on failure
* @access private
*/
function _execute($result_class = true, $result_wrap_class = false)
function _execute($result_class = true, $result_wrap_class = true)
{
if (is_null($this->statement)) {
$result = parent::_execute($result_class, $result_wrap_class);

View File

@ -43,7 +43,7 @@
// | Author: Paul Cooper <pgc@ucecom.com> |
// +----------------------------------------------------------------------+
//
// $Id: pgsql.php 295587 2010-02-28 17:16:38Z quipo $
// $Id$
/**
* MDB2 PostGreSQL driver
@ -652,7 +652,7 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
if ($is_manip) {
$result = $this->_affectedRows($connection, $result);
} else {
$result =& $this->_wrapResult($result, $types, true, false, $limit, $offset);
$result = $this->_wrapResult($result, $types, true, true, $limit, $offset);
}
}
@ -959,17 +959,18 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
$pgtypes[] = 'text';
}
}
if (($key_parameter = array_search($name, $positions))) {
$next_parameter = 1;
foreach ($positions as $key => $value) {
if ($key_parameter == $key) {
break;
}
++$next_parameter;
}
if (($key_parameter = array_search($name, $positions)) !== false) {
//$next_parameter = 1;
$parameter = $key_parameter + 1;
//foreach ($positions as $key => $value) {
// if ($key_parameter == $key) {
// break;
// }
// ++$next_parameter;
//}
} else {
++$parameter;
$next_parameter = $parameter;
//$next_parameter = $parameter;
$positions[] = $name;
}
$query = substr_replace($query, '$'.$parameter, $position, $length);
@ -1178,7 +1179,9 @@ class MDB2_Result_pgsql extends MDB2_Result_Common
if ($fetchmode == MDB2_FETCHMODE_DEFAULT) {
$fetchmode = $this->db->fetchmode;
}
if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
if ( $fetchmode == MDB2_FETCHMODE_ASSOC
|| $fetchmode == MDB2_FETCHMODE_OBJECT
) {
$row = @pg_fetch_array($this->result, null, PGSQL_ASSOC);
if (is_array($row)
&& $this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE
@ -1208,8 +1211,16 @@ class MDB2_Result_pgsql extends MDB2_Result_Common
if ($mode) {
$this->db->_fixResultArrayValues($row, $mode);
}
if (!empty($this->types)) {
if ( ( $fetchmode != MDB2_FETCHMODE_ASSOC
&& $fetchmode != MDB2_FETCHMODE_OBJECT)
&& !empty($this->types)
) {
$row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim);
} elseif (($fetchmode == MDB2_FETCHMODE_ASSOC
|| $fetchmode == MDB2_FETCHMODE_OBJECT)
&& !empty($this->types_assoc)
) {
$row = $this->db->datatype->convertResultRow($this->types_assoc, $row, $rtrim);
}
if (!empty($this->values)) {
$this->_assignBindColumns($row);
@ -1429,7 +1440,7 @@ class MDB2_Statement_pgsql extends MDB2_Statement_Common
* a MDB2 error on failure
* @access private
*/
function _execute($result_class = true, $result_wrap_class = false)
function _execute($result_class = true, $result_wrap_class = true)
{
if (null === $this->statement) {
return parent::_execute($result_class, $result_wrap_class);
@ -1544,5 +1555,29 @@ class MDB2_Statement_pgsql extends MDB2_Statement_Common
parent::free();
return $result;
}
/**
* drop an existing table
*
* @param string $name name of the table that should be dropped
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function dropTable($name)
{
$db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$name = $db->quoteIdentifier($name, true);
$result = $db->exec("DROP TABLE $name");
if (PEAR::isError($result)) {
$result = $db->exec("DROP TABLE $name CASCADE");
}
return $result;
}
}
?>

View File

@ -43,7 +43,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: sqlite.php 295587 2010-02-28 17:16:38Z quipo $
// $Id$
//
/**
@ -142,6 +142,7 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
'/is not unique/' => MDB2_ERROR_CONSTRAINT,
'/columns .* are not unique/i' => MDB2_ERROR_CONSTRAINT,
'/uniqueness constraint failed/' => MDB2_ERROR_CONSTRAINT,
'/violates .*constraint/' => MDB2_ERROR_CONSTRAINT,
'/may not be NULL/' => MDB2_ERROR_CONSTRAINT_NOT_NULL,
'/^no such column:/' => MDB2_ERROR_NOSUCHFIELD,
'/no column named/' => MDB2_ERROR_NOSUCHFIELD,
@ -893,7 +894,9 @@ class MDB2_Result_sqlite extends MDB2_Result_Common
if ($fetchmode == MDB2_FETCHMODE_DEFAULT) {
$fetchmode = $this->db->fetchmode;
}
if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
if ( $fetchmode == MDB2_FETCHMODE_ASSOC
|| $fetchmode == MDB2_FETCHMODE_OBJECT
) {
$row = @sqlite_fetch_array($this->result, SQLITE_ASSOC);
if (is_array($row)
&& $this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE
@ -923,8 +926,16 @@ class MDB2_Result_sqlite extends MDB2_Result_Common
if ($mode) {
$this->db->_fixResultArrayValues($row, $mode);
}
if (!empty($this->types)) {
if ( ( $fetchmode != MDB2_FETCHMODE_ASSOC
&& $fetchmode != MDB2_FETCHMODE_OBJECT)
&& !empty($this->types)
) {
$row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim);
} elseif (($fetchmode == MDB2_FETCHMODE_ASSOC
|| $fetchmode == MDB2_FETCHMODE_OBJECT)
&& !empty($this->types_assoc)
) {
$row = $this->db->datatype->convertResultRow($this->types_assoc, $row, $rtrim);
}
if (!empty($this->values)) {
$this->_assignBindColumns($row);

View File

@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: Extended.php 302784 2010-08-25 23:29:16Z quipo $
// $Id$
/**
* @package MDB2
@ -645,6 +645,9 @@ class MDB2_Extended extends MDB2_Module_Common
*/
function executeMultiple($stmt, $params = null)
{
if (MDB2::isError($stmt)) {
return $stmt;
}
for ($i = 0, $j = count($params); $i < $j; $i++) {
$result = $stmt->execute($params[$i]);
if (PEAR::isError($result)) {

View File

@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: Iterator.php 295586 2010-02-28 17:04:17Z quipo $
// $Id$
/**
* PHP5 Iterator
@ -54,6 +54,9 @@
class MDB2_Iterator implements Iterator
{
protected $fetchmode;
/**
* @var MDB2_Result_Common
*/
protected $result;
protected $row;
@ -62,7 +65,7 @@ class MDB2_Iterator implements Iterator
/**
* Constructor
*/
public function __construct($result, $fetchmode = MDB2_FETCHMODE_DEFAULT)
public function __construct(MDB2_Result_Common $result, $fetchmode = MDB2_FETCHMODE_DEFAULT)
{
$this->result = $result;
$this->fetchmode = $fetchmode;

View File

@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: LOB.php 222350 2006-10-25 11:52:21Z lsmith $
// $Id$
/**
* @package MDB2

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-2008 Manuel Lemos, Tomas V.V.Cox,
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved.
*
@ -39,15 +37,14 @@
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Lukas Smith <smith@pooteeweet.org>
* Author: Igor Feghali <ifeghali@php.net>
* PHP version 5
*
* @category Database
* @package MDB2_Schema
* @author Lukas Smith <smith@pooteeweet.org>
* @author Igor Feghali <ifeghali@php.net>
* @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
*/
@ -96,7 +93,7 @@ class MDB2_Schema extends PEAR
'parser' => 'MDB2_Schema_Parser',
'writer' => 'MDB2_Schema_Writer',
'validate' => 'MDB2_Schema_Validate',
'drop_missing_tables' => false
'drop_obsolete_objects' => false
);
// }}}
@ -237,9 +234,9 @@ class MDB2_Schema extends PEAR
* @access public
* @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);
if (PEAR::isError($result)) {
@ -284,14 +281,14 @@ class MDB2_Schema extends PEAR
$this->disconnect();
if (!MDB2::isConnection($db)) {
$db =& MDB2::factory($db, $db_options);
$db = MDB2::factory($db, $db_options);
}
if (PEAR::isError($db)) {
return $db;
}
$this->db =& $db;
$this->db = $db;
$this->db->loadModule('Datatype');
$this->db->loadModule('Manager');
$this->db->loadModule('Reverse');
@ -380,7 +377,7 @@ class MDB2_Schema extends PEAR
$dtd_file = $this->options['dtd_file'];
if ($dtd_file) {
include_once 'XML/DTD/XmlValidator.php';
$dtd =& new XML_DTD_XmlValidator;
$dtd = new XML_DTD_XmlValidator;
if (!$dtd->isValid($dtd_file, $input_file)) {
return $this->raiseError(MDB2_SCHEMA_ERROR_PARSE, null, null, $dtd->getMessage());
}
@ -393,7 +390,16 @@ class MDB2_Schema extends PEAR
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);
if (PEAR::isError($result)) {
return $result;
@ -436,7 +442,17 @@ class MDB2_Schema extends PEAR
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(
'name' => $database,
@ -470,7 +486,7 @@ class MDB2_Schema extends PEAR
'initialization' => array()
);
$table_definition =& $database_definition['tables'][$table_name];
$table_definition = $database_definition['tables'][$table_name];
foreach ($fields as $field_name) {
$definition = $this->db->reverse->getTableFieldDefinition($table_name, $field_name);
if (PEAR::isError($definition)) {
@ -1455,16 +1471,17 @@ class MDB2_Schema extends PEAR
$changes['tables'] = MDB2_Schema::arrayMergeClobber($changes['tables'], $change);
}
}
}
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])) {
$changes['tables']['remove'][$table_name] = true;
}
}
}
}
if (!empty($current_definition['sequences']) && is_array($current_definition['sequences'])) {
$changes['sequences'] = $defined_sequences = array();
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);
}
}
if (!empty($previous_definition['sequences']) && is_array($previous_definition['sequences'])) {
}
if (!empty($previous_definition['sequences'])
&& is_array($previous_definition['sequences'])
) {
foreach ($previous_definition['sequences'] as $sequence_name => $sequence) {
if (empty($defined_sequences[$sequence_name])) {
$changes['sequences']['remove'][$sequence_name] = true;
}
}
}
}
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'])
&& is_array($changes['remove'])) {
&& is_array($changes['remove'])
) {
foreach ($changes['remove'] as $table_name => $table) {
$result = $this->db->manager->dropTable($table_name);
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) {
$result = $this->db->manager->dropSequence($sequence_name);
if (PEAR::isError($result)) {
@ -2232,7 +2256,7 @@ class MDB2_Schema extends PEAR
}
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) {
$this->db->debug("$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 ($this->options['drop_obsolete_objects']) {
foreach ($changes['sequences']['remove'] as $sequence_name => $sequence) {
$this->db->debug("$sequence_name:", __FUNCTION__);
$this->db->debug("\tAdded sequence '$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'])) {
@ -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);
}
@ -2696,9 +2726,9 @@ class MDB2_Schema extends PEAR
* @access public
* @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);
return $err;
}
@ -2717,7 +2747,7 @@ class MDB2_Schema extends PEAR
* @return bool true if parameter is an error
* @access public
*/
function isError($data, $code = null)
static function isError($data, $code = null)
{
if (is_a($data, 'MDB2_Schema_Error')) {
if (is_null($code)) {
@ -2764,4 +2794,3 @@ class MDB2_Schema_Error extends PEAR_Error
$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-2008 Manuel Lemos, Tomas V.V.Cox,
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved.
*
@ -39,21 +37,17 @@
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Christian Dickmann <dickmann@php.net>
* Author: Igor Feghali <ifeghali@php.net>
*
* $Id: Parser.php,v 1.68 2008/11/30 03:34:00 clockwerx Exp $
* PHP version 5
*
* @category Database
* @package MDB2_Schema
* @author Christian Dickmann <dickmann@php.net>
* @author Igor Feghali <ifeghali@php.net>
* @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
*/
require_once 'XML/Parser.php';
require_once 'MDB2/Schema/Validate.php';
@ -114,27 +108,83 @@ class MDB2_Schema_Parser extends XML_Parser
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,
$structure = false, $valid_types = array(),
$force_defaults = 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
// 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->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,
$structure = false, $valid_types = array(),
$force_defaults = 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);
}
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') {
$this->var_mode = true;
@ -335,12 +385,21 @@ class MDB2_Schema_Parser extends XML_Parser
'start' => '',
'description' => '',
'comments' => '',
'on' => array('table' => '', 'field' => '')
);
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)
{
if (strtolower($element) == 'variable') {
@ -503,7 +562,21 @@ class MDB2_Schema_Parser extends XML_Parser
$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)) {
$error = '';
@ -530,11 +603,21 @@ class MDB2_Schema_Parser extends XML_Parser
$error .= "\n";
$this->error =& MDB2_Schema::raiseError($ecode, null, null, $error);
$this->error = MDB2_Schema::raiseError($ecode, null, null, $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)
{
if ($this->var_mode == true) {
@ -806,6 +889,9 @@ class MDB2_Schema_Parser extends XML_Parser
case 'database-sequence-comments':
$this->sequence['comments'] .= $data;
break;
case 'database-sequence-on':
$this->sequence['on'] = array('table' => '', 'field' => '');
break;
case 'database-sequence-on-table':
$this->sequence['on']['table'] .= $data;
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-2008 Manuel Lemos, Tomas V.V.Cox,
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved.
*
@ -39,13 +37,13 @@
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Igor Feghali <ifeghali@php.net>
* PHP version 5
*
* @category Database
* @package MDB2_Schema
* @author Igor Feghali <ifeghali@php.net>
* @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
*/
@ -100,8 +98,30 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
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
// todo: this probably needs to be investigated some more and cleaned up
$this->options['encoding'] = 'ISO-8859-1';
@ -119,15 +139,44 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
$this->variables = $variables;
$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);
}
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);
}
/**
* Main method. Parses XML Schema File.
*
* @return bool|error object
*
* @access public
*/
function parse()
{
$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)
{
$this->filename = $filename;
return MDB2_OK;
}
function renameKey(&$arr, $oKey, $nKey)
{
$arr[$nKey] = &$arr[$oKey];
unset($arr[$oKey]);
}
/**
* 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 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)
{
$this->database_definition = array(
@ -204,6 +268,18 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
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)
{
$this->table = array(
@ -279,6 +355,17 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
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)
{
$this->field = array();
@ -328,6 +415,17 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
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)
{
$this->index = array(
@ -389,6 +487,17 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
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)
{
$this->constraint = array(
@ -468,6 +577,18 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
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 = '')
{
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 );
}
/**
* 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)
{
$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)
{
$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)
{
$this->sequence = array(
@ -562,7 +760,6 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
'start' => '',
'description' => '',
'comments' => '',
'on' => array('table' => '', 'field' => '')
);
if (!empty($sequence['name'])) {
@ -610,15 +807,23 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
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)
{
if (is_null($this->error)) {
$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;
}
}
?>

View File

@ -1,49 +1,51 @@
<?php
// {{{ Disclaimer, Licence, copyrights
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | 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 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. |
// +----------------------------------------------------------------------+
// | Author: Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
// }}}
<?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 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']
/**
* Has a list of reserved words of Interbase/Firebird
@ -433,4 +435,3 @@ $GLOBALS['_MDB2_Schema_Reserved']['ibase'] = array(
'ZONE',
);
// }}}
?>

View File

@ -1,48 +1,52 @@
<?php
// {{{ Disclaimer, Licence, copyrights
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | 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 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. |
// +----------------------------------------------------------------------+
// | Author: David Coallier <davidc@php.net> |
// +----------------------------------------------------------------------+
// }}}
<?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 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']
/**
* Has a list of all the reserved words for mssql.
@ -254,5 +258,3 @@ $GLOBALS['_MDB2_Schema_Reserved']['mssql'] = array(
'SELECT',
);
//}}}
?>

View File

@ -1,50 +1,52 @@
<?php
// {{{ Disclaimer, Licence, copyrights
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | 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 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. |
// +----------------------------------------------------------------------+
// | Author: David Coallier <davidc@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: mysql.php,v 1.3 2006/03/01 12:16:40 lsmith Exp $
// }}}
<?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 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']['mysql']
/**
* Has a list of reserved words of mysql
@ -281,4 +283,3 @@ $GLOBALS['_MDB2_Schema_Reserved']['mysql'] = array(
'ZEROFILL',
);
// }}}
?>

View File

@ -1,48 +1,52 @@
<?php
// {{{ Disclaimer, Licence, copyrights
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | 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 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. |
// +----------------------------------------------------------------------+
// | Author: David Coallier <davidc@php.net> |
// +----------------------------------------------------------------------+
// }}}
<?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 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']
/**
* Has a list of all the reserved words for oracle.
@ -167,5 +171,3 @@ $GLOBALS['_MDB2_Schema_Reserved']['oci8'] = array(
'WITH',
);
// }}}
?>

View File

@ -1,49 +1,52 @@
<?php
// {{{ Disclaimer, Licence, copyrights
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | 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 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. |
// +----------------------------------------------------------------------+
// | Author: Marcelo Santos Araujo <msaraujo@php.net> |
// +----------------------------------------------------------------------+
//
// }}}
<?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 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']
/**
* Has a list of reserved words of pgsql
@ -143,5 +146,3 @@ $GLOBALS['_MDB2_Schema_Reserved']['pgsql'] = array(
'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-2008 Manuel Lemos, Tomas V.V.Cox,
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved.
*
@ -39,14 +37,13 @@
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Christian Weiske <cweiske@php.net>
* $Id: Tool.php,v 1.6 2008/12/13 00:26:07 clockwerx Exp $
* 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 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
*/
@ -152,7 +149,9 @@ class MDB2_Schema_Tool
case '--init':
return 'init';
default:
throw new MDB2_Schema_Tool_ParameterException("Unknown mode \"$arg\"");
throw new MDB2_Schema_Tool_ParameterException(
"Unknown mode \"$arg\""
);
}
}//protected function getAction(&$args)
@ -179,7 +178,8 @@ class MDB2_Schema_Tool
*/
protected function doHelp()
{
self::toStdErr(<<<EOH
self::toStdErr(
<<<EOH
Usage: mdb2_schematool mode parameters
Works with database schemas
@ -205,7 +205,8 @@ EOH
*/
protected function doHelpDump()
{
self::toStdErr( <<<EOH
self::toStdErr(
<<<EOH
Usage: mdb2_schematool dump [all|data|schema] [-p] DSN
Dumps a database schema to stdout
@ -216,7 +217,8 @@ DSN: Data source name in the form of
driver://user:password@host/database
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
);
@ -231,7 +233,8 @@ EOH
*/
protected function doHelpInit()
{
self::toStdErr( <<<EOH
self::toStdErr(
<<<EOH
Usage: mdb2_schematool init source [-p] destination
Initializes a database with data
@ -244,7 +247,8 @@ DSN: Data source name in the form of
driver://user:password@host/database
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
);
@ -259,7 +263,8 @@ EOH
*/
protected function doHelpLoad()
{
self::toStdErr( <<<EOH
self::toStdErr(
<<<EOH
Usage: mdb2_schematool load [-p] source [-p] 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
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
);
@ -334,7 +340,9 @@ EOH
protected function getFileOrDsn(&$args)
{
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);
@ -450,7 +458,8 @@ EOH
list($type, $dsn) = $this->getFileOrDsn($args);
if ($type == 'file') {
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);
$where = 'loading schema file';
} else {
$schemaSource = MDB2_Schema::factory($dsnSource, $this->getSchemaOptions());
$this->throwExceptionOnError($schemaSource, 'connecting to source database');
$schemaSource = MDB2_Schema::factory(
$dsnSource,
$this->getSchemaOptions()
);
$this->throwExceptionOnError(
$schemaSource,
'connecting to source database'
);
$definition = $schemaSource->getDefinitionFromDatabase();
$where = 'loading definition from database';
@ -514,7 +529,11 @@ EOH
//create destination database from definition
$simulate = false;
$op = $schemaDest->createDatabase($definition, array(), $simulate);
$op = $schemaDest->createDatabase(
$definition,
array(),
$simulate
);
$this->throwExceptionOnError($op, 'creating the database');
}//protected function doLoad($args)
@ -545,10 +564,16 @@ EOH
}
$schemaDest = MDB2_Schema::factory($dsnDest, $this->getSchemaOptions());
$this->throwExceptionOnError($schemaDest, 'connecting to destination database');
$this->throwExceptionOnError(
$schemaDest,
'connecting to destination database'
);
$definition = $schemaDest->getDefinitionFromDatabase();
$this->throwExceptionOnError($definition, 'loading definition from database');
$this->throwExceptionOnError(
$definition,
'loading definition from database'
);
$op = $schemaDest->writeInitialization($dsnSource, $definition);
$this->throwExceptionOnError($op, 'initializing database');
@ -556,5 +581,3 @@ EOH
}//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
{}
?>
{
}

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-2008 Manuel Lemos, Tomas V.V.Cox,
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved.
*
@ -39,15 +37,14 @@
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Christian Dickmann <dickmann@php.net>
* Author: Igor Feghali <ifeghali@php.net>
* PHP version 5
*
* @category Database
* @package MDB2_Schema
* @author Christian Dickmann <dickmann@php.net>
* @author Igor Feghali <ifeghali@php.net>
* @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
*/
@ -70,11 +67,30 @@ class MDB2_Schema_Validate
var $force_defaults = true;
var $max_identifiers_length = null;
// }}}
// {{{ 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'])) {
$GLOBALS['_MDB2_Schema_Reserved'] = array();
}
@ -89,19 +105,47 @@ class MDB2_Schema_Validate
}
$this->valid_types = $valid_types;
$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);
}
// }}}
// {{{ 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)
{
$error =& MDB2_Schema::raiseError($ecode, null, null, $msg);
$error = MDB2_Schema::raiseError($ecode, null, null, $msg);
return $error;
}
@ -176,27 +220,18 @@ class MDB2_Schema_Validate
*/
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? */
if (is_array($tables) && isset($tables[$table_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'table "'.$table_name.'" already exists');
}
/* Table name reserved? */
if (is_array($this->fail_on_invalid_names)) {
$name = strtoupper($table_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,
'table name "'.$table_name.'" is a reserved word in: '.$rdbms);
}
}
/**
* Valid name ?
*/
$result = $this->validateIdentifier($table_name, 'table');
if (PEAR::isError($result)) {
return $result;
}
/* Was */
@ -289,10 +324,12 @@ class MDB2_Schema_Validate
*/
function validateField($fields, &$field, $field_name)
{
/* Have we got a name? */
if (!$field_name) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'field name missing');
/**
* Valid name ?
*/
$result = $this->validateIdentifier($field_name, 'field');
if (PEAR::isError($result)) {
return $result;
}
/* Field name duplicated? */
@ -301,17 +338,6 @@ class MDB2_Schema_Validate
'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 */
if (empty($field['type'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
@ -422,10 +448,14 @@ class MDB2_Schema_Validate
*/
function validateIndex($table_indexes, &$index, $index_name)
{
if (!$index_name) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'an index has to have a name');
/**
* Valid name ?
*/
$result = $this->validateIdentifier($index_name, 'index');
if (PEAR::isError($result)) {
return $result;
}
if (is_array($table_indexes) && isset($table_indexes[$index_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'index "'.$index_name.'" already exists');
@ -470,14 +500,18 @@ class MDB2_Schema_Validate
*/
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])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'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'])) {
$field['sorting'] = 'ascending';
} elseif ($field['sorting'] !== 'ascending' && $field['sorting'] !== 'descending') {
@ -506,10 +540,14 @@ class MDB2_Schema_Validate
*/
function validateConstraint($table_constraints, &$constraint, $constraint_name)
{
if (!$constraint_name) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'a foreign key has to have a name');
/**
* Valid name ?
*/
$result = $this->validateIdentifier($constraint_name, 'foreign key');
if (PEAR::isError($result)) {
return $result;
}
if (is_array($table_constraints) && isset($table_constraints[$constraint_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'foreign key "'.$constraint_name.'" already exists');
@ -555,10 +593,14 @@ class MDB2_Schema_Validate
*/
function validateConstraintField($constraint_fields, $field_name)
{
if (!$field_name) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'empty value for foreign-field');
/**
* Valid name ?
*/
$result = $this->validateIdentifier($field_name, 'foreign key field');
if (PEAR::isError($result)) {
return $result;
}
if (is_array($constraint_fields) && isset($constraint_fields[$field_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'foreign field "'.$field_name.'" already exists');
@ -582,10 +624,14 @@ class MDB2_Schema_Validate
*/
function validateConstraintReferencedField($referenced_fields, $field_name)
{
if (!$field_name) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'empty value for referenced foreign-field');
/**
* Valid name ?
*/
$result = $this->validateIdentifier($field_name, 'referenced foreign field');
if (PEAR::isError($result)) {
return $result;
}
if (is_array($referenced_fields) && isset($referenced_fields[$field_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'foreign field "'.$field_name.'" already referenced');
@ -612,9 +658,12 @@ class MDB2_Schema_Validate
*/
function validateSequence($sequences, &$sequence, $sequence_name)
{
if (!$sequence_name) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'a sequence has to have a name');
/**
* Valid name ?
*/
$result = $this->validateIdentifier($sequence_name, 'sequence');
if (PEAR::isError($result)) {
return $result;
}
if (is_array($sequences) && isset($sequences[$sequence_name])) {
@ -661,21 +710,17 @@ class MDB2_Schema_Validate
*/
function validateDatabase(&$database)
{
/* Have we got a name? */
if (!is_array($database) || !isset($database['name']) || !$database['name']) {
if (!is_array($database)) {
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)) {
$name = strtoupper($database['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,
'database name "'.$database['name'].'" is a reserved word in: '.$rdbms);
}
}
/**
* Valid name ?
*/
$result = $this->validateIdentifier($database['name'], 'database');
if (PEAR::isError($result)) {
return $result;
}
/* Create */
@ -798,9 +843,12 @@ class MDB2_Schema_Validate
*/
function validateDataField($table_fields, $instruction_fields, &$field)
{
if (!$field['name']) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'field-name has to be specified');
/**
* Valid name ?
*/
$result = $this->validateIdentifier($field['name'], 'field');
if (PEAR::isError($result)) {
return $result;
}
if (is_array($instruction_fields) && isset($instruction_fields[$field['name']])) {
@ -917,6 +965,62 @@ class MDB2_Schema_Validate
}
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-2008 Manuel Lemos, Tomas V.V.Cox,
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved.
*
@ -39,15 +37,14 @@
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Lukas Smith <smith@pooteeweet.org>
* Author: Igor Feghali <ifeghali@php.net>
* PHP version 5
*
* @category Database
* @package MDB2_Schema
* @author Lukas Smith <smith@pooteeweet.org>
* @author Igor Feghali <ifeghali@php.net>
* @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
*/
@ -69,11 +66,33 @@ class MDB2_Schema_Writer
// }}}
// {{{ constructor
/**
* PHP 5 constructor
*
* @param array $valid_types information of all valid fields
* types
*
* @return void
*
* @access public
* @static
*/
function __construct($valid_types = array())
{
$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())
{
$this->__construct($valid_types);
@ -87,15 +106,18 @@ class MDB2_Schema_Writer
* callbacks etc. Basically a wrapper for PEAR::raiseError
* without the message string.
*
* @param int|PEAR_Error $code integer error code or and PEAR_Error instance
* @param int $mode error mode, see PEAR_Error docs
* error level (E_USER_NOTICE etc). If error mode is
* PEAR_ERROR_CALLBACK, this is the callback function,
* either as a function name, or as an array of an
* object and method name. For other error modes this
* @param int|PEAR_Error $code integer error code or and PEAR_Error
* instance
* @param int $mode error mode, see PEAR_Error docs error
* level (E_USER_NOTICE etc). If error mode
* is PEAR_ERROR_CALLBACK, this is the
* callback function, either as a function
* name, or as an array of an object and
* method name. For other error modes this
* parameter is ignored.
* @param string $options Extra debug information. Defaults to the last
* query and native error code.
* @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
* @access public
@ -103,7 +125,7 @@ class MDB2_Schema_Writer
*/
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;
}
@ -578,4 +600,3 @@ class MDB2_Schema_Writer
// }}}
}
?>

10
3rdparty/PEAR.php vendored
View File

@ -247,7 +247,7 @@ class PEAR
* @access public
* @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')) {
return false;
@ -469,7 +469,7 @@ class PEAR
* @see PEAR::setErrorHandling
* @since PHP 4.0.5
*/
function &raiseError($message = null,
static function &raiseError($message = null,
$code = null,
$mode = null,
$options = null,
@ -555,11 +555,11 @@ class PEAR
function &throwError($message = null, $code = null, $userinfo = null)
{
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;
}
$a = &PEAR::raiseError($message, $code, null, null, $userinfo);
$a = PEAR::raiseError($message, $code, null, null, $userinfo);
return $a;
}
@ -695,7 +695,7 @@ class PEAR
* @param string $ext The extension name
* @return bool Success or not on the dl() call
*/
function loadExtension($ext)
static function loadExtension($ext)
{
if (extension_loaded($ext)) {
return true;

View File

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

View File

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

View File

@ -168,7 +168,7 @@ class PEAR_Common extends PEAR
function PEAR_Common()
{
parent::PEAR();
$this->config = &PEAR_Config::singleton();
$this->config = PEAR_Config::singleton();
$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);
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
// ----- Creates with the package.xml file
$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';
$packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, $name);
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
// ----- Creates with the package.xml file
$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');
// }}}
// {{{ 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
@ -364,7 +344,7 @@ class XML_Parser extends PEAR
}
$this->parser = $xp;
$result = $this->_initHandlers($this->mode);
if ($this->isError($result)) {
if (PEAR::isError($result)) {
return $result;
}
xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, $this->folding);
@ -393,7 +373,7 @@ class XML_Parser extends PEAR
function reset()
{
$result = $this->_create();
if ($this->isError($result)) {
if (PEAR::isError($result)) {
return $result;
}
return true;
@ -505,7 +485,7 @@ class XML_Parser extends PEAR
* reset the parser
*/
$result = $this->reset();
if ($this->isError($result)) {
if (PEAR::isError($result)) {
return $result;
}
// if $this->fp was fopened previously
@ -610,10 +590,16 @@ class XML_Parser extends PEAR
*
* @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;
$err = &new XML_Parser_Error($msg, $ecode);
$err = new XML_Parser_Error($msg, $ecode);
return parent::raiseError($err);
}