CMS 3D CMS Logo

ConnectionManager.cc
Go to the documentation of this file.
1 
2 #include <cstring>
3 #include <cstdio>
4 
7 #include <cctype>
8 
9 ConnectionManager::ConnectionManager() : env(nullptr), conn(nullptr) {}
10 
11 static const std::string keyFile("/nfshome0/hcalsw/.ReadOMDSKey");
12 
13 static void clean(char* s) {
14  for (int x = strlen(s) - 1; x >= 0; x--) {
15  if (isspace(s[x]))
16  s[x] = 0;
17  }
18 }
19 
21  if (env != nullptr)
22  return true;
23  std::string username, password, database;
24 
25  char s[100];
26  FILE* f = fopen(keyFile.c_str(), "r");
27  s[0] = 0;
28  fgets(s, 100, f);
29  clean(s);
30  username = s;
31  s[0] = 0;
32  fgets(s, 100, f);
33  clean(s);
34  password = s;
35  s[0] = 0;
36  fgets(s, 100, f);
37  clean(s);
38  database = s;
39  fclose(f);
40 
41  // printf("'%s' '%s' '%s'\n",username.c_str(),password.c_str(),database.c_str());
42  try {
43  env = oracle::occi::Environment::createEnvironment(oracle::occi::Environment::DEFAULT);
44  conn = env->createConnection(username, password, database);
45  } catch (...) {
46  return false;
47  }
48  return true;
49 }
50 oracle::occi::Statement* ConnectionManager::getStatement(const std::string& query) {
51  if (env == nullptr)
52  return nullptr;
53  return conn->createStatement(query);
54 }
56  if (env == nullptr)
57  return;
58  env->terminateConnection(conn);
59  oracle::occi::Environment::terminateEnvironment(env);
60  env = nullptr;
61  conn = nullptr;
62 }
oracle::occi::Connection * conn
oracle::occi::Statement * getStatement(const std::string &query)
Definition: query.py:1
static void clean(char *s)
double f[11][100]
static const std::string keyFile("/nfshome0/hcalsw/.ReadOMDSKey")
conn
Definition: getInfo.py:9
float x
oracle::occi::Environment * env