Skip to content

Commit

Permalink
- Fix to MDEV-9542 Connect was not handling NULLs in the answer
Browse files Browse the repository at this point in the history
  from catalog functions and tables. It does now and when decimal
  is NULL defines DOUBLE without parameters.
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/mysql-test/connect/r/odbc.result
  modified:   storage/connect/mysql-test/connect/r/odbc_oracle.result
  modified:   storage/connect/mysql-test/connect/r/odbc_postgresql.result
  modified:   storage/connect/mysql-test/connect/r/odbc_sqlite3.result
  modified:   storage/connect/mysql-test/connect/r/odbc_xls.result
  modified:   storage/connect/odbconn.cpp
  modified:   storage/connect/table.cpp
  modified:   storage/connect/valblk.h
  • Loading branch information
Buggynours committed Feb 15, 2016
1 parent 62a5e56 commit 481e643
Show file tree
Hide file tree
Showing 10 changed files with 2,520 additions and 2,490 deletions.
21 changes: 11 additions & 10 deletions storage/connect/ha_connect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4926,11 +4926,11 @@ 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) {
if (len && typ != TYPE_DATE && (typ != TYPE_DOUBLE || dec >= 0)) {
error|= sql->append('(');
error|= sql->append_ulonglong(len);

if (!strcmp(type, "DOUBLE")) {
if (typ == TYPE_DOUBLE) {
error|= sql->append(',');
// dec must be < len and < 31
error|= sql->append_ulonglong(MY_MIN(dec, (MY_MIN(len, 31) - 1)));
Expand Down Expand Up @@ -5516,16 +5516,17 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
dec= crp->Prec;
flg= crp->Flag;
v= crp->Var;
tm= (crp->Kdata->IsNullable()) ? 0 : NOT_NULL_FLAG;

if (!len && typ == TYPE_STRING)
len= 256; // STRBLK's have 0 length

// Now add the field
#if defined(NEW_WAY)
rc= add_fields(g, thd, &alter_info, cnm, typ, len, dec,
NOT_NULL_FLAG, "", flg, dbf, v);
tm, "", flg, dbf, v);
#else // !NEW_WAY
if (add_field(&sql, cnm, typ, len, dec, NULL, NOT_NULL_FLAG,
if (add_field(&sql, cnm, typ, len, dec, NULL, tm,
NULL, NULL, NULL, NULL, flg, dbf, v))
rc= HA_ERR_OUT_OF_MEM;
#endif // !NEW_WAY
Expand Down Expand Up @@ -5582,7 +5583,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
len= crp->Kdata->GetIntValue(i);
break;
case FLD_SCALE:
dec= crp->Kdata->GetIntValue(i);
dec = (!crp->Kdata->IsNull(i)) ? crp->Kdata->GetIntValue(i) : -1;
break;
case FLD_NULL:
if (crp->Kdata->GetIntValue(i))
Expand Down Expand Up @@ -5675,14 +5676,14 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
dec= 0;
} // endswitch typ

} // endif ttp
} else
#endif // ODBC_SUPPORT

// Make the arguments as required by add_fields
if (typ == TYPE_DATE)
if (typ == TYPE_DOUBLE)
prec= len;

if (typ == TYPE_DATE)
prec= 0;
else if (typ == TYPE_DOUBLE)
prec= len;

// Now add the field
#if defined(NEW_WAY)
Expand Down
20 changes: 10 additions & 10 deletions storage/connect/mysql-test/connect/r/odbc.result
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,43 @@ SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`Name` varchar(256) NOT NULL,
`Description` varchar(256) NOT NULL
`Description` varchar(256) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`='ODBC' `CATFUNC`='Sources'
DROP TABLE t1;
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CATFUNC=Drivers;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`Description` char(128) NOT NULL,
`Attributes` varchar(256) NOT NULL
`Attributes` varchar(256) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`='ODBC' `CATFUNC`='Drivers'
DROP TABLE t1;
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CATFUNC=Tables CONNECTION='Not important';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`Table_Cat` char(128) NOT NULL,
`Table_Schema` char(128) NOT NULL,
`Table_Cat` char(128) DEFAULT NULL,
`Table_Schema` char(128) DEFAULT NULL,
`Table_Name` char(128) NOT NULL,
`Table_Type` char(16) NOT NULL,
`Remark` char(255) NOT NULL
`Remark` char(255) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='Not important' `TABLE_TYPE`='ODBC' `CATFUNC`='Tables'
DROP TABLE t1;
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CATFUNC=Columns CONNECTION='Not important';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`Table_Cat` char(128) NOT NULL,
`Table_Schema` char(128) NOT NULL,
`Table_Cat` char(128) DEFAULT NULL,
`Table_Schema` char(128) DEFAULT NULL,
`Table_Name` char(128) NOT NULL,
`Column_Name` char(128) NOT NULL,
`Data_Type` smallint(6) NOT NULL,
`Type_Name` char(30) NOT NULL,
`Column_Size` int(10) NOT NULL,
`Buffer_Length` int(10) NOT NULL,
`Decimal_Digits` smallint(6) NOT NULL,
`Radix` smallint(6) NOT NULL,
`Decimal_Digits` smallint(6) DEFAULT NULL,
`Radix` smallint(6) DEFAULT NULL,
`Nullable` smallint(6) NOT NULL,
`Remarks` char(255) NOT NULL
`Remarks` char(255) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='Not important' `TABLE_TYPE`='ODBC' `CATFUNC`='Columns'
DROP TABLE t1;
68 changes: 34 additions & 34 deletions storage/connect/mysql-test/connect/r/odbc_oracle.result
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Table Create Table
t1 CREATE TABLE `t1` (
`Name` varchar(256) NOT NULL,
`Description` varchar(256) NOT NULL
`Description` varchar(256) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`='ODBC' `CATFUNC`='Sources'
SET NAMES utf8;
#
Expand All @@ -14,53 +14,53 @@ TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr'
CATFUNC=Tables;
SELECT * FROM t1 WHERE Table_Schema='MTR' ORDER BY Table_Schema, Table_Name;
Table_Cat Table_Schema Table_Name Table_Type Remark
MTR T1 TABLE
MTR T2 TABLE
MTR V1 VIEW
NULL MTR T1 TABLE NULL
NULL MTR T2 TABLE NULL
NULL MTR V1 VIEW NULL
DROP TABLE t1;
# All tables in all schemas (filtered with WHERE)
CREATE TABLE t1 ENGINE=CONNECT
TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr'
CATFUNC=Tables TABNAME='%.%';
SELECT * FROM t1 WHERE Table_Schema='MTR' ORDER BY Table_Schema, Table_Name;
Table_Cat Table_Schema Table_Name Table_Type Remark
MTR T1 TABLE
MTR T2 TABLE
MTR V1 VIEW
NULL MTR T1 TABLE NULL
NULL MTR T2 TABLE NULL
NULL MTR V1 VIEW NULL
DROP TABLE t1;
# All tables "T1" in all schemas (filtered with WHERE)
CREATE TABLE t1 ENGINE=CONNECT
TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr'
CATFUNC=Tables TABNAME='%.T1';
SELECT * FROM t1 WHERE Table_Schema='MTR' ORDER BY Table_Schema, Table_Name;
Table_Cat Table_Schema Table_Name Table_Type Remark
MTR T1 TABLE
NULL MTR T1 TABLE NULL
DROP TABLE t1;
# All tables "T1" in all schemas (filtered with WHERE)
CREATE TABLE t1 ENGINE=CONNECT
TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr'
CATFUNC=Tables TABNAME='T1';
SELECT * FROM t1 WHERE Table_Schema='MTR' ORDER BY Table_Schema, Table_Name;
Table_Cat Table_Schema Table_Name Table_Type Remark
MTR T1 TABLE
NULL MTR T1 TABLE NULL
DROP TABLE t1;
# Table "T1" in the schema "MTR"
CREATE TABLE t1 ENGINE=CONNECT
TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr'
CATFUNC=Tables TABNAME='MTR.T1';
SELECT * FROM t1 ORDER BY Table_Schema, Table_Name;
Table_Cat Table_Schema Table_Name Table_Type Remark
MTR T1 TABLE
NULL MTR T1 TABLE NULL
DROP TABLE t1;
# All tables in the schema "MTR"
CREATE TABLE t1 ENGINE=CONNECT
TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr'
CATFUNC=Tables TABNAME='MTR.%';
SELECT * FROM t1 ORDER BY Table_Schema, Table_Name;
Table_Cat Table_Schema Table_Name Table_Type Remark
MTR T1 TABLE
MTR T2 TABLE
MTR V1 VIEW
NULL MTR T1 TABLE NULL
NULL MTR T2 TABLE NULL
NULL MTR V1 VIEW NULL
DROP TABLE t1;
#
# Checking CATFUNC=Columns
Expand All @@ -73,10 +73,10 @@ 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
MTR T1 A 3 DECIMAL 38 40 0 10 1
MTR T1 B 6 NUMBER 38 40 0 0 1
MTR T2 A 12 VARCHAR2 64 64 0 0 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 0 0 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
Expand All @@ -85,17 +85,17 @@ 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
MTR T1 A 3 DECIMAL 38 40 0 10 1
MTR T1 B 6 NUMBER 38 40 0 0 1
MTR T2 A 12 VARCHAR2 64 64 0 0 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 0 0 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
MTR T1 A 3 DECIMAL 38 40 0 10 1
MTR T1 B 6 NUMBER 38 40 0 0 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
Expand All @@ -104,7 +104,7 @@ 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
MTR T1 A 3 DECIMAL 38 40 0 10 1
MTR T1 B 6 NUMBER 38 40 0 0 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
Expand All @@ -113,7 +113,7 @@ 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
MTR T1 A 3 DECIMAL 38 40 0 10 1
MTR T1 B 6 NUMBER 38 40 0 0 1
MTR T1 B 6 NUMBER 38 40 NULL NULL 1
DROP TABLE t1;
#
# Checking tables
Expand All @@ -127,32 +127,32 @@ SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`A` decimal(40,0) DEFAULT NULL,
`B` double(40,0) DEFAULT NULL
`B` double DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='T1'
SELECT * FROM t1 ORDER BY A;
A B
10 1000000000
20 1000000000000
30 1000000000000000
30 1e15
CREATE TABLE t2 AS SELECT * FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`A` decimal(40,0) DEFAULT NULL,
`B` double(40,0) DEFAULT NULL
`B` double DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SELECT * FROM t2;
A B
10 1000000000
20 1000000000000
30 1000000000000000
30 1e15
DROP TABLE t2;
CREATE VIEW v1 AS SELECT * FROM t1;
SELECT * FROM v1;
A B
10 1000000000
20 1000000000000
30 1000000000000000
30 1e15
DROP VIEW v1;
DROP TABLE t1;
# Table "T1" in the schema "MTR"
Expand All @@ -163,13 +163,13 @@ SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`A` decimal(40,0) DEFAULT NULL,
`B` double(40,0) DEFAULT NULL
`B` double DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='MTR.T1'
SELECT * FROM t1;
A B
10 1000000000
20 1000000000000
30 1000000000000000
30 1e15
DROP TABLE t1;
# View "V1" in the schema "MTR"
CREATE TABLE t1 ENGINE=CONNECT
Expand All @@ -179,32 +179,32 @@ SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`A` decimal(40,0) DEFAULT NULL,
`B` double(40,0) DEFAULT NULL
`B` double DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='MTR.V1'
SELECT * FROM t1;
A B
10 1000000000
20 1000000000000
30 1000000000000000
30 1e15
CREATE TABLE t2 AS SELECT * FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`A` decimal(40,0) DEFAULT NULL,
`B` double(40,0) DEFAULT NULL
`B` double DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SELECT * FROM t2;
A B
10 1000000000
20 1000000000000
30 1000000000000000
30 1e15
DROP TABLE t2;
CREATE VIEW v1 AS SELECT * FROM t1;
SELECT * FROM v1;
A B
10 1000000000
20 1000000000000
30 1000000000000000
30 1e15
DROP VIEW v1;
DROP TABLE t1;
# Table "T2" in the schema "MTR"
Expand Down
20 changes: 10 additions & 10 deletions storage/connect/mysql-test/connect/r/odbc_postgresql.result
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Table Create Table
t1 CREATE TABLE `t1` (
`Name` varchar(256) NOT NULL,
`Description` varchar(256) NOT NULL
`Description` varchar(256) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`='ODBC' `CATFUNC`='Sources'
SET NAMES utf8;
#
Expand Down Expand Up @@ -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 0 0 0
mtr schema1 t2 a 1 bpchar 10 60 0 0 0
mtr schema1 v1 a 1 bpchar 10 60 0 0 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
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='%.%.%';
Expand All @@ -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 0 0 0
mtr schema1 t2 a 1 bpchar 10 60 0 0 0
mtr schema1 v1 a 1 bpchar 10 60 0 0 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
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 0 0 0
mtr schema1 t1 a 1 bpchar 10 60 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';
Expand All @@ -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 0 0 0
mtr schema1 t1 a 1 bpchar 10 60 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 0 0 0
mtr schema1 t1 a 1 bpchar 10 60 NULL NULL 0
DROP TABLE t1;
#
# Checking tables
Expand Down
Loading

0 comments on commit 481e643

Please sign in to comment.