odbc++/drivermanager.h

00001 /*
00002    This file is part of libodbc++.
00003 
00004    Copyright (C) 1999-2000 Manush Dodunekov <manush@stendahls.net>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.  If not, write to
00018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.
00020 */
00021 
00022 #ifndef __ODBCXX_DRIVERMANAGER_H
00023 #define __ODBCXX_DRIVERMANAGER_H
00024 
00025 #include <odbc++/setup.h>
00026 
00027 #include <odbc++/types.h>
00028 
00030 namespace odbc {
00031 
00032   class Connection;
00033   class ErrorHandler;
00034 
00037   class ODBCXX_EXPORT Driver {
00038   private:
00039     ODBCXX_STRING description_;
00040     std::vector<ODBCXX_STRING> attributes_;
00041 
00042     Driver(const Driver&); //forbid
00043     Driver& operator=(const Driver&); //forbid
00044 
00045   public:
00047     Driver(const ODBCXX_STRING& description,
00048            const std::vector<ODBCXX_STRING>& attributes)
00049       :description_(description), attributes_(attributes) {}
00050 
00052     virtual ~Driver() {}
00053 
00055     const ODBCXX_STRING& getDescription() const {
00056       return description_;
00057     }
00058 
00060     const std::vector<ODBCXX_STRING>& getAttributes() const {
00061       return attributes_;
00062     }
00063   };
00064 
00066   typedef CleanVector<Driver*> DriverList;
00067 
00068 
00070   class ODBCXX_EXPORT DataSource {
00071   private:
00072     ODBCXX_STRING name_;
00073     ODBCXX_STRING description_;
00074 
00075   public:
00077     DataSource(const ODBCXX_STRING& name, const ODBCXX_STRING& description)
00078       :name_(name), description_(description) {}
00079 
00081     virtual ~DataSource() {}
00082 
00084     const ODBCXX_STRING& getName() const {
00085       return name_;
00086     }
00087 
00089     const ODBCXX_STRING& getDescription() const {
00090       return description_;
00091     }
00092   };
00093 
00095   typedef CleanVector<DataSource*> DataSourceList;
00096 
00097 
00100   class ODBCXX_EXPORT DriverManager {
00101   private:
00102     static SQLHENV henv_;
00103     static ErrorHandler* eh_;
00104     static int loginTimeout_;
00105 
00106     static void _checkInit();
00107     static Connection* _createConnection();
00108 
00109     // forbid
00110     DriverManager();
00111 
00112   public:
00113 
00115     static Connection* getConnection(const ODBCXX_STRING& dsn,
00116                                      const ODBCXX_STRING& user,
00117                                      const ODBCXX_STRING& password);
00118 
00122     static Connection* getConnection(const ODBCXX_STRING& connectString);
00123 
00127     static int getLoginTimeout();
00128 
00133     static void setLoginTimeout(int seconds);
00134 
00137     static DataSourceList* getDataSources();
00138 
00141     static DriverList* getDrivers();
00142 
00146     static void shutdown();
00147   };
00148 
00149 
00150 
00151 } // namespace odbc
00152 
00153 
00154 #endif // __ODBCXX_DRIVERMANAGER_H

Go back to the libodbc++ homepage