Changeset 18 for trunk/tmdmcreator


Ignore:
Timestamp:
02/22/13 13:30:00 (11 years ago)
Author:
lucsch
Message:
  • Preliminary code for processing user_content.txt. Processing thematic_layers is now working
  • Corrected base_structure and user_structure.sql
Location:
trunk/tmdmcreator/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/tmdmcreator/src/main.cpp

    r16 r18  
    8383    bool bVerbose = parser.Found("verbose"); 
    8484    bool bToolMap = parser.Found("toolmap"); 
    85     if (parser.Found("overwrite")) { 
     85    if (parser.Found("overwrite") && wxFileExists(parser.GetParam(3))) { 
    8686        wxRemoveFile(parser.GetParam(3)); 
    8787    } 
  • trunk/tmdmcreator/src/tmdmcopier.cpp

    r16 r18  
    2626 
    2727TmDmCopier::~TmDmCopier() { 
     28    m_File->Flush(); 
    2829    wxDELETE(m_File); 
    2930} 
     
    4950 
    5051bool TmDmCopier::CopyFrom(const wxString & text) { 
     52    m_File->SeekEnd(); 
    5153    if (m_File->Write(text) == false) { 
    5254        m_Errors.Add(wxString::Format(_("Writing to: %s failed!"), m_File->GetName())); 
  • trunk/tmdmcreator/src/tmdmcreator.cpp

    r17 r18  
    9494    errorsmsg.Clear(); 
    9595    // Copy structure 
    96     TmDmCopier myCopier(m_FileNameOutSQL); 
    97     if (myCopier.CopyFrom(m_FileNameBaseSQL) == false) { 
    98         errorsmsg.Add(wxString::Format(_("Copying: %s failed!"), m_FileNameBaseSQL.GetFullPath())); 
    99         return false; 
     96    { // needed to destroy the copier before processing layers 
     97        TmDmCopier myCopier(m_FileNameOutSQL); 
     98        if (myCopier.CopyFrom(m_FileNameBaseSQL) == false) { 
     99            errorsmsg.Add(wxString::Format(_("Copying: %s failed!"), m_FileNameBaseSQL.GetFullPath())); 
     100            return false; 
     101        } 
     102         
     103        if (myCopier.CopyFrom(m_FileNameUserSQL) == false) { 
     104            errorsmsg.Add(wxString::Format(_("Copying: %s failed!"), m_FileNameUserSQL.GetFullPath())); 
     105            return false; 
     106        } 
    100107    } 
    101      
    102     if (myCopier.CopyFrom(m_FileNameUserSQL) == false) { 
    103         errorsmsg.Add(wxString::Format(_("Copying: %s failed!"), m_FileNameUserSQL.GetFullPath())); 
    104         return false; 
    105     } 
    106      
     108 
    107109    // Process layers 
    108110    TmDmProcessorSimple myLayerProc(m_FileNameUserContent, m_FileNameOutSQL); 
     
    112114        return false; 
    113115    } 
    114     if (myLayerProc.ProcessBlock(myThematicLayersStart)==false) { 
     116    if (myLayerProc.ProcessBlock(myThematicLayersStart, _T("thematic_layers"))==false) { 
    115117        errorsmsg.Add(wxString::Format(_("Processing 'thematic_layers' failed in %s"), m_FileNameUserContent.GetFullPath())); 
    116118        return false; 
  • trunk/tmdmcreator/src/tmdmprocessor.cpp

    r17 r18  
    6161 
    6262 
    63 bool TmDmProcessorSimple::ProcessBlock(int blockstart) { 
    64     wxString mySQLCols = wxEmptyString; 
    65     wxString mySQLTxt = wxEmptyString; 
     63bool TmDmProcessorSimple::ProcessBlock(int blockstart, const wxString & tablename) { 
     64    wxArrayString mySQLCols; 
     65    TmDmCopier myCopier(m_FileDst); 
    6666     
    6767    wxFileInputStream input(m_FileSrc.GetFullPath()); 
     
    6969    long myLineIndex = 0; 
    7070    while(input.IsOk() && !input.Eof() ){ 
     71        wxString myRow = text.ReadLine(); 
    7172        if (myLineIndex <= blockstart) { 
    7273            myLineIndex++; 
     
    7475        } 
    7576         
    76         wxString myRow = text.ReadLine(); 
     77        if (myLineIndex == blockstart+1) { 
     78            mySQLCols = wxStringTokenize(myRow, _T("\t"), wxTOKEN_RET_EMPTY); 
     79            myLineIndex++; 
     80            continue; 
     81        } 
    7782         
    78         // HERE !!!  
     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        } 
    7995         
    80          
    81          
     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); 
    82109        myLineIndex++; 
    83110    } 
    84     return wxNOT_FOUND; 
    85  
    86      
    87      
    88      
    89111    return false; 
    90112} 
     
    104126} 
    105127 
    106 bool TmDmProcessorAttributs::ProcessBlock(int blockstart) { 
     128bool TmDmProcessorAttributs::ProcessBlock(int blockstart, const wxString & tablename) { 
    107129    return false; 
    108130} 
  • trunk/tmdmcreator/src/tmdmprocessor.h

    r17 r18  
    2424#include <wx/wfstream.h> 
    2525#include <wx/txtstrm.h> 
     26#include <wx/tokenzr.h> 
    2627 
    2728 
     
    3738     
    3839    int FindBlock(const wxString & blockname); 
    39     virtual bool ProcessBlock(int blockstart) = 0; 
     40    virtual bool ProcessBlock(int blockstart, const wxString & tablename) = 0; 
    4041}; 
    4142 
     
    5152    virtual ~TmDmProcessorSimple(); 
    5253     
    53     virtual bool ProcessBlock(int blockstart); 
     54    virtual bool ProcessBlock(int blockstart, const wxString & tablename); 
    5455}; 
    5556 
     
    6566    virtual ~TmDmProcessorAttributs(); 
    6667     
    67     virtual bool ProcessBlock(int blockstart); 
     68    virtual bool ProcessBlock(int blockstart, const wxString & tablename); 
    6869}; 
    6970#endif 
Note: See TracChangeset for help on using the changeset viewer.