Ignore:
Timestamp:
02/22/13 14:37:37 (11 years ago)
Author:
lucsch
Message:

Exporting to SQL is now working

File:
1 edited

Legend:

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

    r18 r19  
    6464    wxArrayString mySQLCols; 
    6565    TmDmCopier myCopier(m_FileDst); 
     66    myCopier.CopyFrom(wxString::Format(_T("\n-- %s --\n"), tablename)); 
     67 
    6668     
    6769    wxFileInputStream input(m_FileSrc.GetFullPath()); 
     
    123125} 
    124126 
     127 
     128 
    125129TmDmProcessorAttributs::~TmDmProcessorAttributs() { 
    126130} 
    127131 
     132 
     133 
     134bool TmDmProcessorAttributs::_ProcessAttributesName(int blockstart) { 
     135    wxArrayString mySQLCols; 
     136    TmDmCopier myCopier(m_FileDst); 
     137    myCopier.CopyFrom(wxString::Format(_T("\n-- %s --\n"), _T("dmn_layer_attribut"))); 
     138    int NUM_COLS = 3; 
     139    wxArrayString myPreviousRow; 
     140     
     141    wxFileInputStream input(m_FileSrc.GetFullPath()); 
     142    wxTextInputStream text(input); 
     143    long myLineIndex = 0; 
     144    while(input.IsOk() && !input.Eof() ){ 
     145        wxString myRow = text.ReadLine(); 
     146        if (myLineIndex <= blockstart) { 
     147            myLineIndex++; 
     148            continue; 
     149        } 
     150         
     151        if (myLineIndex == blockstart+1) { 
     152            mySQLCols = wxStringTokenize(myRow, _T("\t"), wxTOKEN_RET_EMPTY); 
     153            myLineIndex++; 
     154            continue; 
     155        } 
     156         
     157        wxArrayString myValues = wxStringTokenize(myRow, _T("\t"), wxTOKEN_RET_EMPTY_ALL); 
     158        bool bEmpty = true; 
     159        for (unsigned int i = 0; i< myValues.GetCount(); i++) { 
     160            if (myValues[i] != wxEmptyString) { 
     161                bEmpty = false; 
     162                break; 
     163            } 
     164        } 
     165        if (bEmpty == true) { 
     166            // ok empty line found 
     167            return true; 
     168        } 
     169         
     170        // check that this row differs from previous 
     171        wxArrayString myAttributRow; 
     172        for (unsigned int i = 0; i< NUM_COLS; i++) { 
     173            myAttributRow.Add(myValues.Item(i)); 
     174        } 
     175        if (myAttributRow == myPreviousRow) { 
     176            continue; 
     177        } 
     178        myPreviousRow = myAttributRow; 
     179         
     180         
     181        wxString myInsert = _T("INSERT INTO `dmn_layer_attribut` VALUES ("); 
     182        for (unsigned int i = 0; i< myAttributRow.GetCount(); i++) { 
     183            myInsert.Append(wxString::Format(_T("\"%s\","), myAttributRow.Item(i))); 
     184        } 
     185        myInsert.RemoveLast(); 
     186        myInsert.Append(_T(");\n")); 
     187        myCopier.CopyFrom(myInsert); 
     188        myLineIndex++; 
     189    } 
     190    return true; 
     191} 
     192 
     193 
     194 
     195bool TmDmProcessorAttributs::_ProcessAttributesValues(int blockstart) { 
     196    wxArrayString mySQLCols; 
     197    TmDmCopier myCopier(m_FileDst); 
     198    myCopier.CopyFrom(wxString::Format(_T("\n-- %s --\n"), _T("attribut values"))); 
     199    int START_COL = 3; 
     200     
     201    wxFileInputStream input(m_FileSrc.GetFullPath()); 
     202    wxTextInputStream text(input); 
     203    long myLineIndex = 0; 
     204    while(input.IsOk() && !input.Eof() ){ 
     205        wxString myRow = text.ReadLine(); 
     206        if (myLineIndex <= blockstart) { 
     207            myLineIndex++; 
     208            continue; 
     209        } 
     210         
     211        if (myLineIndex == blockstart+1) { 
     212            mySQLCols = wxStringTokenize(myRow, _T("\t"), wxTOKEN_RET_EMPTY); 
     213            myLineIndex++; 
     214            continue; 
     215        } 
     216         
     217         
     218        wxArrayString myValues = wxStringTokenize(myRow, _T("\t"), wxTOKEN_RET_EMPTY_ALL); 
     219        bool bEmpty = true; 
     220        for (unsigned int i = 0; i< myValues.GetCount(); i++) { 
     221            if (myValues[i] != wxEmptyString) { 
     222                bEmpty = false; 
     223                break; 
     224            } 
     225        } 
     226        if (bEmpty == true) { 
     227            // ok empty line found 
     228            return true; 
     229        } 
     230         
     231        // query to dmn_catalog 
     232        wxString myInsert = _T("INSERT INTO `dmn_catalog` VALUES ("); 
     233        for (unsigned int i = START_COL; i< mySQLCols.GetCount(); i++) { 
     234            myInsert.Append(wxString::Format(_T("\"%s\","), myValues.Item(i))); 
     235        } 
     236        myInsert.RemoveLast(); 
     237        myInsert.Append(_T(");\n")); 
     238         
     239         
     240        // query to dmn_attribut_value 
     241        myInsert.Append(wxString::Format(_T("INSERT INTO `dmn_attribut_value` VALUES (%s, %s);\n"), 
     242                                         myValues.Item(0), myValues.Item(START_COL))); 
     243         
     244        myCopier.CopyFrom(myInsert); 
     245        myLineIndex++; 
     246    } 
     247    return true; 
     248} 
     249 
     250 
     251 
    128252bool TmDmProcessorAttributs::ProcessBlock(int blockstart, const wxString & tablename) { 
    129     return false; 
    130 } 
    131  
     253    if (_ProcessAttributesName(blockstart) == false) { 
     254        return false; 
     255    } 
     256     
     257    if (_ProcessAttributesValues(blockstart) == false) { 
     258        return false; 
     259    } 
     260    return true; 
     261} 
     262 
     263 
     264 
Note: See TracChangeset for help on using the changeset viewer.