/** * Builds the DDL SQL for a Column object. * @return string */ public function getColumnDDL(Column $col) { $platform = $this->getPlatform(); $domain = $col->getDomain(); $sb = ""; $sb .= $this->quoteIdentifier($col->getName()) . " "; $sb .= $domain->getSqlType(); if ($platform->hasSize($domain->getSqlType())) { $sb .= $domain->printSize(); } $sb .= " "; $sb .= $col->getDefaultSetting() . " "; $sb .= $col->getNotNullString() . " "; $sb .= $col->getAutoIncrementString(); return trim($sb); }
/** * Builds the DDL SQL for a Column object. * @return string */ public function getColumnDDL(Column $col) { $platform = $this->getPlatform(); $domain = $col->getDomain(); $sqlType = $domain->getSqlType(); $notNullString = $col->getNotNullString(); $defaultSetting = $col->getDefaultSetting(); // Special handling of TIMESTAMP/DATETIME types ... // See: http://propel.phpdb.org/trac/ticket/538 if ($sqlType == 'DATETIME') { $def = $domain->getDefaultValue(); if ($def && $def->isExpression()) { // DATETIME values can only have constant expressions $sqlType = 'TIMESTAMP'; } } elseif ($sqlType == 'DATE') { $def = $domain->getDefaultValue(); if ($def && $def->isExpression()) { // DATE values don't support expressions in MySQL throw new EngineException("DATE columns cannot have default *expressions* in MySQL."); } } $sb = ""; $sb .= $this->quoteIdentifier($col->getName()) . " "; $sb .= $sqlType; if ($platform->hasSize($sqlType)) { $sb .= $domain->printSize(); } $sb .= " "; if ($sqlType == 'TIMESTAMP') { $notNullString = $col->getNotNullString(); $defaultSetting = $col->getDefaultSetting(); if ($notNullString == '') { $notNullString = 'NULL'; } if ($defaultSetting == '' && $notNullString == 'NOT NULL') { $defaultSetting = 'DEFAULT CURRENT_TIMESTAMP'; } $sb .= $notNullString . " " . $defaultSetting . " "; } else { $sb .= $defaultSetting . " "; $sb .= $notNullString . " "; } $sb .= $col->getAutoIncrementString(); return trim($sb); }
/** * Builds the DDL SQL for a Column object. * @return string */ public function getColumnDDL(Column $col) { $platform = $this->getPlatform(); $domain = $col->getDomain(); $sqlType = $domain->getSqlType(); $notNullString = $col->getNotNullString(); $defaultSetting = $col->getDefaultSetting(); // Special handling of TIMESTAMP/DATETIME types ... // See: http://propel.phpdb.org/trac/ticket/538 if ($sqlType == 'DATETIME') { $def = $domain->getDefaultValue(); if ($def && $def->isExpression()) { // DATETIME values can only have constant expressions $sqlType = 'TIMESTAMP'; } } elseif ($sqlType == 'DATE') { $def = $domain->getDefaultValue(); if ($def && $def->isExpression()) { throw new EngineException("DATE columns cannot have default *expressions* in MySQL."); } } elseif ($sqlType == 'TEXT' || $sqlType == 'BLOB') { if ($domain->getDefaultValue()) { throw new EngineException("BLOB and TEXT columns cannot have DEFAULT values. in MySQL."); } } $sb = ""; $sb .= $this->quoteIdentifier($col->getName()) . " "; $sb .= $sqlType; if ($platform->hasSize($sqlType)) { $sb .= $domain->printSize(); } $colinfo = $col->getVendorInfoForType($platform->getDatabaseType()); if ($colinfo->hasParameter('Charset')) { $sb .= ' CHARACTER SET ' . $platform->quote($colinfo->getParameter('Charset')); } if ($colinfo->hasParameter('Collation')) { $sb .= ' COLLATE ' . $platform->quote($colinfo->getParameter('Collation')); } elseif ($colinfo->hasParameter('Collate')) { $sb .= ' COLLATE ' . $platform->quote($colinfo->getParameter('Collate')); } if ($sqlType == 'TIMESTAMP') { $notNullString = $col->getNotNullString(); $defaultSetting = $col->getDefaultSetting(); if ($notNullString == '') { $notNullString = 'NULL'; } if ($defaultSetting == '' && $notNullString == 'NOT NULL') { $defaultSetting = 'DEFAULT CURRENT_TIMESTAMP'; } $sb .= ' ' . $notNullString . ' ' . $defaultSetting; } else { $sb .= ' ' . $defaultSetting . ' ' . $notNullString; } if ($autoIncrement = $col->getAutoIncrementString()) { $sb .= ' ' . $autoIncrement; } if ($col->getDescription()) { $sb .= ' COMMENT ' . $platform->quote($col->getDescription()); } return trim($sb); }