Fix PostgreSQL query for storing timestamps (#13745)

Fixes #13121

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2022-11-19 20:57:51 +01:00 committed by GitHub
parent c9b9002b8e
commit d3348327a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 0 deletions

View File

@ -13,6 +13,7 @@
package org.openhab.persistence.jdbc.internal.db; package org.openhab.persistence.jdbc.internal.db;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List; import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
@ -167,6 +168,22 @@ public class JdbcPostgresqlDAO extends JdbcBaseDAO {
} }
} }
@Override
public void doStoreItemValue(Item item, State itemState, ItemVO vo, ZonedDateTime date) throws JdbcSQLException {
ItemVO storedVO = storeItemValueProvider(item, itemState, vo);
String sql = StringUtilsExt.replaceArrayMerge(sqlInsertItemValue,
new String[] { "#tableName#", "#dbType#", "#tablePrimaryValue#" },
new String[] { storedVO.getTableName(), storedVO.getDbType(), "?" });
java.sql.Timestamp timestamp = new java.sql.Timestamp(date.toInstant().toEpochMilli());
Object[] params = { timestamp, storedVO.getValue() };
logger.debug("JDBC::doStoreItemValue sql={} timestamp={} value='{}'", sql, timestamp, storedVO.getValue());
try {
Yank.execute(sql, params);
} catch (YankSQLException e) {
throw new JdbcSQLException(e);
}
}
/**************************** /****************************
* SQL generation Providers * * SQL generation Providers *
****************************/ ****************************/