From 5b998bf953af257ac2271a49803b05ed58de7a6b Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Sun, 27 Aug 2017 17:23:27 +0200 Subject: [PATCH] - Fix MDEV-13621 JDBC UPDATE containing single or double quote chars produces wrong result in ha_connect::GetStringOption modified: storage/connect/ha_connect.cc - Begin implement data type BINARY modified: storage/connect/ha_connect.cc modified: storage/connect/myutil.cpp modified: storage/connect/valblk.cpp modified: storage/connect/valblk.h modified: storage/connect/value.cpp - Fix MDEV-12422 CONNECT Engine to support CHECK TABLE Adding a fake check function returning HA_ADMIN_OK. modified: storage/connect/ha_connect.h - Treat TBL (thread) as local when connected to the current server and return by timeout when a TBL remote table connection fail (Thread only) modified: storage/connect/myconn.cpp modified: storage/connect/tabmysql.h modified: storage/connect/tabtbl.cpp modified: storage/connect/tabtbl.h - Update some tests and result files Add test output to tbl_thread.test tryng to understand failure modified: storage/connect/mysql-test/connect/r/tbl_thread.result modified: storage/connect/mysql-test/connect/t/tbl_thread.test modified: storage/connect/mysql-test/connect/r/updelx.result - Add the GetCsName function modified: storage/connect/reldef.h --- storage/connect/ha_connect.cc | 21 +- storage/connect/myconn.cpp | 5 +- .../mysql-test/connect/r/tbl_thread.result | 64 ++- .../mysql-test/connect/r/updelx.result | 474 +++++++++--------- .../mysql-test/connect/t/tbl_thread.test | 48 +- storage/connect/myutil.cpp | 4 +- storage/connect/reldef.h | 1 + storage/connect/tabmysql.h | 1 + storage/connect/tabtbl.cpp | 58 ++- storage/connect/tabtbl.h | 1 + storage/connect/valblk.cpp | 13 +- storage/connect/valblk.h | 6 +- storage/connect/value.cpp | 97 +++- 13 files changed, 484 insertions(+), 309 deletions(-) diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index ab718878da96b..ef46750bcca6d 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -1285,9 +1285,14 @@ PCSZ ha_connect::GetStringOption(PCSZ opname, PCSZ sdef) else opval= GetListOption(xp->g, opname, options->oplist); - } else if (!stricmp(opname, "Query_String")) - opval= thd_query_string(table->in_use)->str; - else if (!stricmp(opname, "Partname")) + } else if (!stricmp(opname, "Query_String")) { +// This escapes everything and returns a wrong query +// opval = thd_query_string(table->in_use)->str; + opval = (PCSZ)PlugSubAlloc(xp->g, NULL, + thd_query_string(table->in_use)->length + 1); + strcpy((char*)opval, thd_query_string(table->in_use)->str); +// sprintf((char*)opval, "%s", thd_query_string(table->in_use)->str); + } else if (!stricmp(opname, "Partname")) opval= partname; else if (!stricmp(opname, "Table_charset")) { const CHARSET_INFO *chif= (tshp) ? tshp->table_charset @@ -1501,8 +1506,9 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf) switch (pcf->Type) { case TYPE_STRING: - // Do something for case - cp= fp->charset()->name; + case TYPE_BIN: + // Do something for case + cp= chset; // Find if collation name ends by _ci if (!strcmp(cp + strlen(cp) - 3, "_ci")) { @@ -2114,6 +2120,11 @@ int ha_connect::MakeRecord(char *buf) charset= tdbp->data_charset(); rc= fp->store(p, strlen(p), charset, CHECK_FIELD_WARN); break; + case TYPE_BIN: + p = value->GetCharValue(); + charset = &my_charset_bin; + rc = fp->store(p, strlen(p), charset, CHECK_FIELD_WARN); + break; case TYPE_DOUBLE: rc= fp->store(value->GetFloatValue()); break; diff --git a/storage/connect/myconn.cpp b/storage/connect/myconn.cpp index d2d55f336112d..08bb24e14dfb6 100644 --- a/storage/connect/myconn.cpp +++ b/storage/connect/myconn.cpp @@ -472,7 +472,7 @@ int MYSQLC::Open(PGLOBAL g, const char *host, const char *db, int pt, const char *csname) { const char *pipe = NULL; - uint cto = 6000, nrt = 12000; + uint cto = 10, nrt = 20; my_bool my_true= 1; m_DB = mysql_init(NULL); @@ -525,7 +525,8 @@ int MYSQLC::Open(PGLOBAL g, const char *host, const char *db, 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 (!mysql_real_connect(m_DB, host, user, pwd, db, pt, pipe, + CLIENT_MULTI_RESULTS | CLIENT_REMEMBER_OPTIONS)) { #if defined(_DEBUG) sprintf(g->Message, "mysql_real_connect failed: (%d) %s", mysql_errno(m_DB), mysql_error(m_DB)); diff --git a/storage/connect/mysql-test/connect/r/tbl_thread.result b/storage/connect/mysql-test/connect/r/tbl_thread.result index e3be49dd5cbac..5fafb2a8a5223 100644 --- a/storage/connect/mysql-test/connect/r/tbl_thread.result +++ b/storage/connect/mysql-test/connect/r/tbl_thread.result @@ -28,6 +28,22 @@ a b 9 test09 10 test10 11 test11 +CREATE TABLE rt4 (a int, b char(10)); +INSERT INTO rt4 VALUES (12,'test12'),(13,'test13'),(14,'test14'),(15,'test15'); +SELECT * FROM rt4; +a b +12 test12 +13 test13 +14 test14 +15 test15 +CREATE TABLE rt5 (a int, b char(10)); +INSERT INTO rt5 VALUES (16,'test16'),(17,'test17'),(18,'test18'),(19,'test19'); +SELECT * FROM rt5; +a b +16 test16 +17 test17 +18 test18 +19 test19 CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL CONNECTION='mysql://root@127.0.0.1:MASTER_PORT/test/rt2'; SELECT * FROM t2; @@ -44,11 +60,35 @@ a b 9 test09 10 test10 11 test11 +CREATE TABLE t4 ENGINE=CONNECT TABLE_TYPE=MYSQL +CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/test/rt4'; +SELECT * FROM t4; +a b +12 test12 +13 test13 +14 test14 +15 test15 +CREATE TABLE t5 ENGINE=CONNECT TABLE_TYPE=MYSQL +CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/test/rt5'; +SELECT * FROM t5; +a b +16 test16 +17 test17 +18 test18 +19 test19 CREATE TABLE total (a int, b char(10)) -ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2,t3' +ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2,t3,t4,t5' OPTION_LIST='thread=yes,port=PORT'; SELECT * FROM total order by a desc; a b +19 test19 +18 test18 +17 test17 +16 test16 +15 test15 +14 test14 +13 test13 +12 test12 11 test11 10 test10 9 test09 @@ -62,8 +102,8 @@ a b 1 test01 0 test00 DROP TABLE rt2; -DROP TABLE rt3; -DROP TABLE t1,t2,t3,total; +DROP TABLE rt3,rt4,rt5; +DROP TABLE t1,t2,t3,t4,t5,total; # # Old thread TBL tables test modified # @@ -84,6 +124,24 @@ DROP TABLE t1,t2,total; # # Old thread TBL tables test not modified (suppressed until MDEV-10179 is fixed) # +CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL SRCDEF='select 11 as v'; +SELECT * FROM t1; +v +11 +CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL SRCDEF='select 22 as v'; +SELECT * FROM t2; +v +22 +CREATE TABLE total (v BIGINT(20) UNSIGNED NOT NULL) ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2' OPTION_LIST='thread=yes,port=PORT';; +set connect_xtrace=1; +SELECT * FROM total order by v desc; +v +22 +11 +set connect_xtrace=0; +DROP TABLE total; +DROP TABLE t1; +DROP TABLE t2; DROP TABLE IF EXISTS connect.t1; DROP DATABASE IF EXISTS connect; DROP TABLE IF EXISTS connect.t1; diff --git a/storage/connect/mysql-test/connect/r/updelx.result b/storage/connect/mysql-test/connect/r/updelx.result index 2aed1e0692820..4b8441a6cdee6 100644 --- a/storage/connect/mysql-test/connect/r/updelx.result +++ b/storage/connect/mysql-test/connect/r/updelx.result @@ -986,108 +986,108 @@ DELETE FROM t1; INSERT INTO t1 VALUES(4, 'four'),(7,'seven'),(10,'ten'),(40,'forty'),(60,'sixty'),(81,'eighty one'),(72,'seventy two'),(11,'eleven'),(1,'one'),(35,'thirty five'),(8,'eight'); SELECT * FROM t1; id msg -4 four -7 seven -10 ten -40 forty -60 sixty -81 eighty one -72 seventy two -11 eleven -1 one -35 thirty five -8 eight +4 four +7 seven +10 ten +40 forty +60 sixty +81 eighty one +72 seventy two +11 eleven +1 one +35 thirty five +8 eight UPDATE t1 SET msg = 'bof' WHERE id = 35; SELECT * FROM t1; id msg -4 four -7 seven -10 ten -40 forty -60 sixty -81 eighty one -72 seventy two -11 eleven -1 one -35 bof -8 eight +4 four +7 seven +10 ten +40 forty +60 sixty +81 eighty one +72 seventy two +11 eleven +1 one +35 bof +8 eight UPDATE t1 SET msg = 'big' WHERE id > 50; SELECT * FROM t1; id msg -4 four -7 seven -10 ten -40 forty -60 big -81 big -72 big -11 eleven -1 one -35 bof -8 eight +4 four +7 seven +10 ten +40 forty +60 big +81 big +72 big +11 eleven +1 one +35 bof +8 eight UPDATE t1 SET msg = 'updated' WHERE id IN (8,35,60,72); SELECT * FROM t1; id msg -4 four -7 seven -10 ten -40 forty -60 updated -81 big -72 updated -11 eleven -1 one -35 updated -8 updated +4 four +7 seven +10 ten +40 forty +60 updated +81 big +72 updated +11 eleven +1 one +35 updated +8 updated UPDATE t1 SET msg = 'twin' WHERE id IN (81,10); SELECT * FROM t1; id msg -4 four -7 seven -10 twin -40 forty -60 updated -81 twin -72 updated -11 eleven -1 one -35 updated -8 updated +4 four +7 seven +10 twin +40 forty +60 updated +81 twin +72 updated +11 eleven +1 one +35 updated +8 updated UPDATE t1 SET msg = 'sixty' WHERE id = 60; SELECT * FROM t1 WHERE id = 60; id msg -60 sixty +60 sixty DELETE FROM t1 WHERE id = 4; SELECT * FROM t1; id msg -7 seven -10 twin -40 forty -60 sixty -81 twin -72 updated -11 eleven -1 one -35 updated -8 updated +7 seven +10 twin +40 forty +60 sixty +81 twin +72 updated +11 eleven +1 one +35 updated +8 updated DELETE FROM t1 WHERE id IN (40,11,35); SELECT * FROM t1; id msg -7 seven -10 twin -60 sixty -81 twin -72 updated -1 one -8 updated +7 seven +10 twin +60 sixty +81 twin +72 updated +1 one +8 updated DELETE FROM t1 WHERE id IN (4,60,1); SELECT msg FROM t1; msg -seven -twin -twin -updated -updated +seven +twin +twin +updated +updated DELETE FROM t1 WHERE id IN (81,72); SELECT id FROM t1; id @@ -1097,7 +1097,7 @@ id DELETE FROM t1 WHERE id IN (7,10); SELECT * FROM t1; id msg -8 updated +8 updated DELETE FROM t1 WHERE id = 8; SELECT * FROM t1; id msg @@ -1106,108 +1106,108 @@ DELETE FROM t1; INSERT INTO t1 VALUES(4, 'four'),(7,'seven'),(10,'ten'),(40,'forty'),(60,'sixty'),(81,'eighty one'),(72,'seventy two'),(11,'eleven'),(1,'one'),(35,'thirty five'),(8,'eight'); SELECT * FROM t1; id msg -4 four -7 seven -10 ten -40 forty -60 sixty -81 eighty one -72 seventy two -11 eleven -1 one -35 thirty five -8 eight +4 four +7 seven +10 ten +40 forty +60 sixty +81 eighty one +72 seventy two +11 eleven +1 one +35 thirty five +8 eight UPDATE t1 SET msg = 'bof' WHERE id = 35; SELECT * FROM t1; id msg -4 four -7 seven -10 ten -40 forty -60 sixty -81 eighty one -72 seventy two -11 eleven -1 one -35 bof -8 eight +4 four +7 seven +10 ten +40 forty +60 sixty +81 eighty one +72 seventy two +11 eleven +1 one +35 bof +8 eight UPDATE t1 SET msg = 'big' WHERE id > 50; SELECT * FROM t1; id msg -4 four -7 seven -10 ten -40 forty -60 big -81 big -72 big -11 eleven -1 one -35 bof -8 eight +4 four +7 seven +10 ten +40 forty +60 big +81 big +72 big +11 eleven +1 one +35 bof +8 eight UPDATE t1 SET msg = 'updated' WHERE id IN (8,35,60,72); SELECT * FROM t1; id msg -4 four -7 seven -10 ten -40 forty -60 updated -81 big -72 updated -11 eleven -1 one -35 updated -8 updated +4 four +7 seven +10 ten +40 forty +60 updated +81 big +72 updated +11 eleven +1 one +35 updated +8 updated UPDATE t1 SET msg = 'twin' WHERE id IN (81,10); SELECT * FROM t1; id msg -4 four -7 seven -10 twin -40 forty -60 updated -81 twin -72 updated -11 eleven -1 one -35 updated -8 updated +4 four +7 seven +10 twin +40 forty +60 updated +81 twin +72 updated +11 eleven +1 one +35 updated +8 updated UPDATE t1 SET msg = 'sixty' WHERE id = 60; SELECT * FROM t1 WHERE id = 60; id msg -60 sixty +60 sixty DELETE FROM t1 WHERE id = 4; SELECT * FROM t1; id msg -7 seven -10 twin -40 forty -60 sixty -81 twin -72 updated -11 eleven -1 one -35 updated -8 updated +7 seven +10 twin +40 forty +60 sixty +81 twin +72 updated +11 eleven +1 one +35 updated +8 updated DELETE FROM t1 WHERE id IN (40,11,35); SELECT * FROM t1; id msg -7 seven -10 twin -60 sixty -81 twin -72 updated -1 one -8 updated +7 seven +10 twin +60 sixty +81 twin +72 updated +1 one +8 updated DELETE FROM t1 WHERE id IN (4,60,1); SELECT msg FROM t1; msg -seven -twin -twin -updated -updated +seven +twin +twin +updated +updated DELETE FROM t1 WHERE id IN (81,72); SELECT id FROM t1; id @@ -1217,7 +1217,7 @@ id DELETE FROM t1 WHERE id IN (7,10); SELECT * FROM t1; id msg -8 updated +8 updated DELETE FROM t1 WHERE id = 8; SELECT * FROM t1; id msg @@ -1226,108 +1226,108 @@ DELETE FROM t1; INSERT INTO t1 VALUES(4, 'four'),(7,'seven'),(10,'ten'),(40,'forty'),(60,'sixty'),(81,'eighty one'),(72,'seventy two'),(11,'eleven'),(1,'one'),(35,'thirty five'),(8,'eight'); SELECT * FROM t1; id msg -4 four -7 seven -10 ten -40 forty -60 sixty -81 eighty one -72 seventy two -11 eleven -1 one -35 thirty five -8 eight +4 four +7 seven +10 ten +40 forty +60 sixty +81 eighty one +72 seventy two +11 eleven +1 one +35 thirty five +8 eight UPDATE t1 SET msg = 'bof' WHERE id = 35; SELECT * FROM t1; id msg -4 four -7 seven -10 ten -40 forty -60 sixty -81 eighty one -72 seventy two -11 eleven -1 one -35 bof -8 eight +4 four +7 seven +10 ten +40 forty +60 sixty +81 eighty one +72 seventy two +11 eleven +1 one +35 bof +8 eight UPDATE t1 SET msg = 'big' WHERE id > 50; SELECT * FROM t1; id msg -4 four -7 seven -10 ten -40 forty -60 big -81 big -72 big -11 eleven -1 one -35 bof -8 eight +4 four +7 seven +10 ten +40 forty +60 big +81 big +72 big +11 eleven +1 one +35 bof +8 eight UPDATE t1 SET msg = 'updated' WHERE id IN (8,35,60,72); SELECT * FROM t1; id msg -4 four -7 seven -10 ten -40 forty -60 updated -81 big -72 updated -11 eleven -1 one -35 updated -8 updated +4 four +7 seven +10 ten +40 forty +60 updated +81 big +72 updated +11 eleven +1 one +35 updated +8 updated UPDATE t1 SET msg = 'twin' WHERE id IN (81,10); SELECT * FROM t1; id msg -4 four -7 seven -10 twin -40 forty -60 updated -81 twin -72 updated -11 eleven -1 one -35 updated -8 updated +4 four +7 seven +10 twin +40 forty +60 updated +81 twin +72 updated +11 eleven +1 one +35 updated +8 updated UPDATE t1 SET msg = 'sixty' WHERE id = 60; SELECT * FROM t1 WHERE id = 60; id msg -60 sixty +60 sixty DELETE FROM t1 WHERE id = 4; SELECT * FROM t1; id msg -7 seven -10 twin -40 forty -60 sixty -81 twin -72 updated -11 eleven -1 one -35 updated -8 updated +7 seven +10 twin +40 forty +60 sixty +81 twin +72 updated +11 eleven +1 one +35 updated +8 updated DELETE FROM t1 WHERE id IN (40,11,35); SELECT * FROM t1; id msg -7 seven -10 twin -60 sixty -81 twin -72 updated -1 one -8 updated +7 seven +10 twin +60 sixty +81 twin +72 updated +1 one +8 updated DELETE FROM t1 WHERE id IN (4,60,1); SELECT msg FROM t1; msg -seven -twin -twin -updated -updated +seven +twin +twin +updated +updated DELETE FROM t1 WHERE id IN (81,72); SELECT id FROM t1; id @@ -1337,7 +1337,7 @@ id DELETE FROM t1 WHERE id IN (7,10); SELECT * FROM t1; id msg -8 updated +8 updated DELETE FROM t1 WHERE id = 8; SELECT * FROM t1; id msg diff --git a/storage/connect/mysql-test/connect/t/tbl_thread.test b/storage/connect/mysql-test/connect/t/tbl_thread.test index 0b919f88cd579..3376a121c5c07 100644 --- a/storage/connect/mysql-test/connect/t/tbl_thread.test +++ b/storage/connect/mysql-test/connect/t/tbl_thread.test @@ -2,8 +2,6 @@ connection default; -let $PORT= `select @@port`; - --echo # --echo # Checking thread TBL tables --echo # @@ -24,6 +22,14 @@ CREATE TABLE rt3 (a int, b char(10)); INSERT INTO rt3 VALUES (8,'test08'),(9,'test09'),(10,'test10'),(11,'test11'); SELECT * FROM rt3; +CREATE TABLE rt4 (a int, b char(10)); +INSERT INTO rt4 VALUES (12,'test12'),(13,'test13'),(14,'test14'),(15,'test15'); +SELECT * FROM rt4; + +CREATE TABLE rt5 (a int, b char(10)); +INSERT INTO rt5 VALUES (16,'test16'),(17,'test17'),(18,'test18'),(19,'test19'); +SELECT * FROM rt5; + connection default; --replace_result $MASTER_MYPORT MASTER_PORT @@ -36,9 +42,19 @@ eval CREATE TABLE t3 ENGINE=CONNECT TABLE_TYPE=MYSQL CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/test/rt3'; SELECT * FROM t3; +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE t4 ENGINE=CONNECT TABLE_TYPE=MYSQL +CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/test/rt4'; +SELECT * FROM t4; + +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval CREATE TABLE t5 ENGINE=CONNECT TABLE_TYPE=MYSQL +CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/test/rt5'; +SELECT * FROM t5; + --replace_result $PORT PORT eval CREATE TABLE total (a int, b char(10)) -ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2,t3' +ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2,t3,t4,t5' OPTION_LIST='thread=yes,port=$PORT'; SELECT * FROM total order by a desc; @@ -48,11 +64,11 @@ DROP TABLE rt2; connection slave; -DROP TABLE rt3; +DROP TABLE rt3,rt4,rt5; connection default; -DROP TABLE t1,t2,t3,total; +DROP TABLE t1,t2,t3,t4,t5,total; --echo # --echo # Old thread TBL tables test modified @@ -73,18 +89,20 @@ DROP TABLE t1,t2,total; --echo # --echo # Old thread TBL tables test not modified (suppressed until MDEV-10179 is fixed) --echo # -#CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL SRCDEF='select 11 as v'; -#SELECT * FROM t1; +CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL SRCDEF='select 11 as v'; +SELECT * FROM t1; -#CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL SRCDEF='select 22 as v'; -#SELECT * FROM t2; +CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL SRCDEF='select 22 as v'; +SELECT * FROM t2; -#--replace_result $PORT PORT -#--eval CREATE TABLE total (v BIGINT(20) UNSIGNED NOT NULL) ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2' OPTION_LIST='thread=yes,port=$PORT'; -#SELECT * FROM total order by v desc; +--replace_result $PORT PORT +--eval CREATE TABLE total (v BIGINT(20) UNSIGNED NOT NULL) ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2' OPTION_LIST='thread=yes,port=$PORT'; +set connect_xtrace=1; +SELECT * FROM total order by v desc; +set connect_xtrace=0; -#DROP TABLE total; -#DROP TABLE t1; -#DROP TABLE t2; +DROP TABLE total; +DROP TABLE t1; +DROP TABLE t2; -- source myconn_cleanup.inc diff --git a/storage/connect/myutil.cpp b/storage/connect/myutil.cpp index c2053f1c83293..338a79d945543 100644 --- a/storage/connect/myutil.cpp +++ b/storage/connect/myutil.cpp @@ -218,7 +218,7 @@ int MYSQLtoPLG(int mytype, char *var) case MYSQL_TYPE_VARCHAR: #endif // !ALPHA) case MYSQL_TYPE_STRING: - type = TYPE_STRING; + type = (*var == 'B') ? TYPE_BIN : TYPE_STRING; break; case MYSQL_TYPE_BLOB: case MYSQL_TYPE_TINY_BLOB: @@ -232,7 +232,7 @@ int MYSQLtoPLG(int mytype, char *var) type = TYPE_STRING; *var = 'X'; } else - type = TYPE_ERROR; + type = TYPE_BIN; break; case TPC_SKIP: diff --git a/storage/connect/reldef.h b/storage/connect/reldef.h index 8b19a413ade29..84ae2a491f038 100644 --- a/storage/connect/reldef.h +++ b/storage/connect/reldef.h @@ -94,6 +94,7 @@ class DllExport TABDEF : public RELDEF { /* Logical table descriptor */ virtual void SetIndx(PIXDEF) {} virtual bool IsHuge(void) {return false;} const CHARSET_INFO *data_charset() {return m_data_charset;} + const char *GetCsName(void) {return csname;} // Methods int GetColCatInfo(PGLOBAL g); diff --git a/storage/connect/tabmysql.h b/storage/connect/tabmysql.h index 3c37ae5bf3b37..39fba87bcc96f 100644 --- a/storage/connect/tabmysql.h +++ b/storage/connect/tabmysql.h @@ -69,6 +69,7 @@ class MYSQLDEF : public EXTDEF {/* Logical table description */ /***********************************************************************/ class TDBMYSQL : public TDBEXT { friend class MYSQLCOL; + friend class TDBTBM; public: // Constructor TDBMYSQL(PMYDEF tdp); diff --git a/storage/connect/tabtbl.cpp b/storage/connect/tabtbl.cpp index b567e9aecd4b6..bb7eae9c25677 100644 --- a/storage/connect/tabtbl.cpp +++ b/storage/connect/tabtbl.cpp @@ -578,10 +578,19 @@ pthread_handler_t ThreadOpen(void *p) // Try to open the connection if (!cmp->Tap->GetTo_Tdb()->OpenDB(cmp->G)) { pthread_mutex_lock(&tblmut); + if (trace) + htrc("Table %s ready\n", cmp->Tap->GetName()); + cmp->Ready = true; pthread_mutex_unlock(&tblmut); - } else - cmp->Rc = RC_FX; + } else { + pthread_mutex_lock(&tblmut); + if (trace) + htrc("Opening %s failed\n", cmp->Tap->GetName()); + + cmp->Rc = RC_FX; + pthread_mutex_unlock(&tblmut); + } // endif OpenDB my_thread_end(); } else @@ -632,6 +641,18 @@ int TDBTBM::RowNumber(PGLOBAL g, bool b) return Tdbp->RowNumber(g) + ((b) ? 0 : Rows); } // end of RowNumber +/***********************************************************************/ +/* Returns true if this MYSQL table refers to a local table. */ +/***********************************************************************/ +bool TDBTBM::IsLocal(PTABLE tbp) +{ + TDBMYSQL *tdbp = (TDBMYSQL*)tbp->GetTo_Tdb(); + + return ((!stricmp(tdbp->Host, "localhost") || + !strcmp(tdbp->Host, "127.0.0.1")) && + tdbp->Port == GetDefaultPort()); +} // end of IsLocal + /***********************************************************************/ /* Initialyze table parallel processing. */ /***********************************************************************/ @@ -644,10 +665,13 @@ bool TDBTBM::OpenTables(PGLOBAL g) // Allocates the TBMT blocks for the tables for (tabp = Tablist; tabp; tabp = tabp->Next) - if (tabp->GetTo_Tdb()->GetAmType() == TYPE_AM_MYSQL) { + if (tabp->GetTo_Tdb()->GetAmType() == TYPE_AM_MYSQL && !IsLocal(tabp)) { // Remove remote table from the local list *ptabp = tabp->Next; + if (trace) + htrc("=====> New remote table %s\n", tabp->GetName()); + // Make the remote table block tp = (PTBMT)PlugSubAlloc(g, NULL, sizeof(TBMT)); memset(tp, 0, sizeof(TBMT)); @@ -671,7 +695,10 @@ bool TDBTBM::OpenTables(PGLOBAL g) ptp = &tp->Next; Nrc++; // Number of remote connections } else { - ptabp = &tabp->Next; + if (trace) + htrc("=====> Local table %s\n", tabp->GetName()); + + ptabp = &tabp->Next; Nlc++; // Number of local connections } // endif Type @@ -788,7 +815,7 @@ int TDBTBM::ReadDB(PGLOBAL g) /***********************************************************************/ int TDBTBM::ReadNextRemote(PGLOBAL g) { - bool b = false; + bool b; if (Tdbp) Tdbp->CloseDB(g); @@ -796,17 +823,22 @@ int TDBTBM::ReadNextRemote(PGLOBAL g) Cmp = NULL; retry: - // Search for a remote table having its result set + b = false; + + // Search for a remote table having its result set pthread_mutex_lock(&tblmut); for (PTBMT tp = Tmp; tp; tp = tp->Next) - if (tp->Ready) { - if (!tp->Complete) { - Cmp = tp; - break; - } // endif Complete + if (tp->Rc != RC_FX) { + if (tp->Ready) { + if (!tp->Complete) { + Cmp = tp; + break; + } // endif Complete - } else - b = true; + } else + b = true; + + } // endif Rc pthread_mutex_unlock(&tblmut); diff --git a/storage/connect/tabtbl.h b/storage/connect/tabtbl.h index 3a5ec45d0256c..f02bf620aae98 100644 --- a/storage/connect/tabtbl.h +++ b/storage/connect/tabtbl.h @@ -146,6 +146,7 @@ class DllExport TDBTBM : public TDBTBL { protected: // Internal functions + bool IsLocal(PTABLE tbp); bool OpenTables(PGLOBAL g); int ReadNextRemote(PGLOBAL g); diff --git a/storage/connect/valblk.cpp b/storage/connect/valblk.cpp index 5b98f3eb425cd..018c7ee3fe19f 100644 --- a/storage/connect/valblk.cpp +++ b/storage/connect/valblk.cpp @@ -59,11 +59,12 @@ PVBLK AllocValBlock(PGLOBAL g, void *mp, int type, int nval, int len, switch (type) { case TYPE_STRING: + case TYPE_BIN: case TYPE_DECIM: if (len) - blkp = new(g) CHRBLK(mp, nval, len, prec, blank); + blkp = new(g) CHRBLK(mp, nval, type, len, prec, blank); else - blkp = new(g) STRBLK(g, mp, nval); + blkp = new(g) STRBLK(g, mp, nval, type); break; case TYPE_SHORT: @@ -615,8 +616,8 @@ int TYPBLK::GetMaxLength(void) /***********************************************************************/ /* Constructor. */ /***********************************************************************/ -CHRBLK::CHRBLK(void *mp, int nval, int len, int prec, bool blank) - : VALBLK(mp, TYPE_STRING, nval), Chrp((char*&)Blkp) +CHRBLK::CHRBLK(void *mp, int nval, int type, int len, int prec, bool blank) + : VALBLK(mp, type, nval), Chrp((char*&)Blkp) { Valp = NULL; Blanks = blank; @@ -1008,8 +1009,8 @@ int CHRBLK::GetMaxLength(void) /***********************************************************************/ /* Constructor. */ /***********************************************************************/ -STRBLK::STRBLK(PGLOBAL g, void *mp, int nval) - : VALBLK(mp, TYPE_STRING, nval), Strp((PSZ*&)Blkp) +STRBLK::STRBLK(PGLOBAL g, void *mp, int nval, int type) + : VALBLK(mp, type, nval), Strp((PSZ*&)Blkp) { Global = g; Nullable = true; diff --git a/storage/connect/valblk.h b/storage/connect/valblk.h index 38a7342498583..a3d7bf30fcf07 100644 --- a/storage/connect/valblk.h +++ b/storage/connect/valblk.h @@ -214,7 +214,7 @@ class TYPBLK : public VALBLK { class CHRBLK : public VALBLK { public: // Constructors - CHRBLK(void *mp, int size, int len, int prec, bool b); + CHRBLK(void *mp, int size, int type, int len, int prec, bool b); // Implementation virtual bool Init(PGLOBAL g, bool check); @@ -267,7 +267,7 @@ class CHRBLK : public VALBLK { class STRBLK : public VALBLK { public: // Constructors - STRBLK(PGLOBAL g, void *mp, int size); + STRBLK(PGLOBAL g, void *mp, int size, int type); // Implementation virtual void SetNull(int n, bool b) {if (b) {Strp[n] = NULL;}} @@ -345,7 +345,7 @@ class PTRBLK : public STRBLK { bool, bool, bool); protected: // Constructors - PTRBLK(PGLOBAL g, void *mp, int size) : STRBLK(g, mp, size) {} + PTRBLK(PGLOBAL g, void *mp, int size) : STRBLK(g, mp, size, TYPE_PCHAR) {} // Implementation diff --git a/storage/connect/value.cpp b/storage/connect/value.cpp index 11298355d9d9e..51c422389ca4d 100644 --- a/storage/connect/value.cpp +++ b/storage/connect/value.cpp @@ -236,6 +236,7 @@ bool IsTypeChar(int type) switch (type) { case TYPE_STRING: case TYPE_DECIM: + case TYPE_BIN: return true; } // endswitch type @@ -1857,8 +1858,9 @@ int DECVAL::CompareValue(PVAL vp) BINVAL::BINVAL(PGLOBAL g, void *p, int cl, int n) : VALUE(TYPE_BIN) { assert(g); - Len = n; - Clen = cl; +//Len = n; + Len = (g) ? n : (p) ? strlen((char*)p) : 0; + Clen = cl; Binp = PlugSubAlloc(g, NULL, Clen + 1); memset(Binp, 0, Clen + 1); @@ -1991,10 +1993,15 @@ bool BINVAL::SetValue_pval(PVAL valp, bool chktype) return true; if (!(Null = valp->IsNull() && Nullable)) { - if ((rc = (Len = valp->GetSize()) > Clen)) + int len = Len; + + if ((rc = (Len = valp->GetSize()) > Clen)) Len = Clen; + else if (len > Len) + memset(Binp, 0, len); memcpy(Binp, valp->GetTo_Val(), Len); + ((char*)Binp)[Len] = 0; } else Reset(); @@ -2011,10 +2018,15 @@ bool BINVAL::SetValue_char(const char *p, int n) bool rc; if (p && n > 0) { - rc = n > Clen; - Len = MY_MIN(n, Clen); - memcpy(Binp, p, Len); - Null = false; + int len = Len; + + if (len > (Len = MY_MIN(n, Clen))) + memset(Binp, 0, len); + + memcpy(Binp, p, Len); + ((char*)Binp)[Len] = 0; + rc = n > Clen; + Null = false; } else { rc = false; Reset(); @@ -2030,9 +2042,14 @@ bool BINVAL::SetValue_char(const char *p, int n) void BINVAL::SetValue_psz(PCSZ s) { if (s) { - Len = MY_MIN(Clen, (signed)strlen(s)); - memcpy(Binp, s, Len); - Null = false; + int len = Len; + + if (len > (Len = MY_MIN(Clen, (signed)strlen(s)))) + memset(Binp, 0, len); + + memcpy(Binp, s, Len); + ((char*)Binp)[Len] = 0; + Null = false; } else { Reset(); Null = Nullable; @@ -2052,14 +2069,19 @@ void BINVAL::SetValue_pvblk(PVBLK blk, int n) Reset(); Null = Nullable; } else if (vp != Binp) { + int len = Len; + if (blk->GetType() == TYPE_STRING) Len = strlen((char*)vp); else Len = blk->GetVlen(); - Len = MY_MIN(Clen, Len); + if (len > (Len = MY_MIN(Clen, Len))) + memset(Binp, 0, len); + memcpy(Binp, vp, Len); - Null = false; + ((char*)Binp)[Len] = 0; + Null = false; } // endif vp } // end of SetValue_pvblk @@ -2070,7 +2092,10 @@ void BINVAL::SetValue_pvblk(PVBLK blk, int n) void BINVAL::SetValue(int n) { if (Clen >= 4) { - *((int*)Binp) = n; + if (Len > 4) + memset(Binp, 0, Len); + + *((int*)Binp) = n; Len = 4; } else SetValue((short)n); @@ -2083,7 +2108,10 @@ void BINVAL::SetValue(int n) void BINVAL::SetValue(uint n) { if (Clen >= 4) { - *((uint*)Binp) = n; + if (Len > 4) + memset(Binp, 0, Len); + + *((uint*)Binp) = n; Len = 4; } else SetValue((ushort)n); @@ -2096,7 +2124,10 @@ void BINVAL::SetValue(uint n) void BINVAL::SetValue(short i) { if (Clen >= 2) { - *((int*)Binp) = i; + if (Len > 2) + memset(Binp, 0, Len); + + *((int*)Binp) = i; Len = 2; } else SetValue((char)i); @@ -2109,7 +2140,10 @@ void BINVAL::SetValue(short i) void BINVAL::SetValue(ushort i) { if (Clen >= 2) { - *((uint*)Binp) = i; + if (Len > 2) + memset(Binp, 0, Len); + + *((uint*)Binp) = i; Len = 2; } else SetValue((uchar)i); @@ -2122,7 +2156,10 @@ void BINVAL::SetValue(ushort i) void BINVAL::SetValue(longlong n) { if (Clen >= 8) { - *((longlong*)Binp) = n; + if (Len > 8) + memset(Binp, 0, Len); + + *((longlong*)Binp) = n; Len = 8; } else SetValue((int)n); @@ -2135,7 +2172,10 @@ void BINVAL::SetValue(longlong n) void BINVAL::SetValue(ulonglong n) { if (Clen >= 8) { - *((ulonglong*)Binp) = n; + if (Len > 8) + memset(Binp, 0, Len); + + *((ulonglong*)Binp) = n; Len = 8; } else SetValue((uint)n); @@ -2146,6 +2186,9 @@ void BINVAL::SetValue(ulonglong n) /***********************************************************************/ void BINVAL::SetValue(double n) { + if (Len > 8) + memset(Binp, 0, Len); + if (Clen >= 8) { *((double*)Binp) = n; Len = 8; @@ -2162,7 +2205,10 @@ void BINVAL::SetValue(double n) /***********************************************************************/ void BINVAL::SetValue(char c) { - *((char*)Binp) = c; + if (Len > 1) + memset(Binp, 0, Len); + + *((char*)Binp) = c; Len = 1; } // end of SetValue @@ -2171,7 +2217,10 @@ void BINVAL::SetValue(char c) /***********************************************************************/ void BINVAL::SetValue(uchar c) { - *((uchar*)Binp) = c; + if (Len > 1) + memset(Binp, 0, Len); + + *((uchar*)Binp) = c; Len = 1; } // end of SetValue @@ -2181,6 +2230,7 @@ void BINVAL::SetValue(uchar c) void BINVAL::SetBinValue(void *p) { memcpy(Binp, p, Clen); + Len = Clen; } // end of SetBinValue /***********************************************************************/ @@ -2206,10 +2256,11 @@ bool BINVAL::GetBinValue(void *buf, int buflen, bool go) /***********************************************************************/ char *BINVAL::ShowValue(char *buf, int len) { - int n = MY_MIN(Len, len / 2); + //int n = MY_MIN(Len, len / 2); - sprintf(buf, GetXfmt(), n, Binp); - return buf; + //sprintf(buf, GetXfmt(), n, Binp); + //return buf; + return (char*)Binp; } // end of ShowValue /***********************************************************************/