From bdbe7430bc16d8cff18733b84de5db62c89ad5d9 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Thu, 27 Mar 2014 19:07:17 +0100 Subject: - Make local MySQL connection default to unix socket on Linux or enable to use named pipe on Windows by specifying the host as '.' This addresses MDEV-5952. modified: storage/connect/myconn.cpp - Clean some unused code modified: storage/connect/connect.cc storage/connect/connect.h storage/connect/ha_connect.cc storage/connect/ha_connect.h --- storage/connect/myconn.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'storage/connect/myconn.cpp') diff --git a/storage/connect/myconn.cpp b/storage/connect/myconn.cpp index 13a6f996605..3d0a3d86136 100644 --- a/storage/connect/myconn.cpp +++ b/storage/connect/myconn.cpp @@ -1,11 +1,11 @@ /************** MyConn C++ Program Source Code File (.CPP) **************/ /* PROGRAM NAME: MYCONN */ /* ------------- */ -/* Version 1.7 */ +/* Version 1.8 */ /* */ /* COPYRIGHT: */ /* ---------- */ -/* (C) Copyright to the author Olivier BERTRAND 2007-2013 */ +/* (C) Copyright to the author Olivier BERTRAND 2007-2014 */ /* */ /* WHAT THIS PROGRAM DOES: */ /* ----------------------- */ @@ -47,7 +47,8 @@ #include "myconn.h" extern "C" int trace; -extern MYSQL_PLUGIN_IMPORT uint mysqld_port; +extern MYSQL_PLUGIN_IMPORT uint mysqld_port; +extern MYSQL_PLUGIN_IMPORT char *mysqld_unix_port; // Returns the current used port uint GetDefaultPort(void) @@ -340,6 +341,7 @@ int MYSQLC::Open(PGLOBAL g, const char *host, const char *db, const char *user, const char *pwd, int pt) { + const char *pipe = NULL; uint cto = 60, nrt = 120; m_DB = mysql_init(NULL); @@ -356,6 +358,16 @@ int MYSQLC::Open(PGLOBAL g, const char *host, const char *db, mysql_options(m_DB, MYSQL_OPT_READ_TIMEOUT, &nrt); //mysql_options(m_DB, MYSQL_OPT_WRITE_TIMEOUT, ...); +#if defined(WIN32) + if (!strcmp(host, ".")) { + mysql_options(m_DB, MYSQL_OPT_NAMED_PIPE, NULL); + pipe = mysqld_unix_port; + } // endif host +#else // !WIN32 + if (!strcmp(host, "localhost")) + pipe = mysqld_unix_port; +#endif // !WIN32 + #if 0 if (pwd && !strcmp(pwd, "*")) { if (GetPromptAnswer(g, "*Enter password:")) { @@ -367,7 +379,7 @@ int MYSQLC::Open(PGLOBAL g, const char *host, const char *db, } // endif pwd #endif // 0 - if (!mysql_real_connect(m_DB, host, user, pwd, db, pt, NULL, CLIENT_MULTI_RESULTS)) { + 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", mysql_errno(m_DB), mysql_error(m_DB)); -- cgit v1.2.1 From fe3cbcdffa6d419bcc3658fb6dda9ea371b19d35 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Sun, 30 Mar 2014 22:52:54 +0200 Subject: - Add system variables type_conv and conv_size. This addresses the eventual conversion from TEXT to VARCHAR in PROXY and MYSQL tables. modified: storage/connect/ha_connect.cc storage/connect/myconn.cpp storage/connect/myconn.h storage/connect/myutil.cpp storage/connect/tabmysql.cpp storage/connect/tabutil.cpp - Add the xmap system variable addressing whether file mapping should be used to handle indexing. modified: storage/connect/CMakeLists.txt storage/connect/ha_connect.cc storage/connect/xindex.cpp storage/connect/xindex.h - Do take care of ~ in Linux version of _fullpath (not tested yet) modified: storage/connect/osutil.c --- storage/connect/myconn.cpp | 47 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) (limited to 'storage/connect/myconn.cpp') diff --git a/storage/connect/myconn.cpp b/storage/connect/myconn.cpp index 3d0a3d86136..e8b72cd3643 100644 --- a/storage/connect/myconn.cpp +++ b/storage/connect/myconn.cpp @@ -47,9 +47,12 @@ #include "myconn.h" extern "C" int trace; +extern "C" int zconv; extern MYSQL_PLUGIN_IMPORT uint mysqld_port; extern MYSQL_PLUGIN_IMPORT char *mysqld_unix_port; +DllExport void PushWarning(PGLOBAL, THD*, int level = 1); + // Returns the current used port uint GetDefaultPort(void) { @@ -61,7 +64,7 @@ uint GetDefaultPort(void) /* of a MySQL table or view. */ /* info = TRUE to get catalog column informations. */ /************************************************************************/ -PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db, +PQRYRES MyColumns(PGLOBAL g, THD *thd, const char *host, const char *db, const char *user, const char *pwd, const char *table, const char *colpat, int port, bool info) @@ -75,7 +78,7 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db, FLD_REM, FLD_NO, FLD_DEFAULT, FLD_EXTRA, FLD_CHARSET}; unsigned int length[] = {0, 4, 16, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0}; - char *fld, *fmt, v, cmd[128], uns[16], zero[16]; + char *fld, *colname, *chset, *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; @@ -144,23 +147,24 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db, /**********************************************************************/ /* Now get the results into blocks. */ /**********************************************************************/ - for (i = 0; i < n; i++) { - if ((rc = myc.Fetch(g, -1) == RC_FX)) { + for (i = 0; i < n; /*i++*/) { + if ((rc = myc.Fetch(g, -1)) == RC_FX) { myc.Close(); return NULL; - } else if (rc == RC_NF) + } else if (rc == RC_EF) break; // Get column name - fld = myc.GetCharField(0); + colname = myc.GetCharField(0); crp = qrp->Colresp; // Column_Name - crp->Kdata->SetValue(fld, i); + crp->Kdata->SetValue(colname, i); // Get type, type name, precision, unsigned and zerofill + chset = myc.GetCharField(2); fld = myc.GetCharField(1); prec = 0; len = 0; - v = 0; + v = (chset && !strcmp(chset, "binary")) ? 'B' : 0; *uns = 0; *zero = 0; @@ -181,11 +185,28 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db, } // endswitch nf if ((type = MYSQLtoPLG(cmd, &v)) == TYPE_ERROR) { - sprintf(g->Message, "Unsupported column type %s", cmd); + if (v == 'K') { + // Skip this column + sprintf(g->Message, "Column %s skipped (unsupported type %s)", + colname, cmd); + PushWarning(g, thd); + continue; + } // endif v + + sprintf(g->Message, "Column %s unsupported type %s", colname, cmd); myc.Close(); return NULL; - } else if (type == TYPE_STRING) - len = min(len, 4096); + } else if (type == TYPE_STRING) { + if (v == 'X') { + len = zconv; + sprintf(g->Message, "Column %s converted to varchar(%d)", + colname, len); + PushWarning(g, thd); + v = 'V'; + } else + len = min(len, 4096); + + } // endif type qrp->Nblin++; crp = crp->Next; // Data_Type @@ -241,8 +262,10 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db, crp->Kdata->SetValue(fld, i); crp = crp->Next; // New (charset) - fld = myc.GetCharField(2); + fld = chset; crp->Kdata->SetValue(fld, i); + + i++; // Can be skipped } // endfor i #if 0 -- cgit v1.2.1