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

[jdbc.mysql] Parameter tableIdDigitCount is ignored when set to 0 #9339

Closed
bubuche79 opened this issue Nov 23, 2019 · 2 comments
Closed

[jdbc.mysql] Parameter tableIdDigitCount is ignored when set to 0 #9339

bubuche79 opened this issue Nov 23, 2019 · 2 comments
Labels
bug An unexpected problem or unintended behavior of an add-on

Comments

@bubuche79
Copy link

Hello,

In services/jdbc.cfg, when using 0 for tableIdDigitCount:

# Tablename Prefix generation, using Item real names or "item" (optional, default: false -> "item") 
# If true, 'tableNamePrefix' is ignored.
tableUseRealItemNames=true

# Tablename Suffix length (optional, default: 4 -> 0001-9999) 
# for Migration from MYSQL-Bundle set to 0.
tableIdDigitCount=0

And using this persistence/jdbc.persist file:

Strategies {
	everyHour : "0 0 * * * ?"
	default = everyChange
}

Items {
	Heating_Energy, Total_Energy : strategy = everyHour
}

I am expecting tables heating_energy and total_energy, but I'm getting heating_energy_$id1 and total_energy_$id2 instead. That would avoid dynamic (and unpredictable) tables names.

This is already pointed out by:

In addition, why ignoring tableNamePrefix when tableUseRealItemNames is true? Prefixing all openhab tables (by "items" or whatever) would ensure that they won't be any naming clash with other objects in the schema (if I want to create other tables or views for example).

Thanks!

Note: I am using OpenHAB 2.5.0 M5.

@bubuche79 bubuche79 changed the title Parameter ignored in persistence service [persistence] Parameter tableIdDigitCount is ignored when set to 0 Nov 23, 2019
@wborn wborn transferred this issue from openhab/openhab-addons Nov 24, 2019
@9037568 9037568 changed the title [persistence] Parameter tableIdDigitCount is ignored when set to 0 [JDBC Persistence] Parameter tableIdDigitCount is ignored when set to 0 Nov 24, 2019
@nimric
Copy link
Contributor

nimric commented Oct 27, 2020

I just encountered the same issue. The tableIdDigitCount should be ignored when set to 0 if tableUseRealItemNames is enabled.

@cweitkamp cweitkamp changed the title [JDBC Persistence] Parameter tableIdDigitCount is ignored when set to 0 [jdbc.mysql] Parameter tableIdDigitCount is ignored when set to 0 Dec 12, 2020
@cweitkamp cweitkamp self-assigned this Dec 12, 2020
@cweitkamp cweitkamp transferred this issue from openhab/openhab1-addons Dec 12, 2020
@cweitkamp cweitkamp added the bug An unexpected problem or unintended behavior of an add-on label Dec 12, 2020
@cweitkamp cweitkamp removed their assignment Apr 15, 2021
@jlaur
Copy link
Contributor

jlaur commented Nov 15, 2022

The behavior is documented:

Property Default Required Description
tableIdDigitCount 4 No when tableUseRealItemNames is false and thus table names are generated sequentially, this controls how many zero-padded digits are used in the table name. With the default of 4, the first table name will end with 0001. For migration from the MySQL persistence service, set this to 0.

However, with #13544 a new option was introduced:

Property Default Required Description
tableCaseSensitiveItemNames false No table name case when tableUseRealItemNames is true. When set to true, item name case is preserved in table names and no suffix is used. When set to false, table names are lower cased and a numeric suffix is added. Please read this before enabling.

The only thing missing:

In addition, why ignoring tableNamePrefix when tableUseRealItemNames is true? Prefixing all openhab tables (by "items" or whatever) would ensure that they won't be any naming clash with other objects in the schema (if I want to create other tables or views for example).

Currently it is (perhaps implicitly) assumed that JDBC Persistence Service will have its own schema. I will add a note in the README emphasizing this need especially for tableCaseSensitiveItemNames because of increased risk of collisions.

If there are strong arguments/need for co-existence in the same schema when using tableCaseSensitiveItemNames, I would suggest creating a new issue specifically for this. There are some obstacles though:

  • Backwards compatibility: We can not redefine the interpretation of the parameters, individually or combined, as this would break existing users' installations.
  • Migrations: Currently migrations need to analyze/assume things about the previous configuration, since only the new configuration is available. As an example, if tableNamePrefix would be changed without using digit suffixes, migration would have no way of finding the item tables (without having an index). See also [jdbc.mysql] MySQL migration - Items table is not used for index but creates a new table called items #9637 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

No branches or pull requests

4 participants