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 @@ ...@@ -79,6 +79,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_TINY 4
#define TYPE_BIGINT 5 #define TYPE_BIGINT 5
#define TYPE_LIST 6 #define TYPE_LIST 6
#define TYPE_INT 7 #define TYPE_INT 7
......
...@@ -1097,6 +1097,9 @@ void *ha_connect::GetColumnOption(void *field, PCOLINFO pcf) ...@@ -1097,6 +1097,9 @@ void *ha_connect::GetColumnOption(void *field, PCOLINFO pcf)
case MYSQL_TYPE_SHORT: case MYSQL_TYPE_SHORT:
pcf->Type= TYPE_SHORT; pcf->Type= TYPE_SHORT;
break; break;
case MYSQL_TYPE_TINY:
pcf->Type= TYPE_TINY;
break;
case MYSQL_TYPE_DOUBLE: case MYSQL_TYPE_DOUBLE:
case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_FLOAT:
pcf->Type= TYPE_FLOAT; pcf->Type= TYPE_FLOAT;
...@@ -3797,6 +3800,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, ...@@ -3797,6 +3800,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
case MYSQL_TYPE_NEWDATE: case MYSQL_TYPE_NEWDATE:
case MYSQL_TYPE_VARCHAR: case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_LONGLONG: case MYSQL_TYPE_LONGLONG:
case MYSQL_TYPE_TINY:
break; // Ok break; // Ok
case MYSQL_TYPE_VAR_STRING: case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_STRING: case MYSQL_TYPE_STRING:
...@@ -3804,7 +3808,6 @@ int ha_connect::create(const char *name, TABLE *table_arg, ...@@ -3804,7 +3808,6 @@ int ha_connect::create(const char *name, TABLE *table_arg,
case MYSQL_TYPE_NEWDECIMAL: case MYSQL_TYPE_NEWDECIMAL:
case MYSQL_TYPE_INT24: case MYSQL_TYPE_INT24:
break; // To be checked break; // To be checked
case MYSQL_TYPE_TINY:
case MYSQL_TYPE_BIT: case MYSQL_TYPE_BIT:
case MYSQL_TYPE_NULL: case MYSQL_TYPE_NULL:
case MYSQL_TYPE_ENUM: case MYSQL_TYPE_ENUM:
......
/************** MyUtil C++ Program Source Code File (.CPP) **************/ /************** MyUtil C++ Program Source Code File (.CPP) **************/
/* PROGRAM NAME: MYUTIL */ /* PROGRAM NAME: MYUTIL */
/* ------------- */ /* ------------- */
/* Version 1.0 */ /* Version 1.1 */
/* */ /* */
/* Author Olivier BERTRAND 2013 */ /* Author Olivier BERTRAND 2013 */
/* */ /* */
...@@ -35,7 +35,7 @@ int MYSQLtoPLG(char *typname) ...@@ -35,7 +35,7 @@ int MYSQLtoPLG(char *typname)
if (!stricmp(typname, "int") || !stricmp(typname, "mediumint") || if (!stricmp(typname, "int") || !stricmp(typname, "mediumint") ||
!stricmp(typname, "integer")) !stricmp(typname, "integer"))
type = TYPE_INT; type = TYPE_INT;
else if (!stricmp(typname, "tinyint") || !stricmp(typname, "smallint")) else if (!stricmp(typname, "smallint"))
type = TYPE_SHORT; type = TYPE_SHORT;
else if (!stricmp(typname, "char") || !stricmp(typname, "varchar") || else if (!stricmp(typname, "char") || !stricmp(typname, "varchar") ||
!stricmp(typname, "text") || !stricmp(typname, "blob")) !stricmp(typname, "text") || !stricmp(typname, "blob"))
...@@ -50,6 +50,8 @@ int MYSQLtoPLG(char *typname) ...@@ -50,6 +50,8 @@ int MYSQLtoPLG(char *typname)
type = TYPE_DATE; type = TYPE_DATE;
else if (!stricmp(typname, "bigint") || !stricmp(typname, "longlong")) else if (!stricmp(typname, "bigint") || !stricmp(typname, "longlong"))
type = TYPE_BIGINT; type = TYPE_BIGINT;
else if (!stricmp(typname, "tinyint"))
type = TYPE_TINY;
else else
type = TYPE_ERROR; type = TYPE_ERROR;
...@@ -82,6 +84,9 @@ enum enum_field_types PLGtoMYSQL(int type, bool dbf) ...@@ -82,6 +84,9 @@ enum enum_field_types PLGtoMYSQL(int type, bool dbf)
case TYPE_BIGINT: case TYPE_BIGINT:
mytype = MYSQL_TYPE_LONGLONG; mytype = MYSQL_TYPE_LONGLONG;
break; break;
case TYPE_TINY:
mytype = MYSQL_TYPE_TINY;
break;
default: default:
mytype = MYSQL_TYPE_NULL; mytype = MYSQL_TYPE_NULL;
} // endswitch mytype } // endswitch mytype
...@@ -97,7 +102,6 @@ int MYSQLtoPLG(int mytype) ...@@ -97,7 +102,6 @@ int MYSQLtoPLG(int mytype)
int type; int type;
switch (mytype) { switch (mytype) {
case MYSQL_TYPE_TINY:
case MYSQL_TYPE_SHORT: case MYSQL_TYPE_SHORT:
type = TYPE_SHORT; type = TYPE_SHORT;
break; break;
...@@ -109,6 +113,9 @@ int MYSQLtoPLG(int mytype) ...@@ -109,6 +113,9 @@ int MYSQLtoPLG(int mytype)
case MYSQL_TYPE_LONGLONG: case MYSQL_TYPE_LONGLONG:
type = TYPE_BIGINT; type = TYPE_BIGINT;
break; break;
case MYSQL_TYPE_TINY:
type = TYPE_TINY;
break;
case MYSQL_TYPE_DECIMAL: case MYSQL_TYPE_DECIMAL:
#if !defined(ALPHA) #if !defined(ALPHA)
case MYSQL_TYPE_NEWDECIMAL: case MYSQL_TYPE_NEWDECIMAL:
......
...@@ -1529,6 +1529,10 @@ void PlugPutOut(PGLOBAL g, FILE *f, short t, void *v, uint n) ...@@ -1529,6 +1529,10 @@ void PlugPutOut(PGLOBAL g, FILE *f, short t, void *v, uint n)
fprintf(f, "%s%hd\n", m, *(short *)v); fprintf(f, "%s%hd\n", m, *(short *)v);
break; break;
case TYPE_TINY:
fprintf(f, "%s%d\n", m, (int)*(char *)v);
break;
case TYPE_VOID: case TYPE_VOID:
break; break;
......
...@@ -1086,6 +1086,7 @@ void DOSCOL::ReadColumn(PGLOBAL g) ...@@ -1086,6 +1086,7 @@ void DOSCOL::ReadColumn(PGLOBAL g)
if (Nod) switch (Buf_Type) { if (Nod) switch (Buf_Type) {
case TYPE_INT: case TYPE_INT:
case TYPE_SHORT: case TYPE_SHORT:
case TYPE_TINY:
case TYPE_BIGINT: case TYPE_BIGINT:
Value->SetValue_char(p, field - Dcm); Value->SetValue_char(p, field - Dcm);
break; break;
...@@ -1175,7 +1176,7 @@ void DOSCOL::WriteColumn(PGLOBAL g) ...@@ -1175,7 +1176,7 @@ void DOSCOL::WriteColumn(PGLOBAL g)
len = sprintf(Buf, fmt, field - i, Value->GetShortValue()); len = sprintf(Buf, fmt, field - i, Value->GetShortValue());
break; break;
case TYPE_INT: case TYPE_INT:
strcpy(fmt, (Ldz) ? "%0*ld" : "%*.ld"); strcpy(fmt, (Ldz) ? "%0*d" : "%*.d");
i = 0; i = 0;
if (Nod) if (Nod)
...@@ -1184,6 +1185,16 @@ void DOSCOL::WriteColumn(PGLOBAL g) ...@@ -1184,6 +1185,16 @@ void DOSCOL::WriteColumn(PGLOBAL g)
len = sprintf(Buf, fmt, field - i, Value->GetIntValue()); len = sprintf(Buf, fmt, field - i, Value->GetIntValue());
break; 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: case TYPE_FLOAT:
strcpy(fmt, (Ldz) ? "%0*.*lf" : "%*.*lf"); strcpy(fmt, (Ldz) ? "%0*.*lf" : "%*.*lf");
sprintf(Buf, fmt, field + ((Nod && Dcm) ? 1 : 0), sprintf(Buf, fmt, field + ((Nod && Dcm) ? 1 : 0),
......
...@@ -256,10 +256,13 @@ PQRYRES WMIColumns(PGLOBAL g, char *nsp, char *cls, bool info) ...@@ -256,10 +256,13 @@ PQRYRES WMIColumns(PGLOBAL g, char *nsp, char *cls, bool info)
case CIM_UINT32: case CIM_UINT32:
case CIM_BOOLEAN: case CIM_BOOLEAN:
typ = TYPE_INT; typ = TYPE_INT;
lng = 9; lng = 11;
break; break;
case CIM_SINT8: case CIM_SINT8:
case CIM_UINT8: case CIM_UINT8:
typ = TYPE_TINY;
lng = 4;
break;
case CIM_SINT16: case CIM_SINT16:
case CIM_UINT16: case CIM_UINT16:
typ = TYPE_SHORT; typ = TYPE_SHORT;
...@@ -268,11 +271,14 @@ PQRYRES WMIColumns(PGLOBAL g, char *nsp, char *cls, bool info) ...@@ -268,11 +271,14 @@ PQRYRES WMIColumns(PGLOBAL g, char *nsp, char *cls, bool info)
case CIM_REAL64: case CIM_REAL64:
case CIM_REAL32: case CIM_REAL32:
prec = 2; prec = 2;
case CIM_SINT64:
case CIM_UINT64:
typ = TYPE_FLOAT; typ = TYPE_FLOAT;
lng = 15; lng = 15;
break; break;
case CIM_SINT64:
case CIM_UINT64:
typ = TYPE_BIGINT;
lng = 20;
break;
case CIM_DATETIME: case CIM_DATETIME:
typ = TYPE_DATE; typ = TYPE_DATE;
lng = 19; lng = 19;
......
/************ Valblk C++ Functions Source Code File (.CPP) *************/ /************ Valblk C++ Functions Source Code File (.CPP) *************/
/* Name: VALBLK.CPP Version 1.6 */ /* Name: VALBLK.CPP Version 1.7 */
/* */ /* */
/* (C) Copyright to the author Olivier BERTRAND 2005-2013 */ /* (C) Copyright to the author Olivier BERTRAND 2005-2013 */
/* */ /* */
...@@ -78,6 +78,9 @@ PVBLK AllocValBlock(PGLOBAL g, void *mp, int type, int nval, int len, ...@@ -78,6 +78,9 @@ PVBLK AllocValBlock(PGLOBAL g, void *mp, int type, int nval, int len,
case TYPE_FLOAT: case TYPE_FLOAT:
blkp = new(g) TYPBLK<double>(mp, nval, prec, type); blkp = new(g) TYPBLK<double>(mp, nval, prec, type);
break; break;
case TYPE_TINY:
blkp = new(g) TYPBLK<char>(mp, nval, type);
break;
default: default:
sprintf(g->Message, MSG(BAD_VALBLK_TYPE), type); sprintf(g->Message, MSG(BAD_VALBLK_TYPE), type);
return NULL; return NULL;
...@@ -258,6 +261,10 @@ template <> ...@@ -258,6 +261,10 @@ template <>
double TYPBLK<double>::GetTypedValue(PVAL valp) double TYPBLK<double>::GetTypedValue(PVAL valp)
{return valp->GetFloatValue();} {return valp->GetFloatValue();}
template <>
char TYPBLK<char>::GetTypedValue(PVAL valp)
{return valp->GetTinyValue();}
/***********************************************************************/ /***********************************************************************/
/* Set one value in a block. */ /* Set one value in a block. */
/***********************************************************************/ /***********************************************************************/
...@@ -284,6 +291,8 @@ template <> ...@@ -284,6 +291,8 @@ template <>
longlong TYPBLK<longlong>::GetTypedValue(PSZ p) {return atoll(p);} longlong TYPBLK<longlong>::GetTypedValue(PSZ p) {return atoll(p);}
template <> template <>
double TYPBLK<double>::GetTypedValue(PSZ p) {return atof(p);} double TYPBLK<double>::GetTypedValue(PSZ p) {return atof(p);}
template <>
char TYPBLK<char>::GetTypedValue(PSZ p) {return (char)atoi(p);}
/***********************************************************************/ /***********************************************************************/
/* Set one value in a block from a value in another block. */ /* Set one value in a block from a value in another block. */
...@@ -320,6 +329,10 @@ template <> ...@@ -320,6 +329,10 @@ template <>
double TYPBLK<double>::GetTypedValue(PVBLK blk, int n) double TYPBLK<double>::GetTypedValue(PVBLK blk, int n)
{return blk->GetFloatValue(n);} {return blk->GetFloatValue(n);}
template <>
char TYPBLK<char>::GetTypedValue(PVBLK blk, int n)
{return blk->GetTinyValue(n);}
#if 0 #if 0
/***********************************************************************/ /***********************************************************************/
/* Set many values in a block from values in another block. */ /* Set many values in a block from values in another block. */
...@@ -486,7 +499,7 @@ char *CHRBLK::GetCharValue(int n) ...@@ -486,7 +499,7 @@ char *CHRBLK::GetCharValue(int n)
short CHRBLK::GetShortValue(int n) short CHRBLK::GetShortValue(int n)
{ {
return (short)atoi((char *)GetValPtrEx(n)); return (short)atoi((char *)GetValPtrEx(n));
} // end of GetIntValue } // end of GetShortValue
/***********************************************************************/ /***********************************************************************/
/* Return the value of the nth element converted to int. */ /* Return the value of the nth element converted to int. */
...@@ -502,7 +515,7 @@ int CHRBLK::GetIntValue(int n) ...@@ -502,7 +515,7 @@ int CHRBLK::GetIntValue(int n)
longlong CHRBLK::GetBigintValue(int n) longlong CHRBLK::GetBigintValue(int n)
{ {
return atoll((char *)GetValPtrEx(n)); return atoll((char *)GetValPtrEx(n));
} // end of GetIntValue } // end of GetBigintValue
/***********************************************************************/ /***********************************************************************/
/* Return the value of the nth element converted to double. */ /* Return the value of the nth element converted to double. */
...@@ -512,6 +525,14 @@ double CHRBLK::GetFloatValue(int n) ...@@ -512,6 +525,14 @@ double CHRBLK::GetFloatValue(int n)
return atof((char *)GetValPtrEx(n)); return atof((char *)GetValPtrEx(n));
} // end of GetFloatValue } // end of GetFloatValue
/***********************************************************************/
/* Return the value of the nth element converted to tiny int. */
/***********************************************************************/
char CHRBLK::GetTinyValue(int n)
{
return (char)atoi((char *)GetValPtrEx(n));
} // end of GetTinyValue
/***********************************************************************/ /***********************************************************************/
/* Set one value in a block. */ /* Set one value in a block. */
/***********************************************************************/ /***********************************************************************/
...@@ -875,720 +896,41 @@ int STRBLK::GetMaxLength(void) ...@@ -875,720 +896,41 @@ int STRBLK::GetMaxLength(void)
return n; return n;
} // end of GetMaxLength } // end of GetMaxLength
#if 0 /* -------------------------- Class DATBLK --------------------------- */
/* -------------------------- Class SHRBLK --------------------------- */
/***********************************************************************/
/* Constructor. */
/***********************************************************************/
SHRBLK::SHRBLK(void *mp, int nval)
: VALBLK(mp, TYPE_SHORT, nval), Shrp((short*&)Blkp)
{
} // end of SHRBLK constructor
/***********************************************************************/
/* Initialization routine. */
/***********************************************************************/
void SHRBLK::Init(PGLOBAL g, bool check)
{
if (!Blkp)
Blkp = PlugSubAlloc(g, NULL, Nval * sizeof(short));
Check = check;
Global = g;
} // end of Init
/***********************************************************************/
/* Set one value in a block. */
/***********************************************************************/
void SHRBLK::SetValue(PVAL valp, int n)
{
CheckParms(valp, n)
bool b;
if (!(b = valp->IsNull() && Nullable))
Shrp[n] = valp->GetShortValue();
else
Reset(n);
SetNull(n, b);
} // end of SetValue
/***********************************************************************/
/* Set one value in a block. */
/***********************************************************************/
void SHRBLK::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
Shrp[n] = (short)atoi(p);
SetNull(n, false);
} // end of SetValue
/***********************************************************************/
/* Set one value in a block from a value in another block. */
/***********************************************************************/
void SHRBLK::SetValue(PVBLK pv, int n1, int n2)
{
CheckType(pv)
bool b;
if (!(b = pv->IsNull(n2) && Nullable))
Shrp[n1] = ((SHRBLK*)pv)->Shrp[n2];
else
Reset(n1);
SetNull(n1, b);
} // end of SetValue
#if 0
/***********************************************************************/
/* Set many values in a block from values in another block. */
/***********************************************************************/
void SHRBLK::SetValues(PVBLK pv, int k, int n)
{
CheckType(pv)
short *sp = ((SHRBLK*)pv)->Shrp;
for (register int i = k; i < n; i++)
Shrp[i] = sp[i];
} // end of SetValues
#endif // 0
/***********************************************************************/
/* Move one value from i to j. */
/***********************************************************************/
void SHRBLK::Move(int i, int j)
{
Shrp[j] = Shrp[i];
MoveNull(i, j);
} // end of Move
/***********************************************************************/
/* Compare a Value object with the nth value of the block. */
/***********************************************************************/
int SHRBLK::CompVal(PVAL vp, int n)
{
CheckParms(vp, n)
short msv = Shrp[n];
short vsv = vp->GetShortValue();
return (vsv > msv) ? 1 : (vsv < msv) ? (-1) : 0;
} // end of CompVal
/***********************************************************************/
/* Compare two values of the block. */
/***********************************************************************/
int SHRBLK::CompVal(int i1, int i2)
{
short sv1 = Shrp[i1];
short sv2 = Shrp[i2];
return (sv1 > sv2) ? 1 : (sv1 < sv2) ? (-1) : 0;
} // end of CompVal
/***********************************************************************/
/* Get a pointer on the nth value of the block. */
/***********************************************************************/
void *SHRBLK::GetValPtr(int n)
{
ChkIndx(n);
return Shrp + n;
} // end of GetValPtr
/***********************************************************************/
/* Get a pointer on the nth value of the block. */
/***********************************************************************/
void *SHRBLK::GetValPtrEx(int n)
{
ChkIndx(n);
return Shrp + n;
} // end of GetValPtrEx
/***********************************************************************/
/* Returns index of matching value in block or -1. */
/***********************************************************************/
int SHRBLK::Find(PVAL vp)
{
CheckType(vp)
int i;
short n = vp->GetShortValue();
for (i = 0; i < Nval; i++)
if (n == Shrp[i])
break;
return (i < Nval) ? i : (-1);
} // end of Find
/***********************************************************************/
/* Returns the length of the longest string in the block. */
/***********************************************************************/
int SHRBLK::GetMaxLength(void)
{
char buf[12];
int i, n;
for (i = n = 0; i < Nval; i++) {
sprintf(buf, "%hd", Shrp[i]);
n = max(n, (signed)strlen(buf));
} // endfor i
return n;
} // end of GetMaxLength
/* -------------------------- Class LNGBLK --------------------------- */
/***********************************************************************/ /***********************************************************************/
/* Constructor. */ /* Constructor. */
/***********************************************************************/ /***********************************************************************/
LNGBLK::LNGBLK(void *mp, int nval) DATBLK::DATBLK(void *mp, int nval) : TYPBLK<int>(mp, nval, TYPE_INT)
: VALBLK(mp, TYPE_INT, nval), Lngp((int*&)Blkp)
{
} // end of LNGBLK constructor
/***********************************************************************/
/* Initialization routine. */
/***********************************************************************/
void LNGBLK::Init(PGLOBAL g, bool check)
{
if (!Blkp)
Blkp = PlugSubAlloc(g, NULL, Nval * sizeof(int));
Check = check;
Global = g;
} // end of Init
/***********************************************************************/
/* Set one value in a block. */
/***********************************************************************/
void LNGBLK::SetValue(PVAL valp, int n)
{ {
CheckParms(valp, n) Type = TYPE_DATE;
bool b; Dvalp = NULL;
} // end of DATBLK constructor
if (!(b = valp->IsNull() && Nullable))
Lngp[n] = valp->GetIntValue();
else
Reset(n);
SetNull(n, b);
} // end of SetValue
/***********************************************************************/ /***********************************************************************/
/* Set one value in a block. */ /* Set format so formatted dates can be converted on input. */
/***********************************************************************/ /***********************************************************************/
void LNGBLK::SetValue(PSZ p, int n) bool DATBLK::SetFormat(PGLOBAL g, PSZ fmt, int len, int year)
{ {
#if defined(_DEBUG) || defined(DEBTRACE) if (!(Dvalp = AllocateValue(g, TYPE_DATE, len, year, fmt)))
if (Check) { return true;
PGLOBAL& g = Global;
strcpy(g->Message, MSG(BAD_SET_STRING));
longjmp(g->jumper[g->jump_level], Type);
} // endif Check
#endif
Lngp[n] = atol(p); return false;
} // end of SetValue } // end of SetFormat
/***********************************************************************/ /***********************************************************************/
/* Set one value in a block from a value in another block. */ /* Set one value in a block from a char string. */
/***********************************************************************/ /***********************************************************************/
void LNGBLK::SetValue(PVBLK pv, int n1, int n2) void DATBLK::SetValue(PSZ p, int n)
{ {
CheckType(pv) if (Dvalp) {
bool b; // Decode the string according to format
Dvalp->SetValue_psz(p);
if (!(b = pv->IsNull(n2) && Nullable)) Typp[n] = Dvalp->GetIntValue();
Lngp[n1] = ((LNGBLK*)pv)->Lngp[n2]; } else
else TYPBLK<int>::SetValue(p, n);
Reset(n1);
SetNull(n1, b);
} // end of SetValue } // end of SetValue
#if 0
/***********************************************************************/
/* Set many values in a block from values in another block. */
/***********************************************************************/
void LNGBLK::SetValues(PVBLK pv, int k, int n)
{
CheckType(pv)
int *lp = ((LNGBLK*)pv)->Lngp;
for (register int i = k; i < n; i++)
Lngp[i] = lp[i];
} // end of SetValues
#endif // 0
/***********************************************************************/
/* Move one value from i to j. */
/***********************************************************************/
void LNGBLK::Move(int i, int j)
{
Lngp[j] = Lngp[i];
MoveNull(i, j);
} // end of Move
/***********************************************************************/
/* Compare a Value object with the nth value of the block. */
/***********************************************************************/
int LNGBLK::CompVal(PVAL vp, int n)
{
CheckParms(vp, n)
register int mlv = Lngp[n];
register int vlv = vp->GetIntValue();
return (vlv > mlv) ? 1 : (vlv < mlv) ? (-1) : 0;
} // end of CompVal
/***********************************************************************/
/* Compare two values of the block. */
/***********************************************************************/
int LNGBLK::CompVal(int i1, int i2)
{
register int lv1 = Lngp[i1];
register int 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 *LNGBLK::GetValPtr(int n)
{
ChkIndx(n);
return Lngp + n;
} // end of GetValPtr
/***********************************************************************/
/* Get a pointer on the nth value of the block. */
/***********************************************************************/
void *LNGBLK::GetValPtrEx(int n)
{
ChkIndx(n);
return Lngp + n;
} // end of GetValPtrEx
/***********************************************************************/
/* Returns index of matching value in block or -1. */
/***********************************************************************/
int LNGBLK::Find(PVAL vp)
{
CheckType(vp)
int i;
int n = vp->GetIntValue();
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 LNGBLK::GetMaxLength(void)
{
char buf[12];
int i, n;
for (i = n = 0; i < Nval; i++) {
sprintf(buf, "%d", Lngp[i]);
n = max(n, (signed)strlen(buf));
} // endfor i
return n;
} // end of GetMaxLength
#endif // 0
/* -------------------------- Class DATBLK --------------------------- */
/***********************************************************************/
/* Constructor. */
/***********************************************************************/
DATBLK::DATBLK(void *mp, int nval) : TYPBLK<int>(mp, nval, TYPE_INT)
{
Type = TYPE_DATE;
Dvalp = NULL;
} // end of DATBLK constructor
/***********************************************************************/
/* Set format so formatted dates can be converted on input. */
/***********************************************************************/
bool DATBLK::SetFormat(PGLOBAL g, PSZ fmt, int len, int year)
{
if (!(Dvalp = AllocateValue(g, TYPE_DATE, len, year, fmt)))
return true;
return false;
} // end of SetFormat
/***********************************************************************/
/* Set one value in a block from a char string. */
/***********************************************************************/
void DATBLK::SetValue(PSZ p, int n)
{
if (Dvalp) {
// Decode the string according to format
Dvalp->SetValue_psz(p);
Typp[n] = Dvalp->GetIntValue();
} else
TYPBLK<int>::SetValue(p, n);
} // end of SetValue
#if 0
/* -------------------------- 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)
bool b;
if (!(b = valp->IsNull() && Nullable))
Lngp[n] = valp->GetBigintValue();
else
Reset(n);
SetNull(n, b);
} // 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 from a value in another block. */
/***********************************************************************/
void BIGBLK::SetValue(PVBLK pv, int n1, int n2)
{
CheckType(pv)
bool b;
if (!(b = pv->IsNull(n2) && Nullable))
Lngp[n1] = ((BIGBLK*)pv)->Lngp[n2];
else
Reset(n1);
SetNull(n1, b);
} // end of SetValue
#if 0
/***********************************************************************/
/* 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
#endif // 0
/***********************************************************************/
/* Move one value from i to j. */
/***********************************************************************/
void BIGBLK::Move(int i, int j)
{
Lngp[j] = Lngp[i];
MoveNull(i, j);
} // 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)
{
ChkIndx(n);
return Lngp + n;
} // end of GetValPtr
/***********************************************************************/
/* Get a pointer on the nth value of the block. */
/***********************************************************************/
void *BIGBLK::GetValPtrEx(int n)
{
ChkIndx(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 --------------------------- */
/***********************************************************************/
/* Constructor. */
/***********************************************************************/
DBLBLK::DBLBLK(void *mp, int nval, int prec)
: VALBLK(mp, TYPE_FLOAT, nval), Dblp((double*&)Blkp)
{
Prec = prec;
} // end of DBLBLK constructor
/***********************************************************************/
/* Initialization routine. */
/***********************************************************************/
void DBLBLK::Init(PGLOBAL g, bool check)
{
if (!Blkp)
Blkp = PlugSubAlloc(g, NULL, Nval * sizeof(double));
Check = check;
Global = g;
} // end of Init
/***********************************************************************/
/* Set one value in a block from a value in another block. */
/***********************************************************************/
void DBLBLK::SetValue(PVBLK pv, int n1, int n2)
{
CheckType(pv)
bool b;
if (!(b = pv->IsNull(n2) && Nullable))
Dblp[n1] = ((DBLBLK*)pv)->Dblp[n2];
else
Reset(n1);
SetNull(n1, b);
} // end of SetValue
/***********************************************************************/
/* Set one value in a block. */
/***********************************************************************/
void DBLBLK::SetValue(PVAL valp, int n)
{
CheckParms(valp, n)
bool b;
if (!(b = valp->IsNull() && Nullable))
Dblp[n] = valp->GetFloatValue();
else
Reset(n);
SetNull(n, b);
} // end of SetValue
/***********************************************************************/
/* Set one value in a block. */
/***********************************************************************/
void DBLBLK::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
Dblp[n] = atof(p);
} // end of SetValue
#if 0
/***********************************************************************/
/* Set many values in a block from values in another block. */
/***********************************************************************/
void DBLBLK::SetValues(PVBLK pv, int k, int n)
{
CheckType(pv)
double *dp = ((DBLBLK*)pv)->Dblp;
for (register int i = k; i < n; i++)
Dblp[i] = dp[i];
} // end of SetValues
#endif // 0
/***********************************************************************/
/* Move one value from i to j. */
/***********************************************************************/
void DBLBLK::Move(int i, int j)
{
Dblp[j] = Dblp[i];
MoveNull(i, j);
} // end of Move
/***********************************************************************/
/* Compare a Value object with the nth value of the block. */
/***********************************************************************/
int DBLBLK::CompVal(PVAL vp, int n)
{
CheckParms(vp, n)
double mfv = Dblp[n];
double vfv = vp->GetFloatValue();
return (vfv > mfv) ? 1 : (vfv < mfv) ? (-1) : 0;
} // end of CompVal
/***********************************************************************/
/* Compare two values of the block. */
/***********************************************************************/
int DBLBLK::CompVal(int i1, int i2)
{
register double dv1 = Dblp[i1];
register double dv2 = Dblp[i2];
return (dv1 > dv2) ? 1 : (dv1 < dv2) ? (-1) : 0;
} // end of CompVal
/***********************************************************************/
/* Get a pointer on the nth value of the block. */
/***********************************************************************/
void *DBLBLK::GetValPtr(int n)
{
ChkIndx(n);
return Dblp + n;
} // end of GetValPtr
/***********************************************************************/
/* Get a pointer on the nth value of the block. */
/***********************************************************************/
void *DBLBLK::GetValPtrEx(int n)
{
ChkIndx(n);
return Dblp + n;
} // end of GetValPtrEx
/***********************************************************************/
/* Returns index of matching value in block or -1. */
/***********************************************************************/
int DBLBLK::Find(PVAL vp)
{
CheckType(vp)
int i;
double d = vp->GetFloatValue();
for (i = 0; i < Nval; i++)
if (d == Dblp[i])
break;
return (i < Nval) ? i : (-1);
} // end of Find
/***********************************************************************/
/* Returns the length of the longest string in the block. */
/***********************************************************************/
int DBLBLK::GetMaxLength(void)
{
char buf[32];
int i, n;
for (i = n = 0; i < Nval; i++) {
sprintf(buf, "%lf", Dblp[i]);
n = max(n, (signed)strlen(buf));
} // endfor i
return n;
} // end of GetMaxLength
#endif // 0
/* ------------------------- End of Valblk --------------------------- */ /* ------------------------- End of Valblk --------------------------- */
/*************** Valblk H Declares Source Code File (.H) ***************/ /*************** 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 */ /* (C) Copyright to the author Olivier BERTRAND 2005-2013 */
/* */ /* */
...@@ -50,6 +50,7 @@ class VALBLK : public BLOCK { ...@@ -50,6 +50,7 @@ class VALBLK : public BLOCK {
virtual int GetIntValue(int n) = 0; virtual int GetIntValue(int n) = 0;
virtual longlong GetBigintValue(int n) = 0; virtual longlong GetBigintValue(int n) = 0;
virtual double GetFloatValue(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 ReAlloc(void *mp, int n) {Blkp = mp; Nval = n;}
virtual void Reset(int n) = 0; virtual void Reset(int n) = 0;
virtual bool SetFormat(PGLOBAL g, PSZ fmt, int len, int year = 0); virtual bool SetFormat(PGLOBAL g, PSZ fmt, int len, int year = 0);
...@@ -61,6 +62,7 @@ class VALBLK : public BLOCK { ...@@ -61,6 +62,7 @@ class VALBLK : public BLOCK {
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(longlong lval, int n) {assert(false);}
virtual void SetValue(double fval, 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(PSZ sp, int n) {assert(false);}
virtual void SetValue(PVAL valp, int n) = 0; virtual void SetValue(PVAL valp, int n) = 0;
virtual void SetValue(PVBLK pv, int n1, int n2) = 0; virtual void SetValue(PVBLK pv, int n1, int n2) = 0;
...@@ -113,6 +115,7 @@ class TYPBLK : public VALBLK { ...@@ -113,6 +115,7 @@ class TYPBLK : public VALBLK {
virtual int GetIntValue(int n) {return (int)Typp[n];} virtual int GetIntValue(int n) {return (int)Typp[n];}
virtual longlong GetBigintValue(int n) {return (longlong)Typp[n];} virtual longlong GetBigintValue(int n) {return (longlong)Typp[n];}
virtual double GetFloatValue(int n) {return (double)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;} virtual void Reset(int n) {Typp[n] = 0;}
// Methods // Methods
...@@ -125,6 +128,8 @@ class TYPBLK : public VALBLK { ...@@ -125,6 +128,8 @@ class TYPBLK : public VALBLK {
{Typp[n] = (TYPE)lval; SetNull(n, false);} {Typp[n] = (TYPE)lval; SetNull(n, false);}
virtual void SetValue(double fval, int n) virtual void SetValue(double fval, int n)
{Typp[n] = (TYPE)fval; SetNull(n, false);} {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(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2); virtual void SetValue(PVBLK pv, int n1, int n2);
//virtual void SetValues(PVBLK pv, int k, int n); //virtual void SetValues(PVBLK pv, int k, int n);
...@@ -163,6 +168,7 @@ class CHRBLK : public VALBLK { ...@@ -163,6 +168,7 @@ class CHRBLK : public VALBLK {
virtual int GetIntValue(int n); virtual int GetIntValue(int n);
virtual longlong GetBigintValue(int n); virtual longlong GetBigintValue(int n);
virtual double GetFloatValue(int n); virtual double GetFloatValue(int n);
virtual char GetTinyValue(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);}
virtual bool IsCi(void) {return Ci;} virtual bool IsCi(void) {return Ci;}
...@@ -210,6 +216,7 @@ class STRBLK : public VALBLK { ...@@ -210,6 +216,7 @@ class STRBLK : public VALBLK {
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 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 char GetTinyValue(int n) {return (char)atoi(Strp[n]);}
virtual void Reset(int n) {Strp[n] = NULL;} virtual void Reset(int n) {Strp[n] = NULL;}
// Methods // Methods
...@@ -230,92 +237,6 @@ class STRBLK : public VALBLK { ...@@ -230,92 +237,6 @@ class STRBLK : public VALBLK {
PSZ* const &Strp; // Pointer to PSZ buffer PSZ* const &Strp; // Pointer to PSZ buffer
}; // end of class STRBLK }; // 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. */ /* Class DATBLK: represents a block of time stamp values. */
/***********************************************************************/ /***********************************************************************/
...@@ -335,86 +256,5 @@ class DATBLK : public TYPBLK<int> { ...@@ -335,86 +256,5 @@ class DATBLK : public TYPBLK<int> {
PVAL Dvalp; // Date value used to convert string PVAL Dvalp; // Date value used to convert string
}; // end of class DATBLK }; // 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__ #endif // __VALBLK__H__
/************* Value C++ Functions Source Code File (.CPP) *************/ /************* 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 */ /* (C) Copyright to the author Olivier BERTRAND 2001-2013 */
/* */ /* */
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
/* to avoid too complicated classes and unuseful duplication of many */ /* to avoid too complicated classes and unuseful duplication of many */
/* functions used on one family only. The drawback is that for new */ /* functions used on one family only. The drawback is that for new */
/* types of objects, we shall have more classes to update. */ /* types of objects, we shall have more classes to update. */
/* Currently the only implemented types are STRING, INT, DOUBLE, DATE */ /* Currently the only implemented types are STRING, INT, SHORT, TINY, */
/* and LONGLONG. Shortly we should add at least TINY and VARCHAR. */ /* DATE and LONGLONG. Shortly we should add at least UNSIGNED types. */
/***********************************************************************/ /***********************************************************************/
/***********************************************************************/ /***********************************************************************/
...@@ -128,6 +128,7 @@ PSZ GetTypeName(int type) ...@@ -128,6 +128,7 @@ PSZ GetTypeName(int type)
case TYPE_BIGINT: name = "BIGINT"; 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;
case TYPE_TINY: name = "TINY"; break;
} // endswitch type } // endswitch type
return name; return name;
...@@ -145,6 +146,7 @@ int GetTypeSize(int type, int len) ...@@ -145,6 +146,7 @@ int GetTypeSize(int type, int len)
case TYPE_BIGINT: len = sizeof(longlong); break; case TYPE_BIGINT: len = sizeof(longlong); break;
case TYPE_DATE: len = sizeof(int); break; case TYPE_DATE: len = sizeof(int); break;
case TYPE_FLOAT: len = sizeof(double); break; case TYPE_FLOAT: len = sizeof(double); break;
case TYPE_TINY: len = sizeof(char); break;
break; break;
default: len = 0; default: len = 0;
} // endswitch type } // endswitch type
...@@ -206,6 +208,7 @@ char *GetFormatType(int type) ...@@ -206,6 +208,7 @@ char *GetFormatType(int type)
case TYPE_BIGINT: c = "L"; 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;
case TYPE_TINY: c = "T"; break;
} // endswitch type } // endswitch type
return c; return c;
...@@ -225,6 +228,7 @@ int GetFormatType(char c) ...@@ -225,6 +228,7 @@ int GetFormatType(char c)
case 'L': type = TYPE_BIGINT; 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;
case 'T': type = TYPE_TINY; break;
} // endswitch type } // endswitch type
return type; return type;
...@@ -256,6 +260,7 @@ bool IsTypeNum(int type) ...@@ -256,6 +260,7 @@ bool IsTypeNum(int type)
case TYPE_FLOAT: case TYPE_FLOAT:
case TYPE_SHORT: case TYPE_SHORT:
case TYPE_NUM: case TYPE_NUM:
case TYPE_TINY:
return true; return true;
} // endswitch type } // endswitch type
...@@ -267,13 +272,14 @@ bool IsTypeNum(int type) ...@@ -267,13 +272,14 @@ bool IsTypeNum(int type)
/***********************************************************************/ /***********************************************************************/
const char *GetFmt(int type) const char *GetFmt(int type)
{ {
const char *fmt = "%d";; const char *fmt;
switch (type) { switch (type) {
case TYPE_STRING: fmt = "%s"; break; case TYPE_STRING: fmt = "%s"; break;
case TYPE_SHORT: fmt = "%hd"; break; case TYPE_SHORT: fmt = "%hd"; break;
case TYPE_BIGINT: fmt = "%lld"; break; case TYPE_BIGINT: fmt = "%lld"; break;
case TYPE_FLOAT: fmt = "%.*lf"; break; case TYPE_FLOAT: fmt = "%.*lf"; break;
default: fmt = "%d"; break;
} // endswitch Type } // endswitch Type
return fmt; return fmt;
...@@ -304,7 +310,8 @@ int ConvertType(int target, int type, CONV kind, bool match) ...@@ -304,7 +310,8 @@ int ConvertType(int target, int type, CONV kind, bool match)
: (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_BIGINT || type == TYPE_BIGINT) ? TYPE_BIGINT
: (target == TYPE_INT || type == TYPE_INT) ? TYPE_INT : (target == TYPE_INT || type == TYPE_INT) ? TYPE_INT
: TYPE_SHORT; : (target == TYPE_SHORT || type == TYPE_SHORT) ? TYPE_SHORT
: TYPE_TINY;
default: default:
if (target == TYPE_ERROR || target == type) if (target == TYPE_ERROR || target == type)
return type; return type;
...@@ -319,6 +326,7 @@ int ConvertType(int target, int type, CONV kind, bool match) ...@@ -319,6 +326,7 @@ int ConvertType(int target, int type, CONV kind, bool match)
: (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
: (target == TYPE_TINY || type == TYPE_TINY) ? TYPE_TINY
: TYPE_ERROR; : TYPE_ERROR;
} // endswitch kind } // endswitch kind
...@@ -350,6 +358,9 @@ PVAL AllocateValue(PGLOBAL g, void *value, short type) ...@@ -350,6 +358,9 @@ PVAL AllocateValue(PGLOBAL g, void *value, short type)
case TYPE_FLOAT: case TYPE_FLOAT:
valp = new(g) TYPVAL<double>(*(double *)value, TYPE_FLOAT); valp = new(g) TYPVAL<double>(*(double *)value, TYPE_FLOAT);
break; break;
case TYPE_TINY:
valp = new(g) TYPVAL<char>(*(char *)value, TYPE_TINY);
break;
default: default:
sprintf(g->Message, MSG(BAD_VALUE_TYPE), type); sprintf(g->Message, MSG(BAD_VALUE_TYPE), type);
return NULL; return NULL;
...@@ -386,6 +397,9 @@ PVAL AllocateValue(PGLOBAL g, int type, int len, int prec, ...@@ -386,6 +397,9 @@ PVAL AllocateValue(PGLOBAL g, int type, int len, int prec,
case TYPE_FLOAT: case TYPE_FLOAT:
valp = new(g) TYPVAL<double>(0.0, prec, TYPE_FLOAT); valp = new(g) TYPVAL<double>(0.0, prec, TYPE_FLOAT);
break; break;
case TYPE_TINY:
valp = new(g) TYPVAL<char>((char)0, TYPE_SHORT);
break;
default: default:
sprintf(g->Message, MSG(BAD_VALUE_TYPE), type); sprintf(g->Message, MSG(BAD_VALUE_TYPE), type);
return NULL; return NULL;
...@@ -430,6 +444,9 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype) ...@@ -430,6 +444,9 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype)
case TYPE_FLOAT: case TYPE_FLOAT:
valp = new(g) TYPVAL<double>(valp->GetFloatValue(), TYPE_FLOAT); valp = new(g) TYPVAL<double>(valp->GetFloatValue(), TYPE_FLOAT);
break; break;
case TYPE_TINY:
valp = new(g) TYPVAL<char>(valp->GetTinyValue(), TYPE_TINY);
break;
default: default:
sprintf(g->Message, MSG(BAD_VALUE_TYPE), newtype); sprintf(g->Message, MSG(BAD_VALUE_TYPE), newtype);
return NULL; return NULL;
...@@ -460,13 +477,14 @@ VALUE::VALUE(int type) : Type(type) ...@@ -460,13 +477,14 @@ VALUE::VALUE(int type) : Type(type)
/***********************************************************************/ /***********************************************************************/
const char *VALUE::GetXfmt(void) const char *VALUE::GetXfmt(void)
{ {
const char *fmt = "%*d";; const char *fmt;
switch (Type) { switch (Type) {
case TYPE_STRING: fmt = "%*s"; break; case TYPE_STRING: fmt = "%*s"; break;
case TYPE_SHORT: fmt = "%*hd"; break; case TYPE_SHORT: fmt = "%*hd"; break;
case TYPE_BIGINT: fmt = "%*lld"; break; case TYPE_BIGINT: fmt = "%*lld"; break;
case TYPE_FLOAT: fmt = "%*.*lf"; break; case TYPE_FLOAT: fmt = "%*.*lf"; break;
default: fmt = "%*d"; break;
} // endswitch Type } // endswitch Type
return fmt; return fmt;
...@@ -527,7 +545,6 @@ bool TYPVAL<TYPE>::SetValue_pval(PVAL valp, bool chktype) ...@@ -527,7 +545,6 @@ bool TYPVAL<TYPE>::SetValue_pval(PVAL valp, bool chktype)
return true; return true;
if (!(Null = valp->IsNull() && Nullable)) if (!(Null = valp->IsNull() && Nullable))
// Tval = (TYPE)valp->GetBigintValue();
Tval = GetTypedValue(valp); Tval = GetTypedValue(valp);
else else
Reset(); Reset();
...@@ -551,6 +568,10 @@ template <> ...@@ -551,6 +568,10 @@ template <>
double TYPVAL<double>::GetTypedValue(PVAL valp) double TYPVAL<double>::GetTypedValue(PVAL valp)
{return valp->GetFloatValue();} {return valp->GetFloatValue();}
template <>
char TYPVAL<char>::GetTypedValue(PVAL valp)
{return valp->GetTinyValue();}
/***********************************************************************/ /***********************************************************************/
/* TYPVAL SetValue: convert chars extracted from a line to TYPE value.*/ /* TYPVAL SetValue: convert chars extracted from a line to TYPE value.*/
/***********************************************************************/ /***********************************************************************/
...@@ -628,7 +649,8 @@ template <> ...@@ -628,7 +649,8 @@ template <>
longlong TYPVAL<longlong>::GetTypedValue(PSZ s) {return atoll(s);} longlong TYPVAL<longlong>::GetTypedValue(PSZ s) {return atoll(s);}
template <> template <>
double TYPVAL<double>::GetTypedValue(PSZ s) {return atof(s);} 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. */ /* TYPVAL SetValue: set value with a TYPE extracted from a block. */
...@@ -656,6 +678,10 @@ template <> ...@@ -656,6 +678,10 @@ template <>
double TYPVAL<double>::GetTypedValue(PVBLK blk, int n) double TYPVAL<double>::GetTypedValue(PVBLK blk, int n)
{return blk->GetFloatValue(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. */ /* TYPVAL SetBinValue: with bytes extracted from a line. */
/***********************************************************************/ /***********************************************************************/
...@@ -766,6 +792,16 @@ char *TYPVAL<TYPE>::GetFloatString(char *p, int n, int prec) ...@@ -766,6 +792,16 @@ char *TYPVAL<TYPE>::GetFloatString(char *p, int n, int prec)
return p; return p;
} // end of GetFloatString } // 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. */ /* TYPVAL compare value with another Value. */
/***********************************************************************/ /***********************************************************************/
...@@ -997,6 +1033,15 @@ void TYPVAL<PSZ>::SetValue(double f) ...@@ -997,6 +1033,15 @@ void TYPVAL<PSZ>::SetValue(double f)
Null = false; Null = false;
} // end of SetValue } // 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. */ /* STRING SetBinValue: fill string with chars extracted from a line. */
/***********************************************************************/ /***********************************************************************/
...@@ -1078,6 +1123,15 @@ char *TYPVAL<PSZ>::GetFloatString(char *p, int n, int prec) ...@@ -1078,6 +1123,15 @@ char *TYPVAL<PSZ>::GetFloatString(char *p, int n, int prec)
return p; return p;
} // end of GetFloatString } // 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. */ /* STRING compare value with another Value. */
/***********************************************************************/ /***********************************************************************/
......
/**************** Value H Declares Source Code File (.H) ***************/ /**************** 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 */ /* (C) Copyright to the author Olivier BERTRAND 2001-2013 */
/* */ /* */
...@@ -76,6 +76,7 @@ class DllExport VALUE : public BLOCK { ...@@ -76,6 +76,7 @@ class DllExport VALUE : public BLOCK {
virtual int GetValPrec(void) = 0; virtual int GetValPrec(void) = 0;
virtual int GetLength(void) {return 1;} virtual int GetLength(void) {return 1;}
virtual PSZ GetCharValue(void) {assert(false); return NULL;} 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 short GetShortValue(void) {assert(false); return 0;}
virtual int GetIntValue(void) = 0; virtual int GetIntValue(void) = 0;
virtual longlong GetBigintValue(void) = 0; virtual longlong GetBigintValue(void) = 0;
...@@ -93,6 +94,7 @@ class DllExport VALUE : public BLOCK { ...@@ -93,6 +94,7 @@ class DllExport VALUE : public BLOCK {
virtual bool SetValue_pval(PVAL valp, bool chktype = false) = 0; virtual bool SetValue_pval(PVAL valp, bool chktype = false) = 0;
virtual void SetValue_char(char *p, int n) = 0; virtual void SetValue_char(char *p, int n) = 0;
virtual void SetValue_psz(PSZ s) = 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(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(longlong n) {assert(false);}
...@@ -106,6 +108,7 @@ class DllExport VALUE : public BLOCK { ...@@ -106,6 +108,7 @@ class DllExport VALUE : public BLOCK {
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 *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 char *GetTinyString(char *p, int n) {return "?";}
virtual bool IsEqual(PVAL vp, bool chktype) = 0; virtual bool IsEqual(PVAL vp, bool chktype) = 0;
virtual bool FormatValue(PVAL vp, char *fmt) = 0; virtual bool FormatValue(PVAL vp, char *fmt) = 0;
...@@ -145,6 +148,7 @@ class DllExport TYPVAL : public VALUE { ...@@ -145,6 +148,7 @@ class DllExport TYPVAL : public VALUE {
virtual int GetValPrec() {return 0;} virtual int GetValPrec() {return 0;}
virtual int GetSize(void) {return sizeof(TYPE);} virtual int GetSize(void) {return sizeof(TYPE);}
virtual PSZ GetCharValue(void) {return VALUE::GetCharValue();} virtual PSZ GetCharValue(void) {return VALUE::GetCharValue();}
virtual char GetTinyValue(void) {return (char)Tval;}
virtual short GetShortValue(void) {return (short)Tval;} virtual short GetShortValue(void) {return (short)Tval;}
virtual int GetIntValue(void) {return (int)Tval;} virtual int GetIntValue(void) {return (int)Tval;}
virtual longlong GetBigintValue(void) {return (longlong)Tval;} virtual longlong GetBigintValue(void) {return (longlong)Tval;}
...@@ -155,6 +159,7 @@ class DllExport TYPVAL : public VALUE { ...@@ -155,6 +159,7 @@ class DllExport TYPVAL : public VALUE {
virtual bool SetValue_pval(PVAL valp, bool chktype); virtual bool SetValue_pval(PVAL valp, bool chktype);
virtual void SetValue_char(char *p, int n); virtual void SetValue_char(char *p, int n);
virtual void SetValue_psz(PSZ s); 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(short i) {Tval = (TYPE)i; Null = false;}
virtual void SetValue(int n) {Tval = (TYPE)n; Null = false;} virtual void SetValue(int n) {Tval = (TYPE)n; Null = false;}
virtual void SetValue(longlong 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 { ...@@ -168,6 +173,7 @@ class DllExport TYPVAL : public VALUE {
virtual char *GetIntString(char *p, int n); virtual char *GetIntString(char *p, int n);
virtual char *GetBigintString(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 char *GetTinyString(char *p, int n);
virtual bool IsEqual(PVAL vp, bool chktype); virtual bool IsEqual(PVAL vp, bool chktype);
virtual bool SetConstFormat(PGLOBAL, FORMAT&); virtual bool SetConstFormat(PGLOBAL, FORMAT&);
virtual bool FormatValue(PVAL vp, char *fmt); virtual bool FormatValue(PVAL vp, char *fmt);
...@@ -205,6 +211,7 @@ class DllExport TYPVAL<PSZ>: public VALUE { ...@@ -205,6 +211,7 @@ class DllExport TYPVAL<PSZ>: public VALUE {
virtual int GetValPrec() {return (Ci) ? 1 : 0;} virtual int GetValPrec() {return (Ci) ? 1 : 0;}
virtual int GetSize(void) {return (Strp) ? strlen(Strp) : 0;} virtual int GetSize(void) {return (Strp) ? strlen(Strp) : 0;}
virtual PSZ GetCharValue(void) {return Strp;} virtual PSZ GetCharValue(void) {return Strp;}
virtual char GetTinyValue(void) {return (char)atoi(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 atoll(Strp);} virtual longlong GetBigintValue(void) {return atoll(Strp);}
...@@ -216,6 +223,7 @@ class DllExport TYPVAL<PSZ>: public VALUE { ...@@ -216,6 +223,7 @@ class DllExport TYPVAL<PSZ>: public VALUE {
virtual void SetValue_char(char *p, int n); virtual void SetValue_char(char *p, int n);
virtual void SetValue_psz(PSZ s); virtual void SetValue_psz(PSZ s);
virtual void SetValue_pvblk(PVBLK blk, int n); virtual void SetValue_pvblk(PVBLK blk, int n);
virtual void SetValue(char c);
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(longlong n);
...@@ -228,6 +236,7 @@ class DllExport TYPVAL<PSZ>: public VALUE { ...@@ -228,6 +236,7 @@ class DllExport TYPVAL<PSZ>: public VALUE {
virtual char *GetIntString(char *p, int n); virtual char *GetIntString(char *p, int n);
virtual char *GetBigintString(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 char *GetTinyString(char *p, int n);
virtual bool IsEqual(PVAL vp, bool chktype); virtual bool IsEqual(PVAL vp, bool chktype);
virtual bool FormatValue(PVAL vp, char *fmt); virtual bool FormatValue(PVAL vp, char *fmt);
virtual bool SetConstFormat(PGLOBAL, FORMAT&); virtual bool SetConstFormat(PGLOBAL, FORMAT&);
......
...@@ -153,6 +153,12 @@ bool CONSTANT::Rephrase(PGLOBAL g, PSZ work) ...@@ -153,6 +153,12 @@ bool CONSTANT::Rephrase(PGLOBAL g, PSZ work)
case TYPE_FLOAT: case TYPE_FLOAT:
sprintf(work + strlen(work), "%lf", Value->GetFloatValue()); sprintf(work + strlen(work), "%lf", Value->GetFloatValue());
break; break;
case TYPE_BIGINT:
sprintf(work + strlen(work), "%lld", Value->GetBigintValue());
break;
case TYPE_TINY:
sprintf(work + strlen(work), "%d", Value->GetTinyValue());
break;
default: default:
sprintf(g->Message, MSG(BAD_CONST_TYPE), Value->GetType()); sprintf(g->Message, MSG(BAD_CONST_TYPE), Value->GetType());
return false; 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