Skip to content

Commit

Permalink
- Add support to NULL values. This concern the MYSQL
Browse files Browse the repository at this point in the history
  and ODBC table types. Not supported yet for indexes.

modified:
  storage/connect/colblk.cpp
  storage/connect/colblk.h
  storage/connect/connect.cc
  storage/connect/ha_connect.cc
  storage/connect/tabmysql.cpp
  storage/connect/tabodbc.cpp
  storage/connect/valblk.cpp
  storage/connect/valblk.h
  storage/connect/value.cpp
  storage/connect/value.h
  storage/connect/xindex.cpp
  • Loading branch information
Buggynours committed Feb 24, 2013
1 parent a769cb2 commit 2b60525
Show file tree
Hide file tree
Showing 11 changed files with 571 additions and 249 deletions.
6 changes: 4 additions & 2 deletions storage/connect/colblk.cpp
@@ -1,7 +1,7 @@
/************* Colblk C++ Functions Source Code File (.CPP) ************/
/* Name: COLBLK.CPP Version 1.9 */
/* Name: COLBLK.CPP Version 2.0 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 1998-2012 */
/* (C) Copyright to the author Olivier BERTRAND 1998-2013 */
/* */
/* This file contains the COLBLK class functions. */
/***********************************************************************/
Expand Down Expand Up @@ -49,6 +49,7 @@ COLBLK::COLBLK(PCOLDEF cdp, PTDB tdbp, int i)
} // endif cdp

To_Tdb = tdbp;
Nullable = false;
Status = BUF_NO;
//Value = NULL; done in XOBJECT constructor
To_Kcol = NULL;
Expand Down Expand Up @@ -190,6 +191,7 @@ bool COLBLK::InitValue(PGLOBAL g)
return true;

Status = BUF_READY;
Value->SetNullable(Nullable);

#ifdef DEBTRACE
htrc(" colp=%p type=%d value=%p coluse=%.4X status=%.4X\n",
Expand Down
7 changes: 5 additions & 2 deletions storage/connect/colblk.h
@@ -1,7 +1,7 @@
/*************** Colblk H Declares Source Code File (.H) ***************/
/* Name: COLBLK.H Version 1.5 */
/* Name: COLBLK.H Version 1.6 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2005-2012 */
/* (C) Copyright to the author Olivier BERTRAND 2005-2013 */
/* */
/* This file contains the COLBLK and derived classes declares. */
/***********************************************************************/
Expand Down Expand Up @@ -53,6 +53,8 @@ class DllExport COLBLK : public XOBJECT {
PSZ GetDomain(void) {return (Cdp) ? Cdp->Decode : NULL;}
PSZ GetDesc(void) {return (Cdp) ? Cdp->Desc : NULL;}
PSZ GetFmt(void) {return (Cdp) ? Cdp->Fmt : NULL;}
bool IsNullable(void) {return Nullable;}
void SetNullable(bool b) {Nullable = b;}

// Methods
virtual void Reset(void);
Expand Down Expand Up @@ -81,6 +83,7 @@ class DllExport COLBLK : public XOBJECT {
PCOLDEF Cdp; // To column definition block
PTDB To_Tdb; // Points to Table Descriptor Block
PXCOL To_Kcol; // Points to Xindex matching column
bool Nullable; // True if nullable
int Index; // Column number in table
int Opt; // Cluster/sort information
int Buf_Type; // Data type
Expand Down
9 changes: 6 additions & 3 deletions storage/connect/connect.cc
Expand Up @@ -273,8 +273,10 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2,
cp= new(g) COLUMN(p + 1);
cp->SetTo_Table(tdbp->GetTable());
colp= ((PTDBASE)tdbp)->InsertSpcBlk(g, cp);
} else
colp= tdbp->ColDB(g, p, 0);
} else {
colp= tdbp->ColDB(g, p + 1, 0);
colp->SetNullable(*p == '1');
} // endif p

if (!colp) {
sprintf(g->Message, "Column %s not found in %s", p, tdbp->GetName());
Expand Down Expand Up @@ -338,7 +340,8 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2,
utp->ColDB(g, NULL, 0);
else for (p= c2; *p; p+= n) {
// Allocate only used column blocks
utp->ColDB(g, p, 0);
colp= utp->ColDB(g, p + 1, 0);
colp->SetNullable(*p == '1');
n= strlen(p) + 1;
} // endfor p

Expand Down
98 changes: 54 additions & 44 deletions storage/connect/ha_connect.cc
Expand Up @@ -1211,7 +1211,7 @@ int ha_connect::GetColNameLen(Field *fp)
if (fop && fop->special)
n= strlen(fop->special) + 1;
else
n= strlen(fp->field_name);
n= strlen(fp->field_name) + 1;

return n;
} // end of GetColNameLen
Expand All @@ -1238,7 +1238,7 @@ void ha_connect::AddColName(char *cp, Field *fp)
// The prefix * mark the column as "special"
strcat(strcpy(cp, "*"), strupr(fop->special));
else
strcpy(cp, (char*)fp->field_name);
strcat(strcpy(cp, fp->maybe_null() ? "1" : "0"), (char*)fp->field_name);

} // end of AddColName

Expand Down Expand Up @@ -1456,49 +1456,54 @@ int ha_connect::MakeRecord(char *buf)
value= colp->GetValue();

// All this could be better optimized
switch (value->GetType()) {
case TYPE_DATE:
if (!sdval)
sdval= AllocateValue(xp->g, TYPE_STRING, 20);

switch (fp->type()) {
case MYSQL_TYPE_DATE:
fmt= "%Y-%m-%d";
break;
case MYSQL_TYPE_TIME:
fmt= "%H:%M:%S";
break;
default:
fmt= "%Y-%m-%d %H:%M:%S";
} // endswitch type

// Get date in the format required by MySQL fields
value->FormatValue(sdval, fmt);
p= sdval->GetCharValue();
break;
case TYPE_FLOAT:
p= NULL;
break;
case TYPE_STRING:
// Passthru
default:
p= value->GetCharString(val);
} // endswitch Type

if (p) {
if (fp->store(p, strlen(p), charset, CHECK_FIELD_WARN)) {
// Avoid "error" on null fields
if (value->GetIntValue())
if (!value->IsNull()) {
switch (value->GetType()) {
case TYPE_DATE:
if (!sdval)
sdval= AllocateValue(xp->g, TYPE_STRING, 20);

switch (fp->type()) {
case MYSQL_TYPE_DATE:
fmt= "%Y-%m-%d";
break;
case MYSQL_TYPE_TIME:
fmt= "%H:%M:%S";
break;
default:
fmt= "%Y-%m-%d %H:%M:%S";
} // endswitch type

// Get date in the format required by MySQL fields
value->FormatValue(sdval, fmt);
p= sdval->GetCharValue();
break;
case TYPE_FLOAT:
p= NULL;
break;
case TYPE_STRING:
// Passthru
default:
p= value->GetCharString(val);
} // endswitch Type

if (p) {
if (fp->store(p, strlen(p), charset, CHECK_FIELD_WARN)) {
// Avoid "error" on null fields
if (value->GetIntValue())
rc= HA_ERR_WRONG_IN_RECORD;

DBUG_PRINT("MakeRecord", (p));
} // endif store

} else
if (fp->store(value->GetFloatValue())) {
rc= HA_ERR_WRONG_IN_RECORD;
DBUG_PRINT("MakeRecord", (value->GetCharString(val)));
} // endif store

DBUG_PRINT("MakeRecord", (p));
} // endif store

fp->set_notnull();
} else
if (fp->store(value->GetFloatValue())) {
rc= HA_ERR_WRONG_IN_RECORD;
DBUG_PRINT("MakeRecord", (value->GetCharString(val)));
} // endif store
fp->set_null();

} // endif bitmap

Expand Down Expand Up @@ -1552,7 +1557,12 @@ int ha_connect::ScanRecord(PGLOBAL g, uchar *buf)

// This is a used field, fill the value from the row buffer
// All this could be better optimized
switch (value->GetType()) {
if (fp->is_null()) {
if (colp->IsNullable())
value->SetNull(true);

value->Reset();
} else switch (value->GetType()) {
case TYPE_FLOAT:
value->SetValue(fp->val_real());
break;
Expand Down Expand Up @@ -3306,7 +3316,7 @@ bool ha_connect::add_fields(THD *thd, void *alt_info,
alter_info->create_list.push_back(new_field);
//lex->last_field=new_field;
DBUG_RETURN(0);
}
} // end of add_fields

/**
@brief
Expand Down
11 changes: 8 additions & 3 deletions storage/connect/tabmysql.cpp
Expand Up @@ -109,14 +109,15 @@ MYSQLDEF::MYSQLDEF(void)
/* An Example: */
/* */
/* CREATE TABLE t1 (id int(32)) */
/* ENGINE="FEDERATEDX" */
/* ENGINE="CONNECT" TABLE_TYPE="MYSQL" */
/* CONNECTION="mysql://joe:pwd@192.168.1.111:9308/dbname/tabname"; */
/* */
/* CREATE TABLE t2 ( */
/* id int(4) NOT NULL auto_increment, */
/* name varchar(32) NOT NULL, */
/* PRIMARY KEY(id) */
/* ) ENGINE="FEDERATEDX" CONNECTION="my_conn"; (NIY) */
/* ) ENGINE="CONNECT" TABLE_TYPE="MYSQL" */
/* CONNECTION="my_conn"; (NIY) */
/* */
/* 'password' and 'port' are both optional. */
/* */
Expand Down Expand Up @@ -1040,8 +1041,12 @@ void MYSQLCOL::ReadColumn(PGLOBAL g)

if ((buf = ((PTDBMY)To_Tdb)->Myc.GetCharField(Rank)))
Value->SetValue_char(buf, Long);
else
else {
if (Nullable)
Value->SetNull(true);

Value->Reset(); // Null value
} // endelse

} // end of ReadColumn

Expand Down
6 changes: 5 additions & 1 deletion storage/connect/tabodbc.cpp
Expand Up @@ -796,9 +796,13 @@ void ODBCCOL::ReadColumn(PGLOBAL g)

if (StrLen[n] == SQL_NULL_DATA) {
// Null value
if (Nullable)
Value->SetNull(true);

Value->Reset();
return;
} // endif StrLen
} else
Value->SetNull(false);

if (Bufp && tdbp->Rows)
if (Buf_Type == TYPE_DATE)
Expand Down

0 comments on commit 2b60525

Please sign in to comment.