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");
13 db_user=std::string(c_user);
14 db_pass=std::string(c_pass);
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);
28 int global_run, std::string data_time)
31 std::string tab, tab_map, tab_data;
32 std::string sqlStmt, sqlStmt1;
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";
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;
91 std::string st=data_time.substr(4,3);
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 ();
111 std::cout<<
"Exception thrown for insertBind"<<std::endl;
112 std::cout<<
"Error number: "<< ex.getErrorCode() << std::endl;
117 sqlStmt =
"SELECT max(map_id) from "+tab_map;
118 stmt->setSQL(sqlStmt);
119 rset =
stmt->executeQuery ();
121 while (rset->next ())
122 {map_id= rset->getInt (1);}
129 stmt->closeResultSet (rset);
131 std::ostringstream ss;
134 sqlStmt =
"SELECT max(map_index) from "+tab_map+
" where record_id="+ss.str();
136 stmt->setSQL(sqlStmt);
137 rset =
stmt->executeQuery ();
139 while (rset->next ())
140 {map_index= rset->getInt (1);}
147 stmt->closeResultSet (rset);
149 sqlStmt =
"INSERT INTO "+tab_map+
" VALUES (:1, :2, :3, :4)";
150 stmt->setSQL(sqlStmt);
152 std::map<int,std::vector<std::vector<float> > >::const_iterator itm;
153 itm=obj->
obj.begin();
154 int sizeint=itm->second[0].size();
155 sqlStmt1 =
"INSERT INTO "+tab_data+
" VALUES (:1, :2";
156 for(i=1;i<sizeint+1;++
i){
158 sqlStmt1=sqlStmt1+
", :"+ss.str();
161 sqlStmt1=sqlStmt1+
")";
164 sb4 sf=
sizeof(float);
175 stmt1->setSQL(sqlStmt1);
177 for(itm=obj->
obj.begin();itm!=obj->
obj.end(); ++itm){
178 int id_det=itm->first;
179 int sizev=obj->
obj[id_det].size();
182 map_index=map_index+1;
184 stmt->setInt (1, map_id);
185 stmt->setInt (2, record);
186 stmt->setInt (3, map_index);
187 stmt->setInt (4, id_det);
188 if(obj_name!=
"test")
stmt->executeUpdate ();
197 for(i=0;i<sizev;++
i){
198 int sizei=obj->
obj[id_det][
i].size();
200 std::cout<<
"Inconsistent object - dimention of internal vector is not "
201 <<sizeint<<std::endl;
207 for(j=0;j<sizei;++
j){
208 c[
j][
i]=obj->
obj[id_det][
i][
j];
212 stmt1->setDataBuffer(1, c1, oracle::occi::OCCIINT, si , &elensi[0]);
213 stmt1->setDataBuffer(2, c2, oracle::occi::OCCIINT, si , &elensi[0]);
214 for(j=0;j<sizeint;++
j){
215 stmt1->setDataBuffer(j+3, c[j], oracle::occi::OCCIFLOAT, sf, &elensf[0]);
217 if(obj_name!=
"test")
stmt1->executeArrayUpdate(sizev);
226 con->terminateStatement (
stmt);
233 sqlStmt =
"SELECT max(record_id) from "+obj_name;
235 stmt->setSQL(sqlStmt);
237 rset =
stmt->executeQuery ();
239 while (rset->next ())
240 {*record = rset->getInt (1);}
247 con->terminateStatement (
stmt);
254 int map_id=0, map_index=0, layer_id=0;
255 std::string tab, tab_map, tab_data;
257 tab_map=obj_name+
"_map";
258 tab_data=obj_name+
"_data";
262 std::string sqlStmt,sqlStmt1;
266 std::ostringstream ss;
269 const char*
p=tab_data.c_str();
270 len=tab_data.length();
275 sqlStmt =
"SELECT count(column_name) from user_tab_columns where table_name='"+ss.str()+
"'";
277 stmt->setSQL(sqlStmt);
278 rset =
stmt->executeQuery ();
280 while (rset->next ())
281 {num_var= rset->getInt(1) - 2;}
288 stmt->closeResultSet (rset);
292 sqlStmt =
"SELECT map_id,map_index,layer_id from "+tab_map+
" where record_id="+ss.str()+
" order by map_index";
294 stmt->setSQL(sqlStmt);
295 rset =
stmt->executeQuery ();
297 while (rset->next ())
298 {map_id = rset->getInt (1);
299 map_index = rset->getInt (2);
300 layer_id = rset->getInt (3);
302 sqlStmt1 =
"SELECT * from "+tab_data+
" where map_id="+ss.str()+
" order by vec_index";
304 stmt1->setSQL(sqlStmt1);
305 rset1 =
stmt1->executeQuery ();
307 while (rset1->next ())
308 {vec_index = rset1->getInt (2);
309 obj->
obj[layer_id].resize(vec_index);
310 for(i=0;i<num_var;++
i){
311 obj->
obj[layer_id][vec_index-1].push_back(rset1->getFloat(3+i));
oracle::occi::Statement * stmt
oracle::occi::SQLException SQLException
tuple obj
Example code starts here #.
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::ResultSet ResultSet
oracle::occi::Environment * env
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)