added operator<< for NdbRecAttr and removed attrtype from Event impl

parent a481c4aa
......@@ -475,5 +475,7 @@ NdbRecAttr::isNULL() const
return theNULLind;
}
class NdbOut& operator <<(class NdbOut&, const NdbRecAttr &);
#endif
......@@ -499,8 +499,7 @@ NdbEventOperationImpl::print()
NdbRecAttr *p = theFirstRecAttrs[i];
ndbout << " %u " << i;
while (p) {
ndbout << " : " << p->attrId() << " = ";
printRecAttr(p);
ndbout << " : " << p->attrId() << " = " << *p;
p = p->next();
}
ndbout << "\n";
......@@ -1248,60 +1247,3 @@ NdbGlobalEventBuffer::real_wait(NdbGlobalEventBufferHandle *h,
n += hasData(h->m_bufferIds[i]);
return n;
}
/**
* TODO Change this function to use the real datatypes
* from NdbDictionary alternatively make a
* "printer" in NdbRecAttr that can be used from all programs
*/
// and remove this include
#include "NdbSchemaOp.hpp"
void
NdbEventOperationImpl::printRecAttr(NdbRecAttr *p)
{
int size = p->attrSize();
int aSize = p->arraySize();
switch(convertColumnTypeToAttrType(p->getType())){
case UnSigned:
switch(size) {
case 8: ndbout << p->u_64_value(); break;
case 4: ndbout << p->u_32_value(); break;
case 2: ndbout << p->u_short_value(); break;
case 1: ndbout << (unsigned) p->u_char_value(); break;
default: ndbout << "Unknown size" << endl;
}
break;
case Signed:
switch(size) {
case 8: ndbout << p->int64_value(); break;
case 4: ndbout << p->int32_value(); break;
case 2: ndbout << p->short_value(); break;
case 1: ndbout << (int) p->char_value(); break;
default: ndbout << "Unknown size" << endl;
}
break;
case String:
{
char* buf = new char[aSize+1];
memcpy(buf, p->aRef(), aSize);
buf[aSize] = 0;
ndbout << buf;
delete [] buf;
}
break;
case Float:
ndbout << p->float_value();
break;
default:
ndbout << "Unknown";
break;
}
}
......@@ -60,7 +60,6 @@ public:
void print();
void printAll();
void printRecAttr(NdbRecAttr *);
Ndb *m_ndb;
NdbEventImpl *m_eventImpl;
......
......@@ -27,7 +27,8 @@ Documentation:
Adjust: 971206 UABRONM First version
************************************************************************************************/
#include <ndb_global.h>
#include "NdbRecAttr.hpp"
#include <NdbOut.hpp>
#include <NdbRecAttr.hpp>
#include "NdbDictionaryImpl.hpp"
NdbRecAttr::NdbRecAttr() :
......@@ -124,3 +125,88 @@ NdbRecAttr::clone() const {
memcpy(ret->theRef, theRef, n);
return ret;
}
NdbOut& operator <<(NdbOut& ndbout, const NdbRecAttr &r)
{
if (r.isNULL())
{
ndbout << "[NULL]";
return ndbout;
}
switch(r.getType()){
case NdbDictionary::Column::Bigunsigned:
ndbout << r.u_64_value();
break;
case NdbDictionary::Column::Unsigned:
ndbout << r.u_32_value();
break;
case NdbDictionary::Column::Smallunsigned:
ndbout << r.u_short_value();
break;
case NdbDictionary::Column::Tinyunsigned:
ndbout << (unsigned) r.u_char_value();
break;
case NdbDictionary::Column::Bigint:
ndbout << r.int64_value();
break;
case NdbDictionary::Column::Int:
ndbout << r.int32_value();
break;
case NdbDictionary::Column::Smallint:
ndbout << r.short_value();
break;
case NdbDictionary::Column::Tinyint:
ndbout << (int) r.char_value();
break;
case NdbDictionary::Column::Char:
case NdbDictionary::Column::Varchar:
{
int aSize = r.arraySize();
char* buf = new char[aSize+1];
memcpy(buf, r.aRef(), aSize);
buf[aSize] = 0;
ndbout << buf;
delete [] buf;
}
break;
case NdbDictionary::Column::Float:
ndbout << r.float_value();
break;
case NdbDictionary::Column::Double:
ndbout << r.double_value();
break;
case NdbDictionary::Column::Mediumint:
ndbout << "[Mediumint]";
break;
case NdbDictionary::Column::Mediumunsigned:
ndbout << "[Mediumunsigend]";
break;
case NdbDictionary::Column::Binary:
ndbout << "[Binary]";
break;
case NdbDictionary::Column::Varbinary:
ndbout << "[Varbinary]";
break;
case NdbDictionary::Column::Decimal:
ndbout << "[Decimal]";
break;
case NdbDictionary::Column::Timespec:
ndbout << "[Timespec]";
break;
case NdbDictionary::Column::Blob:
ndbout << "[Blob]";
break;
case NdbDictionary::Column::Undefined:
ndbout << "[Undefined]";
break;
default:
ndbout << "[unknown]";
break;
}
return ndbout;
}
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