Skip to content

Commit 36d2bd6

Browse files
committed
Handle ODBC table null values modified: tabodbc.cpp
1 parent e8ea671 commit 36d2bd6

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

storage/connect/connect.cc

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,28 @@ int CntIndexInit(PGLOBAL g, PTDB ptdb, int id, bool sorted)
709709
return (tdbp->To_Kindex->IsMul()) ? 2 : 1;
710710
} // end of CntIndexInit
711711

712+
#if defined(WORDS_BIGENDIAN)
713+
/***********************************************************************/
714+
/* Swap bytes of the key that are written in little endian order. */
715+
/***********************************************************************/
716+
static void SetSwapValue(PVAL valp, char *kp)
717+
{
718+
if (valp->IsTypeNum() && valp->GetType() != TYPE_DECIM) {
719+
uchar buf[8];
720+
int i, k= valp->GetClen();
721+
722+
for (i = 0; k > 0;)
723+
buf[i++]= kp[--k];
724+
725+
726+
727+
valp->SetBinValue((void*)buf);
728+
} else
729+
valp->SetBinValue((void*)kp);
730+
731+
} // end of SetSwapValue
732+
#endif // WORDS_BIGENDIAN
733+
712734
/***********************************************************************/
713735
/* IndexRead: fetch a record having the index value. */
714736
/***********************************************************************/
@@ -779,7 +801,12 @@ RCODE CntIndexRead(PGLOBAL g, PTDB ptdb, OPVAL op,
779801

780802
if (!valp->IsTypeNum()) {
781803
if (colp->GetColUse(U_VAR)) {
804+
#if defined(WORDS_BIGENDIAN)
805+
((char*)&lg)[0]= ((char*)kp)[1];
806+
((char*)&lg)[1]= ((char*)kp)[0];
807+
#else // !WORDS_BIGENDIAN
782808
lg= *(short*)kp;
809+
#endif //!WORDS_BIGENDIAN
783810
kp+= sizeof(short);
784811
rcb= valp->SetValue_char(kp, (int)lg);
785812
} else
@@ -797,7 +824,11 @@ RCODE CntIndexRead(PGLOBAL g, PTDB ptdb, OPVAL op,
797824
} // endif b
798825

799826
} else
827+
#if defined(WORDS_BIGENDIAN)
828+
SetSwapValue(valp, kp);
829+
#else // !WORDS_BIGENDIAN
800830
valp->SetBinValue((void*)kp);
831+
#endif //!WORDS_BIGENDIAN
801832

802833
kp+= valp->GetClen();
803834

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

894925
if (!valp->IsTypeNum()) {
895926
if (colp->GetColUse(U_VAR)) {
927+
#if defined(WORDS_BIGENDIAN)
928+
((char*)&lg)[0]= ((char*)p)[1];
929+
((char*)&lg)[1]= ((char*)p)[0];
930+
#else // !WORDS_BIGENDIAN
896931
lg= *(short*)p;
932+
#endif //!WORDS_BIGENDIAN
897933
p+= sizeof(short);
898934
rcb= valp->SetValue_char((char*)p, (int)lg);
899935
} else
@@ -912,7 +948,11 @@ int CntIndexRange(PGLOBAL g, PTDB ptdb, const uchar* *key, uint *len,
912948
} // endif b
913949

914950
} else
915-
valp->SetBinValue((void*)p);
951+
#if defined(WORDS_BIGENDIAN)
952+
SetSwapValue(valp, (char*)kp);
953+
#else // !WORDS_BIGENDIAN
954+
valp->SetBinValue((void*)kp);
955+
#endif // !WORDS_BIGENDIAN
916956

917957
if (trace) {
918958
char bf[32];

storage/connect/tabodbc.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,10 @@ void ODBCCOL::ReadColumn(PGLOBAL g)
12681268

12691269
} // endif Buf_Type
12701270

1271+
// Handle null values
1272+
if (Value->IsZero())
1273+
Value->SetNull(Nullable);
1274+
12711275
if (trace) {
12721276
char buf[64];
12731277

@@ -1393,7 +1397,7 @@ void ODBCCOL::WriteColumn(PGLOBAL g)
13931397
/* -------------------------- Class TDBXDBC -------------------------- */
13941398

13951399
/***********************************************************************/
1396-
/* Implementation of the TDBODBC class. */
1400+
/* Implementation of the TDBXDBC class. */
13971401
/***********************************************************************/
13981402
TDBXDBC::TDBXDBC(PODEF tdp) : TDBODBC(tdp)
13991403
{

storage/connect/xindex.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ typedef struct index_def : public BLOCK {
6565

6666
typedef struct index_off {
6767
union {
68+
#if defined(WORDS_BIGENDIAN)
69+
struct {int High; int Low;};
70+
#else // !WORDS_BIGENDIAN
6871
struct {int Low; int High;};
72+
#endif //!WORDS_BIGENDIAN
6973
longlong Val; // File position
7074
}; // end of union
7175
} IOFF;

0 commit comments

Comments
 (0)