Changeset 18927 for trunk/FACT++/src
- Timestamp:
- 11/09/17 13:40:41 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/rootifysql.cc
r18892 r18927 169 169 170 170 // -------------------------- Request data from database ------------------- 171 const mysqlpp::StoreQueryResult res = 172 Database(uri).query(query).store(); 173 // ------------------------------------------------------------------------- 174 175 if (verbose>0) 176 { 177 cout << res.size() << " rows received." << endl; 178 cout << "Query time: " << Time().UnixTime()-start2.UnixTime() << "s" << endl; 179 } 180 181 if (res.empty()) 182 { 183 cerr << "Nothing to write." << endl; 184 return 5; 185 } 171 Database connection(uri); // Keep alive while fetching rows 172 173 const mysqlpp::UseQueryResult res = 174 connection.query(query).use(); 175 // ------------------------------------------------------------------------- 186 176 187 177 if (verbose>0) … … 191 181 TFile tfile(path, update?"UPDATE":(force?"RECREATE":"CREATE"), "Rootify SQL", compression); 192 182 if (tfile.IsZombie()) 183 return 5; 184 185 // ------------------------------------------------------------------------- 186 187 // get the first row to get the field description 188 mysqlpp::Row row = res.fetch_row(); 189 if (!row) 190 { 191 cerr << "Empty set returned... nothing to write." << endl; 193 192 return 6; 194 // ------------------------------------------------------------------------- 195 196 const mysqlpp::Row &r = res.front(); 197 198 if (verbose>0) 199 cout << "Trying to setup " << r.size() << " branches..." << endl; 193 } 194 195 if (verbose>0) 196 cout << "Trying to setup " << row.size() << " branches..." << endl; 200 197 201 198 if (verbose>1) 202 199 cout << endl; 203 200 204 const mysqlpp::FieldNames &l = *r .field_list().list;201 const mysqlpp::FieldNames &l = *row.field_list().list; 205 202 206 203 vector<double> buf(l.size()); … … 213 210 for (size_t i=0; i<l.size(); i++) 214 211 { 215 const string t = r [i].type().sql_name();212 const string t = row[i].type().sql_name(); 216 213 217 214 if (t.find("DATETIME")!=string::npos) … … 258 255 259 256 // ---------------------- Fill TTree with DB data -------------------------- 260 size_t skip = 0; 261 for (auto row=res.begin(); row<res.end(); row++) 262 { 257 size_t count = 0; 258 size_t skip = 0; 259 do 260 { 261 count++; 262 263 263 ostringstream sout; 264 264 265 265 size_t idx=0; 266 for (auto col=row ->begin(); col!=row->end(); col++, idx++)266 for (auto col=row.begin(); col!=row.end(); col++, idx++) 267 267 { 268 268 if (display) … … 302 302 } 303 303 304 if (idx==row ->size())304 if (idx==row.size()) 305 305 { 306 306 ttree->Fill(); … … 308 308 cout << sout.str() << endl; 309 309 } 310 } 310 311 row = res.fetch_row(); 312 313 } while (row); 314 311 315 // ------------------------------------------------------------------------- 312 316 … … 316 320 if (verbose>0) 317 321 { 322 cout << count << " rows fetched." << endl; 318 323 if (skip>0) 319 324 cout << skip << " rows skipped due to NULL field." << endl;
Note:
See TracChangeset
for help on using the changeset viewer.