📄 common.php
字号:
$autoincrement = !empty($current['autoincrement']) ? $current['autoincrement'] : false; if ($previous_autoincrement != $autoincrement) { $change['autoincrement'] = true; } return $change; } // }}} // {{{ _compareTextDefinition() /** * Obtain an array of changes that may need to applied to an text field * * @param array $current new definition * @param array $previous old definition * @return array containing all changes that will need to be applied * @access protected */ function _compareTextDefinition($current, $previous) { $change = array(); $previous_length = !empty($previous['length']) ? $previous['length'] : 0; $length = !empty($current['length']) ? $current['length'] : 0; if ($previous_length != $length) { $change['length'] = true; } $previous_fixed = !empty($previous['fixed']) ? $previous['fixed'] : 0; $fixed = !empty($current['fixed']) ? $current['fixed'] : 0; if ($previous_fixed != $fixed) { $change['fixed'] = true; } return $change; } // }}} // {{{ _compareCLOBDefinition() /** * Obtain an array of changes that may need to applied to an CLOB field * * @param array $current new definition * @param array $previous old definition * @return array containing all changes that will need to be applied * @access protected */ function _compareCLOBDefinition($current, $previous) { return $this->_compareTextDefinition($current, $previous); } // }}} // {{{ _compareBLOBDefinition() /** * Obtain an array of changes that may need to applied to an BLOB field * * @param array $current new definition * @param array $previous old definition * @return array containing all changes that will need to be applied * @access protected */ function _compareBLOBDefinition($current, $previous) { return $this->_compareTextDefinition($current, $previous); } // }}} // {{{ _compareDateDefinition() /** * Obtain an array of changes that may need to applied to an date field * * @param array $current new definition * @param array $previous old definition * @return array containing all changes that will need to be applied * @access protected */ function _compareDateDefinition($current, $previous) { return array(); } // }}} // {{{ _compareTimeDefinition() /** * Obtain an array of changes that may need to applied to an time field * * @param array $current new definition * @param array $previous old definition * @return array containing all changes that will need to be applied * @access protected */ function _compareTimeDefinition($current, $previous) { return array(); } // }}} // {{{ _compareTimestampDefinition() /** * Obtain an array of changes that may need to applied to an timestamp field * * @param array $current new definition * @param array $previous old definition * @return array containing all changes that will need to be applied * @access protected */ function _compareTimestampDefinition($current, $previous) { return array(); } // }}} // {{{ _compareBooleanDefinition() /** * Obtain an array of changes that may need to applied to an boolean field * * @param array $current new definition * @param array $previous old definition * @return array containing all changes that will need to be applied * @access protected */ function _compareBooleanDefinition($current, $previous) { return array(); } // }}} // {{{ _compareFloatDefinition() /** * Obtain an array of changes that may need to applied to an float field * * @param array $current new definition * @param array $previous old definition * @return array containing all changes that will need to be applied * @access protected */ function _compareFloatDefinition($current, $previous) { return array(); } // }}} // {{{ _compareDecimalDefinition() /** * Obtain an array of changes that may need to applied to an decimal field * * @param array $current new definition * @param array $previous old definition * @return array containing all changes that will need to be applied * @access protected */ function _compareDecimalDefinition($current, $previous) { return array(); } // }}} // {{{ quote() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param string $value text string value that is intended to be converted. * @param string $type type to which the value should be converted to * @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. * @access public */ function quote($value, $type = null, $quote = true, $escape_wildcards = false) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } if (is_null($value) || ($value === '' && $db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL) ) { if (!$quote) { return null; } return 'NULL'; } if (is_null($type)) { switch (gettype($value)) { case 'integer': $type = 'integer'; break; case 'double': // todo: default to decimal as float is quite unusual // $type = 'float'; $type = 'decimal'; break; case 'boolean': $type = 'boolean'; break; case 'array': $value = serialize($value); case 'object': $type = 'text'; break; default: if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/', $value)) { $type = 'timestamp'; } elseif (preg_match('/^\d{2}:\d{2}$/', $value)) { $type = 'time'; } elseif (preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) { $type = 'date'; } else { $type = 'text'; } break; } } elseif (!empty($db->options['datatype_map'][$type])) { $type = $db->options['datatype_map'][$type]; if (!empty($db->options['datatype_map_callback'][$type])) { $parameter = array('type' => $type, 'value' => $value, 'quote' => $quote, 'escape_wildcards' => $escape_wildcards); return call_user_func_array($db->options['datatype_map_callback'][$type], array(&$db, __FUNCTION__, $parameter)); } } if (!method_exists($this, "_quote{$type}")) { return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 'type not defined: '.$type, __FUNCTION__); } $value = $this->{"_quote{$type}"}($value, $quote, $escape_wildcards); if ($quote && $escape_wildcards && $db->string_quoting['escape_pattern'] && $db->string_quoting['escape'] !== $db->string_quoting['escape_pattern'] ) { $value.= $this->patternEscapeString(); } return $value; } // }}} // {{{ _quoteInteger() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param string $value text string 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. * @access protected */ function _quoteInteger($value, $quote, $escape_wildcards) { return (int)$value; } // }}} // {{{ _quoteText() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param string $value text string 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 already contains any DBMS specific * escaped character sequences. * @access protected */ function _quoteText($value, $quote, $escape_wildcards) { if (!$quote) { return $value; } $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } $value = $db->escape($value, $escape_wildcards); return "'".$value."'"; } // }}} // {{{ _readFile() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ function _readFile($value) { $close = false; if (preg_match('/^(\w+:\/\/)(.*)$/', $value, $match)) { $close = true; if ($match[1] == 'file://') { $value = $match[2]; } $value = @fopen($value, 'r'); } if (is_resource($value)) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } $fp = $value; $value = ''; while (!@feof($fp)) { $value.= @fread($fp, $db->options['lob_buffer_length']); } if ($close) { @fclose($fp); } } return $value; } // }}} // {{{ _quoteLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param string $value text string 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. * @access protected */ function _quoteLOB($value, $quote, $escape_wildcards) { $value = $this->_readFile($value); return $this->_quoteText($value, $quote, $escape_wildcards); } // }}} // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param string $value text string 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. * @access protected */ function _quoteCLOB($value, $quote, $escape_wildcards) { return $this->_quoteLOB($value, $quote, $escape_wildcards); } // }}} // {{{ _quoteBLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param string $value text string 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. * @access protected */ function _quoteBLOB($value, $quote, $escape_wildcards) { return $this->_quoteLOB($value, $quote, $escape_wildcards); } // }}} // {{{ _quoteBoolean() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param string $value text string 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. * @access protected */ function _quoteBoolean($value, $quote, $escape_wildcards) { return ($value ? 1 : 0); } // }}} // {{{ _quoteDate() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param string $value text string 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. * @access protected */ function _quoteDate($value, $quote, $escape_wildcards) { if ($value === 'CURRENT_DATE') { $db =& $this->getDBInstance();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -