Skip to content

Commit

Permalink
- Set connection charset before calling mysql_real_connect for MYSQL
Browse files Browse the repository at this point in the history
  tables. This should fix bug MDEV-7343.
modified:
  storage/connect/ha_connect.cc
  storage/connect/myconn.cpp
  storage/connect/myconn.h
  storage/connect/reldef.cpp
  storage/connect/reldef.h
  storage/connect/table.cpp
  storage/connect/tabmysql.cpp
  storage/connect/xtable.h

- Prevent double column evaluation when CONNECT does filtering
modified:
  storage/connect/connect.cc

- Export CreateFileMap and CloseMemMap (for OEM tables)
modified:
  storage/connect/maputil.h

- Add the compute function to be used on VALUE types.
  Preserve precision for DOUBLE values.
modified:
  storage/connect/value.cpp
  storage/connect/value.h

- Typo (in preparation to the future JSON table type)
modified:
  storage/connect/ha_connect.cc
  storage/connect/mycat.cc
  storage/connect/plgdbsem.h
  • Loading branch information
Buggynours committed Jan 6, 2015
1 parent 8761f22 commit afd373c
Show file tree
Hide file tree
Showing 14 changed files with 305 additions and 26 deletions.
15 changes: 10 additions & 5 deletions storage/connect/connect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
/* Routines called internally by semantic routines. */
/***********************************************************************/
void CntEndDB(PGLOBAL);
RCODE EvalColumns(PGLOBAL g, PTDB tdbp, bool mrr= false);
RCODE EvalColumns(PGLOBAL g, PTDB tdbp, bool reset, bool mrr= false);

/***********************************************************************/
/* MySQL routines called externally by semantic routines. */
Expand Down Expand Up @@ -388,7 +388,7 @@ bool CntRewindTable(PGLOBAL g, PTDB tdbp)
/***********************************************************************/
/* Evaluate all columns after a record is read. */
/***********************************************************************/
RCODE EvalColumns(PGLOBAL g, PTDB tdbp, bool mrr)
RCODE EvalColumns(PGLOBAL g, PTDB tdbp, bool reset, bool mrr)
{
RCODE rc= RC_OK;
PCOL colp;
Expand All @@ -413,7 +413,8 @@ RCODE EvalColumns(PGLOBAL g, PTDB tdbp, bool mrr)

for (colp= tdbp->GetColumns(); rc == RC_OK && colp;
colp= colp->GetNext()) {
colp->Reset();
if (reset)
colp->Reset();

// Virtual columns are computed by MariaDB
if (!colp->GetColUse(U_VIRTUAL) && (!mrr || colp->GetKcol()))
Expand Down Expand Up @@ -457,6 +458,10 @@ RCODE CntReadNext(PGLOBAL g, PTDB tdbp)
goto err;
} // endif rc

// Do it now to avoid double eval when filtering
for (PCOL colp= tdbp->GetColumns(); colp; colp= colp->GetNext())
colp->Reset();

do {
if ((rc= (RCODE)tdbp->ReadDB(g)) == RC_OK)
if (!ApplyFilter(g, tdbp->GetFilter()))
Expand All @@ -466,7 +471,7 @@ RCODE CntReadNext(PGLOBAL g, PTDB tdbp)

err:
g->jump_level--;
return (rc != RC_OK) ? rc : EvalColumns(g, tdbp);
return (rc != RC_OK) ? rc : EvalColumns(g, tdbp, false);
} // end of CntReadNext

/***********************************************************************/
Expand Down Expand Up @@ -812,7 +817,7 @@ RCODE CntIndexRead(PGLOBAL g, PTDB ptdb, OPVAL op,

rnd:
if ((rc= (RCODE)ptdb->ReadDB(g)) == RC_OK)
rc= EvalColumns(g, ptdb, mrr);
rc= EvalColumns(g, ptdb, true, mrr);

return rc;
} // end of CntIndexRead
Expand Down
9 changes: 9 additions & 0 deletions storage/connect/ha_connect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,14 @@ char *ha_connect::GetStringOption(char *opname, char *sdef)
opval= (char*)options->colist;
else if (!stricmp(opname, "Data_charset"))
opval= (char*)options->data_charset;
else if (!stricmp(opname, "Table_charset")) {
const CHARSET_INFO *chif= (tshp) ? tshp->table_charset
: table->s->table_charset;

if (chif)
opval= (char*)chif->csname;

} // endif Table_charset

if (!opval && options && options->oplist)
opval= GetListOption(xp->g, opname, options->oplist);
Expand Down Expand Up @@ -3806,6 +3814,7 @@ bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn)
case TAB_XML:
case TAB_INI:
case TAB_VEC:
// case TAB_JSON:
if (options->filename && *options->filename) {
char *s, path[FN_REFLEN], dbpath[FN_REFLEN];
#if defined(WIN32)
Expand Down
4 changes: 2 additions & 2 deletions storage/connect/maputil.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ typedef struct {
DWORD lenH;
} MEMMAP;

HANDLE CreateFileMap(PGLOBAL, LPCSTR, MEMMAP *, MODE, bool);
bool CloseMemMap(void *memory, size_t dwSize);
DllExport HANDLE CreateFileMap(PGLOBAL, LPCSTR, MEMMAP *, MODE, bool);
DllExport bool CloseMemMap(void *memory, size_t dwSize);

#ifdef __cplusplus
}
Expand Down
11 changes: 8 additions & 3 deletions storage/connect/mycat.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) Olivier Bertrand 2004 - 2013
/* Copyright (C) Olivier Bertrand 2004 - 2014
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -18,7 +18,7 @@
/* ------------- */
/* Version 1.4 */
/* */
/* Author: Olivier Bertrand 2012 - 2013 */
/* Author: Olivier Bertrand 2012 - 2014 */
/* */
/* WHAT THIS PROGRAM DOES: */
/* ----------------------- */
Expand Down Expand Up @@ -89,6 +89,7 @@
#include "tabpivot.h"
#endif // PIVOT_SUPPORT
#include "tabvir.h"
//#include "tabjson.h"
#include "ha_connect.h"
#include "mycat.h"

Expand Down Expand Up @@ -139,6 +140,7 @@ TABTYPE GetTypeID(const char *type)
: (!stricmp(type, "PIVOT")) ? TAB_PIVOT
#endif
: (!stricmp(type, "VIR")) ? TAB_VIR
// : (!stricmp(type, "JSON")) ? TAB_JSON
: (!stricmp(type, "OEM")) ? TAB_OEM : TAB_NIY;
} // end of GetTypeID

Expand All @@ -159,6 +161,7 @@ bool IsFileType(TABTYPE type)
case TAB_XML:
case TAB_INI:
case TAB_VEC:
// case TAB_JSON:
isfile= true;
break;
default:
Expand All @@ -181,6 +184,7 @@ bool IsExactType(TABTYPE type)
case TAB_BIN:
case TAB_DBF:
// case TAB_XML: depends on Multiple || Xpand || Coltype
// case TAB_JSON: depends on Multiple || Xpand || Coltype
case TAB_VEC:
case TAB_VIR:
exact= true;
Expand Down Expand Up @@ -214,7 +218,7 @@ bool IsTypeNullable(TABTYPE type)
} // end of IsTypeNullable

/***********************************************************************/
/* Return true for indexable table by XINDEX. */
/* Return true for fixed record length tables. */
/***********************************************************************/
bool IsTypeFixed(TABTYPE type)
{
Expand Down Expand Up @@ -538,6 +542,7 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am)
case TAB_PIVOT: tdp= new(g) PIVOTDEF; break;
#endif // PIVOT_SUPPORT
case TAB_VIR: tdp= new(g) VIRDEF; break;
// case TAB_JSON: tdp= new(g) JSONDEF; break;
default:
sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name);
} // endswitch
Expand Down
17 changes: 15 additions & 2 deletions storage/connect/myconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,11 @@ int MYSQLC::GetResultSize(PGLOBAL g, PSZ sql)
/***********************************************************************/
int MYSQLC::Open(PGLOBAL g, const char *host, const char *db,
const char *user, const char *pwd,
int pt)
int pt, const char *csname)
{
const char *pipe = NULL;
uint cto = 6000, nrt = 12000;
uint cto = 6000, nrt = 12000;
my_bool my_true= 1;

m_DB = mysql_init(NULL);

Expand Down Expand Up @@ -470,6 +471,18 @@ int MYSQLC::Open(PGLOBAL g, const char *host, const char *db,
} // endif pwd
#endif // 0

/***********************************************************************/
/* BUG# 17044 Federated Storage Engine is not UTF8 clean */
/* Add set names to whatever charset the table is at open of table */
/* this sets the csname like 'set names utf8'. */
/***********************************************************************/
if (csname)
mysql_options(m_DB, MYSQL_SET_CHARSET_NAME, csname);

// Don't know what this one do but FEDERATED does it
mysql_options(m_DB, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY,
(char*)&my_true);

if (!mysql_real_connect(m_DB, host, user, pwd, db, pt, pipe, CLIENT_MULTI_RESULTS)) {
#if defined(_DEBUG)
sprintf(g->Message, "mysql_real_connect failed: (%d) %s",
Expand Down
3 changes: 2 additions & 1 deletion storage/connect/myconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DllItem MYSQLC {
int GetTableSize(PGLOBAL g, PSZ query);
int Open(PGLOBAL g, const char *host, const char *db,
const char *user= "root", const char *pwd= "*",
int pt= 0);
int pt= 0, const char *csname = NULL);
int KillQuery(ulong id);
int ExecSQL(PGLOBAL g, const char *query, int *w = NULL);
int ExecSQLcmd(PGLOBAL g, const char *query, int *w);
Expand Down Expand Up @@ -98,5 +98,6 @@ class DllItem MYSQLC {
int m_Fields; // The number of result fields
int m_Afrw; // The number of affected rows
bool m_Use; // Use or store result set
const char *csname; // Table charset name
}; // end of class MYSQLC

8 changes: 5 additions & 3 deletions storage/connect/plgdbsem.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ enum TABTYPE {TAB_UNDEF = 0, /* Table of undefined type */
TAB_PLG = 20, /* PLG NIY */
TAB_PIVOT = 21, /* PIVOT table */
TAB_VIR = 22, /* Virtual tables */
TAB_JCT = 23, /* Junction tables NIY */
TAB_DMY = 24, /* DMY Dummy tables NIY */
TAB_NIY = 25}; /* Table not implemented yet */
TAB_JSON = 23, /* JSON tables */
TAB_JSN = 24, /* Semi-json tables */
TAB_JCT = 25, /* Junction tables NIY */
TAB_DMY = 26, /* DMY Dummy tables NIY */
TAB_NIY = 27}; /* Table not implemented yet */

enum AMT {TYPE_AM_ERROR = 0, /* Type not defined */
TYPE_AM_ROWID = 1, /* ROWID type (special column) */
Expand Down
3 changes: 3 additions & 0 deletions storage/connect/reldef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ TABDEF::TABDEF(void)
Degree = 0;
Pseudo = 0;
Read_Only = false;
m_data_charset = NULL;
csname = NULL;
} // end of TABDEF constructor

/***********************************************************************/
Expand All @@ -224,6 +226,7 @@ bool TABDEF::Define(PGLOBAL g, PCATLG cat, LPCSTR name, LPCSTR am)
m_data_charset= data_charset_name ?
get_charset_by_csname(data_charset_name, MY_CS_PRIMARY, 0):
NULL;
csname = GetStringCatInfo(g, "Table_charset", NULL);

// Get The column definitions
if ((poff = GetColCatInfo(g)) < 0)
Expand Down
2 changes: 2 additions & 0 deletions storage/connect/reldef.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class DllExport TABDEF : public RELDEF { /* Logical table descriptor */
friend class CATALOG;
friend class PLUGCAT;
friend class MYCAT;
friend class TDBASE;
public:
// Constructor
TABDEF(void); // Constructor
Expand Down Expand Up @@ -110,6 +111,7 @@ class DllExport TABDEF : public RELDEF { /* Logical table descriptor */
int Pseudo; /* Bit: 1 ROWID Ok, 2 FILEID Ok */
bool Read_Only; /* true for read only tables */
const CHARSET_INFO *m_data_charset;
const char *csname; /* Table charset name */
}; // end of TABDEF

/***********************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions storage/connect/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ TDBASE::TDBASE(PTABDEF tdp) : TDB(tdp)
Knum = 0;
Read_Only = (tdp) ? tdp->IsReadOnly() : false;
m_data_charset= (tdp) ? tdp->data_charset() : NULL;
csname = (tdp) ? tdp->csname : NULL;
} // end of TDBASE constructor

TDBASE::TDBASE(PTDBASE tdbp) : TDB(tdbp)
Expand All @@ -161,6 +162,7 @@ TDBASE::TDBASE(PTDBASE tdbp) : TDB(tdbp)
Knum = tdbp->Knum;
Read_Only = tdbp->Read_Only;
m_data_charset= tdbp->m_data_charset;
csname = tdbp->csname;
} // end of TDBASE copy constructor

/***********************************************************************/
Expand Down
4 changes: 2 additions & 2 deletions storage/connect/tabmysql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ int TDBMYSQL::Cardinality(PGLOBAL g)
char query[96];
MYSQLC myc;

if (myc.Open(g, Host, Database, User, Pwd, Port))
if (myc.Open(g, Host, Database, User, Pwd, Port, csname))
return -1;

strcpy(query, "SELECT COUNT(*) FROM ");
Expand Down Expand Up @@ -871,7 +871,7 @@ bool TDBMYSQL::OpenDB(PGLOBAL g)
/* servers allowing concurency in getting results ??? */
/*********************************************************************/
if (!Myc.Connected()) {
if (Myc.Open(g, Host, Database, User, Pwd, Port))
if (Myc.Open(g, Host, Database, User, Pwd, Port, csname))
return true;

} // endif Connected
Expand Down
Loading

0 comments on commit afd373c

Please sign in to comment.