From edd161587eeb296563622309c5809d4f4e68fb67 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Mon, 25 Feb 2013 22:44:42 +0100 Subject: [PATCH] - 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 --- storage/connect/colblk.cpp | 3 ++- storage/connect/connect.cc | 9 +++------ storage/connect/ha_connect.cc | 4 ++-- storage/connect/odbconn.cpp | 22 ++++++++++++---------- storage/connect/plgdbsem.h | 7 +++++-- storage/connect/table.cpp | 2 +- storage/connect/tabmysql.cpp | 18 +++++++++++------- 7 files changed, 36 insertions(+), 29 deletions(-) diff --git a/storage/connect/colblk.cpp b/storage/connect/colblk.cpp index 027ac5710ab..cdbf6f4b42b 100644 --- a/storage/connect/colblk.cpp +++ b/storage/connect/colblk.cpp @@ -40,16 +40,17 @@ COLBLK::COLBLK(PCOLDEF cdp, PTDB tdbp, int i) Long = cdp->Long; Buf_Type = cdp->Buf_Type; ColUse |= cdp->Flags; // Used by CONNECT + Nullable = !!(cdp->Flags & U_NULLS); } else { Name = NULL; memset(&Format, 0, sizeof(FORMAT)); Opt = 0; Long = 0; Buf_Type = TYPE_ERROR; + Nullable = false; } // endif cdp To_Tdb = tdbp; - Nullable = false; Status = BUF_NO; //Value = NULL; done in XOBJECT constructor To_Kcol = NULL; diff --git a/storage/connect/connect.cc b/storage/connect/connect.cc index 3fee989907d..d24bec39c34 100644 --- a/storage/connect/connect.cc +++ b/storage/connect/connect.cc @@ -273,10 +273,8 @@ 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 + 1, 0); - colp->SetNullable(*p == '1'); - } // endif p + } else + colp= tdbp->ColDB(g, p, 0); if (!colp) { 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, utp->ColDB(g, NULL, 0); else for (p= c2; *p; p+= n) { // Allocate only used column blocks - colp= utp->ColDB(g, p + 1, 0); - colp->SetNullable(*p == '1'); + colp= utp->ColDB(g, p, 0); n= strlen(p) + 1; } // endfor p diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 5e23b3746d5..44924aa1995 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -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 - strcat(strcpy(cp, fp->maybe_null() ? "1" : "0"), (char*)fp->field_name); + strcpy(cp, (char*)fp->field_name); } // end of AddColName @@ -1313,7 +1313,7 @@ bool ha_connect::OpenTable(PGLOBAL g, bool del) } // endif if (ump && bitmap_is_set(ump, (*field)->field_index)) { - n2+= (GetColNameLen(*field) + 1); + n2+= GetColNameLen(*field); k2++; } // endif diff --git a/storage/connect/odbconn.cpp b/storage/connect/odbconn.cpp index 2ffe03048d0..683d63cfbed 100644 --- a/storage/connect/odbconn.cpp +++ b/storage/connect/odbconn.cpp @@ -238,10 +238,10 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *table, TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT, TYPE_INT, TYPE_SHORT, TYPE_SHORT, TYPE_SHORT, TYPE_STRING}; - static XFLD fldtyp[] = {FLD_NO, FLD_NO, FLD_NO, - FLD_NAME, FLD_TYPE, FLD_TYPENAME, - FLD_PREC, FLD_LENGTH, FLD_SCALE, - FLD_RADIX, FLD_NULL, FLD_REM}; + static XFLD fldtyp[] = {FLD_QUALIF, FLD_OWNER, FLD_TABNAME, + FLD_NAME, FLD_TYPE, FLD_TYPENAME, + FLD_PREC, FLD_LENGTH, FLD_SCALE, + FLD_RADIX, FLD_NULL, FLD_REM}; static unsigned int length[] = {0, 0, 0, 0, 6, 20, 10, 10, 6, 6, 6, 128}; int n, ncol = 12; int maxres; @@ -395,8 +395,9 @@ PQRYRES MyODBCCols(PGLOBAL g, char *dsn, char *tab, bool info) /*************************************************************************/ PQRYRES ODBCDataSources(PGLOBAL g, bool info) { - static int dbtype[] = {DB_CHAR, DB_CHAR}; - static int buftyp[] = {TYPE_STRING, TYPE_STRING}; + static int dbtype[] = {DB_CHAR, DB_CHAR}; + static int buftyp[] = {TYPE_STRING, TYPE_STRING}; + static XFLD fldtyp[] = {FLD_NAME, FLD_REM}; static unsigned int length[] = {0, 256}; int n = 0, ncol = 2; int maxres; @@ -423,7 +424,7 @@ PQRYRES ODBCDataSources(PGLOBAL g, bool info) /* Allocate the structures used to refer to the result set. */ /************************************************************************/ 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. */ @@ -444,8 +445,9 @@ PQRYRES ODBCDataSources(PGLOBAL g, bool info) /*************************************************************************/ PQRYRES ODBCDrivers(PGLOBAL g, bool info) { - static int dbtype[] = {DB_CHAR, DB_CHAR}; - static int buftyp[] = {TYPE_STRING, TYPE_STRING}; + static int dbtype[] = {DB_CHAR, DB_CHAR}; + static int buftyp[] = {TYPE_STRING, TYPE_STRING}; + static XFLD fldtyp[] = {FLD_NAME, FLD_REM}; static unsigned int length[] = {128, 256}; int ncol = 2; int maxres; @@ -468,7 +470,7 @@ PQRYRES ODBCDrivers(PGLOBAL g, bool info) /* Allocate the structures used to refer to the result set. */ /************************************************************************/ 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. */ diff --git a/storage/connect/plgdbsem.h b/storage/connect/plgdbsem.h index 0aa7f796639..f77dda67984 100644 --- a/storage/connect/plgdbsem.h +++ b/storage/connect/plgdbsem.h @@ -469,7 +469,7 @@ typedef struct _tabs { /* Following definitions are used to define table fields (columns). */ /***********************************************************************/ 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_TYPENAME = 3, /* Field type name */ FLD_PREC = 4, /* Field precision (length?) */ @@ -482,7 +482,10 @@ enum XFLD {FLD_NO = 0, /* Not a field definition item */ FLD_KEY = 11, /* Field key property */ FLD_DEFAULT = 12, /* Field default value */ 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. */ diff --git a/storage/connect/table.cpp b/storage/connect/table.cpp index 84eb40144cc..3768109809e 100644 --- a/storage/connect/table.cpp +++ b/storage/connect/table.cpp @@ -530,7 +530,7 @@ bool TDBCAT::InitCol(PGLOBAL g) for (colp = (PCATCOL)Columns; colp; colp = (PCATCOL)colp->GetNext()) { 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->Crp = crp; break; diff --git a/storage/connect/tabmysql.cpp b/storage/connect/tabmysql.cpp index fafa5caf6d8..5126663d0b2 100644 --- a/storage/connect/tabmysql.cpp +++ b/storage/connect/tabmysql.cpp @@ -846,15 +846,19 @@ int TDBMYSQL::WriteDB(PGLOBAL g) // Make the Insert command value list for (PCOL colp = Columns; colp; colp = colp->GetNext()) { - if (colp->GetResultType() == TYPE_STRING || - colp->GetResultType() == TYPE_DATE) - strcat(Qbuf, "'"); + if (!colp->GetValue()->IsNull()) { + if (colp->GetResultType() == TYPE_STRING || + colp->GetResultType() == TYPE_DATE) + strcat(Qbuf, "'"); - strcat(Qbuf, colp->GetValue()->GetCharString(buf)); + strcat(Qbuf, colp->GetValue()->GetCharString(buf)); - if (colp->GetResultType() == TYPE_STRING || - colp->GetResultType() == TYPE_DATE) - strcat(Qbuf, "'"); + if (colp->GetResultType() == TYPE_STRING || + colp->GetResultType() == TYPE_DATE) + strcat(Qbuf, "'"); + + } else + strcat(Qbuf, "NULL"); strcat(Qbuf, (colp->GetNext()) ? "," : ")"); } // endfor colp