Generates the SQL definition for a column type.
public typeToSql ( string $type, integer $limit = null, integer $precision = null, integer $scale = null, boolean $unsigned = null ) : string | ||
$type | string | A column type. |
$limit | integer | Maximum column length (non decimal type only) |
$precision | integer | The number precision (decimal type only). |
$scale | integer | The number scaling (decimal columns only). |
$unsigned | boolean | Whether the column is an unsigned number (non decimal columns only). |
Résultat | string | The SQL definition. If $type is not one of the internally supported types, $type is returned unchanged. |
/** * Generates the SQL definition for a column type. * * @param string $type A column type. * @param integer $limit Maximum column length (non decimal type only) * @param integer $precision The number precision (decimal type only). * @param integer $scale The number scaling (decimal columns only). * @param boolean $unsigned Whether the column is an unsigned number * (non decimal columns only). * * @return string The SQL definition. If $type is not one of the * internally supported types, $type is returned unchanged. */ public function typeToSql($type, $limit = null, $precision = null, $scale = null, $unsigned = null) { if ($type != 'integer') { return parent::typeToSql($type, $limit, $precision, $scale); } switch ($limit) { case 1: case 2: return 'smallint'; case 3: case 4: case null: return 'integer'; case 5: case 6: case 7: case 8: return 'bigint'; } throw new Horde_Db_Exception("No integer type has byte size {$limit}. Use a numeric with precision 0 instead."); }
/** * Generates the SQL definition for a column type. * * @param string $type A column type. * @param integer $limit Maximum column length (non decimal type only) * @param integer $precision The number precision (decimal type only). * @param integer $scale The number scaling (decimal columns only). * @param boolean $unsigned Whether the column is an unsigned number * (non decimal columns only). * * @return string The SQL definition. If $type is not one of the * internally supported types, $type is returned unchanged. */ public function typeToSql($type, $limit = null, $precision = null, $scale = null, $unsigned = null) { // If there is no explicit limit, adjust $nativeLimit for unsigned // integers. if ($type == 'integer' && !empty($unsigned) && empty($limit)) { $natives = $this->nativeDatabaseTypes(); $native = isset($natives[$type]) ? $natives[$type] : null; if (empty($native)) { return $type; } $nativeLimit = is_array($native) ? $native['limit'] : null; if (is_integer($nativeLimit)) { $limit = $nativeLimit - 1; } } $sql = parent::typeToSql($type, $limit, $precision, $scale, $unsigned); if (!empty($unsigned)) { $sql .= ' UNSIGNED'; } return $sql; }