Commit 67567f5c authored by Olivier Bertrand's avatar Olivier Bertrand

- 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.result
  modified:   storage/connect/mysql-test/connect/r/jdbc_postgresql.result
  modified:   storage/connect/mysql-test/connect/r/mysql_exec.result
  modified:   storage/connect/mysql-test/connect/r/odbc_postgresql.result

- Typo
  modified:   storage/connect/global.h
parent dbf25197
......@@ -254,7 +254,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);
......
/***********************************************************************/
/* 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,9 +170,9 @@
#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 compver[]= "Version 1.06.0008 " __DATE__ " " __TIME__;
char slash= '\\';
#else // !__WIN__
char slash= '/';
......@@ -3290,6 +3290,58 @@ 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.
......@@ -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,6 +3493,9 @@ int ha_connect::optimize(THD* thd, HA_CHECK_OPT*)
rc = HA_ERR_INTERNAL_ERROR;
} // end catch
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_DELETE_MULTI:
*cras = true;
case SQLCOM_DELETE:
case SQLCOM_TRUNCATE:
newmode= MODE_DELETE;
break;
case SQLCOM_UPDATE:
case SQLCOM_UPDATE_MULTI:
newmode= MODE_UPDATE;
*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,18 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd,
switch (thd_sql_command(thd)) {
case SQLCOM_CREATE_TABLE:
*chk= true;
*cras= true;
break;
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 +4645,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 +4929,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
......@@ -7248,7 +7310,7 @@ maria_declare_plugin(connect)
0x0107, /* version number (1.05) */
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
......
......@@ -236,24 +236,37 @@ WHEELFOR SALESMAN 10030.00
MARTIN ENGINEER 10000.00
DROP TABLE t1, connect.emp;
CREATE TABLE t2 (command varchar(128) not null,number int(5) not null flag=1,message varchar(255) flag=2) ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='jdbc:mariadb://localhost:PORT/connect' OPTION_LIST='User=root,Execsrc=1';
SELECT * FROM t2 WHERE command='drop table tx1';
command number message
drop table tx1 0 Execute: java.sql.SQLSyntaxErrorException: (conn:24) Unknown table 'connect.tx1'
Warnings:
Warning 1105 Execute: java.sql.SQLSyntaxErrorException: (conn:24) Unknown table 'connect.tx1'
SELECT * FROM t2 WHERE command = 'create table tx1 (a int not null, b char(32), c double(8,2))';
command number message
create table tx1 (a int not null, b char(32), c double(8,2)) 0 Affected rows
Warnings:
Warning 1105 Affected rows
SELECT * FROM t2 WHERE command in ('insert into tx1 values(1,''The number one'',456.12)',"insert into tx1(a,b) values(2,'The number two'),(3,'The number three')");
command number message
insert into tx1 values(1,'The number one',456.12) 1 Affected rows
insert into tx1(a,b) values(2,'The number two'),(3,'The number three') 2 Affected rows
Warnings:
Warning 1105 Affected rows
SELECT * FROM t2 WHERE command='update tx1 set c = 3.1416 where a = 2';
command number message
update tx1 set c = 3.1416 where a = 2 1 Affected rows
Warnings:
Warning 1105 Affected rows
SELECT * FROM t2 WHERE command='select * from tx1';
command number message
select * from tx1 3 Result set column number
Warnings:
Warning 1105 Result set column number
SELECT * FROM t2 WHERE command='delete from tx1 where a = 2';
command number message
delete from tx1 where a = 2 1 Affected rows
Warnings:
Warning 1105 Affected rows
SELECT * FROM connect.tx1;
a b c
1 The number one 456.12
......
......@@ -9,12 +9,18 @@ OPTION_LIST='Execsrc=1';
SELECT * FROM t2 WHERE command='drop table employee';
command number message
drop table employee 0 Execute: org.postgresql.util.PSQLException: ERREUR: la table « employee » n'existe pas
Warnings:
Warning 1105 Execute: org.postgresql.util.PSQLException: ERREUR: la table employee n'existe pas
SELECT * FROM t2 WHERE command = 'create table employee (id int not null, name varchar(32), title char(16), salary decimal(8,2))';
command number message
create table employee (id int not null, name varchar(32), title char(16), salary decimal(8,2)) 0 Affected rows
Warnings:
Warning 1105 Affected rows
SELECT * FROM t2 WHERE command = "insert into employee values(4567,'Johnson', 'Engineer', 12560.50)";
command number message
insert into employee values(4567,'Johnson', 'Engineer', 12560.50) 1 Affected rows
Warnings:
Warning 1105 Affected rows
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=tables
CONNECTION='jdbc:postgresql://localhost/test?user=postgres&password=tinono'
OPTION_LIST='Tabtype=TABLE,Maxres=10';
......@@ -63,4 +69,6 @@ DROP SERVER 'postgresql';
SELECT * FROM t2 WHERE command='drop table employee';
command number message
drop table employee 0 Affected rows
Warnings:
Warning 1105 Affected rows
DROP TABLE t2;
......@@ -35,6 +35,8 @@ insert ignore into t1(id) values(NULL) 1 1 Affected rows
Warning 0 1364 Field 'msg' doesn't have a default value
update t1 set msg = 'Four' where id = 4 0 1 Affected rows
select * from t1 0 2 Result set columns
Warnings:
Warning 1105 Result set columns
#
# Checking Using Procedure
#
......@@ -48,9 +50,13 @@ CALL p1('insert ignore into t1(id) values(NULL)');
command warnings number message
insert ignore into t1(id) values(NULL) 1 1 Affected rows
Warning 0 1364 Field 'msg' doesn't have a default value
Warnings:
Warning 1105 Affected rows
CALL p1('update t1 set msg = "Five" where id = 5');
command warnings number message
update t1 set msg = "Five" where id = 5 0 1 Affected rows
Warnings:
Warning 1105 Affected rows
DROP PROCEDURE p1;
DROP TABLE t1;
connection slave;
......
......@@ -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
......
......@@ -1249,9 +1249,10 @@ bool TDBXDBC::OpenDB(PGLOBAL g)
/* Get the command to execute. */
/*********************************************************************/
if (!(Cmdlist = MakeCMD(g))) {
Ocp->Close();
return true;
} // endif Query
// Next lines commented out because of CHECK TABLE
//Ocp->Close();
//return true;
} // endif Cmdlist
Rows = 1;
return false;
......@@ -1274,8 +1275,10 @@ int TDBXDBC::ReadDB(PGLOBAL g)
Fpos++; // Used for progress info
Cmdlist = (Nerr > Mxr) ? NULL : Cmdlist->Next;
return RC_OK;
} else
return RC_EF;
} else {
PushWarning(g, this, 1);
return RC_EF;
} // endif Cmdlist
} // end of ReadDB
......
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