Skip to content

Commit ad09ea0

Browse files
committed
- 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
1 parent 15194de commit ad09ea0

File tree

11 files changed

+131
-59
lines changed

11 files changed

+131
-59
lines changed

storage/connect/connect.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2,
255255

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

storage/connect/global.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/***********************************************************************/
22
/* GLOBAL.H: Declaration file used by all CONNECT implementations. */
33
/* (C) Copyright MariaDB Corporation Ab */
4-
/* Author Olivier Bertrand 1993-2017 */
4+
/* Author Olivier Bertrand 1993-2018 */
55
/***********************************************************************/
66

77
/***********************************************************************/
@@ -192,7 +192,7 @@ typedef struct _global { /* Global structure */
192192
PACTIVITY Activityp;
193193
char Message[MAX_STR];
194194
ulong More; /* Used by jsonudf */
195-
int Createas; /* To pass info to created table */
195+
int Createas; /* To pass multi to ext tables */
196196
void *Xchk; /* indexes in create/alter */
197197
short Alchecked; /* Checked for ALTER */
198198
short Mrr; /* True when doing mrr */

storage/connect/ha_connect.cc

Lines changed: 85 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@
170170
#define JSONMAX 10 // JSON Default max grp size
171171

172172
extern "C" {
173-
char version[]= "Version 1.06.0007 August 06, 2018";
173+
char version[] = "Version 1.06.0008 October 06, 2018";
174174
#if defined(__WIN__)
175-
char compver[]= "Version 1.06.0007 " __DATE__ " " __TIME__;
176-
char slash= '\\';
175+
char compver[] = "Version 1.06.0008 " __DATE__ " " __TIME__;
176+
char slash = '\\';
177177
#else // !__WIN__
178-
char slash= '/';
178+
char slash = '/';
179179
#endif // !__WIN__
180180
} // extern "C"
181181

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

32923292

3293-
/**
3293+
int ha_connect::check(THD* thd, HA_CHECK_OPT* check_opt)
3294+
{
3295+
int rc = HA_ADMIN_OK;
3296+
PGLOBAL g = ((table && table->in_use) ? GetPlug(table->in_use, xp) :
3297+
(xp) ? xp->g : NULL);
3298+
DBUG_ENTER("ha_connect::check");
3299+
3300+
if (!g || !table || xmod != MODE_READ)
3301+
DBUG_RETURN(HA_ADMIN_INTERNAL_ERROR);
3302+
3303+
// Do not close the table if it was opened yet (possible?)
3304+
if (IsOpened()) {
3305+
if (IsPartitioned() && CheckColumnList(g)) // map can have been changed
3306+
rc = HA_ADMIN_CORRUPT;
3307+
else if (tdbp->OpenDB(g)) // Rewind table
3308+
rc = HA_ADMIN_CORRUPT;
3309+
3310+
} else if (xp->CheckQuery(valid_query_id)) {
3311+
tdbp = NULL; // Not valid anymore
3312+
3313+
if (OpenTable(g, false))
3314+
rc = HA_ADMIN_CORRUPT;
3315+
3316+
} else // possible?
3317+
DBUG_RETURN(HA_ADMIN_INTERNAL_ERROR);
3318+
3319+
if (rc == HA_ADMIN_OK) {
3320+
TABTYPE type = GetTypeID(GetStringOption("Type", "*"));
3321+
3322+
if (IsFileType(type)) {
3323+
if (check_opt->flags & T_MEDIUM) {
3324+
// TO DO
3325+
do {
3326+
if ((rc = CntReadNext(g, tdbp)) == RC_FX)
3327+
break;
3328+
3329+
} while (rc != RC_EF);
3330+
3331+
rc = (rc == RC_EF) ? HA_ADMIN_OK : HA_ADMIN_CORRUPT;
3332+
} else if (check_opt->flags & T_EXTEND) {
3333+
// TO DO
3334+
} // endif's flags
3335+
3336+
} // endif file type
3337+
3338+
} else
3339+
PushWarning(g, thd, 1);
3340+
3341+
DBUG_RETURN(rc);
3342+
} // end of check
3343+
3344+
3345+
/**
32943346
Return an error message specific to this handler.
32953347
32963348
@param error error code previously returned by handler
@@ -3309,7 +3361,8 @@ bool ha_connect::get_error_message(int error, String* buf)
33093361
if (trace(1))
33103362
htrc("GEM(%d): %s\n", error, g->Message);
33113363

3312-
buf->append(g->Message);
3364+
buf->append(ErrConvString(g->Message, strlen(g->Message),
3365+
&my_charset_latin1).ptr());
33133366
} else
33143367
buf->append("Cannot retrieve error message");
33153368

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

34293482
} // endif rc
34303483

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

3443-
return rc;
3496+
if (rc)
3497+
my_message(ER_WARN_DATA_OUT_OF_RANGE, g->Message, MYF(0));
3498+
3499+
return rc;
34443500
} // end of optimize
34453501

34463502
/**
@@ -4501,14 +4557,16 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd,
45014557
// case SQLCOM_REPLACE_SELECT:
45024558
// newmode= MODE_UPDATE; // To be checked
45034559
// break;
4504-
case SQLCOM_DELETE:
4505-
case SQLCOM_DELETE_MULTI:
4506-
case SQLCOM_TRUNCATE:
4560+
case SQLCOM_DELETE_MULTI:
4561+
*cras = true;
4562+
case SQLCOM_DELETE:
4563+
case SQLCOM_TRUNCATE:
45074564
newmode= MODE_DELETE;
45084565
break;
4509-
case SQLCOM_UPDATE:
4510-
case SQLCOM_UPDATE_MULTI:
4511-
newmode= MODE_UPDATE;
4566+
case SQLCOM_UPDATE_MULTI:
4567+
*cras = true;
4568+
case SQLCOM_UPDATE:
4569+
newmode= MODE_UPDATE;
45124570
break;
45134571
case SQLCOM_SELECT:
45144572
case SQLCOM_OPTIMIZE:
@@ -4533,8 +4591,10 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd,
45334591
newmode= MODE_ANY;
45344592
break;
45354593
// } // endif partitioned
4536-
4537-
default:
4594+
case SQLCOM_REPAIR: // TODO implement it
4595+
newmode = MODE_UPDATE;
4596+
break;
4597+
default:
45384598
htrc("Unsupported sql_command=%d\n", thd_sql_command(thd));
45394599
strcpy(g->Message, "CONNECT Unsupported command");
45404600
my_message(ER_NOT_ALLOWED_COMMAND, g->Message, MYF(0));
@@ -4546,17 +4606,17 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd,
45464606
switch (thd_sql_command(thd)) {
45474607
case SQLCOM_CREATE_TABLE:
45484608
*chk= true;
4549-
*cras= true;
4609+
case SQLCOM_UPDATE_MULTI:
4610+
case SQLCOM_DELETE_MULTI:
4611+
*cras= true;
45504612
case SQLCOM_INSERT:
45514613
case SQLCOM_LOAD:
45524614
case SQLCOM_INSERT_SELECT:
45534615
// case SQLCOM_REPLACE:
45544616
// case SQLCOM_REPLACE_SELECT:
45554617
case SQLCOM_DELETE:
4556-
case SQLCOM_DELETE_MULTI:
45574618
case SQLCOM_TRUNCATE:
45584619
case SQLCOM_UPDATE:
4559-
case SQLCOM_UPDATE_MULTI:
45604620
case SQLCOM_SELECT:
45614621
case SQLCOM_OPTIMIZE:
45624622
case SQLCOM_SET_OPTION:
@@ -4584,8 +4644,9 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd,
45844644
break;
45854645
// } // endif partitioned
45864646

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

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

48724933
if (trace(1)) {
48734934
#if 0
@@ -7247,10 +7308,10 @@ maria_declare_plugin(connect)
72477308
PLUGIN_LICENSE_GPL,
72487309
connect_init_func, /* Plugin Init */
72497310
connect_done_func, /* Plugin Deinit */
7250-
0x0107, /* version number (1.05) */
7311+
0x0106, /* version number (1.06) */
72517312
NULL, /* status variables */
72527313
connect_system_variables, /* system variables */
7253-
"1.06.0007", /* string version */
7314+
"1.06.0008", /* string version */
72547315
MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
72557316
}
72567317
maria_declare_plugin_end;

storage/connect/ha_connect.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,7 @@ PFIL CondFilter(PGLOBAL g, Item *cond);
347347
//PFIL CheckFilter(PGLOBAL g);
348348

349349
/** admin commands - called from mysql_admin_table */
350-
virtual int check(THD* thd, HA_CHECK_OPT* check_opt)
351-
{
352-
// TODO: implement it
353-
return HA_ADMIN_OK; // Just to avoid error message with checktables
354-
} // end of check
350+
virtual int check(THD* thd, HA_CHECK_OPT* check_opt);
355351

356352
/**
357353
Number of rows in table. It will only be called if

storage/connect/mysql-test/connect/r/jdbc_postgresql.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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';
1+
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';
22
CREATE TABLE t2 (
33
command varchar(128) not null,
44
number int(5) not null flag=1,

storage/connect/mysql-test/connect/r/odbc_postgresql.result

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Bu
9999
mtr public t1 a 4 int4 10 4 0 10 0
100100
mtr public t2 a 4 int4 10 4 0 10 0
101101
mtr public v1 a 4 int4 10 4 0 10 1
102-
mtr schema1 t1 a 1 bpchar 10 60 NULL NULL 0
103-
mtr schema1 t2 a 1 bpchar 10 60 NULL NULL 0
104-
mtr schema1 v1 a 1 bpchar 10 60 NULL NULL 1
102+
mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0
103+
mtr schema1 t2 a 1 bpchar 10 40 NULL NULL 0
104+
mtr schema1 v1 a 1 bpchar 10 40 NULL NULL 1
105105
DROP TABLE t1;
106106
# All columns in the schemas "public" and "schema1"
107107
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
110110
mtr public t1 a 4 int4 10 4 0 10 0
111111
mtr public t2 a 4 int4 10 4 0 10 0
112112
mtr public v1 a 4 int4 10 4 0 10 1
113-
mtr schema1 t1 a 1 bpchar 10 60 NULL NULL 0
114-
mtr schema1 t2 a 1 bpchar 10 60 NULL NULL 0
115-
mtr schema1 v1 a 1 bpchar 10 60 NULL NULL 1
113+
mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0
114+
mtr schema1 t2 a 1 bpchar 10 40 NULL NULL 0
115+
mtr schema1 v1 a 1 bpchar 10 40 NULL NULL 1
116116
DROP TABLE t1;
117117
# All tables "t1" in all schemas
118118
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' CATFUNC=Columns TABNAME='%.%.t1';
119119
SELECT * FROM t1 ORDER BY Table_Schema, Table_Name;
120120
Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Radix Nullable Remarks
121121
mtr public t1 a 4 int4 10 4 0 10 0
122-
mtr schema1 t1 a 1 bpchar 10 60 NULL NULL 0
122+
mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0
123123
DROP TABLE t1;
124124
# Table "t1" in the schema "public"
125125
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;
131131
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' CATFUNC=Columns TABNAME='%.schema1.t1';
132132
SELECT * FROM t1 ORDER BY Table_Schema, Table_Name;
133133
Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Radix Nullable Remarks
134-
mtr schema1 t1 a 1 bpchar 10 60 NULL NULL 0
134+
mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0
135135
DROP TABLE t1;
136136
# All tables "t1" in all schemas (Catalog name is ignored by PostgreSQL)
137137
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' CATFUNC=Columns TABNAME='xxx.%.t1';
138138
SELECT * FROM t1 ORDER BY Table_Schema, Table_Name;
139139
Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Radix Nullable Remarks
140140
mtr public t1 a 4 int4 10 4 0 10 0
141-
mtr schema1 t1 a 1 bpchar 10 60 NULL NULL 0
141+
mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0
142142
DROP TABLE t1;
143143
#
144144
# Checking tables

storage/connect/odbconn.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,11 +2354,11 @@ int ODBConn::GetCatInfo(CATPARM *cap)
23542354
if (!Check(rc))
23552355
ThrowDBX(rc, fnc, hstmt);
23562356

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

23632363
// Unconditional to handle STRBLK's
23642364
pval = (PVAL *)PlugSubAlloc(g, NULL, n * sizeof(PVAL));

storage/connect/tabext.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ EXTDEF::EXTDEF(void)
125125
/***********************************************************************/
126126
bool EXTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
127127
{
128+
if (g->Createas) {
129+
strcpy(g->Message,
130+
"Multiple-table UPDATE/DELETE commands are not supported");
131+
return true;
132+
} // endif multi
133+
128134
Desc = NULL;
129135
Tabname = GetStringCatInfo(g, "Name",
130136
(Catfunc & (FNC_TABLE | FNC_COL)) ? NULL : Name);

storage/connect/tabjdbc.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,8 +1157,9 @@ bool TDBXJDC::OpenDB(PGLOBAL g)
11571157
/* Get the command to execute. */
11581158
/*********************************************************************/
11591159
if (!(Cmdlist = MakeCMD(g))) {
1160-
Jcp->Close();
1161-
return true;
1160+
// Next lines commented out because of CHECK TABLE
1161+
//Jcp->Close();
1162+
//return true;
11621163
} // endif Query
11631164

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

11951198
} // end of ReadDB
11961199

storage/connect/tabmysql.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,8 +1587,9 @@ bool TDBMYEXC::OpenDB(PGLOBAL g)
15871587
/* Get the command to execute. */
15881588
/*********************************************************************/
15891589
if (!(Cmdlist = MakeCMD(g))) {
1590-
Myc.Close();
1591-
return true;
1590+
// Next lines commented out because of CHECK TABLE
1591+
//Myc.Close();
1592+
//return true;
15921593
} // endif Cmdlist
15931594

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

16481649
++N;
16491650
return RC_OK;
1650-
} else
1651-
return RC_EF;
1651+
} else {
1652+
PushWarning(g, this, 1);
1653+
return RC_EF;
1654+
} // endif Cmdlist
16521655

16531656
} // end of ReadDB
16541657

0 commit comments

Comments
 (0)