Skip to content

Commit

Permalink
fixing B type field implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
luads committed Oct 22, 2015
1 parent b6a8122 commit 59ce03b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/XBase/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ public function getColIndex()
{
return $this->colIndex;
}
}
}
41 changes: 28 additions & 13 deletions src/XBase/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class Record
const DBFFIELD_TYPE_DATETIME = 'T'; // DateTime
const DBFFIELD_TYPE_INDEX = 'I'; // Index
const DBFFIELD_IGNORE_0 = '0'; // ignore this field
const DBRECORD_ENCODING = 'UTF-8'; // Default encoding

protected $zerodate = 0x253d8c;
protected $table;
Expand All @@ -30,9 +29,6 @@ public function __construct(Table $table, $recordIndex, $rawData = false)
$this->choppedData = array();

if ($rawData && strlen($rawData) > 0) {
if ($this->table->getConvertFrom()) {
$rawData = iconv($this->table->getConvertFrom(), self::DBRECORD_ENCODING, $rawData);
}
$this->inserted = false;
$this->deleted = (ord($rawData[0]) != '32');

Expand Down Expand Up @@ -107,18 +103,24 @@ public function getString($columnName)

public function forceGetString($columnName)
{
if (ord($this->choppedData[$columnName][0]) == '0') {
$data = trim($this->choppedData[$columnName]);

if ($this->table->getConvertFrom()) {
$data = iconv($this->table->getConvertFrom(), 'utf-8', $data);
}

if (!$data || ord($data[0]) == '0') {
return false;
}

return trim($this->choppedData[$columnName]);
return $data;
}

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->getFloat($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());
Expand Down Expand Up @@ -189,17 +191,30 @@ public function getMemo($columnName)
return $this->forceGetString($columnName);
}

public function getFloat($columnName)
public function getDouble($columnName)
{
$s = $this->forceGetString($columnName);
$s = $this->choppedData[$columnName];

if (!$s) {
return false;
$s = unpack('d', $s);

if ($s) {
return $s[1];
}

$s = str_replace(',', '.', $s);
return 0;
}

public function getFloat($columnName)
{
$s = $this->choppedData[$columnName];

$s = unpack('f', $s);

if ($s) {
return $s[1];
}

return floatval($s);
return 0;
}

public function getInt($columnName)
Expand Down

0 comments on commit 59ce03b

Please sign in to comment.