Commit 5b9c32ed authored by Vicențiu Ciorbaru's avatar Vicențiu Ciorbaru

Merge remote-tracking branch 'connect/10.2' into 10.2

parents 22c322c6 bf34e9db
......@@ -245,7 +245,7 @@ int main() {
ENDIF(CONNECT_WITH_ODBC)
#
# JDBC and MongoDB Java Driver
# JDBC with MongoDB Java Driver included but disabled
#
OPTION(CONNECT_WITH_MONGO "Compile CONNECT storage engine with MONGO support" ON)
OPTION(CONNECT_WITH_JDBC "Compile CONNECT storage engine with JDBC support" ON)
......@@ -270,7 +270,7 @@ IF(CONNECT_WITH_JDBC)
jmgfam.cpp jmgoconn.cpp mongo.cpp tabjmg.cpp
jmgfam.h jmgoconn.h mongo.h tabjmg.h
Mongo2Interface.java Mongo3Interface.java)
add_definitions(-DMONGO_SUPPORT)
add_definitions(-DMONGO_SUPPORT -DMONGO_ENABLED=0)
ENDIF()
ELSE()
SET(JDBC_LIBRARY "")
......@@ -290,33 +290,36 @@ IF(CONNECT_WITH_ZIP)
ENDIF(CONNECT_WITH_ZIP)
#
# MONGO C Driver (CMAKE NOT YET WORKING)
# MONGO C Driver
#
#IF(CONNECT_WITH_MONGO)
# IF(WIN32)
# # Adding some typical places to search in
# SET(PC_MONGO_INCLUDE_DIRS
# C:/mongo-c-driver/include
# D:/mongo-c-driver/include)
# SET(PC_MONGO_LIBRARY_DIRS
# C:/mongo-c-driver/lib
# D:/mongo-c-driver/lib)
# ENDIF(WIN32)
# FIND_PACKAGE(libmongoc 1.7)
# IF (MONGO_FOUND)
# INCLUDE_DIRECTORIES(${MONGO_INCLUDE_DIR})
# SET(MONGO_LIBRARY ${MONGO_LIBRARIES})
# SET(CONNECT_SOURCES ${CONNECT_SOURCES}
# cmgoconn.cpp cmgfam.cpp tabcmg.cpp
# cmgoconn.h cmgfam.h tabcmg.h)
# add_definitions(-DCMGO_SUPPORT)
# IF (NOT JAVA_FOUND AND JNI_FOUND)
# SET(CONNECT_SOURCES ${CONNECT_SOURCES} mongo.cpp mongo.h)
# add_definitions(-DMONGO_SUPPORT)
# ENDIF (NOT JAVA_FOUND AND JNI_FOUND)
# ENDIF(MONGO_FOUND)
#ENDIF(CONNECT_WITH_MONGO)
IF(CONNECT_WITH_MONGO)
IF(WIN32)
# Adding some typical places to search in
SET(PC_MONGO_INCLUDE_DIRS
C:/mongo-c-driver/include
D:/mongo-c-driver/include)
SET(PC_MONGO_LIBRARY_DIRS
C:/mongo-c-driver/lib
D:/mongo-c-driver/lib)
ENDIF(WIN32)
FIND_PACKAGE(libmongoc-1.0 1.7)
IF (libmongoc-1.0_FOUND)
INCLUDE_DIRECTORIES(${MONGOC_INCLUDE_DIRS})
SET(MONGOC_LIBRARY ${MONGOC_LIBRARIES})
SET(CONNECT_SOURCES ${CONNECT_SOURCES}
cmgoconn.cpp cmgfam.cpp tabcmg.cpp
cmgoconn.h cmgfam.h tabcmg.h)
add_definitions(-DCMGO_SUPPORT)
IF (NOT JAVA_FOUND AND JNI_FOUND)
SET(CONNECT_SOURCES ${CONNECT_SOURCES} mongo.cpp mongo.h)
add_definitions(-DMONGO_SUPPORT -DMONGO_ENABLED=1)
ELSE ()
remove_definitions(-DMONGO_ENABLED=0)
add_definitions(-DMONGO_ENABLED=1)
ENDIF (NOT JAVA_FOUND AND JNI_FOUND)
ENDIF(libmongoc-1.0_FOUND)
ENDIF(CONNECT_WITH_MONGO)
#
......@@ -337,9 +340,25 @@ MYSQL_ADD_PLUGIN(connect ${CONNECT_SOURCES}
STORAGE_ENGINE
COMPONENT connect-engine
RECOMPILE_FOR_EMBEDDED
# LINK_LIBRARIES ${ZLIB_LIBRARY} ${XML_LIBRARY} ${ICONV_LIBRARY} $(MONGO_LIBRARY)
LINK_LIBRARIES ${ZLIB_LIBRARY} ${XML_LIBRARY} ${ICONV_LIBRARY}
${ODBC_LIBRARY} ${JDBC_LIBRARY} ${IPHLPAPI_LIBRARY})
${ODBC_LIBRARY} ${JDBC_LIBRARY} ${MONGOC_LIBRARY} ${IPHLPAPI_LIBRARY})
IF(NOT TARGET connect)
RETURN()
ENDIF()
# Install some extra files that belong to connect engine
IF(WIN32)
# install ha_connect.lib
GET_TARGET_PROPERTY(CONNECT_LOCATION connect LOCATION)
STRING(REPLACE "dll" "lib" CONNECT_LIB ${CONNECT_LOCATION})
IF(CMAKE_CONFIGURATION_TYPES)
STRING(REPLACE "${CMAKE_CFG_INTDIR}" "\${CMAKE_INSTALL_CONFIG_NAME}"
CONNECT_LIB ${CONNECT_LIB})
ENDIF()
INSTALL(FILES ${CONNECT_LIB}
DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
ENDIF(WIN32)
IF(NOT TARGET connect)
RETURN()
......@@ -368,4 +387,3 @@ IF(CONNECT_WITH_JDBC AND JAVA_FOUND AND JNI_FOUND)
${CMAKE_CURRENT_BINARY_DIR}/JdbcInterface.jar
DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
ENDIF()
......@@ -171,9 +171,9 @@
#define JSONMAX 10 // JSON Default max grp size
extern "C" {
char version[]= "Version 1.06.0001 April 17, 2017";
char version[]= "Version 1.06.0004 September 03, 2017";
#if defined(__WIN__)
char compver[]= "Version 1.06.0001 " __DATE__ " " __TIME__;
char compver[]= "Version 1.06.0004 " __DATE__ " " __TIME__;
char slash= '\\';
#else // !__WIN__
char slash= '/';
......@@ -359,6 +359,13 @@ static MYSQL_THDVAR_STR(java_wrapper,
NULL, NULL, "wrappers/JdbcInterface");
#endif // JDBC_SUPPORT
#if defined(MONGO_SUPPORT)
// Enabling MONGO table type
static MYSQL_THDVAR_BOOL(enable_mongo, PLUGIN_VAR_RQCMDARG,
"Enabling the MongoDB access",
NULL, NULL, MONGO_ENABLED);
#endif // MONGO_SUPPORT
#if defined(XMSG) || defined(NEWMSG)
const char *language_names[]=
{
......@@ -419,6 +426,10 @@ char *GetJavaWrapper(void)
{return connect_hton ? THDVAR(current_thd, java_wrapper) : (char*)"wrappers/JdbcInterface";}
#endif // JDBC_SUPPORT
#if defined(MONGO_SUPPORT)
bool MongoEnabled(void) { return THDVAR(current_thd, enable_mongo); }
#endif // MONGO_SUPPORT
extern "C" const char *msglang(void)
{
#if defined(FRENCH)
......@@ -1285,9 +1296,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
......@@ -1433,7 +1449,7 @@ PFOS ha_connect::GetFieldOptionStruct(Field *fdp)
void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf)
{
const char *cp;
char *chset, v;
char *chset, v = 0;
ha_field_option_struct *fop;
Field* fp;
Field* *fldp;
......@@ -1486,7 +1502,6 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf)
} // endif fop
chset = (char *)fp->charset()->name;
v = (!strcmp(chset, "binary")) ? 'B' : 0;
switch (fp->type()) {
case MYSQL_TYPE_BLOB:
......@@ -1501,8 +1516,9 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf)
switch (pcf->Type) {
case TYPE_STRING:
case TYPE_BIN:
// Do something for case
cp= fp->charset()->name;
cp= chset;
// Find if collation name ends by _ci
if (!strcmp(cp + strlen(cp) - 3, "_ci")) {
......@@ -2114,6 +2130,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;
......@@ -5163,7 +5184,8 @@ static bool add_field(String *sql, const char *field_name, int typ, int len,
error|= sql->append("` ");
error|= sql->append(type);
if (len && typ != TYPE_DATE && (typ != TYPE_DOUBLE || dec >= 0)) {
if (typ == TYPE_STRING ||
(len && typ != TYPE_DATE && (typ != TYPE_DOUBLE || dec >= 0))) {
error|= sql->append('(');
error|= sql->append_ulonglong(len);
......@@ -6389,6 +6411,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_STRING:
#if 0
if (!fp->field_length) {
sprintf(g->Message, "Unsupported 0 length for column %s",
fp->field_name);
......@@ -6398,7 +6421,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
MYF(0), fp->field_name);
DBUG_RETURN(rc);
} // endif fp
#endif // 0
break; // To be checked
case MYSQL_TYPE_BIT:
case MYSQL_TYPE_NULL:
......@@ -7166,7 +7189,10 @@ static struct st_mysql_sys_var* connect_system_variables[]= {
MYSQL_SYSVAR(class_path),
MYSQL_SYSVAR(java_wrapper),
#endif // JDBC_SUPPORT
NULL
#if defined(MONGO_SUPPORT)
MYSQL_SYSVAR(enable_mongo),
#endif // MONGO_SUPPORT
NULL
};
maria_declare_plugin(connect)
......@@ -7175,14 +7201,14 @@ maria_declare_plugin(connect)
&connect_storage_engine,
"CONNECT",
"Olivier Bertrand",
"Management of External Data (SQL/MED), including many file formats",
"Management of External Data (SQL/NOSQL/MED), including many file formats",
PLUGIN_LICENSE_GPL,
connect_init_func, /* Plugin Init */
connect_done_func, /* Plugin Deinit */
0x0106, /* version number (1.05) */
NULL, /* status variables */
connect_system_variables, /* system variables */
"1.06.0001", /* string version */
MariaDB_PLUGIN_MATURITY_BETA /* maturity */
"1.06.0004", /* string version */
MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
}
maria_declare_plugin_end;
......@@ -348,6 +348,13 @@ const char *GetValStr(OPVAL vop, bool neg);
PFIL CondFilter(PGLOBAL g, Item *cond);
//PFIL CheckFilter(PGLOBAL g);
/** admin commands - called from mysql_admin_table */
virtual int check(THD* thd, HA_CHECK_OPT* check_opt)
{
// TODO: implement it
return HA_ADMIN_OK; // Just to avoid error message with checktables
} // end of check
/**
Number of rows in table. It will only be called if
(table_flags() & (HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT)) != 0
......
......@@ -111,6 +111,9 @@
extern "C" HINSTANCE s_hModule; // Saved module handle
#endif // !__WIN__
#if defined(MONGO_SUPPORT)
bool MongoEnabled(void);
#endif // MONGO_SUPPORT
PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info);
/***********************************************************************/
......@@ -558,7 +561,13 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
case TAB_VIR: tdp= new(g) VIRDEF; break;
case TAB_JSON: tdp= new(g) JSONDEF; break;
#if defined(MONGO_SUPPORT)
case TAB_MONGO: tdp = new(g) MGODEF; break;
case TAB_MONGO:
if (MongoEnabled())
tdp = new(g) MGODEF;
else
strcpy(g->Message, "MONGO type not enabled");
break;
#endif // MONGO_SUPPORT
#if defined(ZIP_SUPPORT)
case TAB_ZIP: tdp= new(g) ZIPDEF; break;
......
......@@ -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));
......
SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo2.jar';
set connect_enable_mongo=1;
#
# Test the MONGO table type
#
......@@ -25,7 +26,6 @@ address_street 1 CHAR 38 38 0 0 address.street
address_zipcode 1 CHAR 5 5 0 0 address.zipcode
borough 1 CHAR 13 13 0 0
cuisine 1 CHAR 64 64 0 0
grades 1 CHAR 0 0 0 1
grades_date 1 CHAR 256 256 0 1 grades.0.date
grades_grade 1 CHAR 14 14 0 1 grades.0.grade
grades_score 5 BIGINT 2 2 0 1 grades.0.score
......@@ -72,7 +72,6 @@ t1 CREATE TABLE `t1` (
`address_zipcode` char(5) NOT NULL `FIELD_FORMAT`='address.zipcode',
`borough` char(13) NOT NULL,
`cuisine` char(64) NOT NULL,
`grades` char(1) DEFAULT NULL,
`grades_date` varchar(256) DEFAULT NULL `FIELD_FORMAT`='grades.0.date',
`grades_grade` char(14) DEFAULT NULL `FIELD_FORMAT`='grades.0.grade',
`grades_score` bigint(2) DEFAULT NULL `FIELD_FORMAT`='grades.0.score',
......@@ -80,12 +79,12 @@ t1 CREATE TABLE `t1` (
`restaurant_id` char(8) NOT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='mongodb://localhost:27017' `TABLE_TYPE`='JSON' `TABNAME`='restaurants' `OPTION_LIST`='Level=1,Driver=Java,Version=2' `DATA_CHARSET`='utf8' `LRECL`=4096
SELECT * FROM t1 LIMIT 5;
_id address_building address_coord address_street address_zipcode borough cuisine grades grades_date grades_grade grades_score name restaurant_id
58ada47de5a51ddfcd5ed51c 1007 -73.856077 Morris Park Ave 10462 Bronx Bakery 2 2014-03-03T00:00:00.000Z A 2 Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.961704 Flatbush Avenue 11225 Brooklyn Hamburgers 2 2014-12-30T00:00:00.000Z A 8 Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.98513559999999 West 57 Street 10019 Manhattan Irish 2 2014-09-06T00:00:00.000Z A 2 Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.98241999999999 Stillwell Avenue 11224 Brooklyn American 2 2014-06-10T00:00:00.000Z A 5 Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.8601152 63 Road 11374 Queens Jewish/Kosher 2 2014-11-24T00:00:00.000Z Z 20 Tov Kosher Kitchen 40356068
_id address_building address_coord address_street address_zipcode borough cuisine grades_date grades_grade grades_score name restaurant_id
58ada47de5a51ddfcd5ed51c 1007 -73.856077 Morris Park Ave 10462 Bronx Bakery 2014-03-03T00:00:00.000Z A 2 Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.961704 Flatbush Avenue 11225 Brooklyn Hamburgers 2014-12-30T00:00:00.000Z A 8 Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.98513559999999 West 57 Street 10019 Manhattan Irish 2014-09-06T00:00:00.000Z A 2 Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.98241999999999 Stillwell Avenue 11224 Brooklyn American 2014-06-10T00:00:00.000Z A 5 Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.8601152 63 Road 11374 Queens Jewish/Kosher 2014-11-24T00:00:00.000Z Z 20 Tov Kosher Kitchen 40356068
DROP TABLE t1;
#
# Dropping a column
......@@ -259,7 +258,6 @@ t1 CREATE TABLE `t1` (
`address_street` char(38) NOT NULL `FIELD_FORMAT`='address.street',
`address_zipcode` char(5) NOT NULL `FIELD_FORMAT`='address.zipcode',
`borough` char(13) NOT NULL,
`grades` char(1) DEFAULT NULL,
`grades_date` char(24) DEFAULT NULL `FIELD_FORMAT`='grades.0.date',
`grades_grade` char(14) DEFAULT NULL `FIELD_FORMAT`='grades.0.grade',
`grades_score` bigint(2) DEFAULT NULL `FIELD_FORMAT`='grades.0.score',
......@@ -384,3 +382,4 @@ planner 167 41.75
postcard 23 5.75
DROP TABLE t1;
true
set connect_enable_mongo=0;
SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo3.jar';
set connect_enable_mongo=1;
#
# Test the MONGO table type
#
......@@ -25,7 +26,6 @@ address_street 1 CHAR 38 38 0 0 address.street
address_zipcode 1 CHAR 5 5 0 0 address.zipcode
borough 1 CHAR 13 13 0 0
cuisine 1 CHAR 64 64 0 0
grades 1 CHAR 0 0 0 1
grades_date 1 CHAR 256 256 0 1 grades.0.date
grades_grade 1 CHAR 14 14 0 1 grades.0.grade
grades_score 5 BIGINT 2 2 0 1 grades.0.score
......@@ -72,7 +72,6 @@ t1 CREATE TABLE `t1` (
`address_zipcode` char(5) NOT NULL `FIELD_FORMAT`='address.zipcode',
`borough` char(13) NOT NULL,
`cuisine` char(64) NOT NULL,
`grades` char(1) DEFAULT NULL,
`grades_date` varchar(256) DEFAULT NULL `FIELD_FORMAT`='grades.0.date',
`grades_grade` char(14) DEFAULT NULL `FIELD_FORMAT`='grades.0.grade',
`grades_score` bigint(2) DEFAULT NULL `FIELD_FORMAT`='grades.0.score',
......@@ -80,12 +79,12 @@ t1 CREATE TABLE `t1` (
`restaurant_id` char(8) NOT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='mongodb://localhost:27017' `TABLE_TYPE`='JSON' `TABNAME`='restaurants' `OPTION_LIST`='Level=1,Driver=Java,Version=3' `DATA_CHARSET`='utf8' `LRECL`=4096
SELECT * FROM t1 LIMIT 5;
_id address_building address_coord address_street address_zipcode borough cuisine grades grades_date grades_grade grades_score name restaurant_id
58ada47de5a51ddfcd5ed51c 1007 -73.856077 Morris Park Ave 10462 Bronx Bakery 1 1393804800 A 2 Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.961704 Flatbush Avenue 11225 Brooklyn Hamburgers 1 1419897600 A 8 Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.98513559999999 West 57 Street 10019 Manhattan Irish 1 1409961600 A 2 Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.98241999999999 Stillwell Avenue 11224 Brooklyn American 1 1402358400 A 5 Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.8601152 63 Road 11374 Queens Jewish/Kosher 1 1416787200 Z 20 Tov Kosher Kitchen 40356068
_id address_building address_coord address_street address_zipcode borough cuisine grades_date grades_grade grades_score name restaurant_id
58ada47de5a51ddfcd5ed51c 1007 -73.856077 Morris Park Ave 10462 Bronx Bakery 1393804800 A 2 Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.961704 Flatbush Avenue 11225 Brooklyn Hamburgers 1419897600 A 8 Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.98513559999999 West 57 Street 10019 Manhattan Irish 1409961600 A 2 Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.98241999999999 Stillwell Avenue 11224 Brooklyn American 1402358400 A 5 Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.8601152 63 Road 11374 Queens Jewish/Kosher 1416787200 Z 20 Tov Kosher Kitchen 40356068
DROP TABLE t1;
#
# Dropping a column
......@@ -259,7 +258,6 @@ t1 CREATE TABLE `t1` (
`address_street` char(38) NOT NULL `FIELD_FORMAT`='address.street',
`address_zipcode` char(5) NOT NULL `FIELD_FORMAT`='address.zipcode',
`borough` char(13) NOT NULL,
`grades` char(1) DEFAULT NULL,
`grades_date` bigint(13) DEFAULT NULL `FIELD_FORMAT`='grades.0.date',
`grades_grade` char(14) DEFAULT NULL `FIELD_FORMAT`='grades.0.grade',
`grades_score` bigint(2) DEFAULT NULL `FIELD_FORMAT`='grades.0.score',
......@@ -384,3 +382,4 @@ planner 167 41.75
postcard 23 5.75
DROP TABLE t1;
true
set connect_enable_mongo=0;
set connect_enable_mongo=1;
#
# Test the MONGO table type
#
......@@ -24,7 +25,6 @@ address_street 1 CHAR 38 38 0 0 address.street
address_zipcode 1 CHAR 5 5 0 0 address.zipcode
borough 1 CHAR 13 13 0 0
cuisine 1 CHAR 64 64 0 0
grades 1 CHAR 0 0 0 1
grades_date 1 CHAR 256 256 0 1 grades.0.date
grades_grade 1 CHAR 14 14 0 1 grades.0.grade
grades_score 5 BIGINT 2 2 0 1 grades.0.score
......@@ -71,7 +71,6 @@ t1 CREATE TABLE `t1` (
`address_zipcode` char(5) NOT NULL `FIELD_FORMAT`='address.zipcode',
`borough` char(13) NOT NULL,
`cuisine` char(64) NOT NULL,
`grades` char(1) DEFAULT NULL,
`grades_date` varchar(256) DEFAULT NULL `FIELD_FORMAT`='grades.0.date',
`grades_grade` char(14) DEFAULT NULL `FIELD_FORMAT`='grades.0.grade',
`grades_score` bigint(2) DEFAULT NULL `FIELD_FORMAT`='grades.0.score',
......@@ -79,12 +78,12 @@ t1 CREATE TABLE `t1` (
`restaurant_id` char(8) NOT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='mongodb://localhost:27017' `TABLE_TYPE`='JSON' `TABNAME`='restaurants' `OPTION_LIST`='Level=1,Driver=C,Version=0' `DATA_CHARSET`='utf8' `LRECL`=1024
SELECT * FROM t1 LIMIT 5;
_id address_building address_coord address_street address_zipcode borough cuisine grades grades_date grades_grade grades_score name restaurant_id
58ada47de5a51ddfcd5ed51c 1007 -73.856076999999999089 Morris Park Ave 10462 Bronx Bakery 1 1393804800 A 2 Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.96170399999999745 Flatbush Avenue 11225 Brooklyn Hamburgers 1 1419897600 A 8 Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.985135599999992451 West 57 Street 10019 Manhattan Irish 1 1409961600 A 2 Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.982419999999990523 Stillwell Avenue 11224 Brooklyn American 1 1402358400 A 5 Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.860115199999995639 63 Road 11374 Queens Jewish/Kosher 1 1416787200 Z 20 Tov Kosher Kitchen 40356068
_id address_building address_coord address_street address_zipcode borough cuisine grades_date grades_grade grades_score name restaurant_id
58ada47de5a51ddfcd5ed51c 1007 -73.856076999999999089 Morris Park Ave 10462 Bronx Bakery 1393804800 A 2 Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.96170399999999745 Flatbush Avenue 11225 Brooklyn Hamburgers 1419897600 A 8 Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.985135599999992451 West 57 Street 10019 Manhattan Irish 1409961600 A 2 Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.982419999999990523 Stillwell Avenue 11224 Brooklyn American 1402358400 A 5 Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.860115199999995639 63 Road 11374 Queens Jewish/Kosher 1416787200 Z 20 Tov Kosher Kitchen 40356068
DROP TABLE t1;
#
# Dropping a column
......@@ -258,7 +257,6 @@ t1 CREATE TABLE `t1` (
`address_street` char(38) NOT NULL `FIELD_FORMAT`='address.street',
`address_zipcode` char(5) NOT NULL `FIELD_FORMAT`='address.zipcode',
`borough` char(13) NOT NULL,
`grades` char(1) DEFAULT NULL,
`grades_date` bigint(13) DEFAULT NULL `FIELD_FORMAT`='grades.0.date',
`grades_grade` char(14) DEFAULT NULL `FIELD_FORMAT`='grades.0.grade',
`grades_score` bigint(2) DEFAULT NULL `FIELD_FORMAT`='grades.0.score',
......@@ -383,3 +381,4 @@ planner 167 41.75
postcard 23 5.75
DROP TABLE t1;
true
set connect_enable_mongo=0;
set connect_enable_mongo=1;
#
# Test the MONGO table type
#
......@@ -376,3 +377,4 @@ planner 167 41.750000
postcard 23 5.750000
DROP TABLE t1;
true
set connect_enable_mongo=0;
SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo2.jar';
set connect_enable_mongo=1;
#
# Test the MONGO table type
#
......@@ -377,3 +378,4 @@ planner 167 41.75
postcard 23 5.75
DROP TABLE t1;
true
set connect_enable_mongo=0;
SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo3.jar';
set connect_enable_mongo=1;
#
# Test the MONGO table type
#
......@@ -377,3 +378,4 @@ planner 167 41.75
postcard 23 5.75
DROP TABLE t1;
true
set connect_enable_mongo=0;
......@@ -72,11 +72,11 @@ TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr'
CATFUNC=Columns;
SELECT * FROM t1 WHERE Table_Schema='MTR' ORDER BY Table_Schema, Table_Name;
Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Radix Nullable Remarks
NULL MTR T1 A 3 DECIMAL 38 40 0 10 1 NULL
NULL MTR T1 B 6 NUMBER 38 40 NULL NULL 1 NULL
NULL MTR T2 A 12 VARCHAR2 64 64 NULL NULL 1 NULL
NULL MTR V1 A 3 DECIMAL 38 40 0 10 1 NULL
NULL MTR V1 B 6 NUMBER 38 40 NULL NULL 1 NULL
MTR T1 A 3 DECIMAL 38 40 0 10 1
MTR T1 B 6 NUMBER 38 40 NULL NULL 1
MTR T2 A 12 VARCHAR2 64 64 NULL NULL 1
MTR V1 A 3 DECIMAL 38 40 0 10 1
MTR V1 B 6 NUMBER 38 40 NULL NULL 1
DROP TABLE t1;
# All columns in all schemas (limited with WHERE)
CREATE TABLE t1 ENGINE=CONNECT
......@@ -84,18 +84,18 @@ TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr'
CATFUNC=Columns TABNAME='%.%';
SELECT * FROM t1 WHERE Table_Schema='MTR' ORDER BY Table_Schema, Table_Name;
Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Radix Nullable Remarks
NULL MTR T1 A 3 DECIMAL 38 40 0 10 1 NULL
NULL MTR T1 B 6 NUMBER 38 40 NULL NULL 1 NULL
NULL MTR T2 A 12 VARCHAR2 64 64 NULL NULL 1 NULL
NULL MTR V1 A 3 DECIMAL 38 40 0 10 1 NULL
NULL MTR V1 B 6 NUMBER 38 40 NULL NULL 1 NULL
MTR T1 A 3 DECIMAL 38 40 0 10 1
MTR T1 B 6 NUMBER 38 40 NULL NULL 1
MTR T2 A 12 VARCHAR2 64 64 NULL NULL 1
MTR V1 A 3 DECIMAL 38 40 0 10 1
MTR V1 B 6 NUMBER 38 40 NULL NULL 1
DROP TABLE t1;
# All tables "T1" in all schemas (limited with WHERE)
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr' CATFUNC=Columns TABNAME='%.T1';
SELECT * FROM t1 WHERE Table_Schema='MTR' ORDER BY Table_Schema, Table_Name;
Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Radix Nullable Remarks
NULL MTR T1 A 3 DECIMAL 38 40 0 10 1 NULL
NULL MTR T1 B 6 NUMBER 38 40 NULL NULL 1 NULL
MTR T1 A 3 DECIMAL 38 40 0 10 1
MTR T1 B 6 NUMBER 38 40 NULL NULL 1
DROP TABLE t1;
# Table "T1" in the schema "MTR"
CREATE TABLE t1 ENGINE=CONNECT
......@@ -103,8 +103,8 @@ TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr'
CATFUNC=Columns TABNAME='MTR.T1';
SELECT * FROM t1 ORDER BY Table_Schema, Table_Name;
Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Radix Nullable Remarks
NULL MTR T1 A 3 DECIMAL 38 40 0 10 1 NULL
NULL MTR T1 B 6 NUMBER 38 40 NULL NULL 1 NULL
MTR T1 A 3 DECIMAL 38 40 0 10 1
MTR T1 B 6 NUMBER 38 40 NULL NULL 1
DROP TABLE t1;
# All tables "T1" in all schemas (filtered with WHERE)
CREATE TABLE t1 ENGINE=CONNECT
......@@ -112,8 +112,8 @@ TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr'
CATFUNC=Columns TABNAME='%.T1';
SELECT * FROM t1 WHERE Table_Schema='MTR' ORDER BY Table_Schema, Table_Name;
Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Radix Nullable Remarks
NULL MTR T1 A 3 DECIMAL 38 40 0 10 1 NULL
NULL MTR T1 B 6 NUMBER 38 40 NULL NULL 1 NULL
MTR T1 A 3 DECIMAL 38 40 0 10 1
MTR T1 B 6 NUMBER 38 40 NULL NULL 1
DROP TABLE t1;
#
# Checking tables
......
......@@ -35,6 +35,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
connection default;
CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://root@127.0.0.1:MASTER_PORT/test/rt2';
......@@ -52,11 +68,36 @@ 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';
set connect_xtrace=1;
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
......@@ -69,12 +110,13 @@ a b
2 test02
1 test01
0 test00
set connect_xtrace=0;
connection master;
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;
#
# Old thread TBL tables test modified
#
......@@ -87,13 +129,15 @@ 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 t1,t2,total;
#
# Old thread TBL tables test not modified
# 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;
......@@ -104,10 +148,12 @@ 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;
......
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
set connect_enable_mongo=1;
--echo #
--echo # Test the MONGO table type
--echo #
......@@ -201,3 +203,5 @@ OPTION_LIST='Driver=$DRV,Version=$VERS,Pipeline=YES' $CONN;
SELECT * FROM t1;
DROP TABLE t1;
--exec $MONGO --eval "db.testcoll.drop()" --quiet
set connect_enable_mongo=0;
......@@ -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,11 +42,23 @@ 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';
set connect_xtrace=1;
SELECT * FROM total order by a desc;
set connect_xtrace=0;
connection master;
......@@ -48,11 +66,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
......@@ -67,11 +85,13 @@ 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';
set connect_xtrace=1;
SELECT * FROM total order by v desc;
set connect_xtrace=0;
DROP TABLE t1,t2,total;
--echo #
--echo # Old thread TBL tables test not modified
--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;
......@@ -81,7 +101,9 @@ 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';
set connect_xtrace=1;
SELECT * FROM total order by v desc;
set connect_xtrace=0;
DROP TABLE total;
DROP TABLE t1;
......
......@@ -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:
......
......@@ -789,7 +789,7 @@ int COLDEF::Define(PGLOBAL g, void *, PCOLINFO cfp, int poff)
Poff = poff;
Buf_Type = cfp->Type;
if ((Clen = GetTypeSize(Buf_Type, cfp->Length)) <= 0) {
if ((Clen = GetTypeSize(Buf_Type, cfp->Length)) < 0) {
sprintf(g->Message, MSG(BAD_COL_TYPE), GetTypeName(Buf_Type), Name);
return -1;
} // endswitch
......
......@@ -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);
......
......@@ -279,21 +279,13 @@ int TDBEXT::Decode(PCSZ txt, char *buf, size_t n)
} // end of Decode
/***********************************************************************/
/* MakeSQL: make the SQL statement use with remote connection. */
/* TODO: when implementing remote filtering, column only used in */
/* local filter should be removed from column list. */
/* MakeSrcdef: make the SQL statement from SRDEF option. */
/***********************************************************************/
bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
bool TDBEXT::MakeSrcdef(PGLOBAL g)
{
PCSZ schmp = NULL;
char *catp = NULL, buf[NAM_LEN * 3];
int len;
bool first = true;
PTABLE tablep = To_Table;
PCOL colp;
char *catp = strstr(Srcdef, "%s");
if (Srcdef) {
if ((catp = strstr(Srcdef, "%s"))) {
if (catp) {
char *fil1, *fil2;
PCSZ ph = ((EXTDEF*)To_Def)->Phpos;
......@@ -331,7 +323,24 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
Query = new(g)STRING(g, 0, Srcdef);
return false;
} // endif Srcdef
} // end of MakeSrcdef
/***********************************************************************/
/* MakeSQL: make the SQL statement use with remote connection. */
/* TODO: when implementing remote filtering, column only used in */
/* local filter should be removed from column list. */
/***********************************************************************/
bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
{
PCSZ schmp = NULL;
char *catp = NULL, buf[NAM_LEN * 3];
int len;
bool first = true;
PTABLE tablep = To_Table;
PCOL colp;
if (Srcdef)
return MakeSrcdef(g);
// Allocate the string used to contain the Query
Query = new(g)STRING(g, 1023, "SELECT ");
......
......@@ -126,6 +126,7 @@ class DllExport TDBEXT : public TDB {
protected:
// Internal functions
virtual bool MakeSrcdef(PGLOBAL g);
virtual bool MakeSQL(PGLOBAL g, bool cnt);
//virtual bool MakeInsert(PGLOBAL g);
virtual bool MakeCommand(PGLOBAL g);
......
......@@ -136,6 +136,7 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info)
tdp->Base = GetIntegerTableOption(g, topt, "Base", 0) ? 1 : 0;
tdp->Pretty = GetIntegerTableOption(g, topt, "Pretty", 2);
tdp->Xcol = GetStringTableOption(g, topt, "Expand", NULL);
tdp->Accept = GetBooleanTableOption(g, topt, "Accept", false);
tdp->Uri = (dsn && *dsn ? dsn : NULL);
if (!tdp->Fn && !tdp->Uri) {
......@@ -365,7 +366,7 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info)
jcp->Scale = MY_MAX(jcp->Scale, jcol.Scale);
jcp->Cbn |= jcol.Cbn;
jcp->Found = true;
} else {
} else if (jcol.Type != TYPE_UNKNOWN || tdp->Accept) {
// New column
jcp = (PJCL)PlugSubAlloc(g, NULL, sizeof(JCOL));
*jcp = jcol;
......@@ -448,8 +449,8 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info)
/* Now get the results into blocks. */
/*********************************************************************/
for (i = 0, jcp = fjcp; jcp; i++, jcp = jcp->Next) {
if (jcp->Type == TYPE_UNKNOWN) // Void column
jcp->Type = TYPE_STRING;
if (jcp->Type == TYPE_UNKNOWN)
jcp->Type = TYPE_STRING; // Void column
crp = qrp->Colresp; // Column Name
crp->Kdata->SetValue(jcp->Name, i);
......
......@@ -513,18 +513,8 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx)
if (Query)
return false; // already done
if (Srcdef) {
if (strstr(Srcdef, "%s")) {
char *fil;
fil = (To_CondFil) ? To_CondFil->Body : PlugDup(g, "1=1");
Query = new(g)STRING(g, strlen(Srcdef) + strlen(fil));
Query->SetLength(sprintf(Query->GetStr(), Srcdef, fil));
} else
Query = new(g)STRING(g, 0, Srcdef);
return false;
} // endif Srcdef
if (Srcdef)
return MakeSrcdef(g);
// Allocate the string used to contain Query
Query = new(g) STRING(g, 1023, "SELECT ");
......@@ -1270,7 +1260,8 @@ MYSQLCOL::MYSQLCOL(MYSQL_FIELD *fld, PTDB tdbp, int i, PCSZ am)
: COLBLK(NULL, tdbp, i)
{
const char *chset = get_charset_name(fld->charsetnr);
char v = (!strcmp(chset, "binary")) ? 'B' : 0;
//char v = (!strcmp(chset, "binary")) ? 'B' : 0;
char v = 0;
Name = fld->name;
Opt = 0;
......
......@@ -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);
......
......@@ -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
} 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,6 +695,9 @@ bool TDBTBM::OpenTables(PGLOBAL g)
ptp = &tp->Next;
Nrc++; // Number of remote connections
} else {
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,9 +823,12 @@ int TDBTBM::ReadNextRemote(PGLOBAL g)
Cmp = NULL;
retry:
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->Rc != RC_FX) {
if (tp->Ready) {
if (!tp->Complete) {
Cmp = tp;
......@@ -808,6 +838,8 @@ int TDBTBM::ReadNextRemote(PGLOBAL g)
} else
b = true;
} // endif Rc
pthread_mutex_unlock(&tblmut);
if (!Cmp) {
......
......@@ -146,6 +146,7 @@ class DllExport TDBTBM : public TDBTBL {
protected:
// Internal functions
bool IsLocal(PTABLE tbp);
bool OpenTables(PGLOBAL g);
int ReadNextRemote(PGLOBAL g);
......
......@@ -186,7 +186,8 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
crp->Kdata->SetValue(colname, i);
chset = (char *)fp->charset()->name;
v = (!strcmp(chset, "binary")) ? 'B' : 0;
// v = (!strcmp(chset, "binary")) ? 'B' : 0;
v = 0;
if ((type = MYSQLtoPLG(fp->type(), &v)) == TYPE_ERROR) {
if (v == 'K') {
......
......@@ -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<TYPE>::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;
......
......@@ -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
......
......@@ -176,7 +176,7 @@ int GetTypeSize(int type, int len)
case TYPE_DOUBLE: len = sizeof(double); break;
case TYPE_TINY: len = sizeof(char); break;
case TYPE_PCHAR: len = sizeof(char*); break;
default: len = 0;
default: len = -1;
} // endswitch type
return len;
......@@ -236,6 +236,7 @@ bool IsTypeChar(int type)
switch (type) {
case TYPE_STRING:
case TYPE_DECIM:
case TYPE_BIN:
return true;
} // endswitch type
......@@ -1369,7 +1370,7 @@ bool TYPVAL<PSZ>::SetValue_char(const char *cp, int n)
if (!cp || n == 0) {
Reset();
Null = Nullable;
Null = (cp) ? false : Nullable;
} else if (cp != Strp) {
const char *p = cp + n - 1;
......@@ -1858,7 +1859,8 @@ int DECVAL::CompareValue(PVAL vp)
BINVAL::BINVAL(PGLOBAL g, void *p, int cl, int n) : VALUE(TYPE_BIN)
{
assert(g);
Len = n;
//Len = n;
Len = (g) ? n : (p) ? strlen((char*)p) : 0;
Clen = cl;
Binp = PlugSubAlloc(g, NULL, Clen + 1);
memset(Binp, 0, Clen + 1);
......@@ -1992,10 +1994,15 @@ bool BINVAL::SetValue_pval(PVAL valp, bool chktype)
return true;
if (!(Null = valp->IsNull() && Nullable)) {
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();
......@@ -2012,9 +2019,14 @@ bool BINVAL::SetValue_char(const char *p, int n)
bool rc;
if (p && n > 0) {
rc = n > Clen;
Len = MY_MIN(n, Clen);
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;
......@@ -2031,8 +2043,13 @@ bool BINVAL::SetValue_char(const char *p, int n)
void BINVAL::SetValue_psz(PCSZ s)
{
if (s) {
Len = MY_MIN(Clen, (signed)strlen(s));
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();
......@@ -2053,13 +2070,18 @@ 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);
((char*)Binp)[Len] = 0;
Null = false;
} // endif vp
......@@ -2071,6 +2093,9 @@ void BINVAL::SetValue_pvblk(PVBLK blk, int n)
void BINVAL::SetValue(int n)
{
if (Clen >= 4) {
if (Len > 4)
memset(Binp, 0, Len);
*((int*)Binp) = n;
Len = 4;
} else
......@@ -2084,6 +2109,9 @@ void BINVAL::SetValue(int n)
void BINVAL::SetValue(uint n)
{
if (Clen >= 4) {
if (Len > 4)
memset(Binp, 0, Len);
*((uint*)Binp) = n;
Len = 4;
} else
......@@ -2097,6 +2125,9 @@ void BINVAL::SetValue(uint n)
void BINVAL::SetValue(short i)
{
if (Clen >= 2) {
if (Len > 2)
memset(Binp, 0, Len);
*((int*)Binp) = i;
Len = 2;
} else
......@@ -2110,6 +2141,9 @@ void BINVAL::SetValue(short i)
void BINVAL::SetValue(ushort i)
{
if (Clen >= 2) {
if (Len > 2)
memset(Binp, 0, Len);
*((uint*)Binp) = i;
Len = 2;
} else
......@@ -2123,6 +2157,9 @@ void BINVAL::SetValue(ushort i)
void BINVAL::SetValue(longlong n)
{
if (Clen >= 8) {
if (Len > 8)
memset(Binp, 0, Len);
*((longlong*)Binp) = n;
Len = 8;
} else
......@@ -2136,6 +2173,9 @@ void BINVAL::SetValue(longlong n)
void BINVAL::SetValue(ulonglong n)
{
if (Clen >= 8) {
if (Len > 8)
memset(Binp, 0, Len);
*((ulonglong*)Binp) = n;
Len = 8;
} else
......@@ -2147,6 +2187,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;
......@@ -2163,6 +2206,9 @@ void BINVAL::SetValue(double n)
/***********************************************************************/
void BINVAL::SetValue(char c)
{
if (Len > 1)
memset(Binp, 0, Len);
*((char*)Binp) = c;
Len = 1;
} // end of SetValue
......@@ -2172,6 +2218,9 @@ void BINVAL::SetValue(char c)
/***********************************************************************/
void BINVAL::SetValue(uchar c)
{
if (Len > 1)
memset(Binp, 0, Len);
*((uchar*)Binp) = c;
Len = 1;
} // end of SetValue
......@@ -2182,6 +2231,7 @@ void BINVAL::SetValue(uchar c)
void BINVAL::SetBinValue(void *p)
{
memcpy(Binp, p, Clen);
Len = Clen;
} // end of SetBinValue
/***********************************************************************/
......@@ -2207,10 +2257,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
/***********************************************************************/
......
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