[15] | 1 | /*************************************************************************** |
---|
| 2 | tmdmprocessor.cpp |
---|
| 3 | ------------------- |
---|
[16] | 4 | copyright : (C) 2013 CREALP Lucien Schreiber |
---|
[15] | 5 | email : lucien.schreiber at crealp dot vs dot ch |
---|
| 6 | ***************************************************************************/ |
---|
| 7 | |
---|
| 8 | /*************************************************************************** |
---|
| 9 | * * |
---|
| 10 | * This program is free software; you can redistribute it and/or modify * |
---|
| 11 | * it under the terms of the GNU General Public License as published by * |
---|
| 12 | * the Free Software Foundation; either version 2 of the License, or * |
---|
| 13 | * (at your option) any later version. * |
---|
| 14 | * * |
---|
| 15 | ***************************************************************************/ |
---|
| 16 | |
---|
| 17 | #include "tmdmprocessor.h" |
---|
| 18 | #include "tmdmcopier.h" |
---|
| 19 | |
---|
[17] | 20 | TmDmProcessor::TmDmProcessor(const wxFileName & src, const wxFileName & dest) { |
---|
| 21 | m_FileSrc = src; |
---|
| 22 | m_FileDst = dest; |
---|
[15] | 23 | } |
---|
| 24 | |
---|
[16] | 25 | |
---|
| 26 | |
---|
[15] | 27 | TmDmProcessor::~TmDmProcessor() { |
---|
| 28 | } |
---|
| 29 | |
---|
[16] | 30 | |
---|
| 31 | |
---|
[15] | 32 | int TmDmProcessor::FindBlock(const wxString & blockname) { |
---|
[17] | 33 | wxFileInputStream input(m_FileSrc.GetFullPath()); |
---|
| 34 | wxTextInputStream text(input); |
---|
| 35 | long myLineIndex = 0; |
---|
| 36 | while(input.IsOk() && !input.Eof() ){ |
---|
| 37 | wxString myLine = text.ReadLine(); |
---|
| 38 | if (myLine.StartsWith(blockname)==true){ |
---|
| 39 | return myLineIndex; |
---|
| 40 | } |
---|
| 41 | myLineIndex++; |
---|
| 42 | } |
---|
[16] | 43 | return wxNOT_FOUND; |
---|
[15] | 44 | } |
---|
| 45 | |
---|
[16] | 46 | |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | |
---|
[17] | 53 | TmDmProcessorSimple::TmDmProcessorSimple(const wxFileName & src, const wxFileName & dest) : TmDmProcessor(src,dest) { |
---|
[15] | 54 | } |
---|
| 55 | |
---|
[16] | 56 | |
---|
| 57 | |
---|
[15] | 58 | TmDmProcessorSimple::~TmDmProcessorSimple() { |
---|
| 59 | } |
---|
| 60 | |
---|
[16] | 61 | |
---|
| 62 | |
---|
[18] | 63 | bool TmDmProcessorSimple::ProcessBlock(int blockstart, const wxString & tablename) { |
---|
| 64 | wxArrayString mySQLCols; |
---|
| 65 | TmDmCopier myCopier(m_FileDst); |
---|
[17] | 66 | |
---|
| 67 | wxFileInputStream input(m_FileSrc.GetFullPath()); |
---|
| 68 | wxTextInputStream text(input); |
---|
| 69 | long myLineIndex = 0; |
---|
| 70 | while(input.IsOk() && !input.Eof() ){ |
---|
[18] | 71 | wxString myRow = text.ReadLine(); |
---|
[17] | 72 | if (myLineIndex <= blockstart) { |
---|
| 73 | myLineIndex++; |
---|
| 74 | continue; |
---|
| 75 | } |
---|
| 76 | |
---|
[18] | 77 | if (myLineIndex == blockstart+1) { |
---|
| 78 | mySQLCols = wxStringTokenize(myRow, _T("\t"), wxTOKEN_RET_EMPTY); |
---|
| 79 | myLineIndex++; |
---|
| 80 | continue; |
---|
| 81 | } |
---|
[17] | 82 | |
---|
[18] | 83 | wxArrayString myValues = wxStringTokenize(myRow, _T("\t"), wxTOKEN_RET_EMPTY_ALL); |
---|
| 84 | bool bEmpty = true; |
---|
| 85 | for (unsigned int i = 0; i< myValues.GetCount(); i++) { |
---|
| 86 | if (myValues[i] != wxEmptyString) { |
---|
| 87 | bEmpty = false; |
---|
| 88 | break; |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | if (bEmpty == true) { |
---|
| 92 | // ok empty line found |
---|
| 93 | return true; |
---|
| 94 | } |
---|
[17] | 95 | |
---|
[18] | 96 | // write insert sentence |
---|
| 97 | wxString myInsert = wxString::Format(_T("INSERT INTO `%s` ("), tablename); |
---|
| 98 | for (unsigned int i = 0; i< mySQLCols.GetCount(); i++) { |
---|
| 99 | myInsert.Append(wxString::Format(_T("%s,"), mySQLCols.Item(i))); |
---|
| 100 | } |
---|
| 101 | myInsert.RemoveLast(); |
---|
| 102 | myInsert.Append(_T(") VALUES (")); |
---|
| 103 | for (unsigned int i = 0; i< mySQLCols.GetCount(); i++) { |
---|
| 104 | myInsert.Append(wxString::Format(_T("\"%s\","), myValues.Item(i))); |
---|
| 105 | } |
---|
| 106 | myInsert.RemoveLast(); |
---|
| 107 | myInsert.Append(_T(");\n")); |
---|
| 108 | myCopier.CopyFrom(myInsert); |
---|
[17] | 109 | myLineIndex++; |
---|
| 110 | } |
---|
[16] | 111 | return false; |
---|
[15] | 112 | } |
---|
| 113 | |
---|
[16] | 114 | |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | |
---|
[17] | 122 | TmDmProcessorAttributs::TmDmProcessorAttributs(const wxFileName & src, const wxFileName & dest) : TmDmProcessor(src,dest) { |
---|
[15] | 123 | } |
---|
| 124 | |
---|
| 125 | TmDmProcessorAttributs::~TmDmProcessorAttributs() { |
---|
| 126 | } |
---|
| 127 | |
---|
[18] | 128 | bool TmDmProcessorAttributs::ProcessBlock(int blockstart, const wxString & tablename) { |
---|
[16] | 129 | return false; |
---|
[15] | 130 | } |
---|
| 131 | |
---|