Skip to content
Permalink
Browse files
- Implement the CHECK TABLE statement and accept REPAIR and ANALYZE
  modified:   storage/connect/connect.cc
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/ha_connect.h
  modified:   storage/connect/tabjdbc.cpp
  modified:   storage/connect/tabmysql.cpp
  modified:   storage/connect/tabodbc.cpp

- MDEV-17212: Test if NumResultCols is implemented by the data source
  modified:   storage/connect/odbconn.cpp

- Change error type in Optimize
  modified:   storage/connect/ha_connect.cc

- Update version date
  modified:   storage/connect/ha_connect.cc

- Fix truncating error messages on first unrecognized latin1 character
  modified:   storage/connect/ha_connect.cc

- Fix MDEV-17343
  Reject multi-table UPDATE/DELETE commands that crash on some systems
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/tabext.cpp

- Try fix some failing tests
  modified:   storage/connect/mysql-test/connect/r/jdbc_postgresql.result
  modified:   storage/connect/mysql-test/connect/r/odbc_postgresql.result

- Typo
  modified:   storage/connect/global.h
  • Loading branch information
Buggynours committed Oct 14, 2018
1 parent 15194de commit ad09ea0
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 59 deletions.
@@ -255,7 +255,7 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2,

try {
if (!c1) {
if (mode == MODE_INSERT)
// if (mode == MODE_INSERT) or CHECK TABLE
// Allocate all column blocks for that table
tdbp->ColDB(g, NULL, 0);

@@ -1,7 +1,7 @@
/***********************************************************************/
/* GLOBAL.H: Declaration file used by all CONNECT implementations. */
/* (C) Copyright MariaDB Corporation Ab */
/* Author Olivier Bertrand 1993-2017 */
/* Author Olivier Bertrand 1993-2018 */
/***********************************************************************/

/***********************************************************************/
@@ -192,7 +192,7 @@ typedef struct _global { /* Global structure */
PACTIVITY Activityp;
char Message[MAX_STR];
ulong More; /* Used by jsonudf */
int Createas; /* To pass info to created table */
int Createas; /* To pass multi to ext tables */
void *Xchk; /* indexes in create/alter */
short Alchecked; /* Checked for ALTER */
short Mrr; /* True when doing mrr */
@@ -170,12 +170,12 @@
#define JSONMAX 10 // JSON Default max grp size

extern "C" {
char version[]= "Version 1.06.0007 August 06, 2018";
char version[] = "Version 1.06.0008 October 06, 2018";
#if defined(__WIN__)
char compver[]= "Version 1.06.0007 " __DATE__ " " __TIME__;
char slash= '\\';
char compver[] = "Version 1.06.0008 " __DATE__ " " __TIME__;
char slash = '\\';
#else // !__WIN__
char slash= '/';
char slash = '/';
#endif // !__WIN__
} // extern "C"

@@ -3290,7 +3290,59 @@ ha_rows ha_connect::records()
} // end of records


/**
int ha_connect::check(THD* thd, HA_CHECK_OPT* check_opt)
{
int rc = HA_ADMIN_OK;
PGLOBAL g = ((table && table->in_use) ? GetPlug(table->in_use, xp) :
(xp) ? xp->g : NULL);
DBUG_ENTER("ha_connect::check");

if (!g || !table || xmod != MODE_READ)
DBUG_RETURN(HA_ADMIN_INTERNAL_ERROR);

// Do not close the table if it was opened yet (possible?)
if (IsOpened()) {
if (IsPartitioned() && CheckColumnList(g)) // map can have been changed
rc = HA_ADMIN_CORRUPT;
else if (tdbp->OpenDB(g)) // Rewind table
rc = HA_ADMIN_CORRUPT;

} else if (xp->CheckQuery(valid_query_id)) {
tdbp = NULL; // Not valid anymore

if (OpenTable(g, false))
rc = HA_ADMIN_CORRUPT;

} else // possible?
DBUG_RETURN(HA_ADMIN_INTERNAL_ERROR);

if (rc == HA_ADMIN_OK) {
TABTYPE type = GetTypeID(GetStringOption("Type", "*"));

if (IsFileType(type)) {
if (check_opt->flags & T_MEDIUM) {
// TO DO
do {
if ((rc = CntReadNext(g, tdbp)) == RC_FX)
break;

} while (rc != RC_EF);

rc = (rc == RC_EF) ? HA_ADMIN_OK : HA_ADMIN_CORRUPT;
} else if (check_opt->flags & T_EXTEND) {
// TO DO
} // endif's flags

} // endif file type

} else
PushWarning(g, thd, 1);

DBUG_RETURN(rc);
} // end of check


/**
Return an error message specific to this handler.
@param error error code previously returned by handler
@@ -3309,7 +3361,8 @@ bool ha_connect::get_error_message(int error, String* buf)
if (trace(1))
htrc("GEM(%d): %s\n", error, g->Message);

buf->append(g->Message);
buf->append(ErrConvString(g->Message, strlen(g->Message),
&my_charset_latin1).ptr());
} else
buf->append("Cannot retrieve error message");

@@ -3424,7 +3477,7 @@ int ha_connect::optimize(THD* thd, HA_CHECK_OPT*)
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message);
rc = 0;
} else
rc = HA_ERR_INTERNAL_ERROR;
rc = HA_ERR_CRASHED_ON_USAGE; // Table must be repaired

} // endif rc

@@ -3440,7 +3493,10 @@ int ha_connect::optimize(THD* thd, HA_CHECK_OPT*)
rc = HA_ERR_INTERNAL_ERROR;
} // end catch

return rc;
if (rc)
my_message(ER_WARN_DATA_OUT_OF_RANGE, g->Message, MYF(0));

return rc;
} // end of optimize

/**
@@ -4501,14 +4557,16 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd,
// case SQLCOM_REPLACE_SELECT:
// newmode= MODE_UPDATE; // To be checked
// break;
case SQLCOM_DELETE:
case SQLCOM_DELETE_MULTI:
case SQLCOM_TRUNCATE:
case SQLCOM_DELETE_MULTI:
*cras = true;
case SQLCOM_DELETE:
case SQLCOM_TRUNCATE:
newmode= MODE_DELETE;
break;
case SQLCOM_UPDATE:
case SQLCOM_UPDATE_MULTI:
newmode= MODE_UPDATE;
case SQLCOM_UPDATE_MULTI:
*cras = true;
case SQLCOM_UPDATE:
newmode= MODE_UPDATE;
break;
case SQLCOM_SELECT:
case SQLCOM_OPTIMIZE:
@@ -4533,8 +4591,10 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd,
newmode= MODE_ANY;
break;
// } // endif partitioned

default:
case SQLCOM_REPAIR: // TODO implement it
newmode = MODE_UPDATE;
break;
default:
htrc("Unsupported sql_command=%d\n", thd_sql_command(thd));
strcpy(g->Message, "CONNECT Unsupported command");
my_message(ER_NOT_ALLOWED_COMMAND, g->Message, MYF(0));
@@ -4546,17 +4606,17 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd,
switch (thd_sql_command(thd)) {
case SQLCOM_CREATE_TABLE:
*chk= true;
*cras= true;
case SQLCOM_UPDATE_MULTI:
case SQLCOM_DELETE_MULTI:
*cras= true;
case SQLCOM_INSERT:
case SQLCOM_LOAD:
case SQLCOM_INSERT_SELECT:
// case SQLCOM_REPLACE:
// case SQLCOM_REPLACE_SELECT:
case SQLCOM_DELETE:
case SQLCOM_DELETE_MULTI:
case SQLCOM_TRUNCATE:
case SQLCOM_UPDATE:
case SQLCOM_UPDATE_MULTI:
case SQLCOM_SELECT:
case SQLCOM_OPTIMIZE:
case SQLCOM_SET_OPTION:
@@ -4584,8 +4644,9 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd,
break;
// } // endif partitioned

case SQLCOM_CHECK: // TODO implement it
case SQLCOM_END: // Met in procedures: IF(EXISTS(SELECT...
case SQLCOM_CHECK: // TODO implement it
case SQLCOM_ANALYZE: // TODO implement it
case SQLCOM_END: // Met in procedures: IF(EXISTS(SELECT...
newmode= MODE_READ;
break;
default:
@@ -4867,7 +4928,7 @@ int ha_connect::external_lock(THD *thd, int lock_type)
#endif // 0

if (cras)
g->Createas= 1; // To tell created table to ignore FLAG
g->Createas= 1; // To tell external tables of a multi-table command

if (trace(1)) {
#if 0
@@ -7247,10 +7308,10 @@ maria_declare_plugin(connect)
PLUGIN_LICENSE_GPL,
connect_init_func, /* Plugin Init */
connect_done_func, /* Plugin Deinit */
0x0107, /* version number (1.05) */
0x0106, /* version number (1.06) */
NULL, /* status variables */
connect_system_variables, /* system variables */
"1.06.0007", /* string version */
"1.06.0008", /* string version */
MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
}
maria_declare_plugin_end;
@@ -347,11 +347,7 @@ 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
virtual int check(THD* thd, HA_CHECK_OPT* check_opt);

/**
Number of rows in table. It will only be called if
@@ -1,4 +1,4 @@
SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/JavaWrappers.jar;C:/Jconnectors/postgresql-42.2.1.jar';
SET GLOBAL connect_class_path='C:/MariaDB-10.3/MariaDB/storage/connect/mysql-test/connect/std_data/JavaWrappers.jar;C:/Jconnectors/postgresql-42.2.1.jar';
CREATE TABLE t2 (
command varchar(128) not null,
number int(5) not null flag=1,
@@ -99,9 +99,9 @@ Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Bu
mtr public t1 a 4 int4 10 4 0 10 0
mtr public t2 a 4 int4 10 4 0 10 0
mtr public v1 a 4 int4 10 4 0 10 1
mtr schema1 t1 a 1 bpchar 10 60 NULL NULL 0
mtr schema1 t2 a 1 bpchar 10 60 NULL NULL 0
mtr schema1 v1 a 1 bpchar 10 60 NULL NULL 1
mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0
mtr schema1 t2 a 1 bpchar 10 40 NULL NULL 0
mtr schema1 v1 a 1 bpchar 10 40 NULL NULL 1
DROP TABLE t1;
# All columns in the schemas "public" and "schema1"
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' CATFUNC=Columns TABNAME='%.%.%';
@@ -110,16 +110,16 @@ Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Bu
mtr public t1 a 4 int4 10 4 0 10 0
mtr public t2 a 4 int4 10 4 0 10 0
mtr public v1 a 4 int4 10 4 0 10 1
mtr schema1 t1 a 1 bpchar 10 60 NULL NULL 0
mtr schema1 t2 a 1 bpchar 10 60 NULL NULL 0
mtr schema1 v1 a 1 bpchar 10 60 NULL NULL 1
mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0
mtr schema1 t2 a 1 bpchar 10 40 NULL NULL 0
mtr schema1 v1 a 1 bpchar 10 40 NULL NULL 1
DROP TABLE t1;
# All tables "t1" in all schemas
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' CATFUNC=Columns TABNAME='%.%.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
mtr public t1 a 4 int4 10 4 0 10 0
mtr schema1 t1 a 1 bpchar 10 60 NULL NULL 0
mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0
DROP TABLE t1;
# Table "t1" in the schema "public"
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' CATFUNC=Columns TABNAME='%.public.t1';
@@ -131,14 +131,14 @@ DROP TABLE t1;
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' CATFUNC=Columns TABNAME='%.schema1.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
mtr schema1 t1 a 1 bpchar 10 60 NULL NULL 0
mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0
DROP TABLE t1;
# All tables "t1" in all schemas (Catalog name is ignored by PostgreSQL)
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' CATFUNC=Columns TABNAME='xxx.%.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
mtr public t1 a 4 int4 10 4 0 10 0
mtr schema1 t1 a 1 bpchar 10 60 NULL NULL 0
mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0
DROP TABLE t1;
#
# Checking tables
@@ -2354,11 +2354,11 @@ int ODBConn::GetCatInfo(CATPARM *cap)
if (!Check(rc))
ThrowDBX(rc, fnc, hstmt);

rc = SQLNumResultCols(hstmt, &ncol);

// n because we no more ignore the first column
if ((n = (UWORD)qrp->Nbcol) > (UWORD)ncol)
ThrowDBX(MSG(COL_NUM_MISM));
// Some data source do not implement SQLNumResultCols
if (Check(SQLNumResultCols(hstmt, &ncol)))
// n because we no more ignore the first column
if ((n = (UWORD)qrp->Nbcol) > (UWORD)ncol)
ThrowDBX(MSG(COL_NUM_MISM));

// Unconditional to handle STRBLK's
pval = (PVAL *)PlugSubAlloc(g, NULL, n * sizeof(PVAL));
@@ -125,6 +125,12 @@ EXTDEF::EXTDEF(void)
/***********************************************************************/
bool EXTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
{
if (g->Createas) {
strcpy(g->Message,
"Multiple-table UPDATE/DELETE commands are not supported");
return true;
} // endif multi

Desc = NULL;
Tabname = GetStringCatInfo(g, "Name",
(Catfunc & (FNC_TABLE | FNC_COL)) ? NULL : Name);
@@ -1157,8 +1157,9 @@ bool TDBXJDC::OpenDB(PGLOBAL g)
/* Get the command to execute. */
/*********************************************************************/
if (!(Cmdlist = MakeCMD(g))) {
Jcp->Close();
return true;
// Next lines commented out because of CHECK TABLE
//Jcp->Close();
//return true;
} // endif Query

Rows = 1;
@@ -1189,8 +1190,10 @@ int TDBXJDC::ReadDB(PGLOBAL g)
Fpos++; // Used for progress info
Cmdlist = (Nerr > Mxr) ? NULL : Cmdlist->Next;
return RC_OK;
} else
} else {
PushWarning(g, this, 1);
return RC_EF;
} // endif Cmdlist

} // end of ReadDB

@@ -1587,8 +1587,9 @@ bool TDBMYEXC::OpenDB(PGLOBAL g)
/* Get the command to execute. */
/*********************************************************************/
if (!(Cmdlist = MakeCMD(g))) {
Myc.Close();
return true;
// Next lines commented out because of CHECK TABLE
//Myc.Close();
//return true;
} // endif Cmdlist

return false;
@@ -1647,8 +1648,10 @@ int TDBMYEXC::ReadDB(PGLOBAL g)

++N;
return RC_OK;
} else
return RC_EF;
} else {
PushWarning(g, this, 1);
return RC_EF;
} // endif Cmdlist

} // end of ReadDB

0 comments on commit ad09ea0

Please sign in to comment.