irm-1.6-b3/MDB/Manager.php
/**
     * Create a database space within which may be created database objects
     * like tables, indexes and sequences. The implementation of this function
     * is highly DBMS specific and may require special permissions to run
     * successfully. Consult the documentation or the DBMS drivers that you
     * use to be aware of eventual configuration requirements.
     *
     * @return mixed MDB_OK on success, or a MDB error object
     * @access private
     */
Create a database space within which may be created database objects
like tables, indexes and sequences. The implementation of this function
is highly DBMS specific and may require special permissions to run
successfully. Consult the documentation or the DBMS drivers that you
use to be aware of eventual configuration requirements.

@return mixed MDB_OK on success, or a MDB error object
@access private
Create a database space within which may be created database objects like tables indexes and sequences . The implementation of this function is highly DBMS specific and may require special permissions to run successfully . Consult the documentation or the DBMS drivers that you use to be aware of eventual configuration requirements . @return mixed MDB_OK on success or a MDB error object @access private
function _createDatabase()
    {
        if(!isset($this->database_definition['name'])
            || !strcmp($this->database_definition['name'], '')
        ) {
            return($this->raiseError(MDB_ERROR_INVALID, NULL, NULL,
                'no valid database name specified'));
        }
        $create = (isset($this->database_definition['create']) && $this->database_definition['create']);
        $overwrite = (isset($this->database_definition['overwrite']) && $this->database_definition['overwrite']);
        if($create) {
            $this->database->debug('Create database: '.$this->database_definition['name']);
            $this->expectError(MDB_ERROR_ALREADY_EXISTS);
            $result = $this->database->createDatabase($this->database_definition['name']);
            $this->popExpect();
            if(MDB::isError($result)) {
                if($result->getCode() === MDB_ERROR_ALREADY_EXISTS) {
                    $this->warnings[] = 'Database already exists: '.$this->database_definition['name'];
                    if($overwrite) {
                        $this->database->debug('Overwritting Database');
                        $result = $this->database->dropDatabase($this->database_definition['name']);
                        if(MDB::isError($result)) {
                            return($result);
                        }
                        $result = $this->database->createDatabase($this->database_definition['name']);
                        if(MDB::isError($result)) {
                            return($result);
                        }
                    } else {
                        $result = MDB_OK;
                    }
                } else {
                    $this->database->debug('Create database error.');
                    return($result);
                }
            }
        }
        $previous_database_name = $this->database->setDatabase($this->database_definition['name']);
        if(($support_transactions = $this->database->support('Transactions'))
            && MDB::isError($result = $this->database->autoCommit(FALSE))
        ) {
            return($result);
        }
        $created_objects = 0;
        if(isset($this->database_definition['TABLES'])
            && is_array($this->database_definition['TABLES'])
        ) {
            foreach($this->database_definition['TABLES'] as $table_name => $table) {
                $result = $this->_createTable($table_name, $table, $overwrite);
                if(MDB::isError($result)) {
                    break;
                }
                $created_objects++;
            }
        }
        if(!MDB::isError($result) 
            && isset($this->database_definition['SEQUENCES'])
            && is_array($this->database_definition['SEQUENCES'])
        ) {
            foreach($this->database_definition['SEQUENCES'] as $sequence_name => $sequence) {
                $result = $this->_createSequence($sequence_name, $sequence, 0, $overwrite);
                if(MDB::isError($result)) {
                    break;
                }
                $created_objects++;
            }
        }
        if(MDB::isError($result)) {
            if($created_objects) {
                if($support_transactions) {
                    $res = $this->database->rollback();
                    if(MDB::isError($res))
                        $result = $this->raiseError(MDB_ERROR_MANAGER, NULL, NULL,
                            'Could not rollback the partially created database alterations ('
                            .$result->getMessage().' ('.$result->getUserinfo(),'))',
                            'MDB_Error', TRUE);
                } else {
                    $result = $this->raiseError(MDB_ERROR_MANAGER, NULL, NULL,
                        'the database was only partially created ('
                        .$result->getMessage().' ('.$result->getUserinfo(),'))',
                        'MDB_Error', TRUE);
                }
            }
        } else {
            if($support_transactions) {
                $res = $this->database->autoCommit(TRUE);
                if(MDB::isError($res))
                    $result = $this->raiseError(MDB_ERROR_MANAGER, NULL, NULL,
                        'Could not end transaction after successfully created the database ('
                        .$res->getMessage().' ('.$res->getUserinfo(),'))',
                        'MDB_Error', TRUE);
            }
        }
        $this->database->setDatabase($previous_database_name);
        if(MDB::isError($result)
            && $create
            && MDB::isError($res = $this->database->dropDatabase($this->database_definition['name']))
        ) {
            return($this->raiseError(MDB_ERROR_MANAGER, NULL, NULL,
                'Could not drop the created database after unsuccessful creation attempt ('
                .$res->getMessage().' ('.$res->getUserinfo(),'))',
                'MDB_Error', TRUE));
        }
        if(MDB::isError($result)) {
            return($result);
        }
        return(MDB_OK);
    }
function _createDatabase ( ) { if ( ! isset ( $ this -> database_definition [ 'name' ] ) || ! strcmp ( $ this -> database_definition [ 'name' ] , '' ) ) { return ( $ this -> raiseError ( MDB_ERROR_INVALID , NULL , NULL , 'no valid database name specified' ) ) ; } $ create = ( isset ( $ this -> database_definition [ 'create' ] ) && $ this -> database_definition [ 'create' ] ) ; $ overwrite = ( isset ( $ this -> database_definition [ 'overwrite' ] ) && $ this -> database_definition [ 'overwrite' ] ) ; if ( $ create ) { $ this -> database -> debug ( 'Create database: ' . $ this -> database_definition [ 'name' ] ) ; $ this -> expectError ( MDB_ERROR_ALREADY_EXISTS ) ; $ result = $ this -> database -> createDatabase ( $ this -> database_definition [ 'name' ] ) ; $ this -> popExpect ( ) ; if ( MDB :: isError ( $ result ) ) { if ( $ result -> getCode ( ) === MDB_ERROR_ALREADY_EXISTS ) { $ this -> warnings [ ] = 'Database already exists: ' . $ this -> database_definition [ 'name' ] ; if ( $ overwrite ) { $ this -> database -> debug ( 'Overwritting Database' ) ; $ result = $ this -> database -> dropDatabase ( $ this -> database_definition [ 'name' ] ) ; if ( MDB :: isError ( $ result ) ) { return ( $ result ) ; } $ result = $ this -> database -> createDatabase ( $ this -> database_definition [ 'name' ] ) ; if ( MDB :: isError ( $ result ) ) { return ( $ result ) ; } } else { $ result = MDB_OK ; } } else { $ this -> database -> debug ( 'Create database error.' ) ; return ( $ result ) ; } } } $ previous_database_name = $ this -> database -> setDatabase ( $ this -> database_definition [ 'name' ] ) ; if ( ( $ support_transactions = $ this -> database -> support ( 'Transactions' ) ) && MDB :: isError ( $ result = $ this -> database -> autoCommit ( FALSE ) ) ) { return ( $ result ) ; } $ created_objects = 0 ; if ( isset ( $ this -> database_definition [ 'TABLES' ] ) && is_array ( $ this -> database_definition [ 'TABLES' ] ) ) { foreach ( $ this -> database_definition [ 'TABLES' ] as $ table_name => $ table ) { $ result = $ this -> _createTable ( $ table_name , $ table , $ overwrite ) ; if ( MDB :: isError ( $ result ) ) { break ; } $ created_objects ++ ; } } if ( ! MDB :: isError ( $ result ) && isset ( $ this -> database_definition [ 'SEQUENCES' ] ) && is_array ( $ this -> database_definition [ 'SEQUENCES' ] ) ) { foreach ( $ this -> database_definition [ 'SEQUENCES' ] as $ sequence_name => $ sequence ) { $ result = $ this -> _createSequence ( $ sequence_name , $ sequence , 0 , $ overwrite ) ; if ( MDB :: isError ( $ result ) ) { break ; } $ created_objects ++ ; } } if ( MDB :: isError ( $ result ) ) { if ( $ created_objects ) { if ( $ support_transactions ) { $ res = $ this -> database -> rollback ( ) ; if ( MDB :: isError ( $ res ) ) $ result = $ this -> raiseError ( MDB_ERROR_MANAGER , NULL , NULL , 'Could not rollback the partially created database alterations (' . $ result -> getMessage ( ) . ' (' . $ result -> getUserinfo ( ) , '))' , 'MDB_Error' , TRUE ) ; } else { $ result = $ this -> raiseError ( MDB_ERROR_MANAGER , NULL , NULL , 'the database was only partially created (' . $ result -> getMessage ( ) . ' (' . $ result -> getUserinfo ( ) , '))' , 'MDB_Error' , TRUE ) ; } } } else { if ( $ support_transactions ) { $ res = $ this -> database -> autoCommit ( TRUE ) ; if ( MDB :: isError ( $ res ) ) $ result = $ this -> raiseError ( MDB_ERROR_MANAGER , NULL , NULL , 'Could not end transaction after successfully created the database (' . $ res -> getMessage ( ) . ' (' . $ res -> getUserinfo ( ) , '))' , 'MDB_Error' , TRUE ) ; } } $ this -> database -> setDatabase ( $ previous_database_name ) ; if ( MDB :: isError ( $ result ) && $ create && MDB :: isError ( $ res = $ this -> database -> dropDatabase ( $ this -> database_definition [ 'name' ] ) ) ) { return ( $ this -> raiseError ( MDB_ERROR_MANAGER , NULL , NULL , 'Could not drop the created database after unsuccessful creation attempt (' . $ res -> getMessage ( ) . ' (' . $ res -> getUserinfo ( ) , '))' , 'MDB_Error' , TRUE ) ) ; } if ( MDB :: isError ( $ result ) ) { return ( $ result ) ; } return ( MDB_OK ) ; }
Create a database space within which may be created database objects
 like tables, indexes and sequences.
Create a database space within which may be created database objects like tables indexes and sequences .