Skip to content

MariaDB - failed select in DbDBI.pm #31

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

Open
zbchristian opened this issue Feb 24, 2025 · 2 comments
Open

MariaDB - failed select in DbDBI.pm #31

zbchristian opened this issue Feb 24, 2025 · 2 comments

Comments

@zbchristian
Copy link

zbchristian commented Feb 24, 2025

I am running the API V2 server in a docker container with MariaDB and ran into a problem.

In the module DbDBI.pm, the selection of the owner from the table ovms_owners fails due to a mistake in the WHERE clause in DbOwnerNameByID, DBOwnerIDByName and DbOwnerNameByID:
SELECT * FROM ovms_owners WHERE owner=? and status=1 AND deleted="0000-00-00 00:00:00"

The column deleted is a tinyint(1) and not of type datetime, so the select is always empty, at least in MariaDB.

So the select statement should look like: SELECT * FROM ovms_owners WHERE owner=? and status=1 AND deleted=0

Not sure, why this was not observed before. Might be related to the treatment by MariaDB

@dexterbg
Copy link
Member

While the query may strictly be seen as incorrect or at least misleading, MariaDB just as MySQL normally compares an integer to a string by converting both to a double precision float. So deleted="0000-00-00 00:00:00" normally works just fine:

MariaDB [dexter]> select 0="0000-00-00 00:00:00", 1!="0000-00-00 00:00:00", 1="1.0ABC", 1="1.1ABC";
+-------------------------+--------------------------+------------+------------+
| 0="0000-00-00 00:00:00" | 1!="0000-00-00 00:00:00" | 1="1.0ABC" | 1="1.1ABC" |
+-------------------------+--------------------------+------------+------------+
|                       1 |                        1 |          1 |          0 |
+-------------------------+--------------------------+------------+------------+

If it doesn't in your case, you most probably have a custom MariaDB configuration, be aware that may then affect other queries & statements as well.

Feel free to post a PR.

@zbchristian
Copy link
Author

@dexterbg The container is the official mariadb:latest , which is version 10.6.2, without any modifications.
You are correct, that the implicit cast should take care of this.
Not sure, why this fails in my setting. Have to check the defaults of the container

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