00001
00002
00003
00004
00005
00006
00014 #ifndef DBOUTPUT_H
00015 #define DBOUTPUT_H
00016
00017
00018 #include <string>
00019 #include <vector>
00020 #include <ostream>
00021
00022 #include "Db.h"
00023
00024
00034 class DbOutput
00035 {
00036
00037 public:
00038 Db& _db;
00039
00040 DbOutput(Db& db);
00041 virtual ~DbOutput();
00042
00043 virtual void WriteSchema(const std::string& path = std::string());
00044 virtual void WriteDataLoadingScripts(const std::string& path =
00045 std::string());
00046 virtual void WriteData(Block& block, const std::string& path =
00047 std::string());
00048
00049 void SetInputFile(const std::string& inpFile);
00050
00051 const std::string& GetCommandScriptName();
00052
00053 protected:
00054 static const std::string _DATA_LOADING_SCRIPT;
00055
00056 std::string _SCHEMA_FILE;
00057
00058 std::string _INPUT_FILE;
00059
00060 std::string _stringDelimiter;
00061 std::vector<char> _specialChars;
00062
00063 std::string _dateDelimiter;
00064 std::vector<char> _specialDateChars;
00065
00066 std::string _itemSeparator;
00067 std::string _rowSeparator;
00068
00069 void WriteDbExec(std::ostream& io, const std::string& fileName,
00070 const unsigned int indentLevel = 0);
00071 void WriteDbExecOnly(std::ostream& io, const std::string& fileName,
00072 const unsigned int indentLevel = 1);
00073
00074 void WriteHeader(std::ostream& io);
00075
00076 void _FormatNumericData(std::ostream &io, const std::string &cs);
00077 void _FormatStringData(std::ostream& io, const std::string& cs,
00078 const unsigned int maxWidth);
00079 void _FormatTextData(std::ostream &io, const std::string &cs);
00080 void _FormatDateData(std::ostream& io, const std::string& cs,
00081 const unsigned int maxWidth);
00082
00083 void _FormatData(std::ostream& io, const std::string& cs,
00084 const unsigned int type, const unsigned int witdh);
00085
00086 bool IsSpecialChar(const char& character);
00087 bool IsSpecialDateChar(const char& character);
00088
00089 virtual void WriteEmptyNumeric(std::ostream& io);
00090 virtual void WriteEmptyString(std::ostream& io);
00091 virtual void WriteSpecialChar(std::ostream& io, const char& specChar);
00092
00093 virtual void WriteEmptyDate(std::ostream& io);
00094 virtual void WriteSpecialDateChar(std::ostream& io,
00095 const char& specDateChar);
00096
00097 virtual bool IsFirstTextNewLineSpecial();
00098 virtual void WriteNewLine(std::ostream& io, bool special = false);
00099
00100 virtual void GetTableStart(std::string& tableStart,
00101 const std::string& tableName);
00102 virtual void GetTableEnd(std::string& tableEnd);
00103 const std::string& GetItemSeparator();
00104 const std::string& GetRowSeparator();
00105
00106 void GetMasterIndexAttribValue(std::string& masterIndexAttribValue,
00107 Block& block, const std::string& masterIndexAttribName,
00108 const std::vector<std::string>& tableNames);
00109
00110 protected:
00111 virtual void _WriteTable(std::ostream& io, ISTable* tIn,
00112 std::vector<unsigned int>& widths,
00113 const bool reCalcWidth = false,
00114 const std::vector<eTypeCode>& typeCodes =
00115 std::vector<eTypeCode> (0));
00116
00117 private:
00118 static void _FormatStringDataSql(std::ostream &io, const std::string& cs,
00119 unsigned int maxWidth);
00120 };
00121
00122 #endif