| 236 | } |
| 237 | |
| 238 | void MzMLSqliteHandler::readExperiment(MSExperiment& exp, bool meta_only) const |
| 239 | { |
| 240 | SqliteConnector conn(filename_); |
| 241 | sqlite3* db = conn.getDB(); |
| 242 | |
| 243 | Size nr_results = 0; |
| 244 | if (write_full_meta_) |
| 245 | { |
| 246 | std::string select_sql = "SELECT " \ |
| 247 | "RUN.ID as run_id," \ |
| 248 | "RUN.NATIVE_ID as native_id," \ |
| 249 | "RUN.FILENAME as filename," \ |
| 250 | "RUN_EXTRA.DATA as data " \ |
| 251 | "FROM RUN " \ |
| 252 | "LEFT JOIN RUN_EXTRA ON RUN.ID = RUN_EXTRA.RUN_ID " \ |
| 253 | ";"; |
| 254 | |
| 255 | sqlite3_stmt* stmt; |
| 256 | conn.prepareStatement(&stmt, select_sql); |
| 257 | sqlite3_step(stmt); |
| 258 | |
| 259 | // read data (throw exception if we find multiple runs) |
| 260 | while (sqlite3_column_type(stmt, 0) != SQLITE_NULL) |
| 261 | { |
| 262 | if (nr_results > 0) |
| 263 | { |
| 264 | throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, |
| 265 | "More than one run found, cannot read both into memory"); |
| 266 | } |
| 267 | |
| 268 | const void* raw_text = sqlite3_column_blob(stmt, 3); |
| 269 | size_t blob_bytes = sqlite3_column_bytes(stmt, 3); |
| 270 | |
| 271 | // create mzML file and parse full structure |
| 272 | if (blob_bytes > 0) |
| 273 | { |
| 274 | MzMLFile f; |
| 275 | std::string uncompressed; |
| 276 | OpenMS::ZlibCompression::uncompressString(raw_text, blob_bytes, uncompressed); |
| 277 | f.loadBuffer(uncompressed, exp); |
| 278 | |
| 279 | nr_results++; |
| 280 | } |
| 281 | else |
| 282 | { |
| 283 | const unsigned char* native_id = sqlite3_column_text(stmt, 1); |
| 284 | const unsigned char* filename = sqlite3_column_text(stmt, 2); |
| 285 | OPENMS_LOG_WARN << "Warning: no full meta data found for run " << native_id << " from file " << filename << std::endl; |
| 286 | } |
| 287 | sqlite3_step(stmt); |
| 288 | } |
| 289 | |
| 290 | // free memory |
| 291 | sqlite3_finalize(stmt); |
| 292 | |
| 293 | if (nr_results == 0) |
| 294 | { |
| 295 | OPENMS_LOG_WARN << "Warning: no meta data found, fall back to inference from SQL data structures." << std::endl; |