Commit 17fb343a authored by Olivier Bertrand's avatar Olivier Bertrand

- Add tiny integer as a supported type by CONNECT

modified:
  storage/connect/global.h
  storage/connect/ha_connect.cc
  storage/connect/myutil.cpp
  storage/connect/plgdbutl.cpp
  storage/connect/tabdos.cpp
  storage/connect/tabwmi.cpp
  storage/connect/valblk.cpp
  storage/connect/valblk.h
  storage/connect/value.cpp
  storage/connect/value.h
  storage/connect/xobject.cpp
parent ffc29ac3
......@@ -79,6 +79,7 @@
#define TYPE_STRING 1
#define TYPE_FLOAT 2
#define TYPE_SHORT 3
#define TYPE_TINY 4
#define TYPE_BIGINT 5
#define TYPE_LIST 6
#define TYPE_INT 7
......
......@@ -1097,6 +1097,9 @@ void *ha_connect::GetColumnOption(void *field, PCOLINFO pcf)
case MYSQL_TYPE_SHORT:
pcf->Type= TYPE_SHORT;
break;
case MYSQL_TYPE_TINY:
pcf->Type= TYPE_TINY;
break;
case MYSQL_TYPE_DOUBLE:
case MYSQL_TYPE_FLOAT:
pcf->Type= TYPE_FLOAT;
......@@ -3797,6 +3800,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
case MYSQL_TYPE_NEWDATE:
case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_LONGLONG:
case MYSQL_TYPE_TINY:
break; // Ok
case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_STRING:
......@@ -3804,7 +3808,6 @@ int ha_connect::create(const char *name, TABLE *table_arg,
case MYSQL_TYPE_NEWDECIMAL:
case MYSQL_TYPE_INT24:
break; // To be checked
case MYSQL_TYPE_TINY:
case MYSQL_TYPE_BIT:
case MYSQL_TYPE_NULL:
case MYSQL_TYPE_ENUM:
......
/************** MyUtil C++ Program Source Code File (.CPP) **************/
/* PROGRAM NAME: MYUTIL */
/* ------------- */
/* Version 1.0 */
/* Version 1.1 */
/* */
/* Author Olivier BERTRAND 2013 */
/* */
......@@ -35,7 +35,7 @@ int MYSQLtoPLG(char *typname)
if (!stricmp(typname, "int") || !stricmp(typname, "mediumint") ||
!stricmp(typname, "integer"))
type = TYPE_INT;
else if (!stricmp(typname, "tinyint") || !stricmp(typname, "smallint"))
else if (!stricmp(typname, "smallint"))
type = TYPE_SHORT;
else if (!stricmp(typname, "char") || !stricmp(typname, "varchar") ||
!stricmp(typname, "text") || !stricmp(typname, "blob"))
......@@ -50,6 +50,8 @@ int MYSQLtoPLG(char *typname)
type = TYPE_DATE;
else if (!stricmp(typname, "bigint") || !stricmp(typname, "longlong"))
type = TYPE_BIGINT;
else if (!stricmp(typname, "tinyint"))
type = TYPE_TINY;
else
type = TYPE_ERROR;
......@@ -82,6 +84,9 @@ enum enum_field_types PLGtoMYSQL(int type, bool dbf)
case TYPE_BIGINT:
mytype = MYSQL_TYPE_LONGLONG;
break;
case TYPE_TINY:
mytype = MYSQL_TYPE_TINY;
break;
default:
mytype = MYSQL_TYPE_NULL;
} // endswitch mytype
......@@ -97,7 +102,6 @@ int MYSQLtoPLG(int mytype)
int type;
switch (mytype) {
case MYSQL_TYPE_TINY:
case MYSQL_TYPE_SHORT:
type = TYPE_SHORT;
break;
......@@ -109,6 +113,9 @@ int MYSQLtoPLG(int mytype)
case MYSQL_TYPE_LONGLONG:
type = TYPE_BIGINT;
break;
case MYSQL_TYPE_TINY:
type = TYPE_TINY;
break;
case MYSQL_TYPE_DECIMAL:
#if !defined(ALPHA)
case MYSQL_TYPE_NEWDECIMAL:
......
......@@ -1529,6 +1529,10 @@ void PlugPutOut(PGLOBAL g, FILE *f, short t, void *v, uint n)
fprintf(f, "%s%hd\n", m, *(short *)v);
break;
case TYPE_TINY:
fprintf(f, "%s%d\n", m, (int)*(char *)v);
break;
case TYPE_VOID:
break;
......
......@@ -1086,6 +1086,7 @@ void DOSCOL::ReadColumn(PGLOBAL g)
if (Nod) switch (Buf_Type) {
case TYPE_INT:
case TYPE_SHORT:
case TYPE_TINY:
case TYPE_BIGINT:
Value->SetValue_char(p, field - Dcm);
break;
......@@ -1175,7 +1176,7 @@ void DOSCOL::WriteColumn(PGLOBAL g)
len = sprintf(Buf, fmt, field - i, Value->GetShortValue());
break;
case TYPE_INT:
strcpy(fmt, (Ldz) ? "%0*ld" : "%*.ld");
strcpy(fmt, (Ldz) ? "%0*d" : "%*.d");
i = 0;
if (Nod)
......@@ -1184,6 +1185,16 @@ void DOSCOL::WriteColumn(PGLOBAL g)
len = sprintf(Buf, fmt, field - i, Value->GetIntValue());
break;
case TYPE_TINY:
strcpy(fmt, (Ldz) ? "%0*d" : "%*.d");
i = 0;
if (Nod)
for (; i < Dcm; i++)
strcat(fmt, "0");
len = sprintf(Buf, fmt, field - i, Value->GetTinyValue());
break;
case TYPE_FLOAT:
strcpy(fmt, (Ldz) ? "%0*.*lf" : "%*.*lf");
sprintf(Buf, fmt, field + ((Nod && Dcm) ? 1 : 0),
......
......@@ -256,10 +256,13 @@ PQRYRES WMIColumns(PGLOBAL g, char *nsp, char *cls, bool info)
case CIM_UINT32:
case CIM_BOOLEAN:
typ = TYPE_INT;
lng = 9;
lng = 11;
break;
case CIM_SINT8:
case CIM_UINT8:
typ = TYPE_TINY;
lng = 4;
break;
case CIM_SINT16:
case CIM_UINT16:
typ = TYPE_SHORT;
......@@ -268,11 +271,14 @@ PQRYRES WMIColumns(PGLOBAL g, char *nsp, char *cls, bool info)
case CIM_REAL64:
case CIM_REAL32:
prec = 2;
case CIM_SINT64:
case CIM_UINT64:
typ = TYPE_FLOAT;
lng = 15;
break;
case CIM_SINT64:
case CIM_UINT64:
typ = TYPE_BIGINT;
lng = 20;
break;
case CIM_DATETIME:
typ = TYPE_DATE;
lng = 19;
......
This diff is collapsed.
/*************** Valblk H Declares Source Code File (.H) ***************/
/* Name: VALBLK.H Version 1.8 */
/* Name: VALBLK.H Version 1.9 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2005-2013 */
/* */
......@@ -50,6 +50,7 @@ class VALBLK : public BLOCK {
virtual int GetIntValue(int n) = 0;
virtual longlong GetBigintValue(int n) = 0;
virtual double GetFloatValue(int n) = 0;
virtual char GetTinyValue(int n) = 0;
virtual void ReAlloc(void *mp, int n) {Blkp = mp; Nval = n;}
virtual void Reset(int n) = 0;
virtual bool SetFormat(PGLOBAL g, PSZ fmt, int len, int year = 0);
......@@ -61,6 +62,7 @@ class VALBLK : public BLOCK {
virtual void SetValue(int lval, int n) {assert(false);}
virtual void SetValue(longlong lval, int n) {assert(false);}
virtual void SetValue(double fval, int n) {assert(false);}
virtual void SetValue(char cval, int n) {assert(false);}
virtual void SetValue(PSZ sp, int n) {assert(false);}
virtual void SetValue(PVAL valp, int n) = 0;
virtual void SetValue(PVBLK pv, int n1, int n2) = 0;
......@@ -113,6 +115,7 @@ class TYPBLK : public VALBLK {
virtual int GetIntValue(int n) {return (int)Typp[n];}
virtual longlong GetBigintValue(int n) {return (longlong)Typp[n];}
virtual double GetFloatValue(int n) {return (double)Typp[n];}
virtual char GetTinyValue(int n) {return (char)Typp[n];}
virtual void Reset(int n) {Typp[n] = 0;}
// Methods
......@@ -125,6 +128,8 @@ class TYPBLK : public VALBLK {
{Typp[n] = (TYPE)lval; SetNull(n, false);}
virtual void SetValue(double fval, int n)
{Typp[n] = (TYPE)fval; SetNull(n, false);}
virtual void SetValue(char cval, int n)
{Typp[n] = (TYPE)cval; SetNull(n, false);}
virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2);
//virtual void SetValues(PVBLK pv, int k, int n);
......@@ -163,6 +168,7 @@ class CHRBLK : public VALBLK {
virtual int GetIntValue(int n);
virtual longlong GetBigintValue(int n);
virtual double GetFloatValue(int n);
virtual char GetTinyValue(int n);
virtual void Reset(int n);
virtual void SetPrec(int p) {Ci = (p != 0);}
virtual bool IsCi(void) {return Ci;}
......@@ -210,6 +216,7 @@ class STRBLK : public VALBLK {
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 char GetTinyValue(int n) {return (char)atoi(Strp[n]);}
virtual void Reset(int n) {Strp[n] = NULL;}
// Methods
......@@ -230,92 +237,6 @@ class STRBLK : public VALBLK {
PSZ* const &Strp; // Pointer to PSZ buffer
}; // end of class STRBLK
#if 0
/***********************************************************************/
/* Class SHRBLK: represents a block of short integer values. */
/***********************************************************************/
class SHRBLK : public VALBLK {
public:
// Constructors
SHRBLK(void *mp, int size);
// Implementation
virtual void Init(PGLOBAL g, bool check);
virtual int GetVlen(void) {return sizeof(short);}
//virtual PSZ GetCharValue(int n);
virtual short GetShortValue(int n) {return 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 void Reset(int n) {Shrp[n] = 0;}
// Methods
virtual void SetValue(PSZ sp, int n);
virtual void SetValue(short sval, int n)
{Shrp[n] = sval; SetNull(n, false);}
virtual void SetValue(int lval, int n)
{Shrp[n] = (short)lval; SetNull(n, false);}
virtual void SetValue(longlong lval, int n)
{Shrp[n] = (short)lval; SetNull(n, false);}
virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2);
//virtual void SetValues(PVBLK pv, int k, int n);
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
short* const &Shrp;
}; // end of class SHRBLK
/***********************************************************************/
/* Class LNGBLK: represents a block of int integer values. */
/***********************************************************************/
class LNGBLK : public VALBLK {
public:
// Constructors
LNGBLK(void *mp, int size);
// Implementation
virtual void Init(PGLOBAL g, bool check);
virtual int GetVlen(void) {return sizeof(int);}
//virtual PSZ GetCharValue(int n);
virtual short GetShortValue(int n) {return (short)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 void Reset(int n) {Lngp[n] = 0;}
// Methods
virtual void SetValue(PSZ sp, int n);
virtual void SetValue(short sval, int n)
{Lngp[n] = (int)sval; SetNull(n, false);}
virtual void SetValue(int lval, int n)
{Lngp[n] = lval; SetNull(n, false);}
virtual void SetValue(longlong lval, int n)
{Lngp[n] = (int)lval; SetNull(n, false);}
virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2);
//virtual void SetValues(PVBLK pv, int k, int n);
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
int* const &Lngp;
}; // end of class LNGBLK
#endif // 0
/***********************************************************************/
/* Class DATBLK: represents a block of time stamp values. */
/***********************************************************************/
......@@ -335,86 +256,5 @@ class DATBLK : public TYPBLK<int> {
PVAL Dvalp; // Date value used to convert string
}; // end of class DATBLK
#if 0
/***********************************************************************/
/* Class BIGBLK: represents a block of big 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; SetNull(n, false);}
virtual void SetValue(int lval, int n)
{Lngp[n] = (longlong)lval; SetNull(n, false);}
virtual void SetValue(longlong lval, int n)
{Lngp[n] = lval; SetNull(n, false);}
virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2);
//virtual void SetValues(PVBLK pv, int k, int n);
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 : public VALBLK {
public:
// Constructors
DBLBLK(void *mp, int size, int prec);
// Implementation
virtual void Init(PGLOBAL g, bool check);
virtual int GetVlen(void) {return sizeof(double);}
//virtual PSZ GetCharValue(int n);
virtual short GetShortValue(int n) {return (short)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 void Reset(int n) {Dblp[n] = 0.0;}
virtual void SetPrec(int p) {Prec = p;}
// Methods
virtual void SetValue(PSZ sp, int n);
virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2);
//virtual void SetValues(PVBLK pv, int k, int n);
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
double* const &Dblp;
}; // end of class DBLBLK
#endif // 0
#endif // __VALBLK__H__
/************* Value C++ Functions Source Code File (.CPP) *************/
/* Name: VALUE.CPP Version 2.1 */
/* Name: VALUE.CPP Version 2.2 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2001-2013 */
/* */
......@@ -19,8 +19,8 @@
/* to avoid too complicated classes and unuseful duplication of many */
/* functions used on one family only. The drawback is that for new */
/* types of objects, we shall have more classes to update. */
/* Currently the only implemented types are STRING, INT, DOUBLE, DATE */
/* and LONGLONG. Shortly we should add at least TINY and VARCHAR. */
/* Currently the only implemented types are STRING, INT, SHORT, TINY, */
/* DATE and LONGLONG. Shortly we should add at least UNSIGNED types. */
/***********************************************************************/
/***********************************************************************/
......@@ -128,6 +128,7 @@ PSZ GetTypeName(int type)
case TYPE_BIGINT: name = "BIGINT"; break;
case TYPE_DATE: name = "DATE"; break;
case TYPE_FLOAT: name = "FLOAT"; break;
case TYPE_TINY: name = "TINY"; break;
} // endswitch type
return name;
......@@ -145,6 +146,7 @@ int GetTypeSize(int type, int len)
case TYPE_BIGINT: len = sizeof(longlong); break;
case TYPE_DATE: len = sizeof(int); break;
case TYPE_FLOAT: len = sizeof(double); break;
case TYPE_TINY: len = sizeof(char); break;
break;
default: len = 0;
} // endswitch type
......@@ -206,6 +208,7 @@ char *GetFormatType(int type)
case TYPE_BIGINT: c = "L"; break;
case TYPE_FLOAT: c = "F"; break;
case TYPE_DATE: c = "D"; break;
case TYPE_TINY: c = "T"; break;
} // endswitch type
return c;
......@@ -225,6 +228,7 @@ int GetFormatType(char c)
case 'L': type = TYPE_BIGINT; break;
case 'F': type = TYPE_FLOAT; break;
case 'D': type = TYPE_DATE; break;
case 'T': type = TYPE_TINY; break;
} // endswitch type
return type;
......@@ -256,6 +260,7 @@ bool IsTypeNum(int type)
case TYPE_FLOAT:
case TYPE_SHORT:
case TYPE_NUM:
case TYPE_TINY:
return true;
} // endswitch type
......@@ -267,13 +272,14 @@ bool IsTypeNum(int type)
/***********************************************************************/
const char *GetFmt(int type)
{
const char *fmt = "%d";;
const char *fmt;
switch (type) {
case TYPE_STRING: fmt = "%s"; break;
case TYPE_SHORT: fmt = "%hd"; break;
case TYPE_BIGINT: fmt = "%lld"; break;
case TYPE_FLOAT: fmt = "%.*lf"; break;
default: fmt = "%d"; break;
} // endswitch Type
return fmt;
......@@ -304,7 +310,8 @@ int ConvertType(int target, int type, CONV kind, bool match)
: (target == TYPE_DATE || type == TYPE_DATE) ? TYPE_DATE
: (target == TYPE_BIGINT || type == TYPE_BIGINT) ? TYPE_BIGINT
: (target == TYPE_INT || type == TYPE_INT) ? TYPE_INT
: TYPE_SHORT;
: (target == TYPE_SHORT || type == TYPE_SHORT) ? TYPE_SHORT
: TYPE_TINY;
default:
if (target == TYPE_ERROR || target == type)
return type;
......@@ -319,6 +326,7 @@ int ConvertType(int target, int type, CONV kind, bool match)
: (target == TYPE_INT || type == TYPE_INT) ? TYPE_INT
: (target == TYPE_SHORT || type == TYPE_SHORT) ? TYPE_SHORT
: (target == TYPE_STRING || type == TYPE_STRING) ? TYPE_STRING
: (target == TYPE_TINY || type == TYPE_TINY) ? TYPE_TINY
: TYPE_ERROR;
} // endswitch kind
......@@ -350,6 +358,9 @@ PVAL AllocateValue(PGLOBAL g, void *value, short type)
case TYPE_FLOAT:
valp = new(g) TYPVAL<double>(*(double *)value, TYPE_FLOAT);
break;
case TYPE_TINY:
valp = new(g) TYPVAL<char>(*(char *)value, TYPE_TINY);
break;
default:
sprintf(g->Message, MSG(BAD_VALUE_TYPE), type);
return NULL;
......@@ -386,6 +397,9 @@ PVAL AllocateValue(PGLOBAL g, int type, int len, int prec,
case TYPE_FLOAT:
valp = new(g) TYPVAL<double>(0.0, prec, TYPE_FLOAT);
break;
case TYPE_TINY:
valp = new(g) TYPVAL<char>((char)0, TYPE_SHORT);
break;
default:
sprintf(g->Message, MSG(BAD_VALUE_TYPE), type);
return NULL;
......@@ -430,6 +444,9 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype)
case TYPE_FLOAT:
valp = new(g) TYPVAL<double>(valp->GetFloatValue(), TYPE_FLOAT);
break;
case TYPE_TINY:
valp = new(g) TYPVAL<char>(valp->GetTinyValue(), TYPE_TINY);
break;
default:
sprintf(g->Message, MSG(BAD_VALUE_TYPE), newtype);
return NULL;
......@@ -460,13 +477,14 @@ VALUE::VALUE(int type) : Type(type)
/***********************************************************************/
const char *VALUE::GetXfmt(void)
{
const char *fmt = "%*d";;
const char *fmt;
switch (Type) {
case TYPE_STRING: fmt = "%*s"; break;
case TYPE_SHORT: fmt = "%*hd"; break;
case TYPE_BIGINT: fmt = "%*lld"; break;
case TYPE_FLOAT: fmt = "%*.*lf"; break;
default: fmt = "%*d"; break;
} // endswitch Type
return fmt;
......@@ -527,7 +545,6 @@ bool TYPVAL<TYPE>::SetValue_pval(PVAL valp, bool chktype)
return true;
if (!(Null = valp->IsNull() && Nullable))
// Tval = (TYPE)valp->GetBigintValue();
Tval = GetTypedValue(valp);
else
Reset();
......@@ -551,6 +568,10 @@ template <>
double TYPVAL<double>::GetTypedValue(PVAL valp)
{return valp->GetFloatValue();}
template <>
char TYPVAL<char>::GetTypedValue(PVAL valp)
{return valp->GetTinyValue();}
/***********************************************************************/
/* TYPVAL SetValue: convert chars extracted from a line to TYPE value.*/
/***********************************************************************/
......@@ -628,7 +649,8 @@ template <>
longlong TYPVAL<longlong>::GetTypedValue(PSZ s) {return atoll(s);}
template <>
double TYPVAL<double>::GetTypedValue(PSZ s) {return atof(s);}
template <>
char TYPVAL<char>::GetTypedValue(PSZ s) {return (char)atoi(s);}
/***********************************************************************/
/* TYPVAL SetValue: set value with a TYPE extracted from a block. */
......@@ -656,6 +678,10 @@ template <>
double TYPVAL<double>::GetTypedValue(PVBLK blk, int n)
{return blk->GetFloatValue(n);}
template <>
char TYPVAL<char>::GetTypedValue(PVBLK blk, int n)
{return blk->GetTinyValue(n);}
/***********************************************************************/
/* TYPVAL SetBinValue: with bytes extracted from a line. */
/***********************************************************************/
......@@ -766,6 +792,16 @@ char *TYPVAL<TYPE>::GetFloatString(char *p, int n, int prec)
return p;
} // end of GetFloatString
/***********************************************************************/
/* TYPVAL GetTinyString: get char representation of a typed value. */
/***********************************************************************/
template <class TYPE>
char *TYPVAL<TYPE>::GetTinyString(char *p, int n)
{
sprintf(p, "%*d", n, (int)(char)Tval);
return p;
} // end of GetIntString
/***********************************************************************/
/* TYPVAL compare value with another Value. */
/***********************************************************************/
......@@ -997,6 +1033,15 @@ void TYPVAL<PSZ>::SetValue(double f)
Null = false;
} // end of SetValue
/***********************************************************************/
/* STRING SetValue: get the character representation of a tiny int. */
/***********************************************************************/
void TYPVAL<PSZ>::SetValue(char c)
{
SetValue((int)c);
Null = false;
} // end of SetValue
/***********************************************************************/
/* STRING SetBinValue: fill string with chars extracted from a line. */
/***********************************************************************/
......@@ -1078,6 +1123,15 @@ char *TYPVAL<PSZ>::GetFloatString(char *p, int n, int prec)
return p;
} // end of GetFloatString
/***********************************************************************/
/* STRING GetTinyString: get tiny int representation of a char value. */
/***********************************************************************/
char *TYPVAL<PSZ>::GetTinyString(char *p, int n)
{
sprintf(p, "%*d", n, (Null) ? 0 : (char)atoi(Strp));
return p;
} // end of GetIntString
/***********************************************************************/
/* STRING compare value with another Value. */
/***********************************************************************/
......
/**************** Value H Declares Source Code File (.H) ***************/
/* Name: VALUE.H Version 1.8 */
/* Name: VALUE.H Version 1.9 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2001-2013 */
/* */
......@@ -76,6 +76,7 @@ class DllExport VALUE : public BLOCK {
virtual int GetValPrec(void) = 0;
virtual int GetLength(void) {return 1;}
virtual PSZ GetCharValue(void) {assert(false); return NULL;}
virtual char GetTinyValue(void) {assert(false); return 0;}
virtual short GetShortValue(void) {assert(false); return 0;}
virtual int GetIntValue(void) = 0;
virtual longlong GetBigintValue(void) = 0;
......@@ -93,6 +94,7 @@ class DllExport VALUE : public BLOCK {
virtual bool SetValue_pval(PVAL valp, bool chktype = false) = 0;
virtual void SetValue_char(char *p, int n) = 0;
virtual void SetValue_psz(PSZ s) = 0;
virtual void SetValue(char c) {assert(false);}
virtual void SetValue(short i) {assert(false);}
virtual void SetValue(int n) {assert(false);}
virtual void SetValue(longlong n) {assert(false);}
......@@ -106,6 +108,7 @@ class DllExport VALUE : public BLOCK {
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 *GetTinyString(char *p, int n) {return "?";}
virtual bool IsEqual(PVAL vp, bool chktype) = 0;
virtual bool FormatValue(PVAL vp, char *fmt) = 0;
......@@ -145,6 +148,7 @@ class DllExport TYPVAL : public VALUE {
virtual int GetValPrec() {return 0;}
virtual int GetSize(void) {return sizeof(TYPE);}
virtual PSZ GetCharValue(void) {return VALUE::GetCharValue();}
virtual char GetTinyValue(void) {return (char)Tval;}
virtual short GetShortValue(void) {return (short)Tval;}
virtual int GetIntValue(void) {return (int)Tval;}
virtual longlong GetBigintValue(void) {return (longlong)Tval;}
......@@ -155,6 +159,7 @@ class DllExport TYPVAL : public VALUE {
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(char c) {Tval = (TYPE)c; Null = false;}
virtual void SetValue(short i) {Tval = (TYPE)i; Null = false;}
virtual void SetValue(int n) {Tval = (TYPE)n; Null = false;}
virtual void SetValue(longlong n) {Tval = (TYPE)n; Null = false;}
......@@ -168,6 +173,7 @@ class DllExport TYPVAL : public VALUE {
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 *GetTinyString(char *p, int n);
virtual bool IsEqual(PVAL vp, bool chktype);
virtual bool SetConstFormat(PGLOBAL, FORMAT&);
virtual bool FormatValue(PVAL vp, char *fmt);
......@@ -205,6 +211,7 @@ class DllExport TYPVAL<PSZ>: public VALUE {
virtual int GetValPrec() {return (Ci) ? 1 : 0;}
virtual int GetSize(void) {return (Strp) ? strlen(Strp) : 0;}
virtual PSZ GetCharValue(void) {return Strp;}
virtual char GetTinyValue(void) {return (char)atoi(Strp);}
virtual short GetShortValue(void) {return (short)atoi(Strp);}
virtual int GetIntValue(void) {return atol(Strp);}
virtual longlong GetBigintValue(void) {return atoll(Strp);}
......@@ -216,6 +223,7 @@ class DllExport TYPVAL<PSZ>: public VALUE {
virtual void SetValue_char(char *p, int n);
virtual void SetValue_psz(PSZ s);
virtual void SetValue_pvblk(PVBLK blk, int n);
virtual void SetValue(char c);
virtual void SetValue(short i);
virtual void SetValue(int n);
virtual void SetValue(longlong n);
......@@ -228,6 +236,7 @@ class DllExport TYPVAL<PSZ>: public VALUE {
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 *GetTinyString(char *p, int n);
virtual bool IsEqual(PVAL vp, bool chktype);
virtual bool FormatValue(PVAL vp, char *fmt);
virtual bool SetConstFormat(PGLOBAL, FORMAT&);
......
......@@ -153,6 +153,12 @@ bool CONSTANT::Rephrase(PGLOBAL g, PSZ work)
case TYPE_FLOAT:
sprintf(work + strlen(work), "%lf", Value->GetFloatValue());
break;
case TYPE_BIGINT:
sprintf(work + strlen(work), "%lld", Value->GetBigintValue());
break;
case TYPE_TINY:
sprintf(work + strlen(work), "%d", Value->GetTinyValue());
break;
default:
sprintf(g->Message, MSG(BAD_CONST_TYPE), Value->GetType());
return false;
......
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