#ifndef _TABLE_TO_JSON_HPP_ #define _TABLE_TO_JSON_HPP_ #include #include #include #include #define NORECORD 100 using namespace std; using namespace iPlature; using namespace iDA; using namespace log4cplus; extern iDA::Connection cn; //template class TabToJson class TabToJson { private: iDA::Command cmd; char jsonBuffer[20000]; string tmp; int index; public: TabToJson() { tmp=""; index=0; memset(jsonBuffer,0x00,sizeof(jsonBuffer)); } ~TabToJson() { return; } public: /* Read DB Table Data to json */ /* { "columns":["c1","c2","c3"], "values":[["v11","v12","v13"],["v21","v22","v23"]] } */ string ToJson(char* dbwhere = NULL) { LOG log("TabToJson::ToJson"); try { cmd.SetConnection(&cn); cmd.SetCommandText(dbwhere); cmd.Execute(); int icolCount=cmd.FieldCount(); tmp="{\"columns\":["; sprintf(&jsonBuffer[index],"%s",tmp.c_str()); index+=tmp.size(); for(int i=1;i<=icolCount;i++) { tmp="\""+cmd.Field(i).Name()+"\","; sprintf(&jsonBuffer[index],"%s",tmp.c_str()); index+=tmp.size(); //log.Debug()<<"icols:"<