1

Phpunit detects an error on my query

SQLSTATE[HY000]: General error: 1 near "(": syntax error (SQL:
    select * from "forms"
    where "factual_checkout_at" is null
    and "plan_checkout_at" >= ?
    and CONCAT(UPPER(RIGHT(name, 3)), id) = ?
    and "forms"."deleted_at" is null and "forms"."type" in (?, ?, ?) limit 1
)

I'm trying to get a form with given code. (In this case I combine last 3 digit of user's name with their id).

The problem is, my app runs well with this query, the transaction goes well, but not on phpunit.

Here's the method to get that form (laravel):

$form = Form::whereNull('factual_checkout_at')
            ->where('plan_checkout_at', '>=', Carbon::today())
            ->whereRaw('CONCAT(UPPER(RIGHT(name, 3)), id) = ?', $code)
            ->firstOrFail();
return new FormResource($form);

What did I miss?
Thanks in advance!

4
  • 1
    what database driver are you using in for your unit testing? Commented Mar 16, 2018 at 8:38
  • i use sqlite for unit test Commented Mar 16, 2018 at 8:40
  • CONCAT keyword is not available for SQLite. Commented Mar 16, 2018 at 8:40
  • Well, how fool I am. Thanks! Commented Mar 16, 2018 at 8:48

1 Answer 1

1

So I did miss on my query syntax, because I use sqlite on my test.

Changed the query to

... and upper(substr(name, -3)) || id = ? ...

fixed that. Thanks to @Wreigh!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.