[jdbc] SQLite - Fix insert time format when using persist method of an item (#18407)
Signed-off-by: Zhivka Dimova <zhivka.dimova@myforest.net>pull/17271/head
parent
2ab57c6b2d
commit
6e0c43b2e7
|
@ -42,6 +42,8 @@ public class JdbcSqliteDAO extends JdbcBaseDAO {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(JdbcSqliteDAO.class);
|
private final Logger logger = LoggerFactory.getLogger(JdbcSqliteDAO.class);
|
||||||
|
|
||||||
|
private static final String DATETIME_FORMAT = "'%Y-%m-%d %H:%M:%f'";
|
||||||
|
|
||||||
/********
|
/********
|
||||||
* INIT *
|
* INIT *
|
||||||
********/
|
********/
|
||||||
|
@ -66,7 +68,7 @@ public class JdbcSqliteDAO extends JdbcBaseDAO {
|
||||||
*/
|
*/
|
||||||
private void initSqlTypes() {
|
private void initSqlTypes() {
|
||||||
logger.debug("JDBC::initSqlTypes: Initialize the type array");
|
logger.debug("JDBC::initSqlTypes: Initialize the type array");
|
||||||
sqlTypes.put("tablePrimaryValue", "strftime('%Y-%m-%d %H:%M:%f' , 'now' , 'localtime')");
|
sqlTypes.put("tablePrimaryValue", "strftime(" + DATETIME_FORMAT + " , 'now', 'localtime')");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,10 +132,13 @@ public class JdbcSqliteDAO extends JdbcBaseDAO {
|
||||||
ItemVO storedVO = storeItemValueProvider(item, itemState, vo);
|
ItemVO storedVO = storeItemValueProvider(item, itemState, vo);
|
||||||
String sql = StringUtilsExt.replaceArrayMerge(sqlInsertItemValue,
|
String sql = StringUtilsExt.replaceArrayMerge(sqlInsertItemValue,
|
||||||
new String[] { "#tableName#", "#dbType#", "#tablePrimaryValue#" },
|
new String[] { "#tableName#", "#dbType#", "#tablePrimaryValue#" },
|
||||||
new String[] { formattedIdentifier(storedVO.getTableName()), storedVO.getDbType(), "?" });
|
new String[] { formattedIdentifier(storedVO.getTableName()), storedVO.getDbType(),
|
||||||
java.sql.Timestamp timestamp = new java.sql.Timestamp(date.toInstant().toEpochMilli());
|
"strftime(" + DATETIME_FORMAT + " , ?, 'unixepoch', 'localtime')" });
|
||||||
Object[] params = { timestamp, storedVO.getValue() };
|
|
||||||
logger.debug("JDBC::doStoreItemValue sql={} timestamp={} value='{}'", sql, timestamp, storedVO.getValue());
|
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 {
|
try {
|
||||||
Yank.execute(sql, params);
|
Yank.execute(sql, params);
|
||||||
} catch (YankSQLException e) {
|
} catch (YankSQLException e) {
|
||||||
|
|
Loading…
Reference in New Issue