10 env = oracle::occi::Environment::createEnvironment (oracle::occi::Environment::OBJECT);
11 char* c_user = ::getenv(
"CONDBON_AUTH_USER");
12 char* c_pass = ::getenv(
"CONDBON_AUTH_PASSWORD");
15 con =
env->createConnection (db_user,db_pass,
"omds");
16 std::cout <<
"Connection to Online DB is done." << std::endl;
23 env->terminateConnection (
con);
24 oracle::occi::Environment::terminateEnvironment (
env);
33 int rec_id =0, map_id =0, map_index =0;
38 tab_map=obj_name+
"_map";
39 tab_data=obj_name+
"_data";
43 tab_data=
"gains_data";
47 oracle::occi::ResultSet *rset;
49 sqlStmt =
"SELECT max(record_id) from "+tab;
50 stmt->setSQL(sqlStmt);
51 rset =
stmt->executeQuery ();
54 {rec_id= rset->getInt (1);}
61 stmt->closeResultSet (rset);
64 sqlStmt =
"INSERT INTO "+tab+
" VALUES (:1, :2, :3, :4, :5, null)";
65 stmt->setSQL(sqlStmt);
67 curtime=*localtime(&now);
69 stmt->setInt (1, record);
70 stmt->setInt (2, global_run);
87 std::map <std::string, int> month;
88 month[
"Jan"]=1; month[
"Feb"]=2; month[
"Mar"]=3; month[
"Apr"]=4;
89 month[
"May"]=5; month[
"Jun"]=6; month[
"Jul"]=7; month[
"Aug"]=8;
90 month[
"Sep"]=9; month[
"Oct"]=10; month[
"Nov"]=11; month[
"Dec"]=12;
93 st=data_time.substr(8,2);
94 int mday=atoi(st.c_str());
95 st=data_time.substr(20,4);
96 int year=atoi(st.c_str());
97 st=data_time.substr(11,2);
98 int hour=atoi(st.c_str());
99 st=data_time.substr(14,2);
100 int min=atoi(st.c_str());
101 st=data_time.substr(17,2);
102 int sec=atoi(st.c_str());
103 oracle::occi::Date edate(
env, year, mon, mday, hour, min, sec);
104 stmt->setDate(3, edate);
105 oracle::occi::Date edate_c(
env, curtime.tm_year+1900, curtime.tm_mon+1, curtime.tm_mday,
106 curtime.tm_hour, curtime.tm_min, curtime.tm_sec);
107 stmt->setDate(4, edate_c);
108 if(obj_name!=
"test")
stmt->executeUpdate ();
109 }
catch(oracle::occi::SQLException &ex)
111 std::cout<<
"Exception thrown for insertBind"<<std::endl;
112 std::cout<<
"Error number: "<< ex.getErrorCode() << std::endl;
113 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0) 114 std::cout << ex.getMessage() << std::endl;
119 sqlStmt =
"SELECT max(map_id) from "+tab_map;
120 stmt->setSQL(sqlStmt);
121 rset =
stmt->executeQuery ();
123 while (rset->next ())
124 {map_id= rset->getInt (1);}
131 stmt->closeResultSet (rset);
133 std::ostringstream ss;
136 sqlStmt =
"SELECT max(map_index) from "+tab_map+
" where record_id="+ss.str();
138 stmt->setSQL(sqlStmt);
139 rset =
stmt->executeQuery ();
141 while (rset->next ())
142 {map_index= rset->getInt (1);}
149 stmt->closeResultSet (rset);
151 sqlStmt =
"INSERT INTO "+tab_map+
" VALUES (:1, :2, :3, :4)";
152 stmt->setSQL(sqlStmt);
154 std::map<int,std::vector<std::vector<float> > >::const_iterator itm;
155 itm=obj->
obj.begin();
156 int sizeint=itm->second[0].size();
157 sqlStmt1 =
"INSERT INTO "+tab_data+
" VALUES (:1, :2";
158 for(i=1;i<sizeint+1;++
i){
160 sqlStmt1=sqlStmt1+
", :"+ss.str();
163 sqlStmt1=sqlStmt1+
")";
166 sb4 sf=
sizeof(
float);
177 stmt1->setSQL(sqlStmt1);
179 for(itm=obj->
obj.begin();itm!=obj->
obj.end(); ++itm){
180 int id_det=itm->first;
181 int sizev=obj->
obj[id_det].size();
184 map_index=map_index+1;
186 stmt->setInt (1, map_id);
187 stmt->setInt (2, record);
188 stmt->setInt (3, map_index);
189 stmt->setInt (4, id_det);
190 if(obj_name!=
"test")
stmt->executeUpdate ();
199 for(i=0;i<sizev;++
i){
200 int sizei=obj->
obj[id_det][
i].size();
202 std::cout<<
"Inconsistent object - dimention of internal vector is not " 203 <<sizeint<<std::endl;
209 for(j=0;j<sizei;++j){
210 c[j][
i]=obj->
obj[id_det][
i][j];
214 stmt1->setDataBuffer(1, c1, oracle::occi::OCCIINT, si , &elensi[0]);
215 stmt1->setDataBuffer(2, c2, oracle::occi::OCCIINT, si , &elensi[0]);
216 for(j=0;j<sizeint;++j){
217 stmt1->setDataBuffer(j+3, c[j], oracle::occi::OCCIFLOAT, sf, &elensf[0]);
219 if(obj_name!=
"test")
stmt1->executeArrayUpdate(sizev);
228 con->terminateStatement (
stmt);
235 sqlStmt =
"SELECT max(record_id) from "+obj_name;
237 stmt->setSQL(sqlStmt);
238 oracle::occi::ResultSet *rset;
239 rset =
stmt->executeQuery ();
241 while (rset->next ())
242 {*record = rset->getInt (1);}
249 con->terminateStatement (
stmt);
256 int map_id=0, layer_id=0;
259 tab_map=obj_name+
"_map";
260 tab_data=obj_name+
"_data";
267 oracle::occi::ResultSet *rset, *rset1;
268 std::ostringstream ss;
271 const char*
p=tab_data.c_str();
272 len=tab_data.length();
277 sqlStmt =
"SELECT count(column_name) from user_tab_columns where table_name='"+ss.str()+
"'";
279 stmt->setSQL(sqlStmt);
280 rset =
stmt->executeQuery ();
282 while (rset->next ())
283 {num_var= rset->getInt(1) - 2;}
290 stmt->closeResultSet (rset);
294 sqlStmt =
"SELECT map_id,map_index,layer_id from "+tab_map+
" where record_id="+ss.str()+
" order by map_index";
296 stmt->setSQL(sqlStmt);
297 rset =
stmt->executeQuery ();
299 while (rset->next ())
300 {map_id = rset->getInt (1);
302 layer_id = rset->getInt (3);
304 sqlStmt1 =
"SELECT * from "+tab_data+
" where map_id="+ss.str()+
" order by vec_index";
306 stmt1->setSQL(sqlStmt1);
307 rset1 =
stmt1->executeQuery ();
309 while (rset1->next ())
310 {vec_index = rset1->getInt (2);
311 obj->
obj[layer_id].resize(vec_index);
312 for(i=0;i<num_var;++
i){
313 obj->
obj[layer_id][vec_index-1].push_back(rset1->getFloat(3+i));
condbon() noexcept(false)
oracle::occi::Statement * stmt
void cdbon_last_record(std::string obj_name, int *record)
void cdbon_write(CSCobject *obj, std::string obj_name, int record, int global_run, std::string time)
oracle::occi::Connection * con
oracle::occi::Environment * env
~condbon() noexcept(false)
std::map< int, std::vector< std::vector< float > > > obj
oracle::occi::Statement * stmt1
void cdbon_read_rec(std::string obj_name, int record, CSCobject *obj)