public function setUp() { $forkRate = 16; $file = new FileResourceProxy(fopen("php://memory", "w")); $doublesFile = new FileResourceProxy(fopen("php://memory", "w")); $tableSchemaFile = new FileResourceProxy(fopen("php://memory", "w")); $indexSchemaFile = new FileResourceProxy(fopen("php://memory", "w")); $tableSchema = new TableSchema($tableSchemaFile, $indexSchemaFile); $columnPageA = new ColumnSchema(); $columnPageA->setName("columnB"); $columnPageA->setIndex(0); $columnPageA->setDataType(DataType::INT()); $columnPageA->setLength(4); $tableSchema->addColumnSchema($columnPageA); $columnPageB = new ColumnSchema(); $columnPageB->setName("columnC"); $columnPageB->setIndex(1); $columnPageB->setDataType(DataType::VARCHAR()); $columnPageB->setLength(4); $tableSchema->addColumnSchema($columnPageB); $indexPage = new IndexSchema(); $indexPage->setName("test-index"); $indexPage->setColumns([0, 1]); $indexPage->setType(Type::INDEX()); $indexPage->setEngine(IndexEngine::BTREE()); $this->btree = new BTree($file, $tableSchema, $indexPage, $forkRate); $this->btree->setDoublesFile($doublesFile); $this->btree->setIsDevelopmentMode(true); }
public function setUp() { $file = new FileResourceProxy(fopen("php://memory", "w")); $columnSchema = new ColumnSchema(); $columnSchema->setName("test_column"); $columnSchema->setIndex(0); $columnSchema->setDataType(DataType::VARCHAR()); $columnSchema->setLength(10); $this->columnData = new ColumnData($file, $columnSchema); }
public function setUp() { $file = new FileResourceProxy(fopen("php://memory", "w")); $column1 = new ColumnSchema(); $column1->setName("foo"); $column1->setDataType(DataType::INTEGER()); $column1->setLength(4); $column2 = new ColumnSchema(); $column2->setName("bar"); $column2->setDataType(DataType::VARCHAR()); $column2->setLength(12); $columns = [[$column1, 'ASC'], [$column2, 'DESC']]; $this->index = new QuickSort($file, $columns); }
public function createTableSchema($tableSchemaFile, $indexSchemaFile, $tableName) { $tableSchema = new TableSchema(new FileResourceProxy(fopen("php://memory", "w")), new FileResourceProxy(fopen("php://memory", "w"))); $columns = array(); if (isset($this->columnsMap[$tableName])) { $columns = $this->columnsMap[$tableName]; } foreach ($columns as $index => list($name, $type, $length)) { $columnSchema = new ColumnSchema(); $columnSchema->setName($name); $columnSchema->setIndex($index); $columnSchema->setDataType(DataType::getByValue($type)); $columnSchema->setLength($length); $tableSchema->addColumnSchema($columnSchema); } return $tableSchema; }
/** * * @return TableSchema */ public function getTableSchema() { if (is_null($this->tableSchema)) { $columnFile = new FileResourceProxy(fopen("php://memory", "w")); $indexFile = new FileResourceProxy(fopen("php://memory", "w")); $this->tableSchema = new TableSchema($columnFile, $indexFile); foreach ($this->columnNames as $columnName) { $columnPage = new ColumnSchema(); $columnPage->setName($columnName); $columnPage->setDataType(DataType::VARCHAR()); $columnPage->setLength(1024); $this->tableSchema->addColumnSchema($columnPage); } } return $this->tableSchema; }
public function executeJob(StatementJob $statement, array $parameters = array()) { /* @var $statement CreateTableStatement */ $context = new ExecutionContext($this->schemaManager, $statement, $parameters); /* @var $databaseSchema Schema */ $databaseSchema = $this->schemaManager->getSchema(); $schemaId = $this->schemaManager->getCurrentlyUsedDatabaseId(); $tableName = $this->valueResolver->resolveValue($statement->getName(), $context); $schemaPage = new DatabaseSchemaPage(); $schemaPage->setName($tableName); $schemaPage->setType(Type::TABLE()); $schemaPage->setEngine(Engine::factory($statement->getEngine()->getName())); $schemaPage->setCollation(strtoupper($statement->getCollate())); $schemaPage->setUseChecksum($statement->getUseChecksum()); $schemaPage->setMaxRows($statement->getMaximumRows()); $schemaPage->setMinRows($statement->getMinimumRows()); $schemaPage->setPackKeys($statement->getPackKeys()); $schemaPage->setDelayKeyWrite($statement->getDelayKeyWrite()); $schemaPage->setRowFormat(RowFormat::factory($statement->getRowFormat())); $schemaPage->setInsertMethod(InsertMethod::factory($statement->getInsertMethod())); $databaseSchema->registerTableSchema($schemaPage); /* @var $tableSchema TableSchema */ $tableSchema = $this->schemaManager->getTableSchema($tableName); assert($tableSchema instanceof TableSchema); ### WRITE COLUMNS switch (true) { case is_array($statement->getColumnDefinition()): foreach ($statement->getColumnDefinition() as $name => $column) { /* @var $column ColumnDefinition */ $columnPage = new ColumnSchema(); $columnPage->setName($name); $columnPage->setDataType(DataType::factory($column->getDataType()->getName())); /* @var $dataType DataType */ $dataType = $columnPage->getDataType(); $flags = 0; if ($column->getIsPrimaryKey()) { $flags = $flags ^ ColumnSchema::EXTRA_PRIMARY_KEY; } if ($column->getIsUnique()) { $flags = $flags ^ ColumnSchema::EXTRA_UNIQUE_KEY; } if (!$column->getIsNullable()) { $flags = $flags ^ ColumnSchema::EXTRA_NOT_NULL; } if ($column->getIsAutoIncrement()) { $flags = $flags ^ ColumnSchema::EXTRA_AUTO_INCREMENT; } $columnPage->setExtraFlags($flags); /* @var $dataType DataType */ $dataType = $column->getDataType(); $columnPage->setLength($dataType->getByteLength()); $columnPage->setSecondLength($dataType->getSecondByteLength()); if (!is_null($column->getDataTypeLength())) { $columnPage->setLength($column->getDataTypeLength()); } if (!is_null($column->getDataTypeSecondLength())) { $columnPage->setSecondLength($column->getDataTypeSecondLength()); } if (!is_null($column->getDefaultValue()) && !$columnPage->isDefaultValueInFile()) { $columnPage->setDefaultValue($column->getDefaultValue()); } $columnIndex = $tableSchema->addColumnSchema($columnPage); if (!is_null($column->getDefaultValue()) && $columnPage->isDefaultValueInFile()) { $defaultValueFilepath = sprintf(FilePathes::FILEPATH_DEFAULT_VALUE, $schemaId, $tableName, $columnIndex); $this->tableManager->getFilesystem()->putFileContents($defaultValueFilepath, $column->getDefaultValue()); } } break; case $statement->getColumnDefinition() instanceof Select: break; case $statement->getColumnDefinition() instanceof TableInterface: break; } foreach ($statement->getIndexes() as $indexName => $index) { /* @var $index Index */ $indexSchemaPage = new IndexSchema(); $indexSchemaPage->setName($indexName); $indexSchemaPage->setEngine(IndexEngine::BTREE()); switch (true) { case $index->getIsPrimary(): $indexSchemaPage->setType(IndexType::PRIMARY()); break; case $index->getIsUnique(): $indexSchemaPage->setType(IndexType::UNIQUE()); break; default: $indexSchemaPage->setType(IndexType::INDEX()); break; } $method = ForeignKeyMethod::factory($index->getForeignKeyOnDeleteReferenceOption()->getName()); $indexSchemaPage->setForeignKeyOnDeleteMethod($method); $method = ForeignKeyMethod::factory($index->getForeignKeyOnUpdateReferenceOption()->getName()); $indexSchemaPage->setForeignKeyOnUpdateMethod($method); $keyLength = 0; $columns = array(); foreach ($index->getColumns() as $indexColumnName) { $indexColumnId = $tableSchema->getColumnIndex((string) $indexColumnName); if (strlen($indexColumnId) <= 0) { throw new ErrorException("Could not find index column '{$indexColumnName}' in table-schema!"); } $columns[] = $indexColumnId; $keyLength += $statement->getColumnDefinition()[(string) $indexColumnName]->getDataSize(); } $indexSchemaPage->setColumns($columns); $indexSchemaPage->setKeyLength($keyLength); $tableSchema->addIndexSchema($indexSchemaPage); } foreach ($this->tableManager->getTableFactories() as $tableFactory) { /* @var $tableFactory TableFactoryInterface */ if ($tableFactory instanceof InformationSchemaTableFactory) { $tableFactory->clearCache(); } } ### RESULT $result = new TemporaryResult(); $result->setIsSuccess(true); return $result; }
protected function convertColumnDefinitionToColumnSchema(ColumnDefinition $columnDefinition, ExecutionContext $executionContext) { $columnPage = new ColumnSchema(); $columnPage->setName($columnDefinition->getName()); /* @var $dataType DataType */ $dataType = $columnDefinition->getDataType(); $columnPage->setDataType($dataType); if (!is_null($columnDefinition->getDataTypeLength())) { $columnPage->setLength($columnDefinition->getDataTypeLength()); } if (!is_null($columnDefinition->getDataTypeSecondLength())) { $columnPage->setSecondLength($columnDefinition->getDataTypeSecondLength()); } $flags = 0; if ($columnDefinition->getIsAutoIncrement()) { $flags = $flags ^ ColumnSchema::EXTRA_AUTO_INCREMENT; } if (!$columnDefinition->getIsNullable()) { $flags = $flags ^ ColumnSchema::EXTRA_NOT_NULL; } if ($columnDefinition->getIsPrimaryKey()) { $flags = $flags ^ ColumnSchema::EXTRA_PRIMARY_KEY; } if ($columnDefinition->getIsUnique()) { $flags = $flags ^ ColumnSchema::EXTRA_UNIQUE_KEY; } if ($columnDefinition->getIsUnsigned()) { $flags = $flags ^ ColumnSchema::EXTRA_UNSIGNED; } if (false) { $flags = $flags ^ ColumnSchema::EXTRA_ZEROFILL; } $columnPage->setExtraFlags($flags); #$columnPage->setFKColumnIndex($index); #$columnPage->setFKTableIndex($index); /* @var $defaultValue Value */ $defaultValue = $columnDefinition->getDefaultValue(); if (!is_null($defaultValue)) { if (!$dataType->mustResolveDefaultValue()) { # default value must be resolved at insertion-time => save unresolved $defaultValueData = $this->valueResolver->resolveValue($defaultValue, $executionContext); $defaultValueData = $this->dataConverter->convertStringToBinary($defaultValueData, $columnPage->getDataType()); } else { $defaultValueData = (string) $defaultValue; } } else { $defaultValueData = null; } $columnPage->setDefaultValue($defaultValueData); $comment = $columnDefinition->getComment(); # TODO: save column comment return $columnPage; }
public function dataProviderModifyColumn() { $columnSchema = new ColumnSchema(); $columnSchema->setName("baz"); $columnSchema->setDataType(DataType::VARCHAR()); $columnSchema->setLength(5); return array([[[123, "Lorem ipsum", null], [456, "dolor sit", "2015-06-07 12:34:56"]], $columnSchema, [[789, "amet", "1990-10-02 10:20:30"], [234, "", null]], [['123', "Lorem", null], ['456', "dolor", "2015-06-07 12:34:56"], ['789', "amet", "1990-10-02 10:20:30"], ['234', "", null]]]); }