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

insertGet return null if MySQL table contains JSON type field #153

Open
RGBvision opened this issue Dec 8, 2022 · 3 comments
Open

insertGet return null if MySQL table contains JSON type field #153

RGBvision opened this issue Dec 8, 2022 · 3 comments

Comments

@RGBvision
Copy link

insertGet('table', ['text_field' => 'text', 'json_field' => json_encode([1,2,3])], 'id') will not return 'id'

@paragonie-security
Copy link
Contributor

Does your table have an id field? The JSON is likely a red herring.

@RGBvision
Copy link
Author

Does your table have an id field? The JSON is likely a red herring.

Yep. id - INT (autoincrement) and primary key. insertGet work as expected if I change JSON data type to TEXT. But in this case I can't use benefits of JSON fields.

@paragonie-security
Copy link
Contributor

Oh, interesting.

easydb/src/EasyDB.php

Lines 691 to 709 in 7976058

// We want the latest value:
$limiter = match ($this->dbEngine) {
'mysql' => ' ORDER BY ' .
$this->escapeIdentifier($field) .
' DESC LIMIT 0, 1 ',
'pgsql' => ' ORDER BY ' .
$this->escapeIdentifier($field) .
' DESC OFFSET 0 LIMIT 1 ',
default => '',
};
/** @psalm-taint-escape sql */
$query = 'SELECT ' .
$this->escapeIdentifier($field) .
' FROM ' .
$this->escapeIdentifier($table) .
' WHERE ' .
$conditions .
$limiter;
return $this->single($query, $params);

This logic might be invalid for a JSON field.

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

No branches or pull requests

2 participants