Commit 6ec8f00a authored by Olivier Bertrand's avatar Olivier Bertrand

Added to CONNECT the missing type TYPE_BIGINT (longlong).

parent 5c8c4f4f
...@@ -76,6 +76,7 @@ ...@@ -76,6 +76,7 @@
#define TYPE_STRING 1 #define TYPE_STRING 1
#define TYPE_FLOAT 2 #define TYPE_FLOAT 2
#define TYPE_SHORT 3 #define TYPE_SHORT 3
#define TYPE_BIGINT 5
#define TYPE_LIST 6 #define TYPE_LIST 6
#define TYPE_INT 7 #define TYPE_INT 7
......
...@@ -1075,6 +1075,9 @@ void *ha_connect::GetColumnOption(void *field, PCOLINFO pcf) ...@@ -1075,6 +1075,9 @@ void *ha_connect::GetColumnOption(void *field, PCOLINFO pcf)
case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_TIMESTAMP:
pcf->Type= TYPE_DATE; pcf->Type= TYPE_DATE;
break; break;
case MYSQL_TYPE_LONGLONG:
pcf->Type= TYPE_BIGINT;
break;
default: default:
pcf->Type=TYPE_ERROR; pcf->Type=TYPE_ERROR;
} // endswitch type } // endswitch type
...@@ -3509,6 +3512,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, ...@@ -3509,6 +3512,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
case MYSQL_TYPE_YEAR: case MYSQL_TYPE_YEAR:
case MYSQL_TYPE_NEWDATE: case MYSQL_TYPE_NEWDATE:
case MYSQL_TYPE_VARCHAR: case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_LONGLONG:
break; // Ok break; // Ok
case MYSQL_TYPE_VAR_STRING: case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_STRING: case MYSQL_TYPE_STRING:
...@@ -3518,7 +3522,6 @@ int ha_connect::create(const char *name, TABLE *table_arg, ...@@ -3518,7 +3522,6 @@ int ha_connect::create(const char *name, TABLE *table_arg,
break; // To be checked break; // To be checked
case MYSQL_TYPE_TINY: case MYSQL_TYPE_TINY:
case MYSQL_TYPE_BIT: case MYSQL_TYPE_BIT:
case MYSQL_TYPE_LONGLONG:
case MYSQL_TYPE_NULL: case MYSQL_TYPE_NULL:
case MYSQL_TYPE_ENUM: case MYSQL_TYPE_ENUM:
case MYSQL_TYPE_SET: case MYSQL_TYPE_SET:
......
...@@ -98,9 +98,12 @@ int MYSQLtoPLG(int mytype) ...@@ -98,9 +98,12 @@ int MYSQLtoPLG(int mytype)
break; break;
case MYSQL_TYPE_LONG: case MYSQL_TYPE_LONG:
case MYSQL_TYPE_INT24: case MYSQL_TYPE_INT24:
case MYSQL_TYPE_ENUM: // ???
type = TYPE_INT; type = TYPE_INT;
break; break;
case MYSQL_TYPE_LONGLONG: case MYSQL_TYPE_LONGLONG:
type = TYPE_BIGINT;
break;
case MYSQL_TYPE_DECIMAL: case MYSQL_TYPE_DECIMAL:
#if !defined(ALPHA) #if !defined(ALPHA)
case MYSQL_TYPE_NEWDECIMAL: case MYSQL_TYPE_NEWDECIMAL:
......
...@@ -113,6 +113,9 @@ PVBLK AllocValBlock(PGLOBAL g, void *mp, int type, int nval, int len, ...@@ -113,6 +113,9 @@ PVBLK AllocValBlock(PGLOBAL g, void *mp, int type, int nval, int len,
case TYPE_DATE: // ????? case TYPE_DATE: // ?????
blkp = new(g) DATBLK(mp, nval); blkp = new(g) DATBLK(mp, nval);
break; break;
case TYPE_BIGINT:
blkp = new(g) BIGBLK(mp, nval);
break;
case TYPE_FLOAT: case TYPE_FLOAT:
blkp = new(g) DBLBLK(mp, nval, prec); blkp = new(g) DBLBLK(mp, nval, prec);
break; break;
...@@ -233,6 +236,14 @@ int CHRBLK::GetIntValue(int n) ...@@ -233,6 +236,14 @@ int CHRBLK::GetIntValue(int n)
return atol((char *)GetValPtrEx(n)); return atol((char *)GetValPtrEx(n));
} // end of GetIntValue } // end of GetIntValue
/***********************************************************************/
/* Return the value of the nth element converted to big int. */
/***********************************************************************/
longlong CHRBLK::GetBigintValue(int n)
{
return atoll((char *)GetValPtrEx(n));
} // end of GetIntValue
/***********************************************************************/ /***********************************************************************/
/* Return the value of the nth element converted to double. */ /* Return the value of the nth element converted to double. */
/***********************************************************************/ /***********************************************************************/
...@@ -1027,6 +1038,196 @@ void DATBLK::SetValue(PSZ p, int n) ...@@ -1027,6 +1038,196 @@ void DATBLK::SetValue(PSZ p, int n)
} // end of SetValue } // end of SetValue
/* -------------------------- Class BIGBLK --------------------------- */
/***********************************************************************/
/* Constructor. */
/***********************************************************************/
BIGBLK::BIGBLK(void *mp, int nval)
: VALBLK(mp, TYPE_BIGINT, nval), Lngp((longlong*&)Blkp)
{
} // end of BIGBLK constructor
/***********************************************************************/
/* Initialization routine. */
/***********************************************************************/
void BIGBLK::Init(PGLOBAL g, bool check)
{
if (!Blkp)
Blkp = PlugSubAlloc(g, NULL, Nval * sizeof(longlong));
Check = check;
Global = g;
} // end of Init
/***********************************************************************/
/* Set one value in a block. */
/***********************************************************************/
void BIGBLK::SetValue(PVAL valp, int n)
{
CheckParms(valp, n)
Lngp[n] = valp->GetBigintValue();
} // end of SetValue
/***********************************************************************/
/* Set one value in a block. */
/***********************************************************************/
void BIGBLK::SetValue(PSZ p, int n)
{
#if defined(_DEBUG) || defined(DEBTRACE)
if (Check) {
PGLOBAL& g = Global;
strcpy(g->Message, MSG(BAD_SET_STRING));
longjmp(g->jumper[g->jump_level], Type);
} // endif Check
#endif
Lngp[n] = atoll(p);
} // end of SetValue
/***********************************************************************/
/* Set one value in a block if val is less than the current value. */
/***********************************************************************/
void BIGBLK::SetMin(PVAL valp, int n)
{
CheckParms(valp, n)
longlong lval = valp->GetIntValue();
longlong& lmin = Lngp[n];
if (lval < lmin)
lmin = lval;
} // end of SetMin
/***********************************************************************/
/* Set one value in a block if val is greater than the current value. */
/***********************************************************************/
void BIGBLK::SetMax(PVAL valp, int n)
{
CheckParms(valp, n)
longlong lval = valp->GetIntValue();
longlong& lmax = Lngp[n];
if (lval > lmax)
lmax = lval;
} // end of SetMax
/***********************************************************************/
/* Set one value in a block from a value in another block. */
/***********************************************************************/
void BIGBLK::SetValue(PVBLK pv, int n1, int n2)
{
CheckType(pv)
Lngp[n1] = ((BIGBLK*)pv)->Lngp[n2];
} // end of SetValue
/***********************************************************************/
/* Set many values in a block from values in another block. */
/***********************************************************************/
void BIGBLK::SetValues(PVBLK pv, int k, int n)
{
CheckType(pv)
longlong *lp = ((BIGBLK*)pv)->Lngp;
for (register int i = k; i < n; i++)
Lngp[i] = lp[i];
} // end of SetValues
/***********************************************************************/
/* This function is used by class RESCOL when calculating COUNT. */
/***********************************************************************/
void BIGBLK::AddMinus1(PVBLK pv, int n1, int n2)
{
assert(Type == pv->GetType());
Lngp[n1] += (((BIGBLK*)pv)->Lngp[n2] - 1);
} // end of AddMinus1
/***********************************************************************/
/* Move one value from i to j. */
/***********************************************************************/
void BIGBLK::Move(int i, int j)
{
Lngp[j] = Lngp[i];
} // end of Move
/***********************************************************************/
/* Compare a Value object with the nth value of the block. */
/***********************************************************************/
int BIGBLK::CompVal(PVAL vp, int n)
{
CheckParms(vp, n)
longlong mlv = Lngp[n];
longlong vlv = vp->GetBigintValue();
return (vlv > mlv) ? 1 : (vlv < mlv) ? (-1) : 0;
} // end of CompVal
/***********************************************************************/
/* Compare two values of the block. */
/***********************************************************************/
int BIGBLK::CompVal(int i1, int i2)
{
longlong lv1 = Lngp[i1];
longlong lv2 = Lngp[i2];
return (lv1 > lv2) ? 1 : (lv1 < lv2) ? (-1) : 0;
} // end of CompVal
/***********************************************************************/
/* Get a pointer on the nth value of the block. */
/***********************************************************************/
void *BIGBLK::GetValPtr(int n)
{
CheckIndex(n)
return Lngp + n;
} // end of GetValPtr
/***********************************************************************/
/* Get a pointer on the nth value of the block. */
/***********************************************************************/
void *BIGBLK::GetValPtrEx(int n)
{
CheckIndex(n)
return Lngp + n;
} // end of GetValPtrEx
/***********************************************************************/
/* Returns index of matching value in block or -1. */
/***********************************************************************/
int BIGBLK::Find(PVAL vp)
{
CheckType(vp)
int i;
longlong n = vp->GetBigintValue();
for (i = 0; i < Nval; i++)
if (n == Lngp[i])
break;
return (i < Nval) ? i : (-1);
} // end of Find
/***********************************************************************/
/* Returns the length of the longest string in the block. */
/***********************************************************************/
int BIGBLK::GetMaxLength(void)
{
char buf[24];
int i, n;
for (i = n = 0; i < Nval; i++) {
sprintf(buf, "%lld", Lngp[i]);
n = max(n, (signed)strlen(buf));
} // endfor i
return n;
} // end of GetMaxLength
/* -------------------------- Class DBLBLK --------------------------- */ /* -------------------------- Class DBLBLK --------------------------- */
/***********************************************************************/ /***********************************************************************/
......
/*************** Valblk H Declares Source Code File (.H) ***************/ /*************** Valblk H Declares Source Code File (.H) ***************/
/* Name: VALBLK.H Version 1.6 */ /* Name: VALBLK.H Version 1.7 */
/* */ /* */
/* (C) Copyright to the author Olivier BERTRAND 2005-2012 */ /* (C) Copyright to the author Olivier BERTRAND 2005-2013 */
/* */ /* */
/* This file contains the VALBLK and derived classes declares. */ /* This file contains the VALBLK and derived classes declares. */
/***********************************************************************/ /***********************************************************************/
...@@ -42,6 +42,7 @@ class VALBLK : public BLOCK { ...@@ -42,6 +42,7 @@ class VALBLK : public BLOCK {
virtual PSZ GetCharValue(int n); virtual PSZ GetCharValue(int n);
virtual short GetShortValue(int n) = 0; virtual short GetShortValue(int n) = 0;
virtual int GetIntValue(int n) = 0; virtual int GetIntValue(int n) = 0;
virtual longlong GetBigintValue(int n) = 0;
virtual double GetFloatValue(int n) = 0; virtual double GetFloatValue(int n) = 0;
virtual void ReAlloc(void *mp, int n) {Blkp = mp; Nval = n;} virtual void ReAlloc(void *mp, int n) {Blkp = mp; Nval = n;}
virtual void Reset(int n) = 0; virtual void Reset(int n) = 0;
...@@ -52,6 +53,7 @@ class VALBLK : public BLOCK { ...@@ -52,6 +53,7 @@ class VALBLK : public BLOCK {
// Methods // Methods
virtual void SetValue(short sval, int n) {assert(false);} virtual void SetValue(short sval, int n) {assert(false);}
virtual void SetValue(int lval, int n) {assert(false);} virtual void SetValue(int lval, int n) {assert(false);}
virtual void SetValue(longlong lval, int n) {assert(false);}
virtual void SetValue(PSZ sp, int n) {assert(false);} virtual void SetValue(PSZ sp, int n) {assert(false);}
virtual void SetValue(PVAL valp, int n) = 0; virtual void SetValue(PVAL valp, int n) = 0;
virtual void SetMin(PVAL valp, int n) = 0; virtual void SetMin(PVAL valp, int n) = 0;
...@@ -98,6 +100,7 @@ class CHRBLK : public VALBLK { ...@@ -98,6 +100,7 @@ class CHRBLK : public VALBLK {
virtual PSZ GetCharValue(int n); virtual PSZ GetCharValue(int n);
virtual short GetShortValue(int n); virtual short GetShortValue(int n);
virtual int GetIntValue(int n); virtual int GetIntValue(int n);
virtual longlong GetBigintValue(int n);
virtual double GetFloatValue(int n); virtual double GetFloatValue(int n);
virtual void Reset(int n); virtual void Reset(int n);
virtual void SetPrec(int p) {Ci = (p != 0);} virtual void SetPrec(int p) {Ci = (p != 0);}
...@@ -143,6 +146,7 @@ class STRBLK : public VALBLK { ...@@ -143,6 +146,7 @@ class STRBLK : public VALBLK {
virtual PSZ GetCharValue(int n) {return Strp[n];} virtual PSZ GetCharValue(int n) {return Strp[n];}
virtual short GetShortValue(int n) {return (short)atoi(Strp[n]);} virtual short GetShortValue(int n) {return (short)atoi(Strp[n]);}
virtual int GetIntValue(int n) {return atol(Strp[n]);} virtual int GetIntValue(int n) {return atol(Strp[n]);}
virtual longlong GetBigintValue(int n) {return atoll(Strp[n]);}
virtual double GetFloatValue(int n) {return atof(Strp[n]);} virtual double GetFloatValue(int n) {return atof(Strp[n]);}
virtual void Reset(int n) {Strp[n] = NULL;} virtual void Reset(int n) {Strp[n] = NULL;}
...@@ -180,6 +184,7 @@ class SHRBLK : public VALBLK { ...@@ -180,6 +184,7 @@ class SHRBLK : public VALBLK {
//virtual PSZ GetCharValue(int n); //virtual PSZ GetCharValue(int n);
virtual short GetShortValue(int n) {return Shrp[n];} virtual short GetShortValue(int n) {return Shrp[n];}
virtual int GetIntValue(int n) {return (int)Shrp[n];} virtual int GetIntValue(int n) {return (int)Shrp[n];}
virtual longlong GetBigintValue(int n) {return (longlong)Shrp[n];}
virtual double GetFloatValue(int n) {return (double)Shrp[n];} virtual double GetFloatValue(int n) {return (double)Shrp[n];}
virtual void Reset(int n) {Shrp[n] = 0;} virtual void Reset(int n) {Shrp[n] = 0;}
...@@ -187,6 +192,7 @@ class SHRBLK : public VALBLK { ...@@ -187,6 +192,7 @@ class SHRBLK : public VALBLK {
virtual void SetValue(PSZ sp, int n); virtual void SetValue(PSZ sp, int n);
virtual void SetValue(short sval, int n) {Shrp[n] = sval;} virtual void SetValue(short sval, int n) {Shrp[n] = sval;}
virtual void SetValue(int lval, int n) {Shrp[n] = (short)lval;} virtual void SetValue(int lval, int n) {Shrp[n] = (short)lval;}
virtual void SetValue(longlong lval, int n) {Shrp[n] = (short)lval;}
virtual void SetValue(PVAL valp, int n); virtual void SetValue(PVAL valp, int n);
virtual void SetMin(PVAL valp, int n); virtual void SetMin(PVAL valp, int n);
virtual void SetMax(PVAL valp, int n); virtual void SetMax(PVAL valp, int n);
...@@ -220,6 +226,7 @@ class LNGBLK : public VALBLK { ...@@ -220,6 +226,7 @@ class LNGBLK : public VALBLK {
//virtual PSZ GetCharValue(int n); //virtual PSZ GetCharValue(int n);
virtual short GetShortValue(int n) {return (short)Lngp[n];} virtual short GetShortValue(int n) {return (short)Lngp[n];}
virtual int GetIntValue(int n) {return Lngp[n];} virtual int GetIntValue(int n) {return Lngp[n];}
virtual longlong GetBigintValue(int n) {return (longlong)Lngp[n];}
virtual double GetFloatValue(int n) {return (double)Lngp[n];} virtual double GetFloatValue(int n) {return (double)Lngp[n];}
virtual void Reset(int n) {Lngp[n] = 0;} virtual void Reset(int n) {Lngp[n] = 0;}
...@@ -227,6 +234,7 @@ class LNGBLK : public VALBLK { ...@@ -227,6 +234,7 @@ class LNGBLK : public VALBLK {
virtual void SetValue(PSZ sp, int n); virtual void SetValue(PSZ sp, int n);
virtual void SetValue(short sval, int n) {Lngp[n] = (int)sval;} virtual void SetValue(short sval, int n) {Lngp[n] = (int)sval;}
virtual void SetValue(int lval, int n) {Lngp[n] = lval;} virtual void SetValue(int lval, int n) {Lngp[n] = lval;}
virtual void SetValue(longlong lval, int n) {Lngp[n] = (int)lval;}
virtual void SetValue(PVAL valp, int n); virtual void SetValue(PVAL valp, int n);
virtual void SetMin(PVAL valp, int n); virtual void SetMin(PVAL valp, int n);
virtual void SetMax(PVAL valp, int n); virtual void SetMax(PVAL valp, int n);
...@@ -265,6 +273,48 @@ class DATBLK : public LNGBLK { ...@@ -265,6 +273,48 @@ class DATBLK : public LNGBLK {
PVAL Dvalp; // Date value used to convert string PVAL Dvalp; // Date value used to convert string
}; // end of class DATBLK }; // end of class DATBLK
/***********************************************************************/
/* Class LNGBLK: represents a block of int integer values. */
/***********************************************************************/
class BIGBLK : public VALBLK {
public:
// Constructors
BIGBLK(void *mp, int size);
// Implementation
virtual void Init(PGLOBAL g, bool check);
virtual int GetVlen(void) {return sizeof(longlong);}
//virtual PSZ GetCharValue(int n);
virtual short GetShortValue(int n) {return (short)Lngp[n];}
virtual int GetIntValue(int n) {return (int)Lngp[n];}
virtual longlong GetBigintValue(int n) {return Lngp[n];}
virtual double GetFloatValue(int n) {return (double)Lngp[n];}
virtual void Reset(int n) {Lngp[n] = 0LL;}
// Methods
virtual void SetValue(PSZ sp, int n);
virtual void SetValue(short sval, int n) {Lngp[n] = (longlong)sval;}
virtual void SetValue(int lval, int n) {Lngp[n] = (longlong)lval;}
virtual void SetValue(longlong lval, int n) {Lngp[n] = lval;}
virtual void SetValue(PVAL valp, int n);
virtual void SetMin(PVAL valp, int n);
virtual void SetMax(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2);
virtual void SetValues(PVBLK pv, int k, int n);
virtual void AddMinus1(PVBLK pv, int n1, int n2);
virtual void Move(int i, int j);
virtual int CompVal(PVAL vp, int n);
virtual int CompVal(int i1, int i2);
virtual void *GetValPtr(int n);
virtual void *GetValPtrEx(int n);
virtual int Find(PVAL vp);
virtual int GetMaxLength(void);
protected:
// Members
longlong* const &Lngp;
}; // end of class BIGBLK
/***********************************************************************/ /***********************************************************************/
/* Class DBLBLK: represents a block of double float values. */ /* Class DBLBLK: represents a block of double float values. */
/***********************************************************************/ /***********************************************************************/
...@@ -279,6 +329,7 @@ class DBLBLK : public VALBLK { ...@@ -279,6 +329,7 @@ class DBLBLK : public VALBLK {
//virtual PSZ GetCharValue(int n); //virtual PSZ GetCharValue(int n);
virtual short GetShortValue(int n) {return (short)Dblp[n];} virtual short GetShortValue(int n) {return (short)Dblp[n];}
virtual int GetIntValue(int n) {return (int)Dblp[n];} virtual int GetIntValue(int n) {return (int)Dblp[n];}
virtual longlong GetBigintValue(int n) {return (longlong)Dblp[n];}
virtual double GetFloatValue(int n) {return Dblp[n];} virtual double GetFloatValue(int n) {return Dblp[n];}
virtual void Reset(int n) {Dblp[n] = 0.0;} virtual void Reset(int n) {Dblp[n] = 0.0;}
virtual void SetPrec(int p) {Prec = p;} virtual void SetPrec(int p) {Prec = p;}
......
/************* Value C++ Functions Source Code File (.CPP) *************/ /************* Value C++ Functions Source Code File (.CPP) *************/
/* Name: VALUE.CPP Version 1.9 */ /* Name: VALUE.CPP Version 2.0 */
/* */ /* */
/* (C) Copyright to the author Olivier BERTRAND 2001-2012 */ /* (C) Copyright to the author Olivier BERTRAND 2001-2013 */
/* */ /* */
/* This file contains the VALUE and derived classes family functions. */ /* This file contains the VALUE and derived classes family functions. */
/* These classes contain values of different types. They are used so */ /* These classes contain values of different types. They are used so */
...@@ -131,6 +131,7 @@ PSZ GetTypeName(int type) ...@@ -131,6 +131,7 @@ PSZ GetTypeName(int type)
case TYPE_STRING: name = "CHAR"; break; case TYPE_STRING: name = "CHAR"; break;
case TYPE_SHORT: name = "SMALLINT"; break; case TYPE_SHORT: name = "SMALLINT"; break;
case TYPE_INT: name = "INTEGER"; break; case TYPE_INT: name = "INTEGER"; break;
case TYPE_BIGINT: name = "BIGINT"; break;
case TYPE_DATE: name = "DATE"; break; case TYPE_DATE: name = "DATE"; break;
case TYPE_FLOAT: name = "FLOAT"; break; case TYPE_FLOAT: name = "FLOAT"; break;
} // endswitch type } // endswitch type
...@@ -146,8 +147,9 @@ int GetTypeSize(int type, int len) ...@@ -146,8 +147,9 @@ int GetTypeSize(int type, int len)
switch (type) { switch (type) {
case TYPE_STRING: len = len * sizeof(char); break; case TYPE_STRING: len = len * sizeof(char); break;
case TYPE_SHORT: len = sizeof(short); break; case TYPE_SHORT: len = sizeof(short); break;
case TYPE_INT: len = sizeof(int); break; case TYPE_INT: len = sizeof(int); break;
case TYPE_DATE: len = sizeof(int); break; case TYPE_BIGINT: len = sizeof(longlong); break;
case TYPE_DATE: len = sizeof(int); break;
case TYPE_FLOAT: len = sizeof(double); break; case TYPE_FLOAT: len = sizeof(double); break;
break; break;
default: len = 0; default: len = 0;
...@@ -186,7 +188,8 @@ int GetDBType(int type) ...@@ -186,7 +188,8 @@ int GetDBType(int type)
switch (type) { switch (type) {
case TYPE_STRING: tp = DB_CHAR; break; case TYPE_STRING: tp = DB_CHAR; break;
case TYPE_SHORT: tp = DB_SHORT; break; case TYPE_SHORT: tp = DB_SHORT; break;
case TYPE_INT: tp = DB_INT; break; case TYPE_INT: tp = DB_INT; break;
case TYPE_BIGINT:
case TYPE_FLOAT: tp = DB_DOUBLE; break; case TYPE_FLOAT: tp = DB_DOUBLE; break;
case TYPE_DATE: tp = DB_DATE; break; case TYPE_DATE: tp = DB_DATE; break;
default: tp = DB_ERROR; default: tp = DB_ERROR;
...@@ -207,6 +210,7 @@ short GetSQLType(int type) ...@@ -207,6 +210,7 @@ short GetSQLType(int type)
case TYPE_SHORT: tp = SQL_SMALLINT; break; case TYPE_SHORT: tp = SQL_SMALLINT; break;
case TYPE_INT: tp = SQL_INTEGER; break; case TYPE_INT: tp = SQL_INTEGER; break;
case TYPE_DATE: tp = SQL_TIMESTAMP; break; case TYPE_DATE: tp = SQL_TIMESTAMP; break;
case TYPE_BIGINT:
case TYPE_FLOAT: tp = SQL_DOUBLE; break; case TYPE_FLOAT: tp = SQL_DOUBLE; break;
} // endswitch type } // endswitch type
...@@ -225,6 +229,7 @@ int GetSQLCType(int type) ...@@ -225,6 +229,7 @@ int GetSQLCType(int type)
case TYPE_SHORT: tp = SQL_C_SHORT; break; case TYPE_SHORT: tp = SQL_C_SHORT; break;
case TYPE_INT: tp = SQL_C_LONG; break; case TYPE_INT: tp = SQL_C_LONG; break;
case TYPE_DATE: tp = SQL_C_TIMESTAMP; break; case TYPE_DATE: tp = SQL_C_TIMESTAMP; break;
case TYPE_BIGINT:
case TYPE_FLOAT: tp = SQL_C_DOUBLE; break; case TYPE_FLOAT: tp = SQL_C_DOUBLE; break;
} // endswitch type } // endswitch type
...@@ -242,6 +247,7 @@ char *GetFormatType(int type) ...@@ -242,6 +247,7 @@ char *GetFormatType(int type)
case TYPE_STRING: c = "C"; break; case TYPE_STRING: c = "C"; break;
case TYPE_SHORT: c = "S"; break; case TYPE_SHORT: c = "S"; break;
case TYPE_INT: c = "N"; break; case TYPE_INT: c = "N"; break;
case TYPE_BIGINT: c = "L"; break;
case TYPE_FLOAT: c = "F"; break; case TYPE_FLOAT: c = "F"; break;
case TYPE_DATE: c = "D"; break; case TYPE_DATE: c = "D"; break;
} // endswitch type } // endswitch type
...@@ -259,7 +265,8 @@ int GetFormatType(char c) ...@@ -259,7 +265,8 @@ int GetFormatType(char c)
switch (c) { switch (c) {
case 'C': type = TYPE_STRING; break; case 'C': type = TYPE_STRING; break;
case 'S': type = TYPE_SHORT; break; case 'S': type = TYPE_SHORT; break;
case 'N': type = TYPE_INT; break; case 'N': type = TYPE_INT; break;
case 'L': type = TYPE_BIGINT; break;
case 'F': type = TYPE_FLOAT; break; case 'F': type = TYPE_FLOAT; break;
case 'D': type = TYPE_DATE; break; case 'D': type = TYPE_DATE; break;
} // endswitch type } // endswitch type
...@@ -281,11 +288,12 @@ int TranslateSQLType(int stp, int prec, int& len) ...@@ -281,11 +288,12 @@ int TranslateSQLType(int stp, int prec, int& len)
break; break;
case SQL_LONGVARCHAR: // (-1) case SQL_LONGVARCHAR: // (-1)
type = TYPE_STRING; type = TYPE_STRING;
len = min(abs(len), 128); len = min(abs(len), 255);
break; break;
case SQL_NUMERIC: // 2 case SQL_NUMERIC: // 2
case SQL_DECIMAL: // 3 case SQL_DECIMAL: // 3
type = (prec) ? TYPE_FLOAT : TYPE_INT; type = (prec) ? TYPE_FLOAT
: (len > 10) ? TYPE_BIGINT : TYPE_INT;
break; break;
case SQL_INTEGER: // 4 case SQL_INTEGER: // 4
type = TYPE_INT; type = TYPE_INT;
...@@ -314,11 +322,13 @@ int TranslateSQLType(int stp, int prec, int& len) ...@@ -314,11 +322,13 @@ int TranslateSQLType(int stp, int prec, int& len)
type = TYPE_DATE; type = TYPE_DATE;
len = 19 + ((prec) ? (prec+1) : 0); len = 19 + ((prec) ? (prec+1) : 0);
break; break;
case SQL_BIGINT: // (-5)
type = TYPE_BIGINT;
break;
case SQL_UNKNOWN_TYPE: // 0 case SQL_UNKNOWN_TYPE: // 0
case SQL_BINARY: // (-2) case SQL_BINARY: // (-2)
case SQL_VARBINARY: // (-3) case SQL_VARBINARY: // (-3)
case SQL_LONGVARBINARY: // (-4) case SQL_LONGVARBINARY: // (-4)
case SQL_BIGINT: // (-5)
// case SQL_BIT: // (-7) // case SQL_BIT: // (-7)
case SQL_GUID: // (-11) case SQL_GUID: // (-11)
default: default:
...@@ -349,6 +359,7 @@ bool IsTypeNum(int type) ...@@ -349,6 +359,7 @@ bool IsTypeNum(int type)
{ {
switch (type) { switch (type) {
case TYPE_INT: case TYPE_INT:
case TYPE_BIGINT:
case TYPE_DATE: case TYPE_DATE:
case TYPE_FLOAT: case TYPE_FLOAT:
case TYPE_SHORT: case TYPE_SHORT:
...@@ -380,10 +391,11 @@ int ConvertType(int target, int type, CONV kind, bool match) ...@@ -380,10 +391,11 @@ int ConvertType(int target, int type, CONV kind, bool match)
if (match && (!IsTypeNum(target) || !IsTypeNum(type))) if (match && (!IsTypeNum(target) || !IsTypeNum(type)))
return TYPE_ERROR; return TYPE_ERROR;
return (target == TYPE_FLOAT || type == TYPE_FLOAT) ? TYPE_FLOAT return (target == TYPE_FLOAT || type == TYPE_FLOAT) ? TYPE_FLOAT
: (target == TYPE_DATE || type == TYPE_DATE) ? TYPE_DATE : (target == TYPE_DATE || type == TYPE_DATE) ? TYPE_DATE
: (target == TYPE_INT || type == TYPE_INT) ? TYPE_INT : (target == TYPE_BIGINT || type == TYPE_BIGINT) ? TYPE_BIGINT
: TYPE_SHORT; : (target == TYPE_INT || type == TYPE_INT) ? TYPE_INT
: TYPE_SHORT;
default: default:
if (!target || target == type) if (!target || target == type)
return type; return type;
...@@ -394,6 +406,7 @@ int ConvertType(int target, int type, CONV kind, bool match) ...@@ -394,6 +406,7 @@ int ConvertType(int target, int type, CONV kind, bool match)
return (target == TYPE_FLOAT || type == TYPE_FLOAT) ? TYPE_FLOAT return (target == TYPE_FLOAT || type == TYPE_FLOAT) ? TYPE_FLOAT
: (target == TYPE_DATE || type == TYPE_DATE) ? TYPE_DATE : (target == TYPE_DATE || type == TYPE_DATE) ? TYPE_DATE
: (target == TYPE_BIGINT || type == TYPE_BIGINT) ? TYPE_BIGINT
: (target == TYPE_INT || type == TYPE_INT) ? TYPE_INT : (target == TYPE_INT || type == TYPE_INT) ? TYPE_INT
: (target == TYPE_SHORT || type == TYPE_SHORT) ? TYPE_SHORT : (target == TYPE_SHORT || type == TYPE_SHORT) ? TYPE_SHORT
: (target == TYPE_STRING || type == TYPE_STRING) ? TYPE_STRING : (target == TYPE_STRING || type == TYPE_STRING) ? TYPE_STRING
...@@ -413,10 +426,11 @@ PVAL AllocateValue(PGLOBAL g, void *value, short type) ...@@ -413,10 +426,11 @@ PVAL AllocateValue(PGLOBAL g, void *value, short type)
htrc("AllocateConstant: value=%p type=%hd\n", value, type); htrc("AllocateConstant: value=%p type=%hd\n", value, type);
switch (type) { switch (type) {
case TYPE_STRING: valp = new(g) STRING((PSZ)value); break; case TYPE_STRING: valp = new(g) STRING((PSZ)value); break;
case TYPE_SHORT: valp = new(g) SHVAL(*(short*)value); break; case TYPE_SHORT: valp = new(g) SHVAL(*(short*)value); break;
case TYPE_INT: valp = new(g) INTVAL(*(int*)value); break; case TYPE_INT: valp = new(g) INTVAL(*(int*)value); break;
case TYPE_FLOAT: valp = new(g) DFVAL(*(double *)value); break; case TYPE_BIGINT: valp = new(g) BIGVAL(*(longlong*)value); break;
case TYPE_FLOAT: valp = new(g) DFVAL(*(double *)value); break;
default: default:
sprintf(g->Message, MSG(BAD_VALUE_TYPE), type); sprintf(g->Message, MSG(BAD_VALUE_TYPE), type);
return NULL; return NULL;
...@@ -439,6 +453,7 @@ PVAL AllocateValue(PGLOBAL g, int type, int len, int prec, ...@@ -439,6 +453,7 @@ PVAL AllocateValue(PGLOBAL g, int type, int len, int prec,
break; break;
case TYPE_DATE: valp = new(g) DTVAL(g, len, prec, dom); break; case TYPE_DATE: valp = new(g) DTVAL(g, len, prec, dom); break;
case TYPE_INT: valp = new(g) INTVAL((int)0); break; case TYPE_INT: valp = new(g) INTVAL((int)0); break;
case TYPE_BIGINT: valp = new(g) BIGVAL((longlong)0); break;
case TYPE_SHORT: valp = new(g) SHVAL((short)0); break; case TYPE_SHORT: valp = new(g) SHVAL((short)0); break;
case TYPE_FLOAT: valp = new(g) DFVAL(0.0, prec); break; case TYPE_FLOAT: valp = new(g) DFVAL(0.0, prec); break;
default: default:
...@@ -470,10 +485,11 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype) ...@@ -470,10 +485,11 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype)
valp = new(g) STRING(g, p, valp->GetValLen(), valp->GetValPrec()); valp = new(g) STRING(g, p, valp->GetValLen(), valp->GetValPrec());
break; break;
case TYPE_SHORT: valp = new(g) SHVAL(valp->GetShortValue()); break; case TYPE_SHORT: valp = new(g) SHVAL(valp->GetShortValue()); break;
case TYPE_INT: valp = new(g) INTVAL(valp->GetIntValue()); break; case TYPE_INT: valp = new(g) INTVAL(valp->GetIntValue()); break;
case TYPE_DATE: valp = new(g) DTVAL(g, valp->GetIntValue()); break; case TYPE_BIGINT: valp = new(g) BIGVAL(valp->GetBigintValue()); break;
case TYPE_FLOAT: valp = new(g) DFVAL(valp->GetFloatValue()); break; case TYPE_DATE: valp = new(g) DTVAL(g, valp->GetIntValue()); break;
case TYPE_FLOAT: valp = new(g) DFVAL(valp->GetFloatValue()); break;
default: default:
sprintf(g->Message, MSG(BAD_VALUE_TYPE), newtype); sprintf(g->Message, MSG(BAD_VALUE_TYPE), newtype);
return NULL; return NULL;
...@@ -510,6 +526,9 @@ char *VALUE::ShowTypedValue(PGLOBAL g, char *buf, int typ, int n, int p) ...@@ -510,6 +526,9 @@ char *VALUE::ShowTypedValue(PGLOBAL g, char *buf, int typ, int n, int p)
case TYPE_SHORT: case TYPE_SHORT:
buf = GetShortString(buf, n); buf = GetShortString(buf, n);
break; break;
case TYPE_BIGINT:
buf = GetBigintString(buf, n);
break;
default: default:
// More should be added for additional values. // More should be added for additional values.
if (trace) if (trace)
...@@ -586,6 +605,17 @@ STRING::STRING(PGLOBAL g, int n) : VALUE(TYPE_STRING) ...@@ -586,6 +605,17 @@ STRING::STRING(PGLOBAL g, int n) : VALUE(TYPE_STRING)
Ci = false; Ci = false;
} // end of STRING constructor } // end of STRING constructor
/***********************************************************************/
/* STRING public constructor from bigint. */
/***********************************************************************/
STRING::STRING(PGLOBAL g, longlong n) : VALUE(TYPE_STRING)
{
Strp = (char *)PlugSubAlloc(g, NULL, 12);
Len = sprintf(Strp, "%lld", n);
Clen = Len;
Ci = false;
} // end of STRING constructor
/***********************************************************************/ /***********************************************************************/
/* STRING public constructor from double. */ /* STRING public constructor from double. */
/***********************************************************************/ /***********************************************************************/
...@@ -645,7 +675,7 @@ void STRING::SetValue_pvblk(PVBLK blk, int n) ...@@ -645,7 +675,7 @@ void STRING::SetValue_pvblk(PVBLK blk, int n)
} // end of SetValue_pvblk } // end of SetValue_pvblk
/***********************************************************************/ /***********************************************************************/
/* STRING SetValue: get the character representation of an integer. */ /* STRING SetValue: get the character representation of a short int. */
/***********************************************************************/ /***********************************************************************/
void STRING::SetValue(short n) void STRING::SetValue(short n)
{ {
...@@ -669,6 +699,23 @@ void STRING::SetValue(int n) ...@@ -669,6 +699,23 @@ void STRING::SetValue(int n)
} // end of SetValue } // end of SetValue
/***********************************************************************/
/* STRING SetValue: get the character representation of a big integer.*/
/***********************************************************************/
void STRING::SetValue(longlong n)
{
char buf[24];
PGLOBAL& g = Global;
int k = sprintf(buf, "%lld", n);
if (k > Len) {
sprintf(g->Message, MSG(VALSTR_TOO_LONG), buf, Len);
longjmp(g->jumper[g->jump_level], 138);
} else
SetValue_psz(buf);
} // end of SetValue
/***********************************************************************/ /***********************************************************************/
/* STRING SetValue: get the character representation of a double. */ /* STRING SetValue: get the character representation of a double. */
/***********************************************************************/ /***********************************************************************/
...@@ -759,14 +806,23 @@ char *STRING::GetShortString(char *p, int n) ...@@ -759,14 +806,23 @@ char *STRING::GetShortString(char *p, int n)
} // end of GetShortString } // end of GetShortString
/***********************************************************************/ /***********************************************************************/
/* STRING GetIntString: get int representation of a char value. */ /* STRING GetIntString: get int representation of a char value. */
/***********************************************************************/ /***********************************************************************/
char *STRING::GetIntString(char *p, int n) char *STRING::GetIntString(char *p, int n)
{ {
sprintf(p, "%*ld", n, atol(Strp)); sprintf(p, "%*d", n, atol(Strp));
return p; return p;
} // end of GetIntString } // end of GetIntString
/***********************************************************************/
/* STRING GetIntString: get big int representation of a char value. */
/***********************************************************************/
char *STRING::GetBigintString(char *p, int n)
{
sprintf(p, "%*lld", n, atol(Strp));
return p;
} // end of GetBigintString
/***********************************************************************/ /***********************************************************************/
/* STRING GetFloatString: get double representation of a char value. */ /* STRING GetFloatString: get double representation of a char value. */
/***********************************************************************/ /***********************************************************************/
...@@ -1383,7 +1439,7 @@ SHVAL::SHVAL(short i) : VALUE(TYPE_SHORT) ...@@ -1383,7 +1439,7 @@ SHVAL::SHVAL(short i) : VALUE(TYPE_SHORT)
} // end of SHVAL constructor } // end of SHVAL constructor
/***********************************************************************/ /***********************************************************************/
/* SHVAL public constructor from int. */ /* SHVAL public constructor from int. */
/***********************************************************************/ /***********************************************************************/
SHVAL::SHVAL(int n) : VALUE(TYPE_SHORT) SHVAL::SHVAL(int n) : VALUE(TYPE_SHORT)
{ {
...@@ -1391,6 +1447,15 @@ SHVAL::SHVAL(int n) : VALUE(TYPE_SHORT) ...@@ -1391,6 +1447,15 @@ SHVAL::SHVAL(int n) : VALUE(TYPE_SHORT)
Clen = sizeof(short); Clen = sizeof(short);
} // end of SHVAL constructor } // end of SHVAL constructor
/***********************************************************************/
/* SHVAL public constructor from big int. */
/***********************************************************************/
SHVAL::SHVAL(longlong n) : VALUE(TYPE_SHORT)
{
Sval = (short)n;
Clen = sizeof(short);
} // end of SHVAL constructor
/***********************************************************************/ /***********************************************************************/
/* SHVAL public constructor from double. */ /* SHVAL public constructor from double. */
/***********************************************************************/ /***********************************************************************/
...@@ -1550,14 +1615,23 @@ char *SHVAL::GetShortString(char *p, int n) ...@@ -1550,14 +1615,23 @@ char *SHVAL::GetShortString(char *p, int n)
} // end of GetShortString } // end of GetShortString
/***********************************************************************/ /***********************************************************************/
/* SHVAL GetIntString: get int representation of a short value. */ /* SHVAL GetIntString: get int representation of a short value. */
/***********************************************************************/ /***********************************************************************/
char *SHVAL::GetIntString(char *p, int n) char *SHVAL::GetIntString(char *p, int n)
{ {
sprintf(p, "%*ld", n, (int)Sval); sprintf(p, "%*d", n, (int)Sval);
return p; return p;
} // end of GetIntString } // end of GetIntString
/***********************************************************************/
/* SHVAL GetBigintString: get big int representation of a short value.*/
/***********************************************************************/
char *SHVAL::GetBigintString(char *p, int n)
{
sprintf(p, "%*lld", n, (longlong)Sval);
return p;
} // end of GetBigintString
/***********************************************************************/ /***********************************************************************/
/* SHVAL GetFloatString: get double representation of a short value. */ /* SHVAL GetFloatString: get double representation of a short value. */
/***********************************************************************/ /***********************************************************************/
...@@ -1653,7 +1727,7 @@ bool SHVAL::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op) ...@@ -1653,7 +1727,7 @@ bool SHVAL::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op)
Sval = strlen(p); Sval = strlen(p);
if (trace) if (trace)
htrc("Compute result=%d val=%s op=%d\n", Sval, p, op); htrc("Compute result=%hd val=%s op=%d\n", Sval, p, op);
} else if (op == OP_INSTR || op == OP_LIKE || op == OP_CNTIN) { } else if (op == OP_INSTR || op == OP_LIKE || op == OP_CNTIN) {
char *p, *tp = g->Message; char *p, *tp = g->Message;
...@@ -2039,7 +2113,7 @@ bool SHVAL::SetConstFormat(PGLOBAL g, FORMAT& fmt) ...@@ -2039,7 +2113,7 @@ bool SHVAL::SetConstFormat(PGLOBAL g, FORMAT& fmt)
{ {
char c[16]; char c[16];
fmt.Type[0] = 'N'; fmt.Type[0] = 'S';
fmt.Length = sprintf(c, "%hd", Sval); fmt.Length = sprintf(c, "%hd", Sval);
fmt.Prec = 0; fmt.Prec = 0;
return false; return false;
...@@ -2096,7 +2170,16 @@ INTVAL::INTVAL(int n) : VALUE(TYPE_INT) ...@@ -2096,7 +2170,16 @@ INTVAL::INTVAL(int n) : VALUE(TYPE_INT)
} // end of INTVAL constructor } // end of INTVAL constructor
/***********************************************************************/ /***********************************************************************/
/* INTVAL public constructor from double. */ /* INTVAL public constructor from big int. */
/***********************************************************************/
INTVAL::INTVAL(longlong n) : VALUE(TYPE_INT)
{
Ival = (int)n;
Clen = sizeof(int);
} // end of INTVAL constructor
/***********************************************************************/
/* INTVAL public constructor from double. */
/***********************************************************************/ /***********************************************************************/
INTVAL::INTVAL(double f) : VALUE(TYPE_INT) INTVAL::INTVAL(double f) : VALUE(TYPE_INT)
{ {
...@@ -2228,7 +2311,7 @@ void INTVAL::GetBinValue(void *buf, int buflen) ...@@ -2228,7 +2311,7 @@ void INTVAL::GetBinValue(void *buf, int buflen)
/***********************************************************************/ /***********************************************************************/
char *INTVAL::ShowValue(char *buf, int len) char *INTVAL::ShowValue(char *buf, int len)
{ {
sprintf(buf, "%*ld", len, Ival); sprintf(buf, "%*d", len, Ival);
return buf; return buf;
} // end of ShowValue } // end of ShowValue
...@@ -2251,14 +2334,23 @@ char *INTVAL::GetShortString(char *p, int n) ...@@ -2251,14 +2334,23 @@ char *INTVAL::GetShortString(char *p, int n)
} // end of GetShortString } // end of GetShortString
/***********************************************************************/ /***********************************************************************/
/* INTVAL GetIntString: get int representation of a int value. */ /* INTVAL GetIntString: get int representation of a int value. */
/***********************************************************************/ /***********************************************************************/
char *INTVAL::GetIntString(char *p, int n) char *INTVAL::GetIntString(char *p, int n)
{ {
sprintf(p, "%*ld", n, Ival); sprintf(p, "%*d", n, Ival);
return p; return p;
} // end of GetIntString } // end of GetIntString
/***********************************************************************/
/* INTVAL GetBigintString: get big int representation of a int value. */
/***********************************************************************/
char *INTVAL::GetBigintString(char *p, int n)
{
sprintf(p, "%*lld", n, (longlong)Ival);
return p;
} // end of GetBigintString
/***********************************************************************/ /***********************************************************************/
/* INTVAL GetFloatString: get double representation of a int value. */ /* INTVAL GetFloatString: get double representation of a int value. */
/***********************************************************************/ /***********************************************************************/
...@@ -3443,113 +3535,136 @@ bool DTVAL::FormatValue(PVAL vp, char *fmt) ...@@ -3443,113 +3535,136 @@ bool DTVAL::FormatValue(PVAL vp, char *fmt)
} // end of FormatValue } // end of FormatValue
/* -------------------------- Class BIGVAL ---------------------------- */
/* -------------------------- Class DFVAL ---------------------------- */ /***********************************************************************/
/* BIGVAL public constructor from char. */
/***********************************************************************/
BIGVAL::BIGVAL(PSZ s) : VALUE(TYPE_BIGINT)
{
Lval = atoll(s);
Clen = sizeof(longlong);
} // end of BIGVAL constructor
/***********************************************************************/ /***********************************************************************/
/* DFVAL public constructor from char. */ /* BIGVAL public constructor from short. */
/***********************************************************************/ /***********************************************************************/
DFVAL::DFVAL(PSZ s, int prec) : VALUE(TYPE_FLOAT) BIGVAL::BIGVAL(short n) : VALUE(TYPE_BIGINT)
{ {
Fval = atof(s); Lval = (longlong)n;
Prec = prec; Clen = sizeof(longlong);
Clen = sizeof(double); } // end of BIGVAL constructor
} // end of DFVAL constructor
/***********************************************************************/ /***********************************************************************/
/* DFVAL public constructor from short. */ /* BIGVAL public constructor from int. */
/***********************************************************************/ /***********************************************************************/
DFVAL::DFVAL(short n, int prec) : VALUE(TYPE_FLOAT) BIGVAL::BIGVAL(int n) : VALUE(TYPE_BIGINT)
{ {
Fval = (double)n; Lval = (longlong)n;
Prec = prec; Clen = sizeof(longlong);
Clen = sizeof(double); } // end of BIGVAL constructor
} // end of DFVAL constructor
/***********************************************************************/ /***********************************************************************/
/* DFVAL public constructor from int. */ /* BIGVAL public constructor from big int. */
/***********************************************************************/ /***********************************************************************/
DFVAL::DFVAL(int n, int prec) : VALUE(TYPE_FLOAT) BIGVAL::BIGVAL(longlong n) : VALUE(TYPE_BIGINT)
{ {
Fval = (double)n; Lval = n;
Prec = prec; Clen = sizeof(longlong);
Clen = sizeof(double); } // end of BIGVAL constructor
} // end of DFVAL constructor
/***********************************************************************/ /***********************************************************************/
/* DFVAL public constructor from double. */ /* BIGVAL public constructor from double. */
/***********************************************************************/ /***********************************************************************/
DFVAL::DFVAL(double f, int prec) : VALUE(TYPE_FLOAT) BIGVAL::BIGVAL(double f) : VALUE(TYPE_BIGINT)
{ {
Fval = f; Lval = (longlong)f;
Prec = prec; Clen = sizeof(longlong);
Clen = sizeof(double); } // end of BIGVAL constructor
} // end of DFVAL constructor
/***********************************************************************/ /***********************************************************************/
/* DFVAL GetValLen: returns the print length of the double object. */ /* BIGVAL GetValLen: returns the print length of the int object. */
/***********************************************************************/ /***********************************************************************/
int DFVAL::GetValLen(void) int BIGVAL::GetValLen(void)
{ {
char c[32]; char c[24];
return sprintf(c, "%.*lf", Prec, Fval); return sprintf(c, "%lld", Lval);
} // end of GetValLen } // end of GetValLen
/***********************************************************************/ /***********************************************************************/
/* DFVAL SetValue: copy the value of another Value object. */ /* BIGVAL SetValue: copy the value of another Value object. */
/* This function allows conversion if chktype is false. */ /* This function allows conversion if chktype is false. */
/***********************************************************************/ /***********************************************************************/
bool DFVAL::SetValue_pval(PVAL valp, bool chktype) bool BIGVAL::SetValue_pval(PVAL valp, bool chktype)
{ {
if (chktype && Type != valp->GetType()) if (chktype && Type != valp->GetType())
return true; return true;
Fval = valp->GetFloatValue(); Lval = valp->GetBigintValue();
return false; return false;
} // end of SetValue } // end of SetValue
/***********************************************************************/ /***********************************************************************/
/* SetValue: convert chars extracted from a line to double value. */ /* BIGVAL SetValue: convert chars extracted from a line to a big int. */
/***********************************************************************/ /***********************************************************************/
void DFVAL::SetValue_char(char *p, int n) void BIGVAL::SetValue_char(char *p, int n)
{ {
char *p2, buf[32]; char *p2;
bool minus;
for (p2 = p + n; p < p2 && *p == ' '; p++) ; for (p2 = p + n; p < p2 && *p == ' '; p++) ;
n = min(p2 - p, 31); for (Lval = 0LL, minus = false; p < p2; p++)
memcpy(buf, p, n); switch (*p) {
buf[n] = '\0'; case '-':
Fval = atof(buf); minus = true;
case '+':
break;
case '0': Lval = Lval * 10LL; break;
case '1': Lval = Lval * 10LL + 1LL; break;
case '2': Lval = Lval * 10LL + 2LL; break;
case '3': Lval = Lval * 10LL + 3LL; break;
case '4': Lval = Lval * 10LL + 4LL; break;
case '5': Lval = Lval * 10LL + 5LL; break;
case '6': Lval = Lval * 10LL + 6LL; break;
case '7': Lval = Lval * 10LL + 7LL; break;
case '8': Lval = Lval * 10LL + 8LL; break;
case '9': Lval = Lval * 10LL + 9LL; break;
default:
p = p2;
} // endswitch *p
if (minus && Lval)
Lval = - Lval;
if (trace) if (trace)
htrc(" setting double: '%s' -> %lf\n", buf, Fval); htrc(" setting big int to: %lld\n", Lval);
} // end of SetValue } // end of SetValue
/***********************************************************************/ /***********************************************************************/
/* DFVAL SetValue: fill a double float value from a string. */ /* BIGVAL SetValue: fill a big int value from a string. */
/***********************************************************************/ /***********************************************************************/
void DFVAL::SetValue_psz(PSZ s) void BIGVAL::SetValue_psz(PSZ s)
{ {
Fval = atof(s); Lval = atoll(s);
} // end of SetValue } // end of SetValue
/***********************************************************************/ /***********************************************************************/
/* DFVAL SetValue: set value with a double extracted from a block. */ /* BIGVAL SetValue: set value with a int extracted from a block. */
/***********************************************************************/ /***********************************************************************/
void DFVAL::SetValue_pvblk(PVBLK blk, int n) void BIGVAL::SetValue_pvblk(PVBLK blk, int n)
{ {
Fval = blk->GetFloatValue(n); Lval = blk->GetBigintValue(n);
} // end of SetValue } // end of SetValue
/***********************************************************************/ /***********************************************************************/
/* SetBinValue: with bytes extracted from a line. */ /* BIGVAL SetBinValue: with bytes extracted from a line. */
/***********************************************************************/ /***********************************************************************/
void DFVAL::SetBinValue(void *p) void BIGVAL::SetBinValue(void *p)
{ {
Fval = *(double *)p; Lval = *(longlong *)p;
} // end of SetBinValue } // end of SetBinValue
/***********************************************************************/ /***********************************************************************/
...@@ -3558,19 +3673,19 @@ void DFVAL::SetBinValue(void *p) ...@@ -3558,19 +3673,19 @@ void DFVAL::SetBinValue(void *p)
/* returns true if not. Actual filling occurs only if go is true. */ /* returns true if not. Actual filling occurs only if go is true. */
/* Currently used by WriteColumn of binary files. */ /* Currently used by WriteColumn of binary files. */
/***********************************************************************/ /***********************************************************************/
bool DFVAL::GetBinValue(void *buf, int buflen, bool go) bool BIGVAL::GetBinValue(void *buf, int buflen, bool go)
{ {
// Test on length was removed here until a variable in column give the // Test on length was removed here until a variable in column give the
// real field length. For BIN files the field length logically cannot // real field length. For BIN files the field length logically cannot
// be different from the variable length because no conversion is done. // be different from the variable length because no conversion is done.
// Therefore this test is useless anyway. // Therefore this test is useless anyway.
//#if defined(_DEBUG) //#if defined(_DEBUG)
// if (sizeof(double) > buflen) // if (sizeof(int) > buflen)
// return true; // return true;
//#endif //#endif
if (go) if (go)
*(double *)buf = Fval; *(longlong *)buf = Lval;
return false; return false;
} // end of GetBinValue } // end of GetBinValue
...@@ -3578,52 +3693,755 @@ bool DFVAL::GetBinValue(void *buf, int buflen, bool go) ...@@ -3578,52 +3693,755 @@ bool DFVAL::GetBinValue(void *buf, int buflen, bool go)
/***********************************************************************/ /***********************************************************************/
/* GetBinValue: used by SELECT when called from QUERY and KINDEX. */ /* GetBinValue: used by SELECT when called from QUERY and KINDEX. */
/* This is a fast implementation that does not do any checking. */ /* This is a fast implementation that does not do any checking. */
/* Note: type is not needed here and just kept for compatibility. */
/***********************************************************************/ /***********************************************************************/
void DFVAL::GetBinValue(void *buf, int buflen) void BIGVAL::GetBinValue(void *buf, int buflen)
{ {
assert(buflen == sizeof(double)); assert(buflen == sizeof(longlong));
*(double *)buf = Fval; *(longlong *)buf = Lval;
} // end of GetBinValue } // end of GetBinValue
/***********************************************************************/ /***********************************************************************/
/* DFVAL ShowValue: get string representation of a double value. */ /* BIGVAL ShowValue: get string representation of a big int value. */
/***********************************************************************/ /***********************************************************************/
char *DFVAL::ShowValue(char *buf, int len) char *BIGVAL::ShowValue(char *buf, int len)
{ {
// TODO: use snprintf to avoid possible overflow sprintf(buf, "%*lld", len, Lval);
sprintf(buf, "%*.*lf", len, Prec, Fval);
return buf; return buf;
} // end of ShowValue } // end of ShowValue
/***********************************************************************/ /***********************************************************************/
/* DFVAL GetCharString: get string representation of a double value. */ /* BIGVAL GetCharString: get string representation of a big int value.*/
/***********************************************************************/ /***********************************************************************/
char *DFVAL::GetCharString(char *p) char *BIGVAL::GetCharString(char *p)
{ {
sprintf(p, "%.*lf", Prec, Fval); sprintf(p, "%lld", Lval);
return p; return p;
} // end of GetCharString } // end of GetCharString
/***********************************************************************/ /***********************************************************************/
/* DFVAL GetShortString: get short representation of a double value. */ /* BIGVAL GetShortString: get short representation of a int value. */
/***********************************************************************/ /***********************************************************************/
char *DFVAL::GetShortString(char *p, int n) char *BIGVAL::GetShortString(char *p, int n)
{ {
sprintf(p, "%*hd", n, (short)Fval); sprintf(p, "%*hd", n, (short)Lval);
return p; return p;
} // end of GetShortString } // end of GetShortString
/***********************************************************************/ /***********************************************************************/
/* DFVAL GetIntString: get int representation of a double value. */ /* BIGVAL GetIntString: get int representation of a int value. */
/***********************************************************************/ /***********************************************************************/
char *DFVAL::GetIntString(char *p, int n) char *BIGVAL::GetIntString(char *p, int n)
{ {
sprintf(p, "%*ld", n, (int)Fval); sprintf(p, "%*d", n, (int)Lval);
return p; return p;
} // end of GetIntString } // end of GetIntString
/***********************************************************************/
/* BIGVAL GetBigintString: get big int representation of a int value. */
/***********************************************************************/
char *BIGVAL::GetBigintString(char *p, int n)
{
sprintf(p, "%*lld", n, Lval);
return p;
} // end of GetBigintString
/***********************************************************************/
/* BIGVAL GetFloatString: get double representation of a int value. */
/***********************************************************************/
char *BIGVAL::GetFloatString(char *p, int n, int prec)
{
sprintf(p, "%*.*lf", n, (prec < 0) ? 2 : prec, (double)Lval);
return p;
} // end of GetFloatString
/***********************************************************************/
/* BIGVAL compare value with another Value. */
/***********************************************************************/
bool BIGVAL::IsEqual(PVAL vp, bool chktype)
{
if (this == vp)
return true;
else if (chktype && Type != vp->GetType())
return false;
else
return (Lval == vp->GetBigintValue());
} // end of IsEqual
/***********************************************************************/
/* Compare values and returns 1, 0 or -1 according to comparison. */
/* This function is used for evaluation of big int integer filters. */
/***********************************************************************/
int BIGVAL::CompareValue(PVAL vp)
{
//assert(vp->GetType() == Type);
// Process filtering on big int integers.
longlong n = vp->GetBigintValue();
if (trace > 1)
htrc(" Comparing: val=%lld,%lld\n", Lval, n);
return (Lval > n) ? 1 : (Lval < n) ? (-1) : 0;
} // end of CompareValue
/***********************************************************************/
/* SafeAdd: adds a value and test whether overflow/underflow occured. */
/***********************************************************************/
longlong BIGVAL::SafeAdd(longlong n1, longlong n2)
{
PGLOBAL& g = Global;
longlong n = n1 + n2;
if ((n2 > 0LL) && (n < n1)) {
// Overflow
strcpy(g->Message, MSG(FIX_OVFLW_ADD));
longjmp(g->jumper[g->jump_level], 138);
} else if ((n2 < 0LL) && (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
/***********************************************************************/
/* SafeMult: multiply values and test whether overflow occured. */
/***********************************************************************/
longlong BIGVAL::SafeMult(longlong n1, longlong n2)
{
PGLOBAL& g = Global;
double n = (double)n1 * (double)n2;
if (n > LLONG_MAX) {
// Overflow
strcpy(g->Message, MSG(FIX_OVFLW_TIMES));
longjmp(g->jumper[g->jump_level], 138);
} else if (n < LLONG_MIN) {
// Underflow
strcpy(g->Message, MSG(FIX_UNFLW_TIMES));
longjmp(g->jumper[g->jump_level], 138);
} // endif's n2
return n1 * n2;
} // end of SafeMult
/***********************************************************************/
/* Compute a function on a int integers. */
/***********************************************************************/
bool BIGVAL::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op)
{
if (op == OP_LEN) {
assert(np == 1);
char buf[32];
char *p = vp[0]->GetCharString(buf);
Lval = strlen(p);
if (trace)
htrc("Compute result=%lld val=%s op=%d\n", Lval, p, op);
} else if (op == OP_INSTR || op == OP_LIKE || op == OP_CNTIN) {
char *p, *tp = g->Message;
char *p1, val1[32];
char *p2, val2[32];
bool b = (vp[0]->IsCi() || vp[1]->IsCi());
assert(np == 2);
p1 = vp[0]->GetCharString(val1);
p2 = vp[1]->GetCharString(val2);
if (op != OP_LIKE) {
if (!strcmp(p2, "\\t"))
p2 = "\t";
if (b) { // Case insensitive
if (strlen(p1) + strlen(p2) + 1 >= MAX_STR &&
!(tp = new char[strlen(p1) + strlen(p2) + 2])) {
strcpy(g->Message, MSG(NEW_RETURN_NULL));
return true;
} // endif p
// Make a lower case copy of p1 and p2
p1 = strlwr(strcpy(tp, p1));
p2 = strlwr(strcpy(tp + strlen(p1) + 1, p2));
} // endif b
if (op == OP_CNTIN) {
size_t t2 = strlen(p2);
for (Lval = 0LL; (p = strstr(p1, p2)); Lval++, p1 = p + t2) ;
} else // OP_INSTR
Lval = (p = strstr(p1, p2)) ? 1LL + (longlong)(p - p1) : 0LL;
if (tp != g->Message) // If working space was obtained
delete [] tp; // by the use of new, delete it.
} else // OP_LIKE
Lval = (PlugEvalLike(g, p1, p2, b)) ? 1LL : 0LL;
if (trace)
htrc("Compute result=%lld val=%s,%s op=%d\n", Lval, p1, p2, op);
} else {
longlong val[2];
assert(np <= 2);
for (int i = 0; i < np; i++)
val[i] = vp[i]->GetBigintValue();
switch (op) {
case OP_ABS:
assert(np == 1);
Lval = (*val >= 0LL) ? *val : -*val;
break;
case OP_SIGN:
assert(np == 1);
Lval = (*val < 0LL) ? (-1) : 1;
break;
case OP_CEIL:
case OP_FLOOR:
assert(np == 1);
Lval = *val;
break;
case OP_ADD:
assert(np == 2);
Lval = SafeAdd(val[0], val[1]);
break;
case OP_SUB:
assert(np == 2);
Lval = SafeAdd(val[0], -val[1]);
break;
case OP_MULT:
assert(np == 2);
Lval = SafeMult(val[0], val[1]);
break;
case OP_MIN:
assert(np == 2);
Lval = min(val[0], val[1]);
break;
case OP_MAX:
assert(np == 2);
Lval = max(val[0], val[1]);
break;
case OP_DIV:
assert(np == 2);
if (!val[1]) {
strcpy(g->Message, MSG(ZERO_DIVIDE));
return true;
} // endif
Lval = val[0] / val[1];
break;
case OP_MOD:
assert(np == 2);
if (!val[1]) {
strcpy(g->Message, MSG(ZERO_DIVIDE));
return true;
} // endif
Lval = val[0] % val[1];
break;
case OP_BITAND:
assert(np == 2);
Lval = val[0] & val[1];
break;
case OP_BITOR:
assert(np == 2);
Lval = val[0] | val[1];
break;
case OP_BITXOR:
assert(np == 2);
Lval = val[0] ^ val[1];
break;
case OP_BITNOT:
assert(np == 1);
Lval = ~val[0];
break;
case OP_DELTA:
// assert(np == 1);
Lval = val[0] - Lval;
break;
default:
sprintf(g->Message, MSG(BAD_EXP_OPER), op);
return true;
} // endswitch op
if (trace)
if (np = 1)
htrc(" result=%lld val=%lld op=%d\n", Lval, val[0], op);
else
htrc(" result=%lld val=%lld,%lld op=%d\n",
Lval, val[0], val[1], op);
} // endif op
return false;
} // end of Compute
/***********************************************************************/
/* Divide: used by aggregate functions when calculating average. */
/***********************************************************************/
void BIGVAL::Divide(int cnt)
{
Lval /= cnt;
} // end of Divide
/***********************************************************************/
/* StdVar: used by aggregate functions for Stddev and Variance. */
/***********************************************************************/
void BIGVAL::StdVar(PVAL vp, int cnt, bool b)
{
longlong lv2 = vp->GetBigintValue();
Lval = (cnt == 1) ? 0
: (SafeAdd(lv2, -(SafeMult(Lval, Lval) / cnt)) / (cnt - 1));
if (b) // Builtin == FNC_STDDEV
Lval = (longlong)sqrt((double)Lval);
} // end of StdVar
/***********************************************************************/
/* Times: used by aggregate functions for Stddev and Variance. */
/***********************************************************************/
void BIGVAL::Times(PVAL vp)
{
Lval = SafeMult(Lval, vp->GetBigintValue());
} // end of Times
/***********************************************************************/
/* Add: used by aggregate functions for Sum and other functions. */
/***********************************************************************/
void BIGVAL::Add(PVAL vp)
{
Lval = SafeAdd(Lval, vp->GetBigintValue());
} // end of Add
/***********************************************************************/
/* Add: used by QUERY for function Sum and other functions. */
/***********************************************************************/
void BIGVAL::Add(PVBLK vbp, int i)
{
Lval = SafeAdd(Lval, vbp->GetBigintValue(i));
} // end of Add
/***********************************************************************/
/* Add: used by QUERY for function Sum and other functions. */
/***********************************************************************/
void BIGVAL::Add(PVBLK vbp, int j, int k)
{
CheckType(vbp)
longlong *lp = (longlong *)vbp->GetValPointer();
for (register int i = j; i < k; i++)
Lval = SafeAdd(Lval, lp[i]);
} // end of Add
/***********************************************************************/
/* Add: used by QUERY for function Sum and other functions. */
/***********************************************************************/
void BIGVAL::Add(PVBLK vbp, int *x, int j, int k)
{
CheckType(vbp)
longlong *lp = (longlong *)vbp->GetValPointer();
for (register int i = j; i < k; i++)
Lval = SafeAdd(Lval, lp[x[i]]);
} // end of Add
/***********************************************************************/
/* AddSquare: used by aggregate functions for Stddev and Variance. */
/***********************************************************************/
void BIGVAL::AddSquare(PVAL vp)
{
longlong val = vp->GetBigintValue();
Lval = SafeAdd(Lval, SafeMult(val, val));
} // end of AddSquare
/***********************************************************************/
/* AddSquare: used by QUERY for functions Stddev and Variance. */
/***********************************************************************/
void BIGVAL::AddSquare(PVBLK vbp, int i)
{
longlong val = vbp->GetBigintValue(i);
Lval = SafeAdd(Lval, SafeMult(val, val));
} // end of AddSquare
/***********************************************************************/
/* AddSquare: used by QUERY for functions Stddev and Variance. */
/***********************************************************************/
void BIGVAL::AddSquare(PVBLK vbp, int j, int k)
{
CheckType(vbp)
longlong *lp = (longlong *)vbp->GetValPointer();
for (register int i = j; i < k; i++)
Lval = SafeAdd(Lval, SafeMult(lp[i], lp[i]));
} // end of AddSquare
/***********************************************************************/
/* 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. */
/***********************************************************************/
bool BIGVAL::FormatValue(PVAL vp, char *fmt)
{
char *buf = (char*)vp->GetTo_Val(); // Should be big enough
int n = sprintf(buf, fmt, Lval);
return (n > vp->GetValLen());
} // end of FormatValue
/***********************************************************************/
/* SetMin: used by the aggregate function MIN. */
/***********************************************************************/
void BIGVAL::SetMin(PVAL vp)
{
longlong val = vp->GetBigintValue();
if (val < Lval)
Lval = val;
} // end of SetMin
/***********************************************************************/
/* SetMin: used by QUERY for the aggregate function MIN. */
/***********************************************************************/
void BIGVAL::SetMin(PVBLK vbp, int i)
{
longlong val = vbp->GetBigintValue(i);
if (val < Lval)
Lval = val;
} // end of SetMin
/***********************************************************************/
/* SetMin: used by QUERY for the aggregate function MIN. */
/***********************************************************************/
void BIGVAL::SetMin(PVBLK vbp, int j, int k)
{
CheckType(vbp)
longlong *lp = (longlong *)vbp->GetValPointer();
for (register int i = j; i < k; i++)
if (lp[i] < Lval)
Lval = lp[i];
} // end of SetMin
/***********************************************************************/
/* SetMin: used by QUERY for the aggregate function MIN. */
/***********************************************************************/
void BIGVAL::SetMin(PVBLK vbp, int *x, int j, int k)
{
CheckType(vbp)
longlong val;
longlong *lp = (longlong *)vbp->GetValPointer();
for (register int i = j; i < k; i++) {
val = lp[x[i]];
if (val < Lval)
Lval = val;
} // endfor i
} // end of SetMin
/***********************************************************************/
/* SetMax: used by the aggregate function MAX. */
/***********************************************************************/
void BIGVAL::SetMax(PVAL vp)
{
longlong val = vp->GetBigintValue();
if (val > Lval)
Lval = val;
} // end of SetMax
/***********************************************************************/
/* SetMax: used by QUERY for the aggregate function MAX. */
/***********************************************************************/
void BIGVAL::SetMax(PVBLK vbp, int i)
{
longlong val = vbp->GetBigintValue(i);
if (val > Lval)
Lval = val;
} // end of SetMax
/***********************************************************************/
/* SetMax: used by QUERY for the aggregate function MAX. */
/***********************************************************************/
void BIGVAL::SetMax(PVBLK vbp, int j, int k)
{
CheckType(vbp)
longlong *lp = (longlong *)vbp->GetValPointer();
for (register int i = j; i < k; i++)
if (lp[i] > Lval)
Lval = lp[i];
} // end of SetMax
/***********************************************************************/
/* SetMax: used by QUERY for the aggregate function MIN. */
/***********************************************************************/
void BIGVAL::SetMax(PVBLK vbp, int *x, int j, int k)
{
CheckType(vbp)
longlong val;
longlong *lp = (longlong *)vbp->GetValPointer();
for (register int i = j; i < k; i++) {
val = lp[x[i]];
if (val > Lval)
Lval = val;
} // endfor i
} // end of SetMax
/***********************************************************************/
/* BIGVAL SetFormat function (used to set SELECT output format). */
/***********************************************************************/
bool BIGVAL::SetConstFormat(PGLOBAL g, FORMAT& fmt)
{
char c[16];
fmt.Type[0] = 'L';
fmt.Length = sprintf(c, "%lld", Lval);
fmt.Prec = 0;
return false;
} // end of SetConstFormat
/***********************************************************************/
/* Make file output of a big int object. */
/***********************************************************************/
void BIGVAL::Print(PGLOBAL g, FILE *f, uint n)
{
char m[64];
memset(m, ' ', n); /* Make margin string */
m[n] = '\0';
fprintf(f, "%s%lld\n", m, Lval);
} /* end of Print */
/***********************************************************************/
/* Make string output of a int object. */
/***********************************************************************/
void BIGVAL::Print(PGLOBAL g, char *ps, uint z)
{
sprintf(ps, "%lld", Lval);
} /* end of Print */
/* -------------------------- Class DFVAL ---------------------------- */
/***********************************************************************/
/* DFVAL public constructor from char. */
/***********************************************************************/
DFVAL::DFVAL(PSZ s, int prec) : VALUE(TYPE_FLOAT)
{
Fval = atof(s);
Prec = prec;
Clen = sizeof(double);
} // end of DFVAL constructor
/***********************************************************************/
/* DFVAL public constructor from short. */
/***********************************************************************/
DFVAL::DFVAL(short n, int prec) : VALUE(TYPE_FLOAT)
{
Fval = (double)n;
Prec = prec;
Clen = sizeof(double);
} // end of DFVAL constructor
/***********************************************************************/
/* DFVAL public constructor from int. */
/***********************************************************************/
DFVAL::DFVAL(int n, int prec) : VALUE(TYPE_FLOAT)
{
Fval = (double)n;
Prec = prec;
Clen = sizeof(double);
} // end of DFVAL constructor
/***********************************************************************/
/* DFVAL public constructor from double. */
/***********************************************************************/
DFVAL::DFVAL(double f, int prec) : VALUE(TYPE_FLOAT)
{
Fval = f;
Prec = prec;
Clen = sizeof(double);
} // end of DFVAL constructor
/***********************************************************************/
/* DFVAL GetValLen: returns the print length of the double object. */
/***********************************************************************/
int DFVAL::GetValLen(void)
{
char c[32];
return sprintf(c, "%.*lf", Prec, Fval);
} // end of GetValLen
/***********************************************************************/
/* DFVAL SetValue: copy the value of another Value object. */
/* This function allows conversion if chktype is false. */
/***********************************************************************/
bool DFVAL::SetValue_pval(PVAL valp, bool chktype)
{
if (chktype && Type != valp->GetType())
return true;
Fval = valp->GetFloatValue();
return false;
} // end of SetValue
/***********************************************************************/
/* SetValue: convert chars extracted from a line to double value. */
/***********************************************************************/
void DFVAL::SetValue_char(char *p, int n)
{
char *p2, buf[32];
for (p2 = p + n; p < p2 && *p == ' '; p++) ;
n = min(p2 - p, 31);
memcpy(buf, p, n);
buf[n] = '\0';
Fval = atof(buf);
if (trace)
htrc(" setting double: '%s' -> %lf\n", buf, Fval);
} // end of SetValue
/***********************************************************************/
/* DFVAL SetValue: fill a double float value from a string. */
/***********************************************************************/
void DFVAL::SetValue_psz(PSZ s)
{
Fval = atof(s);
} // end of SetValue
/***********************************************************************/
/* DFVAL SetValue: set value with a double extracted from a block. */
/***********************************************************************/
void DFVAL::SetValue_pvblk(PVBLK blk, int n)
{
Fval = blk->GetFloatValue(n);
} // end of SetValue
/***********************************************************************/
/* SetBinValue: with bytes extracted from a line. */
/***********************************************************************/
void DFVAL::SetBinValue(void *p)
{
Fval = *(double *)p;
} // end of SetBinValue
/***********************************************************************/
/* GetBinValue: fill a buffer with the internal binary value. */
/* This function checks whether the buffer length is enough and */
/* returns true if not. Actual filling occurs only if go is true. */
/* Currently used by WriteColumn of binary files. */
/***********************************************************************/
bool DFVAL::GetBinValue(void *buf, int buflen, bool go)
{
// Test on length was removed here until a variable in column give the
// real field length. For BIN files the field length logically cannot
// be different from the variable length because no conversion is done.
// Therefore this test is useless anyway.
//#if defined(_DEBUG)
// if (sizeof(double) > buflen)
// return true;
//#endif
if (go)
*(double *)buf = Fval;
return false;
} // end of GetBinValue
/***********************************************************************/
/* GetBinValue: used by SELECT when called from QUERY and KINDEX. */
/* This is a fast implementation that does not do any checking. */
/* Note: type is not needed here and just kept for compatibility. */
/***********************************************************************/
void DFVAL::GetBinValue(void *buf, int buflen)
{
assert(buflen == sizeof(double));
*(double *)buf = Fval;
} // end of GetBinValue
/***********************************************************************/
/* DFVAL ShowValue: get string representation of a double value. */
/***********************************************************************/
char *DFVAL::ShowValue(char *buf, int len)
{
// TODO: use snprintf to avoid possible overflow
sprintf(buf, "%*.*lf", len, Prec, Fval);
return buf;
} // end of ShowValue
/***********************************************************************/
/* DFVAL GetCharString: get string representation of a double value. */
/***********************************************************************/
char *DFVAL::GetCharString(char *p)
{
sprintf(p, "%.*lf", Prec, Fval);
return p;
} // end of GetCharString
/***********************************************************************/
/* DFVAL GetShortString: get short representation of a double value. */
/***********************************************************************/
char *DFVAL::GetShortString(char *p, int n)
{
sprintf(p, "%*hd", n, (short)Fval);
return p;
} // end of GetShortString
/***********************************************************************/
/* DFVAL GetIntString: get int representation of a double value. */
/***********************************************************************/
char *DFVAL::GetIntString(char *p, int n)
{
sprintf(p, "%*ld", n, (int)Fval);
return p;
} // end of GetIntString
/***********************************************************************/
/* DFVAL GetBigintString: get big int representation of a double val. */
/***********************************************************************/
char *DFVAL::GetBigintString(char *p, int n)
{
sprintf(p, "%*lld", n, (longlong)Fval);
return p;
} // end of GetBigintString
/***********************************************************************/ /***********************************************************************/
/* DFVAL GetFloatString: get double representation of a double value. */ /* DFVAL GetFloatString: get double representation of a double value. */
/***********************************************************************/ /***********************************************************************/
......
/**************** Value H Declares Source Code File (.H) ***************/ /**************** Value H Declares Source Code File (.H) ***************/
/* Name: VALUE.H Version 1.6 */ /* Name: VALUE.H Version 1.7 */
/* */ /* */
/* (C) Copyright to the author Olivier BERTRAND 2001-2012 */ /* (C) Copyright to the author Olivier BERTRAND 2001-2013 */
/* */ /* */
/* This file contains the VALUE and derived classes declares. */ /* This file contains the VALUE and derived classes declares. */
/***********************************************************************/ /***********************************************************************/
...@@ -16,6 +16,11 @@ ...@@ -16,6 +16,11 @@
#include "assert.h" #include "assert.h"
#include "block.h" #include "block.h"
#if defined(WIN32)
#define strtoll _strtoi64
#define atoll(S) strtoll(S, NULL, 10)
#endif // WIN32
/***********************************************************************/ /***********************************************************************/
/* Types used in some class definitions. */ /* Types used in some class definitions. */
/***********************************************************************/ /***********************************************************************/
...@@ -72,6 +77,7 @@ class DllExport VALUE : public BLOCK { ...@@ -72,6 +77,7 @@ class DllExport VALUE : public BLOCK {
virtual PSZ GetCharValue(void) {assert(false); return NULL;} virtual PSZ GetCharValue(void) {assert(false); return NULL;}
virtual short GetShortValue(void) {assert(false); return 0;} virtual short GetShortValue(void) {assert(false); return 0;}
virtual int GetIntValue(void) = 0; virtual int GetIntValue(void) = 0;
virtual longlong GetBigintValue(void) = 0;
virtual double GetFloatValue(void) = 0; virtual double GetFloatValue(void) = 0;
virtual void *GetTo_Val(void) = 0; virtual void *GetTo_Val(void) = 0;
int GetType(void) {return Type;} int GetType(void) {return Type;}
...@@ -85,6 +91,7 @@ class DllExport VALUE : public BLOCK { ...@@ -85,6 +91,7 @@ class DllExport VALUE : public BLOCK {
virtual void SetValue_bool(bool b) {assert(false);} virtual void SetValue_bool(bool b) {assert(false);}
virtual void SetValue(short i) {assert(false);} virtual void SetValue(short i) {assert(false);}
virtual void SetValue(int n) {assert(false);} virtual void SetValue(int n) {assert(false);}
virtual void SetValue(longlong n) {assert(false);}
virtual void SetValue(double f) {assert(false);} virtual void SetValue(double f) {assert(false);}
virtual void SetValue_pvblk(PVBLK blk, int n) = 0; virtual void SetValue_pvblk(PVBLK blk, int n) = 0;
virtual void SetBinValue(void *p) = 0; virtual void SetBinValue(void *p) = 0;
...@@ -116,6 +123,7 @@ class DllExport VALUE : public BLOCK { ...@@ -116,6 +123,7 @@ class DllExport VALUE : public BLOCK {
virtual char *GetCharString(char *p) = 0; virtual char *GetCharString(char *p) = 0;
virtual char *GetShortString(char *p, int n) {return "#####";} virtual char *GetShortString(char *p, int n) {return "#####";}
virtual char *GetIntString(char *p, int n) = 0; virtual char *GetIntString(char *p, int n) = 0;
virtual char *GetBigintString(char *p, int n) = 0;
virtual char *GetFloatString(char *p, int n, int prec) = 0; virtual char *GetFloatString(char *p, int n, int prec) = 0;
virtual bool Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op) = 0; virtual bool Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op) = 0;
virtual int GetTime(PGLOBAL g, PVAL *vp, int np) = 0; virtual int GetTime(PGLOBAL g, PVAL *vp, int np) = 0;
...@@ -145,6 +153,7 @@ class STRING : public VALUE { ...@@ -145,6 +153,7 @@ class STRING : public VALUE {
STRING(PGLOBAL g, PSZ s, int n, int c = 0); STRING(PGLOBAL g, PSZ s, int n, int c = 0);
STRING(PGLOBAL g, short i); STRING(PGLOBAL g, short i);
STRING(PGLOBAL g, int n); STRING(PGLOBAL g, int n);
STRING(PGLOBAL g, longlong n);
STRING(PGLOBAL g, double f); STRING(PGLOBAL g, double f);
// Implementation // Implementation
...@@ -159,6 +168,7 @@ class STRING : public VALUE { ...@@ -159,6 +168,7 @@ class STRING : public VALUE {
virtual PSZ GetCharValue(void) {return Strp;} virtual PSZ GetCharValue(void) {return Strp;}
virtual short GetShortValue(void) {return (short)atoi(Strp);} virtual short GetShortValue(void) {return (short)atoi(Strp);}
virtual int GetIntValue(void) {return atol(Strp);} virtual int GetIntValue(void) {return atol(Strp);}
virtual longlong GetBigintValue(void) {return strtoll(Strp, NULL, 10);}
virtual double GetFloatValue(void) {return atof(Strp);} virtual double GetFloatValue(void) {return atof(Strp);}
virtual void *GetTo_Val(void) {return Strp;} virtual void *GetTo_Val(void) {return Strp;}
...@@ -169,6 +179,7 @@ class STRING : public VALUE { ...@@ -169,6 +179,7 @@ class STRING : public VALUE {
virtual void SetValue_pvblk(PVBLK blk, int n); virtual void SetValue_pvblk(PVBLK blk, int n);
virtual void SetValue(short i); virtual void SetValue(short i);
virtual void SetValue(int n); virtual void SetValue(int n);
virtual void SetValue(longlong n);
virtual void SetValue(double f); virtual void SetValue(double f);
virtual void SetBinValue(void *p); virtual void SetBinValue(void *p);
virtual bool GetBinValue(void *buf, int buflen, bool go); virtual bool GetBinValue(void *buf, int buflen, bool go);
...@@ -177,6 +188,7 @@ class STRING : public VALUE { ...@@ -177,6 +188,7 @@ class STRING : public VALUE {
virtual char *GetCharString(char *p); virtual char *GetCharString(char *p);
virtual char *GetShortString(char *p, int n); virtual char *GetShortString(char *p, int n);
virtual char *GetIntString(char *p, int n); virtual char *GetIntString(char *p, int n);
virtual char *GetBigintString(char *p, int n);
virtual char *GetFloatString(char *p, int n, int prec = -1); virtual char *GetFloatString(char *p, int n, int prec = -1);
virtual bool IsEqual(PVAL vp, bool chktype); virtual bool IsEqual(PVAL vp, bool chktype);
virtual int CompareValue(PVAL vp); virtual int CompareValue(PVAL vp);
...@@ -215,6 +227,7 @@ class SHVAL : public VALUE { ...@@ -215,6 +227,7 @@ class SHVAL : public VALUE {
SHVAL(PSZ s); SHVAL(PSZ s);
SHVAL(short n); SHVAL(short n);
SHVAL(int n); SHVAL(int n);
SHVAL(longlong n);
SHVAL(double f); SHVAL(double f);
// Implementation // Implementation
...@@ -227,6 +240,7 @@ class SHVAL : public VALUE { ...@@ -227,6 +240,7 @@ class SHVAL : public VALUE {
//virtual PSZ GetCharValue(void) {} //virtual PSZ GetCharValue(void) {}
virtual short GetShortValue(void) {return Sval;} virtual short GetShortValue(void) {return Sval;}
virtual int GetIntValue(void) {return (int)Sval;} virtual int GetIntValue(void) {return (int)Sval;}
virtual longlong GetBigintValue(void) {return (longlong)Sval;}
virtual double GetFloatValue(void) {return (double)Sval;} virtual double GetFloatValue(void) {return (double)Sval;}
virtual void *GetTo_Val(void) {return &Sval;} virtual void *GetTo_Val(void) {return &Sval;}
...@@ -237,6 +251,7 @@ class SHVAL : public VALUE { ...@@ -237,6 +251,7 @@ class SHVAL : public VALUE {
virtual void SetValue_bool(bool b) {Sval = (b) ? 1 : 0;} virtual void SetValue_bool(bool b) {Sval = (b) ? 1 : 0;}
virtual void SetValue(short i) {Sval = i;} virtual void SetValue(short i) {Sval = i;}
virtual void SetValue(int n) {Sval = (short)n;} virtual void SetValue(int n) {Sval = (short)n;}
virtual void SetValue(longlong n) {Sval = (short)n;}
virtual void SetValue_pvblk(PVBLK blk, int n); virtual void SetValue_pvblk(PVBLK blk, int n);
virtual void SetBinValue(void *p); virtual void SetBinValue(void *p);
virtual bool GetBinValue(void *buf, int buflen, bool go); virtual bool GetBinValue(void *buf, int buflen, bool go);
...@@ -245,6 +260,7 @@ class SHVAL : public VALUE { ...@@ -245,6 +260,7 @@ class SHVAL : public VALUE {
virtual char *GetCharString(char *p); virtual char *GetCharString(char *p);
virtual char *GetShortString(char *p, int n); virtual char *GetShortString(char *p, int n);
virtual char *GetIntString(char *p, int n); virtual char *GetIntString(char *p, int n);
virtual char *GetBigintString(char *p, int n);
virtual char *GetFloatString(char *p, int n, int prec = -1); virtual char *GetFloatString(char *p, int n, int prec = -1);
virtual bool IsEqual(PVAL vp, bool chktype); virtual bool IsEqual(PVAL vp, bool chktype);
virtual int CompareValue(PVAL vp); virtual int CompareValue(PVAL vp);
...@@ -293,6 +309,7 @@ class DllExport INTVAL : public VALUE { ...@@ -293,6 +309,7 @@ class DllExport INTVAL : public VALUE {
INTVAL(PSZ s); INTVAL(PSZ s);
INTVAL(short i); INTVAL(short i);
INTVAL(int n); INTVAL(int n);
INTVAL(longlong n);
INTVAL(double f); INTVAL(double f);
// Implementation // Implementation
...@@ -305,6 +322,7 @@ class DllExport INTVAL : public VALUE { ...@@ -305,6 +322,7 @@ class DllExport INTVAL : public VALUE {
//virtual PSZ GetCharValue(void) {} //virtual PSZ GetCharValue(void) {}
virtual short GetShortValue(void) {return (short)Ival;} virtual short GetShortValue(void) {return (short)Ival;}
virtual int GetIntValue(void) {return Ival;} virtual int GetIntValue(void) {return Ival;}
virtual longlong GetBigintValue(void) {return (longlong)Ival;}
virtual double GetFloatValue(void) {return (double)Ival;} virtual double GetFloatValue(void) {return (double)Ival;}
virtual void *GetTo_Val(void) {return &Ival;} virtual void *GetTo_Val(void) {return &Ival;}
...@@ -315,6 +333,7 @@ class DllExport INTVAL : public VALUE { ...@@ -315,6 +333,7 @@ class DllExport INTVAL : public VALUE {
virtual void SetValue_bool(bool b) {Ival = (b) ? 1 : 0;} virtual void SetValue_bool(bool b) {Ival = (b) ? 1 : 0;}
virtual void SetValue(short i) {Ival = (int)i;} virtual void SetValue(short i) {Ival = (int)i;}
virtual void SetValue(int n) {Ival = n;} virtual void SetValue(int n) {Ival = n;}
virtual void SetValue(longlong n) {Ival = (int)n;}
virtual void SetValue(double f) {Ival = (int)f;} virtual void SetValue(double f) {Ival = (int)f;}
virtual void SetValue_pvblk(PVBLK blk, int n); virtual void SetValue_pvblk(PVBLK blk, int n);
virtual void SetBinValue(void *p); virtual void SetBinValue(void *p);
...@@ -324,6 +343,7 @@ class DllExport INTVAL : public VALUE { ...@@ -324,6 +343,7 @@ class DllExport INTVAL : public VALUE {
virtual char *GetCharString(char *p); virtual char *GetCharString(char *p);
virtual char *GetShortString(char *p, int n); virtual char *GetShortString(char *p, int n);
virtual char *GetIntString(char *p, int n); virtual char *GetIntString(char *p, int n);
virtual char *GetBigintString(char *p, int n);
virtual char *GetFloatString(char *p, int n, int prec = -1); virtual char *GetFloatString(char *p, int n, int prec = -1);
virtual bool IsEqual(PVAL vp, bool chktype); virtual bool IsEqual(PVAL vp, bool chktype);
virtual int CompareValue(PVAL vp); virtual int CompareValue(PVAL vp);
...@@ -373,6 +393,7 @@ class DllExport DTVAL : public INTVAL { ...@@ -373,6 +393,7 @@ class DllExport DTVAL : public INTVAL {
DTVAL(PGLOBAL g, PSZ s, int n); DTVAL(PGLOBAL g, PSZ s, int n);
DTVAL(PGLOBAL g, short i); DTVAL(PGLOBAL g, short i);
DTVAL(PGLOBAL g, int n); DTVAL(PGLOBAL g, int n);
DTVAL(PGLOBAL g, longlong n);
DTVAL(PGLOBAL g, double f); DTVAL(PGLOBAL g, double f);
// Implementation // Implementation
...@@ -413,6 +434,89 @@ class DllExport DTVAL : public INTVAL { ...@@ -413,6 +434,89 @@ class DllExport DTVAL : public INTVAL {
int Len; // Used by CHAR scalar function int Len; // Used by CHAR scalar function
}; // end of class DTVAL }; // end of class DTVAL
/***********************************************************************/
/* Class BIGVAL: represents bigint integer values. */
/***********************************************************************/
class DllExport BIGVAL : public VALUE {
public:
// Constructors
BIGVAL(PSZ s);
BIGVAL(short i);
BIGVAL(int n);
BIGVAL(longlong n);
BIGVAL(double f);
// Implementation
virtual bool IsTypeNum(void) {return true;}
virtual bool IsZero(void) {return Lval == 0;}
virtual void Reset(void) {Lval = 0;}
virtual int GetValLen(void);
virtual int GetValPrec() {return 0;}
virtual int GetSize(void) {return sizeof(longlong);}
//virtual PSZ GetCharValue(void) {}
virtual short GetShortValue(void) {return (short)Lval;}
virtual int GetIntValue(void) {return (int)Lval;}
virtual longlong GetBigintValue(void) {return Lval;}
virtual double GetFloatValue(void) {return (double)Lval;}
virtual void *GetTo_Val(void) {return &Lval;}
// Methods
virtual bool SetValue_pval(PVAL valp, bool chktype);
virtual void SetValue_char(char *p, int n);
virtual void SetValue_psz(PSZ s);
virtual void SetValue_bool(bool b) {Lval = (b) ? 1 : 0;}
virtual void SetValue(short i) {Lval = (longlong)i;}
virtual void SetValue(int n) {Lval = (longlong)n;}
virtual void SetValue(longlong n) {Lval = n;}
virtual void SetValue(double f) {Lval = (longlong)f;}
virtual void SetValue_pvblk(PVBLK blk, int n);
virtual void SetBinValue(void *p);
virtual bool GetBinValue(void *buf, int buflen, bool go);
virtual void GetBinValue(void *buf, int len);
virtual char *ShowValue(char *buf, int);
virtual char *GetCharString(char *p);
virtual char *GetShortString(char *p, int n);
virtual char *GetIntString(char *p, int n);
virtual char *GetBigintString(char *p, int n);
virtual char *GetFloatString(char *p, int n, int prec = -1);
virtual bool IsEqual(PVAL vp, bool chktype);
virtual int CompareValue(PVAL vp);
virtual void Divide(int cnt);
virtual void StdVar(PVAL vp, int cnt, bool b);
virtual void Add(int lv) {Lval += (longlong)lv;}
virtual void Add(PVAL vp);
virtual void Add(PVBLK vbp, int i);
virtual void Add(PVBLK vbp, int j, int k);
virtual void Add(PVBLK vbp, int *x, int j, int k);
virtual void AddSquare(PVAL vp);
virtual void AddSquare(PVBLK vbp, int i);
virtual void AddSquare(PVBLK vbp, int j, int k);
virtual void Times(PVAL vp);
virtual void SetMin(PVAL vp);
virtual void SetMin(PVBLK vbp, int i);
virtual void SetMin(PVBLK vbp, int j, int k);
virtual void SetMin(PVBLK vbp, int *x, int j, int k);
virtual void SetMax(PVAL vp);
virtual void SetMax(PVBLK vbp, int i);
virtual void SetMax(PVBLK vbp, int j, int k);
virtual void SetMax(PVBLK vbp, int *x, int j, int k);
virtual bool SetConstFormat(PGLOBAL, FORMAT&);
virtual bool Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op);
virtual int GetTime(PGLOBAL g, PVAL *vp, int np) {return 0;}
virtual bool FormatValue(PVAL vp, char *fmt);
virtual void Print(PGLOBAL g, FILE *, uint);
virtual void Print(PGLOBAL g, char *, uint);
protected:
longlong SafeAdd(longlong n1, longlong n2);
longlong SafeMult(longlong n1, longlong n2);
// Default constructor not to be used
BIGVAL(void) : VALUE(TYPE_ERROR) {}
// Members
longlong Lval;
}; // end of class BIGVAL
/***********************************************************************/ /***********************************************************************/
/* Class DFVAL: represents double float values. */ /* Class DFVAL: represents double float values. */
/***********************************************************************/ /***********************************************************************/
...@@ -422,6 +526,7 @@ class DFVAL : public VALUE { ...@@ -422,6 +526,7 @@ class DFVAL : public VALUE {
DFVAL(PSZ s, int prec = 2); DFVAL(PSZ s, int prec = 2);
DFVAL(short i, int prec = 2); DFVAL(short i, int prec = 2);
DFVAL(int n, int prec = 2); DFVAL(int n, int prec = 2);
DFVAL(longlong n, int prec = 2);
DFVAL(double f, int prec = 2); DFVAL(double f, int prec = 2);
// Implementation // Implementation
...@@ -434,6 +539,7 @@ class DFVAL : public VALUE { ...@@ -434,6 +539,7 @@ class DFVAL : public VALUE {
//virtual PSZ GetCharValue(void) {} //virtual PSZ GetCharValue(void) {}
virtual short GetShortValue(void) {return (short)Fval;} virtual short GetShortValue(void) {return (short)Fval;}
virtual int GetIntValue(void) {return (int)Fval;} virtual int GetIntValue(void) {return (int)Fval;}
virtual longlong GetBigintValue(void) {return (longlong)Fval;}
virtual double GetFloatValue(void) {return Fval;} virtual double GetFloatValue(void) {return Fval;}
virtual void *GetTo_Val(void) {return &Fval;} virtual void *GetTo_Val(void) {return &Fval;}
void SetPrec(int prec) {Prec = prec;} void SetPrec(int prec) {Prec = prec;}
...@@ -444,6 +550,7 @@ class DFVAL : public VALUE { ...@@ -444,6 +550,7 @@ class DFVAL : public VALUE {
virtual void SetValue_psz(PSZ s); virtual void SetValue_psz(PSZ s);
virtual void SetValue(short i) {Fval = (double)i;} virtual void SetValue(short i) {Fval = (double)i;}
virtual void SetValue(int n) {Fval = (double)n;} virtual void SetValue(int n) {Fval = (double)n;}
virtual void SetValue(longlong n) {Fval = (double)n;}
virtual void SetValue(double f) {Fval = f;} virtual void SetValue(double f) {Fval = f;}
virtual void SetValue_pvblk(PVBLK blk, int n); virtual void SetValue_pvblk(PVBLK blk, int n);
virtual void SetBinValue(void *p); virtual void SetBinValue(void *p);
...@@ -453,6 +560,7 @@ class DFVAL : public VALUE { ...@@ -453,6 +560,7 @@ class DFVAL : public VALUE {
virtual char *GetCharString(char *p); virtual char *GetCharString(char *p);
virtual char *GetShortString(char *p, int n); virtual char *GetShortString(char *p, int n);
virtual char *GetIntString(char *p, int n); virtual char *GetIntString(char *p, int n);
virtual char *GetBigintString(char *p, int n);
virtual char *GetFloatString(char *p, int n, int prec = -1); virtual char *GetFloatString(char *p, int n, int prec = -1);
virtual bool IsEqual(PVAL vp, bool chktype); virtual bool IsEqual(PVAL vp, bool chktype);
virtual int CompareValue(PVAL vp); virtual int CompareValue(PVAL vp);
......
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