singlestore-labs / singlestoredb-laravel-driver

The official SingleStore Laravel driver.
https://github.com/singlestore-labs/singlestore-laravel-driver
Apache License 2.0
222 stars 22 forks source link

Wrong charset is used when adding columns #78

Closed nick-potts closed 6 months ago

nick-potts commented 8 months ago

When adding a column like so:

 $table->string('model_value')->nullable();

I must set the charset and collation manually so it matches the driver config like so:

$charset = config('database.connections.singlestore.charset');
$collation = config('database.connections.singlestore.collation');
$table->string('model_value')->nullable()->charset($charset)->collation($collation);

is this expected behaviour?

AdalbertMemSQL commented 6 months ago

Hey @nick-potts Sorry for the late reply. I'm going to check this issue this week.

AdalbertMemSQL commented 6 months ago

database.connections.singlestore.charset configuration sets charset used for communication between client and server.

        if (isset($config['charset'])) {
            if (isset($config['collation'])) {
                $statements[] = sprintf("NAMES '%s' COLLATE '%s'", $config['charset'], $config['collation']);
            } else {
                $statements[] = sprintf("NAMES '%s'", $config['charset']);
            }
        }

https://dev.mysql.com/doc/refman/8.0/en/set-names.html In SingleStore this is no-op and is done for compatibility with MySQL.

On the other hand, charset($charset) specifies the charset of the column. By default, the charset of the column, which by default is the charset of the table, which by default is the charset of the database, which by default is the charset of the server and is controlled by the character_set_server variable.

This looks like expected behavior. Driver config should set a charset of the connection, not a charset of the created table.

nick-potts commented 6 months ago

Ok, appreciate you explaining this to me