diff options
author | Olivier Bertrand <bertrandop@gmail.com> | 2015-01-06 10:18:04 +0100 |
---|---|---|
committer | Olivier Bertrand <bertrandop@gmail.com> | 2015-01-06 10:18:04 +0100 |
commit | afd373c11951f48f7f9dde9990e7be2c76456559 (patch) | |
tree | 9744ecf79636c1ffd9e59e1bf05d22b2f3649edf /storage/connect/value.cpp | |
parent | 8761f22a11e3ebe9563b93bb79cb65260b177873 (diff) | |
download | mariadb-git-afd373c11951f48f7f9dde9990e7be2c76456559.tar.gz |
- Set connection charset before calling mysql_real_connect for MYSQL
tables. This should fix bug MDEV-7343.
modified:
storage/connect/ha_connect.cc
storage/connect/myconn.cpp
storage/connect/myconn.h
storage/connect/reldef.cpp
storage/connect/reldef.h
storage/connect/table.cpp
storage/connect/tabmysql.cpp
storage/connect/xtable.h
- Prevent double column evaluation when CONNECT does filtering
modified:
storage/connect/connect.cc
- Export CreateFileMap and CloseMemMap (for OEM tables)
modified:
storage/connect/maputil.h
- Add the compute function to be used on VALUE types.
Preserve precision for DOUBLE values.
modified:
storage/connect/value.cpp
storage/connect/value.h
- Typo (in preparation to the future JSON table type)
modified:
storage/connect/ha_connect.cc
storage/connect/mycat.cc
storage/connect/plgdbsem.h
Diffstat (limited to 'storage/connect/value.cpp')
-rw-r--r-- | storage/connect/value.cpp | 236 |
1 files changed, 233 insertions, 3 deletions
diff --git a/storage/connect/value.cpp b/storage/connect/value.cpp index 7227e637a14..3ed58d3e257 100644 --- a/storage/connect/value.cpp +++ b/storage/connect/value.cpp @@ -330,7 +330,7 @@ int ConvertType(int target, int type, CONV kind, bool match) /***********************************************************************/ /* AllocateConstant: allocates a constant Value. */ /***********************************************************************/ -PVAL AllocateValue(PGLOBAL g, void *value, short type) +PVAL AllocateValue(PGLOBAL g, void *value, short type, short prec) { PVAL valp; @@ -351,7 +351,7 @@ PVAL AllocateValue(PGLOBAL g, void *value, short type) valp = new(g) TYPVAL<longlong>(*(longlong*)value, TYPE_BIGINT); break; case TYPE_DOUBLE: - valp = new(g) TYPVAL<double>(*(double *)value, TYPE_DOUBLE, 2); + valp = new(g) TYPVAL<double>(*(double *)value, TYPE_DOUBLE, prec); break; case TYPE_TINY: valp = new(g) TYPVAL<char>(*(char *)value, TYPE_TINY); @@ -475,7 +475,7 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype, int uns) break; case TYPE_DOUBLE: valp = new(g) TYPVAL<double>(valp->GetFloatValue(), TYPE_DOUBLE, - valp->GetValPrec()); + (uns) ? uns : valp->GetValPrec()); break; case TYPE_TINY: if (un) @@ -542,6 +542,15 @@ BYTE VALUE::TestValue(PVAL vp) return (n > 0) ? 0x04 : (n < 0) ? 0x02 : 0x01; } // end of TestValue +/***********************************************************************/ +/* Compute a function on a string. */ +/***********************************************************************/ +bool VALUE::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op) + { + strcpy(g->Message, "Compute not implemented for this value type"); + return true; + } // end of Compute + /* -------------------------- Class TYPVAL ---------------------------- */ /***********************************************************************/ @@ -930,6 +939,188 @@ int TYPVAL<TYPE>::CompareValue(PVAL vp) return (Tval > n) ? 1 : (Tval < n) ? (-1) : 0; } // end of CompareValue +#if 0 +/***********************************************************************/ +/* Return max type value if b is true, else min type value. */ +/***********************************************************************/ +template <> +short TYPVAL<short>::MinMaxVal(bool b) + {return (b) ? MAXINT16 : MININT16;} + +template <> +USHORT TYPVAL<USHORT>::MinMaxVal(bool b) + {return (b) ? MAXUINT16 : 0;} + +template <> +int TYPVAL<int>::MinMaxVal(bool b) + {return (b) ? MAXINT32 : MININT32;} + +template <> +UINT TYPVAL<UINT>::MinMaxVal(bool b) + {return (b) ? MAXUINT32 : 0;} + +template <> +longlong TYPVAL<longlong>::MinMaxVal(bool b) + {return (b) ? MAXINT64 : MININT64;} + +template <> +ulonglong TYPVAL<ulonglong>::MinMaxVal(bool b) + {return (b) ? MAXUINT64 : 0;} + +template <> +double TYPVAL<double>::MinMaxVal(bool b) + {assert(false); return 0.0;} + +template <> +char TYPVAL<char>::MinMaxVal(bool b) + {return (b) ? MAXINT8 : MININT8;} + +template <> +UCHAR TYPVAL<UCHAR>::MinMaxVal(bool b) + {return (b) ? MAXUINT8 : 0;} + +/***********************************************************************/ +/* SafeAdd: adds a value and test whether overflow/underflow occured. */ +/***********************************************************************/ +template <class TYPE> +TYPE TYPVAL<TYPE>::SafeAdd(TYPE n1, TYPE n2) + { + PGLOBAL& g = Global; + TYPE n = n1 + n2; + + if ((n2 > 0) && (n < n1)) { + // Overflow + strcpy(g->Message, MSG(FIX_OVFLW_ADD)); + longjmp(g->jumper[g->jump_level], 138); + } else if ((n2 < 0) && (n > n1)) { + // Underflow + strcpy(g->Message, MSG(FIX_UNFLW_ADD)); + longjmp(g->jumper[g->jump_level], 138); + } // endif's n2 + + return n; + } // end of SafeAdd + +template <> +inline double TYPVAL<double>::SafeAdd(double n1, double n2) + { + assert(false); return 0; + } // end of SafeAdd + +/***********************************************************************/ +/* SafeMult: multiply values and test whether overflow occured. */ +/***********************************************************************/ +template <class TYPE> +TYPE TYPVAL<TYPE>::SafeMult(TYPE n1, TYPE n2) + { + PGLOBAL& g = Global; + double n = (double)n1 * (double)n2; + + if (n > MinMaxVal(true)) { + // Overflow + strcpy(g->Message, MSG(FIX_OVFLW_TIMES)); + longjmp(g->jumper[g->jump_level], 138); + } else if (n < MinMaxVal(false)) { + // Underflow + strcpy(g->Message, MSG(FIX_UNFLW_TIMES)); + longjmp(g->jumper[g->jump_level], 138); + } // endif's n2 + + return (TYPE)n; + } // end of SafeMult + +template <> +inline double TYPVAL<double>::SafeMult(double n1, double n2) + { + assert(false); return 0; + } // end of SafeMult +#endif // 0 + +/***********************************************************************/ +/* Compute defined functions for the type. */ +/***********************************************************************/ +template <class TYPE> +bool TYPVAL<TYPE>::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op) + { + bool rc = false; + TYPE val[2]; + + assert(np == 2); + + for (int i = 0; i < np; i++) + val[i] = GetTypedValue(vp[i]); + + switch (op) { + case OP_ADD: +// Tval = SafeAdd(val[0], val[1]); + Tval = val[0] + val[1]; + break; + case OP_MULT: +// Tval = SafeMult(val[0], val[1]); + Tval = val[0] * val[1]; + break; + default: + rc = Compall(g, vp, np, op); + break; + } // endswitch op + + return rc; + } // end of Compute + +#if 0 +template <> +bool TYPVAL<double>::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op) + { + bool rc = false; + double val[2]; + + assert(np == 2); + + for (int i = 0; i < np; i++) + val[i] = vp[i]->GetFloatValue(); + + switch (op) { + case OP_ADD: + Tval = val[0] + val[1]; + break; + case OP_MULT: + Tval = val[0] * val[1]; + break; + default: + rc = Compall(g, vp, np, op); + } // endswitch op + + return rc; + } // end of Compute +#endif // 0 + +/***********************************************************************/ +/* Compute a function for all types. */ +/***********************************************************************/ +template <class TYPE> +bool TYPVAL<TYPE>::Compall(PGLOBAL g, PVAL *vp, int np, OPVAL op) + { + TYPE val[2]; + + for (int i = 0; i < np; i++) + val[i] = GetTypedValue(vp[i]); + + switch (op) { + case OP_MIN: + Tval = MY_MIN(val[0], val[1]); + break; + case OP_MAX: + Tval = MY_MAX(val[0], val[1]); + break; + default: +// sprintf(g->Message, MSG(BAD_EXP_OPER), op); + strcpy(g->Message, "Function not supported"); + return true; + } // endswitch op + + return false; + } // end of Compall + /***********************************************************************/ /* FormatValue: This function set vp (a STRING value) to the string */ /* constructed from its own value formated using the fmt format. */ @@ -1410,6 +1601,45 @@ int TYPVAL<PSZ>::CompareValue(PVAL vp) } // end of CompareValue /***********************************************************************/ +/* Compute a function on a string. */ +/***********************************************************************/ +bool TYPVAL<PSZ>::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op) + { + char *p[2], val[2][32]; + int i; + + for (i = 0; i < np; i++) + p[i] = vp[i]->GetCharString(val[i]); + + switch (op) { + case OP_CNC: + assert(np == 1 || np == 2); + + if (np == 2) + strncpy(Strp, p[0], Len); + + if ((i = Len - (signed)strlen(Strp)) > 0) + strncat(Strp, p[np - 1], i); + + break; + case OP_MIN: + assert(np == 2); + strcpy(Strp, (strcmp(p[0], p[1]) < 0) ? p[0] : p[1]); + break; + case OP_MAX: + assert(np == 2); + strcpy(Strp, (strcmp(p[0], p[1]) > 0) ? p[0] : p[1]); + break; + default: +// sprintf(g->Message, MSG(BAD_EXP_OPER), op); + strcpy(g->Message, "Function not supported"); + return true; + } // endswitch op + + return false; + } // end of Compute + +/***********************************************************************/ /* FormatValue: This function set vp (a STRING value) to the string */ /* constructed from its own value formated using the fmt format. */ /* This function assumes that the format matches the value type. */ |