Commit 1357bffb authored by Olivier Bertrand's avatar Olivier Bertrand

- Add support of NULLs for file table columns.

  Update CONNECT version number and date.

modified:
  mysql-test/suite/connect/r/null.result
  mysql-test/suite/connect/r/xml.result
  mysql-test/suite/connect/t/null.test
  storage/connect/ha_connect.cc
  storage/connect/mycat.cc
  storage/connect/tabdos.cpp
  storage/connect/tabfix.cpp
  storage/connect/tabfmt.cpp
  storage/connect/tabtbl.cpp
  storage/connect/tabvct.cpp
parent 9b790248
...@@ -3,41 +3,117 @@ ...@@ -3,41 +3,117 @@
# #
CREATE TABLE t1 CREATE TABLE t1
( (
id INT id INT NOT NULL,
) ENGINE=CONNECT TABLE_TYPE=FIX FILE_NAME='t1.txt'; nb INT,
ERROR HY000: Table type FIX does not support nullable columns msg VARCHAR(12)
) ENGINE=CONNECT TABLE_TYPE=FIX;
Warnings:
Warning 1105 No file name. Table will use t1.fix
INSERT INTO t1 values(NULL,1,'Hello');
ERROR 23000: Column 'id' cannot be null
INSERT INTO t1 values(10,4,NULL),(20,2,'Hello'),(0,0,'Zero');
SELECT * FROM t1;
id nb msg
10 4 NULL
20 2 Hello
0 NULL Zero
SELECT* FROM t1 WHERE id IS NULL;
id nb msg
SELECT * FROM t1 WHERE nb IS NULL;
id nb msg
0 NULL Zero
SELECT * FROM t1 WHERE msg IS NOT NULL;
id nb msg
20 2 Hello
0 NULL Zero
DROP TABLE t1;
# #
# Testing CSV null columns # Testing CSV null columns
# #
CREATE TABLE t1 CREATE TABLE t1
( (
id INT id INT NOT NULL,
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='t1.csv'; nb INT,
ERROR HY000: Table type CSV does not support nullable columns msg VARCHAR(12)
# ) ENGINE=CONNECT TABLE_TYPE=CSV HEADER=1;
# Testing VEC null columns Warnings:
# Warning 1105 No file name. Table will use t1.csv
CREATE TABLE t1 INSERT INTO t1 values(NULL,1,'Hello');
( ERROR 23000: Column 'id' cannot be null
id INT INSERT INTO t1 values(10,4,NULL),(20,2,'Hello'),(0,0,'Zero');
) ENGINE=CONNECT TABLE_TYPE=VEC FILE_NAME='t1.vec'; SELECT * FROM t1;
ERROR HY000: Table type VEC does not support nullable columns id nb msg
10 4 NULL
20 2 Hello
0 NULL Zero
SELECT* FROM t1 WHERE id IS NULL;
id nb msg
SELECT * FROM t1 WHERE nb IS NULL;
id nb msg
0 NULL Zero
SELECT * FROM t1 WHERE msg IS NOT NULL;
id nb msg
20 2 Hello
0 NULL Zero
DROP TABLE t1;
# #
# Testing DOS null columns # Testing BIN null columns
# #
CREATE TABLE t1 CREATE TABLE t1
( (
id INT id INT NOT NULL,
) ENGINE=CONNECT FILE_NAME='t1.txt'; nb INT,
ERROR HY000: Table type DOS does not support nullable columns msg VARCHAR(12)
) ENGINE=CONNECT TABLE_TYPE=BIN;
Warnings:
Warning 1105 No file name. Table will use t1.bin
INSERT INTO t1 values(NULL,1,'Hello');
ERROR 23000: Column 'id' cannot be null
INSERT INTO t1 values(10,4,NULL),(20,2,'Hello'),(0,0,'Zero');
SELECT * FROM t1;
id nb msg
10 4 NULL
20 2 Hello
0 NULL Zero
SELECT* FROM t1 WHERE id IS NULL;
id nb msg
SELECT * FROM t1 WHERE nb IS NULL;
id nb msg
0 NULL Zero
SELECT * FROM t1 WHERE msg IS NOT NULL;
id nb msg
20 2 Hello
0 NULL Zero
DROP TABLE t1;
# #
# Testing DBF null columns # Testing DBF null columns
# #
CREATE TABLE t1 CREATE TABLE t1
( (
id INT id INT NOT NULL,
) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf'; nb INT,
ERROR HY000: Table type DBF does not support nullable columns msg VARCHAR(12)
) ENGINE=CONNECT TABLE_TYPE=DBF;
Warnings:
Warning 1105 No file name. Table will use t1.dbf
INSERT INTO t1 values(NULL,1,'Hello');
ERROR 23000: Column 'id' cannot be null
INSERT INTO t1 values(10,4,NULL),(20,2,'Hello'),(0,0,'Zero');
SELECT * FROM t1;
id nb msg
10 4 NULL
20 2 Hello
0 NULL Zero
SELECT* FROM t1 WHERE id IS NULL;
id nb msg
SELECT * FROM t1 WHERE nb IS NULL;
id nb msg
0 NULL Zero
SELECT * FROM t1 WHERE msg IS NOT NULL;
id nb msg
20 2 Hello
0 NULL Zero
DROP TABLE t1;
# #
# Testing INI null columns # Testing INI null columns
# #
......
...@@ -507,7 +507,7 @@ DROP TABLE t1; ...@@ -507,7 +507,7 @@ DROP TABLE t1;
SET @a=LOAD_FILE('test/t1.xml'); SET @a=LOAD_FILE('test/t1.xml');
SELECT CAST(@a AS CHAR CHARACTER SET latin1); SELECT CAST(@a AS CHAR CHARACTER SET latin1);
CAST(@a AS CHAR CHARACTER SET latin1) <?xml version="1.0" encoding="iso-8859-1"?> CAST(@a AS CHAR CHARACTER SET latin1) <?xml version="1.0" encoding="iso-8859-1"?>
<!-- Created by CONNECT Version 1.01.0003 March 02, 2013 --> <!-- Created by CONNECT Version 1.01.0004 April 10, 2013 -->
<t1> <t1>
<line> <line>
<node>ÀÁÂÃ</node> <node>ÀÁÂÃ</node>
......
let $MYSQLD_DATADIR= `select @@datadir`; let $MYSQLD_DATADIR= `select @@datadir`;
--echo # --echo #
--echo # Testing FIX null columns --echo # Testing FIX null columns
--echo # --echo #
--error ER_UNKNOWN_ERROR CREATE TABLE t1
CREATE TABLE t1 (
( id INT NOT NULL,
id INT nb INT,
) ENGINE=CONNECT TABLE_TYPE=FIX FILE_NAME='t1.txt'; msg VARCHAR(12)
) ENGINE=CONNECT TABLE_TYPE=FIX;
--echo # --error ER_BAD_NULL_ERROR
--echo # Testing CSV null columns INSERT INTO t1 values(NULL,1,'Hello');
--echo # INSERT INTO t1 values(10,4,NULL),(20,2,'Hello'),(0,0,'Zero');
--error ER_UNKNOWN_ERROR SELECT * FROM t1;
CREATE TABLE t1 SELECT* FROM t1 WHERE id IS NULL;
( SELECT * FROM t1 WHERE nb IS NULL;
id INT SELECT * FROM t1 WHERE msg IS NOT NULL;
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='t1.csv'; DROP TABLE t1;
--echo # --echo #
--echo # Testing VEC null columns --echo # Testing CSV null columns
--echo # --echo #
--error ER_UNKNOWN_ERROR CREATE TABLE t1
CREATE TABLE t1 (
( id INT NOT NULL,
id INT nb INT,
) ENGINE=CONNECT TABLE_TYPE=VEC FILE_NAME='t1.vec'; msg VARCHAR(12)
) ENGINE=CONNECT TABLE_TYPE=CSV HEADER=1;
--echo # --error ER_BAD_NULL_ERROR
--echo # Testing DOS null columns INSERT INTO t1 values(NULL,1,'Hello');
--echo # INSERT INTO t1 values(10,4,NULL),(20,2,'Hello'),(0,0,'Zero');
--error ER_UNKNOWN_ERROR SELECT * FROM t1;
CREATE TABLE t1 SELECT* FROM t1 WHERE id IS NULL;
( SELECT * FROM t1 WHERE nb IS NULL;
id INT SELECT * FROM t1 WHERE msg IS NOT NULL;
) ENGINE=CONNECT FILE_NAME='t1.txt'; DROP TABLE t1;
--echo # --echo #
--echo # Testing DBF null columns --echo # Testing BIN null columns
--echo # --echo #
--error ER_UNKNOWN_ERROR CREATE TABLE t1
CREATE TABLE t1 (
( id INT NOT NULL,
id INT nb INT,
) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf'; msg VARCHAR(12)
) ENGINE=CONNECT TABLE_TYPE=BIN;
--echo # --error ER_BAD_NULL_ERROR
--echo # Testing INI null columns INSERT INTO t1 values(NULL,1,'Hello');
--echo # INSERT INTO t1 values(10,4,NULL),(20,2,'Hello'),(0,0,'Zero');
CREATE TABLE t1 SELECT * FROM t1;
( SELECT* FROM t1 WHERE id IS NULL;
`sec` char(8) NOT NULL flag=1, SELECT * FROM t1 WHERE nb IS NULL;
`key` char(12) SELECT * FROM t1 WHERE msg IS NOT NULL;
) ENGINE=CONNECT TABLE_TYPE=INI; DROP TABLE t1;
INSERT INTO t1(sec) values('S1');
SELECT * FROM t1; --echo #
INSERT INTO t1 values('S1','Newval'); --echo # Testing DBF null columns
SELECT * FROM t1; --echo #
DROP TABLE t1; CREATE TABLE t1
(
id INT NOT NULL,
nb INT,
msg VARCHAR(12)
) ENGINE=CONNECT TABLE_TYPE=DBF;
--error ER_BAD_NULL_ERROR
INSERT INTO t1 values(NULL,1,'Hello');
INSERT INTO t1 values(10,4,NULL),(20,2,'Hello'),(0,0,'Zero');
SELECT * FROM t1;
SELECT* FROM t1 WHERE id IS NULL;
SELECT * FROM t1 WHERE nb IS NULL;
SELECT * FROM t1 WHERE msg IS NOT NULL;
DROP TABLE t1;
--echo #
--echo # Testing INI null columns
--echo #
CREATE TABLE t1
(
`sec` char(8) NOT NULL flag=1,
`key` char(12)
) ENGINE=CONNECT TABLE_TYPE=INI;
INSERT INTO t1(sec) values('S1');
SELECT * FROM t1;
INSERT INTO t1 values('S1','Newval');
SELECT * FROM t1;
DROP TABLE t1;
...@@ -156,7 +156,7 @@ extern "C" char nmfile[]; ...@@ -156,7 +156,7 @@ extern "C" char nmfile[];
extern "C" char pdebug[]; extern "C" char pdebug[];
extern "C" { extern "C" {
char version[]= "Version 1.01.0003 March 02, 2013"; char version[]= "Version 1.01.0004 April 10, 2013";
#if defined(XMSG) #if defined(XMSG)
char msglang[]; // Default message language char msglang[]; // Default message language
...@@ -2146,10 +2146,15 @@ int ha_connect::optimize(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -2146,10 +2146,15 @@ int ha_connect::optimize(THD* thd, HA_CHECK_OPT* check_opt)
if (!((PTDBASE)tdbp)->GetDef()->Indexable()) { if (!((PTDBASE)tdbp)->GetDef()->Indexable()) {
sprintf(g->Message, "Table %s is not indexable", tdbp->GetName()); sprintf(g->Message, "Table %s is not indexable", tdbp->GetName());
rc= HA_ERR_INTERNAL_ERROR; rc= HA_ERR_INTERNAL_ERROR;
} else } else if ((rc= ((PTDBASE)tdbp)->ResetTableOpt(g, true))) {
if (((PTDBASE)tdbp)->ResetTableOpt(g, true)) if (rc == RC_INFO) {
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message);
rc= 0;
} else
rc = HA_ERR_INTERNAL_ERROR; rc = HA_ERR_INTERNAL_ERROR;
} // endif's
} else } else
rc= HA_ERR_INTERNAL_ERROR; rc= HA_ERR_INTERNAL_ERROR;
...@@ -4310,7 +4315,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, ...@@ -4310,7 +4315,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
if (cat) { if (cat) {
cat->SetDataPath(g, table_arg->in_use->db); cat->SetDataPath(g, table_arg->in_use->db);
if ((rc= optimize(NULL, NULL))) { if ((rc= optimize(table->in_use, NULL))) {
printf("Create rc=%d %s\n", rc, g->Message); printf("Create rc=%d %s\n", rc, g->Message);
my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0));
rc= HA_ERR_INTERNAL_ERROR; rc= HA_ERR_INTERNAL_ERROR;
......
...@@ -161,6 +161,7 @@ bool IsTypeNullable(TABTYPE type) ...@@ -161,6 +161,7 @@ bool IsTypeNullable(TABTYPE type)
{ {
bool nullable; bool nullable;
#if 0
switch (type) { switch (type) {
case TAB_ODBC: case TAB_ODBC:
case TAB_MYSQL: case TAB_MYSQL:
...@@ -173,6 +174,18 @@ bool IsTypeNullable(TABTYPE type) ...@@ -173,6 +174,18 @@ bool IsTypeNullable(TABTYPE type)
nullable= false; nullable= false;
break; break;
} // endswitch type } // endswitch type
#endif // 0
switch (type) {
case TAB_MAC:
case TAB_DIR:
nullable= false;
break;
default:
nullable= true;
break;
} // endswitch type
return nullable; return nullable;
} // end of IsTypeNullable } // end of IsTypeNullable
......
...@@ -571,7 +571,7 @@ int TDBDOS::MakeIndex(PGLOBAL g, PIXDEF pxdf, bool add) ...@@ -571,7 +571,7 @@ int TDBDOS::MakeIndex(PGLOBAL g, PIXDEF pxdf, bool add)
goto err; goto err;
} else } else
break; // Physical table does not exist yet or anymore return RC_INFO; // Error or Physical table does not exist
if (Use == USE_OPEN) if (Use == USE_OPEN)
CloseDB(g); CloseDB(g);
...@@ -1112,6 +1112,10 @@ void DOSCOL::ReadColumn(PGLOBAL g) ...@@ -1112,6 +1112,10 @@ void DOSCOL::ReadColumn(PGLOBAL g)
longjmp(g->jumper[g->jump_level], 34); longjmp(g->jumper[g->jump_level], 34);
} // endswitch Ftype } // endswitch Ftype
// Set null when applicable
if (Nullable)
Value->SetNull(Value->IsZero());
} // end of ReadColumn } // end of ReadColumn
/***********************************************************************/ /***********************************************************************/
......
...@@ -382,6 +382,10 @@ void BINCOL::ReadColumn(PGLOBAL g) ...@@ -382,6 +382,10 @@ void BINCOL::ReadColumn(PGLOBAL g)
longjmp(g->jumper[g->jump_level], 11); longjmp(g->jumper[g->jump_level], 11);
} // endswitch Fmt } // endswitch Fmt
// Set null when applicable
if (Nullable)
Value->SetNull(Value->IsZero());
} // end of ReadColumn } // end of ReadColumn
/***********************************************************************/ /***********************************************************************/
......
...@@ -1341,6 +1341,11 @@ void CSVCOL::ReadColumn(PGLOBAL g) ...@@ -1341,6 +1341,11 @@ void CSVCOL::ReadColumn(PGLOBAL g)
PSZ fp = tdbp->Field[Fldnum]; PSZ fp = tdbp->Field[Fldnum];
Value->SetValue_psz(fp); Value->SetValue_psz(fp);
// Set null when applicable
if (Nullable)
Value->SetNull(Value->IsZero());
} // endif Mode } // endif Mode
} // end of ReadColumn } // end of ReadColumn
......
...@@ -759,6 +759,11 @@ void TBLCOL::ReadColumn(PGLOBAL g) ...@@ -759,6 +759,11 @@ void TBLCOL::ReadColumn(PGLOBAL g)
if (Colp) { if (Colp) {
Colp->ReadColumn(g); Colp->ReadColumn(g);
Value->SetValue_pval(To_Val); Value->SetValue_pval(To_Val);
// Set null when applicable
if (Colp->IsNullable())
Value->SetNull(Value->IsZero());
} // endif Colp } // endif Colp
} // end of ReadColumn } // end of ReadColumn
...@@ -774,6 +779,7 @@ void TBTBLK::ReadColumn(PGLOBAL g) ...@@ -774,6 +779,7 @@ void TBTBLK::ReadColumn(PGLOBAL g)
htrc("TBT ReadColumn: name=%s\n", Name); htrc("TBT ReadColumn: name=%s\n", Name);
Value->SetValue_psz((char*)((PTDBTBL)To_Tdb)->Tdbp->GetName()); Value->SetValue_psz((char*)((PTDBTBL)To_Tdb)->Tdbp->GetName());
} // end of ReadColumn } // end of ReadColumn
/* ------------------------------------------------------------------- */ /* ------------------------------------------------------------------- */
...@@ -534,6 +534,11 @@ void VCTCOL::ReadColumn(PGLOBAL g) ...@@ -534,6 +534,11 @@ void VCTCOL::ReadColumn(PGLOBAL g)
//ColBlk = txfp->CurBlk; done in ReadBlock //ColBlk = txfp->CurBlk; done in ReadBlock
ColPos = txfp->CurNum; ColPos = txfp->CurNum;
Value->SetValue_pvblk(Blk, ColPos); Value->SetValue_pvblk(Blk, ColPos);
// Set null when applicable
if (Nullable)
Value->SetNull(Value->IsZero());
} // end of ReadColumn } // end of ReadColumn
/***********************************************************************/ /***********************************************************************/
......
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