Back to MysqlChangeItem class

Method checkDefault

private string
checkDefault
(mixed $changesArray, mixed $type)
Create query clause for column changes/modifications for DEFAULT attribute
Parameters
  • array $changesArray The array of words after COLUMN name
  • string $type The type of the COLUMN
Returns
  • string The query clause for DEFAULT check in the check query
Since
  • 3.8.6

Method checkDefault - Source code

/**
 * Create query clause for column changes/modifications for DEFAULT attribute
 *
 * @param   array   $changesArray  The array of words after COLUMN name
 * @param   string  $type          The type of the COLUMN
 *
 * @return  string  The query clause for DEFAULT check in the check query
 *
 * @since   3.8.6
 */
private function checkDefault($changesArray, $type)
{
    // Skip types that do not support default values
    $type = strtolower($type);
    if (substr($type, -4) === 'text' || substr($type, -4) === 'blob') {
        return false;
    }
    // Find DEFAULT keyword
    $index = array_search('default', array_map('strtolower', $changesArray));
    // Create the check
    if ($index !== false) {
        if (strtolower($changesArray[$index + 1]) === 'null') {
            return ' `default` IS NULL';
        } else {
            return ' `default` = ' . $changesArray[$index + 1];
        }
    }
    return false;
}