48require_once 
'MDB2/Driver/Manager/Common.php';
 
   78        $query = 
"CREATE DATABASE $name";
 
  104        $query = 
"DROP DATABASE $name";
 
  162        $options_strings = array();
 
  165            $options_strings[
'comment'] = 
'COMMENT = '.$db->quote(
$options[
'comment'], 
'text');
 
  169            $options_strings[
'charset'] = 
'DEFAULT CHARACTER SET '.$options[
'charset'];
 
  171                $options_strings[
'charset'].= 
' COLLATE '.$options[
'collate'];
 
  178        } elseif ($db->options[
'default_table_type']) {
 
  179            $type = $db->options[
'default_table_type'];
 
  182            $options_strings[] = 
"ENGINE = $type";
 
  185        if (!empty($options_strings)) {
 
  186            $query .= 
' '.implode(
' ', $options_strings);
 
  206        $options_strings = array();
 
  209            $options_strings[
'comment'] = 
'COMMENT = '.$db->quote(
$options[
'comment'], 
'text');
 
  213            $options_strings[
'charset'] = 
'DEFAULT CHARACTER SET '.$options[
'charset'];
 
  215                $options_strings[
'charset'].= 
' COLLATE '.$options[
'collate'];
 
  222        } elseif ($db->options[
'default_table_type']) {
 
  223            $type = $db->options[
'default_table_type'];
 
  226            $options_strings[] = 
"ENGINE = $type";
 
  229        if (!empty($options_strings)) {
 
  230            $query .= 
' '.implode(
' ', $options_strings);
 
  336        foreach ($changes as $change_name => $change) {
 
  337            switch ($change_name) {
 
  346                    'change type "'.$change_name.
'" not yet supported', __FUNCTION__);
 
  355        if (!empty($changes[
'name'])) {
 
  356            $change_name = $db->quoteIdentifier($changes[
'name'], 
true);
 
  357            $query .= 
'RENAME TO ' . $change_name;
 
  360        if (!empty($changes[
'add']) && is_array($changes[
'add'])) {
 
  361            foreach ($changes[
'add'] as $field_name => $field) {
 
  365                $query.= 
'ADD ' . $db->getDeclaration($field[
'type'], $field_name, $field);
 
  369        if (!empty($changes[
'remove']) && is_array($changes[
'remove'])) {
 
  370            foreach ($changes[
'remove'] as $field_name => $field) {
 
  374                $field_name = $db->quoteIdentifier($field_name, 
true);
 
  375                $query.= 
'DROP ' . $field_name;
 
  380        if (!empty($changes[
'rename']) && is_array($changes[
'rename'])) {
 
  381            foreach ($changes[
'rename'] as $field_name => $field) {
 
  382                $rename[$field[
'name']] = $field_name;
 
  386        if (!empty($changes[
'change']) && is_array($changes[
'change'])) {
 
  387            foreach ($changes[
'change'] as $field_name => $field) {
 
  391                if (isset($rename[$field_name])) {
 
  392                    $old_field_name = $rename[$field_name];
 
  393                    unset($rename[$field_name]);
 
  395                    $old_field_name = $field_name;
 
  397                $old_field_name = $db->quoteIdentifier($old_field_name, 
true);
 
  398                $query.= 
"CHANGE $old_field_name " . $db->getDeclaration($field[
'definition'][
'type'], $field_name, $field[
'definition']);
 
  402        if (!empty($rename) && is_array($rename)) {
 
  403            foreach ($rename as $rename_name => $renamed_field) {
 
  407                $field = $changes[
'rename'][$renamed_field];
 
  408                $renamed_field = $db->quoteIdentifier($renamed_field, 
true);
 
  409                $query.= 
'CHANGE ' . $renamed_field . 
' ' . $db->getDeclaration($field[
'definition'][
'type'], $field[
'name'], $field[
'definition']);
 
  418        return $db->exec(
"ALTER TABLE $name $query");
 
  437        $result = $db->queryCol(
'SHOW DATABASES');
 
  442            $result = array_map(($db->options[
'field_case'] == CASE_LOWER ? 
'strtolower' : 
'strtoupper'), 
$result);
 
  463        return $db->queryCol(
'SELECT DISTINCT USER FROM mysql.USER');
 
  482        $query = 
"SELECT name FROM mysql.proc";
 
  493            $result = array_map(($db->options[
'field_case'] == CASE_LOWER ? 
'strtolower' : 
'strtoupper'), 
$result);
 
  525            $result = array_map(($db->options[
'field_case'] == CASE_LOWER ? 
'strtolower' : 
'strtoupper'), 
$result);
 
  547        $query = 
"SHOW /*!50002 FULL*/ TABLES";
 
  548        if (!is_null($database)) {
 
  549            $query .= 
" FROM $database";
 
  551        $query.= 
"/*!50002  WHERE Table_type = 'BASE TABLE'*/";
 
  559        foreach ($table_names as 
$table) {
 
  565            $result = array_map(($db->options[
'field_case'] == CASE_LOWER ? 
'strtolower' : 
'strtoupper'), 
$result);
 
  587        $query = 
'SHOW FULL TABLES';
 
  588        if (!is_null($database)) {
 
  589            $query.= 
" FROM $database";
 
  591        $query.= 
" WHERE Table_type = 'VIEW'";
 
  599            $result = array_map(($db->options[
'field_case'] == CASE_LOWER ? 
'strtolower' : 
'strtoupper'), 
$result);
 
  622        $result = $db->queryCol(
"SHOW COLUMNS FROM $table");
 
  627            $result = array_map(($db->options[
'field_case'] == CASE_LOWER ? 
'strtolower' : 
'strtoupper'), 
$result);
 
  677        $name = $db->quoteIdentifier($db->getIndexName(
$name), 
true);
 
  678        $query = 
"CREATE INDEX $name ON $table";
 
  680        foreach ($definition[
'fields'] as $field => $fieldinfo) {
 
  681            if (!empty($fieldinfo[
'length'])) {
 
  682                $fields[] = $db->quoteIdentifier($field, 
true) . 
'(' . $fieldinfo[
'length'] . 
')';
 
  684                $fields[] = $db->quoteIdentifier($field, 
true);
 
  687        $query .= 
' ('. implode(
', ', $fields) . 
')';
 
  710        $name = $db->quoteIdentifier($db->getIndexName(
$name), 
true);
 
  711        return $db->exec(
"DROP INDEX $name ON $table");
 
  731        $key_name = 
'Key_name';
 
  732        $non_unique = 
'Non_unique';
 
  734            if ($db->options[
'field_case'] == CASE_LOWER) {
 
  735                $key_name = strtolower($key_name);
 
  736                $non_unique = strtolower($non_unique);
 
  738                $key_name = strtoupper($key_name);
 
  739                $non_unique = strtoupper($non_unique);
 
  744        $query = 
"SHOW INDEX FROM $table";
 
  751        foreach ($indexes as $index_data) {
 
  758            $result = array_change_key_case(
$result, $db->options[
'field_case']);
 
  796        $name = $db->quoteIdentifier($db->getIndexName(
$name), 
true);
 
  797        if (!empty($definition[
'primary'])) {
 
  800        } elseif (!empty($definition[
'unique'])) {
 
  805                'invalid definition, could not create constraint', __FUNCTION__);
 
  809        $query = 
"ALTER TABLE $table ADD $type $name";
 
  811        foreach (array_keys($definition[
'fields']) as $field) {
 
  812            $fields[] = $db->quoteIdentifier($field, 
true);
 
  814        $query .= 
' ('. implode(
', ', $fields) . 
')';
 
  838        if ($primary || strtolower(
$name) == 
'primary') {
 
  839            $query = 
"ALTER TABLE $table DROP PRIMARY KEY";
 
  841            $name = $db->quoteIdentifier($db->getIndexName(
$name), 
true);
 
  842            $query = 
"ALTER TABLE $table DROP INDEX $name";
 
  864        $key_name = 
'Key_name';
 
  865        $non_unique = 
'Non_unique';
 
  867            if ($db->options[
'field_case'] == CASE_LOWER) {
 
  868                $key_name = strtolower($key_name);
 
  869                $non_unique = strtolower($non_unique);
 
  871                $key_name = strtoupper($key_name);
 
  872                $non_unique = strtoupper($non_unique);
 
  877        $query = 
"SHOW INDEX FROM $table";
 
  884        foreach ($indexes as $index_data) {
 
  885            if (!$index_data[$non_unique]) {
 
  886                if ($index_data[$key_name] !== 
'PRIMARY') {
 
  898            $result = array_change_key_case(
$result, $db->options[
'field_case']);
 
  928        $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), 
true);
 
  929        $seqcol_name = $db->quoteIdentifier($db->options[
'seqcol_name'], 
true);
 
  931        $options_strings = array();
 
  934            $options_strings[
'comment'] = 
'COMMENT = '.$db->quote(
$options[
'comment'], 
'text');
 
  938            $options_strings[
'charset'] = 
'DEFAULT CHARACTER SET '.$options[
'charset'];
 
  940                $options_strings[
'charset'].= 
' COLLATE '.$options[
'collate'];
 
  947        } elseif ($db->options[
'default_table_type']) {
 
  948            $type = $db->options[
'default_table_type'];
 
  951            $options_strings[] = 
"ENGINE = $type";
 
  954        if (!empty($options_strings)) {
 
  955            $query.= 
' '.implode(
' ', $options_strings);
 
  958        $query = 
"CREATE TABLE $sequence_name ($seqcol_name INT NOT NULL AUTO_INCREMENT, PRIMARY KEY ($seqcol_name))";
 
  959        if (!empty($options_strings)) {
 
  960            $query .= 
' '.implode(
' ', $options_strings);
 
  971        $query = 
"INSERT INTO $sequence_name ($seqcol_name) VALUES (".($start-1).
')';
 
  978        $result = $db->exec(
"DROP TABLE $sequence_name");
 
  980            return $db->raiseError(
$result, 
null, 
null,
 
  981                'could not drop inconsistent sequence table', __FUNCTION__);
 
  984        return $db->raiseError(
$res, 
null, 
null,
 
  985            'could not create sequence table', __FUNCTION__);
 
 1005        $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), 
true);
 
 1006        return $db->exec(
"DROP TABLE $sequence_name");
 
 1027        if (!is_null($database)) {
 
 1028            $query .= 
" FROM $database";
 
 1030        $table_names = $db->queryCol(
$query);
 
 1032            return $table_names;
 
 1036        foreach ($table_names as $table_name) {
 
 1042            $result = array_map(($db->options[
'field_case'] == CASE_LOWER ? 
'strtolower' : 
'strtoupper'), 
$result);
 
const MDB2_PORTABILITY_FIX_CASE
Portability: convert names of tables and fields to case defined in the "field_case" option when using...
const MDB2_OK(!class_exists('PEAR'))
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these.
const MDB2_FETCHMODE_ORDERED
Column data indexed by numbers, ordered from 0 and up.
const MDB2_ERROR_CANNOT_ALTER
const MDB2_ERROR_NEED_MORE_DATA
const MDB2_FETCHMODE_ASSOC
Column data indexed by column names.
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
An exception for terminatinating execution or to throw for unit testing.
_fixIndexName($idx)
Removes any formatting in an index name using the 'idxname_format' option.
_getCreateTableQuery($name, $fields, $options=array())
Create a basic SQL query for a new table creation.
_fixSequenceName($sqn, $check=false)
Removes any formatting in an sequence name using the 'seqname_format' option.
getTableCreationQuery($name, $fields, $options=array())
PATCH: For Testcases Only.
listDatabases()
list all databases
createTable($name, $fields, $options=array())
create a new table
dropConstraint($table, $name, $primary=false)
drop existing constraint
createConstraint($table, $name, $definition)
create a constraint on a table
listSequences($database=null)
list all sequences in the current database
listFunctions()
list all functions in the current database
listTableConstraints($table)
list all constraints in a table
listTableTriggers($table=null)
list all triggers in the database that reference a given table
listTables($database=null)
list all tables in the current database
listTableFields($table)
list all fields in a table in the current database
dropDatabase($name)
drop an existing database
listViews($database=null)
list all views in the current database
dropIndex($table, $name)
drop existing index
createDatabase($name)
create a new database
listTableIndexes($table)
list all indexes in a table
alterTable($name, $changes, $check)
alter an existing table
dropSequence($seq_name)
drop existing sequence
createSequence($seq_name, $start=1, $options=array())
create sequence
createIndex($table, $name, $definition)
Get the stucture of a field into an array.
listUsers()
list all users
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
isError($data, $code=null)
Tell whether a value is a PEAR error.
if(empty($password)) $table
foreach($_POST as $key=> $value) $res