
前提・実現したいこと
LaravelのDBをOracleからMariaDBに変更しようとしていますが、'dbms_lob.INSTR'エラーが出ます。
発生している問題・エラーメッセージ
[2022-03-10 10:06:22] staging.ERROR: SQLSTATE[42000]: Syntax error or access violation: 1370 execute command denied to user '' for routine 'dbms_lob.INSTR' (SQL: select count(*) as aggregate from `bbs` where `bbs_id` = LB041 and `fu_id` = and `article_title` = Tu and `reg_date` >= 2022-03-10 10:04:22 and `wrt_ip` = 172.18.0.1 and exists (select `article_no`, `article_text` from `bbs_text` where `bbs`.`article_no` = `bbs_text`.`article_no` and DBMS_LOB.INSTR(bbs_text.article_text, Tu
該当のソースコード
QnaController.php
1<?php 2 3namespace App\Api\V1\Controllers\Forum; 4 5use App\Api\V1\Controllers\BaseController; 6use App\Api\V1\CustomException; 7use App\Api\V1\Resources\Forum\Qna\CategoryCollection; 8use App\Api\V1\Resources\Forum\Qna\ListCollection; 9use App\Api\V1\Resources\Forum\Qna\ShowResource; 10use App\Models\CategoryInfo; 11use App\Models\Forum; 12use Illuminate\Http\Request; 13use Illuminate\Validation\Rule; 14 15/** 16 * 17 * 18 * Class QnaController 19 * @package App\Api\V1\Controllers\Forum 20 */ 21class QnaController extends BaseController 22{ 23 24 /** 25 * 26 * 27 * @param Request $request 28 * @return \Illuminate\Http\JsonResponse 29 * @throws \Throwable 30 */ 31 public function store(Request $request) 32 { 33 $options = $this->categories()->resource; 34 35 $request_data = $request->validate([ 36 'category_id' => [ 37 'required', 38 Rule::in($options->pluck('catg_id')->toArray()) 39 ], 40 'title' => 'required|string|max:100', 41 'content' => 'required|string|max:500', 42 ], [ 43 'category_id.required' => \LittlefoxLocalization::lang('api_qna_store_validate_fail_category_id_required_msg'), 44 'category_id.in' => \LittlefoxLocalization::lang('api_qna_store_validate_fail_category_id_in_msg'), 45 'title.required' => \LittlefoxLocalization::lang('api_qna_store_validate_fail_title_required_msg'), 46 'title.string' => \LittlefoxLocalization::lang('api_qna_store_validate_fail_title_string_msg'), 47 'title.max' => \LittlefoxLocalization::lang('api_qna_store_validate_fail_title_max_msg'), 48 'content.required' => \LittlefoxLocalization::lang('api_qna_store_validate_fail_content_required_msg'), 49 'content.string' => \LittlefoxLocalization::lang('api_qna_store_validate_fail_content_string_msg'), 50 'content.max' => \LittlefoxLocalization::lang('api_qna_store_validate_fail_content_max_msg'), 51 ]); 52 53 $exists = Forum::where('bbs_id', config('api.forum.qna')) 54 ->where('fu_id', auth()->id()) 55 ->where('article_title', $request_data['title']) 56 ->where('reg_date', '>=', now()->subMinutes(2)->toDateTimeString()) 57 ->where('wrt_ip', $request->ip()) 58 ->whereHas('text', function ($query) use ($request_data) { 59 $query->whereRaw('DBMS_LOB.INSTR('.$query->qualifyColumn('article_text').', ?) > 0', [Forum\Text::escapeText($request_data['content'])]); 60 }) 61 ->count() > 0; 62 63 if ($exists) { 64 throw new CustomException(200, \LittlefoxLocalization::lang('api_forum_qna_store_already_registered_same_contents_msg'), 422); 65 } 66 67 \DB::transaction(function () use ($request_data) { 68 $article = Forum::make([ 69 'bbs_id' => config('api.forum.qna'), 70 'article_title' => $request_data['title'], 71 'article_opt1' => $request_data['category_id'], 72 'fu_id' => auth()->id(), 73 'open_yn' => 'Y', 74 ]); 75 $article->saveOrFail(); 76 77 $forum_text = $article->text()->make(['article_text' => $request_data['content']]); 78 $forum_text->saveOrFail(); 79 }); 80 81 return $this->responseOnlyMessage(\LittlefoxLocalization::lang('api_forum_qna_store_success_msg')); 82 } 83} 84
試したこと
$query->whereRaw('DBMS_LOB.INSTR('.$query->qualifyColumn('article_text').', ?) > 0', [Forum\Text::escapeText($request_data['content'])]);
デバッグして、この行でエラーがあることを確認。Oracleのこの書き方をMariaDBに変えたいが、どう編集すればいいのか困っている。
補足情報(FW/ツールのバージョンなど)
Laravel5.7, MariaDB10.3
こちらの質問が複数のユーザーから「過去の低評価」という指摘を受けました。
回答2件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
退会済みユーザー
2022/03/10 04:33
2022/03/10 04:57
退会済みユーザー
2022/03/10 05:09