Commit 50fc9b3b authored by Olivier Bertrand's avatar Olivier Bertrand

- Fix null handling for date columns (see MDEV-6744)

modified:
  storage/connect/ha_connect.cc
  storage/connect/plgdbutl.cpp
  storage/connect/value.cpp
  storage/connect/value.h
parent 7531f22a
...@@ -1840,6 +1840,7 @@ int ha_connect::ScanRecord(PGLOBAL g, uchar *buf) ...@@ -1840,6 +1840,7 @@ int ha_connect::ScanRecord(PGLOBAL g, uchar *buf)
} // endswitch type } // endswitch type
((DTVAL*)sdvalin)->SetFormat(g, fmt, strlen(fmt)); ((DTVAL*)sdvalin)->SetFormat(g, fmt, strlen(fmt));
sdvalin->SetNullable(colp->IsNullable());
fp->val_str(&attribute); fp->val_str(&attribute);
sdvalin->SetValue_psz(attribute.c_ptr_safe()); sdvalin->SetValue_psz(attribute.c_ptr_safe());
value->SetValue_pval(sdvalin); value->SetValue_pval(sdvalin);
......
...@@ -730,6 +730,7 @@ int ExtractDate(char *dts, PDTP pdp, int defy, int val[6]) ...@@ -730,6 +730,7 @@ int ExtractDate(char *dts, PDTP pdp, int defy, int val[6])
char *fmt, c, d, e, W[8][12]; char *fmt, c, d, e, W[8][12];
int i, k, m, numval; int i, k, m, numval;
int n, y = 30; int n, y = 30;
bool b = true; // true for null dates
if (pdp) if (pdp)
fmt = pdp->InFmt; fmt = pdp->InFmt;
...@@ -763,7 +764,8 @@ int ExtractDate(char *dts, PDTP pdp, int defy, int val[6]) ...@@ -763,7 +764,8 @@ int ExtractDate(char *dts, PDTP pdp, int defy, int val[6])
m = pdp->Num; m = pdp->Num;
for (i = 0; i < m; i++) { for (i = 0; i < m; i++) {
n = *(int*)W[i]; if ((n = *(int*)W[i]))
b = false;
switch (k = pdp->Index[i]) { switch (k = pdp->Index[i]) {
case 0: case 0:
...@@ -822,7 +824,7 @@ int ExtractDate(char *dts, PDTP pdp, int defy, int val[6]) ...@@ -822,7 +824,7 @@ int ExtractDate(char *dts, PDTP pdp, int defy, int val[6])
htrc("numval=%d val=(%d,%d,%d,%d,%d,%d)\n", htrc("numval=%d val=(%d,%d,%d,%d,%d,%d)\n",
numval, val[0], val[1], val[2], val[3], val[4], val[5]); numval, val[0], val[1], val[2], val[3], val[4], val[5]);
return numval; return (b) ? 0 : numval;
} // end of ExtractDate } // end of ExtractDate
/***********************************************************************/ /***********************************************************************/
......
...@@ -2428,9 +2428,11 @@ bool DTVAL::SetValue_char(char *p, int n) ...@@ -2428,9 +2428,11 @@ bool DTVAL::SetValue_char(char *p, int n)
if (trace > 1) if (trace > 1)
htrc(" setting date: '%s' -> %d\n", Sdate, Tval); htrc(" setting date: '%s' -> %d\n", Sdate, Tval);
Null = false; Null = (Nullable && ndv == 0);
} else } else {
rc = TYPVAL<int>::SetValue_char(p, n); rc = TYPVAL<int>::SetValue_char(p, n);
Null = (Nullable && Tval == 0);
} // endif Pdtp
return rc; return rc;
} // end of SetValue } // end of SetValue
...@@ -2453,9 +2455,11 @@ void DTVAL::SetValue_psz(PSZ p) ...@@ -2453,9 +2455,11 @@ void DTVAL::SetValue_psz(PSZ p)
if (trace > 1) if (trace > 1)
htrc(" setting date: '%s' -> %d\n", Sdate, Tval); htrc(" setting date: '%s' -> %d\n", Sdate, Tval);
Null = false; Null = (Nullable && ndv == 0);
} else } else {
TYPVAL<int>::SetValue_psz(p); TYPVAL<int>::SetValue_psz(p);
Null = (Nullable && Tval == 0);
} // endif Pdtp
} // end of SetValue } // end of SetValue
...@@ -2496,7 +2500,7 @@ char *DTVAL::GetCharString(char *p) ...@@ -2496,7 +2500,7 @@ char *DTVAL::GetCharString(char *p)
} else } else
sprintf(p, "%d", Tval); sprintf(p, "%d", Tval);
Null = false; //Null = false; ??????????????
return p; return p;
} // end of GetCharString } // end of GetCharString
...@@ -2507,24 +2511,29 @@ char *DTVAL::ShowValue(char *buf, int len) ...@@ -2507,24 +2511,29 @@ char *DTVAL::ShowValue(char *buf, int len)
{ {
if (Pdtp) { if (Pdtp) {
char *p; char *p;
size_t m, n = 0;
struct tm tm, *ptm = GetGmTime(&tm);
if (Len < len) {
p = buf;
m = len;
} else {
p = Sdate;
m = Len + 1;
} // endif Len
if (ptm) if (!Null) {
n = strftime(p, m, Pdtp->OutFmt, ptm); size_t m, n = 0;
struct tm tm, *ptm = GetGmTime(&tm);
if (Len < len) {
p = buf;
m = len;
} else {
p = Sdate;
m = Len + 1;
} // endif Len
if (ptm)
n = strftime(p, m, Pdtp->OutFmt, ptm);
if (!n) {
*p = '\0';
strncat(p, "Error", m);
} // endif n
if (!n) { } else
*p = '\0'; p = ""; // DEFAULT VALUE ???
strncat(p, "Error", m);
} // endif n
return p; return p;
} else } else
......
...@@ -357,6 +357,7 @@ class DllExport DTVAL : public TYPVAL<int> { ...@@ -357,6 +357,7 @@ class DllExport DTVAL : public TYPVAL<int> {
DTVAL(PGLOBAL g, double f); DTVAL(PGLOBAL g, double f);
// Implementation // Implementation
virtual bool IsZero(void) {return Null;}
virtual bool SetValue_pval(PVAL valp, bool chktype); virtual bool SetValue_pval(PVAL valp, bool chktype);
virtual bool SetValue_char(char *p, int n); virtual bool SetValue_char(char *p, int n);
virtual void SetValue_psz(PSZ s); virtual void SetValue_psz(PSZ s);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment