/** * General type conversion method * * @param mixed $value refernce to a value to be converted * @param string $type specifies which type to convert to * @param boolean $rtrim [optional] when TRUE [default], apply rtrim() to text * @return object a MDB2 error on failure * @access protected */ function _baseConvertResult($value, $type, $rtrim = true) { if (is_null($value)) { return null; } $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } switch ($type) { case 'timestamp': return substr($value, 0, strlen('YYYY-MM-DD HH:MM:SS')); } return parent::_baseConvertResult($value, $type, $rtrim); }
/** * general type conversion method * * @param mixed $value refernce to a value to be converted * @param string $type specifies which type to convert to * @param string $rtrim if text should be rtrimmed * @return object a MDB2 error on failure * @access protected */ function _baseConvertResult($value, $type, $rtrim = true) { if (null === $value) { return null; } switch ($type) { case 'boolean': return $value == 'T'; case 'time': if ($value[0] == '+') { return substr($value, 1); } else { return $value; } } return parent::_baseConvertResult($value, $type, $rtrim); }
/** * general type conversion method * * @param mixed $value refernce to a value to be converted * @param string $type specifies which type to convert to * @param boolean $rtrim [optional] when TRUE [default], apply rtrim() to text * @return object a MDB2 error on failure * @access protected */ function _baseConvertResult($value, $type, $rtrim = true) { if (null === $value) { return null; } switch ($type) { case 'boolean': return $value == '1'; case 'date': if (strlen($value) > 10) { $value = substr($value, 0, 10); } return $value; case 'time': if (strlen($value) > 8) { $value = substr($value, 11, 8); } return $value; } return parent::_baseConvertResult($value, $type, $rtrim); }
/** * General type conversion method * * @param mixed $value refernce to a value to be converted * @param string $type specifies which type to convert to * @param bool $rtrim optional value, when true, rtrim text values * @return object an MDB2 error on failure * @access protected */ function _baseConvertResult($value, $type, $rtrim = true) { if (is_null($value)) { return null; } switch ($type) { case 'boolean': return $value == 't'; case 'float': return doubleval($value); case 'date': return $value; case 'time': return substr($value, 0, strlen('HH:MM:SS')); case 'timestamp': return substr($value, 0, strlen('YYYY-MM-DD HH:MM:SS')); case 'blob': $value = pg_unescape_bytea($value); return parent::_baseConvertResult($value, $type, $rtrim); } return parent::_baseConvertResult($value, $type, $rtrim); }
/** * Obtain DBMS specific SQL code portion needed to declare * of the given type * * @param string $type type to which the value should be converted to * @param string $name name the field to be declared. * @param string $field definition of the field * * @return string DBMS-specific SQL code portion that should be used to * declare the specified field. * @access public */ function getDeclaration($type, $name, $field) { // MySQL DDL syntax forbids combining NOT NULL with DEFAULT NULL. // To get a default of NULL for NOT NULL columns, omit it. if (isset($field['notnull']) && !empty($field['notnull']) && array_key_exists('default', $field) && null === $field['default']) { unset($field['default']); } return parent::getDeclaration($type, $name, $field); }
/** * Read data from large object input stream. * * @param array $lob array * @param blob $data reference to a variable that will hold data to be * read from the large object input stream * @param int $length integer value that indicates the largest ammount of * data to be read from the large object input stream. * @return mixed length on success, a MDB2 error on failure * @access protected */ function _readLOB($lob, $length) { if ($lob['loaded']) { return parent::_readLOB($lob, $length); } if (!is_object($lob['resource'])) { $db = $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'attemped to retrieve LOB from non existing or NULL column', __FUNCTION__); } $data = $lob['resource']->read($length); if (!is_string($data)) { $db = $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } return $db->raiseError(null, null, null, 'Unable to read LOB', __FUNCTION__); } return $data; }
/** * Obtain an array of changes that may need to applied * * @param array new definition * @param array old definition * * @return array containing all changes that will need to be applied */ public function compareDefinition($current, $previous) { $result = $this->loadModule('Datatype', null, true); if (MDB2::isError($result)) { return $result; } return $this->datatype->compareDefinition($current, $previous); }
/** * Convert a UUID value into a DBMS specific format that is suitable to * compose query statements. * * @param string $value UUID value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. */ protected function _quoteUUID($value, $quote, $escape_wildcards) { $uuid = parent::_quoteUUID($value, $quote, $escape_wildcards); return $uuid . '::uuid'; }
/** * General type conversion method * * @param mixed $value refernce to a value to be converted * @param string $type specifies which type to convert to * @param boolean $rtrim [optional] when TRUE [default], apply rtrim() to text * @return object a MDB2 error on failure * @access protected */ function _baseConvertResult($value, $type, $rtrim = true) { if (null === $value) { return null; } $db = $this->getDBInstance(); if (MDB2::isError($db)) { return $db; } $connection = $db->getConnection(); if (MDB2::isError($connection)) { return $connection; } switch ($type) { case 'text': $blob_info = @ibase_blob_info($connection, $value); if (is_array($blob_info) && $blob_info['length'] > 0) { //LOB => fetch into variable $clob = $this->_baseConvertResult($value, 'clob', $rtrim); if (!MDB2::isError($clob) && is_resource($clob)) { $clob_value = ''; while (!feof($clob)) { $clob_value .= fread($clob, 8192); } $this->destroyLOB($clob); } $value = $clob_value; } if ($rtrim) { $value = rtrim($value); } return $value; case 'timestamp': return substr($value, 0, strlen('YYYY-MM-DD HH:MM:SS')); } return parent::_baseConvertResult($value, $type, $rtrim); }