summaryrefslogtreecommitdiff
path: root/storage/connect/tabutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'storage/connect/tabutil.cpp')
-rw-r--r--storage/connect/tabutil.cpp69
1 files changed, 36 insertions, 33 deletions
diff --git a/storage/connect/tabutil.cpp b/storage/connect/tabutil.cpp
index d469594916f..331a7f45d4d 100644
--- a/storage/connect/tabutil.cpp
+++ b/storage/connect/tabutil.cpp
@@ -1,7 +1,7 @@
/************* Tabutil cpp Declares Source Code File (.CPP) ************/
-/* Name: TABUTIL.CPP Version 1.0 */
+/* Name: TABUTIL.CPP Version 1.1 */
/* */
-/* (C) Copyright to the author Olivier BERTRAND 2013 */
+/* (C) Copyright to the author Olivier BERTRAND 2013 - 2015 */
/* */
/* Utility function used by the PROXY, XCOL, OCCUR, and TBL tables. */
/***********************************************************************/
@@ -9,11 +9,12 @@
/***********************************************************************/
/* Include relevant section of system dependant header files. */
/***********************************************************************/
-#include "my_global.h"
+#define MYSQL_SERVER 1
+#include <my_global.h>
#include "sql_class.h"
#include "table.h"
#include "field.h"
-#if defined(WIN32)
+#if defined(__WIN__)
#include <stdlib.h>
#include <stdio.h>
#if defined(__BORLANDC__)
@@ -42,19 +43,16 @@
#include "plgdbsem.h"
#include "plgcnx.h" // For DB types
#include "myutil.h"
-#include "mycat.h"
#include "valblk.h"
#include "resource.h"
#include "reldef.h"
#include "xtable.h"
-#if defined(MYSQL_SUPPORT)
#include "tabmysql.h"
-#endif // MYSQL_SUPPORT
#include "tabcol.h"
#include "tabutil.h"
#include "ha_connect.h"
-extern "C" int zconv;
+int GetConvSize(void);
/************************************************************************/
/* Used by MYSQL tables to get MySQL parameters from the calling proxy */
@@ -73,11 +71,8 @@ TABLE_SHARE *GetTableShare(PGLOBAL g, THD *thd, const char *db,
{
char key[256];
uint k;
-//TABLE_LIST table_list;
TABLE_SHARE *s;
-//table_list.init_one_table(db, strlen(db), name, strlen(name),
-// NULL, TL_IGNORE);
k = sprintf(key, "%s", db) + 1;
k += sprintf(key + k, "%s", name);
key[++k] = 0;
@@ -87,26 +82,20 @@ TABLE_SHARE *GetTableShare(PGLOBAL g, THD *thd, const char *db,
return NULL;
} // endif s
-// 1 2 4 8
-//flags = GTS_TABLE | GTS_VIEW | GTS_NOLOCK | GTS_FORCE_DISCOVERY;
-
if (!open_table_def(thd, s, GTS_TABLE | GTS_VIEW)) {
if (!s->is_view) {
- if (stricmp(plugin_name(s->db_plugin)->str, "connect")) {
-#if defined(MYSQL_SUPPORT)
+ if (stricmp(plugin_name(s->db_plugin)->str, "connect"))
mysql = true;
-#else // !MYSQL_SUPPORT
- sprintf(g->Message, "%s.%s is not a CONNECT table", db, name);
- return NULL;
-#endif // MYSQL_SUPPORT
- } else
+ else
mysql = false;
- } else {
+ } else
mysql = true;
- } // endif is_view
} else {
+ if (thd->is_error())
+ thd->clear_error(); // Avoid stopping info commands
+
sprintf(g->Message, "Error %d opening share\n", s->error);
free_table_share(s);
return NULL;
@@ -132,6 +121,7 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
char *fld, *colname, *chset, *fmt, v;
int i, n, ncol = sizeof(buftyp) / sizeof(int);
int prec, len, type, scale;
+ int zconv = GetConvSize();
bool mysql;
TABLE_SHARE *s = NULL;
Field* *field;
@@ -302,7 +292,7 @@ PRXDEF::PRXDEF(void)
/***********************************************************************/
/* DefineAM: define specific AM block values from XCOL file. */
/***********************************************************************/
-bool PRXDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
+bool PRXDEF::DefineAM(PGLOBAL g, LPCSTR, int)
{
char *pn, *db, *tab, *def = NULL;
@@ -332,7 +322,7 @@ bool PRXDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
/***********************************************************************/
/* GetTable: makes a new TDB of the proper type. */
/***********************************************************************/
-PTDB PRXDEF::GetTable(PGLOBAL g, MODE mode)
+PTDB PRXDEF::GetTable(PGLOBAL g, MODE)
{
if (Catfunc == FNC_COL)
return new(g) TDBTBC(this);
@@ -351,7 +341,7 @@ TDBPRX::TDBPRX(PPRXDEF tdp) : TDBASE(tdp)
Tdbp = NULL; // The object table
} // end of TDBPRX constructor
-TDBPRX::TDBPRX(PGLOBAL g, PTDBPRX tdbp) : TDBASE(tdbp)
+TDBPRX::TDBPRX(PTDBPRX tdbp) : TDBASE(tdbp)
{
Tdbp = tdbp->Tdbp;
} // end of TDBPRX copy constructor
@@ -363,7 +353,7 @@ PTDB TDBPRX::CopyOne(PTABS t)
PPRXCOL cp1, cp2;
PGLOBAL g = t->G;
- tp = new(g) TDBPRX(g, this);
+ tp = new(g) TDBPRX(this);
for (cp1 = (PPRXCOL)Columns; cp1; cp1 = (PPRXCOL)cp1->GetNext()) {
cp2 = new(g) PRXCOL(cp1, tp); // Make a copy
@@ -422,7 +412,6 @@ PTDBASE TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp, bool b)
} // endif srcdef
if (mysql) {
-#if defined(MYSQL_SUPPORT)
// Access sub-table via MySQL API
if (!(tdbp= cat->GetTable(g, tabp, Mode, "MYPRX"))) {
char buf[MAX_STR];
@@ -439,11 +428,6 @@ PTDBASE TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp, bool b)
if (Mode == MODE_UPDATE || Mode == MODE_DELETE)
tdbp->SetName(Name); // For Make_Command
-#else // !MYSQL_SUPPORT
- sprintf(g->Message, "%s.%s is not a CONNECT table",
- db, tblp->Name);
- goto err;
-#endif // MYSQL_SUPPORT
} else {
// Sub-table is a CONNECT table
tabp->Next = To_Table; // For loop checking
@@ -669,6 +653,22 @@ PRXCOL::PRXCOL(PRXCOL *col1, PTDB tdbp) : COLBLK(col1, tdbp)
} // end of PRXCOL copy constructor
/***********************************************************************/
+/* Convert an UTF-8 name to latin characters. */
+/***********************************************************************/
+char *PRXCOL::Decode(PGLOBAL g, const char *cnm)
+ {
+ char *buf= (char*)PlugSubAlloc(g, NULL, strlen(cnm) + 1);
+ uint dummy_errors;
+ uint32 len= copy_and_convert(buf, strlen(cnm) + 1,
+ &my_charset_latin1,
+ cnm, strlen(cnm),
+ &my_charset_utf8_general_ci,
+ &dummy_errors);
+ buf[len]= '\0';
+ return buf;
+ } // end of Decode
+
+/***********************************************************************/
/* PRXCOL initialization routine. */
/* Look for the matching column in the object table. */
/***********************************************************************/
@@ -683,6 +683,9 @@ bool PRXCOL::Init(PGLOBAL g, PTDBASE tp)
if (Colp) {
MODE mode = To_Tdb->GetMode();
+ // Needed for MYSQL subtables
+ ((XCOLBLK*)Colp)->Name = Decode(g, Colp->GetName());
+
// May not have been done elsewhere
Colp->InitValue(g);
To_Val = Colp->GetValue();