Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.openhab.persistence.jdbc.internal.db;

import java.time.ZonedDateTime;
import java.time.temporal.ChronoField;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -67,6 +68,8 @@ private void initSqlQueries() {
private void initSqlTypes() {
logger.debug("JDBC::initSqlTypes: Initialize the type array");
sqlTypes.put("tablePrimaryValue", "strftime('%Y-%m-%d %H:%M:%f' , 'now' , 'localtime')");
sqlTypes.put("tablePrimaryValueFormated",
"strftime('%Y-%m-%d %H:%M:%S' , ?, 'unixepoch', 'localtime') || '.' || ?");
}

/**
Expand Down Expand Up @@ -130,10 +133,15 @@ public void doStoreItemValue(Item item, State itemState, ItemVO vo, ZonedDateTim
ItemVO storedVO = storeItemValueProvider(item, itemState, vo);
String sql = StringUtilsExt.replaceArrayMerge(sqlInsertItemValue,
new String[] { "#tableName#", "#dbType#", "#tablePrimaryValue#" },
new String[] { formattedIdentifier(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());
new String[] { formattedIdentifier(storedVO.getTableName()), storedVO.getDbType(),
sqlTypes.get("tablePrimaryValueFormated") });

java.time.Instant dateInstant = date.toInstant();
long epochSecond = dateInstant.getEpochSecond();
int millis = dateInstant.get(ChronoField.MILLI_OF_SECOND);
Object[] params = { epochSecond, millis, storedVO.getValue() };
logger.debug("JDBC::doStoreItemValue sql={} seconds={} millis={} value='{}'", sql, epochSecond, millis,
storedVO.getValue());
try {
Yank.execute(sql, params);
} catch (YankSQLException e) {
Expand Down