1 | /*************************************************************************** |
---|
2 | tmdmprocessor.cpp |
---|
3 | ------------------- |
---|
4 | copyright : (C) 2013 CREALP Lucien Schreiber |
---|
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 | |
---|
20 | TmDmProcessor::TmDmProcessor(const wxFileName & src, const wxFileName & dest) { |
---|
21 | m_FileSrc = src; |
---|
22 | m_FileDst = dest; |
---|
23 | } |
---|
24 | |
---|
25 | |
---|
26 | |
---|
27 | TmDmProcessor::~TmDmProcessor() { |
---|
28 | } |
---|
29 | |
---|
30 | |
---|
31 | |
---|
32 | int TmDmProcessor::FindBlock(const wxString & blockname) { |
---|
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 | } |
---|
43 | return wxNOT_FOUND; |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | TmDmProcessorSimple::TmDmProcessorSimple(const wxFileName & src, const wxFileName & dest) : TmDmProcessor(src,dest) { |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | TmDmProcessorSimple::~TmDmProcessorSimple() { |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | bool TmDmProcessorSimple::ProcessBlock(int blockstart, const wxString & tablename) { |
---|
64 | wxArrayString mySQLCols; |
---|
65 | TmDmCopier myCopier(m_FileDst); |
---|
66 | |
---|
67 | wxFileInputStream input(m_FileSrc.GetFullPath()); |
---|
68 | wxTextInputStream text(input); |
---|
69 | long myLineIndex = 0; |
---|
70 | while(input.IsOk() && !input.Eof() ){ |
---|
71 | wxString myRow = text.ReadLine(); |
---|
72 | if (myLineIndex <= blockstart) { |
---|
73 | myLineIndex++; |
---|
74 | continue; |
---|
75 | } |
---|
76 | |
---|
77 | if (myLineIndex == blockstart+1) { |
---|
78 | mySQLCols = wxStringTokenize(myRow, _T("\t"), wxTOKEN_RET_EMPTY); |
---|
79 | myLineIndex++; |
---|
80 | continue; |
---|
81 | } |
---|
82 | |
---|
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 | } |
---|
95 | |
---|
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); |
---|
109 | myLineIndex++; |
---|
110 | } |
---|
111 | return false; |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | TmDmProcessorAttributs::TmDmProcessorAttributs(const wxFileName & src, const wxFileName & dest) : TmDmProcessor(src,dest) { |
---|
123 | } |
---|
124 | |
---|
125 | TmDmProcessorAttributs::~TmDmProcessorAttributs() { |
---|
126 | } |
---|
127 | |
---|
128 | bool TmDmProcessorAttributs::ProcessBlock(int blockstart, const wxString & tablename) { |
---|
129 | return false; |
---|
130 | } |
---|
131 | |
---|