brouznouf / fivem-mysql-async

MySql Async Library for FiveM
MIT License
111 stars 106 forks source link

SELECT query inside INSERT query #168

Closed KR3KZ closed 3 years ago

KR3KZ commented 3 years ago

Describe the bug MySQL async do not accept SELECT query inside INSERT query

To Reproduce

-- this doesnt works
local type = 'licence'
local id = '64499c693ce22a57b735a4c56ac3c1fc8e0be406'
MySQL.Async.execute(
"INSERT INTO user (fivem_id, license_type) VALUES (@id, (SELECT id FROM license_type WHERE name = @type))",
{
  ['id'] = id,
  ['type'] = type
})

This query should work but see the image below.

But a SELECT query inside a SELECT query works, as it should!

-- this works
MySQL.Async.fetchAll(
"SELECT * FROM user WHERE fivem_id = @id AND license_type = (SELECT id FROM license_type WHERE name = @type)",
{
  ['id'] = id,
  ['type'] = type
}       

Expected behavior The query should be executed just fine, I don't know why it doesn't work, it's basic SQL stuff.

Screenshots / Logs image

I did try to allow NULL on license_type so the query runs, but the the data created was this: image

Software:

KR3KZ commented 3 years ago

I'm just so dumb. I typed licence instead of license. It's working perfectly.