summaryrefslogtreecommitdiff
path: root/storage/connect/value.cpp
diff options
context:
space:
mode:
authorOlivier Bertrand <bertrandop@gmail.com>2015-01-20 01:21:56 +0100
committerOlivier Bertrand <bertrandop@gmail.com>2015-01-20 01:21:56 +0100
commit8fc695643062a7add3c8e484dd0daf80b368720c (patch)
treee884e0962b679ca0a8a079e40c6c0abef012d00c /storage/connect/value.cpp
parentf5beda4866b71a6a1d4b28191355c827670d92dc (diff)
parent2d2e110bcef08a772cae8e2ee7d226e2831f6459 (diff)
downloadmariadb-git-8fc695643062a7add3c8e484dd0daf80b368720c.tar.gz
- Fix compile errors and warnings of LINUX G++
added: storage/connect/json.cpp storage/connect/json.h storage/connect/mysql-test/connect/r/json.result storage/connect/mysql-test/connect/std_data/biblio.jsn storage/connect/mysql-test/connect/std_data/expense.jsn storage/connect/mysql-test/connect/std_data/mulexp3.jsn storage/connect/mysql-test/connect/std_data/mulexp4.jsn storage/connect/mysql-test/connect/std_data/mulexp5.jsn storage/connect/mysql-test/connect/t/json.test storage/connect/tabjson.cpp storage/connect/tabjson.h modified: storage/connect/CMakeLists.txt storage/connect/engmsg.h storage/connect/filamtxt.h storage/connect/ha_connect.cc storage/connect/msgid.h storage/connect/mycat.cc storage/connect/plgdbsem.h storage/connect/tabdos.cpp storage/connect/value.cpp storage/connect/value.h
Diffstat (limited to 'storage/connect/value.cpp')
-rw-r--r--storage/connect/value.cpp93
1 files changed, 55 insertions, 38 deletions
diff --git a/storage/connect/value.cpp b/storage/connect/value.cpp
index 3ed58d3e257..1cc40473433 100644
--- a/storage/connect/value.cpp
+++ b/storage/connect/value.cpp
@@ -434,6 +434,7 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype, int uns)
{
PSZ p, sp;
bool un = (uns < 0) ? false : (uns > 0) ? true : valp->IsUnsigned();
+ PVAL vp;
if (newtype == TYPE_VOID) // Means allocate a value of the same type
newtype = valp->GetType();
@@ -445,53 +446,55 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype, int uns)
if ((sp = valp->GetCharString(p)) != p)
strcpy (p, sp);
- valp = new(g) TYPVAL<PSZ>(g, p, valp->GetValLen(), valp->GetValPrec());
+ vp = new(g) TYPVAL<PSZ>(g, p, valp->GetValLen(), valp->GetValPrec());
break;
case TYPE_SHORT:
if (un)
- valp = new(g) TYPVAL<ushort>(valp->GetUShortValue(),
- TYPE_SHORT, 0, true);
+ vp = new(g) TYPVAL<ushort>(valp->GetUShortValue(),
+ TYPE_SHORT, 0, true);
else
- valp = new(g) TYPVAL<short>(valp->GetShortValue(), TYPE_SHORT);
+ vp = new(g) TYPVAL<short>(valp->GetShortValue(), TYPE_SHORT);
break;
case TYPE_INT:
if (un)
- valp = new(g) TYPVAL<uint>(valp->GetUIntValue(), TYPE_INT, 0, true);
+ vp = new(g) TYPVAL<uint>(valp->GetUIntValue(), TYPE_INT, 0, true);
else
- valp = new(g) TYPVAL<int>(valp->GetIntValue(), TYPE_INT);
+ vp = new(g) TYPVAL<int>(valp->GetIntValue(), TYPE_INT);
break;
case TYPE_BIGINT:
if (un)
- valp = new(g) TYPVAL<ulonglong>(valp->GetUBigintValue(),
- TYPE_BIGINT, 0, true);
+ vp = new(g) TYPVAL<ulonglong>(valp->GetUBigintValue(),
+ TYPE_BIGINT, 0, true);
else
- valp = new(g) TYPVAL<longlong>(valp->GetBigintValue(), TYPE_BIGINT);
+ vp = new(g) TYPVAL<longlong>(valp->GetBigintValue(), TYPE_BIGINT);
break;
case TYPE_DATE:
- valp = new(g) DTVAL(g, valp->GetIntValue());
+ vp = new(g) DTVAL(g, valp->GetIntValue());
break;
case TYPE_DOUBLE:
- valp = new(g) TYPVAL<double>(valp->GetFloatValue(), TYPE_DOUBLE,
- (uns) ? uns : valp->GetValPrec());
+ vp = new(g) TYPVAL<double>(valp->GetFloatValue(), TYPE_DOUBLE,
+ (uns) ? uns : valp->GetValPrec());
break;
case TYPE_TINY:
if (un)
- valp = new(g) TYPVAL<uchar>(valp->GetUTinyValue(),
+ vp = new(g) TYPVAL<uchar>(valp->GetUTinyValue(),
TYPE_TINY, 0, true);
else
- valp = new(g) TYPVAL<char>(valp->GetTinyValue(), TYPE_TINY);
+ vp = new(g) TYPVAL<char>(valp->GetTinyValue(), TYPE_TINY);
break;
default:
sprintf(g->Message, MSG(BAD_VALUE_TYPE), newtype);
return NULL;
} // endswitch type
-
- valp->SetGlobal(g);
- return valp;
+
+ vp->SetNullable(valp->GetNullable());
+ vp->SetNull(valp->IsNull());
+ vp->SetGlobal(g);
+ return vp;
} // end of AllocateValue
/* -------------------------- Class VALUE ---------------------------- */
@@ -939,33 +942,32 @@ 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;}
+ {return (b) ? INT_MAX16 : INT_MIN16;}
template <>
-USHORT TYPVAL<USHORT>::MinMaxVal(bool b)
- {return (b) ? MAXUINT16 : 0;}
+ushort TYPVAL<ushort>::MinMaxVal(bool b)
+ {return (b) ? UINT_MAX16 : 0;}
template <>
int TYPVAL<int>::MinMaxVal(bool b)
- {return (b) ? MAXINT32 : MININT32;}
+ {return (b) ? INT_MAX32 : INT_MIN32;}
template <>
-UINT TYPVAL<UINT>::MinMaxVal(bool b)
- {return (b) ? MAXUINT32 : 0;}
+uint TYPVAL<uint>::MinMaxVal(bool b)
+ {return (b) ? UINT_MAX32 : 0;}
template <>
longlong TYPVAL<longlong>::MinMaxVal(bool b)
- {return (b) ? MAXINT64 : MININT64;}
+ {return (b) ? INT_MAX64 : INT_MIN64;}
template <>
ulonglong TYPVAL<ulonglong>::MinMaxVal(bool b)
- {return (b) ? MAXUINT64 : 0;}
+ {return (b) ? 0xFFFFFFFFFFFFFFFFLL : 0;}
template <>
double TYPVAL<double>::MinMaxVal(bool b)
@@ -973,11 +975,11 @@ double TYPVAL<double>::MinMaxVal(bool b)
template <>
char TYPVAL<char>::MinMaxVal(bool b)
- {return (b) ? MAXINT8 : MININT8;}
+ {return (b) ? INT_MAX8 : INT_MIN8;}
template <>
-UCHAR TYPVAL<UCHAR>::MinMaxVal(bool b)
- {return (b) ? MAXUINT8 : 0;}
+uchar TYPVAL<uchar>::MinMaxVal(bool b)
+ {return (b) ? UINT_MAX8 : 0;}
/***********************************************************************/
/* SafeAdd: adds a value and test whether overflow/underflow occured. */
@@ -1004,7 +1006,7 @@ TYPE TYPVAL<TYPE>::SafeAdd(TYPE n1, TYPE n2)
template <>
inline double TYPVAL<double>::SafeAdd(double n1, double n2)
{
- assert(false); return 0;
+ return n1 + n2;
} // end of SafeAdd
/***********************************************************************/
@@ -1032,9 +1034,8 @@ TYPE TYPVAL<TYPE>::SafeMult(TYPE n1, TYPE n2)
template <>
inline double TYPVAL<double>::SafeMult(double n1, double n2)
{
- assert(false); return 0;
+ return n1 * n2;
} // end of SafeMult
-#endif // 0
/***********************************************************************/
/* Compute defined functions for the type. */
@@ -1052,12 +1053,18 @@ bool TYPVAL<TYPE>::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op)
switch (op) {
case OP_ADD:
-// Tval = SafeAdd(val[0], val[1]);
- Tval = val[0] + val[1];
+ Tval = SafeAdd(val[0], val[1]);
break;
case OP_MULT:
-// Tval = SafeMult(val[0], val[1]);
- Tval = val[0] * val[1];
+ Tval = SafeMult(val[0], val[1]);
+ break;
+ case OP_DIV:
+ if (!val[1]) {
+ strcpy(g->Message, MSG(ZERO_DIVIDE));
+ return true;
+ } // endif
+
+ Tval = val[0] / val[1];
break;
default:
rc = Compall(g, vp, np, op);
@@ -1067,7 +1074,6 @@ bool TYPVAL<TYPE>::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op)
return rc;
} // end of Compute
-#if 0
template <>
bool TYPVAL<double>::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op)
{
@@ -1092,7 +1098,6 @@ bool TYPVAL<double>::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op)
return rc;
} // end of Compute
-#endif // 0
/***********************************************************************/
/* Compute a function for all types. */
@@ -1106,6 +1111,18 @@ bool TYPVAL<TYPE>::Compall(PGLOBAL g, PVAL *vp, int np, OPVAL op)
val[i] = GetTypedValue(vp[i]);
switch (op) {
+ case OP_DIV:
+ if (val[0]) {
+ if (!val[1]) {
+ strcpy(g->Message, MSG(ZERO_DIVIDE));
+ return true;
+ } // endif
+
+ Tval = val[0] / val[1];
+ } else
+ Tval = 0;
+
+ break;
case OP_MIN:
Tval = MY_MIN(val[0], val[1]);
break;