Skip to content

Commit

Permalink
Handle ODBC table null values modified: tabodbc.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Buggynours committed Jun 3, 2015
1 parent e8ea671 commit 36d2bd6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
42 changes: 41 additions & 1 deletion storage/connect/connect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,28 @@ int CntIndexInit(PGLOBAL g, PTDB ptdb, int id, bool sorted)
return (tdbp->To_Kindex->IsMul()) ? 2 : 1;
} // end of CntIndexInit

#if defined(WORDS_BIGENDIAN)
/***********************************************************************/
/* Swap bytes of the key that are written in little endian order. */
/***********************************************************************/
static void SetSwapValue(PVAL valp, char *kp)
{
if (valp->IsTypeNum() && valp->GetType() != TYPE_DECIM) {
uchar buf[8];
int i, k= valp->GetClen();

for (i = 0; k > 0;)
buf[i++]= kp[--k];



valp->SetBinValue((void*)buf);
} else
valp->SetBinValue((void*)kp);

} // end of SetSwapValue
#endif // WORDS_BIGENDIAN

/***********************************************************************/
/* IndexRead: fetch a record having the index value. */
/***********************************************************************/
Expand Down Expand Up @@ -779,7 +801,12 @@ RCODE CntIndexRead(PGLOBAL g, PTDB ptdb, OPVAL op,

if (!valp->IsTypeNum()) {
if (colp->GetColUse(U_VAR)) {
#if defined(WORDS_BIGENDIAN)
((char*)&lg)[0]= ((char*)kp)[1];
((char*)&lg)[1]= ((char*)kp)[0];
#else // !WORDS_BIGENDIAN
lg= *(short*)kp;
#endif //!WORDS_BIGENDIAN
kp+= sizeof(short);
rcb= valp->SetValue_char(kp, (int)lg);
} else
Expand All @@ -797,7 +824,11 @@ RCODE CntIndexRead(PGLOBAL g, PTDB ptdb, OPVAL op,
} // endif b

} else
#if defined(WORDS_BIGENDIAN)
SetSwapValue(valp, kp);
#else // !WORDS_BIGENDIAN
valp->SetBinValue((void*)kp);
#endif //!WORDS_BIGENDIAN

kp+= valp->GetClen();

Expand Down Expand Up @@ -893,7 +924,12 @@ int CntIndexRange(PGLOBAL g, PTDB ptdb, const uchar* *key, uint *len,

if (!valp->IsTypeNum()) {
if (colp->GetColUse(U_VAR)) {
#if defined(WORDS_BIGENDIAN)
((char*)&lg)[0]= ((char*)p)[1];
((char*)&lg)[1]= ((char*)p)[0];
#else // !WORDS_BIGENDIAN
lg= *(short*)p;
#endif //!WORDS_BIGENDIAN
p+= sizeof(short);
rcb= valp->SetValue_char((char*)p, (int)lg);
} else
Expand All @@ -912,7 +948,11 @@ int CntIndexRange(PGLOBAL g, PTDB ptdb, const uchar* *key, uint *len,
} // endif b

} else
valp->SetBinValue((void*)p);
#if defined(WORDS_BIGENDIAN)
SetSwapValue(valp, (char*)kp);
#else // !WORDS_BIGENDIAN
valp->SetBinValue((void*)kp);
#endif // !WORDS_BIGENDIAN

if (trace) {
char bf[32];
Expand Down
6 changes: 5 additions & 1 deletion storage/connect/tabodbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,10 @@ void ODBCCOL::ReadColumn(PGLOBAL g)

} // endif Buf_Type

// Handle null values
if (Value->IsZero())
Value->SetNull(Nullable);

if (trace) {
char buf[64];

Expand Down Expand Up @@ -1393,7 +1397,7 @@ void ODBCCOL::WriteColumn(PGLOBAL g)
/* -------------------------- Class TDBXDBC -------------------------- */

/***********************************************************************/
/* Implementation of the TDBODBC class. */
/* Implementation of the TDBXDBC class. */
/***********************************************************************/
TDBXDBC::TDBXDBC(PODEF tdp) : TDBODBC(tdp)
{
Expand Down
4 changes: 4 additions & 0 deletions storage/connect/xindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ typedef struct index_def : public BLOCK {

typedef struct index_off {
union {
#if defined(WORDS_BIGENDIAN)
struct {int High; int Low;};
#else // !WORDS_BIGENDIAN
struct {int Low; int High;};
#endif //!WORDS_BIGENDIAN
longlong Val; // File position
}; // end of union
} IOFF;
Expand Down

0 comments on commit 36d2bd6

Please sign in to comment.