Commit edd16158 authored by Olivier Bertrand's avatar Olivier Bertrand

- Catalog table: Use XFLD as Flag value instead of column index.

- Use the COLDEF flag to initialize column nullable value.
- Fix a bug on inserting null values in MYSQL tables.

modified:
  storage/connect/colblk.cpp
  storage/connect/connect.cc
  storage/connect/ha_connect.cc
  storage/connect/odbconn.cpp
  storage/connect/plgdbsem.h
  storage/connect/table.cpp
  storage/connect/tabmysql.cpp
parent 2b60525d
...@@ -40,16 +40,17 @@ COLBLK::COLBLK(PCOLDEF cdp, PTDB tdbp, int i) ...@@ -40,16 +40,17 @@ COLBLK::COLBLK(PCOLDEF cdp, PTDB tdbp, int i)
Long = cdp->Long; Long = cdp->Long;
Buf_Type = cdp->Buf_Type; Buf_Type = cdp->Buf_Type;
ColUse |= cdp->Flags; // Used by CONNECT ColUse |= cdp->Flags; // Used by CONNECT
Nullable = !!(cdp->Flags & U_NULLS);
} else { } else {
Name = NULL; Name = NULL;
memset(&Format, 0, sizeof(FORMAT)); memset(&Format, 0, sizeof(FORMAT));
Opt = 0; Opt = 0;
Long = 0; Long = 0;
Buf_Type = TYPE_ERROR; Buf_Type = TYPE_ERROR;
Nullable = false;
} // endif cdp } // endif cdp
To_Tdb = tdbp; To_Tdb = tdbp;
Nullable = false;
Status = BUF_NO; Status = BUF_NO;
//Value = NULL; done in XOBJECT constructor //Value = NULL; done in XOBJECT constructor
To_Kcol = NULL; To_Kcol = NULL;
......
...@@ -273,10 +273,8 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2, ...@@ -273,10 +273,8 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2,
cp= new(g) COLUMN(p + 1); cp= new(g) COLUMN(p + 1);
cp->SetTo_Table(tdbp->GetTable()); cp->SetTo_Table(tdbp->GetTable());
colp= ((PTDBASE)tdbp)->InsertSpcBlk(g, cp); colp= ((PTDBASE)tdbp)->InsertSpcBlk(g, cp);
} else { } else
colp= tdbp->ColDB(g, p + 1, 0); colp= tdbp->ColDB(g, p, 0);
colp->SetNullable(*p == '1');
} // endif p
if (!colp) { if (!colp) {
sprintf(g->Message, "Column %s not found in %s", p, tdbp->GetName()); sprintf(g->Message, "Column %s not found in %s", p, tdbp->GetName());
...@@ -340,8 +338,7 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2, ...@@ -340,8 +338,7 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2,
utp->ColDB(g, NULL, 0); utp->ColDB(g, NULL, 0);
else for (p= c2; *p; p+= n) { else for (p= c2; *p; p+= n) {
// Allocate only used column blocks // Allocate only used column blocks
colp= utp->ColDB(g, p + 1, 0); colp= utp->ColDB(g, p, 0);
colp->SetNullable(*p == '1');
n= strlen(p) + 1; n= strlen(p) + 1;
} // endfor p } // endfor p
......
...@@ -1238,7 +1238,7 @@ void ha_connect::AddColName(char *cp, Field *fp) ...@@ -1238,7 +1238,7 @@ void ha_connect::AddColName(char *cp, Field *fp)
// The prefix * mark the column as "special" // The prefix * mark the column as "special"
strcat(strcpy(cp, "*"), strupr(fop->special)); strcat(strcpy(cp, "*"), strupr(fop->special));
else else
strcat(strcpy(cp, fp->maybe_null() ? "1" : "0"), (char*)fp->field_name); strcpy(cp, (char*)fp->field_name);
} // end of AddColName } // end of AddColName
...@@ -1313,7 +1313,7 @@ bool ha_connect::OpenTable(PGLOBAL g, bool del) ...@@ -1313,7 +1313,7 @@ bool ha_connect::OpenTable(PGLOBAL g, bool del)
} // endif } // endif
if (ump && bitmap_is_set(ump, (*field)->field_index)) { if (ump && bitmap_is_set(ump, (*field)->field_index)) {
n2+= (GetColNameLen(*field) + 1); n2+= GetColNameLen(*field);
k2++; k2++;
} // endif } // endif
......
...@@ -238,7 +238,7 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *table, ...@@ -238,7 +238,7 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *table,
TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_STRING, TYPE_SHORT, TYPE_STRING,
TYPE_INT, TYPE_INT, TYPE_SHORT, TYPE_INT, TYPE_INT, TYPE_SHORT,
TYPE_SHORT, TYPE_SHORT, TYPE_STRING}; TYPE_SHORT, TYPE_SHORT, TYPE_STRING};
static XFLD fldtyp[] = {FLD_NO, FLD_NO, FLD_NO, static XFLD fldtyp[] = {FLD_QUALIF, FLD_OWNER, FLD_TABNAME,
FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_NAME, FLD_TYPE, FLD_TYPENAME,
FLD_PREC, FLD_LENGTH, FLD_SCALE, FLD_PREC, FLD_LENGTH, FLD_SCALE,
FLD_RADIX, FLD_NULL, FLD_REM}; FLD_RADIX, FLD_NULL, FLD_REM};
...@@ -397,6 +397,7 @@ PQRYRES ODBCDataSources(PGLOBAL g, bool info) ...@@ -397,6 +397,7 @@ PQRYRES ODBCDataSources(PGLOBAL g, bool info)
{ {
static int dbtype[] = {DB_CHAR, DB_CHAR}; static int dbtype[] = {DB_CHAR, DB_CHAR};
static int buftyp[] = {TYPE_STRING, TYPE_STRING}; static int buftyp[] = {TYPE_STRING, TYPE_STRING};
static XFLD fldtyp[] = {FLD_NAME, FLD_REM};
static unsigned int length[] = {0, 256}; static unsigned int length[] = {0, 256};
int n = 0, ncol = 2; int n = 0, ncol = 2;
int maxres; int maxres;
...@@ -423,7 +424,7 @@ PQRYRES ODBCDataSources(PGLOBAL g, bool info) ...@@ -423,7 +424,7 @@ PQRYRES ODBCDataSources(PGLOBAL g, bool info)
/* Allocate the structures used to refer to the result set. */ /* Allocate the structures used to refer to the result set. */
/************************************************************************/ /************************************************************************/
qrp = PlgAllocResult(g, ncol, maxres, IDS_DSRC, qrp = PlgAllocResult(g, ncol, maxres, IDS_DSRC,
dbtype, buftyp, NULL, length, true, true); dbtype, buftyp, fldtyp, length, true, true);
/************************************************************************/ /************************************************************************/
/* Now get the results into blocks. */ /* Now get the results into blocks. */
...@@ -446,6 +447,7 @@ PQRYRES ODBCDrivers(PGLOBAL g, bool info) ...@@ -446,6 +447,7 @@ PQRYRES ODBCDrivers(PGLOBAL g, bool info)
{ {
static int dbtype[] = {DB_CHAR, DB_CHAR}; static int dbtype[] = {DB_CHAR, DB_CHAR};
static int buftyp[] = {TYPE_STRING, TYPE_STRING}; static int buftyp[] = {TYPE_STRING, TYPE_STRING};
static XFLD fldtyp[] = {FLD_NAME, FLD_REM};
static unsigned int length[] = {128, 256}; static unsigned int length[] = {128, 256};
int ncol = 2; int ncol = 2;
int maxres; int maxres;
...@@ -468,7 +470,7 @@ PQRYRES ODBCDrivers(PGLOBAL g, bool info) ...@@ -468,7 +470,7 @@ PQRYRES ODBCDrivers(PGLOBAL g, bool info)
/* Allocate the structures used to refer to the result set. */ /* Allocate the structures used to refer to the result set. */
/************************************************************************/ /************************************************************************/
qrp = PlgAllocResult(g, ncol, maxres, IDS_DRIVER, qrp = PlgAllocResult(g, ncol, maxres, IDS_DRIVER,
dbtype, buftyp, NULL, length, true, true); dbtype, buftyp, fldtyp, length, true, true);
/************************************************************************/ /************************************************************************/
/* Now get the results into blocks. */ /* Now get the results into blocks. */
......
...@@ -469,7 +469,7 @@ typedef struct _tabs { ...@@ -469,7 +469,7 @@ typedef struct _tabs {
/* Following definitions are used to define table fields (columns). */ /* Following definitions are used to define table fields (columns). */
/***********************************************************************/ /***********************************************************************/
enum XFLD {FLD_NO = 0, /* Not a field definition item */ enum XFLD {FLD_NO = 0, /* Not a field definition item */
FLD_NAME = 1, /* Field name */ FLD_NAME = 1, /* Item name */
FLD_TYPE = 2, /* Field type */ FLD_TYPE = 2, /* Field type */
FLD_TYPENAME = 3, /* Field type name */ FLD_TYPENAME = 3, /* Field type name */
FLD_PREC = 4, /* Field precision (length?) */ FLD_PREC = 4, /* Field precision (length?) */
...@@ -482,7 +482,10 @@ enum XFLD {FLD_NO = 0, /* Not a field definition item */ ...@@ -482,7 +482,10 @@ enum XFLD {FLD_NO = 0, /* Not a field definition item */
FLD_KEY = 11, /* Field key property */ FLD_KEY = 11, /* Field key property */
FLD_DEFAULT = 12, /* Field default value */ FLD_DEFAULT = 12, /* Field default value */
FLD_PRIV = 13, /* Field priviledges */ FLD_PRIV = 13, /* Field priviledges */
FLD_DATEFMT = 14}; /* Field date format */ FLD_DATEFMT = 14, /* Field date format */
FLD_QUALIF = 15, /* Table qualifier */
FLD_OWNER = 16, /* Table owner */
FLD_TABNAME = 17}; /* Column Table name */
/***********************************************************************/ /***********************************************************************/
/* Result of last SQL noconv query. */ /* Result of last SQL noconv query. */
......
...@@ -530,7 +530,7 @@ bool TDBCAT::InitCol(PGLOBAL g) ...@@ -530,7 +530,7 @@ bool TDBCAT::InitCol(PGLOBAL g)
for (colp = (PCATCOL)Columns; colp; colp = (PCATCOL)colp->GetNext()) { for (colp = (PCATCOL)Columns; colp; colp = (PCATCOL)colp->GetNext()) {
for (crp = Qrp->Colresp; crp; crp = crp->Next) for (crp = Qrp->Colresp; crp; crp = crp->Next)
if ((colp->Flag == crp->Ncol) || if ((colp->Flag && colp->Flag == crp->Fld) ||
(!colp->Flag && !stricmp(colp->Name, crp->Name))) { (!colp->Flag && !stricmp(colp->Name, crp->Name))) {
colp->Crp = crp; colp->Crp = crp;
break; break;
......
...@@ -846,6 +846,7 @@ int TDBMYSQL::WriteDB(PGLOBAL g) ...@@ -846,6 +846,7 @@ int TDBMYSQL::WriteDB(PGLOBAL g)
// Make the Insert command value list // Make the Insert command value list
for (PCOL colp = Columns; colp; colp = colp->GetNext()) { for (PCOL colp = Columns; colp; colp = colp->GetNext()) {
if (!colp->GetValue()->IsNull()) {
if (colp->GetResultType() == TYPE_STRING || if (colp->GetResultType() == TYPE_STRING ||
colp->GetResultType() == TYPE_DATE) colp->GetResultType() == TYPE_DATE)
strcat(Qbuf, "'"); strcat(Qbuf, "'");
...@@ -856,6 +857,9 @@ int TDBMYSQL::WriteDB(PGLOBAL g) ...@@ -856,6 +857,9 @@ int TDBMYSQL::WriteDB(PGLOBAL g)
colp->GetResultType() == TYPE_DATE) colp->GetResultType() == TYPE_DATE)
strcat(Qbuf, "'"); strcat(Qbuf, "'");
} else
strcat(Qbuf, "NULL");
strcat(Qbuf, (colp->GetNext()) ? "," : ")"); strcat(Qbuf, (colp->GetNext()) ? "," : ")");
} // endfor colp } // endfor colp
......
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