/** * Converts a XML description of a SQL column into a full SQL type * * <column name="_rate" nametype="namesuffix" type="sql:decimal(16,8)" unsigned="true" null="true" default="NULL" auto_increment="100" /> * * Returns: $fulltype: 'decimal(16,8) unsigned NULL DEFAULT NULL' * * @param SimpleXMLElement $column Column to determine type * @param string $tableName Name of table (for determining engine for preferred type) * @param string $tableEngine Engine of table (if $tableName is not yet created, for preferred type) * @return string|boolean Full SQL creation type or FALSE in case of error */ protected function fullColumnType(SimpleXMLElement $column, $tableName, $tableEngine = null) { $fullType = false; if ($column->getName() == 'column') { // $colName = $column->attributes( 'name' ); // $colNameType = $column->attributes( 'nametype' ); // if ( $colNameType == 'namesuffix' ) { // $colName = $colNamePrefix . $colName; // } $type = $this->getPreferredColumnType($column, $tableName, $tableEngine); $unsigned = $column->attributes('unsigned'); $null = $column->attributes('null'); $default = $column->attributes('default'); $auto_increment = $column->attributes('auto_increment'); if (cbStartOfStringMatch($type, 'sql:')) { $type = trim(substr($type, 4)); // remove 'sql:' if ($type) { $notQuoted = array('int', 'float', 'tinyint', 'bigint', 'decimal', 'boolean', 'bit', 'serial', 'smallint', 'mediumint', 'double', 'year'); $isInt = false; foreach ($notQuoted as $n) { if (cbStartOfStringMatch($type, $n)) { $isInt = true; break; } } $fullType = $type; if ($unsigned == 'true') { $fullType .= ' unsigned'; } if ($null !== 'true') { $fullType .= ' NOT NULL'; } if (!in_array($type, array('text', 'blob', 'tinytext', 'mediumtext', 'longtext', 'tinyblob', 'mediumblob', 'longblob'))) { // BLOB and TEXT columns cannot have DEFAULT values. http://dev.mysql.com/doc/refman/5.0/en/blob.html if ($default !== null) { $fullType .= ' DEFAULT ' . ($isInt || $default === 'NULL' ? $default : $this->_db->Quote($default)); } elseif (!$auto_increment) { // MySQL 5.0.51a and b have a bug: they need a default value always to be able to return it correctly in SHOW COLUMNS FROM ...: if ($null === 'true') { $default = 'NULL'; } elseif ($isInt) { $default = 0; } elseif (in_array($type, array('datetime', 'date', 'time'))) { $default = $this->_db->getNullDate($type); } else { $default = ''; } $fullType .= ' DEFAULT ' . ($isInt || $default === 'NULL' ? $default : $this->_db->Quote($default)); } } if ($auto_increment) { $fullType .= ' auto_increment'; } } } } return $fullType; }