Skip to content
Merged
Changes from 6 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 @@ -42,6 +42,8 @@ public class JdbcSqliteDAO extends JdbcBaseDAO {

private final Logger logger = LoggerFactory.getLogger(JdbcSqliteDAO.class);

private static final String datetimeFormat = "'%Y-%m-%d %H:%M:%f'";

/********
* INIT *
********/
Expand All @@ -66,7 +68,7 @@ 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("tablePrimaryValue", "strftime(" + datetimeFormat + " , 'now', 'localtime')");
}

/**
Expand Down Expand Up @@ -130,10 +132,13 @@ 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(),
"strftime(" + datetimeFormat + " , ?, 'unixepoch', 'localtime')" });

double epochSecondsWithMillis = date.toInstant().toEpochMilli() / 1_000.0;
Object[] params = { epochSecondsWithMillis, storedVO.getValue() };
logger.debug("JDBC::doStoreItemValue sql={} epochSecondsWithMillis={} value='{}'", sql, epochSecondsWithMillis,
storedVO.getValue());
try {
Yank.execute(sql, params);
} catch (YankSQLException e) {
Expand Down