📄 mssql.php
字号:
if (PEAR::isError($db)) { return $db; } $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; $default = $autoinc = ''; if (!empty($field['autoincrement'])) { $autoinc = ' IDENTITY PRIMARY KEY'; } elseif (array_key_exists('default', $field)) { if ($field['default'] === '') { $field['default'] = 0; } if (is_null($field['default'])) { $default = ' DEFAULT (null)'; } else { $default = ' DEFAULT (' . $this->quote($field['default'], 'integer') . ')'; } } if (!empty($field['unsigned'])) { $db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer"; } $name = $db->quoteIdentifier($name, true); return $name.' '.$this->getTypeDeclaration($field).$notnull.$default.$autoinc; } // }}} // {{{ _getCLOBDeclaration() /** * Obtain DBMS specific SQL code portion needed to declare an character * large object type field to be used in statements like CREATE TABLE. * * @param string $name name the field to be declared. * @param array $field associative array with the name of the properties * of the field being declared as array indexes. Currently, the types * of supported field properties are as follows: * * length * Integer value that determines the maximum length of the large * object field. If this argument is missing the field should be * declared to have the longest length allowed by the DBMS. * * notnull * Boolean flag that indicates whether this field is constrained * to not be set to null. * @return string DBMS specific SQL code portion that should be used to * declare the specified field. * @access public */ function _getCLOBDeclaration($name, $field) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; $name = $db->quoteIdentifier($name, true); return $name.' '.$this->getTypeDeclaration($field).$notnull; } // }}} // {{{ _getBLOBDeclaration() /** * Obtain DBMS specific SQL code portion needed to declare an binary large * object type field to be used in statements like CREATE TABLE. * * @param string $name name the field to be declared. * @param array $field associative array with the name of the properties * of the field being declared as array indexes. Currently, the types * of supported field properties are as follows: * * length * Integer value that determines the maximum length of the large * object field. If this argument is missing the field should be * declared to have the longest length allowed by the DBMS. * * notnull * Boolean flag that indicates whether this field is constrained * to not be set to null. * @return string DBMS specific SQL code portion that should be used to * declare the specified field. * @access protected */ function _getBLOBDeclaration($name, $field) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; $name = $db->quoteIdentifier($name, true); return $name.' '.$this->getTypeDeclaration($field).$notnull; } // }}} // {{{ _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) { if (!$quote) { return $value; } $value = '0x'.bin2hex($this->_readFile($value)); return $value; } // }}} // {{{ _mapNativeDatatype() /** * Maps a native array description of a field to a MDB2 datatype and length * * @param array $field native field description * @return array containing the various possible types, length, sign, fixed * @access public */ function _mapNativeDatatype($field) { // todo: handle length of various int variations $db_type = preg_replace('/\d/', '', strtolower($field['type'])); $length = $field['length']; $type = array(); // todo: unsigned handling seems to be missing $unsigned = $fixed = null; switch ($db_type) { case 'bit': $type[0] = 'boolean'; break; case 'tinyint': $type[0] = 'integer'; $length = 1; break; case 'smallint': $type[0] = 'integer'; $length = 2; break; case 'int': $type[0] = 'integer'; $length = 4; break; case 'bigint': $type[0] = 'integer'; $length = 8; break; case 'datetime': $type[0] = 'timestamp'; break; case 'float': case 'real': case 'numeric': $type[0] = 'float'; break; case 'decimal': case 'money': $type[0] = 'decimal'; $length = $field['numeric_precision'].','.$field['numeric_scale']; break; case 'text': case 'ntext': case 'varchar': case 'nvarchar': $fixed = false; case 'char': case 'nchar': $type[0] = 'text'; if ($length == '1') { $type[] = 'boolean'; if (preg_match('/^(is|has)/', $field['name'])) { $type = array_reverse($type); } } elseif (strstr($db_type, 'text')) { $type[] = 'clob'; $type = array_reverse($type); } if ($fixed !== false) { $fixed = true; } break; case 'image': case 'varbinary': $type[] = 'blob'; $length = null; break; default: $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 'unknown database attribute type: '.$db_type, __FUNCTION__); } if ((int)$length <= 0) { $length = null; } return array($type, $length, $unsigned, $fixed); } // }}}}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -