Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 public function setData($data)
 {
     if (strlen($data) !== self::PAGE_SIZE) {
         throw new \InvalidArgumentException("Invalid data-block given to column-page! (length " . strlen($data) . " != " . self::PAGE_SIZE . ")");
     }
     $rawName = substr($data, 0, 128);
     $rawIndex = substr($data, 128, 2);
     $rawDataType = substr($data, 130, 2);
     $rawLength = substr($data, 132, 16);
     $rawSecondLength = substr($data, 148, 16);
     $hasDefaultValue = substr($data, 164, 1);
     $rawDefaultValue = substr($data, 165, 63);
     $rawExtra = substr($data, 228, 2);
     $rawFkTable = substr($data, 230, 8);
     $rawFkColumn = substr($data, 238, 4);
     $name = rtrim($rawName, "");
     $length = ltrim($rawLength, "");
     $secondLength = ltrim($rawSecondLength, "");
     $defaultValue = rtrim($rawDefaultValue, "");
     $fkTable = ltrim($rawFkTable, "");
     $fkColumn = ltrim($rawFkColumn, "");
     $dataType = unpack("n", $rawDataType)[1];
     $index = unpack("n", $rawIndex)[1];
     $length = $this->strdec($length);
     $secondLength = $this->strdec($secondLength);
     $extra = unpack("n", $rawExtra)[1];
     $fkTable = $this->strdec($fkTable);
     $fkColumn = $this->strdec($fkColumn);
     $hasDefaultValue = (bool) ord($hasDefaultValue);
     if (!$hasDefaultValue) {
         $defaultValue = null;
     }
     $this->setName($name);
     $this->setIndex($index);
     $this->setDataType(DataType::getByValue($dataType));
     $this->setLength($length);
     $this->setSecondLength($secondLength);
     $this->setDefaultValue($defaultValue);
     $this->setExtraFlags($extra);
     $this->setFKTableIndex($fkTable);
     $this->setFKColumnIndex($fkColumn);
 }