16MYSQL* ReadRuntripFromDb::OpenDb()
const {
18 const char host[] =
"bes3db2.ihep.ac.cn";
19 const char user[] =
"guest";
20 const char passwd[] =
"guestpass";
21 const char db[] =
"offlinedb";
22 unsigned int port_num = 3306;
24 MYSQL* mysql = mysql_init(NULL);
25 mysql = mysql_real_connect(mysql, host, user, passwd, db, port_num,
30 fprintf(stderr,
"can not open database: offlinedb\n");
36void ReadRuntripFromDb::CloseDb(
MYSQL* mysql)
const {
43 MYSQL* mysql=OpenDb();
47 "select trip_start, trip_stop "
48 "from RunParams where run_number = %d", run);
50 if (mysql_real_query(mysql, stmt, strlen(stmt)))
52 fprintf(stderr,
"query error\n");
57 MYSQL_RES* result_set = mysql_store_result(mysql);
58 MYSQL_ROW row = mysql_fetch_row(result_set);
59 if (row[0]==NULL || row[1]==NULL)
61 fprintf(stderr,
"can't find trip information for tripped run: %d\n", run);
62 mysql_free_result(result_set);
72 token = strtok(row[0],
",");
74 timest.push_back(tripst);
75 while((token =strtok(NULL,
","))!= NULL){
77 timest.push_back(tripst);
79 doken = strtok(row[1],
",");
81 timend.push_back(tripnd);
82 while((doken = strtok(NULL,
","))!= NULL){
84 timend.push_back(tripnd);
88 mysql_free_result(result_set);
109 return timest.size();
114 return timend.size();
struct st_mysql_res MYSQL_RES