oracle/factory.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2007 Maciej Sobczak, Stephen Hutton
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 //
7 
8 #define SOCI_ORACLE_SOURCE
9 #include "soci-oracle.h"
10 #include <connection-parameters.h>
11 #include <backend-loader.h>
12 #include <cctype>
13 #include <cstdio>
14 #include <cstring>
15 #include <ctime>
16 #include <sstream>
17 
18 #ifdef _MSC_VER
19 #pragma warning(disable:4355)
20 #endif
21 
22 using namespace soci;
23 using namespace soci::details;
24 
25 // retrieves service name, user name and password from the
26 // uniform connect string
27 void chop_connect_string(std::string const & connectString,
28  std::string & serviceName, std::string & userName,
29  std::string & password, int & mode, bool & decimals_as_strings)
30 {
31  // transform the connect string into a sequence of tokens
32  // separated by spaces, this is done by replacing each first '='
33  // in each original token with space
34  // note: each original token is a key=value pair and only the first
35  // '=' there is replaced with space, so that potential '=' signs
36  // in the value part are left intact
37 
38  std::string tmp;
39  bool in_value = false;
40  for (std::string::const_iterator i = connectString.begin(),
41  end = connectString.end(); i != end; ++i)
42  {
43  if (*i == '=' && in_value == false)
44  {
45  // this is the first '=' in the key=value pair
46  tmp += ' ';
47  in_value = true;
48  }
49  else
50  {
51  tmp += *i;
52  if (*i == ' ' || *i == '\t')
53  {
54  // follow with the next key=value pair
55  in_value = false;
56  }
57  }
58  }
59 
60  serviceName.clear();
61  userName.clear();
62  password.clear();
63  mode = OCI_DEFAULT;
64  decimals_as_strings = false;
65 
66  std::istringstream iss(tmp);
67  std::string key, value;
68  while (iss >> key >> value)
69  {
70  if (key == "service")
71  {
72  serviceName = value;
73  }
74  else if (key == "user")
75  {
76  userName = value;
77  }
78  else if (key == "password")
79  {
80  password = value;
81  }
82  else if (key == "mode")
83  {
84  if (value == "sysdba")
85  {
86  mode = OCI_SYSDBA;
87  }
88  else if (value == "sysoper")
89  {
90  mode = OCI_SYSOPER;
91  }
92  else if (value == "default")
93  {
94  mode = OCI_DEFAULT;
95  }
96  else
97  {
98  throw soci_error("Invalid connection mode.");
99  }
100  }
101  else if (key == "decimals_as_strings")
102  {
103  decimals_as_strings = value == "1" || value == "Y" || value == "y";
104  }
105  }
106 }
107 
108 // concrete factory for Empty concrete strategies
110  connection_parameters const & parameters) const
111 {
112  std::string serviceName, userName, password;
113  int mode;
114  bool decimals_as_strings;
115 
116  chop_connect_string(parameters.get_connect_string(), serviceName, userName, password,
117  mode, decimals_as_strings);
118 
119  return new oracle_session_backend(serviceName, userName, password,
120  mode, decimals_as_strings);
121 }
122 
124 
125 extern "C"
126 {
127 
128 // for dynamic backend loading
130 {
131  return &soci::oracle;
132 }
133 
135 {
136  soci::dynamic_backends::register_backend("oracle", soci::oracle);
137 }
138 
139 } // extern "C"
#define SOCI_ORACLE_DECL
Definition: soci-oracle.h:23
SOCI_ORACLE_DECL oracle_backend_factory const oracle
SOCI_ORACLE_DECL backend_factory const * factory_oracle()
std::string const & get_connect_string() const
SOCI_DECL void register_backend(std::string const &name, std::string const &shared_object=std::string())
virtual oracle_session_backend * make_session(connection_parameters const &parameters) const
void chop_connect_string(std::string const &connectString, std::string &serviceName, std::string &userName, std::string &password, int &mode, bool &decimals_as_strings)
std::string connectString
Definition: test-db2.cpp:21
SOCI_ORACLE_DECL void register_factory_oracle()
std::vector< ISM::CombinatorialTrainerParameters > parameters


asr_lib_ism
Author(s): Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Wed Jan 8 2020 04:02:40