This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
The following commit(s) were added to refs/heads/master by this push:
new ee005909 Prevent the discard of fractional timestamp seconds when the
ODBCappender target is postgresSQL (#208)
ee005909 is described below
commit ee005909f61438fb80190f0fa7045cd17262f37c
Author: Stephen Webb <[email protected]>
AuthorDate: Fri Apr 28 13:08:17 2023 +1000
Prevent the discard of fractional timestamp seconds when the ODBCappender
target is postgresSQL (#208)
---
src/main/cpp/odbcappender.cpp | 37 ++++++++++++++++++----
.../input/xml/odbcAppenderDSN-Log4cxxTest.xml | 8 ++---
2 files changed, 34 insertions(+), 11 deletions(-)
diff --git a/src/main/cpp/odbcappender.cpp b/src/main/cpp/odbcappender.cpp
index 79f647f9..b5202c6b 100644
--- a/src/main/cpp/odbcappender.cpp
+++ b/src/main/cpp/odbcappender.cpp
@@ -346,7 +346,29 @@ ODBCAppender::SQLHDBC
ODBCAppender::getConnection(log4cxx::helpers::Pool& p)
throw ex;
}
-
+#if LOG4CXX_LOGCHAR_IS_WCHAR
+ SQLWCHAR *wUser = nullptr, *wPwd = nullptr;
+ if (!_priv->databaseUser.empty())
+ wUser = (SQLWCHAR*)_priv->databaseUser.c_str();
+ if (!_priv->databasePassword.empty())
+ wPwd = (SQLWCHAR*)_priv->databasePassword.c_str();
+ ret = SQLConnectW(_priv->connection
+ , (SQLWCHAR*)_priv->databaseURL.c_str(), SQL_NTS
+ , wUser, SQL_NTS
+ , wPwd, SQL_NTS
+ );
+#elif LOG4CXX_LOGCHAR_IS_UTF8
+ SQLCHAR *wUser = nullptr, *wPwd = nullptr;
+ if (!_priv->databaseUser.empty())
+ wUser = (SQLCHAR*)_priv->databaseUser.c_str();
+ if (!_priv->databasePassword.empty())
+ wPwd = (SQLCHAR*)_priv->databasePassword.c_str();
+ ret = SQLConnectA(_priv->connection
+ , (SQLCHAR*)_priv->databaseURL.c_str(), SQL_NTS
+ , wUser, SQL_NTS
+ , wPwd, SQL_NTS
+ );
+#else
SQLWCHAR* wURL, *wUser = nullptr, *wPwd = nullptr;
encode(&wURL, _priv->databaseURL, p);
if (!_priv->databaseUser.empty())
@@ -354,11 +376,12 @@ ODBCAppender::SQLHDBC
ODBCAppender::getConnection(log4cxx::helpers::Pool& p)
if (!_priv->databasePassword.empty())
encode(&wPwd, _priv->databasePassword, p);
- ret = SQLConnectW( _priv->connection,
- wURL, SQL_NTS,
- wUser, SQL_NTS,
- wPwd, SQL_NTS);
-
+ ret = SQLConnectW( _priv->connection
+ , wURL, SQL_NTS
+ , wUser, SQL_NTS
+ , wPwd, SQL_NTS
+ );
+#endif
if (ret < 0)
{
@@ -472,7 +495,7 @@ void
ODBCAppender::ODBCAppenderPriv::setPreparedStatement(SQLHDBC con, Pool& p)
|| SQL_DATETIME == targetType)
{
item.paramType = SQL_C_TYPE_TIMESTAMP;
- item.paramMaxCharCount = decimalDigits;
+ item.paramMaxCharCount = (0 <= decimalDigits) ?
decimalDigits : 6;
item.paramValueSize = sizeof(SQL_TIMESTAMP_STRUCT);
item.paramValue =
(SQLPOINTER)p.palloc(item.paramValueSize);
}
diff --git a/src/test/resources/input/xml/odbcAppenderDSN-Log4cxxTest.xml
b/src/test/resources/input/xml/odbcAppenderDSN-Log4cxxTest.xml
index 781bd84e..c82c63ba 100644
--- a/src/test/resources/input/xml/odbcAppenderDSN-Log4cxxTest.xml
+++ b/src/test/resources/input/xml/odbcAppenderDSN-Log4cxxTest.xml
@@ -27,11 +27,13 @@
</appender>
<appender name="PatternAppender" class="ODBCAppender">
<param name="DSN" value="Log4cxxTest"/>
- <param name="sql" value="INSERT INTO [ApplicationLogs].[dbo].[UnitTestLog]
([Thread],[LogName],[LogTime],[LogLevel],[FileName],[FileLine],[Message])
VALUES ('%t','%c','%d{yyyy-MM-dd HH:mm:ss.SSSSSS}','%p','%f','%L','%m{'}')" />
+ <param name="sql" value="INSERT INTO UnitTestLog
(Thread,LogName,LogTime,LogLevel,FileName,FileLine,Message) VALUES
('%t','%c','%d{yyyy-MM-dd HH:mm:ss.SSSSSS}','%p','%f','%L','%m{'}')" />
+ <!--param name="sql" value="INSERT INTO ApplicationLogs.dbo.UnitTestLog
(Thread,LogName,LogTime,LogLevel,FileName,FileLine,Message) VALUES
('%t','%c','%d{yyyy-MM-dd HH:mm:ss.SSSSSS}','%p','%f','%L','%m{'}')" /-->
</appender>
<appender name="PreparedAppender" class="ODBCAppender">
<param name="DSN" value="Log4cxxTest"/>
- <param name="sql" value="INSERT INTO [ApplicationLogs].[dbo].[UnitTestLog]
([Thread],[LogName],[LogTime],[LogLevel],[FileName],[FileLine],[Message])
VALUES (?,?,?,?,?,?,?)" />
+ <param name="sql" value="INSERT INTO UnitTestLog
(Thread,LogName,LogTime,LogLevel,FileName,FileLine,Message) VALUES
(?,?,?,?,?,?,?)" />
+ <!--param name="sql" value="INSERT INTO ApplicationLogs.dbo.UnitTestLog
(Thread,LogName,LogTime,LogLevel,FileName,FileLine,Message) VALUES
(?,?,?,?,?,?,?)" /-->
<param name="ColumnMapping" value="thread"/>
<param name="ColumnMapping" value="logger"/>
<param name="ColumnMapping" value="time"/>
@@ -39,8 +41,6 @@
<param name="ColumnMapping" value="shortfilename"/>
<param name="ColumnMapping" value="line"/>
<param name="ColumnMapping" value="message"/>
- <!--param name="User" value="dbo"/-->
- <!--param name="Password" value="myLog4cxxTestPassword"/-->
</appender>
<appender name="ASYNC" class="AsyncAppender">
<param name="BufferSize" value="1000"/>