libodbc++  0.2.5
drivermanager.h
1 /*
2  This file is part of libodbc++.
3 
4  Copyright (C) 1999-2000 Manush Dodunekov <manush@stendahls.net>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING. If not, write to
18  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  Boston, MA 02111-1307, USA.
20 */
21 
22 #ifndef __ODBCXX_DRIVERMANAGER_H
23 #define __ODBCXX_DRIVERMANAGER_H
24 
25 #include <memory>
26 
27 #include <odbc++/setup.h>
28 #include <odbc++/types.h>
29 
31 namespace odbc {
32 
33  class Connection;
34  class ErrorHandler;
35 
38  class ODBCXX_EXPORT Driver {
39  private:
40  ODBCXX_STRING description_;
41  std::vector<ODBCXX_STRING> attributes_;
42 
43  Driver(const Driver&); //forbid
44  Driver& operator=(const Driver&); //forbid
45 
46  public:
48  Driver(const ODBCXX_STRING& description,
49  const std::vector<ODBCXX_STRING>& attributes)
50  :description_(description), attributes_(attributes) {}
51 
53  virtual ~Driver() {}
54 
56  const ODBCXX_STRING& getDescription() const {
57  return description_;
58  }
59 
61  const std::vector<ODBCXX_STRING>& getAttributes() const {
62  return attributes_;
63  }
64  };
65 
67  typedef CleanVector<Driver*> DriverList;
68 
69 
71  class ODBCXX_EXPORT DataSource {
72  private:
73  ODBCXX_STRING name_;
74  ODBCXX_STRING description_;
75 
76  public:
78  DataSource(const ODBCXX_STRING& name, const ODBCXX_STRING& description)
79  :name_(name), description_(description) {}
80 
82  virtual ~DataSource() {}
83 
85  const ODBCXX_STRING& getName() const {
86  return name_;
87  }
88 
90  const ODBCXX_STRING& getDescription() const {
91  return description_;
92  }
93  };
94 
96  typedef CleanVector<DataSource*> DataSourceList;
97 
98 
101  class ODBCXX_EXPORT DriverManager {
102  private:
103  static SQLHENV henv_;
104  static std::auto_ptr<ErrorHandler> eh_;
105  static int loginTimeout_;
106  static SQLUSMALLINT driverCompletion_;
107 
108  static void _checkInit();
109  static Connection* _createConnection();
110 
111  // forbid
112  DriverManager();
113 
114  public:
115 
117  static Connection* getConnection(const ODBCXX_STRING& dsn,
118  const ODBCXX_STRING& user,
119  const ODBCXX_STRING& password);
120 
124  static Connection* getConnection(const ODBCXX_STRING& connectString);
125 
129  static int getLoginTimeout();
130 
135  static void setLoginTimeout(int seconds);
136  // -------------------------------------------
142  static void setDriverCompletion(SQLUSMALLINT drvcmpl);
143  static SQLUSMALLINT getDriverCompletion(void);
144 
147  static DataSourceList* getDataSources();
148 
151  static DriverList* getDrivers();
152 
156  static void shutdown();
157  };
158 
159 
160 
161 } // namespace odbc
162 
163 
164 #endif // __ODBCXX_DRIVERMANAGER_H

Go back to the libodbc++ homepage