openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.87k stars 3.58k forks source link

[jdbc.mysql] Persistence works not safely with images #10077

Open JensHoRi opened 3 years ago

JensHoRi commented 3 years ago

Field-Length for storage of items from TYPE IMAGE is actual VARCHAR, not long enough if for example Datanbase is UTF-8 or Image is to big.

So Type of value-Field should be BLOB.

Tested successfully with adding sqltype.IMAGE = BLOB in jdbc.cfg

https://community.openhab.org/t/oh3-issue-jdbc-mysql-table-creation-for-image-item/113474

Option a (quick-win) Change

openhab-addons/bundles/org.openhab.persistence.jdbc/src/main/resources/OH-INF/config/

adding sqltype.IMAGE = BLOB

Option b) Change default for item type IMAGE (didn't found where they are defined)

cweitkamp commented 3 years ago

@mhilbush Do you like to jump in?

mhilbush commented 3 years ago

I'm not sure what to do about this. While I'm no database expert, there are a few things worth considering.

TINYBLOB (255 B) BLOB (64 KB) MEDIUMBLOB (16 MB) LONGBLOB (4 GB)

So, at a minimum, it might make sense to discuss this in the documentation, especially since the blob support will vary across db platforms. We also could describe how the user can set the sqltype.IMAGE config parameter to suit their specific need. In fact, I missed updating the README here when I did my PR.

WDYT?

JensHoRi commented 3 years ago

Sorry for late reply. As default BLOB and in Documentation a hint for larger Images would be great. In my case BLOB is able to save much bigger images as VARCHAR can, because VARCHAR depends on charsets in system / mysql.

foobar26 commented 2 years ago

Just want to add that the image type - even if you change the db column type to BLOB - currently isn't stored correctly (see #11148). So even small images where the current default db column type VARCHAR would be sufficient cannot be stored/restored correctly.

lsiepel commented 9 months ago

If i understand it correctly, the default db type for images should not be changed. Maybe a documentation can be made, any suggestion of the text? Maybe a paragraph in https://www.openhab.org/addons/persistence/jdbc/#technical-notes would be good.