Hauptseite | Liste aller Namensbereiche | Klassenhierarchie | Übersicht | Auflistung der Dateien | Elemente eines Namensbereiches | Datenstruktur-Elemente | Datei-Elemente

DbWriteDriverMySql.cpp

gehe zur Dokumentation dieser Datei
00001 // Copyright (C) 2004 Bernhard Assmann <bernie@tuxomania.net>
00002 //  
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //  
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //  
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 //  
00017 
00018 #include <iostream>
00019 #include <vector>
00020 #include <algorithm>
00021 #include <sstream>
00022 #include <utility>
00023 #include <fstream>
00024 #include <iterator>
00025 
00026 #include "psfa/DbWriteDriverMySql.hpp"
00027 #include "psfa/Config.hpp"
00028 #include "psfa/Helper.hpp"
00029 #include "psfa/CheckData.hpp"
00030 #include "psfa/UnitParser.hpp"
00031 
00032 
00033 
00034 psfa::DbWriteDriverMySql::DbWriteDriverMySql()
00035 {
00036   success_ = myHelper_.connect();
00037   if( !success_ ) {
00038     std::cout << "Es konnte keine Verbindung zur Datenbank hergestellt werden."
00039          << std::endl;
00040     exit(1);
00041   }
00042 }
00043 
00044 
00045 
00046 psfa::DbWriteDriverMySql::~DbWriteDriverMySql() 
00047 {
00048   success_ = myHelper_.disconnect();
00049   if( !success_ ) {
00050     std::cerr << "Die Verbindung zur DB konnte nicht erfolgreich abgebaut werden."
00051          << std::endl;
00052   }
00053   
00054 }
00055 
00056 
00057   
00058 void
00059 psfa::DbWriteDriverMySql::initPsfa() 
00060 {
00061   using std::string;
00062   using psfahelper::splitString;
00063   using psfahelper::getFilePaths;
00064   typedef std::vector< string > sVec;
00065 
00066   Config* conf = Config::getConfig();
00067   string p = conf->getConfigValue( "psfa", "pools" );
00068   sVec pools;
00069   splitString( p, pools );
00070 
00071   sVec::iterator iEnd = pools.end();
00072   
00073   for( sVec::iterator i = pools.begin(); i != iEnd; ++i ) {
00074     if( existPool( *i ) ) {
00075       delPool( *i );
00076     }
00077     int poolId = insertPool( *i );
00078     insertKontext( *i, poolId );
00079     insertSearch( *i, poolId );
00080     string path = conf->getConfigValue( *i, "root" );
00081     sVec files;
00082     getFilePaths( path, "*.xml", files );
00083     insertFiles( poolId, files, path );
00084   }
00085   return;
00086 }
00087 
00088   
00089 
00090 void
00091 psfa::DbWriteDriverMySql::delPool( const std::string poolName ) 
00092 {
00093   std::ostringstream sql;
00094   sql << "SELECT pool_id FROM pool WHERE p_name = '"
00095       << poolName
00096       << "'";
00097   int id = myHelper_.getSingleValueInt( sql );
00098   sql.str( "" );
00099   sql << "DELETE FROM pool WHERE pool_id = "
00100       << id;
00101   myHelper_.executeSql( sql );
00102   
00103   sql.str( "" );
00104   std::ostringstream ids;
00105   sql << "SELECT file_id FROM file WHERE pool_id = "
00106       << id;
00107   myHelper_.getValueStream( sql, ids, ", " );
00108   std::string idList = ids.str();
00109   if( !idList.empty() ) {
00110     sql.str("");
00111     sql << "DELETE FROM file_row WHERE file_id IN("
00112    << idList
00113    << ")";
00114     myHelper_.executeSql( sql );
00115   }
00116 
00117   sql.str("");
00118   sql << "DELETE FROM file WHERE pool_id = "
00119       << id;
00120   myHelper_.executeSql( sql );
00121   
00122   sql.str("");
00123   sql << "DELETE FROM unit WHERE pool_id = "
00124       << id;
00125   myHelper_.executeSql( sql );
00126   
00127   sql.str( "" );
00128   sql << "DELETE FROM kontext WHERE pool_id = "
00129       << id;
00130   myHelper_.executeSql( sql );
00131   
00132   sql.str( "" );
00133   sql << "DELETE FROM search WHERE pool_id = "
00134       << id;
00135   myHelper_.executeSql( sql );
00136   
00137   sql.str( "" );
00138   sql << "SELECT entry_id FROM entry WHERE pool_id = "
00139       << id;
00140   ids.str("");
00141   myHelper_.getValueStream( sql, ids, ", " );
00142   idList = ids.str();
00143   if( !idList.empty() ) {
00144     sql.str("");
00145     sql << "DELETE FROM attribut WHERE entry_id IN("
00146    << idList
00147    << ")";
00148     myHelper_.executeSql( sql );
00149   }
00150   sql.str( "" );
00151   sql << "DELETE FROM entry WHERE pool_id = "
00152       << id;
00153   myHelper_.executeSql( sql );
00154 
00155   return;
00156 }
00157 
00158 
00159   
00160 int
00161 psfa::DbWriteDriverMySql::index( const std::string poolName, 
00162              CheckData& check )
00163 {
00164   using std::string;
00165   typedef std::vector< string > sVec;
00166 
00167   UnitParser up( poolName );
00168   std::vector< IndexData_SP > index;
00169   std::ostringstream sql;
00170 
00171   sql.str("");
00172   sql << "SELECT pool_id FROM pool WHERE p_name = '"
00173       << poolName
00174       << "'";
00175   int poolId = myHelper_.getSingleValueInt( sql );
00176   Config* conf = Config::getConfig();
00177   string path = conf->getConfigValue( poolName, "root" );
00178   sVec errorFiles;
00179  
00180   if( check.poolIndex ) {
00181     sVec files = check.poolIndexList[ poolName ];
00182     up.parse( files, index, errorFiles );
00183     insertEntries( poolId, index );
00184     if( !errorFiles.empty() ) {
00185       removeFiles( poolId, errorFiles );
00186       errorFiles.clear();
00187     }
00188     index.clear();
00189   }
00190   if( check.poolInsert ) {
00191     sVec files = check.poolInsertList[ poolName ];
00192     up.parse( files, index, errorFiles );
00193     insertFiles( poolId, files, path );
00194     insertEntries( poolId, index );
00195     if( !errorFiles.empty() ) {
00196       removeFiles( poolId, errorFiles );
00197       errorFiles.clear();
00198     }
00199     index.clear();
00200   }
00201   if( check.poolUpdate ) {
00202     sVec files = check.poolUpdateList[ poolName ];
00203     up.parse( files, index, errorFiles );
00204     removeFiles( poolId, files );
00205     insertFiles( poolId, files, path );
00206     insertEntries( poolId, index );
00207     if( !errorFiles.empty() ) {
00208       removeFiles( poolId, errorFiles );
00209       errorFiles.clear();
00210     }
00211     index.clear();
00212   }
00213   if( check.poolRemove ) {
00214     sVec files = check.poolRemoveList[ poolName ];
00215     removeFiles( poolId, files );
00216   }
00217 
00218   sql.str("");
00219   sql << "SELECT COUNT( entry_id ) FROM entry WHERE pool_id = '"
00220       << poolId
00221       << "'";
00222   return myHelper_.getSingleValueInt( sql );
00223 }
00224 
00225 
00226 
00227 bool
00228 psfa::DbWriteDriverMySql::existPool( const std::string poolName ) 
00229 {
00230   std::ostringstream sql;
00231   sql << "SELECT pool_id FROM pool WHERE p_name = '"
00232       << poolName
00233       << "'";
00234   int id = myHelper_.getSingleValueInt( sql );
00235   if( id != 0 ) {
00236     return true;
00237   }
00238   return false;
00239 }
00240 
00241 
00242 
00243 void
00244 psfa::DbWriteDriverMySql::check( CheckData& check ) 
00245 {
00246   using std::string;
00247   using std::equal;
00248   using std::sort;
00249   using std::set_difference;
00250   using psfahelper::splitString;
00251   using psfahelper::getFilePaths;
00252   using psfahelper::getMd5Sum;
00253     
00254   typedef std::vector< string > sVec;
00255   typedef sVec::size_type vSize;
00256   
00257   Config* conf = Config::getConfig();
00258   std::ostringstream sql;
00259 
00260   string pools = conf->getConfigValue( "psfa", "pools" );
00261   sVec inConfig;
00262   splitString( pools, inConfig );
00263   sql << "SELECT p_name FROM pool";
00264   sVec inDb;
00265   myHelper_.getValueVector( sql, inDb );
00266 
00267   sort( inConfig.begin(), inConfig.end() );
00268   sort( inDb.begin(), inDb.end() );
00269   bool isEqual = true;
00270   if( inConfig.size() == inDb.size() ) {
00271     isEqual = equal( inConfig.begin(), inConfig.end(), inDb.begin() );
00272   }
00273   else {
00274     isEqual = false;
00275   }
00276   if( !isEqual ) {
00277     check.init = true;
00278     sVec diff;
00279     vSize s = inConfig.size() + inDb.size();
00280     diff.reserve( s );
00281     // in der Db aber nicht in der Config
00282     sVec::iterator diffEnd = set_difference( inDb.begin(),
00283                     inDb.end(),
00284                     inConfig.begin(),
00285                     inConfig.end(),
00286                     diff.begin()
00287                     );
00288     if( diff.begin() != diffEnd ) {
00289       check.poolDel = true;
00290       check.poolDelList.reserve( diffEnd - diff.begin() );
00291       check.poolDelList.insert( check.poolDelList.begin(),
00292                 diff.begin(),
00293                 diffEnd
00294                 );
00295     }
00296   }
00297 
00298   sVec::iterator p;
00299   sVec::iterator pEnd = inConfig.end();
00300   // für jeden Pool in der Config
00301   for( p = inConfig.begin(); p != pEnd; ++p ) {
00302     if( !existPool( *p ) ) {
00303       continue;
00304     }
00305     sql.str("");
00306     sql << "SELECT pool_id FROM pool WHERE p_name = '"
00307    << *p
00308    << "'";
00309     int poolId = myHelper_.getSingleValueInt( sql );
00310       
00311     // Searchs und Kontexts
00312     if( !check.init ) {
00313       // Searchs
00314       string tmp = conf->getConfigValue( *p, "tags" );
00315       sVec config;
00316       splitString( tmp, config );
00317       sql.str("");
00318       sql << "SELECT s_name FROM search WHERE pool_id = '"
00319      << poolId
00320      << "'";
00321       sVec db;
00322       myHelper_.getValueVector( sql, db );
00323       sort( config.begin(), config.end() );
00324       sort( db.begin(), db.end() );
00325       isEqual = true;
00326       if( config.size() == db.size() ) {
00327    isEqual = equal( config.begin(), config.end(), db.begin() );
00328       }
00329       else {
00330    isEqual = false;
00331       }
00332       if( !isEqual ) {
00333    check.init = true;
00334       }
00335       // Kontexts
00336       if( !check.init ) {
00337    tmp = conf->getConfigValue( *p, "kontexts" );
00338    config.clear();
00339    splitString( tmp, config );
00340    sql.str("");
00341    sql << "SELECT k_name FROM kontext WHERE pool_id = '"
00342        << poolId
00343        << "'";
00344    db.clear();
00345    myHelper_.getValueVector( sql, db );
00346    sort( config.begin(), config.end() );
00347    sort( db.begin(), db.end() );
00348    isEqual = true;
00349    if( config.size() == db.size() ) {
00350      isEqual = equal( config.begin(), config.end(), db.begin() );
00351    }
00352    else {
00353      isEqual = false;
00354    }
00355    if( !isEqual ) {
00356      check.init = true;
00357    }
00358       }
00359     }
00360     // Dateien
00361     sVec insertList;
00362     sVec updateList;
00363     sVec removeList;
00364     string path = conf->getConfigValue( *p, "root" );
00365     sVec files;
00366     getFilePaths( path, "*.xml", files );
00367     sVec::iterator i;
00368     sVec::iterator iEnd = files.end();
00369     for( i = files.begin(); i != iEnd; ++i ) {
00370       sql.str("");
00371       sql << "SELECT f_md5 FROM file WHERE f_name = '"
00372      << *i
00373      << "' AND pool_id = '"
00374      << poolId
00375      << "'";
00376       string md5Db = myHelper_.getSingleValueString( sql );
00377       if( md5Db == "" ) {
00378    // Neue Datei im FS
00379    check.poolInsert = true;
00380    insertList.push_back( *i );
00381    continue;
00382       }
00383       string md5File = getMd5Sum( path, *i );
00384       if( md5Db != md5File ) {
00385    // Geänderte Datei im FS
00386    check.poolUpdate = true;
00387    updateList.push_back( *i );
00388       }
00389     }
00390     sql.str("");
00391     sql << "SELECT f_name FROM file WHERE pool_id = '"
00392    << poolId
00393    << "'";
00394     inDb.clear();
00395     myHelper_.getValueVector( sql, inDb );
00396 
00397 
00398      // Anzahl der indizierten Tags
00399     sql.str("");
00400     sql << "SELECT COUNT( entry_id ) FROM entry WHERE pool_id = '"
00401    << poolId
00402    << "'";
00403     int count = myHelper_.getSingleValueInt( sql );
00404     if( count == 0 ) {
00405       check.poolIndex = true;
00406       check.poolIndexList.insert( std::make_pair( *p, inDb ) );
00407     }
00408     check.indexCountList.insert( std::make_pair( *p, count ) );
00409 
00410     sort( files.begin(), files.end() );
00411     sort( inDb.begin(), inDb.end() );
00412     isEqual = true;
00413     if( files.size() == inDb.size() ) {
00414       isEqual = equal( files.begin(), files.end(), inDb.begin() );
00415     }
00416     else {
00417       isEqual = false;
00418     }
00419     
00420     if( !isEqual ) {
00421       sVec diff;
00422       vSize s = files.size() + inDb.size();
00423       diff.reserve( s );
00424       sVec::iterator diffEnd = set_difference( inDb.begin(),
00425                       inDb.end(),
00426                       files.begin(),
00427                       files.end(),
00428                       diff.begin()
00429                       );
00430       if( diff.begin() != diffEnd ) {
00431    // Dateien in der DB aber nicht mehr im FS
00432    check.poolRemove = true;
00433    removeList.reserve( diffEnd - diff.begin() );
00434    removeList.insert( removeList.begin(),
00435             diff.begin(),
00436             diffEnd
00437             );
00438       }
00439     }
00440     check.poolInsertList.insert( std::make_pair( *p, insertList ) );
00441     check.poolUpdateList.insert( std::make_pair( *p, updateList ) );
00442     check.poolRemoveList.insert( std::make_pair( *p, removeList ) );
00443   }
00444   return;
00445 }
00446   
00447 
00448 
00449 
00450 bool
00451 psfa::DbWriteDriverMySql::success()
00452 {
00453   return success_;
00454 }
00455 
00456 
00457 
00458 
00459 int
00460 psfa::DbWriteDriverMySql::insertPool( const std::string poolName ) 
00461 {
00462   std::ostringstream sql;
00463   int id = myHelper_.getNextId( "pool", "pool_id" );
00464   sql << "INSERT INTO pool VALUES("
00465       << "'" << id << "',"
00466       << "'" << poolName << "'"
00467       << ")";
00468   myHelper_.executeSql( sql );
00469   return id;
00470 }
00471 
00472 
00473 
00474 void
00475 psfa::DbWriteDriverMySql::insertKontext( const std::string pool,
00476                 const int poolId ) 
00477 {
00478   typedef std::vector< std::string > sVec;
00479   using psfahelper::splitString;
00480 
00481   Config* conf = Config::getConfig();
00482   std::string k = conf->getConfigValue( pool, "kontexts" );
00483   sVec kontexts;
00484   splitString( k, kontexts );
00485   sVec::iterator i;
00486   sVec::iterator iEnd = kontexts.end();
00487   for( i = kontexts.begin(); i != iEnd; ++i ) {
00488     std::ostringstream sql;
00489     int id = myHelper_.getNextId( "kontext", "kontext_id" );
00490     sql << "INSERT INTO kontext VALUES("
00491    << "'" << id << "',"
00492    << "'" << poolId << "',"
00493    << "'" << *i << "'"
00494    << ")";
00495     myHelper_.executeSql( sql );
00496   }
00497   return;
00498 }
00499 
00500 
00501 
00502 void
00503 psfa::DbWriteDriverMySql::insertSearch( const std::string pool, 
00504                const int poolId )
00505 {
00506   using psfahelper::splitString;
00507   typedef std::vector< std::string > sVec;
00508 
00509   Config* conf = Config::getConfig();
00510   std::string t = conf->getConfigValue( pool, "tags" );
00511   sVec tags;
00512   splitString( t, tags );
00513   sVec::iterator i;
00514   sVec::iterator iEnd = tags.end();
00515   for( i = tags.begin(); i != iEnd; ++i ) {
00516     std::ostringstream sql;
00517     int id = myHelper_.getNextId( "search", "search_id" );
00518     sql << "INSERT INTO search VALUES("
00519    << "'" << id << "',"
00520    << "'" << poolId << "',"
00521    << "'" << *i << "'"
00522    << ")";
00523     myHelper_.executeSql( sql );
00524   }
00525   return;
00526 }
00527 
00528 
00529 
00530 void
00531 psfa::DbWriteDriverMySql::insertFiles( const int poolId,
00532                    const std::vector< std::string >& files,
00533                    const std::string path )
00534 {
00535   using std::string;
00536   using psfahelper::getMd5Sum;
00537   typedef std::vector< string > sVec;
00538 
00539   sVec::const_iterator i;
00540   sVec::const_iterator iEnd = files.end();
00541   for( i = files.begin(); i != iEnd; ++i ) {
00542     std::ostringstream sql;
00543     int id = myHelper_.getNextId( "file", "file_id" );
00544     int dos = 0;
00545     bool d = insertFileRows( id, path, *i );
00546     if( d ) {
00547       dos = 1;
00548     }
00549     string md5 = getMd5Sum( path, *i );
00550     sql << "INSERT INTO file VALUES("
00551    << "'" << id << "',"
00552    << "'" << poolId << "',"
00553    << "'" << *i << "',"
00554    << "'" << md5 << "',"
00555    << "'" << dos << "'"
00556    << ")";
00557     myHelper_.executeSql( sql );
00558   }
00559   return;
00560 }
00561 
00562 
00563 
00564 bool
00565 psfa::DbWriteDriverMySql::insertFileRows( const int fileId,
00566                  const std::string path,
00567                  const std::string fileName )
00568 {
00569   std::string filePath = path + "/" + fileName;
00570   int size = psfahelper::getFileSize( filePath );
00571 
00572   std::ifstream file( filePath.c_str() );
00573   std::istreambuf_iterator<char> in( file );
00574   std::istreambuf_iterator<char> eof;
00575   std::vector<char> fileData;
00576   fileData.reserve( size );
00577   std::copy( in, eof, std::back_inserter( fileData ) );
00578     
00579   std::vector<char>::iterator f    = fileData.begin();
00580   std::vector<char>::iterator fEnd = fileData.end();
00581   std::vector<char>::iterator g    = fileData.begin();
00582   char pattern  = 10; // Line Feed
00583 
00584   bool dos = false;
00585   f = std::find( g, fEnd, pattern );
00586   --f;
00587   if( *f == 13 ) {
00588     dos = true;
00589   }
00590   std::ostringstream sql;
00591   while( f != fEnd ) {
00592     f = std::find( g, fEnd, pattern );
00593     // Die zweite Bedingung sichert gegen eine Datei ohne abschließendes
00594     // Newline ab. Dann muß nämlich noch eine Zeile verarbeitet werden, ...
00595     if( f == fEnd && (f - g) == 0 ) {
00596       continue;
00597     }
00598     int laenge = f - g + 1;
00599     // ... die aber um ein Byte kürzer ist.
00600     if( f == fEnd ) {
00601       --laenge;
00602     }
00603     g = f;
00604     ++g;
00605     if( dos ) {
00606       --laenge;
00607     }
00608     int row_id = myHelper_.getNextId( "file_row", "__id" );
00609     sql.str("");
00610     sql << "INSERT INTO file_row VALUES("
00611    << "'" << row_id << "',"
00612    << "'" << fileId << "',"
00613    << "'" << laenge << "'"
00614    << ")";
00615     myHelper_.executeSql( sql );
00616   }
00617   return dos;
00618 }
00619 
00620     
00621 
00622 int
00623 psfa::DbWriteDriverMySql::insertUnit( const std::string unit, 
00624                   const int poolId,
00625                   const int file_id ) 
00626 {
00627   std::ostringstream sql;
00628 
00629   int unit_id = myHelper_.getNextId( "unit", "unit_id" );
00630   sql << "INSERT INTO unit VALUES("
00631       << "'" << unit_id << "',"
00632       << "'" << poolId << "',"
00633       << "'" << file_id << "',"
00634       << "'" << unit << "'"
00635       << ")";
00636   myHelper_.executeSql( sql );
00637   return unit_id;
00638 }
00639 
00640 
00641 
00642 void
00643 psfa::DbWriteDriverMySql::insertEntries( const int poolId,
00644                 const std::vector< IndexData_SP >& index ) 
00645 {
00646   using std::string;
00647   typedef std::map< string, int > sMap;
00648   
00649   int search_id  = 0;
00650   int kontext_id = 0;
00651   int unit_id    = 0;
00652   int file_id    = 0;
00653   
00654   sMap idMap;
00655   sMap::iterator id;
00656 
00657   std::ostringstream sql;
00658   std::vector< IndexData_SP >::const_iterator i;
00659   std::vector< IndexData_SP >::const_iterator iEnd   = index.end();
00660   for( i = index.begin(); i < iEnd; ++i ) {
00661     IndexData_SP d = *i;
00662     int entry_id = myHelper_.getNextId( "entry", "entry_id" );
00663 
00664     id = idMap.find( d->tag );
00665     if( id == idMap.end() ) {
00666       sql.str("");
00667       sql << "SELECT search_id FROM search WHERE s_name = '"
00668      << d->tag
00669      << "'";
00670       search_id = myHelper_.getSingleValueInt( sql );
00671       sMap::value_type v( d->tag, search_id );
00672       idMap.insert( v );
00673     }
00674     else {
00675       search_id = id->second;
00676     }
00677     
00678     id = idMap.find( d->kontext );
00679     if( id == idMap.end() ) {
00680       sql.str("");
00681       sql << "SELECT kontext_id FROM kontext WHERE k_name = '"
00682      << d->kontext
00683      << "'";
00684       kontext_id = myHelper_.getSingleValueInt( sql );
00685       sMap::value_type v( d->kontext, kontext_id );
00686       idMap.insert( v );
00687     }
00688     else {
00689       kontext_id = id->second;
00690     }
00691     
00692     id = idMap.find( d->unit );
00693     if( id == idMap.end() ) {
00694       id = idMap.find( d->file );
00695       if( id == idMap.end() ) {
00696    sql.str("");
00697    sql << "SELECT file_id FROM file WHERE f_name = '"
00698        << d->file
00699        << "'";
00700    file_id = myHelper_.getSingleValueInt( sql );
00701    sMap::value_type v( d->file, file_id );
00702    idMap.insert( v );
00703       }
00704       else {
00705    file_id = id->second;
00706       }
00707       unit_id = insertUnit( d->unit, poolId, file_id );
00708       sMap::value_type v( d->unit, unit_id );
00709       idMap.insert( v );
00710     }
00711     else {
00712       unit_id = id->second;
00713     }
00714 
00715     int pstart = myHelper_.calculateFilePosition( d->lineStart,
00716                     d->columnStart,
00717                     file_id );
00718     int pstop = myHelper_.calculateFilePosition( d->lineStop,
00719                    d->columnStop,
00720                    file_id );
00721     sql.str("");
00722     sql << "INSERT into entry VALUES("
00723    << "'" << entry_id << "', "
00724    << "'" << poolId << "', "
00725    << "'" << search_id << "', "
00726    << "'" << kontext_id << "', "
00727    << "'" << unit_id << "', "
00728    << "'" << file_id << "', "
00729    << "'" << d->content << "', "
00730    << "'" << d->lineStart << "', "
00731    << "'" << d->columnStart << "', "
00732    << "'" << d->lineStop << "', "
00733    << "'" << d->columnStop << "',"
00734    << "'" << pstart << "', "
00735    << "'" << pstop << "'"
00736    << ")";
00737     myHelper_.executeSql( sql );
00738 
00739     AttMap atts = d->attributes;
00740     AttMap::iterator a;
00741     AttMap::iterator aEnd = atts.end();
00742     if( !atts.empty() ) {
00743       int att_id = 0;
00744       for( a = atts.begin(); a != aEnd; ++a ) {
00745    att_id = myHelper_.getNextId( "attribut", "__id" );
00746    sql.str("");
00747    sql << "INSERT into attribut VALUES("
00748        << "'" << att_id << "', "
00749        << "'" << entry_id << "', "
00750        << "'" << a->first << "', "
00751        << "'" << a->second << "'"
00752        << ")";
00753    myHelper_.executeSql( sql );
00754       }
00755     }
00756   }
00757   return;
00758 }
00759 
00760 void
00761 psfa::DbWriteDriverMySql::removeFiles( const int poolId,
00762                    const std::vector< std::string >& files )
00763 {
00764   using std::string;
00765   using std::ostringstream;
00766   using std::vector;
00767   using std::ostream_iterator;
00768   typedef std::vector< string > sVec;
00769 
00770   ostringstream fileNames;
00771   std::copy( files.begin(),
00772         files.end(),
00773         ostream_iterator<string>( fileNames, "', '")
00774         );
00775 
00776   std::ostringstream sql;
00777   sql << "SELECT file_id FROM file WHERE f_name IN('"
00778       << fileNames.str()
00779       << "') AND pool_id = "
00780       << poolId;
00781   ostringstream fileIds;
00782   myHelper_.getValueStream( sql, fileIds, "', '" );
00783    
00784   sql.str("");
00785   sql << "SELECT unit_id FROM unit WHERE file_id IN('"
00786       << fileIds.str()
00787       << "') AND pool_id = "
00788       << poolId;
00789   ostringstream unitIds;
00790   myHelper_.getValueStream( sql, unitIds, "', '" );
00791 
00792   sql.str("");
00793   sql << "SELECT entry_id FROM entry WHERE unit_id IN('"
00794       << unitIds.str()
00795       << "') AND pool_id = "
00796       << poolId;
00797   ostringstream entryIds;
00798   myHelper_.getValueStream( sql, entryIds, "', '" );
00799 
00800   sql.str( "" );
00801   sql << "DELETE FROM attribut WHERE entry_id IN('"
00802       << entryIds.str()
00803       << "')";
00804   myHelper_.executeSql( sql );
00805 
00806   sql.str( "" );
00807   sql << "DELETE FROM entry WHERE entry_id IN('"
00808       << entryIds.str()
00809       << "')";
00810   myHelper_.executeSql( sql );
00811   
00812   sql.str( "" );
00813   sql << "DELETE FROM unit WHERE unit_id IN('"
00814       << unitIds.str()
00815       << "')";
00816   myHelper_.executeSql( sql );
00817   
00818   sql.str( "" );
00819   sql << "DELETE FROM file_row WHERE file_id IN('"
00820       << fileIds.str()
00821       << "')";
00822   myHelper_.executeSql( sql );
00823 
00824   sql.str( "" );
00825   sql << "DELETE FROM file WHERE file_id IN('"
00826       << fileIds.str()
00827       << "')";
00828   myHelper_.executeSql( sql );
00829 
00830   return;
00831 }

Erzeugt am Mon Jul 12 11:45:04 2004 für PSFA von doxygen 1.3.4