[sqlapi-announce] ! the correct patch file ! SQLAPI++ library 5.1.1 bugfix (SADateTime initialization)

  • From: "Sergey Chumakov" <dmarc-noreply-nopost@xxxxxxxxxxxxx> (Redacted sender "sergey.chumakov" for DMARC)
  • To: sqlapi-announce@xxxxxxxxxxxxx <sqlapi-announce@xxxxxxxxxxxxx>
  • Date: Fri, 4 Sep 2020 07:21:07 +0000

! the correct patch file !

2020-09-04

-- General: Fixed some SADateTime initialization variants (thanks Jesús 
Malo Poyatos, Georgiy Pakhutin).

Use attached file for 5.1.1 sources patching. It fixes SADateTime(doble) 
constructor and an unwanted exception thrown with 
SQLAPI_DATETIME_WRONG_EXCEPTION build option used.

-- 
Best regards,
Sergey Chumakov, SQLAPI++ development team

 src/SADateTime.cpp | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/SADateTime.cpp b/src/SADateTime.cpp
index a936666..47d194c 100644
--- a/src/SADateTime.cpp
+++ b/src/SADateTime.cpp
@@ -389,7 +389,9 @@ SADateTime::SADateTime(double dt/*!< Floating-point value, 
measuring days from m
         throw SAException(SA_Library_Error, SA_Library_Error_WrongDatetime, 
-1, IDS_DATETIME_WRONG_ERROR);
 #else
         Init_Tm();
-#endif         
+#endif
+
+    m_parts.hasDate = m_parts.hasTime = true;
 }
 
 /*!
@@ -498,7 +500,7 @@ void SADateTime::Init(int nYear, int nMonth, int nDay, int 
nHour, int nMin, int
     m_timezone = timezone;
 
     // Validate year and month
-    if (nYear > 9999 || nMonth < 1 || nMonth > 12)
+    if ((nYear > 9999 || nMonth < 1 || nMonth > 12) && m_parts.hasDate)
 #ifdef SQLAPI_DATETIME_WRONG_EXCEPTION
         throw SAException(SA_Library_Error, SA_Library_Error_WrongDatetime, 
-1, IDS_DATETIME_WRONG_ERROR);
 #else
@@ -514,9 +516,9 @@ void SADateTime::Init(int nYear, int nMonth, int nDay, int 
nHour, int nMin, int
         ((bLeapYear && nDay == 29 && nMonth == 2) ? 1 : 0);
 
     // Finish validating the date
-    if (nDay < 1 || nDay > nDaysInMonth ||
+    if ((nDay < 1 || nDay > nDaysInMonth ||
         nHour > 23 || nMin > 59 ||
-        nSec > 59)
+        nSec > 59) && m_parts.hasTime)
 #ifdef SQLAPI_DATETIME_WRONG_EXCEPTION
         throw SAException(SA_Library_Error, SA_Library_Error_WrongDatetime, 
-1, IDS_DATETIME_WRONG_ERROR);
 #else
@@ -543,38 +545,38 @@ void SADateTime::Init(int nYear, int nMonth, int nDay, 
int nHour, int nMin, int
 
 SADateTime::SADateTime(int nYear, int nMonth, int nDay)
 {
+    m_parts.hasDate = true;  m_parts.hasTime = false;
     Init(nYear, nMonth, nDay, 0, 0, 0, 0, _TSA(""));
-       m_parts.hasDate = true;  m_parts.hasTime = false;
 }
 
 SADateTime::SADateTime(int nYear, int nMonth, int nDay, int nHour, int nMin, 
int nSec)
 {
+    m_parts.hasDate = true;  m_parts.hasTime = true;
     Init(nYear, nMonth, nDay, nHour, nMin, nSec, 0, _TSA(""));
-       m_parts.hasDate = true;  m_parts.hasTime = true;
 }
 
 SADateTime::SADateTime(int nYear, int nMonth, int nDay, int nHour, int nMin, 
int nSec, unsigned int nFraction)
 {
+    m_parts.hasDate = true;  m_parts.hasTime = true;
     Init(nYear, nMonth, nDay, nHour, nMin, nSec, nFraction, _TSA(""));
-       m_parts.hasDate = true;  m_parts.hasTime = true;
 }
 
 SADateTime::SADateTime(int nYear, int nMonth, int nDay, int nHour, int nMin, 
int nSec, const SAChar* timezone)
 {
+    m_parts.hasDate = true;  m_parts.hasTime = true;
     Init(nYear, nMonth, nDay, nHour, nMin, nSec, 0, timezone);
-       m_parts.hasDate = true;  m_parts.hasTime = true;
 }
 
 SADateTime::SADateTime(int nYear, int nMonth, int nDay, int nHour, int nMin, 
int nSec, unsigned int nFraction, const SAChar* timezone)
 {
+    m_parts.hasDate = true;  m_parts.hasTime = true;
     Init(nYear, nMonth, nDay, nHour, nMin, nSec, nFraction, timezone);
-       m_parts.hasDate = true;  m_parts.hasTime = true;
 }
 
 SADateTime::SADateTime(int nHour, int nMin, int nSec, unsigned int nFraction)
 {
+    m_parts.hasDate = false;  m_parts.hasTime = true;
     Init(0, 0, 0, nHour, nMin, nSec, nFraction, _TSA(""));
-       m_parts.hasDate = false;  m_parts.hasTime = true;
 }
 
 unsigned int SADateTime::Fraction() const

Other related posts:

  • » [sqlapi-announce] ! the correct patch file ! SQLAPI++ library 5.1.1 bugfix (SADateTime initialization) - Sergey Chumakov