Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 multibyte object name causes error #895

Merged
merged 2 commits into from
Dec 15, 2024

Conversation

shufo
Copy link
Contributor

@shufo shufo commented Dec 14, 2024

Context

Multi byte character handling

  • Oracle 12.2.0.2.1 EE
  • laracel-oci v11.6.2

Problem

Oracle database allows multi byte characters in object names such as sequences, so if I try to use multi byte characters in sequence names, an exception will be thrown due to the handling of multi byte characters.

{
    "message": "ORA-01756: quoted string not properly terminated (Connection: oracle, SQL: select * from all_sequences where sequence_name=upper('PRF_商品マスタ_商品コ�') and sequence_owner=upper(user))",
    "context": {
        "exception": {
            "class": "Illuminate\\Database\\QueryException",
            "message": "ORA-01756: quoted string not properly terminated (Connection: oracle, SQL: select * from all_sequences where sequence_name=upper('PRF_商品マスタ_商品コ�') and sequence_owner=upper(user))",
            "code": 0,
            "file": "/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:825",
            "previous": {
                "class": "Yajra\\Pdo\\Oci8\\Exceptions\\Oci8Exception",
                "message": "ORA-01756: quoted string not properly terminated",
                "code": 0,
                "file": "/app/vendor/yajra/laravel-pdo-via-oci8/src/Pdo/Oci8.php:328"
            }
        }
    },
    "level": 400,
    "level_name": "ERROR",
    "channel": "local",
    "datetime": "2024-12-15T04:22:08.339346+09:00",
    "extra": {}
}

I know it should not use multi byte character in any object name but sadly my recent work environment using multi byte object name.

How to reproduce

  1. Set oracle server character set to JA16SJISTILDE

  2. Create migration file like below

$ php artisan make:migration create_multibyte_object_name
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
use Yajra\Oci8\Schema\OracleBlueprint;

return new class () extends Migration {
    public function up(): void
    {
        Schema::create('PRF_商品マスタ', function (OracleBlueprint $table) {
            $table->string('商品コード', 10);
            $table->primary('商品コード', 'PK_PRF_商品マスタ');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('PRF_商品マスタ');
    }

    public function getConnection()
    {
        return 'oracle';
    }
};
  1. php artisan migrate
  2. php artisan migrate:rollback -> above error occur

Solution

  • Use mb_substr instead of substr. Because it handles both unicode character and ascii character properly.

@yajra yajra merged commit 08740d4 into yajra:master Dec 15, 2024
2 checks passed
@yajra
Copy link
Owner

yajra commented Dec 15, 2024

Released on https://github.com/yajra/laravel-oci8/releases/tag/v11.6.3 🚀 Thanks!

@shufo
Copy link
Contributor Author

shufo commented Dec 16, 2024

@yajra
Thank you for the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants