mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
- Add support for unsigned numeric types
added: storage/connect/mysql-test/connect/r/unsigned.result storage/connect/mysql-test/connect/t/unsigned.test modified: storage/connect/colblk.cpp storage/connect/colblk.h storage/connect/connect.cc storage/connect/ha_connect.cc storage/connect/myconn.cpp storage/connect/mysql-test/connect/r/mysql_discovery.result storage/connect/mysql-test/connect/r/xml.result storage/connect/myutil.cpp storage/connect/myutil.h storage/connect/plgdbsem.h storage/connect/tabdos.cpp storage/connect/tabfix.cpp storage/connect/tabmysql.cpp storage/connect/tabutil.cpp storage/connect/valblk.cpp storage/connect/valblk.h storage/connect/value.cpp storage/connect/value.h storage/connect/xobject.cpp storage/connect/xobject.h
This commit is contained in:
@@ -41,6 +41,7 @@ COLBLK::COLBLK(PCOLDEF cdp, PTDB tdbp, int i)
|
||||
Buf_Type = cdp->Buf_Type;
|
||||
ColUse |= cdp->Flags; // Used by CONNECT
|
||||
Nullable = !!(cdp->Flags & U_NULLS);
|
||||
Unsigned = !!(cdp->Flags & U_UNSIGNED);
|
||||
} else {
|
||||
Name = NULL;
|
||||
memset(&Format, 0, sizeof(FORMAT));
|
||||
@@ -48,6 +49,7 @@ COLBLK::COLBLK(PCOLDEF cdp, PTDB tdbp, int i)
|
||||
Long = 0;
|
||||
Buf_Type = TYPE_ERROR;
|
||||
Nullable = false;
|
||||
Unsigned = false;
|
||||
} // endif cdp
|
||||
|
||||
To_Tdb = tdbp;
|
||||
@@ -171,9 +173,12 @@ bool COLBLK::InitValue(PGLOBAL g)
|
||||
if (Value)
|
||||
return false; // Already done
|
||||
|
||||
// Unsigned can be set only for valid value types
|
||||
int prec = (Unsigned) ? 1 : GetPrecision();
|
||||
|
||||
// Allocate a Value object
|
||||
if (!(Value = AllocateValue(g, Buf_Type, Format.Length,
|
||||
GetPrecision(), GetDomain())))
|
||||
prec, GetDomain())))
|
||||
return true;
|
||||
|
||||
AddStatus(BUF_READY);
|
||||
|
@@ -83,6 +83,7 @@ class DllExport COLBLK : public XOBJECT {
|
||||
PTDB To_Tdb; // Points to Table Descriptor Block
|
||||
PXCOL To_Kcol; // Points to Xindex matching column
|
||||
bool Nullable; // True if nullable
|
||||
bool Unsigned; // True if unsigned
|
||||
int Index; // Column number in table
|
||||
int Opt; // Cluster/sort information
|
||||
int Buf_Type; // Data type
|
||||
|
@@ -685,6 +685,7 @@ RCODE CntIndexRead(PGLOBAL g, PTDB ptdb, OPVAL op,
|
||||
char *kp= (char*)key;
|
||||
int n;
|
||||
short lg;
|
||||
bool rcb;
|
||||
RCODE rc;
|
||||
PVAL valp;
|
||||
PCOL colp;
|
||||
@@ -719,9 +720,20 @@ RCODE CntIndexRead(PGLOBAL g, PTDB ptdb, OPVAL op,
|
||||
if (colp->GetColUse(U_VAR)) {
|
||||
lg= *(short*)kp;
|
||||
kp+= sizeof(short);
|
||||
valp->SetValue_char(kp, (int)lg);
|
||||
rcb= valp->SetValue_char(kp, (int)lg);
|
||||
} else
|
||||
valp->SetValue_char(kp, valp->GetClen());
|
||||
rcb= valp->SetValue_char(kp, valp->GetClen());
|
||||
|
||||
if (rcb) {
|
||||
if (tdbp->RowNumber(g))
|
||||
sprintf(g->Message, "Out of range value for column %s at row %d",
|
||||
colp->GetName(), tdbp->RowNumber(g));
|
||||
else
|
||||
sprintf(g->Message, "Out of range value for column %s",
|
||||
colp->GetName());
|
||||
|
||||
PushWarning(g, tdbp);
|
||||
} // endif b
|
||||
|
||||
} else
|
||||
valp->SetBinValue((void*)kp);
|
||||
@@ -759,7 +771,7 @@ int CntIndexRange(PGLOBAL g, PTDB ptdb, const uchar* *key, uint *len,
|
||||
const uchar *p, *kp;
|
||||
int i, n, k[2];
|
||||
short lg;
|
||||
bool b;
|
||||
bool b, rcb;
|
||||
PVAL valp;
|
||||
PCOL colp;
|
||||
PTDBDOX tdbp;
|
||||
@@ -802,9 +814,21 @@ int CntIndexRange(PGLOBAL g, PTDB ptdb, const uchar* *key, uint *len,
|
||||
if (colp->GetColUse(U_VAR)) {
|
||||
lg= *(short*)p;
|
||||
p+= sizeof(short);
|
||||
valp->SetValue_char((char*)p, (int)lg);
|
||||
rcb= valp->SetValue_char((char*)p, (int)lg);
|
||||
} else
|
||||
valp->SetValue_char((char*)p, valp->GetClen());
|
||||
rcb= valp->SetValue_char((char*)p, valp->GetClen());
|
||||
|
||||
if (rcb) {
|
||||
if (tdbp->RowNumber(g))
|
||||
sprintf(g->Message,
|
||||
"Out of range value for column %s at row %d",
|
||||
colp->GetName(), tdbp->RowNumber(g));
|
||||
else
|
||||
sprintf(g->Message, "Out of range value for column %s",
|
||||
colp->GetName());
|
||||
|
||||
PushWarning(g, tdbp);
|
||||
} // endif b
|
||||
|
||||
} else
|
||||
valp->SetBinValue((void*)p);
|
||||
|
@@ -165,7 +165,7 @@ extern "C" char nmfile[];
|
||||
extern "C" char pdebug[];
|
||||
|
||||
extern "C" {
|
||||
char version[]= "Version 1.01.0009 October 29, 2013";
|
||||
char version[]= "Version 1.01.0010 November 30, 2013";
|
||||
|
||||
#if defined(XMSG)
|
||||
char msglang[]; // Default message language
|
||||
@@ -777,7 +777,7 @@ int ha_connect::GetIntegerOption(char *opname)
|
||||
|
||||
if (opval == (ulonglong)NO_IVAL && options && options->oplist)
|
||||
if ((pv= GetListOption(xp->g, opname, options->oplist)))
|
||||
opval= (unsigned)atoll(pv);
|
||||
opval= CharToNumber(pv, strlen(pv), ULONGLONG_MAX, true);
|
||||
|
||||
return (int)opval;
|
||||
} // end of GetIntegerOption
|
||||
@@ -936,6 +936,12 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf)
|
||||
break;
|
||||
} // endswitch type
|
||||
|
||||
if (fp->flags & UNSIGNED_FLAG)
|
||||
pcf->Flags |= U_UNSIGNED;
|
||||
|
||||
if (fp->flags & ZEROFILL_FLAG)
|
||||
pcf->Flags |= U_ZEROFILL;
|
||||
|
||||
// This is used to skip null bit
|
||||
if (fp->real_maybe_null())
|
||||
pcf->Flags |= U_NULLS;
|
||||
@@ -1341,7 +1347,15 @@ int ha_connect::MakeRecord(char *buf)
|
||||
|
||||
} else
|
||||
if (fp->store(value->GetFloatValue())) {
|
||||
rc= HA_ERR_WRONG_IN_RECORD;
|
||||
// rc= HA_ERR_WRONG_IN_RECORD; a Warning was ignored
|
||||
char buf[128];
|
||||
THD *thd= ha_thd();
|
||||
|
||||
sprintf(buf, "Out of range value for column '%s' at row %ld",
|
||||
fp->field_name,
|
||||
thd->get_stmt_da()->current_row_for_warning());
|
||||
|
||||
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, buf);
|
||||
DBUG_PRINT("MakeRecord", ("%s", value->GetCharString(val)));
|
||||
} // endif store
|
||||
|
||||
@@ -3511,7 +3525,7 @@ static bool add_fields(PGLOBAL g,
|
||||
#else // !NEW_WAY
|
||||
static bool add_field(String *sql, const char *field_name, int typ,
|
||||
int len, int dec, uint tm, const char *rem,
|
||||
int flag, bool dbf, char v)
|
||||
char *dft, int flag, bool dbf, char v)
|
||||
{
|
||||
char var = (len > 255) ? 'V' : v;
|
||||
bool error= false;
|
||||
@@ -3535,9 +3549,26 @@ static bool add_field(String *sql, const char *field_name, int typ,
|
||||
error|= sql->append(')');
|
||||
} // endif len
|
||||
|
||||
if (v == 'U')
|
||||
error|= sql->append(" UNSIGNED");
|
||||
else if (v == 'Z')
|
||||
error|= sql->append(" ZEROFILL");
|
||||
|
||||
if (tm)
|
||||
error|= sql->append(STRING_WITH_LEN(" NOT NULL"), system_charset_info);
|
||||
|
||||
if (dft && *dft) {
|
||||
error|= sql->append(" DEFAULT ");
|
||||
|
||||
if (IsTypeChar(typ)) {
|
||||
error|= sql->append("'");
|
||||
error|= sql->append_for_single_quote(dft, strlen(dft));
|
||||
error|= sql->append("'");
|
||||
} else
|
||||
error|= sql->append(dft);
|
||||
|
||||
} // endif rem
|
||||
|
||||
if (rem && *rem) {
|
||||
error|= sql->append(" COMMENT '");
|
||||
error|= sql->append_for_single_quote(rem, strlen(rem));
|
||||
@@ -4044,8 +4075,8 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
|
||||
} // endif src
|
||||
|
||||
if (ok) {
|
||||
char *cnm, *rem;
|
||||
int i, len, dec, typ, flg;
|
||||
char *cnm, *rem, *dft;
|
||||
int i, len, prec, dec, typ, flg;
|
||||
PDBUSER dup= PlgGetUser(g);
|
||||
PCATLG cat= (dup) ? dup->Catalog : NULL;
|
||||
|
||||
@@ -4154,16 +4185,17 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
|
||||
NOT_NULL_FLAG, "", flg, dbf);
|
||||
#else // !NEW_WAY
|
||||
// Now add the field
|
||||
if (add_field(&sql, cnm, typ, len, dec, NOT_NULL_FLAG, 0, flg, dbf, 0))
|
||||
if (add_field(&sql, cnm, typ, len, dec, NOT_NULL_FLAG, 0, NULL, flg, dbf, 0))
|
||||
rc= HA_ERR_OUT_OF_MEM;
|
||||
#endif // !NEW_WAY
|
||||
} // endfor crp
|
||||
|
||||
} else // Not a catalog table
|
||||
for (i= 0; !rc && i < qrp->Nblin; i++) {
|
||||
typ= len= dec= 0;
|
||||
typ= len= prec= dec= 0;
|
||||
tm= NOT_NULL_FLAG;
|
||||
cnm= (char*)"noname";
|
||||
dft= NULL;
|
||||
#if defined(NEW_WAY)
|
||||
rem= "";
|
||||
// cs= NULL;
|
||||
@@ -4181,6 +4213,10 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
|
||||
v = (crp->Nulls) ? crp->Nulls[i] : 0;
|
||||
break;
|
||||
case FLD_PREC:
|
||||
// PREC must be always before LENGTH
|
||||
len= prec= crp->Kdata->GetIntValue(i);
|
||||
break;
|
||||
case FLD_LENGTH:
|
||||
len= crp->Kdata->GetIntValue(i);
|
||||
break;
|
||||
case FLD_SCALE:
|
||||
@@ -4200,6 +4236,9 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
|
||||
// cs= get_charset_by_name(csn, 0);
|
||||
|
||||
// break;
|
||||
case FLD_DEFAULT:
|
||||
dft= crp->Kdata->GetCharValue(i);
|
||||
break;
|
||||
default:
|
||||
break; // Ignore
|
||||
} // endswitch Fld
|
||||
@@ -4209,16 +4248,16 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
|
||||
int plgtyp;
|
||||
|
||||
// typ must be PLG type, not SQL type
|
||||
if (!(plgtyp= TranslateSQLType(typ, dec, len, v))) {
|
||||
if (!(plgtyp= TranslateSQLType(typ, dec, prec, v))) {
|
||||
sprintf(g->Message, "Unsupported SQL type %d", typ);
|
||||
my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0));
|
||||
return HA_ERR_INTERNAL_ERROR;
|
||||
} else
|
||||
typ= plgtyp;
|
||||
|
||||
// Some data sources do not count dec in length
|
||||
// Some data sources do not count dec in length (prec)
|
||||
if (typ == TYPE_FLOAT)
|
||||
len += (dec + 2); // To be safe
|
||||
prec += (dec + 2); // To be safe
|
||||
else
|
||||
dec= 0;
|
||||
|
||||
@@ -4227,14 +4266,16 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
|
||||
|
||||
// Make the arguments as required by add_fields
|
||||
if (typ == TYPE_DATE)
|
||||
len= 0;
|
||||
prec= 0;
|
||||
else if (typ == TYPE_FLOAT)
|
||||
prec= len;
|
||||
|
||||
// Now add the field
|
||||
#if defined(NEW_WAY)
|
||||
rc= add_fields(g, thd, &alter_info, cnm, typ, len, dec,
|
||||
tm, rem, 0, true);
|
||||
#else // !NEW_WAY
|
||||
if (add_field(&sql, cnm, typ, len, dec, tm, rem, 0, dbf, v))
|
||||
if (add_field(&sql, cnm, typ, prec, dec, tm, rem, dft, 0, dbf, v))
|
||||
rc= HA_ERR_OUT_OF_MEM;
|
||||
#endif // !NEW_WAY
|
||||
} // endfor i
|
||||
|
@@ -46,21 +46,6 @@
|
||||
#define DLL_EXPORT // Items are exported from this DLL
|
||||
#include "myconn.h"
|
||||
|
||||
#if defined(EMBEDDED)
|
||||
static char *server_args[] = {
|
||||
"this_program", /* this string is not used */
|
||||
"--skip-bdb",
|
||||
"--skip-innodb"
|
||||
};
|
||||
|
||||
static char *server_groups[] = {
|
||||
"PlugDB_SERVER",
|
||||
"embedded",
|
||||
"server",
|
||||
(char *)NULL
|
||||
};
|
||||
#endif // EMBEDDED
|
||||
|
||||
extern "C" int trace;
|
||||
extern MYSQL_PLUGIN_IMPORT uint mysqld_port;
|
||||
|
||||
@@ -82,12 +67,12 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db,
|
||||
{
|
||||
static int buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT,
|
||||
TYPE_STRING, TYPE_SHORT, TYPE_SHORT, TYPE_SHORT,
|
||||
TYPE_STRING, TYPE_STRING, TYPE_STRING};
|
||||
TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING};
|
||||
static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_PREC,
|
||||
FLD_KEY, FLD_SCALE, FLD_RADIX, FLD_NULL,
|
||||
FLD_REM, FLD_NO, FLD_CHARSET};
|
||||
static unsigned int length[] = {0, 4, 16, 4, 4, 4, 4, 4, 256, 32, 32};
|
||||
char *fld, *fmt, v, cmd[128];
|
||||
FLD_REM, FLD_NO, FLD_DEFAULT, FLD_CHARSET};
|
||||
static unsigned int length[] = {0, 4, 16, 4, 4, 4, 4, 4, 0, 32, 0, 32};
|
||||
char *fld, *fmt, v, cmd[128], uns[16], zero[16];
|
||||
int i, n, nf, ncol = sizeof(buftyp) / sizeof(int);
|
||||
int len, type, prec, rc, k = 0;
|
||||
PQRYRES qrp;
|
||||
@@ -122,9 +107,10 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db,
|
||||
} // endif n
|
||||
|
||||
/********************************************************************/
|
||||
/* Get the size of the name columns. */
|
||||
/* Get the size of the name and default columns. */
|
||||
/********************************************************************/
|
||||
length[0] = myc.GetFieldLength(0);
|
||||
length[10] = myc.GetFieldLength(5);
|
||||
} else {
|
||||
n = 0;
|
||||
length[0] = 128;
|
||||
@@ -164,18 +150,29 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db,
|
||||
crp = qrp->Colresp; // Column_Name
|
||||
crp->Kdata->SetValue(fld, i);
|
||||
|
||||
// Get type, type name, and precision
|
||||
// Get type, type name, precision, unsigned and zerofill
|
||||
fld = myc.GetCharField(1);
|
||||
prec = 0;
|
||||
len = 0;
|
||||
v = 0;
|
||||
*uns = 0;
|
||||
*zero = 0;
|
||||
|
||||
if ((nf = sscanf(fld, "%[^(](%d,%d", cmd, &len, &prec)) < 1) {
|
||||
sprintf(g->Message, MSG(BAD_FIELD_TYPE), fld);
|
||||
myc.Close();
|
||||
return NULL;
|
||||
} else
|
||||
qrp->Nblin++;
|
||||
switch ((nf = sscanf(fld, "%[^(](%d,%d", cmd, &len, &prec))) {
|
||||
case 3:
|
||||
nf = sscanf(fld, "%[^(](%d,%d) %s %s", cmd, &len, &prec, uns, zero);
|
||||
break;
|
||||
case 2:
|
||||
nf = sscanf(fld, "%[^(](%d) %s %s", cmd, &len, uns, zero) + 1;
|
||||
break;
|
||||
case 1:
|
||||
nf = sscanf(fld, "%s %s %s", cmd, uns, zero) + 2;
|
||||
break;
|
||||
default:
|
||||
sprintf(g->Message, MSG(BAD_FIELD_TYPE), fld);
|
||||
myc.Close();
|
||||
return NULL;
|
||||
} // endswitch nf
|
||||
|
||||
if ((type = MYSQLtoPLG(cmd, &v)) == TYPE_ERROR) {
|
||||
sprintf(g->Message, "Unsupported column type %s", cmd);
|
||||
@@ -184,9 +181,16 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db,
|
||||
} else if (type == TYPE_STRING)
|
||||
len = min(len, 4096);
|
||||
|
||||
qrp->Nblin++;
|
||||
crp = crp->Next; // Data_Type
|
||||
crp->Kdata->SetValue(type, i);
|
||||
crp->Nulls[i] = v;
|
||||
|
||||
switch (nf) {
|
||||
case 5: crp->Nulls[i] = 'Z'; break;
|
||||
case 4: crp->Nulls[i] = 'U'; break;
|
||||
default: crp->Nulls[i] = v; break;
|
||||
} // endswitch nf
|
||||
|
||||
crp = crp->Next; // Type_Name
|
||||
crp->Kdata->SetValue(cmd, i);
|
||||
|
||||
@@ -200,7 +204,7 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db,
|
||||
crp = crp->Next; // Precision
|
||||
crp->Kdata->SetValue(len, i);
|
||||
|
||||
crp = crp->Next; // was Length
|
||||
crp = crp->Next; // key (was Length)
|
||||
fld = myc.GetCharField(4);
|
||||
crp->Kdata->SetValue(fld, i);
|
||||
|
||||
@@ -218,9 +222,13 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db,
|
||||
fld = myc.GetCharField(8);
|
||||
crp->Kdata->SetValue(fld, i);
|
||||
|
||||
crp = crp->Next; // New
|
||||
crp = crp->Next; // Date format
|
||||
crp->Kdata->SetValue((fmt) ? fmt : (char*) "", i);
|
||||
|
||||
crp = crp->Next; // New (default)
|
||||
fld = myc.GetCharField(5);
|
||||
crp->Kdata->SetValue(fld, i);
|
||||
|
||||
crp = crp->Next; // New (charset)
|
||||
fld = myc.GetCharField(2);
|
||||
crp->Kdata->SetValue(fld, i);
|
||||
@@ -657,6 +665,7 @@ PQRYRES MYSQLC::GetResult(PGLOBAL g, bool pdb)
|
||||
{
|
||||
char *fmt;
|
||||
int n;
|
||||
bool uns;
|
||||
PCOLRES *pcrp, crp;
|
||||
PQRYRES qrp;
|
||||
MYSQL_FIELD *fld;
|
||||
@@ -707,9 +716,10 @@ PQRYRES MYSQLC::GetResult(PGLOBAL g, bool pdb)
|
||||
crp->Prec = (crp->Type == TYPE_FLOAT) ? fld->decimals : 0;
|
||||
crp->Length = fld->max_length;
|
||||
crp->Clen = GetTypeSize(crp->Type, crp->Length);
|
||||
uns = (fld->flags & (UNSIGNED_FLAG | ZEROFILL_FLAG)) ? true : false;
|
||||
|
||||
if (!(crp->Kdata = AllocValBlock(g, NULL, crp->Type, m_Rows,
|
||||
crp->Clen, 0, FALSE, TRUE, FALSE))) {
|
||||
crp->Clen, 0, FALSE, TRUE, uns))) {
|
||||
sprintf(g->Message, MSG(INV_RESULT_TYPE),
|
||||
GetFormatType(crp->Type));
|
||||
return NULL;
|
||||
|
@@ -15,7 +15,7 @@ t1 CREATE TABLE `t1` (
|
||||
`id` int(20) NOT NULL,
|
||||
`group` int(11) NOT NULL,
|
||||
`a\\b` int(11) NOT NULL,
|
||||
`a\\` int(10) DEFAULT NULL,
|
||||
`a\\` int(10) unsigned DEFAULT NULL,
|
||||
`name` varchar(32) DEFAULT NULL
|
||||
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/test/t1' `TABLE_TYPE`='MYSQL'
|
||||
INSERT INTO t1 (id, name) VALUES (1, 'foo');
|
||||
|
73
storage/connect/mysql-test/connect/r/unsigned.result
Normal file
73
storage/connect/mysql-test/connect/r/unsigned.result
Normal file
@@ -0,0 +1,73 @@
|
||||
#
|
||||
# Testing unsigned types
|
||||
#
|
||||
DROP TABLE IF EXISTS t1;
|
||||
Warnings:
|
||||
Note 1051 Unknown table 'test.t1'
|
||||
CREATE TABLE t1 (
|
||||
a TINYINT UNSIGNED NOT NULL,
|
||||
b SMALLINT ZEROFILL NOT NULL,
|
||||
c INT UNSIGNED NOT NULL,
|
||||
d BIGINT UNSIGNED NOT NULL,
|
||||
e CHAR(32) NOT NULL DEFAULT '???') ENGINE=CONNECT TABLE_TYPE=FIX;
|
||||
Warnings:
|
||||
Warning 1105 No file name. Table will use t1.fix
|
||||
DESCRIBE t1;
|
||||
Field Type Null Key Default Extra
|
||||
a tinyint(3) unsigned NO NULL
|
||||
b smallint(5) unsigned zerofill NO NULL
|
||||
c int(10) unsigned NO NULL
|
||||
d bigint(20) unsigned NO NULL
|
||||
e char(32) NO ???
|
||||
INSERT INTO t1(a,b,c,d) VALUES(255,65535,4294967295,18446744073709551615);
|
||||
SELECT * FROM t1;
|
||||
a b c d e
|
||||
255 65535 4294967295 18446744073709551615 ???
|
||||
UPDATE t1 SET e = d;
|
||||
SELECT * FROM t1;
|
||||
a b c d e
|
||||
255 65535 4294967295 18446744073709551615 18446744073709551615
|
||||
UPDATE t1 SET c = d;
|
||||
Warnings:
|
||||
Warning 1264 Out of range value for column 'c' at row 1
|
||||
SELECT * FROM t1;
|
||||
a b c d e
|
||||
255 65535 4294967295 18446744073709551615 18446744073709551615
|
||||
UPDATE t1 SET c = e;
|
||||
Warnings:
|
||||
Warning 1264 Out of range value for column 'c' at row 1
|
||||
SELECT * FROM t1;
|
||||
a b c d e
|
||||
255 65535 4294967295 18446744073709551615 18446744073709551615
|
||||
UPDATE t1 SET d = e;
|
||||
SELECT * FROM t1;
|
||||
a b c d e
|
||||
255 65535 4294967295 18446744073709551615 18446744073709551615
|
||||
DROP TABLE IF EXISTS t2;
|
||||
Warnings:
|
||||
Note 1051 Unknown table 'test.t2'
|
||||
CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=PROXY TABNAME=t1;
|
||||
DESCRIBE t2;
|
||||
Field Type Null Key Default Extra
|
||||
a tinyint(3) unsigned NO NULL
|
||||
b smallint(5) unsigned zerofill NO NULL
|
||||
c int(10) unsigned NO NULL
|
||||
d bigint(20) unsigned NO NULL
|
||||
e char(32) NO NULL
|
||||
SELECT * FROM t2;
|
||||
a b c d e
|
||||
255 65535 4294967295 18446744073709551615 18446744073709551615
|
||||
DROP TABLE t2;
|
||||
CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL TABNAME=t1;
|
||||
DESCRIBE t2;
|
||||
Field Type Null Key Default Extra
|
||||
a tinyint(3) unsigned NO NULL
|
||||
b smallint(5) unsigned zerofill NO NULL
|
||||
c int(10) unsigned NO NULL
|
||||
d bigint(20) unsigned NO NULL
|
||||
e char(32) NO ???
|
||||
SELECT * FROM t2;
|
||||
a b c d e
|
||||
255 65535 4294967295 18446744073709551615 18446744073709551615
|
||||
DROP TABLE t2;
|
||||
DROP TABLE t1;
|
@@ -413,7 +413,7 @@ DROP TABLE t1;
|
||||
SET @a=LOAD_FILE('MYSQLD_DATADIR/test/t1.xml');
|
||||
SELECT CAST(@a AS CHAR CHARACTER SET latin1);
|
||||
CAST(@a AS CHAR CHARACTER SET latin1) <?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- Created by CONNECT Version 1.01.0009 October 29, 2013 -->
|
||||
<!-- Created by CONNECT Version 1.01.0010 November 30, 2013 -->
|
||||
<t1>
|
||||
<line>
|
||||
<node>ÀÁÂÃ</node>
|
||||
|
34
storage/connect/mysql-test/connect/t/unsigned.test
Normal file
34
storage/connect/mysql-test/connect/t/unsigned.test
Normal file
@@ -0,0 +1,34 @@
|
||||
--echo #
|
||||
--echo # Testing unsigned types
|
||||
--echo #
|
||||
DROP TABLE IF EXISTS t1;
|
||||
CREATE TABLE t1 (
|
||||
a TINYINT UNSIGNED NOT NULL,
|
||||
b SMALLINT ZEROFILL NOT NULL,
|
||||
c INT UNSIGNED NOT NULL,
|
||||
d BIGINT UNSIGNED NOT NULL,
|
||||
e CHAR(32) NOT NULL DEFAULT '???') ENGINE=CONNECT TABLE_TYPE=FIX;
|
||||
DESCRIBE t1;
|
||||
INSERT INTO t1(a,b,c,d) VALUES(255,65535,4294967295,18446744073709551615);
|
||||
SELECT * FROM t1;
|
||||
UPDATE t1 SET e = d;
|
||||
SELECT * FROM t1;
|
||||
UPDATE t1 SET c = d;
|
||||
SELECT * FROM t1;
|
||||
UPDATE t1 SET c = e;
|
||||
SELECT * FROM t1;
|
||||
UPDATE t1 SET d = e;
|
||||
SELECT * FROM t1;
|
||||
|
||||
DROP TABLE IF EXISTS t2;
|
||||
CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=PROXY TABNAME=t1;
|
||||
DESCRIBE t2;
|
||||
SELECT * FROM t2;
|
||||
|
||||
DROP TABLE t2;
|
||||
CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL TABNAME=t1;
|
||||
DESCRIBE t2;
|
||||
SELECT * FROM t2;
|
||||
|
||||
DROP TABLE t2;
|
||||
DROP TABLE t1;
|
@@ -143,7 +143,7 @@ const char *PLGtoMYSQLtype(int type, bool dbf, char v)
|
||||
/************************************************************************/
|
||||
/* Convert from MySQL type to PlugDB type number */
|
||||
/************************************************************************/
|
||||
int MYSQLtoPLG(int mytype)
|
||||
int MYSQLtoPLG(int mytype, char *var)
|
||||
{
|
||||
int type;
|
||||
|
||||
@@ -177,7 +177,6 @@ int MYSQLtoPLG(int mytype)
|
||||
case MYSQL_TYPE_TIME:
|
||||
type = TYPE_DATE;
|
||||
break;
|
||||
case MYSQL_TYPE_STRING:
|
||||
case MYSQL_TYPE_VAR_STRING:
|
||||
#if !defined(ALPHA)
|
||||
case MYSQL_TYPE_VARCHAR:
|
||||
@@ -186,6 +185,8 @@ int MYSQLtoPLG(int mytype)
|
||||
case MYSQL_TYPE_TINY_BLOB:
|
||||
case MYSQL_TYPE_MEDIUM_BLOB:
|
||||
case MYSQL_TYPE_LONG_BLOB:
|
||||
if (var) *var = 'V';
|
||||
case MYSQL_TYPE_STRING:
|
||||
type = TYPE_STRING;
|
||||
break;
|
||||
default:
|
||||
|
@@ -7,7 +7,7 @@
|
||||
enum enum_field_types PLGtoMYSQL(int type, bool dbf);
|
||||
const char *PLGtoMYSQLtype(int type, bool dbf, char var = NULL);
|
||||
int MYSQLtoPLG(char *typname, char *var = NULL);
|
||||
int MYSQLtoPLG(int mytype);
|
||||
int MYSQLtoPLG(int mytype, char *var = NULL);
|
||||
char *MyDateFmt(int mytype);
|
||||
char *MyDateFmt(char *typname);
|
||||
|
||||
|
@@ -330,7 +330,9 @@ enum COLUSE {U_P = 0x01, /* the projection list. */
|
||||
U_VIRTUAL = 0x20, /* a VIRTUAL column */
|
||||
U_NULLS = 0x40, /* The column may have nulls */
|
||||
U_IS_NULL = 0x80, /* The column has a null value */
|
||||
U_SPECIAL = 0x100}; /* The column is special */
|
||||
U_SPECIAL = 0x100, /* The column is special */
|
||||
U_UNSIGNED = 0x200, /* The column type is unsigned */
|
||||
U_ZEROFILL = 0x400}; /* The column is zero filled */
|
||||
|
||||
/***********************************************************************/
|
||||
/* DB description class and block pointer definitions. */
|
||||
|
@@ -1087,7 +1087,12 @@ void DOSCOL::ReadColumn(PGLOBAL g)
|
||||
case TYPE_SHORT:
|
||||
case TYPE_TINY:
|
||||
case TYPE_BIGINT:
|
||||
Value->SetValue_char(p, field - Dcm);
|
||||
if (Value->SetValue_char(p, field - Dcm)) {
|
||||
sprintf(g->Message, "Out of range value for column %s at row %d",
|
||||
Name, tdbp->RowNumber(g));
|
||||
PushWarning(g, tdbp);
|
||||
} // endif SetValue_char
|
||||
|
||||
break;
|
||||
case TYPE_FLOAT:
|
||||
Value->SetValue_char(p, field);
|
||||
@@ -1104,7 +1109,11 @@ void DOSCOL::ReadColumn(PGLOBAL g)
|
||||
} // endswitch Buf_Type
|
||||
|
||||
else
|
||||
Value->SetValue_char(p, field);
|
||||
if (Value->SetValue_char(p, field)) {
|
||||
sprintf(g->Message, "Out of range value for column %s at row %d",
|
||||
Name, tdbp->RowNumber(g));
|
||||
PushWarning(g, tdbp);
|
||||
} // endif SetValue_char
|
||||
|
||||
break;
|
||||
default:
|
||||
|
@@ -375,7 +375,12 @@ void BINCOL::ReadColumn(PGLOBAL g)
|
||||
Value->SetValue(*(double*)p);
|
||||
break;
|
||||
case 'C': // Text
|
||||
Value->SetValue_char(p, Long);
|
||||
if (Value->SetValue_char(p, Long)) {
|
||||
sprintf(g->Message, "Out of range value for column %s at row %d",
|
||||
Name, tdbp->RowNumber(g));
|
||||
PushWarning(g, tdbp);
|
||||
} // endif SetValue_char
|
||||
|
||||
break;
|
||||
default:
|
||||
sprintf(g->Message, MSG(BAD_BIN_FMT), Fmt, Name);
|
||||
|
@@ -1284,13 +1284,18 @@ void MYSQLCOL::ReadColumn(PGLOBAL g)
|
||||
htrc("MySQL ReadColumn: name=%s buf=%s\n", Name, buf);
|
||||
|
||||
// TODO: have a true way to differenciate temporal values
|
||||
if (strlen(buf) == 8)
|
||||
if (Buf_Type == TYPE_DATE && strlen(buf) == 8)
|
||||
// This is a TIME value
|
||||
p = strcat(strcpy(tim, "1970-01-01 "), buf);
|
||||
else
|
||||
p = buf;
|
||||
|
||||
Value->SetValue_char(p, strlen(p));
|
||||
if (Value->SetValue_char(p, strlen(p))) {
|
||||
sprintf(g->Message, "Out of range value for column %s at row %d",
|
||||
Name, tdbp->RowNumber(g));
|
||||
PushWarning(g, tdbp);
|
||||
} // endif SetValue_char
|
||||
|
||||
} else {
|
||||
if (Nullable)
|
||||
Value->SetNull(true);
|
||||
|
@@ -117,7 +117,7 @@ TABLE_SHARE *GetTableShare(PGLOBAL g, THD *thd, const char *db,
|
||||
|
||||
/************************************************************************/
|
||||
/* TabColumns: constructs the result blocks containing all the columns */
|
||||
/* of the object table that will be retrieved by GetData commands. */
|
||||
/* description of the object table that will be retrieved by discovery.*/
|
||||
/************************************************************************/
|
||||
PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
|
||||
const char *name, bool& info)
|
||||
@@ -128,8 +128,8 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
|
||||
static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_PREC,
|
||||
FLD_LENGTH, FLD_SCALE, FLD_RADIX, FLD_NULL,
|
||||
FLD_REM, FLD_NO, FLD_CHARSET};
|
||||
static unsigned int length[] = {0, 4, 16, 4, 4, 4, 4, 4, 256, 32, 32};
|
||||
char *fld, *fmt;
|
||||
static unsigned int length[] = {0, 4, 16, 4, 4, 4, 4, 4, 0, 32, 32};
|
||||
char *fld, *fmt, v;
|
||||
int i, n, ncol = sizeof(buftyp) / sizeof(int);
|
||||
int len, type, prec;
|
||||
bool mysql;
|
||||
@@ -164,6 +164,7 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
|
||||
// Some columns must be renamed
|
||||
for (i = 0, crp = qrp->Colresp; crp; crp = crp->Next)
|
||||
switch (++i) {
|
||||
case 2: crp->Nulls = (char*)PlugSubAlloc(g, NULL, n); break;
|
||||
case 10: crp->Name = "Date_fmt"; break;
|
||||
case 11: crp->Name = "Collation"; break;
|
||||
} // endswitch i
|
||||
@@ -181,8 +182,9 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
|
||||
crp = qrp->Colresp; // Column_Name
|
||||
fld = (char *)fp->field_name;
|
||||
crp->Kdata->SetValue(fld, i);
|
||||
v = 0;
|
||||
|
||||
if ((type = MYSQLtoPLG(fp->type())) == TYPE_ERROR) {
|
||||
if ((type = MYSQLtoPLG(fp->type(), &v)) == TYPE_ERROR) {
|
||||
sprintf(g->Message, "Unsupported column type %s", GetTypeName(type));
|
||||
qrp = NULL;
|
||||
break;
|
||||
@@ -190,6 +192,14 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
|
||||
|
||||
crp = crp->Next; // Data_Type
|
||||
crp->Kdata->SetValue(type, i);
|
||||
|
||||
if (fp->flags & ZEROFILL_FLAG)
|
||||
crp->Nulls[i] = 'Z';
|
||||
else if (fp->flags & UNSIGNED_FLAG)
|
||||
crp->Nulls[i] = 'U';
|
||||
else
|
||||
crp->Nulls[i] = v;
|
||||
|
||||
crp = crp->Next; // Type_Name
|
||||
crp->Kdata->SetValue(GetTypeName(type), i);
|
||||
|
||||
@@ -200,7 +210,7 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
|
||||
len = strlen(fmt);
|
||||
} else {
|
||||
fmt = (char*)fp->option_struct->dateformat;
|
||||
len = fp->field_length;
|
||||
fp->field_length;
|
||||
} // endif mysql
|
||||
|
||||
} else {
|
||||
@@ -212,10 +222,10 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
|
||||
crp->Kdata->SetValue(len, i);
|
||||
|
||||
crp = crp->Next; // Length
|
||||
len = fp->field_length;
|
||||
prec = (type == TYPE_FLOAT) ? fp->decimals() : 0;
|
||||
len = (prec == 31) ? 0 : fp->field_length;
|
||||
crp->Kdata->SetValue(len, i);
|
||||
|
||||
prec = (type == TYPE_FLOAT) ? fp->decimals() : 0;
|
||||
crp = crp->Next; // Scale
|
||||
crp->Kdata->SetValue(prec, i);
|
||||
|
||||
@@ -233,7 +243,7 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
|
||||
else
|
||||
crp->Kdata->Reset(i);
|
||||
|
||||
crp = crp->Next; // New
|
||||
crp = crp->Next; // New (date format)
|
||||
crp->Kdata->SetValue((fmt) ? fmt : (char*) "", i);
|
||||
|
||||
crp = crp->Next; // New (charset)
|
||||
|
@@ -191,7 +191,7 @@ void VALBLK::ChkIndx(int n)
|
||||
|
||||
void VALBLK::ChkTyp(PVAL v)
|
||||
{
|
||||
if (Check && Type != v->GetType()) {
|
||||
if (Check && (Type != v->GetType() || Unsigned != v->IsUnsigned())) {
|
||||
PGLOBAL& g = Global;
|
||||
strcpy(g->Message, MSG(VALTYPE_NOMATCH));
|
||||
longjmp(g->jumper[g->jump_level], Type);
|
||||
@@ -201,7 +201,7 @@ void VALBLK::ChkTyp(PVAL v)
|
||||
|
||||
void VALBLK::ChkTyp(PVBLK vb)
|
||||
{
|
||||
if (Check && Type != vb->GetType()) {
|
||||
if (Check && (Type != vb->GetType() || Unsigned != vb->IsUnsigned())) {
|
||||
PGLOBAL& g = Global;
|
||||
strcpy(g->Message, MSG(VALTYPE_NOMATCH));
|
||||
longjmp(g->jumper[g->jump_level], Type);
|
||||
@@ -304,28 +304,44 @@ void TYPBLK<TYPE>::SetValue(PSZ p, int n)
|
||||
longjmp(g->jumper[g->jump_level], Type);
|
||||
} // endif Check
|
||||
|
||||
Typp[n] = GetTypedValue(p);
|
||||
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;
|
||||
|
||||
SetNull(n, false);
|
||||
} // end of SetValue
|
||||
|
||||
template <class TYPE>
|
||||
ulonglong TYPBLK<TYPE>::MaxVal(void) {DBUG_ASSERT(false); return 0;}
|
||||
|
||||
template <>
|
||||
int TYPBLK<int>::GetTypedValue(PSZ p) {return atol(p);}
|
||||
ulonglong TYPBLK<short>::MaxVal(void) {return INT_MAX16;}
|
||||
|
||||
template <>
|
||||
uint TYPBLK<uint>::GetTypedValue(PSZ p) {return (unsigned)atol(p);}
|
||||
ulonglong TYPBLK<ushort>::MaxVal(void) {return UINT_MAX16;}
|
||||
|
||||
template <>
|
||||
short TYPBLK<short>::GetTypedValue(PSZ p) {return (short)atoi(p);}
|
||||
ulonglong TYPBLK<int>::MaxVal(void) {return INT_MAX32;}
|
||||
|
||||
template <>
|
||||
ushort TYPBLK<ushort>::GetTypedValue(PSZ p) {return (ushort)atoi(p);}
|
||||
ulonglong TYPBLK<uint>::MaxVal(void) {return UINT_MAX32;}
|
||||
|
||||
template <>
|
||||
longlong TYPBLK<longlong>::GetTypedValue(PSZ p) {return atoll(p);}
|
||||
ulonglong TYPBLK<char>::MaxVal(void) {return INT_MAX8;}
|
||||
|
||||
template <>
|
||||
ulonglong TYPBLK<ulonglong>::GetTypedValue(PSZ p) {return (unsigned)atoll(p);}
|
||||
ulonglong TYPBLK<uchar>::MaxVal(void) {return UINT_MAX8;}
|
||||
|
||||
template <>
|
||||
double TYPBLK<double>::GetTypedValue(PSZ p) {return atof(p);}
|
||||
ulonglong TYPBLK<longlong>::MaxVal(void) {return INT_MAX64;}
|
||||
|
||||
template <>
|
||||
char TYPBLK<char>::GetTypedValue(PSZ p) {return (char)atoi(p);}
|
||||
template <>
|
||||
uchar TYPBLK<uchar>::GetTypedValue(PSZ p) {return (uchar)atoi(p);}
|
||||
ulonglong TYPBLK<ulonglong>::MaxVal(void) {return ULONGLONG_MAX;}
|
||||
|
||||
/***********************************************************************/
|
||||
/* Set one value in a block from an array of characters. */
|
||||
@@ -557,12 +573,36 @@ char *CHRBLK::GetCharValue(int n)
|
||||
return (char *)GetValPtrEx(n);
|
||||
} // end of GetCharValue
|
||||
|
||||
/***********************************************************************/
|
||||
/* 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
|
||||
|
||||
/***********************************************************************/
|
||||
/* Return the value of the nth element converted to short. */
|
||||
/***********************************************************************/
|
||||
short CHRBLK::GetShortValue(int n)
|
||||
{
|
||||
return (short)atoi((char *)GetValPtrEx(n));
|
||||
bool m;
|
||||
ulonglong val = CharToNumber((char*)GetValPtr(n), Long, INT_MAX16,
|
||||
false, &m);
|
||||
|
||||
return (m && val < INT_MAX16) ? (short)(-(signed)val) : (short)val;
|
||||
} // end of GetShortValue
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -570,7 +610,7 @@ short CHRBLK::GetShortValue(int n)
|
||||
/***********************************************************************/
|
||||
ushort CHRBLK::GetUShortValue(int n)
|
||||
{
|
||||
return (ushort)atoi((char *)GetValPtrEx(n));
|
||||
return (ushort)CharToNumber((char*)GetValPtr(n), Long, UINT_MAX16, true);
|
||||
} // end of GetShortValue
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -578,7 +618,11 @@ ushort CHRBLK::GetUShortValue(int n)
|
||||
/***********************************************************************/
|
||||
int CHRBLK::GetIntValue(int n)
|
||||
{
|
||||
return atol((char *)GetValPtrEx(n));
|
||||
bool m;
|
||||
ulonglong val = CharToNumber((char*)GetValPtr(n), Long, INT_MAX32,
|
||||
false, &m);
|
||||
|
||||
return (m && val < INT_MAX32) ? (int)(-(signed)val) : (int)val;
|
||||
} // end of GetIntValue
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -586,7 +630,7 @@ int CHRBLK::GetIntValue(int n)
|
||||
/***********************************************************************/
|
||||
uint CHRBLK::GetUIntValue(int n)
|
||||
{
|
||||
return (unsigned)atol((char *)GetValPtrEx(n));
|
||||
return (uint)CharToNumber((char*)GetValPtr(n), Long, UINT_MAX32, true);
|
||||
} // end of GetIntValue
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -594,7 +638,11 @@ uint CHRBLK::GetUIntValue(int n)
|
||||
/***********************************************************************/
|
||||
longlong CHRBLK::GetBigintValue(int n)
|
||||
{
|
||||
return atoll((char *)GetValPtrEx(n));
|
||||
bool m;
|
||||
ulonglong val = CharToNumber((char*)GetValPtr(n), Long, INT_MAX64,
|
||||
false, &m);
|
||||
|
||||
return (m && val < INT_MAX64) ? (longlong)(-(signed)val) : (longlong)val;
|
||||
} // end of GetBigintValue
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -602,8 +650,8 @@ longlong CHRBLK::GetBigintValue(int n)
|
||||
/***********************************************************************/
|
||||
ulonglong CHRBLK::GetUBigintValue(int n)
|
||||
{
|
||||
return (unsigned)atoll((char *)GetValPtrEx(n));
|
||||
} // end of GetBigintValue
|
||||
return CharToNumber((char*)GetValPtr(n), Long, ULONGLONG_MAX, true);
|
||||
} // end of GetUBigintValue
|
||||
|
||||
/***********************************************************************/
|
||||
/* Return the value of the nth element converted to double. */
|
||||
@@ -613,22 +661,6 @@ double CHRBLK::GetFloatValue(int n)
|
||||
return atof((char *)GetValPtrEx(n));
|
||||
} // 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
|
||||
|
||||
/***********************************************************************/
|
||||
/* Return the value of the nth element converted to unsigned tiny int.*/
|
||||
/***********************************************************************/
|
||||
uchar CHRBLK::GetUTinyValue(int n)
|
||||
{
|
||||
return (uchar)atoi((char *)GetValPtrEx(n));
|
||||
} // end of GetTinyValue
|
||||
|
||||
/***********************************************************************/
|
||||
/* Set one value in a block. */
|
||||
/***********************************************************************/
|
||||
@@ -869,6 +901,86 @@ void STRBLK::Init(PGLOBAL g, bool check)
|
||||
Global = g;
|
||||
} // end of Init
|
||||
|
||||
/***********************************************************************/
|
||||
/* 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
|
||||
|
||||
/***********************************************************************/
|
||||
/* Set one value in a block from a value in another block. */
|
||||
/***********************************************************************/
|
||||
|
@@ -45,9 +45,12 @@ class VALBLK : public BLOCK {
|
||||
{if (To_Nulls) {To_Nulls[n] = (b) ? '*' : 0;}}
|
||||
virtual bool IsNull(int n) {return To_Nulls && To_Nulls[n];}
|
||||
virtual void SetNullable(bool b);
|
||||
virtual bool IsUnsigned(void) {return Unsigned;}
|
||||
virtual void Init(PGLOBAL g, bool check) = 0;
|
||||
virtual int GetVlen(void) = 0;
|
||||
virtual PSZ GetCharValue(int n);
|
||||
virtual char GetTinyValue(int n) = 0;
|
||||
virtual uchar GetUTinyValue(int n) = 0;
|
||||
virtual short GetShortValue(int n) = 0;
|
||||
virtual ushort GetUShortValue(int n) = 0;
|
||||
virtual int GetIntValue(int n) = 0;
|
||||
@@ -55,8 +58,6 @@ class VALBLK : public BLOCK {
|
||||
virtual longlong GetBigintValue(int n) = 0;
|
||||
virtual ulonglong GetUBigintValue(int n) = 0;
|
||||
virtual double GetFloatValue(int n) = 0;
|
||||
virtual char GetTinyValue(int n) = 0;
|
||||
virtual uchar GetUTinyValue(int n) = 0;
|
||||
virtual void ReAlloc(void *mp, int n) {Blkp = mp; Nval = n;}
|
||||
virtual void Reset(int n) = 0;
|
||||
virtual bool SetFormat(PGLOBAL g, PSZ fmt, int len, int year = 0);
|
||||
@@ -123,6 +124,8 @@ class TYPBLK : public VALBLK {
|
||||
virtual void Init(PGLOBAL g, bool check);
|
||||
virtual int GetVlen(void) {return sizeof(TYPE);}
|
||||
//virtual PSZ GetCharValue(int n);
|
||||
virtual char GetTinyValue(int n) {return (char)Typp[n];}
|
||||
virtual uchar GetUTinyValue(int n) {return (uchar)Typp[n];}
|
||||
virtual short GetShortValue(int n) {return (short)Typp[n];}
|
||||
virtual ushort GetUShortValue(int n) {return (ushort)Typp[n];}
|
||||
virtual int GetIntValue(int n) {return (int)Typp[n];}
|
||||
@@ -130,8 +133,6 @@ class TYPBLK : public VALBLK {
|
||||
virtual longlong GetBigintValue(int n) {return (longlong)Typp[n];}
|
||||
virtual ulonglong GetUBigintValue(int n) {return (ulonglong)Typp[n];}
|
||||
virtual double GetFloatValue(int n) {return (double)Typp[n];}
|
||||
virtual char GetTinyValue(int n) {return (char)Typp[n];}
|
||||
virtual uchar GetUTinyValue(int n) {return (uchar)Typp[n];}
|
||||
virtual void Reset(int n) {Typp[n] = 0;}
|
||||
|
||||
// Methods
|
||||
@@ -168,9 +169,9 @@ class TYPBLK : public VALBLK {
|
||||
|
||||
protected:
|
||||
// Specialized functions
|
||||
static ulonglong MaxVal(void);
|
||||
TYPE GetTypedValue(PVAL vp);
|
||||
TYPE GetTypedValue(PVBLK blk, int n);
|
||||
TYPE GetTypedValue(PSZ s);
|
||||
|
||||
// Members
|
||||
TYPE* const &Typp;
|
||||
@@ -189,6 +190,8 @@ class CHRBLK : public VALBLK {
|
||||
virtual void Init(PGLOBAL g, bool check);
|
||||
virtual int GetVlen(void) {return Long;}
|
||||
virtual PSZ GetCharValue(int n);
|
||||
virtual char GetTinyValue(int n);
|
||||
virtual uchar GetUTinyValue(int n);
|
||||
virtual short GetShortValue(int n);
|
||||
virtual ushort GetUShortValue(int n);
|
||||
virtual int GetIntValue(int n);
|
||||
@@ -196,8 +199,6 @@ class CHRBLK : public VALBLK {
|
||||
virtual longlong GetBigintValue(int n);
|
||||
virtual ulonglong GetUBigintValue(int n);
|
||||
virtual double GetFloatValue(int n);
|
||||
virtual char GetTinyValue(int n);
|
||||
virtual uchar GetUTinyValue(int n);
|
||||
virtual void Reset(int n);
|
||||
virtual void SetPrec(int p) {Ci = (p != 0);}
|
||||
virtual bool IsCi(void) {return Ci;}
|
||||
@@ -242,15 +243,15 @@ class STRBLK : public VALBLK {
|
||||
virtual void Init(PGLOBAL g, bool check);
|
||||
virtual int GetVlen(void) {return sizeof(PSZ);}
|
||||
virtual PSZ GetCharValue(int n) {return Strp[n];}
|
||||
virtual short GetShortValue(int n) {return (short)atoi(Strp[n]);}
|
||||
virtual ushort GetUShortValue(int n) {return (ushort)atoi(Strp[n]);}
|
||||
virtual int GetIntValue(int n) {return atol(Strp[n]);}
|
||||
virtual uint GetUIntValue(int n) {return (unsigned)atol(Strp[n]);}
|
||||
virtual longlong GetBigintValue(int n) {return atoll(Strp[n]);}
|
||||
virtual ulonglong GetUBigintValue(int n) {return (unsigned)atoll(Strp[n]);}
|
||||
virtual char GetTinyValue(int n);
|
||||
virtual uchar GetUTinyValue(int n);
|
||||
virtual short GetShortValue(int n);
|
||||
virtual ushort GetUShortValue(int n);
|
||||
virtual int GetIntValue(int n);
|
||||
virtual uint GetUIntValue(int n);
|
||||
virtual longlong GetBigintValue(int n);
|
||||
virtual ulonglong GetUBigintValue(int n);
|
||||
virtual double GetFloatValue(int n) {return atof(Strp[n]);}
|
||||
virtual char GetTinyValue(int n) {return (char)atoi(Strp[n]);}
|
||||
virtual uchar GetUTinyValue(int n) {return (uchar)atoi(Strp[n]);}
|
||||
virtual void Reset(int n) {Strp[n] = NULL;}
|
||||
|
||||
// Methods
|
||||
|
@@ -92,6 +92,56 @@ PSZ strlwr(PSZ s);
|
||||
}
|
||||
#endif // !WIN32
|
||||
|
||||
/***********************************************************************/
|
||||
/* Get a long long number from its character representation. */
|
||||
/* IN p: Pointer to the numeric string */
|
||||
/* IN n: The string length */
|
||||
/* IN maxval: The number max value */
|
||||
/* IN un: True if the number must be unsigned */
|
||||
/* OUT rc: Set to TRUE for out of range value */
|
||||
/* OUT minus: Set to true if the number is negative */
|
||||
/* Returned val: The resulting number */
|
||||
/***********************************************************************/
|
||||
ulonglong CharToNumber(char *p, int n, ulonglong maxval,
|
||||
bool un, bool *minus, bool *rc)
|
||||
{
|
||||
char *p2;
|
||||
uchar c;
|
||||
ulonglong val;
|
||||
|
||||
if (minus) *minus = false;
|
||||
if (rc) *rc = false;
|
||||
|
||||
// Eliminate leading blanks or 0
|
||||
for (p2 = p + n; p < p2 && (*p == ' ' || *p == '0'); p++) ;
|
||||
|
||||
// Get an eventual sign character
|
||||
switch (*p) {
|
||||
case '-':
|
||||
if (un) {
|
||||
if (rc) *rc = true;
|
||||
return 0;
|
||||
} else {
|
||||
maxval++;
|
||||
if (minus) *minus = true;
|
||||
} // endif Unsigned
|
||||
|
||||
case '+':
|
||||
p++;
|
||||
break;
|
||||
} // endswitch *p
|
||||
|
||||
for (val = 0; p < p2 && (c = (uchar)(*p - '0')) < 10; p++)
|
||||
if (val > (maxval - c) / 10) {
|
||||
val = maxval;
|
||||
if (rc) *rc = true;
|
||||
break;
|
||||
} else
|
||||
val = val * 10 + c;
|
||||
|
||||
return val;
|
||||
} // end of CharToNumber
|
||||
|
||||
/***********************************************************************/
|
||||
/* GetTypeName: returns the PlugDB internal type name. */
|
||||
/***********************************************************************/
|
||||
@@ -481,6 +531,36 @@ TYPVAL<TYPE>::TYPVAL(TYPE n, int type, int prec, bool un)
|
||||
Prec = prec;
|
||||
} // end of TYPVAL constructor
|
||||
|
||||
/***********************************************************************/
|
||||
/* Return unsigned max value for the type. */
|
||||
/***********************************************************************/
|
||||
template <class TYPE>
|
||||
ulonglong TYPVAL<TYPE>::MaxVal(void) {DBUG_ASSERT(false); return 0;}
|
||||
|
||||
template <>
|
||||
ulonglong TYPVAL<short>::MaxVal(void) {return INT_MAX16;}
|
||||
|
||||
template <>
|
||||
ulonglong TYPVAL<ushort>::MaxVal(void) {return UINT_MAX16;}
|
||||
|
||||
template <>
|
||||
ulonglong TYPVAL<int>::MaxVal(void) {return INT_MAX32;}
|
||||
|
||||
template <>
|
||||
ulonglong TYPVAL<uint>::MaxVal(void) {return UINT_MAX32;}
|
||||
|
||||
template <>
|
||||
ulonglong TYPVAL<char>::MaxVal(void) {return INT_MAX8;}
|
||||
|
||||
template <>
|
||||
ulonglong TYPVAL<uchar>::MaxVal(void) {return UINT_MAX8;}
|
||||
|
||||
template <>
|
||||
ulonglong TYPVAL<longlong>::MaxVal(void) {return INT_MAX64;}
|
||||
|
||||
template <>
|
||||
ulonglong TYPVAL<ulonglong>::MaxVal(void) {return ULONGLONG_MAX;}
|
||||
|
||||
/***********************************************************************/
|
||||
/* TYPVAL GetValLen: returns the print length of the typed object. */
|
||||
/***********************************************************************/
|
||||
@@ -558,45 +638,29 @@ uchar TYPVAL<uchar>::GetTypedValue(PVAL valp)
|
||||
/* TYPVAL SetValue: convert chars extracted from a line to TYPE value.*/
|
||||
/***********************************************************************/
|
||||
template <class TYPE>
|
||||
void TYPVAL<TYPE>::SetValue_char(char *p, int n)
|
||||
bool TYPVAL<TYPE>::SetValue_char(char *p, int n)
|
||||
{
|
||||
char *p2, buf[32];
|
||||
bool minus = false;
|
||||
bool rc, minus;
|
||||
ulonglong maxval = MaxVal();
|
||||
ulonglong val = CharToNumber(p, n, maxval, Unsigned, &minus, &rc);
|
||||
|
||||
for (p2 = p + n; p < p2 && *p == ' '; p++) ;
|
||||
if (minus && val < maxval)
|
||||
Tval = (TYPE)(-(signed)val);
|
||||
else
|
||||
Tval = (TYPE)val;
|
||||
|
||||
for (Tval = 0, minus = false; p < p2; p++)
|
||||
switch (*p) {
|
||||
case '-':
|
||||
minus = true;
|
||||
case '+':
|
||||
break;
|
||||
case '0': Tval = Tval * 10; break;
|
||||
case '1': Tval = Tval * 10 + 1; break;
|
||||
case '2': Tval = Tval * 10 + 2; break;
|
||||
case '3': Tval = Tval * 10 + 3; break;
|
||||
case '4': Tval = Tval * 10 + 4; break;
|
||||
case '5': Tval = Tval * 10 + 5; break;
|
||||
case '6': Tval = Tval * 10 + 6; break;
|
||||
case '7': Tval = Tval * 10 + 7; break;
|
||||
case '8': Tval = Tval * 10 + 8; break;
|
||||
case '9': Tval = Tval * 10 + 9; break;
|
||||
default:
|
||||
p = p2;
|
||||
} // endswitch *p
|
||||
|
||||
if (minus && Tval)
|
||||
Tval = (-(signed)Tval) ? -(signed)Tval : Tval;
|
||||
|
||||
if (trace > 1)
|
||||
if (trace > 1) {
|
||||
char buf[64];
|
||||
htrc(strcat(strcat(strcpy(buf, " setting %s to: "), Fmt), "\n"),
|
||||
GetTypeName(Type), Tval);
|
||||
} // endif trace
|
||||
|
||||
Null = false;
|
||||
return rc;
|
||||
} // end of SetValue
|
||||
|
||||
template <>
|
||||
void TYPVAL<double>::SetValue_char(char *p, int n)
|
||||
bool TYPVAL<double>::SetValue_char(char *p, int n)
|
||||
{
|
||||
if (p) {
|
||||
char buf[32];
|
||||
@@ -617,6 +681,7 @@ void TYPVAL<double>::SetValue_char(char *p, int n)
|
||||
Null = Nullable;
|
||||
} // endif p
|
||||
|
||||
return false;
|
||||
} // end of SetValue
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -626,7 +691,7 @@ template <class TYPE>
|
||||
void TYPVAL<TYPE>::SetValue_psz(PSZ s)
|
||||
{
|
||||
if (s) {
|
||||
Tval = GetTypedValue(s);
|
||||
SetValue_char(s, (int)strlen(s));
|
||||
Null = false;
|
||||
} else {
|
||||
Reset();
|
||||
@@ -635,25 +700,6 @@ void TYPVAL<TYPE>::SetValue_psz(PSZ s)
|
||||
|
||||
} // end of SetValue
|
||||
|
||||
template <>
|
||||
int TYPVAL<int>::GetTypedValue(PSZ s) {return atol(s);}
|
||||
template <>
|
||||
uint TYPVAL<uint>::GetTypedValue(PSZ s) {return (unsigned)atol(s);}
|
||||
template <>
|
||||
short TYPVAL<short>::GetTypedValue(PSZ s) {return (short)atoi(s);}
|
||||
template <>
|
||||
ushort TYPVAL<ushort>::GetTypedValue(PSZ s) {return (ushort)atoi(s);}
|
||||
template <>
|
||||
longlong TYPVAL<longlong>::GetTypedValue(PSZ s) {return atoll(s);}
|
||||
template <>
|
||||
ulonglong TYPVAL<ulonglong>::GetTypedValue(PSZ s) {return (unsigned)atoll(s);}
|
||||
template <>
|
||||
double TYPVAL<double>::GetTypedValue(PSZ s) {return atof(s);}
|
||||
template <>
|
||||
char TYPVAL<char>::GetTypedValue(PSZ s) {return (char)atoi(s);}
|
||||
template <>
|
||||
uchar TYPVAL<uchar>::GetTypedValue(PSZ s) {return (uchar)atoi(s);}
|
||||
|
||||
/***********************************************************************/
|
||||
/* TYPVAL SetValue: set value with a TYPE extracted from a block. */
|
||||
/***********************************************************************/
|
||||
@@ -670,7 +716,7 @@ int TYPVAL<int>::GetTypedValue(PVBLK blk, int n)
|
||||
|
||||
template <>
|
||||
uint TYPVAL<uint>::GetTypedValue(PVBLK blk, int n)
|
||||
{return (unsigned)blk->GetIntValue(n);}
|
||||
{return blk->GetUIntValue(n);}
|
||||
|
||||
template <>
|
||||
short TYPVAL<short>::GetTypedValue(PVBLK blk, int n)
|
||||
@@ -678,7 +724,7 @@ short TYPVAL<short>::GetTypedValue(PVBLK blk, int n)
|
||||
|
||||
template <>
|
||||
ushort TYPVAL<ushort>::GetTypedValue(PVBLK blk, int n)
|
||||
{return (unsigned)blk->GetShortValue(n);}
|
||||
{return blk->GetUShortValue(n);}
|
||||
|
||||
template <>
|
||||
longlong TYPVAL<longlong>::GetTypedValue(PVBLK blk, int n)
|
||||
@@ -686,7 +732,7 @@ longlong TYPVAL<longlong>::GetTypedValue(PVBLK blk, int n)
|
||||
|
||||
template <>
|
||||
ulonglong TYPVAL<ulonglong>::GetTypedValue(PVBLK blk, int n)
|
||||
{return (unsigned)blk->GetBigintValue(n);}
|
||||
{return blk->GetUBigintValue(n);}
|
||||
|
||||
template <>
|
||||
double TYPVAL<double>::GetTypedValue(PVBLK blk, int n)
|
||||
@@ -698,7 +744,7 @@ char TYPVAL<char>::GetTypedValue(PVBLK blk, int n)
|
||||
|
||||
template <>
|
||||
uchar TYPVAL<uchar>::GetTypedValue(PVBLK blk, int n)
|
||||
{return (unsigned)blk->GetTinyValue(n);}
|
||||
{return blk->GetUTinyValue(n);}
|
||||
|
||||
/***********************************************************************/
|
||||
/* TYPVAL SetBinValue: with bytes extracted from a line. */
|
||||
@@ -832,6 +878,8 @@ bool TYPVAL<TYPE>::IsEqual(PVAL vp, bool chktype)
|
||||
return true;
|
||||
else if (chktype && Type != vp->GetType())
|
||||
return false;
|
||||
else if (chktype && Unsigned != vp->IsUnsigned())
|
||||
return false;
|
||||
else if (Null || vp->IsNull())
|
||||
return false;
|
||||
else
|
||||
@@ -933,6 +981,82 @@ TYPVAL<PSZ>::TYPVAL(PGLOBAL g, PSZ s, int n, int c)
|
||||
Ci = (c != 0);
|
||||
} // end of STRING constructor
|
||||
|
||||
/***********************************************************************/
|
||||
/* Get the tiny value represented by the Strp string. */
|
||||
/***********************************************************************/
|
||||
char TYPVAL<PSZ>::GetTinyValue(void)
|
||||
{
|
||||
bool m;
|
||||
ulonglong val = CharToNumber(Strp, strlen(Strp), 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 TYPVAL<PSZ>::GetUTinyValue(void)
|
||||
{
|
||||
return (uchar)CharToNumber(Strp, strlen(Strp), UINT_MAX8, true);
|
||||
} // end of GetUTinyValue
|
||||
|
||||
/***********************************************************************/
|
||||
/* Get the short value represented by the Strp string. */
|
||||
/***********************************************************************/
|
||||
short TYPVAL<PSZ>::GetShortValue(void)
|
||||
{
|
||||
bool m;
|
||||
ulonglong val = CharToNumber(Strp, strlen(Strp), 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 TYPVAL<PSZ>::GetUShortValue(void)
|
||||
{
|
||||
return (ushort)CharToNumber(Strp, strlen(Strp), UINT_MAX16, true);
|
||||
} // end of GetUshortValue
|
||||
|
||||
/***********************************************************************/
|
||||
/* Get the integer value represented by the Strp string. */
|
||||
/***********************************************************************/
|
||||
int TYPVAL<PSZ>::GetIntValue(void)
|
||||
{
|
||||
bool m;
|
||||
ulonglong val = CharToNumber(Strp, strlen(Strp), 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 TYPVAL<PSZ>::GetUIntValue(void)
|
||||
{
|
||||
return (uint)CharToNumber(Strp, strlen(Strp), UINT_MAX32, true);
|
||||
} // end of GetUintValue
|
||||
|
||||
/***********************************************************************/
|
||||
/* Get the big integer value represented by the Strp string. */
|
||||
/***********************************************************************/
|
||||
longlong TYPVAL<PSZ>::GetBigintValue(void)
|
||||
{
|
||||
bool m;
|
||||
ulonglong val = CharToNumber(Strp, strlen(Strp), 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 TYPVAL<PSZ>::GetUBigintValue(void)
|
||||
{
|
||||
return CharToNumber(Strp, strlen(Strp), ULONGLONG_MAX, true);
|
||||
} // end of GetUBigintValue
|
||||
|
||||
/***********************************************************************/
|
||||
/* STRING SetValue: copy the value of another Value object. */
|
||||
/***********************************************************************/
|
||||
@@ -954,9 +1078,13 @@ bool TYPVAL<PSZ>::SetValue_pval(PVAL valp, bool chktype)
|
||||
/***********************************************************************/
|
||||
/* STRING SetValue: fill string with chars extracted from a line. */
|
||||
/***********************************************************************/
|
||||
void TYPVAL<PSZ>::SetValue_char(char *p, int n)
|
||||
bool TYPVAL<PSZ>::SetValue_char(char *p, int n)
|
||||
{
|
||||
bool rc;
|
||||
|
||||
if (p) {
|
||||
rc = n > Len;
|
||||
|
||||
if ((n = min(n, Len))) {
|
||||
strncpy(Strp, p, n);
|
||||
|
||||
@@ -975,10 +1103,12 @@ void TYPVAL<PSZ>::SetValue_char(char *p, int n)
|
||||
|
||||
Null = false;
|
||||
} else {
|
||||
rc = false;
|
||||
Reset();
|
||||
Null = Nullable;
|
||||
} // endif p
|
||||
|
||||
return rc;
|
||||
} // end of SetValue_char
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -1181,53 +1311,6 @@ char *TYPVAL<PSZ>::GetCharString(char *p)
|
||||
return Strp;
|
||||
} // end of GetCharString
|
||||
|
||||
#if 0
|
||||
/***********************************************************************/
|
||||
/* STRING GetShortString: get short representation of a char value. */
|
||||
/***********************************************************************/
|
||||
char *TYPVAL<PSZ>::GetShortString(char *p, int n)
|
||||
{
|
||||
sprintf(p, "%*hd", n, (short)(Null ? 0 : atoi(Strp)));
|
||||
return p;
|
||||
} // end of GetShortString
|
||||
|
||||
/***********************************************************************/
|
||||
/* STRING GetIntString: get int representation of a char value. */
|
||||
/***********************************************************************/
|
||||
char *TYPVAL<PSZ>::GetIntString(char *p, int n)
|
||||
{
|
||||
sprintf(p, "%*ld", n, (Null) ? 0 : atol(Strp));
|
||||
return p;
|
||||
} // end of GetIntString
|
||||
|
||||
/***********************************************************************/
|
||||
/* STRING GetBigintString: get big int representation of a char value.*/
|
||||
/***********************************************************************/
|
||||
char *TYPVAL<PSZ>::GetBigintString(char *p, int n)
|
||||
{
|
||||
sprintf(p, "%*lld", n, (Null) ? 0 : atoll(Strp));
|
||||
return p;
|
||||
} // end of GetBigintString
|
||||
|
||||
/***********************************************************************/
|
||||
/* STRING GetFloatString: get double representation of a char value. */
|
||||
/***********************************************************************/
|
||||
char *TYPVAL<PSZ>::GetFloatString(char *p, int n, int prec)
|
||||
{
|
||||
sprintf(p, "%*.*lf", n, (prec < 0) ? 2 : prec, Null ? 0 : atof(Strp));
|
||||
return p;
|
||||
} // end of GetFloatString
|
||||
|
||||
/***********************************************************************/
|
||||
/* STRING GetTinyString: get tiny int representation of a char value. */
|
||||
/***********************************************************************/
|
||||
char *TYPVAL<PSZ>::GetTinyString(char *p, int n)
|
||||
{
|
||||
sprintf(p, "%*d", n, (Null) ? 0 : (char)atoi(Strp));
|
||||
return p;
|
||||
} // end of GetIntString
|
||||
#endif // 0
|
||||
|
||||
/***********************************************************************/
|
||||
/* STRING compare value with another Value. */
|
||||
/***********************************************************************/
|
||||
@@ -1355,11 +1438,7 @@ void DTVAL::SetTimeShift(void)
|
||||
|
||||
} // end of SetTimeShift
|
||||
|
||||
/***********************************************************************/
|
||||
/* GetGmTime: returns a pointer to a static tm structure obtained */
|
||||
/* though the gmtime C function. The purpose of this function is to */
|
||||
/* extend the range of valid dates by accepting negative time values. */
|
||||
/***********************************************************************/
|
||||
// Added by Alexander Barkov
|
||||
static void TIME_to_localtime(struct tm *tm, const MYSQL_TIME *ltime)
|
||||
{
|
||||
bzero(tm, sizeof(*tm));
|
||||
@@ -1371,7 +1450,7 @@ static void TIME_to_localtime(struct tm *tm, const MYSQL_TIME *ltime)
|
||||
tm->tm_sec= ltime->second;
|
||||
}
|
||||
|
||||
|
||||
// Added by Alexander Barkov
|
||||
static struct tm *gmtime_mysql(const time_t *timep, struct tm *tm)
|
||||
{
|
||||
MYSQL_TIME ltime;
|
||||
@@ -1380,7 +1459,11 @@ static struct tm *gmtime_mysql(const time_t *timep, struct tm *tm)
|
||||
return tm;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************/
|
||||
/* GetGmTime: returns a pointer to a static tm structure obtained */
|
||||
/* though the gmtime C function. The purpose of this function is to */
|
||||
/* extend the range of valid dates by accepting negative time values. */
|
||||
/***********************************************************************/
|
||||
struct tm *DTVAL::GetGmTime(struct tm *tm_buffer)
|
||||
{
|
||||
struct tm *datm;
|
||||
@@ -1403,12 +1486,7 @@ struct tm *DTVAL::GetGmTime(struct tm *tm_buffer)
|
||||
return datm;
|
||||
} // end of GetGmTime
|
||||
|
||||
/***********************************************************************/
|
||||
/* MakeTime: calculates a date value from a tm structures using the */
|
||||
/* mktime C function. The purpose of this function is to extend the */
|
||||
/* range of valid dates by accepting to set negative time values. */
|
||||
/***********************************************************************/
|
||||
|
||||
// Added by Alexander Barkov
|
||||
static time_t mktime_mysql(struct tm *ptm)
|
||||
{
|
||||
MYSQL_TIME ltime;
|
||||
@@ -1419,6 +1497,11 @@ static time_t mktime_mysql(struct tm *ptm)
|
||||
return error_code ? (time_t) -1 : t;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
/* MakeTime: calculates a date value from a tm structures using the */
|
||||
/* mktime C function. The purpose of this function is to extend the */
|
||||
/* range of valid dates by accepting to set negative time values. */
|
||||
/***********************************************************************/
|
||||
bool DTVAL::MakeTime(struct tm *ptm)
|
||||
{
|
||||
int n, y = ptm->tm_year;
|
||||
@@ -1575,8 +1658,10 @@ bool DTVAL::SetValue_pval(PVAL valp, bool chktype)
|
||||
/***********************************************************************/
|
||||
/* SetValue: convert chars extracted from a line to date value. */
|
||||
/***********************************************************************/
|
||||
void DTVAL::SetValue_char(char *p, int n)
|
||||
bool DTVAL::SetValue_char(char *p, int n)
|
||||
{
|
||||
bool rc;
|
||||
|
||||
if (Pdtp) {
|
||||
char *p2;
|
||||
int ndv;
|
||||
@@ -1585,7 +1670,9 @@ void DTVAL::SetValue_char(char *p, int n)
|
||||
// Trim trailing blanks
|
||||
for (p2 = p + n -1; p < p2 && *p2 == ' '; p2--) ;
|
||||
|
||||
n = min(p2 - p + 1, Len);
|
||||
if ((rc = (n = p2 - p + 1) > Len))
|
||||
n = Len;
|
||||
|
||||
memcpy(Sdate, p, n);
|
||||
Sdate[n] = '\0';
|
||||
|
||||
@@ -1597,8 +1684,9 @@ void DTVAL::SetValue_char(char *p, int n)
|
||||
|
||||
Null = false;
|
||||
} else
|
||||
TYPVAL<int>::SetValue_char(p, n);
|
||||
rc = TYPVAL<int>::SetValue_char(p, n);
|
||||
|
||||
return rc;
|
||||
} // end of SetValue
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -1698,6 +1786,7 @@ char *DTVAL::ShowValue(char *buf, int len)
|
||||
|
||||
} // end of ShowValue
|
||||
|
||||
#if 0 // Not used by CONNECT
|
||||
/***********************************************************************/
|
||||
/* Returns a member of the struct tm representation of the date. */
|
||||
/***********************************************************************/
|
||||
@@ -1747,6 +1836,7 @@ bool DTVAL::WeekNum(PGLOBAL g, int& nval)
|
||||
// Everything should be Ok
|
||||
return false;
|
||||
} // end of WeekNum
|
||||
#endif // 0
|
||||
|
||||
/***********************************************************************/
|
||||
/* FormatValue: This function set vp (a STRING value) to the string */
|
||||
|
@@ -16,11 +16,6 @@
|
||||
#include "assert.h"
|
||||
#include "block.h"
|
||||
|
||||
#if defined(WIN32)
|
||||
#define strtoll _strtoi64
|
||||
#define atoll(S) strtoll(S, NULL, 10)
|
||||
#endif // WIN32
|
||||
|
||||
/***********************************************************************/
|
||||
/* Types used in some class definitions. */
|
||||
/***********************************************************************/
|
||||
@@ -55,6 +50,8 @@ DllExport bool IsTypeNum(int type);
|
||||
DllExport PVAL AllocateValue(PGLOBAL, PVAL, int = TYPE_VOID, int = 0);
|
||||
DllExport PVAL AllocateValue(PGLOBAL, int, int len = 0, int prec = 0,
|
||||
PSZ fmt = NULL);
|
||||
DllExport ulonglong CharToNumber(char *, int, ulonglong, bool,
|
||||
bool *minus = NULL, bool *rc = NULL);
|
||||
|
||||
/***********************************************************************/
|
||||
/* Class VALUE represents a constant or variable of any valid type. */
|
||||
@@ -96,7 +93,7 @@ class DllExport VALUE : public BLOCK {
|
||||
|
||||
// Methods
|
||||
virtual bool SetValue_pval(PVAL valp, bool chktype = false) = 0;
|
||||
virtual void SetValue_char(char *p, int n) = 0;
|
||||
virtual bool SetValue_char(char *p, int n) = 0;
|
||||
virtual void SetValue_psz(PSZ s) = 0;
|
||||
virtual void SetValue(char c) {assert(false);}
|
||||
virtual void SetValue(uchar c) {assert(false);}
|
||||
@@ -112,11 +109,6 @@ class DllExport VALUE : public BLOCK {
|
||||
virtual bool GetBinValue(void *buf, int buflen, bool go) = 0;
|
||||
virtual char *ShowValue(char *buf, int len = 0) = 0;
|
||||
virtual char *GetCharString(char *p) = 0;
|
||||
//virtual char *GetShortString(char *p, int n) {return "#####";}
|
||||
//virtual char *GetIntString(char *p, int n) = 0;
|
||||
//virtual char *GetBigintString(char *p, int n) = 0;
|
||||
//virtual char *GetFloatString(char *p, int n, int prec) = 0;
|
||||
//virtual char *GetTinyString(char *p, int n) {return "?";}
|
||||
virtual bool IsEqual(PVAL vp, bool chktype) = 0;
|
||||
virtual bool FormatValue(PVAL vp, char *fmt) = 0;
|
||||
|
||||
@@ -169,7 +161,7 @@ class DllExport TYPVAL : public VALUE {
|
||||
|
||||
// Methods
|
||||
virtual bool SetValue_pval(PVAL valp, bool chktype);
|
||||
virtual void SetValue_char(char *p, int n);
|
||||
virtual bool SetValue_char(char *p, int n);
|
||||
virtual void SetValue_psz(PSZ s);
|
||||
virtual void SetValue(char c) {Tval = (TYPE)c; Null = false;}
|
||||
virtual void SetValue(uchar c) {Tval = (TYPE)c; Null = false;}
|
||||
@@ -185,11 +177,6 @@ class DllExport TYPVAL : public VALUE {
|
||||
virtual bool GetBinValue(void *buf, int buflen, bool go);
|
||||
virtual char *ShowValue(char *buf, int);
|
||||
virtual char *GetCharString(char *p);
|
||||
//virtual char *GetShortString(char *p, int n);
|
||||
//virtual char *GetIntString(char *p, int n);
|
||||
//virtual char *GetBigintString(char *p, int n);
|
||||
//virtual char *GetFloatString(char *p, int n, int prec = -1);
|
||||
//virtual char *GetTinyString(char *p, int n);
|
||||
virtual bool IsEqual(PVAL vp, bool chktype);
|
||||
virtual bool SetConstFormat(PGLOBAL, FORMAT&);
|
||||
virtual bool FormatValue(PVAL vp, char *fmt);
|
||||
@@ -201,9 +188,10 @@ class DllExport TYPVAL : public VALUE {
|
||||
TYPVAL(void) : VALUE(TYPE_ERROR) {}
|
||||
|
||||
// Specialized functions
|
||||
TYPE GetTypedValue(PVAL vp);
|
||||
TYPE GetTypedValue(PVBLK blk, int n);
|
||||
TYPE GetTypedValue(PSZ s);
|
||||
static ulonglong MaxVal(void);
|
||||
TYPE GetTypedValue(PVAL vp);
|
||||
TYPE GetTypedValue(PVBLK blk, int n);
|
||||
// TYPE GetTypedValue(PSZ s);
|
||||
|
||||
// Members
|
||||
TYPE Tval;
|
||||
@@ -227,21 +215,21 @@ class DllExport TYPVAL<PSZ>: public VALUE {
|
||||
virtual int GetValPrec() {return (Ci) ? 1 : 0;}
|
||||
virtual int GetSize(void) {return (Strp) ? strlen(Strp) : 0;}
|
||||
virtual PSZ GetCharValue(void) {return Strp;}
|
||||
virtual char GetTinyValue(void) {return (char)atoi(Strp);}
|
||||
virtual uchar GetUTinyValue(void) {return (uchar)atoi(Strp);}
|
||||
virtual short GetShortValue(void) {return (short)atoi(Strp);}
|
||||
virtual ushort GetUShortValue(void) {return (ushort)atoi(Strp);}
|
||||
virtual int GetIntValue(void) {return atol(Strp);}
|
||||
virtual uint GetUIntValue(void) {return (uint)atol(Strp);}
|
||||
virtual longlong GetBigintValue(void) {return atoll(Strp);}
|
||||
virtual ulonglong GetUBigintValue(void) {return (ulonglong)atoll(Strp);}
|
||||
virtual char GetTinyValue(void);
|
||||
virtual uchar GetUTinyValue(void);
|
||||
virtual short GetShortValue(void);
|
||||
virtual ushort GetUShortValue(void);
|
||||
virtual int GetIntValue(void);
|
||||
virtual uint GetUIntValue(void);
|
||||
virtual longlong GetBigintValue(void);
|
||||
virtual ulonglong GetUBigintValue(void);
|
||||
virtual double GetFloatValue(void) {return atof(Strp);}
|
||||
virtual void *GetTo_Val(void) {return Strp;}
|
||||
virtual void SetPrec(int prec) {Ci = prec != 0;}
|
||||
|
||||
// Methods
|
||||
virtual bool SetValue_pval(PVAL valp, bool chktype);
|
||||
virtual void SetValue_char(char *p, int n);
|
||||
virtual bool SetValue_char(char *p, int n);
|
||||
virtual void SetValue_psz(PSZ s);
|
||||
virtual void SetValue_pvblk(PVBLK blk, int n);
|
||||
virtual void SetValue(char c);
|
||||
@@ -257,23 +245,10 @@ class DllExport TYPVAL<PSZ>: public VALUE {
|
||||
virtual bool GetBinValue(void *buf, int buflen, bool go);
|
||||
virtual char *ShowValue(char *buf, int);
|
||||
virtual char *GetCharString(char *p);
|
||||
//virtual char *GetShortString(char *p, int n);
|
||||
//virtual char *GetIntString(char *p, int n);
|
||||
//virtual char *GetBigintString(char *p, int n);
|
||||
//virtual char *GetFloatString(char *p, int n, int prec = -1);
|
||||
//virtual char *GetTinyString(char *p, int n);
|
||||
virtual bool IsEqual(PVAL vp, bool chktype);
|
||||
virtual bool FormatValue(PVAL vp, char *fmt);
|
||||
virtual bool SetConstFormat(PGLOBAL, FORMAT&);
|
||||
|
||||
// Specialized functions
|
||||
//template <class T>
|
||||
//T GetValue_as(T type) {return Strp;}
|
||||
//int GetValue_as(int type) {return atol(Strp);}
|
||||
//short GetValue_as(short type) {return (short)atoi(Strp);}
|
||||
//longlong GetValue_as(longlong type) {return atoll(Strp);}
|
||||
//double GetValue_as(double type) {return atof(Strp);}
|
||||
|
||||
// Members
|
||||
PSZ Strp;
|
||||
bool Ci; // true if case insensitive
|
||||
@@ -295,7 +270,7 @@ class DllExport DTVAL : public TYPVAL<int> {
|
||||
|
||||
// Implementation
|
||||
virtual bool SetValue_pval(PVAL valp, bool chktype);
|
||||
virtual void SetValue_char(char *p, int n);
|
||||
virtual bool SetValue_char(char *p, int n);
|
||||
virtual void SetValue_psz(PSZ s);
|
||||
virtual void SetValue_pvblk(PVBLK blk, int n);
|
||||
virtual char *GetCharString(char *p);
|
||||
@@ -304,15 +279,15 @@ class DllExport DTVAL : public TYPVAL<int> {
|
||||
bool SetFormat(PGLOBAL g, PSZ fmt, int len, int year = 0);
|
||||
bool SetFormat(PGLOBAL g, PVAL valp);
|
||||
bool IsFormatted(void) {return Pdtp != NULL;}
|
||||
bool GetTmMember(OPVAL op, int& mval);
|
||||
bool DateDiff(DTVAL *dtp, OPVAL op, int& tdif);
|
||||
// bool GetTmMember(OPVAL op, int& mval);
|
||||
// bool DateDiff(DTVAL *dtp, OPVAL op, int& tdif);
|
||||
bool MakeTime(struct tm *ptm);
|
||||
static void SetTimeShift(void);
|
||||
static int GetShift(void) {return Shift;}
|
||||
|
||||
// Methods
|
||||
bool MakeDate(PGLOBAL g, int *val, int nval);
|
||||
bool WeekNum(PGLOBAL g, int& nval);
|
||||
// bool WeekNum(PGLOBAL g, int& nval);
|
||||
|
||||
struct tm *GetGmTime(struct tm *);
|
||||
|
||||
|
@@ -134,6 +134,7 @@ bool CONSTANT::Compare(PXOB xp)
|
||||
|
||||
} // end of Compare
|
||||
|
||||
#if 0
|
||||
/***********************************************************************/
|
||||
/* Rephrase: temporary implementation used by PlugRephraseSQL. */
|
||||
/***********************************************************************/
|
||||
@@ -166,6 +167,7 @@ bool CONSTANT::Rephrase(PGLOBAL g, PSZ work)
|
||||
|
||||
return false;
|
||||
} // end of Rephrase
|
||||
#endif // 0
|
||||
|
||||
/***********************************************************************/
|
||||
/* Make file output of a constant object. */
|
||||
|
@@ -124,7 +124,7 @@ class DllExport CONSTANT : public XOBJECT {
|
||||
{return Value->SetConstFormat(g, fmt);}
|
||||
virtual int CheckSpcCol(PTDB, int) {return 1;}
|
||||
void Convert(PGLOBAL g, int newtype);
|
||||
bool Rephrase(PGLOBAL g, PSZ work);
|
||||
// bool Rephrase(PGLOBAL g, PSZ work);
|
||||
void SetValue(PVAL vp) {Value = vp;}
|
||||
virtual bool VerifyColumn(PTBX txp) {return true;}
|
||||
virtual bool VerifyTdb(PTDB& tdbp) {return true;}
|
||||
|
Reference in New Issue
Block a user