示例#1
0
 /**
  * Normalizes result row.
  * @param  array
  * @return array
  */
 public function normalizeRow($row)
 {
     if ($this->types === NULL) {
         $this->types = array();
         if ($this->connection->getSupplementalDriver()->supports['meta']) {
             // workaround for PHP bugs #53782, #54695
             foreach ($row as $key => $foo) {
                 $type = $this->getColumnMeta(count($this->types));
                 if (isset($type['native_type'])) {
                     $this->types[$key] = Reflection\DatabaseReflection::detectType($type['native_type']);
                 }
             }
         }
     }
     foreach ($this->types as $key => $type) {
         $value = $row[$key];
         if ($value === NULL || $value === FALSE || $type === Reflection\DatabaseReflection::FIELD_TEXT) {
         } elseif ($type === Reflection\DatabaseReflection::FIELD_INTEGER) {
             $row[$key] = is_float($tmp = $value * 1) ? $value : $tmp;
         } elseif ($type === Reflection\DatabaseReflection::FIELD_FLOAT) {
             $row[$key] = (string) ($tmp = (double) $value) === $value ? $tmp : $value;
         } elseif ($type === Reflection\DatabaseReflection::FIELD_BOOL) {
             $row[$key] = (bool) $value && $value !== 'f' && $value !== 'F';
         }
     }
     return $this->connection->getSupplementalDriver()->normalizeRow($row, $this);
 }
示例#2
0
	/**
	 * Normalizes result row.
	 * @param  array
	 * @return array
	 */
	public function normalizeRow($row)
	{
		if ($this->types === NULL) {
			try {
				$this->types = array();
				foreach ($row as $key => $foo) {
					$type = $this->getColumnMeta(count($this->types));
					if (isset($type['native_type'])) {
						$this->types[$key] = DatabaseReflection::detectType($type['native_type']);
					}
				}
			} catch (\PDOException $e) {
			}
		}
		foreach ($this->types as $key => $type) {
			$value = $row[$key];
			if ($value === NULL || $value === FALSE || $type === DatabaseReflection::FIELD_TEXT) {

			} elseif ($type === DatabaseReflection::FIELD_INTEGER) {
				$row[$key] = is_float($tmp = $value * 1) ? $value : $tmp;

			} elseif ($type === DatabaseReflection::FIELD_FLOAT) {
				$row[$key] = (string) ($tmp = (float) $value) === $value ? $tmp : $value;

			} elseif ($type === DatabaseReflection::FIELD_BOOL) {
				$row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F';
			}
		}

		return $this->connection->getSupplementalDriver()->normalizeRow($row, $this);
	}