Commit 514a7d84 authored by Olivier Bertrand's avatar Olivier Bertrand

Add unicode ODBC types to the types recognized by CONNECT.

Was added in function TranslateSQLType.
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/odbconn.cpp
  modified:   storage/connect/value.h

Add some trace in particular in indexing routines.
  modified:   storage/connect/block.h
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/plugutil.c
  modified:   storage/connect/xindex.cpp
  modified:   storage/connect/xindex.h
parent b6a56370
......@@ -38,7 +38,7 @@ typedef class BLOCK *PBLOCK;
class DllExport BLOCK {
public:
void * operator new(size_t size, PGLOBAL g, void *p = NULL) {
// if (trace > 2)
// if (trace > 3)
// htrc("New BLOCK: size=%d g=%p p=%p\n", size, g, p);
return (PlugSubAlloc(g, p, size));
......
......@@ -4755,6 +4755,9 @@ ha_rows ha_connect::records_in_range(uint inx, key_range *min_key,
else
rows= HA_POS_ERROR;
if (trace)
htrc("records_in_range: rows=%llu\n", rows);
DBUG_RETURN(rows);
} // end of records_in_range
......@@ -5524,9 +5527,10 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#if defined(ODBC_SUPPORT)
if (ttp == TAB_ODBC) {
int plgtyp;
bool w= false; // Wide character type
// typ must be PLG type, not SQL type
if (!(plgtyp= TranslateSQLType(typ, dec, prec, v))) {
if (!(plgtyp= TranslateSQLType(typ, dec, prec, v, w))) {
if (GetTypeConv() == TPC_SKIP) {
// Skip this column
sprintf(g->Message, "Column %s skipped (unsupported type %d)",
......@@ -5543,6 +5547,13 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
typ= plgtyp;
switch (typ) {
case TYPE_STRING:
if (w) {
sprintf(g->Message, "Column %s is wide characters", cnm);
push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, 0, g->Message);
} // endif w
break;
case TYPE_DOUBLE:
// Some data sources do not count dec in length (prec)
prec += (dec + 2); // To be safe
......
......@@ -116,16 +116,24 @@ static int GetSQLCType(int type)
/***********************************************************************/
/* TranslateSQLType: translate a SQL Type to a PLG type. */
/***********************************************************************/
int TranslateSQLType(int stp, int prec, int& len, char& v)
int TranslateSQLType(int stp, int prec, int& len, char& v, bool& w)
{
int type;
switch (stp) {
case SQL_WVARCHAR: // (-9)
w = true;
case SQL_VARCHAR: // 12
v = 'V';
type = TYPE_STRING;
break;
case SQL_WCHAR: // (-8)
w = true;
case SQL_CHAR: // 1
type = TYPE_STRING;
break;
case SQL_WLONGVARCHAR: // (-10)
w = true;
case SQL_LONGVARCHAR: // (-1)
v = 'V';
type = TYPE_STRING;
......@@ -180,7 +188,6 @@ int TranslateSQLType(int stp, int prec, int& len, char& v)
case SQL_BINARY: // (-2)
case SQL_VARBINARY: // (-3)
case SQL_LONGVARBINARY: // (-4)
// case SQL_BIT: // (-7)
case SQL_GUID: // (-11)
default:
type = TYPE_ERROR;
......@@ -410,6 +417,7 @@ PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src, POPARM sop)
PQRYRES MyODBCCols(PGLOBAL g, char *dsn, char *tab, bool info)
{
// int i, type, len, prec;
bool w = false;
// PCOLRES crp, crpt, crpl, crpp;
PQRYRES qrp;
ODBConn *ocp;
......@@ -455,7 +463,7 @@ PQRYRES MyODBCCols(PGLOBAL g, char *dsn, char *tab, bool info)
type = crpt->Kdata->GetIntValue(i);
len = crpl->Kdata->GetIntValue(i);
prec = crpp->Kdata->GetIntValue(i);
type = TranslateSQLType(type, prec, len);
type = TranslateSQLType(type, prec, len, w);
crpt->Kdata->SetValue(type, i);
// Some data sources do not count prec in length
......
......@@ -502,7 +502,7 @@ void *PlugSubAlloc(PGLOBAL g, void *memp, size_t size)
size = ((size + 7) / 8) * 8; /* Round up size to multiple of 8 */
pph = (PPOOLHEADER)memp;
if (trace > 2)
if (trace > 3)
htrc("SubAlloc in %p size=%d used=%d free=%d\n",
memp, size, pph->To_Free, pph->FreeBlk);
......@@ -526,7 +526,7 @@ void *PlugSubAlloc(PGLOBAL g, void *memp, size_t size)
pph->To_Free += size; /* New offset of pool free block */
pph->FreeBlk -= size; /* New size of pool free block */
if (trace > 2)
if (trace > 3)
htrc("Done memp=%p used=%d free=%d\n",
memp, pph->To_Free, pph->FreeBlk);
......
......@@ -36,8 +36,9 @@ typedef struct _datpar *PDTP; // For DTVAL
DllExport PSZ GetTypeName(int);
DllExport int GetTypeSize(int, int);
#ifdef ODBC_SUPPORT
/* This function is exported for use in EOM table type DLLs */
DllExport int TranslateSQLType(int stp, int prec, int& len, char& v);
/* This function is exported for use in OEM table type DLLs */
DllExport int TranslateSQLType(int stp, int prec,
int& len, char& v, bool& w);
#endif
DllExport char *GetFormatType(int);
DllExport int GetFormatType(char);
......
......@@ -340,6 +340,9 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
} // endif n
if (trace)
htrc("XINDEX Make: n=%d\n", n);
// File position must be stored
Record.Size = n * sizeof(int);
......@@ -477,6 +480,9 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
} else
To_Rec[nkey] = Tdbp->GetRecpos();
if (trace > 1)
htrc("Make: To_Rec[%d]=%d\n", nkey, To_Rec[nkey]);
/*******************************************************************/
/* Get the keys and place them in the key blocks. */
/*******************************************************************/
......@@ -1759,6 +1765,9 @@ int XINDEX::Fetch(PGLOBAL g)
if (Num_K == 0)
return -1; // means end of file
if (trace > 1)
htrc("XINDEX Fetch: Op=%d\n", Op);
/*********************************************************************/
/* Table read through a sorted index. */
/*********************************************************************/
......@@ -1776,9 +1785,6 @@ int XINDEX::Fetch(PGLOBAL g)
break;
case OP_SAME: // Read next same
// Logically the key values should be the same as before
if (trace > 1)
htrc("looking for next same value\n");
if (NextVal(true)) {
Op = OP_EQ;
return -2; // no more equal values
......@@ -1824,7 +1830,7 @@ int XINDEX::Fetch(PGLOBAL g)
Nth++;
if (trace > 1)
htrc("Fetch: Looking for new value\n");
htrc("Fetch: Looking for new value Nth=%d\n", Nth);
Cur_K = FastFind();
......@@ -1896,6 +1902,10 @@ int XINDEX::FastFind(void)
sup = To_KeyCol->Ndf;
} // endif Nblk
if (trace > 2)
htrc("XINDEX FastFind: Nblk=%d Op=%d inf=%d sup=%d\n",
Nblk, Op, inf, sup);
for (k = 0, kcp = To_KeyCol; kcp; kcp = kcp->Next) {
while (sup - inf > 1) {
i = (inf + sup) >> 1;
......@@ -1970,6 +1980,9 @@ int XINDEX::FastFind(void)
curk = (kcp->Kof) ? kcp->Kof[kcp->Val_K] : kcp->Val_K;
} // endfor kcp
if (trace > 2)
htrc("XINDEX FastFind: curk=%d\n", curk);
return curk;
} // end of FastFind
......@@ -2043,8 +2056,7 @@ int XINDXS::GroupSize(void)
#if defined(_DEBUG)
assert(To_KeyCol->Val_K >= 0 && To_KeyCol->Val_K < Ndif);
#endif // _DEBUG
return (Pof) ? Pof[To_KeyCol->Val_K + 1] - Pof[To_KeyCol->Val_K]
: 1;
return (Pof) ? Pof[To_KeyCol->Val_K + 1] - Pof[To_KeyCol->Val_K] : 1;
} // end of GroupSize
/***********************************************************************/
......@@ -2106,6 +2118,9 @@ int XINDXS::Fetch(PGLOBAL g)
if (Num_K == 0)
return -1; // means end of file
if (trace > 1)
htrc("XINDXS Fetch: Op=%d\n", Op);
/*********************************************************************/
/* Table read through a sorted index. */
/*********************************************************************/
......@@ -2120,9 +2135,6 @@ int XINDXS::Fetch(PGLOBAL g)
Op = OP_NEXT;
break;
case OP_SAME: // Read next same
if (trace > 1)
htrc("looking for next same value\n");
if (!Mul || NextVal(true)) {
Op = OP_EQ;
return -2; // No more equal values
......@@ -2160,7 +2172,7 @@ int XINDXS::Fetch(PGLOBAL g)
Nth++;
if (trace > 1)
htrc("Fetch: Looking for new value\n");
htrc("Fetch: Looking for new value Nth=%d\n", Nth);
Cur_K = FastFind();
......@@ -2215,7 +2227,6 @@ int XINDXS::FastFind(void)
if (inf < 0)
return Num_K;
// i = inf;
inf *= Sblk;
if ((sup = inf + Sblk) > Ndif)
......@@ -2227,6 +2238,10 @@ int XINDXS::FastFind(void)
sup = Ndif;
} // endif Nblk
if (trace > 2)
htrc("XINDXS FastFind: Nblk=%d Op=%d inf=%d sup=%d\n",
Nblk, Op, inf, sup);
while (sup - inf > 1) {
i = (inf + sup) >> 1;
......@@ -2249,6 +2264,9 @@ int XINDXS::FastFind(void)
n = 0;
} // endif sup
if (trace > 2)
htrc("XINDXS FastFind: n=%d i=%d\n", n, i);
// Loop on kcp because of dynamic indexing
for (; kcp; kcp = kcp->Next)
kcp->Val_K = i; // Used by FillValue
......@@ -2330,6 +2348,10 @@ bool XFILE::Open(PGLOBAL g, char *filename, int id, MODE mode)
} // endif
NewOff.Low = (int)ftell(Xfile);
if (trace)
htrc("XFILE Open: NewOff.Low=%d\n", NewOff.Low);
} else if (mode == MODE_WRITE) {
if (id >= 0) {
// New not sep index file. Write the header.
......@@ -2337,6 +2359,10 @@ bool XFILE::Open(PGLOBAL g, char *filename, int id, MODE mode)
Write(g, noff, sizeof(IOFF), MAX_INDX, rc);
fseek(Xfile, 0, SEEK_END);
NewOff.Low = (int)ftell(Xfile);
if (trace)
htrc("XFILE Open: NewOff.Low=%d\n", NewOff.Low);
} // endif id
} else if (mode == MODE_READ && id >= 0) {
......@@ -2346,6 +2372,9 @@ bool XFILE::Open(PGLOBAL g, char *filename, int id, MODE mode)
return true;
} // endif MAX_INDX
if (trace)
htrc("XFILE Open: noff[%d].Low=%d\n", id, noff[id].Low);
// Position the cursor at the offset of this index
if (fseek(Xfile, noff[id].Low, SEEK_SET)) {
sprintf(g->Message, MSG(FUNC_ERRNO), errno, "Xseek");
......@@ -3158,12 +3187,18 @@ bool KXYCOL::InitFind(PGLOBAL g, PXOB xp)
xp->Reset();
xp->Eval(g);
Valp->SetValue_pval(xp->GetValue(), false);
// Valp->SetValue_pval(xp->GetValue(), !Prefix);
} // endif Type
if (trace > 1) {
char buf[32];
htrc("KCOL InitFind: value=%s\n", Valp->GetCharString(buf));
} // endif trace
return false;
} // end of InitFind
#if 0
/***********************************************************************/
/* InitBinFind: initialize Value to the value pointed by vp. */
/***********************************************************************/
......@@ -3171,6 +3206,7 @@ void KXYCOL::InitBinFind(void *vp)
{
Valp->SetBinValue(vp);
} // end of InitBinFind
#endif // 0
/***********************************************************************/
/* KXYCOL FillValue: called by COLBLK::Eval when a column value is */
......
......@@ -462,7 +462,7 @@ class KXYCOL: public BLOCK {
virtual void FreeData(void);
virtual void FillValue(PVAL valp);
virtual int CompVal(int i);
void InitBinFind(void *vp);
// void InitBinFind(void *vp);
bool MakeBlockArray(PGLOBAL g, int nb, int size);
int Compare(int i1, int i2);
int CompBval(int i);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment