2013-02-07 10:34:27 +01:00
|
|
|
/************ Valblk C++ Functions Source Code File (.CPP) *************/
|
2014-02-03 16:14:13 +01:00
|
|
|
/* Name: VALBLK.CPP Version 2.1 */
|
2013-02-07 10:34:27 +01:00
|
|
|
/* */
|
2014-02-03 16:14:13 +01:00
|
|
|
/* (C) Copyright to the author Olivier BERTRAND 2005-2014 */
|
2013-02-07 10:34:27 +01:00
|
|
|
/* */
|
|
|
|
/* This file contains the VALBLK and derived classes functions. */
|
|
|
|
/* Second family is VALBLK, representing simple suballocated arrays */
|
|
|
|
/* of values treated sequentially by FIX, BIN and VCT tables and */
|
|
|
|
/* columns, as well for min/max blocks as for VCT column blocks. */
|
|
|
|
/* Q&A: why not using only one family ? Simple values are arrays that */
|
|
|
|
/* have only one element and arrays could have functions for all kind */
|
|
|
|
/* of processing. The answer is a-because historically it was simpler */
|
|
|
|
/* to do that way, b-because of performance on single values, and c- */
|
|
|
|
/* 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. */
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
/* This is why we are now using a template class for many types. */
|
|
|
|
/* Currently the only implemented types are PSZ, chars, int, short, */
|
2013-11-26 11:47:48 +01:00
|
|
|
/* DATE, longlong, double and tiny. Fix numeric ones can be unsigned. */
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/***********************************************************************/
|
2013-02-24 01:23:18 +01:00
|
|
|
/* Include relevant MariaDB header file. */
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
#include "my_global.h"
|
|
|
|
#if defined(WIN32)
|
|
|
|
//#include <windows.h>
|
|
|
|
#else
|
|
|
|
#include "osutil.h"
|
|
|
|
#include "string.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Include required application header files */
|
|
|
|
/* global.h is header containing all global Plug declarations. */
|
|
|
|
/* plgdbsem.h is header containing the DB applic. declarations. */
|
|
|
|
/* valblk.h is header containing VALBLK derived classes declares. */
|
|
|
|
/***********************************************************************/
|
|
|
|
#include "global.h"
|
|
|
|
#include "plgdbsem.h"
|
|
|
|
#include "valblk.h"
|
|
|
|
|
2014-03-10 12:21:17 +01:00
|
|
|
#define CheckBlanks assert(!Blanks);
|
|
|
|
#define CheckParms(V, N) ChkIndx(N); ChkTyp(V);
|
2013-02-07 10:34:27 +01:00
|
|
|
|
2014-03-18 19:25:50 +01:00
|
|
|
extern "C" int trace;
|
2014-04-05 19:26:32 +02:00
|
|
|
extern MBLOCK Nmblk; /* Used to initialize MBLOCK's */
|
2014-03-18 19:25:50 +01:00
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* AllocValBlock: allocate a VALBLK according to type. */
|
|
|
|
/***********************************************************************/
|
|
|
|
PVBLK AllocValBlock(PGLOBAL g, void *mp, int type, int nval, int len,
|
2013-11-26 11:47:48 +01:00
|
|
|
int prec, bool check, bool blank, bool un)
|
2013-02-07 10:34:27 +01:00
|
|
|
{
|
|
|
|
PVBLK blkp;
|
|
|
|
|
2014-03-18 19:25:50 +01:00
|
|
|
if (trace)
|
|
|
|
htrc("AVB: mp=%p type=%d nval=%d len=%d check=%u blank=%u\n",
|
|
|
|
mp, type, nval, len, check, blank);
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case TYPE_STRING:
|
2013-12-28 15:46:49 +01:00
|
|
|
case TYPE_DECIM:
|
2013-02-07 10:34:27 +01:00
|
|
|
if (len)
|
|
|
|
blkp = new(g) CHRBLK(mp, nval, len, prec, blank);
|
|
|
|
else
|
|
|
|
blkp = new(g) STRBLK(g, mp, nval);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case TYPE_SHORT:
|
2013-11-26 11:47:48 +01:00
|
|
|
if (un)
|
|
|
|
blkp = new(g) TYPBLK<ushort>(mp, nval, type, 0, true);
|
|
|
|
else
|
|
|
|
blkp = new(g) TYPBLK<short>(mp, nval, type);
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
break;
|
|
|
|
case TYPE_INT:
|
2013-11-26 11:47:48 +01:00
|
|
|
if (un)
|
|
|
|
blkp = new(g) TYPBLK<uint>(mp, nval, type, 0, true);
|
|
|
|
else
|
|
|
|
blkp = new(g) TYPBLK<int>(mp, nval, type);
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
break;
|
|
|
|
case TYPE_DATE: // ?????
|
|
|
|
blkp = new(g) DATBLK(mp, nval);
|
|
|
|
break;
|
|
|
|
case TYPE_BIGINT:
|
2013-11-26 11:47:48 +01:00
|
|
|
if (un)
|
|
|
|
blkp = new(g) TYPBLK<ulonglong>(mp, nval, type, 0, true);
|
|
|
|
else
|
|
|
|
blkp = new(g) TYPBLK<longlong>(mp, nval, type);
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
break;
|
2013-12-28 15:46:49 +01:00
|
|
|
case TYPE_DOUBLE:
|
2013-11-26 11:47:48 +01:00
|
|
|
blkp = new(g) TYPBLK<double>(mp, nval, type, prec);
|
2013-02-07 10:34:27 +01:00
|
|
|
break;
|
2013-03-11 16:52:59 +01:00
|
|
|
case TYPE_TINY:
|
2013-11-26 11:47:48 +01:00
|
|
|
if (un)
|
|
|
|
blkp = new(g) TYPBLK<uchar>(mp, nval, type, 0, true);
|
|
|
|
else
|
|
|
|
blkp = new(g) TYPBLK<char>(mp, nval, type);
|
|
|
|
|
2013-03-11 16:52:59 +01:00
|
|
|
break;
|
2013-02-07 10:34:27 +01:00
|
|
|
default:
|
|
|
|
sprintf(g->Message, MSG(BAD_VALBLK_TYPE), type);
|
|
|
|
return NULL;
|
|
|
|
} // endswitch Type
|
|
|
|
|
2014-04-05 19:26:32 +02:00
|
|
|
return (blkp->Init(g, check)) ? NULL : blkp;
|
2013-02-07 10:34:27 +01:00
|
|
|
} // end of AllocValBlock
|
|
|
|
|
|
|
|
/* -------------------------- Class VALBLK --------------------------- */
|
|
|
|
|
2013-02-24 01:23:18 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Constructor. */
|
|
|
|
/***********************************************************************/
|
2013-11-26 11:47:48 +01:00
|
|
|
VALBLK::VALBLK(void *mp, int type, int nval, bool un)
|
2013-02-24 01:23:18 +01:00
|
|
|
{
|
2014-04-05 19:26:32 +02:00
|
|
|
Mblk = Nmblk;
|
2013-02-24 01:23:18 +01:00
|
|
|
Blkp = mp;
|
|
|
|
To_Nulls = NULL;
|
|
|
|
Check = true;
|
|
|
|
Nullable = false;
|
2013-11-26 11:47:48 +01:00
|
|
|
Unsigned = un;
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
Type = type;
|
|
|
|
Nval = nval;
|
|
|
|
Prec = 0;
|
2013-02-24 01:23:18 +01:00
|
|
|
} // end of VALBLK constructor
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Raise error for numeric types. */
|
|
|
|
/***********************************************************************/
|
|
|
|
PSZ VALBLK::GetCharValue(int n)
|
|
|
|
{
|
|
|
|
PGLOBAL& g = Global;
|
|
|
|
|
|
|
|
assert(g);
|
|
|
|
sprintf(g->Message, MSG(NO_CHAR_FROM), Type);
|
|
|
|
longjmp(g->jumper[g->jump_level], Type);
|
|
|
|
return NULL;
|
|
|
|
} // end of GetCharValue
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Set format so formatted dates can be converted on input. */
|
|
|
|
/***********************************************************************/
|
|
|
|
bool VALBLK::SetFormat(PGLOBAL g, PSZ fmt, int len, int year)
|
|
|
|
{
|
|
|
|
sprintf(g->Message, MSG(NO_DATE_FMT), Type);
|
|
|
|
return true;
|
|
|
|
} // end of SetFormat
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Set the index of the location of value and return true if found. */
|
|
|
|
/* To be used on ascending sorted arrays only. */
|
|
|
|
/* Currently used by some BLKFIL classes only. */
|
|
|
|
/***********************************************************************/
|
|
|
|
bool VALBLK::Locate(PVAL vp, int& i)
|
|
|
|
{
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
ChkTyp(vp);
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
int n = 1;
|
|
|
|
|
|
|
|
for (i = 0; i < Nval; i++)
|
|
|
|
if ((n = CompVal(vp, i)) <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
return (!n);
|
|
|
|
} // end of Locate
|
|
|
|
|
2013-02-24 01:23:18 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Set Nullable and allocate the Null array. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void VALBLK::SetNullable(bool b)
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
{
|
2013-02-24 01:23:18 +01:00
|
|
|
if ((Nullable = b)) {
|
|
|
|
To_Nulls = (char*)PlugSubAlloc(Global, NULL, Nval);
|
|
|
|
memset(To_Nulls, 0, Nval);
|
|
|
|
} else
|
|
|
|
To_Nulls = NULL;
|
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
} // end of SetNullable
|
|
|
|
|
2014-04-05 19:26:32 +02:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Buffer allocation routine. */
|
|
|
|
/***********************************************************************/
|
|
|
|
bool VALBLK::AllocBuff(PGLOBAL g, size_t size)
|
|
|
|
{
|
|
|
|
Mblk.Size = size;
|
|
|
|
|
|
|
|
if (!(Blkp = PlgDBalloc(g, NULL, Mblk))) {
|
2014-04-21 12:57:10 +02:00
|
|
|
sprintf(g->Message, MSG(MEM_ALLOC_ERR), "Blkp", (int) Mblk.Size);
|
2014-04-05 19:26:32 +02:00
|
|
|
fprintf(stderr, "%s\n", g->Message);
|
|
|
|
return true;
|
|
|
|
} // endif Blkp
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} // end of AllocBuff
|
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Check functions. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void VALBLK::ChkIndx(int n)
|
|
|
|
{
|
|
|
|
if (n < 0 || n >= Nval) {
|
|
|
|
PGLOBAL& g = Global;
|
|
|
|
strcpy(g->Message, MSG(BAD_VALBLK_INDX));
|
|
|
|
longjmp(g->jumper[g->jump_level], Type);
|
|
|
|
} // endif n
|
|
|
|
|
|
|
|
} // end of ChkIndx
|
|
|
|
|
|
|
|
void VALBLK::ChkTyp(PVAL v)
|
|
|
|
{
|
2013-12-03 22:59:40 +01:00
|
|
|
if (Check && (Type != v->GetType() || Unsigned != v->IsUnsigned())) {
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
PGLOBAL& g = Global;
|
|
|
|
strcpy(g->Message, MSG(VALTYPE_NOMATCH));
|
|
|
|
longjmp(g->jumper[g->jump_level], Type);
|
|
|
|
} // endif Type
|
|
|
|
|
|
|
|
} // end of ChkTyp
|
|
|
|
|
|
|
|
void VALBLK::ChkTyp(PVBLK vb)
|
|
|
|
{
|
2013-12-03 22:59:40 +01:00
|
|
|
if (Check && (Type != vb->GetType() || Unsigned != vb->IsUnsigned())) {
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
PGLOBAL& g = Global;
|
|
|
|
strcpy(g->Message, MSG(VALTYPE_NOMATCH));
|
|
|
|
longjmp(g->jumper[g->jump_level], Type);
|
|
|
|
} // endif Type
|
|
|
|
|
|
|
|
} // end of ChkTyp
|
|
|
|
|
|
|
|
/* -------------------------- Class TYPBLK --------------------------- */
|
|
|
|
|
|
|
|
/***********************************************************************/
|
2013-11-26 11:47:48 +01:00
|
|
|
/* Constructor. */
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
2013-11-26 11:47:48 +01:00
|
|
|
TYPBLK<TYPE>::TYPBLK(void *mp, int nval, int type, int prec, bool un)
|
|
|
|
: VALBLK(mp, type, nval, un), Typp((TYPE*&)Blkp)
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
{
|
|
|
|
Prec = prec;
|
|
|
|
Fmt = GetFmt(Type);
|
2013-11-26 11:47:48 +01:00
|
|
|
} // end of TYPBLK constructor
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Initialization routine. */
|
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
2014-04-05 19:26:32 +02:00
|
|
|
bool TYPBLK<TYPE>::Init(PGLOBAL g, bool check)
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
{
|
|
|
|
if (!Blkp)
|
2014-04-05 19:26:32 +02:00
|
|
|
if (AllocBuff(g, Nval * sizeof(TYPE)))
|
|
|
|
return true;
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
|
|
|
|
Check = check;
|
|
|
|
Global = g;
|
2014-04-05 19:26:32 +02:00
|
|
|
return false;
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
} // end of Init
|
|
|
|
|
2014-02-03 16:14:13 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* TYPVAL GetCharString: get string representation of a typed value. */
|
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
|
|
|
char *TYPBLK<TYPE>::GetCharString(char *p, int n)
|
|
|
|
{
|
|
|
|
sprintf(p, Fmt, Typp[n]);
|
|
|
|
return p;
|
|
|
|
} // end of GetCharString
|
|
|
|
|
|
|
|
template <>
|
|
|
|
char *TYPBLK<double>::GetCharString(char *p, int n)
|
|
|
|
{
|
|
|
|
sprintf(p, Fmt, Prec, Typp[n]);
|
|
|
|
return p;
|
|
|
|
} // end of GetCharString
|
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Set one value in a block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
|
|
|
void TYPBLK<TYPE>::SetValue(PVAL valp, int n)
|
|
|
|
{
|
|
|
|
bool b;
|
|
|
|
|
|
|
|
ChkIndx(n);
|
|
|
|
ChkTyp(valp);
|
|
|
|
|
2013-12-16 01:32:47 +01:00
|
|
|
if (!(b = valp->IsNull()))
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
Typp[n] = GetTypedValue(valp);
|
|
|
|
else
|
|
|
|
Reset(n);
|
|
|
|
|
2013-12-16 01:32:47 +01:00
|
|
|
SetNull(n, b && Nullable);
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
} // end of SetValue
|
|
|
|
|
|
|
|
template <>
|
|
|
|
int TYPBLK<int>::GetTypedValue(PVAL valp)
|
|
|
|
{return valp->GetIntValue();}
|
|
|
|
|
2013-11-28 23:37:27 +01:00
|
|
|
template <>
|
2013-11-26 11:47:48 +01:00
|
|
|
uint TYPBLK<uint>::GetTypedValue(PVAL valp)
|
|
|
|
{return valp->GetUIntValue();}
|
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
template <>
|
|
|
|
short TYPBLK<short>::GetTypedValue(PVAL valp)
|
|
|
|
{return valp->GetShortValue();}
|
|
|
|
|
2013-11-26 11:47:48 +01:00
|
|
|
template <>
|
|
|
|
ushort TYPBLK<ushort>::GetTypedValue(PVAL valp)
|
|
|
|
{return valp->GetUShortValue();}
|
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
template <>
|
|
|
|
longlong TYPBLK<longlong>::GetTypedValue(PVAL valp)
|
|
|
|
{return valp->GetBigintValue();}
|
|
|
|
|
2013-11-26 11:47:48 +01:00
|
|
|
template <>
|
|
|
|
ulonglong TYPBLK<ulonglong>::GetTypedValue(PVAL valp)
|
|
|
|
{return valp->GetUBigintValue();}
|
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
template <>
|
|
|
|
double TYPBLK<double>::GetTypedValue(PVAL valp)
|
|
|
|
{return valp->GetFloatValue();}
|
|
|
|
|
2013-03-11 16:52:59 +01:00
|
|
|
template <>
|
|
|
|
char TYPBLK<char>::GetTypedValue(PVAL valp)
|
|
|
|
{return valp->GetTinyValue();}
|
|
|
|
|
2013-11-26 11:47:48 +01:00
|
|
|
template <>
|
|
|
|
uchar TYPBLK<uchar>::GetTypedValue(PVAL valp)
|
|
|
|
{return valp->GetUTinyValue();}
|
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
/***********************************************************************/
|
2013-04-29 13:50:20 +02:00
|
|
|
/* Set one value in a block from a zero terminated string. */
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
|
|
|
void TYPBLK<TYPE>::SetValue(PSZ p, int n)
|
|
|
|
{
|
|
|
|
ChkIndx(n);
|
|
|
|
|
|
|
|
if (Check) {
|
|
|
|
PGLOBAL& g = Global;
|
|
|
|
strcpy(g->Message, MSG(BAD_SET_STRING));
|
|
|
|
longjmp(g->jumper[g->jump_level], Type);
|
|
|
|
} // endif Check
|
|
|
|
|
2013-12-03 22:59:40 +01:00
|
|
|
bool minus;
|
|
|
|
ulonglong maxval = MaxVal();
|
|
|
|
ulonglong val = CharToNumber(p, strlen(p), maxval, Unsigned, &minus);
|
|
|
|
|
|
|
|
if (minus && val < maxval)
|
|
|
|
Typp[n] = (TYPE)(-(signed)val);
|
|
|
|
else
|
|
|
|
Typp[n] = (TYPE)val;
|
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
SetNull(n, false);
|
|
|
|
} // end of SetValue
|
|
|
|
|
2013-12-03 22:59:40 +01:00
|
|
|
template <class TYPE>
|
|
|
|
ulonglong TYPBLK<TYPE>::MaxVal(void) {DBUG_ASSERT(false); return 0;}
|
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
template <>
|
2013-12-03 22:59:40 +01:00
|
|
|
ulonglong TYPBLK<short>::MaxVal(void) {return INT_MAX16;}
|
|
|
|
|
2013-11-26 11:47:48 +01:00
|
|
|
template <>
|
2013-12-03 22:59:40 +01:00
|
|
|
ulonglong TYPBLK<ushort>::MaxVal(void) {return UINT_MAX16;}
|
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
template <>
|
2013-12-03 22:59:40 +01:00
|
|
|
ulonglong TYPBLK<int>::MaxVal(void) {return INT_MAX32;}
|
|
|
|
|
2013-11-26 11:47:48 +01:00
|
|
|
template <>
|
2013-12-03 22:59:40 +01:00
|
|
|
ulonglong TYPBLK<uint>::MaxVal(void) {return UINT_MAX32;}
|
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
template <>
|
2013-12-03 22:59:40 +01:00
|
|
|
ulonglong TYPBLK<char>::MaxVal(void) {return INT_MAX8;}
|
|
|
|
|
2013-11-26 11:47:48 +01:00
|
|
|
template <>
|
2013-12-03 22:59:40 +01:00
|
|
|
ulonglong TYPBLK<uchar>::MaxVal(void) {return UINT_MAX8;}
|
|
|
|
|
2013-03-11 16:52:59 +01:00
|
|
|
template <>
|
2013-12-03 22:59:40 +01:00
|
|
|
ulonglong TYPBLK<longlong>::MaxVal(void) {return INT_MAX64;}
|
|
|
|
|
2013-11-26 11:47:48 +01:00
|
|
|
template <>
|
2013-12-03 22:59:40 +01:00
|
|
|
ulonglong TYPBLK<ulonglong>::MaxVal(void) {return ULONGLONG_MAX;}
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
|
2013-12-28 15:46:49 +01:00
|
|
|
template <>
|
|
|
|
void TYPBLK<double>::SetValue(PSZ p, int n)
|
|
|
|
{
|
|
|
|
ChkIndx(n);
|
|
|
|
|
|
|
|
if (Check) {
|
|
|
|
PGLOBAL& g = Global;
|
|
|
|
strcpy(g->Message, MSG(BAD_SET_STRING));
|
|
|
|
longjmp(g->jumper[g->jump_level], Type);
|
|
|
|
} // endif Check
|
|
|
|
|
|
|
|
Typp[n] = atof(p);
|
|
|
|
SetNull(n, false);
|
|
|
|
} // end of SetValue
|
|
|
|
|
2013-04-29 13:50:20 +02:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Set one value in a block from an array of characters. */
|
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
|
|
|
void TYPBLK<TYPE>::SetValue(char *sp, uint len, int n)
|
|
|
|
{
|
|
|
|
PGLOBAL& g = Global;
|
|
|
|
PSZ spz = (PSZ)PlugSubAlloc(g, NULL, 0); // Temporary
|
|
|
|
|
|
|
|
if (sp)
|
|
|
|
memcpy(spz, sp, len);
|
|
|
|
|
|
|
|
spz[len] = 0;
|
|
|
|
SetValue(spz, n);
|
|
|
|
} // end of SetValue
|
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Set one value in a block from a value in another block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
|
|
|
void TYPBLK<TYPE>::SetValue(PVBLK pv, int n1, int n2)
|
|
|
|
{
|
|
|
|
bool b;
|
|
|
|
|
|
|
|
ChkIndx(n1);
|
|
|
|
ChkTyp(pv);
|
|
|
|
|
|
|
|
if (!(b = pv->IsNull(n2) && Nullable))
|
|
|
|
Typp[n1] = GetTypedValue(pv, n2);
|
|
|
|
else
|
|
|
|
Reset(n1);
|
|
|
|
|
|
|
|
SetNull(n1, b);
|
|
|
|
} // end of SetValue
|
|
|
|
|
|
|
|
template <>
|
|
|
|
int TYPBLK<int>::GetTypedValue(PVBLK blk, int n)
|
|
|
|
{return blk->GetIntValue(n);}
|
|
|
|
|
2013-11-26 11:47:48 +01:00
|
|
|
template <>
|
|
|
|
uint TYPBLK<uint>::GetTypedValue(PVBLK blk, int n)
|
|
|
|
{return blk->GetUIntValue(n);}
|
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
template <>
|
|
|
|
short TYPBLK<short>::GetTypedValue(PVBLK blk, int n)
|
|
|
|
{return blk->GetShortValue(n);}
|
|
|
|
|
2013-11-26 11:47:48 +01:00
|
|
|
template <>
|
|
|
|
ushort TYPBLK<ushort>::GetTypedValue(PVBLK blk, int n)
|
|
|
|
{return blk->GetUShortValue(n);}
|
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
template <>
|
|
|
|
longlong TYPBLK<longlong>::GetTypedValue(PVBLK blk, int n)
|
|
|
|
{return blk->GetBigintValue(n);}
|
|
|
|
|
2013-11-26 11:47:48 +01:00
|
|
|
template <>
|
|
|
|
ulonglong TYPBLK<ulonglong>::GetTypedValue(PVBLK blk, int n)
|
|
|
|
{return blk->GetUBigintValue(n);}
|
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
template <>
|
|
|
|
double TYPBLK<double>::GetTypedValue(PVBLK blk, int n)
|
|
|
|
{return blk->GetFloatValue(n);}
|
|
|
|
|
2013-03-11 16:52:59 +01:00
|
|
|
template <>
|
|
|
|
char TYPBLK<char>::GetTypedValue(PVBLK blk, int n)
|
|
|
|
{return blk->GetTinyValue(n);}
|
|
|
|
|
2013-11-26 11:47:48 +01:00
|
|
|
template <>
|
|
|
|
uchar TYPBLK<uchar>::GetTypedValue(PVBLK blk, int n)
|
|
|
|
{return blk->GetUTinyValue(n);}
|
|
|
|
|
2014-03-10 12:21:17 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Set one value in a block if val is less than the current value. */
|
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
|
|
|
void TYPBLK<TYPE>::SetMin(PVAL valp, int n)
|
|
|
|
{
|
|
|
|
CheckParms(valp, n)
|
|
|
|
TYPE tval = GetTypedValue(valp);
|
|
|
|
TYPE& tmin = Typp[n];
|
|
|
|
|
|
|
|
if (tval < tmin)
|
|
|
|
tmin = tval;
|
|
|
|
|
|
|
|
} // end of SetMin
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Set one value in a block if val is greater than the current value. */
|
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
|
|
|
void TYPBLK<TYPE>::SetMax(PVAL valp, int n)
|
|
|
|
{
|
|
|
|
CheckParms(valp, n)
|
|
|
|
TYPE tval = GetTypedValue(valp);
|
|
|
|
TYPE& tmin = Typp[n];
|
|
|
|
|
|
|
|
if (tval > tmin)
|
|
|
|
tmin = tval;
|
|
|
|
|
|
|
|
} // end of SetMax
|
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
#if 0
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Set many values in a block from values in another block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
|
|
|
void TYPBLK<TYPE>::SetValues(PVBLK pv, int k, int n)
|
|
|
|
{
|
|
|
|
CheckType(pv)
|
|
|
|
TYPE *lp = ((TYPBLK*)pv)->Typp;
|
|
|
|
|
|
|
|
for (register int i = k; i < n; i++) // TODO
|
|
|
|
Typp[i] = lp[i];
|
|
|
|
|
|
|
|
} // end of SetValues
|
|
|
|
#endif // 0
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Move one value from i to j. */
|
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
|
|
|
void TYPBLK<TYPE>::Move(int i, int j)
|
|
|
|
{
|
|
|
|
Typp[j] = Typp[i];
|
|
|
|
MoveNull(i, j);
|
|
|
|
} // end of Move
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Compare a Value object with the nth value of the block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
|
|
|
int TYPBLK<TYPE>::CompVal(PVAL vp, int n)
|
|
|
|
{
|
|
|
|
#if defined(_DEBUG)
|
|
|
|
ChkIndx(n);
|
|
|
|
ChkTyp(vp);
|
|
|
|
#endif // _DEBUG
|
|
|
|
TYPE mlv = Typp[n];
|
|
|
|
TYPE vlv = GetTypedValue(vp);
|
|
|
|
|
|
|
|
return (vlv > mlv) ? 1 : (vlv < mlv) ? (-1) : 0;
|
|
|
|
} // end of CompVal
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Compare two values of the block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
|
|
|
int TYPBLK<TYPE>::CompVal(int i1, int i2)
|
|
|
|
{
|
|
|
|
TYPE lv1 = Typp[i1];
|
|
|
|
TYPE lv2 = Typp[i2];
|
|
|
|
|
|
|
|
return (lv1 > lv2) ? 1 : (lv1 < lv2) ? (-1) : 0;
|
|
|
|
} // end of CompVal
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Get a pointer on the nth value of the block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
|
|
|
void *TYPBLK<TYPE>::GetValPtr(int n)
|
|
|
|
{
|
|
|
|
ChkIndx(n);
|
|
|
|
return Typp + n;
|
|
|
|
} // end of GetValPtr
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Get a pointer on the nth value of the block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
|
|
|
void *TYPBLK<TYPE>::GetValPtrEx(int n)
|
|
|
|
{
|
|
|
|
ChkIndx(n);
|
|
|
|
return Typp + n;
|
|
|
|
} // end of GetValPtrEx
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Returns index of matching value in block or -1. */
|
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
|
|
|
int TYPBLK<TYPE>::Find(PVAL vp)
|
|
|
|
{
|
|
|
|
ChkTyp(vp);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
TYPE n = GetTypedValue(vp);
|
|
|
|
|
|
|
|
for (i = 0; i < Nval; i++)
|
|
|
|
if (n == Typp[i])
|
|
|
|
break;
|
|
|
|
|
|
|
|
return (i < Nval) ? i : (-1);
|
|
|
|
} // end of Find
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Returns the length of the longest string in the block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
template <class TYPE>
|
|
|
|
int TYPBLK<TYPE>::GetMaxLength(void)
|
|
|
|
{
|
2014-03-18 19:25:50 +01:00
|
|
|
char buf[64];
|
2013-08-25 11:12:54 +02:00
|
|
|
int i, n, m;
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
|
|
|
|
for (i = n = 0; i < Nval; i++) {
|
2013-08-25 11:12:54 +02:00
|
|
|
m = sprintf(buf, Fmt, Typp[i]);
|
2014-04-21 12:57:10 +02:00
|
|
|
n = MY_MAX(n, m);
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
} // endfor i
|
|
|
|
|
|
|
|
return n;
|
|
|
|
} // end of GetMaxLength
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
/* -------------------------- Class CHRBLK --------------------------- */
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Constructor. */
|
|
|
|
/***********************************************************************/
|
|
|
|
CHRBLK::CHRBLK(void *mp, int nval, int len, int prec, bool blank)
|
|
|
|
: VALBLK(mp, TYPE_STRING, nval), Chrp((char*&)Blkp)
|
|
|
|
{
|
|
|
|
Valp = NULL;
|
|
|
|
Blanks = blank;
|
|
|
|
Ci = (prec != 0);
|
|
|
|
Long = len;
|
|
|
|
} // end of CHRBLK constructor
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Initialization routine. */
|
|
|
|
/***********************************************************************/
|
2014-04-05 19:26:32 +02:00
|
|
|
bool CHRBLK::Init(PGLOBAL g, bool check)
|
2013-02-07 10:34:27 +01:00
|
|
|
{
|
|
|
|
Valp = (char*)PlugSubAlloc(g, NULL, Long + 1);
|
|
|
|
Valp[Long] = '\0';
|
|
|
|
|
|
|
|
if (!Blkp)
|
2014-04-05 19:26:32 +02:00
|
|
|
if (AllocBuff(g, Nval * Long))
|
|
|
|
return true;
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
Check = check;
|
|
|
|
Global = g;
|
2014-04-05 19:26:32 +02:00
|
|
|
return false;
|
2013-02-07 10:34:27 +01:00
|
|
|
} // end of Init
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Reset nth element to a null string. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void CHRBLK::Reset(int n)
|
|
|
|
{
|
|
|
|
if (Blanks)
|
|
|
|
memset(Chrp + n * Long, ' ', Long);
|
|
|
|
else
|
|
|
|
*(Chrp + n * Long) = '\0';
|
|
|
|
|
|
|
|
} // end of Reset
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Return the zero ending value of the nth element. */
|
|
|
|
/***********************************************************************/
|
|
|
|
char *CHRBLK::GetCharValue(int n)
|
|
|
|
{
|
|
|
|
return (char *)GetValPtrEx(n);
|
|
|
|
} // end of GetCharValue
|
|
|
|
|
2013-12-03 22:59:40 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Return the value of the nth element converted to tiny int. */
|
|
|
|
/***********************************************************************/
|
|
|
|
char CHRBLK::GetTinyValue(int n)
|
|
|
|
{
|
|
|
|
bool m;
|
|
|
|
ulonglong val = CharToNumber((char*)GetValPtr(n), Long, INT_MAX8,
|
|
|
|
false, &m);
|
|
|
|
|
|
|
|
return (m && val < INT_MAX8) ? (char)(-(signed)val) : (char)val;
|
|
|
|
} // end of GetTinyValue
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Return the value of the nth element converted to unsigned tiny int.*/
|
|
|
|
/***********************************************************************/
|
|
|
|
uchar CHRBLK::GetUTinyValue(int n)
|
|
|
|
{
|
|
|
|
return (uchar)CharToNumber((char*)GetValPtr(n), Long, UINT_MAX8, true);
|
|
|
|
} // end of GetTinyValue
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Return the value of the nth element converted to short. */
|
|
|
|
/***********************************************************************/
|
|
|
|
short CHRBLK::GetShortValue(int n)
|
|
|
|
{
|
2013-12-03 22:59:40 +01:00
|
|
|
bool m;
|
|
|
|
ulonglong val = CharToNumber((char*)GetValPtr(n), Long, INT_MAX16,
|
|
|
|
false, &m);
|
|
|
|
|
|
|
|
return (m && val < INT_MAX16) ? (short)(-(signed)val) : (short)val;
|
2013-03-11 16:52:59 +01:00
|
|
|
} // end of GetShortValue
|
2013-02-07 10:34:27 +01:00
|
|
|
|
2013-11-26 11:47:48 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Return the value of the nth element converted to ushort. */
|
|
|
|
/***********************************************************************/
|
|
|
|
ushort CHRBLK::GetUShortValue(int n)
|
|
|
|
{
|
2013-12-03 22:59:40 +01:00
|
|
|
return (ushort)CharToNumber((char*)GetValPtr(n), Long, UINT_MAX16, true);
|
2013-11-26 11:47:48 +01:00
|
|
|
} // end of GetShortValue
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
2013-02-24 01:23:18 +01:00
|
|
|
/* Return the value of the nth element converted to int. */
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
int CHRBLK::GetIntValue(int n)
|
|
|
|
{
|
2013-12-03 22:59:40 +01:00
|
|
|
bool m;
|
|
|
|
ulonglong val = CharToNumber((char*)GetValPtr(n), Long, INT_MAX32,
|
|
|
|
false, &m);
|
|
|
|
|
|
|
|
return (m && val < INT_MAX32) ? (int)(-(signed)val) : (int)val;
|
2013-02-07 10:34:27 +01:00
|
|
|
} // end of GetIntValue
|
|
|
|
|
2013-11-26 11:47:48 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Return the value of the nth element converted to uint. */
|
|
|
|
/***********************************************************************/
|
|
|
|
uint CHRBLK::GetUIntValue(int n)
|
|
|
|
{
|
2013-12-03 22:59:40 +01:00
|
|
|
return (uint)CharToNumber((char*)GetValPtr(n), Long, UINT_MAX32, true);
|
2013-11-26 11:47:48 +01:00
|
|
|
} // end of GetIntValue
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Return the value of the nth element converted to big int. */
|
|
|
|
/***********************************************************************/
|
|
|
|
longlong CHRBLK::GetBigintValue(int n)
|
|
|
|
{
|
2013-12-03 22:59:40 +01:00
|
|
|
bool m;
|
|
|
|
ulonglong val = CharToNumber((char*)GetValPtr(n), Long, INT_MAX64,
|
|
|
|
false, &m);
|
|
|
|
|
|
|
|
return (m && val < INT_MAX64) ? (longlong)(-(signed)val) : (longlong)val;
|
2013-03-11 16:52:59 +01:00
|
|
|
} // end of GetBigintValue
|
2013-02-07 10:34:27 +01:00
|
|
|
|
2013-11-26 11:47:48 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Return the value of the nth element converted to unsigned big int. */
|
|
|
|
/***********************************************************************/
|
|
|
|
ulonglong CHRBLK::GetUBigintValue(int n)
|
|
|
|
{
|
2013-12-03 22:59:40 +01:00
|
|
|
return CharToNumber((char*)GetValPtr(n), Long, ULONGLONG_MAX, true);
|
|
|
|
} // end of GetUBigintValue
|
2013-11-26 11:47:48 +01:00
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Return the value of the nth element converted to double. */
|
|
|
|
/***********************************************************************/
|
|
|
|
double CHRBLK::GetFloatValue(int n)
|
|
|
|
{
|
|
|
|
return atof((char *)GetValPtrEx(n));
|
|
|
|
} // end of GetFloatValue
|
|
|
|
|
2014-02-03 16:14:13 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* STRING GetCharString: get string representation of a char value. */
|
|
|
|
/***********************************************************************/
|
|
|
|
char *CHRBLK::GetCharString(char *p, int n)
|
|
|
|
{
|
|
|
|
return (char *)GetValPtrEx(n);
|
|
|
|
} // end of GetCharString
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Set one value in a block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void CHRBLK::SetValue(PVAL valp, int n)
|
|
|
|
{
|
2013-02-24 01:23:18 +01:00
|
|
|
bool b;
|
2013-02-07 10:34:27 +01:00
|
|
|
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
ChkIndx(n);
|
|
|
|
ChkTyp(valp);
|
|
|
|
|
2013-12-16 01:32:47 +01:00
|
|
|
if (!(b = valp->IsNull()))
|
2013-02-24 01:23:18 +01:00
|
|
|
SetValue((PSZ)valp->GetCharValue(), n);
|
|
|
|
else
|
|
|
|
Reset(n);
|
|
|
|
|
2013-12-16 01:32:47 +01:00
|
|
|
SetNull(n, b && Nullable);
|
2013-02-07 10:34:27 +01:00
|
|
|
} // end of SetValue
|
|
|
|
|
|
|
|
/***********************************************************************/
|
2013-04-29 13:50:20 +02:00
|
|
|
/* Set one value in a block from a zero terminated string. */
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
void CHRBLK::SetValue(PSZ sp, int n)
|
|
|
|
{
|
2013-04-29 13:50:20 +02:00
|
|
|
uint len = (sp) ? strlen(sp) : 0;
|
|
|
|
SetValue(sp, len, n);
|
|
|
|
} // end of SetValue
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Set one value in a block from an array of characters. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void CHRBLK::SetValue(char *sp, uint len, int n)
|
|
|
|
{
|
2013-02-07 10:34:27 +01:00
|
|
|
char *p = Chrp + n * Long;
|
|
|
|
|
2014-03-18 19:25:50 +01:00
|
|
|
#if defined(_DEBUG)
|
2013-02-07 10:34:27 +01:00
|
|
|
if (Check && (signed)len > Long) {
|
|
|
|
PGLOBAL& g = Global;
|
|
|
|
strcpy(g->Message, MSG(SET_STR_TRUNC));
|
|
|
|
longjmp(g->jumper[g->jump_level], Type);
|
|
|
|
} // endif Check
|
2014-03-18 19:25:50 +01:00
|
|
|
#endif // _DEBUG
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
if (sp)
|
2014-04-21 12:57:10 +02:00
|
|
|
memcpy(p, sp, MY_MIN((unsigned)Long, len));
|
2013-02-07 10:34:27 +01:00
|
|
|
|
2013-04-29 13:50:20 +02:00
|
|
|
if (Blanks) {
|
2013-02-07 10:34:27 +01:00
|
|
|
// Suppress eventual ending zero and right fill with blanks
|
|
|
|
for (register int i = len; i < Long; i++)
|
|
|
|
p[i] = ' ';
|
|
|
|
|
2013-04-29 13:50:20 +02:00
|
|
|
} else if ((signed)len < Long)
|
|
|
|
p[len] = 0;
|
|
|
|
|
2013-02-24 01:23:18 +01:00
|
|
|
SetNull(n, false);
|
2013-02-07 10:34:27 +01:00
|
|
|
} // end of SetValue
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Set one value in a block from a value in another block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void CHRBLK::SetValue(PVBLK pv, int n1, int n2)
|
|
|
|
{
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
bool b;
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
if (Type != pv->GetType() || Long != ((CHRBLK*)pv)->Long) {
|
|
|
|
PGLOBAL& g = Global;
|
|
|
|
strcpy(g->Message, MSG(BLKTYPLEN_MISM));
|
|
|
|
longjmp(g->jumper[g->jump_level], Type);
|
|
|
|
} // endif Type
|
2013-02-24 01:23:18 +01:00
|
|
|
|
|
|
|
if (!(b = pv->IsNull(n2) && Nullable))
|
|
|
|
memcpy(Chrp + n1 * Long, ((CHRBLK*)pv)->Chrp + n2 * Long, Long);
|
|
|
|
else
|
|
|
|
Reset(n1);
|
2013-02-07 10:34:27 +01:00
|
|
|
|
2013-02-24 01:23:18 +01:00
|
|
|
SetNull(n1, b);
|
2013-02-07 10:34:27 +01:00
|
|
|
} // end of SetValue
|
|
|
|
|
2014-03-10 12:21:17 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Set one value in a block if val is less than the current value. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void CHRBLK::SetMin(PVAL valp, int n)
|
|
|
|
{
|
|
|
|
CheckParms(valp, n)
|
|
|
|
CheckBlanks
|
|
|
|
char *vp = valp->GetCharValue();
|
|
|
|
char *bp = Chrp + n * Long;
|
|
|
|
|
|
|
|
if (((Ci) ? strnicmp(vp, bp, Long) : strncmp(vp, bp, Long)) < 0)
|
|
|
|
memcpy(bp, vp, Long);
|
|
|
|
|
|
|
|
} // end of SetMin
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Set one value in a block if val is greater than the current value. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void CHRBLK::SetMax(PVAL valp, int n)
|
|
|
|
{
|
|
|
|
CheckParms(valp, n)
|
|
|
|
CheckBlanks
|
|
|
|
char *vp = valp->GetCharValue();
|
|
|
|
char *bp = Chrp + n * Long;
|
|
|
|
|
|
|
|
if (((Ci) ? strnicmp(vp, bp, Long) : strncmp(vp, bp, Long)) > 0)
|
|
|
|
memcpy(bp, vp, Long);
|
|
|
|
|
|
|
|
} // end of SetMax
|
|
|
|
|
2013-02-24 01:23:18 +01:00
|
|
|
#if 0
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Set many values in a block from values in another block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void CHRBLK::SetValues(PVBLK pv, int k, int n)
|
|
|
|
{
|
2014-03-18 19:25:50 +01:00
|
|
|
#if defined(_DEBUG)
|
2013-02-07 10:34:27 +01:00
|
|
|
if (Type != pv->GetType() || Long != ((CHRBLK*)pv)->Long) {
|
|
|
|
PGLOBAL& g = Global;
|
|
|
|
strcpy(g->Message, MSG(BLKTYPLEN_MISM));
|
|
|
|
longjmp(g->jumper[g->jump_level], Type);
|
|
|
|
} // endif Type
|
2014-03-18 19:25:50 +01:00
|
|
|
#endif // _DEBUG
|
2013-02-07 10:34:27 +01:00
|
|
|
char *p = ((CHRBLK*)pv)->Chrp;
|
|
|
|
|
|
|
|
if (!k)
|
|
|
|
memcpy(Chrp, p, Long * n);
|
|
|
|
else
|
|
|
|
memcpy(Chrp + k * Long, p + k * Long, Long * (n - k));
|
|
|
|
|
|
|
|
} // end of SetValues
|
2013-02-24 01:23:18 +01:00
|
|
|
#endif // 0
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Move one value from i to j. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void CHRBLK::Move(int i, int j)
|
|
|
|
{
|
2013-06-30 12:43:30 +02:00
|
|
|
if (i != j) {
|
|
|
|
memcpy(Chrp + j * Long, Chrp + i * Long, Long);
|
|
|
|
MoveNull(i, j);
|
|
|
|
} // endif i
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
} // end of Move
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Compare a Value object with the nth value of the block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
int CHRBLK::CompVal(PVAL vp, int n)
|
|
|
|
{
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
ChkIndx(n);
|
|
|
|
ChkTyp(vp);
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
char *xvp = vp->GetCharValue(); // Get Value zero ended string
|
|
|
|
bool ci = Ci || vp->IsCi(); // true if is case insensitive
|
|
|
|
|
|
|
|
GetValPtrEx(n); // Get a zero ended string in Valp
|
|
|
|
return (ci) ? stricmp(xvp, Valp) : strcmp(xvp, Valp);
|
|
|
|
} // end of CompVal
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Compare two values of the block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
int CHRBLK::CompVal(int i1, int i2)
|
|
|
|
{
|
|
|
|
return (Ci) ? strnicmp(Chrp + i1 * Long, Chrp + i2 * Long, Long)
|
|
|
|
: strncmp(Chrp + i1 * Long, Chrp + i2 * Long, Long);
|
|
|
|
} // end of CompVal
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Get a pointer on the nth value of the block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void *CHRBLK::GetValPtr(int n)
|
|
|
|
{
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
ChkIndx(n);
|
2013-02-07 10:34:27 +01:00
|
|
|
return Chrp + n * Long;
|
|
|
|
} // end of GetValPtr
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Get a pointer on a zero ended string equal to nth value. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void *CHRBLK::GetValPtrEx(int n)
|
|
|
|
{
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
ChkIndx(n);
|
2013-02-07 10:34:27 +01:00
|
|
|
memcpy(Valp, Chrp + n * Long, Long);
|
|
|
|
|
2013-02-24 01:23:18 +01:00
|
|
|
if (IsNull(n))
|
2013-04-19 20:35:43 +02:00
|
|
|
return const_cast<char *>("");
|
2013-02-24 01:23:18 +01:00
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
if (Blanks) {
|
|
|
|
// The (fast) way this is done works only for blocks such
|
|
|
|
// as Min and Max where strings are stored with the ending 0
|
|
|
|
// except for those whose length is equal to Len.
|
|
|
|
// For VCT blocks we must remove rightmost blanks.
|
|
|
|
char *p = Valp + Long;
|
|
|
|
|
2013-08-13 18:53:14 +02:00
|
|
|
for (p--; p >= Valp && *p == ' '; p--) ;
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
*(++p) = '\0';
|
|
|
|
} // endif Blanks
|
|
|
|
|
|
|
|
return Valp;
|
|
|
|
} // end of GetValPtrEx
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Returns index of matching value in block or -1. */
|
|
|
|
/***********************************************************************/
|
|
|
|
int CHRBLK::Find(PVAL vp)
|
|
|
|
{
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
ChkTyp(vp);
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
int i;
|
|
|
|
bool ci = Ci || vp->IsCi();
|
|
|
|
PSZ s = vp->GetCharValue();
|
|
|
|
|
2013-02-24 01:23:18 +01:00
|
|
|
if (vp->IsNull())
|
|
|
|
return -1;
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
for (i = 0; i < Nval; i++) {
|
2013-02-24 01:23:18 +01:00
|
|
|
if (IsNull(i))
|
|
|
|
continue;
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
GetValPtrEx(i); // Get a zero ended string in Valp
|
|
|
|
|
|
|
|
if (!((ci) ? strnicmp(s, Valp, Long) : strncmp(s, Valp, Long)))
|
|
|
|
break;
|
|
|
|
|
|
|
|
} // endfor i
|
|
|
|
|
|
|
|
return (i < Nval) ? i : (-1);
|
2013-02-24 01:23:18 +01:00
|
|
|
} // end of Find
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Returns the length of the longest string in the block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
int CHRBLK::GetMaxLength(void)
|
|
|
|
{
|
|
|
|
int i, n;
|
|
|
|
|
2013-02-24 01:23:18 +01:00
|
|
|
for (i = n = 0; i < Nval; i++)
|
|
|
|
if (!IsNull(i)) {
|
|
|
|
GetValPtrEx(i);
|
2014-04-21 12:57:10 +02:00
|
|
|
n = MY_MAX(n, (signed)strlen(Valp));
|
2013-02-24 01:23:18 +01:00
|
|
|
} // endif null
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
return n;
|
|
|
|
} // end of GetMaxLength
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------- Class STRBLK --------------------------- */
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Constructor. */
|
|
|
|
/***********************************************************************/
|
|
|
|
STRBLK::STRBLK(PGLOBAL g, void *mp, int nval)
|
|
|
|
: VALBLK(mp, TYPE_STRING, nval), Strp((PSZ*&)Blkp)
|
|
|
|
{
|
|
|
|
Global = g;
|
2013-02-24 01:23:18 +01:00
|
|
|
Nullable = true;
|
2013-12-16 01:32:47 +01:00
|
|
|
Sorted = false;
|
2013-02-07 10:34:27 +01:00
|
|
|
} // end of STRBLK constructor
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Initialization routine. */
|
|
|
|
/***********************************************************************/
|
2014-04-05 19:26:32 +02:00
|
|
|
bool STRBLK::Init(PGLOBAL g, bool check)
|
2013-02-07 10:34:27 +01:00
|
|
|
{
|
|
|
|
if (!Blkp)
|
2014-04-05 19:26:32 +02:00
|
|
|
if (AllocBuff(g, Nval * sizeof(PSZ)))
|
|
|
|
return true;
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
Check = check;
|
|
|
|
Global = g;
|
2014-04-05 19:26:32 +02:00
|
|
|
return false;
|
2013-02-07 10:34:27 +01:00
|
|
|
} // end of Init
|
|
|
|
|
|
|
|
/***********************************************************************/
|
2013-12-03 22:59:40 +01:00
|
|
|
/* Get the tiny value represented by the Strp string. */
|
|
|
|
/***********************************************************************/
|
|
|
|
char STRBLK::GetTinyValue(int n)
|
|
|
|
{
|
|
|
|
bool m;
|
|
|
|
ulonglong val = CharToNumber(Strp[n], strlen(Strp[n]), INT_MAX8,
|
|
|
|
false, &m);
|
|
|
|
|
|
|
|
return (m && val < INT_MAX8) ? (char)(-(signed)val) : (char)val;
|
|
|
|
} // end of GetTinyValue
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Get the unsigned tiny value represented by the Strp string. */
|
|
|
|
/***********************************************************************/
|
|
|
|
uchar STRBLK::GetUTinyValue(int n)
|
|
|
|
{
|
|
|
|
return (uchar)CharToNumber(Strp[n], strlen(Strp[n]), UINT_MAX8, true);
|
|
|
|
} // end of GetUTinyValue
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Get the short value represented by the Strp string. */
|
|
|
|
/***********************************************************************/
|
|
|
|
short STRBLK::GetShortValue(int n)
|
|
|
|
{
|
|
|
|
bool m;
|
|
|
|
ulonglong val = CharToNumber(Strp[n], strlen(Strp[n]), INT_MAX16,
|
|
|
|
false, &m);
|
|
|
|
|
|
|
|
return (m && val < INT_MAX16) ? (short)(-(signed)val) : (short)val;
|
|
|
|
} // end of GetShortValue
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Get the unsigned short value represented by the Strp string. */
|
|
|
|
/***********************************************************************/
|
|
|
|
ushort STRBLK::GetUShortValue(int n)
|
|
|
|
{
|
|
|
|
return (ushort)CharToNumber(Strp[n], strlen(Strp[n]), UINT_MAX16, true);
|
|
|
|
} // end of GetUshortValue
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Get the integer value represented by the Strp string. */
|
|
|
|
/***********************************************************************/
|
|
|
|
int STRBLK::GetIntValue(int n)
|
|
|
|
{
|
|
|
|
bool m;
|
|
|
|
ulonglong val = CharToNumber(Strp[n], strlen(Strp[n]), INT_MAX32,
|
|
|
|
false, &m);
|
|
|
|
|
|
|
|
return (m && val < INT_MAX32) ? (int)(-(signed)val) : (int)val;
|
|
|
|
} // end of GetIntValue
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Get the unsigned integer value represented by the Strp string. */
|
|
|
|
/***********************************************************************/
|
|
|
|
uint STRBLK::GetUIntValue(int n)
|
|
|
|
{
|
|
|
|
return (uint)CharToNumber(Strp[n], strlen(Strp[n]), UINT_MAX32, true);
|
|
|
|
} // end of GetUintValue
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Get the big integer value represented by the Strp string. */
|
|
|
|
/***********************************************************************/
|
|
|
|
longlong STRBLK::GetBigintValue(int n)
|
|
|
|
{
|
|
|
|
bool m;
|
|
|
|
ulonglong val = CharToNumber(Strp[n], strlen(Strp[n]), INT_MAX64,
|
|
|
|
false, &m);
|
|
|
|
|
|
|
|
return (m && val < INT_MAX64) ? (-(signed)val) : (longlong)val;
|
|
|
|
} // end of GetBigintValue
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Get the unsigned big integer value represented by the Strp string. */
|
|
|
|
/***********************************************************************/
|
|
|
|
ulonglong STRBLK::GetUBigintValue(int n)
|
|
|
|
{
|
|
|
|
return CharToNumber(Strp[n], strlen(Strp[n]), ULONGLONG_MAX, true);
|
|
|
|
} // end of GetUBigintValue
|
|
|
|
|
|
|
|
/***********************************************************************/
|
2013-02-07 10:34:27 +01:00
|
|
|
/* Set one value in a block from a value in another block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void STRBLK::SetValue(PVBLK pv, int n1, int n2)
|
|
|
|
{
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
ChkTyp(pv);
|
2013-02-24 01:23:18 +01:00
|
|
|
Strp[n1] = (!pv->IsNull(n2)) ? ((STRBLK*)pv)->Strp[n2] : NULL;
|
2013-02-07 10:34:27 +01:00
|
|
|
} // end of SetValue
|
|
|
|
|
2013-02-24 01:23:18 +01:00
|
|
|
#if 0
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Set many values in a block from values in another block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void STRBLK::SetValues(PVBLK pv, int k, int n)
|
|
|
|
{
|
|
|
|
CheckType(pv)
|
|
|
|
PSZ *sp = ((STRBLK*)pv)->Strp;
|
|
|
|
|
|
|
|
for (register int i = k; i < n; i++)
|
2013-02-24 01:23:18 +01:00
|
|
|
Strp[i] = (!pv->IsNull(i)) ? sp[i] : NULL;
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
} // end of SetValues
|
2013-02-24 01:23:18 +01:00
|
|
|
#endif // 0
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Set one value in a block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void STRBLK::SetValue(PVAL valp, int n)
|
|
|
|
{
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
ChkIndx(n);
|
|
|
|
ChkTyp(valp);
|
2013-02-24 01:23:18 +01:00
|
|
|
|
|
|
|
if (!valp->IsNull())
|
|
|
|
SetValue((PSZ)valp->GetCharValue(), n);
|
|
|
|
else
|
|
|
|
Strp[n] = NULL;
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
} // end of SetValue
|
|
|
|
|
|
|
|
/***********************************************************************/
|
2013-04-29 13:50:20 +02:00
|
|
|
/* Set one value in a block from a zero terminated string. */
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
void STRBLK::SetValue(PSZ p, int n)
|
|
|
|
{
|
2013-04-29 13:50:20 +02:00
|
|
|
if (p) {
|
2013-12-16 01:32:47 +01:00
|
|
|
if (!Sorted || !n || !Strp[n-1] || strcmp(p, Strp[n-1])) {
|
|
|
|
Strp[n] = (PSZ)PlugSubAlloc(Global, NULL, strlen(p) + 1);
|
|
|
|
strcpy(Strp[n], p);
|
|
|
|
} else
|
|
|
|
Strp[n] = Strp[n-1];
|
|
|
|
|
2013-04-29 13:50:20 +02:00
|
|
|
} else
|
|
|
|
Strp[n] = NULL;
|
|
|
|
|
|
|
|
} // end of SetValue
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Set one value in a block from an array of characters. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void STRBLK::SetValue(char *sp, uint len, int n)
|
|
|
|
{
|
|
|
|
PSZ p;
|
|
|
|
|
|
|
|
if (sp) {
|
2013-12-16 01:32:47 +01:00
|
|
|
if (!Sorted || !n || !Strp[n-1] || strlen(Strp[n-1]) != len ||
|
|
|
|
strncmp(sp, Strp[n-1], len)) {
|
|
|
|
p = (PSZ)PlugSubAlloc(Global, NULL, len + 1);
|
|
|
|
memcpy(p, sp, len);
|
|
|
|
p[len] = 0;
|
|
|
|
} else
|
2013-12-16 17:40:42 +01:00
|
|
|
p = Strp[n-1];
|
2013-12-16 01:32:47 +01:00
|
|
|
|
2013-04-29 13:50:20 +02:00
|
|
|
} else
|
|
|
|
p = NULL;
|
|
|
|
|
|
|
|
Strp[n] = p;
|
2013-02-07 10:34:27 +01:00
|
|
|
} // end of SetValue
|
|
|
|
|
2014-03-10 12:21:17 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Set one value in a block if val is less than the current value. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void STRBLK::SetMin(PVAL valp, int n)
|
|
|
|
{
|
|
|
|
CheckParms(valp, n)
|
|
|
|
char *vp = valp->GetCharValue();
|
|
|
|
char *bp = Strp[n];
|
|
|
|
|
|
|
|
if (strcmp(vp, bp) < 0)
|
|
|
|
SetValue(valp, n);
|
|
|
|
|
|
|
|
} // end of SetMin
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Set one value in a block if val is greater than the current value. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void STRBLK::SetMax(PVAL valp, int n)
|
|
|
|
{
|
|
|
|
CheckParms(valp, n)
|
|
|
|
char *vp = valp->GetCharValue();
|
|
|
|
char *bp = Strp[n];
|
|
|
|
|
|
|
|
if (strcmp(vp, bp) > 0)
|
|
|
|
SetValue(valp, n);
|
|
|
|
|
|
|
|
} // end of SetMax
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Move one value from i to j. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void STRBLK::Move(int i, int j)
|
|
|
|
{
|
|
|
|
Strp[j] = Strp[i];
|
|
|
|
} // end of Move
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Compare a Value object with the nth value of the block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
int STRBLK::CompVal(PVAL vp, int n)
|
|
|
|
{
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
ChkIndx(n);
|
|
|
|
ChkTyp(vp);
|
2013-02-24 01:23:18 +01:00
|
|
|
|
|
|
|
if (vp->IsNull() || !Strp[n])
|
|
|
|
DBUG_ASSERT(false);
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
return strcmp(vp->GetCharValue(), Strp[n]);
|
|
|
|
} // end of CompVal
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Compare two values of the block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
int STRBLK::CompVal(int i1, int i2)
|
|
|
|
{
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
if (!Strp[i1] || !Strp[i2])
|
2013-02-24 01:23:18 +01:00
|
|
|
DBUG_ASSERT(false);
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
return (strcmp(Strp[i1], Strp[i2]));
|
|
|
|
} // end of CompVal
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Get a pointer on the nth value of the block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void *STRBLK::GetValPtr(int n)
|
|
|
|
{
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
ChkIndx(n);
|
2013-02-07 10:34:27 +01:00
|
|
|
return Strp + n;
|
|
|
|
} // end of GetValPtr
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Get a pointer on a zero ended string equal to nth value. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void *STRBLK::GetValPtrEx(int n)
|
|
|
|
{
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
ChkIndx(n);
|
2013-04-19 20:35:43 +02:00
|
|
|
return (Strp[n]) ? Strp[n] : const_cast<char*>("");
|
2013-02-07 10:34:27 +01:00
|
|
|
} // end of GetValPtrEx
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Returns index of matching value in block or -1. */
|
|
|
|
/***********************************************************************/
|
|
|
|
int STRBLK::Find(PVAL vp)
|
|
|
|
{
|
|
|
|
int i;
|
2013-02-24 01:23:18 +01:00
|
|
|
PSZ s;
|
- Rewrite some VALBLK classes as templates
- Correct typo initializing datm in DTVAL::MakeDate as {0,0,0,2,0,70,0,0,0}
instead of {0,0,0,1,0,70,0,0,0}
modified:
storage/connect/valblk.cpp
storage/connect/valblk.h
storage/connect/value.cpp
storage/connect/value.h
2013-03-01 22:23:40 +01:00
|
|
|
|
|
|
|
ChkTyp(vp);
|
2013-02-24 01:23:18 +01:00
|
|
|
|
|
|
|
if (vp->IsNull())
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
s = vp->GetCharValue();
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
for (i = 0; i < Nval; i++)
|
2013-02-24 01:23:18 +01:00
|
|
|
if (Strp[i] && !strcmp(s, Strp[i]))
|
2013-02-07 10:34:27 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
return (i < Nval) ? i : (-1);
|
|
|
|
} // end of Find
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Returns the length of the longest string in the block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
int STRBLK::GetMaxLength(void)
|
|
|
|
{
|
|
|
|
int i, n;
|
|
|
|
|
|
|
|
for (i = n = 0; i < Nval; i++)
|
2013-02-24 01:23:18 +01:00
|
|
|
if (Strp[i])
|
2014-04-21 12:57:10 +02:00
|
|
|
n = MY_MAX(n, (signed)strlen(Strp[i]));
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
return n;
|
|
|
|
} // end of GetMaxLength
|
|
|
|
|
2013-03-11 16:52:59 +01:00
|
|
|
/* -------------------------- Class DATBLK --------------------------- */
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Constructor. */
|
|
|
|
/***********************************************************************/
|
2013-03-11 16:52:59 +01:00
|
|
|
DATBLK::DATBLK(void *mp, int nval) : TYPBLK<int>(mp, nval, TYPE_INT)
|
2013-02-07 10:34:27 +01:00
|
|
|
{
|
2013-03-11 16:52:59 +01:00
|
|
|
Type = TYPE_DATE;
|
|
|
|
Dvalp = NULL;
|
|
|
|
} // end of DATBLK constructor
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
/***********************************************************************/
|
2013-03-11 16:52:59 +01:00
|
|
|
/* Set format so formatted dates can be converted on input. */
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
2013-03-11 16:52:59 +01:00
|
|
|
bool DATBLK::SetFormat(PGLOBAL g, PSZ fmt, int len, int year)
|
2013-02-07 10:34:27 +01:00
|
|
|
{
|
2013-12-28 15:46:49 +01:00
|
|
|
if (!(Dvalp = AllocateValue(g, TYPE_DATE, len, year, false, fmt)))
|
2013-03-11 16:52:59 +01:00
|
|
|
return true;
|
2013-02-07 10:34:27 +01:00
|
|
|
|
2013-03-11 16:52:59 +01:00
|
|
|
return false;
|
|
|
|
} // end of SetFormat
|
2013-02-07 10:34:27 +01:00
|
|
|
|
2014-02-03 16:14:13 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* DTVAL GetCharString: get string representation of a date value. */
|
|
|
|
/***********************************************************************/
|
|
|
|
char *DATBLK::GetCharString(char *p, int n)
|
|
|
|
{
|
|
|
|
char *vp;
|
|
|
|
|
|
|
|
if (Dvalp) {
|
|
|
|
Dvalp->SetValue(Typp[n]);
|
|
|
|
vp = Dvalp->GetCharString(p);
|
|
|
|
} else
|
|
|
|
vp = TYPBLK<int>::GetCharString(p, n);
|
|
|
|
|
|
|
|
return vp;
|
|
|
|
} // end of GetCharString
|
|
|
|
|
2013-02-24 01:23:18 +01:00
|
|
|
/***********************************************************************/
|
2013-03-11 16:52:59 +01:00
|
|
|
/* Set one value in a block from a char string. */
|
2013-02-24 01:23:18 +01:00
|
|
|
/***********************************************************************/
|
2013-03-11 16:52:59 +01:00
|
|
|
void DATBLK::SetValue(PSZ p, int n)
|
2013-02-24 01:23:18 +01:00
|
|
|
{
|
2013-03-11 16:52:59 +01:00
|
|
|
if (Dvalp) {
|
|
|
|
// Decode the string according to format
|
|
|
|
Dvalp->SetValue_psz(p);
|
|
|
|
Typp[n] = Dvalp->GetIntValue();
|
|
|
|
} else
|
|
|
|
TYPBLK<int>::SetValue(p, n);
|
2013-02-24 01:23:18 +01:00
|
|
|
|
|
|
|
} // end of SetValue
|
|
|
|
|
2014-03-10 12:21:17 +01:00
|
|
|
/* -------------------------- Class MBVALS --------------------------- */
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Allocate a value block according to type,len, and nb of values. */
|
|
|
|
/***********************************************************************/
|
|
|
|
PVBLK MBVALS::Allocate(PGLOBAL g, int type, int len, int prec,
|
|
|
|
int n, bool sub)
|
|
|
|
{
|
|
|
|
Mblk.Sub = sub;
|
|
|
|
Mblk.Size = n * GetTypeSize(type, len);
|
|
|
|
|
|
|
|
if (!PlgDBalloc(g, NULL, Mblk)) {
|
|
|
|
sprintf(g->Message, MSG(ALLOC_ERROR), "MBVALS::Allocate");
|
|
|
|
return NULL;
|
|
|
|
} else
|
|
|
|
Vblk = AllocValBlock(g, Mblk.Memp, type, n, len, prec,
|
|
|
|
TRUE, TRUE, FALSE);
|
|
|
|
|
|
|
|
return Vblk;
|
|
|
|
} // end of Allocate
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Reallocate the value block according to the new size. */
|
|
|
|
/***********************************************************************/
|
|
|
|
bool MBVALS::ReAllocate(PGLOBAL g, int n)
|
|
|
|
{
|
|
|
|
if (!PlgDBrealloc(g, NULL, Mblk, n * Vblk->GetVlen())) {
|
|
|
|
sprintf(g->Message, MSG(ALLOC_ERROR), "MBVALS::ReAllocate");
|
|
|
|
return TRUE;
|
|
|
|
} else
|
|
|
|
Vblk->ReAlloc(Mblk.Memp, n);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
} // end of ReAllocate
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Free the value block. */
|
|
|
|
/***********************************************************************/
|
|
|
|
void MBVALS::Free(void)
|
|
|
|
{
|
|
|
|
PlgDBfree(Mblk);
|
|
|
|
Vblk = NULL;
|
|
|
|
} // end of Free
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
/* ------------------------- End of Valblk --------------------------- */
|
|
|
|
|