fix so that ndb handler can cope with char(0), mapped to char(1) for now

parent a1bd5432
...@@ -395,3 +395,22 @@ b attr1 ...@@ -395,3 +395,22 @@ b attr1
9413 9412 9413 9412
drop table test.t1, t2; drop table test.t1, t2;
drop database mysqltest; drop database mysqltest;
use test;
create table t1 (a int primary key, b char(0));
insert into t1 values (1,"");
insert into t1 values (2,NULL);
select * from t1 order by a;
a b
1
2 NULL
select * from t1 order by b;
a b
2 NULL
1
select * from t1 where b IS NULL;
a b
2 NULL
select * from t1 where b IS NOT NULL;
a b
1
drop table t1;
...@@ -358,3 +358,16 @@ select b,test.t1.attr1 from test.t1, t2 where test.t1.pk1 < a; ...@@ -358,3 +358,16 @@ select b,test.t1.attr1 from test.t1, t2 where test.t1.pk1 < a;
drop table test.t1, t2; drop table test.t1, t2;
drop database mysqltest; drop database mysqltest;
#
# test support of char(0)
#
use test;
create table t1 (a int primary key, b char(0));
insert into t1 values (1,"");
insert into t1 values (2,NULL);
select * from t1 order by a;
select * from t1 order by b;
select * from t1 where b IS NULL;
select * from t1 where b IS NOT NULL;
drop table t1;
...@@ -89,6 +89,12 @@ static int ndb_get_table_statistics(Ndb*, const char *, ...@@ -89,6 +89,12 @@ static int ndb_get_table_statistics(Ndb*, const char *,
Uint64* rows, Uint64* commits); Uint64* rows, Uint64* commits);
/*
Dummy buffer to read zero pack_length fields
which are mapped to 1 char
*/
static byte dummy_buf[1];
/* /*
Error handling functions Error handling functions
*/ */
...@@ -443,6 +449,13 @@ int ha_ndbcluster::set_ndb_value(NdbOperation *ndb_op, Field *field, ...@@ -443,6 +449,13 @@ int ha_ndbcluster::set_ndb_value(NdbOperation *ndb_op, Field *field,
if (ndb_supported_type(field->type())) if (ndb_supported_type(field->type()))
{ {
// ndb currently does not support size 0
const byte *empty_field= "";
if (pack_len == 0)
{
pack_len= 1;
field_ptr= empty_field;
}
if (! (field->flags & BLOB_FLAG)) if (! (field->flags & BLOB_FLAG))
{ {
if (field->is_null()) if (field->is_null())
...@@ -586,7 +599,11 @@ int ha_ndbcluster::get_ndb_value(NdbOperation *ndb_op, Field *field, ...@@ -586,7 +599,11 @@ int ha_ndbcluster::get_ndb_value(NdbOperation *ndb_op, Field *field,
DBUG_ASSERT(field->ptr != NULL); DBUG_ASSERT(field->ptr != NULL);
if (! (field->flags & BLOB_FLAG)) if (! (field->flags & BLOB_FLAG))
{ {
byte *field_buf= buf + (field->ptr - table->record[0]); byte *field_buf;
if (field->pack_length() != 0)
field_buf= buf + (field->ptr - table->record[0]);
else
field_buf= dummy_buf;
m_value[fieldnr].rec= ndb_op->getValue(fieldnr, m_value[fieldnr].rec= ndb_op->getValue(fieldnr,
field_buf); field_buf);
DBUG_RETURN(m_value[fieldnr].rec == NULL); DBUG_RETURN(m_value[fieldnr].rec == NULL);
...@@ -3164,7 +3181,10 @@ static int create_ndb_column(NDBCOL &col, ...@@ -3164,7 +3181,10 @@ static int create_ndb_column(NDBCOL &col,
col.setType(NDBCOL::Char); col.setType(NDBCOL::Char);
col.setCharset(cs); col.setCharset(cs);
} }
col.setLength(field->pack_length()); if (field->pack_length() == 0)
col.setLength(1); // currently ndb does not support size 0
else
col.setLength(field->pack_length());
break; break;
case MYSQL_TYPE_VAR_STRING: case MYSQL_TYPE_VAR_STRING:
if (field->flags & BINARY_FLAG) if (field->flags & BINARY_FLAG)
......
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