Skip to content

MariaDB column defaults may or may not be quoted #56125

@asmecher

Description

@asmecher

Laravel Version

11.44.1 (also in newer branches)

PHP Version

8.4.6 (PHP version is not a factor)

Database Driver & Version

MariaDB 10.11.13 on Ubuntu

Description

Because of MDEV-13132, releases of MariaDB since 10.2.7 quote string literal column defaults in the information_schema. (MySQL does not currently do this.)

Therefore, depending on what version of MariaDB you're using, calls to Schema::getColumns to determine column details might give you a quoted string, or not, depending on the version of the DBMS.

Steps To Reproduce

Test script:

<?php

require_once('vendor/autoload.php');

use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint;

$capsule = new Capsule;

$capsule->addConnection([
    'driver' => 'mariadb',
    'host' => '127.0.0.1',
    'database' => 'DATABASE_NAME_HERE',
    'username' => 'USERNAME_HERE',
    'password' => 'PASSWORD_HERE',
    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix' => '',
]);

$capsule->setAsGlobal();
$schema = $capsule->schema();

// Clean up from a previous run if necessary, and create a table for testing purposes.
if ($schema->hasTable('test_table')) $schema->drop('test_table');
$schema->create('test_table', function (Blueprint $table) {
    $table->string('test_string')->default('Some default');
});

$columns = $schema->getColumns('test_table');
$column = $columns[0];
echo "The column default is: {$column['default']}\n";

Results with MariaDB 10.2.7 or newer:

The column default is: 'Some default'

Results with MariaDB older than 10.2.7, or any MySQL:

The column default is: Some default

While this is a behavioural change to MariaDB, it would be nice for Laravel to hide this quirk from the caller -- probably by overriding the MySQL schema grammar's implementation of compileColumns to account for it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions