Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:22:00

0001 /* 
0002    This file is part of libodbc++.
0003    
0004    Copyright (C) 1999-2000 Manush Dodunekov <manush@stendahls.net>
0005    
0006    This library is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU Library General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010    
0011    This library is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014    Library General Public License for more details.
0015    
0016    You should have received a copy of the GNU Library General Public License
0017    along with this library; see the file COPYING.  If not, write to
0018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0019    Boston, MA 02111-1307, USA.
0020 */
0021 
0022 #ifndef __ODBCXX_DRIVERMANAGER_H
0023 #define __ODBCXX_DRIVERMANAGER_H
0024 
0025 #include <RDBC/odbc++/setup.h>
0026 
0027 #include <RDBC/odbc++/types.h>
0028 
0029 /** The namespace where all <b>libodbc++</b> classes reside */
0030 namespace odbc {
0031 
0032   class Connection;
0033   
0034   /** An ODBC Driver with it's information.
0035    */
0036   class ODBCXX_EXPORT Driver {
0037   private:
0038     ODBCXX_STRING description_;
0039     std::vector<ODBCXX_STRING> attributes_;
0040 
0041     Driver(const Driver&); //forbid
0042     Driver& operator=(const Driver&); //forbid
0043 
0044   public:
0045     /** Constructor */
0046     Driver(const ODBCXX_STRING& description,
0047        const std::vector<ODBCXX_STRING>& attributes)
0048       :description_(description), attributes_(attributes) {}
0049 
0050     /** Destructor */
0051     virtual ~Driver() {}
0052     
0053     /** Return a description of the driver */
0054     const ODBCXX_STRING& getDescription() const {
0055       return description_;
0056     }
0057 
0058     /** Return a list of keys that can appear in a connect string using this driver */
0059     const std::vector<ODBCXX_STRING>& getAttributes() const {
0060       return attributes_;
0061     }
0062   };
0063   
0064   /** A list of Drivers. Actually an STL vector */
0065   typedef CleanVector<Driver*> DriverList;
0066   
0067 
0068   /** A Data Source */
0069   class ODBCXX_EXPORT DataSource {
0070   private:
0071     ODBCXX_STRING name_;
0072     ODBCXX_STRING description_;
0073 
0074   public:
0075     /** Constructor */
0076     DataSource(const ODBCXX_STRING& name, const ODBCXX_STRING& description)
0077       :name_(name), description_(description) {}
0078     
0079     /** Destructor */
0080     virtual ~DataSource() {}
0081 
0082     /** Return the name of the data source */
0083     const ODBCXX_STRING& getName() const {
0084       return name_;
0085     }
0086     
0087     /** Return the description (if any) of the datasource */
0088     const ODBCXX_STRING& getDescription() const {
0089       return description_;
0090     }
0091   };
0092   
0093   /** A list of datasources. Behaves like an std::vector */
0094   typedef CleanVector<DataSource*> DataSourceList;
0095 
0096 
0097   /** The DriverManager.
0098    */
0099   class ODBCXX_EXPORT DriverManager {
0100   private:
0101     static SQLHENV henv_;
0102     static ErrorHandler* eh_;
0103     static int loginTimeout_;
0104     
0105     static void _checkInit();
0106     static Connection* _createConnection();
0107 
0108     // forbid
0109     DriverManager();
0110 
0111   public:
0112     
0113     /** Opens a connection by it's DSN, a username and a password */
0114     static Connection* getConnection(const ODBCXX_STRING& dsn,
0115                      const ODBCXX_STRING& user,
0116                      const ODBCXX_STRING& password);
0117     
0118     /** Opens a connection using an ODBC connect string. 
0119      * @param connectString Usually something like <tt>"DSN=db;uid=user;pwd=password"</tt>
0120      */
0121     static Connection* getConnection(const ODBCXX_STRING& connectString);
0122     
0123     /** Gets the current login timeout in seconds.
0124      * @return The current login timeout in seconds, or 0 if disabled.
0125      */
0126     static int getLoginTimeout();
0127 
0128     /** Sets the login timeout in seconds
0129      * @param seconds The number of seconds to wait for a connection
0130      * to open. Set to 0 to disable.
0131      */
0132     static void setLoginTimeout(int seconds);
0133 
0134     /** Fetch a list of all available data sources
0135      */
0136     static DataSourceList* getDataSources();
0137 
0138     /** Fetch a list of the available drivers 
0139      */
0140     static DriverList* getDrivers();
0141 
0142     /** Should be called before an application is to exit
0143      * and after all connections have been closed.
0144      */
0145     static void shutdown();
0146   };
0147 
0148 
0149 
0150 };
0151 
0152 
0153 #endif // __ODBCXX_DRIVERMANAGER_H