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 SQL type error #104

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Fix SQL type error #104

wants to merge 4 commits into from

Conversation

hissy
Copy link
Contributor

@hissy hissy commented Mar 29, 2024

Fixes #102, #57, #47

This PR converts values to integers when the table column type is an integer.

You can test this fix by adding an image slider block with entries with no images selected.

Cast int values before save
@@ -35,13 +38,30 @@ public function publish(Batch $batch, $bt, Page $page, $area, BlockValue $value)
}
// Now we import the OTHER records.
if ($b) {
$app = Application::getFacadeApplication();
/** @var Connection $connection */
$connection = $app->make(Connection::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a hard dependency of this class instead of relying on the service locator? IE:

protected $db;

public function __construct(Connection $db)
{
    $this->db = $db;
}

Comment on lines 54 to 62
if ($column->getName() === $key) {
if ($column->getType()->getName() === Type::INTEGER) {
if ($column->getNotnull()) {
$value = (int) $value;
} else {
$value = $value === null ? null : (int) $value;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($column->getName() === $key) {
if ($column->getType()->getName() === Type::INTEGER) {
if ($column->getNotnull()) {
$value = (int) $value;
} else {
$value = $value === null ? null : (int) $value;
}
}
}
if (
$column->getName() !== $key ||
$column->getType()->getName() === Type::INTEGER
) {
continue;
}
$value = ($column->getNotNull() || $column !== null) : (int) $value : null;
break;

Using an early return (early continue) is more readable to me here, also worth breaking when the proper column is matched

@hissy
Copy link
Contributor Author

hissy commented Mar 30, 2024

@KorvinSzanto

Done.

(BC note: If someone created a custom publisher that uses StandardPublisher as fallback, they must change their code)

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.

Empty values in the xml
2 participants