diff options
Diffstat (limited to 'storage/connect/value.cpp')
-rw-r--r-- | storage/connect/value.cpp | 101 |
1 files changed, 76 insertions, 25 deletions
diff --git a/storage/connect/value.cpp b/storage/connect/value.cpp index 60d1c2f459c..a80da808548 100644 --- a/storage/connect/value.cpp +++ b/storage/connect/value.cpp @@ -176,7 +176,7 @@ int GetTypeSize(int type, int len) case TYPE_DOUBLE: len = sizeof(double); break; case TYPE_TINY: len = sizeof(char); break; case TYPE_PCHAR: len = sizeof(char*); break; - default: len = 0; + default: len = -1; } // endswitch type return len; @@ -236,6 +236,7 @@ bool IsTypeChar(int type) switch (type) { case TYPE_STRING: case TYPE_DECIM: + case TYPE_BIN: return true; } // endswitch type @@ -1369,7 +1370,7 @@ bool TYPVAL<PSZ>::SetValue_char(const char *cp, int n) if (!cp || n == 0) { Reset(); - Null = Nullable; + Null = (cp) ? false : Nullable; } else if (cp != Strp) { const char *p = cp + n - 1; @@ -1858,8 +1859,9 @@ int DECVAL::CompareValue(PVAL vp) BINVAL::BINVAL(PGLOBAL g, void *p, int cl, int n) : VALUE(TYPE_BIN) { assert(g); - Len = n; - Clen = cl; +//Len = n; + Len = (g) ? n : (p) ? strlen((char*)p) : 0; + Clen = cl; Binp = PlugSubAlloc(g, NULL, Clen + 1); memset(Binp, 0, Clen + 1); @@ -1992,10 +1994,15 @@ bool BINVAL::SetValue_pval(PVAL valp, bool chktype) return true; if (!(Null = valp->IsNull() && Nullable)) { - if ((rc = (Len = valp->GetSize()) > Clen)) + int len = Len; + + if ((rc = (Len = valp->GetSize()) > Clen)) Len = Clen; + else if (len > Len) + memset(Binp, 0, len); memcpy(Binp, valp->GetTo_Val(), Len); + ((char*)Binp)[Len] = 0; } else Reset(); @@ -2012,10 +2019,15 @@ bool BINVAL::SetValue_char(const char *p, int n) bool rc; if (p && n > 0) { - rc = n > Clen; - Len = MY_MIN(n, Clen); - memcpy(Binp, p, Len); - Null = false; + int len = Len; + + if (len > (Len = MY_MIN(n, Clen))) + memset(Binp, 0, len); + + memcpy(Binp, p, Len); + ((char*)Binp)[Len] = 0; + rc = n > Clen; + Null = false; } else { rc = false; Reset(); @@ -2031,9 +2043,14 @@ bool BINVAL::SetValue_char(const char *p, int n) void BINVAL::SetValue_psz(PCSZ s) { if (s) { - Len = MY_MIN(Clen, (signed)strlen(s)); - memcpy(Binp, s, Len); - Null = false; + int len = Len; + + if (len > (Len = MY_MIN(Clen, (signed)strlen(s)))) + memset(Binp, 0, len); + + memcpy(Binp, s, Len); + ((char*)Binp)[Len] = 0; + Null = false; } else { Reset(); Null = Nullable; @@ -2053,14 +2070,19 @@ void BINVAL::SetValue_pvblk(PVBLK blk, int n) Reset(); Null = Nullable; } else if (vp != Binp) { + int len = Len; + if (blk->GetType() == TYPE_STRING) Len = strlen((char*)vp); else Len = blk->GetVlen(); - Len = MY_MIN(Clen, Len); + if (len > (Len = MY_MIN(Clen, Len))) + memset(Binp, 0, len); + memcpy(Binp, vp, Len); - Null = false; + ((char*)Binp)[Len] = 0; + Null = false; } // endif vp } // end of SetValue_pvblk @@ -2071,7 +2093,10 @@ void BINVAL::SetValue_pvblk(PVBLK blk, int n) void BINVAL::SetValue(int n) { if (Clen >= 4) { - *((int*)Binp) = n; + if (Len > 4) + memset(Binp, 0, Len); + + *((int*)Binp) = n; Len = 4; } else SetValue((short)n); @@ -2084,7 +2109,10 @@ void BINVAL::SetValue(int n) void BINVAL::SetValue(uint n) { if (Clen >= 4) { - *((uint*)Binp) = n; + if (Len > 4) + memset(Binp, 0, Len); + + *((uint*)Binp) = n; Len = 4; } else SetValue((ushort)n); @@ -2097,7 +2125,10 @@ void BINVAL::SetValue(uint n) void BINVAL::SetValue(short i) { if (Clen >= 2) { - *((int*)Binp) = i; + if (Len > 2) + memset(Binp, 0, Len); + + *((int*)Binp) = i; Len = 2; } else SetValue((char)i); @@ -2110,7 +2141,10 @@ void BINVAL::SetValue(short i) void BINVAL::SetValue(ushort i) { if (Clen >= 2) { - *((uint*)Binp) = i; + if (Len > 2) + memset(Binp, 0, Len); + + *((uint*)Binp) = i; Len = 2; } else SetValue((uchar)i); @@ -2123,7 +2157,10 @@ void BINVAL::SetValue(ushort i) void BINVAL::SetValue(longlong n) { if (Clen >= 8) { - *((longlong*)Binp) = n; + if (Len > 8) + memset(Binp, 0, Len); + + *((longlong*)Binp) = n; Len = 8; } else SetValue((int)n); @@ -2136,7 +2173,10 @@ void BINVAL::SetValue(longlong n) void BINVAL::SetValue(ulonglong n) { if (Clen >= 8) { - *((ulonglong*)Binp) = n; + if (Len > 8) + memset(Binp, 0, Len); + + *((ulonglong*)Binp) = n; Len = 8; } else SetValue((uint)n); @@ -2147,6 +2187,9 @@ void BINVAL::SetValue(ulonglong n) /***********************************************************************/ void BINVAL::SetValue(double n) { + if (Len > 8) + memset(Binp, 0, Len); + if (Clen >= 8) { *((double*)Binp) = n; Len = 8; @@ -2163,7 +2206,10 @@ void BINVAL::SetValue(double n) /***********************************************************************/ void BINVAL::SetValue(char c) { - *((char*)Binp) = c; + if (Len > 1) + memset(Binp, 0, Len); + + *((char*)Binp) = c; Len = 1; } // end of SetValue @@ -2172,7 +2218,10 @@ void BINVAL::SetValue(char c) /***********************************************************************/ void BINVAL::SetValue(uchar c) { - *((uchar*)Binp) = c; + if (Len > 1) + memset(Binp, 0, Len); + + *((uchar*)Binp) = c; Len = 1; } // end of SetValue @@ -2182,6 +2231,7 @@ void BINVAL::SetValue(uchar c) void BINVAL::SetBinValue(void *p) { memcpy(Binp, p, Clen); + Len = Clen; } // end of SetBinValue /***********************************************************************/ @@ -2207,10 +2257,11 @@ bool BINVAL::GetBinValue(void *buf, int buflen, bool go) /***********************************************************************/ char *BINVAL::ShowValue(char *buf, int len) { - int n = MY_MIN(Len, len / 2); + //int n = MY_MIN(Len, len / 2); - sprintf(buf, GetXfmt(), n, Binp); - return buf; + //sprintf(buf, GetXfmt(), n, Binp); + //return buf; + return (char*)Binp; } // end of ShowValue /***********************************************************************/ |