123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- /*##############################################################################
- HPCC SYSTEMS software Copyright (C) 2014 HPCC Systems.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- ############################################################################## */
- #ifndef SQLCOLUMN_HPP_
- #define SQLCOLUMN_HPP_
- #include "ws_sql.hpp"
- class SQLColumn : public CInterface, public IInterface
- {
- private:
- StringBuffer name;
- StringBuffer alias;
- StringBuffer parenttable;
- int position;
- bool ascending;
- StringBuffer columnType;
- public:
- IMPLEMENT_IINTERFACE;
- SQLColumn();
- SQLColumn(const char* parentname, const char* columnname, const char* alias, int position);
- virtual ~SQLColumn();
- bool isAscending() const
- {
- return ascending;
- }
- void setAscending(bool ascending)
- {
- this->ascending = ascending;
- }
- const char * getAlias() const
- {
- return alias.str();
- }
- void setAlias(const char * alias)
- {
- this->alias.set(alias);
- }
- const char * getName()
- {
- return name.str();
- }
- void setName(const char * name)
- {
- this->name.set(name);
- }
- const char * getParenttable() const
- {
- return parenttable.str();
- }
- void setParenttable(const char * parenttable)
- {
- this->parenttable.set(parenttable);
- }
- int getPosition() const
- {
- return position;
- }
- void setPosition(int position)
- {
- this->position = position;
- }
- bool isFieldNameOrAalias(const char* possiblenameoralias);
- void toString(StringBuffer & str, bool fullOutput);
- const char * getColumnNameOrAlias()
- {
- if (alias.length() > 0)
- return alias.str();
- else
- return name.str();
- }
- const char * getColumnType() const
- {
- return columnType.str();
- }
- void setColumnType(const char* columnType)
- {
- this->columnType.set(columnType);
- }
- };
- #define DEFAULTDECIMALCHARS 32;
- #define DEFAULTINTBYTES 8;
- #define DEFAULTREALBYTES 8;
- #define DEFAULTCOLCHARS 0;
- #define DEFAULTDECDIGITS 0;
- class HPCCColumnMetaData : public CInterface, public IInterface
- {
- private:
- StringBuffer columnName;
- StringBuffer tableName;
- int index;
- int decimalDigits;
- StringBuffer columnType;
- bool keyedField;
- IArrayOf<HPCCColumnMetaData> childColumns;
- public:
- IMPLEMENT_IINTERFACE;
- static HPCCColumnMetaData * createHPCCColumnMetaData(const char * name)
- {
- return new HPCCColumnMetaData(name);
- }
- HPCCColumnMetaData() : keyedField(false), decimalDigits(0), index(-1)
- {
- columnName.clear();
- }
- HPCCColumnMetaData(const char * colname) : keyedField(false), decimalDigits(0), index(-1)
- {
- columnName.set(colname);
- }
- virtual ~HPCCColumnMetaData()
- {
- #ifdef _DEBUG
- fprintf(stderr, "leaving %s columnmetadata.\n", columnName.str());
- #endif
- childColumns.kill(false);
- }
- StringBuffer &toEclRecString(StringBuffer &result)
- {
- result.append(this->columnType.str());
- result.append(" ");
- result.append(this->columnName.str());
- return result;
- }
- const char * getColumnType() const
- {
- return columnType.str();
- }
- void setColumnType(const char* columnType)
- {
- if (strncmp(columnType, "table of", 8)==0)
- {
- StringBuffer result;
- result.append("DATASET({");
- ForEachItemIn(childIndex, childColumns)
- {
- this->childColumns.item(childIndex).toEclRecString(result);
- if (childIndex < childColumns.length()-1)
- result.append(", ");
- }
- result.append("})");
- this->columnType.set(result);
- }
- else
- this->columnType.set(columnType);
- }
- int getDecimalDigits() const
- {
- return decimalDigits;
- }
- void setDecimalDigits(int decimalDigits = 0)
- {
- this->decimalDigits = decimalDigits;
- }
- int getIndex() const
- {
- return index;
- }
- void setIndex(int index)
- {
- this->index = index;
- }
- const char * getTableName() const
- {
- return tableName.str();
- }
- void setTableName(const char* tableName)
- {
- this->tableName.set(tableName);
- }
- bool isKeyedField() const
- {
- return keyedField;
- }
- void setKeyedField(bool keyedField)
- {
- this->keyedField = keyedField;
- }
- const char * getColumnName() const
- {
- return columnName.str();
- }
- void setChildCol(HPCCColumnMetaData * child)
- {
- childColumns.append(*LINK(child));
- }
- IArrayOf<HPCCColumnMetaData> * getChildColumns()
- {
- return &childColumns;
- }
- };
- #endif /* SQLCOLUMN_HPP_ */
|