protected function readHeader() { $this->version = $this->readChar(); $this->foxpro = $this->version == 48 || $this->version == 49 || $this->version == 245 || $this->version == 251; $this->modifyDate = $this->read3ByteDate(); $this->recordCount = $this->readInt(); $this->headerLength = $this->readShort(); $this->recordByteLength = $this->readShort(); $this->readBytes(2); //reserved $this->inTransaction = $this->readByte() != 0; $this->encrypted = $this->readByte() != 0; $this->readBytes(4); //Free record thread $this->readBytes(8); //Reserved for multi-user dBASE $this->mdxFlag = $this->readByte(); $this->languageCode = $this->readByte(); $this->readBytes(2); //reserved $fieldCount = floor(($this->headerLength - ($this->foxpro ? 296 : 33)) / 32); /* some checking */ if ($this->headerLength > filesize($this->tableName)) { throw new Exception\TableException(sprintf('File %s is not DBF', $this->tableName)); } if ($this->headerLength + $this->recordCount * $this->recordByteLength - 500 > filesize($this->tableName)) { throw new Exception\TableException(sprintf('File %s is not DBF', $this->tableName)); } /* columns */ $this->columns = array(); $bytepos = 1; $j = 0; for ($i = 0; $i < $fieldCount; $i++) { $column = new Column(strtolower($this->readString(11)), $this->readByte(), $this->readInt(), $this->readChar(), $this->readChar(), $this->readBytes(2), $this->readChar(), $this->readBytes(2), $this->readByte() != 0, $this->readBytes(7), $this->readByte() != 0, $j, $bytepos); $bytepos += $column->getLength(); if (!$this->avaliableColumns || $this->avaliableColumns && in_array($column->name, $this->avaliableColumns)) { $this->addColumn($column); $j++; } } if ($this->foxpro) { $this->backlist = $this->readBytes(263); } $this->setFilePos($this->headerLength); $this->recordPos = -1; $this->record = false; $this->deleteCount = 0; }
/** * Returns the difference between the fields $field1 and $field2. * * If there are differences this method returns $field2, otherwise the * boolean false. * * @param Column $column1 * @param Column $column2 * * @return array */ public function diffColumn(Column $column1, Column $column2) { $changedProperties = array(); if ($column1->getType() != $column2->getType()) { $changedProperties[] = 'type'; } if ($column1->getNotnull() != $column2->getNotnull()) { $changedProperties[] = 'notnull'; } if ($column1->getDefault() != $column2->getDefault()) { $changedProperties[] = 'default'; } if ($column1->getUnsigned() != $column2->getUnsigned()) { $changedProperties[] = 'unsigned'; } if ($column1->getType() instanceof \Doctrine\DBAL\Types\StringType) { if ($column1->getLength() != $column2->getLength()) { $changedProperties[] = 'length'; } if ($column1->getFixed() != $column2->getFixed()) { $changedProperties[] = 'fixed'; } } if ($column1->getType() instanceof \Doctrine\DBAL\Types\DecimalType) { if ($column1->getPrecision() != $column2->getPrecision()) { $changedProperties[] = 'precision'; } if ($column1->getScale() != $column2->getScale()) { $changedProperties[] = 'scale'; } } if ($column1->getAutoincrement() != $column2->getAutoincrement()) { $changedProperties[] = 'autoincrement'; } return $changedProperties; }
public function getObject(Column $column) { switch ($column->getType()) { case self::DBFFIELD_TYPE_CHAR: return $this->getString($column->getName()); case self::DBFFIELD_TYPE_DOUBLE: return $this->getDouble($column->getName()); case self::DBFFIELD_TYPE_DATE: return $this->getDate($column->getName()); case self::DBFFIELD_TYPE_DATETIME: return $this->getDateTime($column->getName()); case self::DBFFIELD_TYPE_FLOATING: return $this->getFloat($column->getName()); case self::DBFFIELD_TYPE_LOGICAL: return $this->getBoolean($column->getName()); case self::DBFFIELD_TYPE_MEMO: return $this->getMemo($column->getName()); case self::DBFFIELD_TYPE_NUMERIC: return $this->getNum($column->getName()); case self::DBFFIELD_TYPE_INDEX: return $this->getIndex($column->getName(), $column->getLength()); case self::DBFFIELD_IGNORE_0: return false; } throw new Exception\InvalidColumnException(sprintf('Cannot handle datatype %s', $column->getType())); }
/** * Returns the difference between the fields $field1 and $field2. * * If there are differences this method returns $field2, otherwise the * boolean false. * * @param Column $column1 * @param Column $column2 * * @return array */ public function diffColumn(Column $column1, Column $column2) { $changedProperties = array(); if ($column1->getType() != $column2->getType()) { $changedProperties[] = 'type'; } if ($column1->getNotnull() != $column2->getNotnull()) { $changedProperties[] = 'notnull'; } if ($column1->getDefault() != $column2->getDefault()) { $changedProperties[] = 'default'; } if ($column1->getUnsigned() != $column2->getUnsigned()) { $changedProperties[] = 'unsigned'; } if ($column1->getType() instanceof \Doctrine\DBAL\Types\StringType) { // check if value of length is set at all, default value assumed otherwise. $length1 = $column1->getLength() ?: 255; $length2 = $column2->getLength() ?: 255; if ($length1 != $length2) { $changedProperties[] = 'length'; } if ($column1->getFixed() != $column2->getFixed()) { $changedProperties[] = 'fixed'; } } if ($column1->getType() instanceof \Doctrine\DBAL\Types\DecimalType) { if (($column1->getPrecision() ?: 10) != ($column2->getPrecision() ?: 10)) { $changedProperties[] = 'precision'; } if ($column1->getScale() != $column2->getScale()) { $changedProperties[] = 'scale'; } } if ($column1->getAutoincrement() != $column2->getAutoincrement()) { $changedProperties[] = 'autoincrement'; } // only allow to delete comment if its set to '' not to null. if ($column1->getComment() !== null && $column1->getComment() != $column2->getComment()) { $changedProperties[] = 'comment'; } $options1 = $column1->getCustomSchemaOptions(); $options2 = $column2->getCustomSchemaOptions(); $commonKeys = array_keys(array_intersect_key($options1, $options2)); foreach ($commonKeys as $key) { if ($options1[$key] !== $options2[$key]) { $changedProperties[] = $key; } } $diffKeys = array_keys(array_diff_key($options1, $options2) + array_diff_key($options2, $options1)); $changedProperties = array_merge($changedProperties, $diffKeys); return $changedProperties; }
/** * Returns the difference between the fields $field1 and $field2. * * If there are differences this method returns $field2, otherwise the * boolean false. * * @param Column $column1 * @param Column $column2 * * @return array */ public function diffColumn(Column $column1, Column $column2) { $changedProperties = array(); if ($column1->getType() != $column2->getType()) { $changedProperties[] = 'type'; } if ($column1->getNotnull() != $column2->getNotnull()) { $changedProperties[] = 'notnull'; } if ($column1->getDefault() != $column2->getDefault()) { $changedProperties[] = 'default'; } if ($column1->getUnsigned() != $column2->getUnsigned()) { $changedProperties[] = 'unsigned'; } if ($column1->getType() instanceof \Doctrine\DBAL\Types\StringType) { if ($column1->getLength() != $column2->getLength()) { $changedProperties[] = 'length'; } if ($column1->getFixed() != $column2->getFixed()) { $changedProperties[] = 'fixed'; } } if ($column1->getType() instanceof \Doctrine\DBAL\Types\DecimalType) { if ($column1->getPrecision() != $column2->getPrecision()) { $changedProperties[] = 'precision'; } if ($column1->getScale() != $column2->getScale()) { $changedProperties[] = 'scale'; } } foreach ($this->_checkColumnPlatformOptions as $optionName) { if ($column1->hasPlatformOption($optionName) && $column2->hasPlatformOption($optionName)) { if ($column1->getPlatformOption($optionName) != $column2->getPlatformOption($optionName)) { $changedProperties[] = $optionName; } } else { if ($column1->hasPlatformOption($optionName) != $column2->hasPlatformOption($optionName)) { $changedProperties[] = $optionName; } } } return $changedProperties; }