Creates a database table to persist objects of this type.
@param MWebfile $webfile
@param boolean $dropTableIfExists
486911
private function createTable(MWebfile $webfile, $dropTableIfExists = true)
    {

        $tableName = $this->resolveTableNameFromWebfile($webfile);

        // CREATE METADATA
        if (!$this->metadataExist($tableName)) {
            $this->addMetadata($webfile::$m__sClassName, '1', $tableName);
        }

        $attributeArray = $webfile->getAttributes();

        // CREATE DATABASETABLE
        $table = new MDatabaseTable(
            $this->databaseConnection,
            $tableName);
        $table->specifyIdentifier("id", 10);

        /** @var \ReflectionProperty $oAttribute */
        foreach ($attributeArray as $oAttribute) {

            $sAttributeName = $oAttribute->getName();

            if (MWebfile::isSimpleDatatype($sAttributeName)
                && MWebfile::getSimplifiedAttributeName($sAttributeName) != "id"
                // ignore id as long as its set seperatly as primary key directly after creation of table
            ) {

                $tableColum = $this->createTableColumnFromAttributeName($sAttributeName);
                $table->addColumnObject($tableColum);
            }
        }
        if ($dropTableIfExists && $this->tableExistsByWebfile($webfile)) {
            $table->drop();
        }
        $table->create();
    }
1054821
public static <T> int createTableIfNotExists(ConnectionSource connectionSource, Class<T> dataClass)
			throws SQLException {
		Dao<T, ?> dao = DaoManager.createDao(connectionSource, dataClass);
		return doCreateTable(dao, true);
	}
465991
public function create_table(xmldb_table $xmldb_table) {
        // Check table doesn't exist
        if ($this->table_exists($xmldb_table)) {
            throw new ddl_exception('ddltablealreadyexists', $xmldb_table->getName());
        }

        if (!$sqlarr = $this->generator->getCreateTableSQL($xmldb_table)) {
            throw new ddl_exception('ddlunknownerror', null, 'table create sql not generated');
        }
        $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
    }
857784
public function drop_table(xmldb_table $xmldb_table) {
        // Check table exists
        if (!$this->table_exists($xmldb_table)) {
            throw new ddl_table_missing_exception($xmldb_table->getName());
        }

        if (!$sqlarr = $this->generator->getDropTableSQL($xmldb_table)) {
            throw new ddl_exception('ddlunknownerror', null, 'table drop sql not generated');
        }
        $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
    }
574308
private function getDroppedForeignKeys(Table $oldTable, Table $newTable)
    {
        $droppedForeignKeys = array();

        foreach ($oldTable->getForeignKeys() as $foreignKey) {
            if (!$newTable->hasForeignKey($foreignKey->getName())
                || $this->compareForeignKeys($foreignKey, $newTable->getForeignKey($foreignKey->getName()))) {
                $droppedForeignKeys[] = $foreignKey;
            }
        }

        return $droppedForeignKeys;
    }
301909
public function getDropIndexSQL($xmldb_table, $xmldb_index) {
        $xmldb_table->deleteIndex($xmldb_index->getName());
        return $this->getAlterTableSchema($xmldb_table);
    }
1173504
private function dropField( $db,  $tableName , $dropFieldName )
    {
        $tmpTableName = $tableName.'_ezcbackup';

        $resultArray = $db->query( "PRAGMA TABLE_INFO( $tableName )" );
        $resultArray->setFetchMode( PDO::FETCH_NUM );

        $fieldsDefinitions = array();
        $fieldsList = array();

        foreach ( $resultArray as $row )
        {
            $fieldSql = array();
            $fieldSql[] = "'{$row[1]}'"; // name
            if ( $row[1] == $dropFieldName )
            {
                continue; // don't include droped fileld in temporary table
            }

            $fieldSql[] = $row[2]; // type

            if ( $row[3] == '99' )
            {
                $fieldSql[] = 'NOT NULL';
            }

            $fieldDefault = null;
            if ( $row[4] != '' )
            {
                $fieldSql[]= "DEFAULT '{$row[4]}'";
            }

            if ( $row[5] =='1' )
            {
                $fieldSql[] = 'PRIMARY KEY AUTOINCREMENT';
            }

            // FIXME: unsigned needs to be implemented
            $fieldUnsigned = false;

            $fieldsDefinitions[] = join ( ' ', $fieldSql );
            $fieldsList[] = $fieldSql[0];
        }

        $fields = join( ', ', $fieldsDefinitions );
        $tmpTableCreateSql = "CREATE TEMPORARY TABLE '$tmpTableName'( $fields  );";
        $newTableCreateSql = "CREATE TABLE '$tableName'( $fields )" ;
        if ( count( $fieldsList ) > 0 ) 
        {
            $db->exec( $tmpTableCreateSql );
            $db->exec( "INSERT INTO '$tmpTableName' SELECT ". join( ', ', $fieldsList )." FROM '$tableName';" );
            $db->exec( "DROP TABLE '$tableName';" );
            $db->exec( $newTableCreateSql );
            $db->exec( "INSERT INTO '$tableName' SELECT ". join( ', ', $fieldsList )." FROM '$tmpTableName';" );
            $db->exec( "DROP TABLE '$tmpTableName';" );
        }
        else
        {
            throw new ezcDbSchemaDropAllColumnsException( 
                            "Trying to delete all columns in table: $tableName" );
        }
    }
1164863
public Table createTable(ProjectFile file, byte[] data, VarMeta varMeta, Var2Data varData)
   {
      Table table = new Table();

      table.setID(MPPUtility.getInt(data, 0));
      table.setResourceFlag(MPPUtility.getShort(data, 108) == 1);
      table.setName(MPPUtility.removeAmpersands(MPPUtility.getUnicodeString(data, 4)));

      byte[] columnData = null;
      Integer tableID = Integer.valueOf(table.getID());
      if (m_tableColumnDataBaseline != null)
      {
         columnData = varData.getByteArray(varMeta.getOffset(tableID, m_tableColumnDataBaseline));
      }

      if (columnData == null)
      {
         columnData = varData.getByteArray(varMeta.getOffset(tableID, m_tableColumnDataEnterprise));
         if (columnData == null)
         {
            columnData = varData.getByteArray(varMeta.getOffset(tableID, m_tableColumnDataStandard));
         }
      }

      processColumnData(file, table, columnData);

      //System.out.println(table);

      return (table);
   }
1073478
public void setupDb(boolean createDb, boolean createTables, boolean dropDb) throws Exception {

        if (m_setupBean.isInitialized()) {
            System.out.println("Setup-Bean initialized successfully.");
            CmsSetupDb db = new CmsSetupDb(m_setupBean.getWebAppRfsPath());
            try {
                // try to connect as the runtime user
                db.setConnection(
                    m_setupBean.getDbDriver(),
                    m_setupBean.getDbWorkConStr(),
                    m_setupBean.getDbConStrParams(),
                    m_setupBean.getDbWorkUser(),
                    m_setupBean.getDbWorkPwd(),
                    false);
                if (!db.noErrors()) {

                    // try to connect as the setup user
                    db.closeConnection();
                    db.clearErrors();
                    db.setConnection(
                        m_setupBean.getDbDriver(),
                        m_setupBean.getDbCreateConStr(),
                        m_setupBean.getDbConStrParams(),
                        m_setupBean.getDbCreateUser(),
                        m_setupBean.getDbCreatePwd());
                }
                if (!db.noErrors() || !m_setupBean.validateJdbc()) {
                    throw new DBException("DB connection test failed.", db.getErrors());
                }
            } finally {
                db.clearErrors();
                db.closeConnection();
            }
        }

        System.out.println("DB connection tested successfully.");

        CmsSetupDb db = null;
        boolean dbExists = false;
        if (m_setupBean.isInitialized()) {
            if (createDb || createTables) {
                db = new CmsSetupDb(m_setupBean.getWebAppRfsPath());
                // check if database exists
                if (m_setupBean.getDatabase().startsWith("oracle")
                    || m_setupBean.getDatabase().startsWith("db2")
                    || m_setupBean.getDatabase().startsWith("as400")) {
                    setWorkConnection(db);
                } else {
                    db.setConnection(
                        m_setupBean.getDbDriver(),
                        m_setupBean.getDbWorkConStr(),
                        m_setupBean.getDbConStrParams(),
                        m_setupBean.getDbCreateUser(),
                        m_setupBean.getDbCreatePwd(),
                        false);
                    dbExists = db.noErrors();
                    if (dbExists) {
                        db.closeConnection();
                    } else {
                        db.clearErrors();
                    }
                }
                if (!dbExists || dropDb) {
                    db.closeConnection();
                    if (!m_setupBean.getDatabase().startsWith("db2")
                        && !m_setupBean.getDatabase().startsWith("as400")) {
                        db.setConnection(
                            m_setupBean.getDbDriver(),
                            m_setupBean.getDbCreateConStr(),
                            m_setupBean.getDbConStrParams(),
                            m_setupBean.getDbCreateUser(),
                            m_setupBean.getDbCreatePwd());
                    }
                }
            }
        }
        if (!createDb && !createTables && !dbExists) {
            throw new Exception("You have not created the Alkacon OpenCms database.");
        }
        if (dbExists && createTables && !dropDb && (db != null)) {
            throw new Exception("You have selected to not drop existing DBs, but a DB with the given name exists.");
        }
        if (dbExists && createDb && dropDb && (db != null)) {
            // drop the DB
            db.closeConnection();
            db.setConnection(
                m_setupBean.getDbDriver(),
                m_setupBean.getDbCreateConStr(),
                m_setupBean.getDbConStrParams(),
                m_setupBean.getDbCreateUser(),
                m_setupBean.getDbCreatePwd());
            db.dropDatabase(m_setupBean.getDatabase(), m_setupBean.getReplacer());
            if (!db.noErrors()) {
                List<String> errors = new ArrayList<>(db.getErrors());
                db.clearErrors();
                throw new DBException("Error occurred while dropping the DB!", errors);
            }
            System.out.println("Database dropped successfully.");
        }

        if (createDb && (db != null)) {
            // Create Database
            db.createDatabase(m_setupBean.getDatabase(), m_setupBean.getReplacer());
            if (!db.noErrors()) {
                DBException ex = new DBException("Error occurred while creating the DB!", db.getErrors());
                db.clearErrors();
                throw ex;
            }
            db.closeConnection();
            System.out.println("Database created successfully.");
        }

        if (createTables && (db != null)) {
            setWorkConnection(db);
            //Drop Tables (intentionally quiet)
            db.dropTables(m_setupBean.getDatabase());
            db.clearErrors();
            db.closeConnection();
            // reopen the connection in order to display errors
            setWorkConnection(db);
            //Create Tables
            db.createTables(m_setupBean.getDatabase(), m_setupBean.getReplacer());
            if (!db.noErrors()) {
                DBException ex = new DBException("Error occurred while creating the DB!", db.getErrors());
                db.clearErrors();
                throw ex;
            }
            db.closeConnection();
            System.out.println("Tables created successfully.");
        }
        if (db != null) {
            db.closeConnection();
        }
        System.out.println("Database setup was successful.");
        m_context.stepForward();
    }
57277
public static void setDbFile(final File dbFile, final String[] devices, final String className) throws DevFailed {
        DatabaseFactory.useDb = false;
        DatabaseFactory.fileDatabase = new FileTangoDB(dbFile, Arrays.copyOf(devices, devices.length), className);
    }
337913
protected void create(List<TableInfo> tableInfos)
    {
        for (TableInfo tableInfo : tableInfos)
        {
            DBObject options = setCollectionProperties(tableInfo);
            DB db = mongo.getDB(databaseName);

            if (tableInfo.getLobColumnInfo().isEmpty())
            {
                if (db.collectionExists(tableInfo.getTableName()))
                {
                    db.getCollection(tableInfo.getTableName()).drop();

                    KunderaCoreUtils.printQuery("Drop existing collection: " + tableInfo.getTableName(), showQuery);
                }
                DBCollection collection = db.createCollection(tableInfo.getTableName(), options);
                KunderaCoreUtils.printQuery("Create collection: " + tableInfo.getTableName(), showQuery);

                boolean isCappedCollection = isCappedCollection(tableInfo);
                if (!isCappedCollection)
                {
                    createIndexes(tableInfo, collection);
                }
            }
            else
            {
                /*
                 * In GridFS we have 2 collections. TABLE_NAME.chunks for
                 * storing chunks of data and TABLE_NAME.MongoDBUtils.FILES for
                 * storing it's metadata.
                 */
                checkMultipleLobs(tableInfo);
                if (db.collectionExists(tableInfo.getTableName() + MongoDBUtils.FILES))
                {
                    db.getCollection(tableInfo.getTableName() + MongoDBUtils.FILES).drop();
                    KunderaCoreUtils.printQuery(
                            "Drop existing Grid FS Metadata collection: " + tableInfo.getTableName()
                                    + MongoDBUtils.FILES, showQuery);
                }

                if (db.collectionExists(tableInfo.getTableName() + MongoDBUtils.CHUNKS))
                {
                    db.getCollection(tableInfo.getTableName() + MongoDBUtils.CHUNKS).drop();
                    KunderaCoreUtils.printQuery("Drop existing Grid FS data collection: " + tableInfo.getTableName()
                            + MongoDBUtils.CHUNKS, showQuery);
                }
                coll = db.createCollection(tableInfo.getTableName() + MongoDBUtils.FILES, options);
                createUniqueIndexGFS(coll, tableInfo.getIdColumnName());
                KunderaCoreUtils.printQuery("Create collection: " + tableInfo.getTableName() + MongoDBUtils.FILES,
                        showQuery);
                db.createCollection(tableInfo.getTableName() + MongoDBUtils.CHUNKS, options);
                KunderaCoreUtils.printQuery("Create collection: " + tableInfo.getTableName() + MongoDBUtils.CHUNKS,
                        showQuery);

            }
        }
    }
34472
public function saveDiffToFile( $file, ezcDbSchemaDiff $dbSchema )
    {
        $this->writer = new XMLWriter();
        if ( ! @$this->writer->openUri( $file ) )
        {
            throw new ezcBaseFilePermissionException( $file, ezcBaseFileException::WRITE );
        }
        $this->writer->startDocument( '1.0', 'utf-8' );
        $this->writer->setIndent( true );

        $this->writer->startElement( 'database' );
        $this->writer->flush();

        // New tables
        $this->writer->startElement( 'new-tables' );
        $this->writer->flush();
        foreach ( $dbSchema->newTables as $tableName => $table )
        {
            $this->writeTable( $tableName, $table );
            $this->writer->flush();
        }
        $this->writer->endElement();
        $this->writer->flush();

        // Removed tables
        $this->writer->startElement( 'removed-tables' );
        $this->writer->flush();
        foreach ( $dbSchema->removedTables as $tableName => $tableStatus )
        {
            $this->writer->startElement( 'table' );
            $this->writer->startElement( 'name' );
            $this->writer->text( $tableName );
            $this->writer->endElement();
            $this->writer->startElement( 'removed' );
            $this->writer->text( $tableStatus ? 'true' : 'false' );
            $this->writer->endElement();
            $this->writer->endElement();
            $this->writer->flush();
        }
        $this->writer->endElement();
        $this->writer->flush();

        // Changed tables
        $this->writer->startElement( 'changed-tables' );
        $this->writer->flush();
        foreach ( $dbSchema->changedTables as $tableName => $table )
        {
            $this->writeChangedTable( $tableName, $table );
            $this->writer->flush();
        }
        $this->writer->endElement();
        $this->writer->flush();

        $this->writer->endElement();
        $this->writer->endDocument();
    }
300446
@Override
	public void dropTable(ObjectPath tablePath, boolean ignoreIfNotExists) throws TableNotExistException {
		checkNotNull(tablePath);

		if (tableExists(tablePath)) {
			tables.remove(tablePath);

			partitions.remove(tablePath);
		} else if (!ignoreIfNotExists) {
			throw new TableNotExistException(catalogName, tablePath);
		}
	}
12584
private function _createDBFFile()
    {
        if (! self::supportsDbase() || ! is_array($this->DBFHeader) || count($this->DBFHeader) == 0) {
            $this->DBFFile = null;

            return true;
        }
        $dbf_name = $this->_getFilename('.dbf');

        /* Unlink existing file */
        if (file_exists($dbf_name)) {
            unlink($dbf_name);
        }

        /* Create new file */
        $this->DBFFile = @dbase_create($dbf_name, $this->DBFHeader);
        if ($this->DBFFile === false) {
            $this->setError(sprintf('It wasn\'t possible to create the DBase file "%s"', $dbf_name));

            return false;
        }

        return true;
    }
482206
private void createIfNotExists(String tableName, String createTableStatement) throws SQLException {
		logger.entering(CLASSNAME, "createIfNotExists", new Object[] {tableName, createTableStatement});

		Connection conn = getConnection();
		DatabaseMetaData dbmd = conn.getMetaData();
		ResultSet rs = dbmd.getTables(null, schema, tableName, null);
		PreparedStatement ps = null;
		if(!rs.next()) {
			logger.log(Level.INFO, tableName + " table does not exists. Trying to create it.");
			ps = conn.prepareStatement(createTableStatement);
			ps.executeUpdate();
		}

		cleanupConnection(conn, rs, ps);
		logger.exiting(CLASSNAME, "createIfNotExists");
	}
880355
public function getDropTableSQL($xmldb_table) {
        $sqlarr = parent::getDropTableSQL($xmldb_table);
        if ($this->temptables->is_temptable($xmldb_table->getName())) {
            $sqlarr = preg_replace('/^DROP TABLE/', "DROP TEMPORARY TABLE", $sqlarr);
            $this->temptables->delete_temptable($xmldb_table->getName());
        }
        return $sqlarr;
    }
1332
public boolean dropTableIfExists(final String tableName) {
        Connection conn = getConnection();

        try {
            return JdbcUtil.dropTableIfExists(conn, tableName);
        } finally {
            closeQuietly(conn);
        }
    }