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

DbDriverMySqlHelper.hpp

gehe zur Dokumentation dieser Datei
00001 #ifndef BOERN_PSFA_MYSQL_HELPER_HPP
00002 #define BOERN_PSFA_MYSQL_HELPER_HPP
00003 // Copyright (C) 2004 Bernhard Assmann <bernie@tuxomania.net>
00004 //  
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or
00008 // (at your option) any later version.
00009 //  
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //  
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 //  
00019 
00020 #include <string>
00021 #include <iostream>
00022 #include <iosfwd>
00023 #include <mysqlcppapi/mysqlcppapi.h>
00024 
00025 
00026 namespace psfa 
00027 {
00028 
00037   class DbDriverMySqlHelper 
00038   {
00039   public:
00040 
00049     bool
00050     connect();
00051 
00057     bool
00058     disconnect();  
00059 
00069     mysqlcppapi::Result_NoData
00070     executeSql( const std::ostringstream& sql );
00071 
00078     void
00079     queryDb( const std::ostringstream& sql,
00080         mysqlcppapi::Result_Store& store );
00081     
00090     int
00091     getNextId( const std::string table, const std::string idField );
00092   
00100     const std::string
00101     getSingleValueString( const std::ostringstream& sql );
00102 
00113     int
00114     calculateFilePosition( int line, int column, int fileId );
00115     
00123     int
00124     getSingleValueInt( const std::ostringstream& sql );
00125   
00132     template< class T >
00133     void
00134     getValueVector( const std::ostringstream& sql, T& vec )
00135     {
00136       try {
00137    mysqlcppapi::Query query = con_.create_Query();
00138    query << sql.str();
00139    mysqlcppapi::Result_Store res = query.store();
00140    if( res.size() != 0 ) {
00141      vec.reserve( res.size() );
00142      mysqlcppapi::Result_Store::iterator i;
00143      mysqlcppapi::Result_Store::iterator iEnd = res.end();
00144      for ( i = res.begin(); i != iEnd; ++i) {
00145        mysqlcppapi::Row row = *i;
00146        vec.push_back( row[0] );
00147      }
00148    }
00149       }
00150       catch(mysqlcppapi::ex_BadQuery& er) {
00151    return;
00152       }
00153       catch(mysqlcppapi::ex_BadConversion& er) {
00154    return;
00155       }
00156       return;
00157     }
00158 
00166     template< class T >
00167     void
00168     getValueStream( const std::ostringstream& sql,
00169           T& outStream,
00170           const std::string delim )
00171     {
00172       try {
00173    mysqlcppapi::Query query = con_.create_Query();
00174    query << sql.str();
00175    mysqlcppapi::Result_Store res = query.store();
00176    if( res.size() != 0 ) {
00177      mysqlcppapi::Result_Store::iterator i    = res.begin();
00178      mysqlcppapi::Result_Store::iterator iEnd = res.end();
00179      for ( ; i != iEnd; ++i) {
00180        mysqlcppapi::Row row = *i;
00181        if( (i + 1) == iEnd ) {
00182          outStream << row[0];
00183          continue;
00184        }
00185        outStream << row[0] << delim;
00186      }
00187    }
00188       }
00189       catch(mysqlcppapi::ex_BadQuery& er) {
00190    return;
00191       }
00192       catch(mysqlcppapi::ex_BadConversion& er) {
00193    return;
00194       }
00195       return;
00196     }
00197     
00198   private:
00199 
00200     mysqlcppapi::Connection con_; 
00202     static int fileId_;    
00204     static int overhead_;     
00206     static std::vector< int > lengths_; 
00208   };
00209 }
00210 #endif

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