SqlTable::SqlTable(const char* _cTableName, const char* _cTableStruct ) :m_strTableName( _cTableName ) { CMyStr strQuery( "CREATE TABLE IF NOT EXISTS "+m_strTableName+" ("+_cTableStruct+")" ); m_sqlBase.FreeRes( m_sqlBase.Query( strQuery.c_str() ) ); }
/* INSERT INTO <m_strTableName> (_vecCols[0] ... _vecCols[n]) VALUES (_vecValues[0] ... _vecValues[n]) */ bool SqlTable::Insert(const TVecMyStr& _vecCols, const TVecMyStr& _vecValues ) { if (_vecCols.size() != _vecValues.size() ) return false; CMyStr strQuery( "INSERT INTO " + m_strTableName + "("); //+ " VALUES (" + CMyStr( _pcValue ) + ")" ); for(TVecMyStr::const_iterator it = _vecCols.begin(); it != _vecCols.end(); ++it ) strQuery = strQuery + **it + (( (it - _vecCols.begin()) != (_vecCols.size() - 1) ) ? "," : ""); strQuery = strQuery + ") VALUES ("; for(TVecMyStr::const_iterator itVal = _vecValues.begin(); itVal != _vecValues.end(); ++itVal ) strQuery = strQuery + **itVal + (( (itVal - _vecValues.begin()) != (_vecValues.size() - 1) ) ? "," : ""); strQuery = strQuery + ")"; std::cerr << strQuery.c_str() << std::endl; MYSQL_RES* pRes = m_sqlBase.Query( strQuery.c_str() ); m_sqlBase.FreeRes( pRes ); return true; }
QString CSpmXml::GetQuery(QStringList lstKeys, xmlNodePtr pNode) { pNode = GetNode(pNode); if (0 == pNode) return ""; QStringList strQuery("//"); strQuery.append(QString::fromUtf8((char *)pNode->name)); if (lstKeys.size()) { strQuery.append("["); for (int i = 0; i < lstKeys.size(); i++) { QVariant vtValue = GetAttr(lstKeys.at(i)); if (!vtValue.isValid()) return ""; if (i > 0) strQuery.append("and"); strQuery.append("(@"); strQuery.append(lstKeys.at(i)); strQuery.append("='"); strQuery.append(vtValue.toString()); strQuery.append("')"); } strQuery.append("]"); } return strQuery.join(""); }
/* SELECT <_pcFlt> FROM <m_strTableName> WHERE <_pcKey> ='< _pcVal>' */ bool SqlTable::SelectToStr(const char* _pcFlt, const char* _pcKey,const char* _pcVal, TVecChar* _pvecRes ) { bool isRes; CMyStr strQuery( "SELECT "+CMyStr( _pcFlt )+" FROM "+m_strTableName+" WHERE "+CMyStr( _pcKey )+"='"+CMyStr( _pcVal )+"'" ); std::cerr << strQuery.c_str() << std::endl; MYSQL_RES* pRes = m_sqlBase.Query( strQuery.c_str() ); //syslog( LOG_INFO | LOG_LOCAL0, strQuery.c_str() ); if( isRes = ( pRes != 0 ) ) { MYSQL_ROW Row = mysql_fetch_row( pRes ); unsigned long *lengths = mysql_fetch_lengths(pRes); if( isRes = (( Row != 0 ) && *lengths != 0) ) _pvecRes->assign( Row[0], Row[0] + lengths[0] ); } m_sqlBase.FreeRes( pRes ); /* int isnRes; if ( isRes ) isnRes = 1; else isnRes = 0; syslog( LOG_INFO | LOG_LOCAL0, "SqlTable::SelectToStr return %d", isnRes );*/ return isRes; }
// Update the last-played date/time for each track in the auto-DJ-crates // database. bool AutoDJCratesDAO::updateLastPlayedDateTime() { QSqlQuery oQuery(m_rDatabase); // Rebuild the auto-DJ-playlist last-played date/time. // INSERT OR REPLACE INTO temp_autodj_crates (track_id, craterefs, timesplayed, autodjrefs, lastplayed) SELECT * FROM (SELECT PlaylistTracks.track_id, craterefs, timesplayed, autodjrefs, MAX(pl_datetime_added) AS newlastplayed FROM PlaylistTracks, temp_autodj_crates WHERE PlaylistTracks.playlist_id IN (SELECT id FROM Playlists WHERE hidden = 2) AND PlaylistTracks.track_id = temp_autodj_crates.track_id GROUP BY PlaylistTracks.track_id) WHERE newlastplayed != ""; QString strSetLog; strSetLog.setNum(PlaylistDAO::PLHT_SET_LOG); QString strQuery(QString ("INSERT OR REPLACE INTO " AUTODJCRATES_TABLE " (" AUTODJCRATESTABLE_TRACKID ", " AUTODJCRATESTABLE_CRATEREFS ", " AUTODJCRATESTABLE_TIMESPLAYED ", " AUTODJCRATESTABLE_AUTODJREFS ", " AUTODJCRATESTABLE_LASTPLAYED ")" " SELECT * FROM (SELECT " PLAYLIST_TRACKS_TABLE ".%1, " AUTODJCRATESTABLE_CRATEREFS ", " AUTODJCRATESTABLE_TIMESPLAYED ", " AUTODJCRATESTABLE_AUTODJREFS ", MAX(%3) AS new" AUTODJCRATESTABLE_LASTPLAYED " FROM " PLAYLIST_TRACKS_TABLE ", " AUTODJCRATES_TABLE " WHERE " PLAYLIST_TRACKS_TABLE ".%2 IN (SELECT %4 FROM " PLAYLIST_TABLE " WHERE %5 = %6) AND " PLAYLIST_TRACKS_TABLE ".%1 = " AUTODJCRATES_TABLE "." AUTODJCRATESTABLE_TRACKID " GROUP BY " PLAYLIST_TRACKS_TABLE ".%1) WHERE new" AUTODJCRATESTABLE_LASTPLAYED " != \"\"") .arg(PLAYLISTTRACKSTABLE_TRACKID, // %1 PLAYLISTTRACKSTABLE_PLAYLISTID, // %2 PLAYLISTTRACKSTABLE_DATETIMEADDED, // %3 PLAYLISTTABLE_ID, // %4 PLAYLISTTABLE_HIDDEN, // %5 strSetLog)); // %6 oQuery.prepare(strQuery); if (!oQuery.exec()) { LOG_FAILED_QUERY(oQuery); return false; } return true; }
void CPage::LoadCache(ConnectionPtr connection) { Trace("LoadCache", "",0); ResultPtr result; ncc::safe_array<char> strQuery(10240); try { // load from the database snprintf(strQuery, strQuery.size(), SQL_WTT_LOAD_CACHE, m_runID); Trace("Query for LoadCache", strQuery, 0); result = connection->Query(strQuery); while(result->Next()) { RowPtr row = result->GetCurrentRow(); // add it std::string urlStr; urlStr = row->GetFieldString(1); { // scope for lock Mutex::Lock lock(sm_urlListLock); m_totalUrlList.push_back(urlStr); } } } catch (const std::exception& e) { LogError2("LoadCache() - Caught Exception", e.what(), 0, SC_ERR_GROUP_DB, SC_ERR_CODE_LOAD_CACHE); } }
/* INSERT INTO <m_strTableName> VALUE (<_cszVal>) */ void SqlTable::Insert( const char* _cszVal ) { CMyStr strQuery( "INSERT INTO "+m_strTableName+" VALUE ("+CMyStr( _cszVal )+")" ); MYSQL_RES* pRes = m_sqlBase.Query( strQuery.c_str() ); m_sqlBase.FreeRes( pRes ); }
void CPage::SaveCache(ConnectionPtr connection) { Trace("SaveCache", "", m_totalUrlList.size()); // save all the cookies in the current memory list to the database // in the WebPageCookies table ncc::safe_array<char> strQuery(102400); ncc::safe_array<char> sqlCache(40961); { // scope for lock // delete the existing cache in the table for this run snprintf(strQuery, strQuery.size(), SQL_WTT_DEL_CACHE, m_runID); Trace("Query for SaveCache", strQuery, 0); connection->Query(strQuery); try { for (URLList::const_iterator it = m_totalUrlList.begin(); it != m_totalUrlList.end(); ++it) { // convert the string ready to be inserted int len = 0; // convert the string for inserting len = mysql_escape_string(sqlCache, (*it).c_str(),((*it).size()<40960)?((*it).size()):40960); // terminate the string if( len > 40960) { sqlCache[40960] = '\0'; } else { sqlCache[len] = '\0'; } // make sure last char not a \ - it would escape the final quote if( sqlCache[40959] == '\\') { sqlCache[40959] = ' '; } else if( sqlCache[len-1] == '\\') { sqlCache[len-1] = ' '; } // save to the database snprintf(strQuery, strQuery.size(), SQL_WTT_SAVE_CACHE, m_runID, static_cast<const char*>(sqlCache)); Trace("Query for SaveCache", strQuery, 0); connection->Query(strQuery); } } catch (const std::exception& e) { LogError2("SaveCache() - Caught Exception", e.what(), 0, SC_ERR_GROUP_DB, SC_ERR_CODE_STORE_CACHE); } } }
std::string ccMongooseWebServerRequest::GetQueryString() { if (_pMgHttpMessage == NULL) return _strNullData; std::string strQuery(_pMgHttpMessage->query_string.p, _pMgHttpMessage->query_string.len); return strQuery; }
/* UPDATE <m_strTableName> SET <_cszCol>=<_cszNewVal> WHERE <_cszKey> =< _cszVal>;*/ void SqlTable::Update( const char* _cszCol, const char* _cszNewVal, const char* _cszKey, const char* _cszVal ) { CMyStr strQuery( "UPDATE " + m_strTableName + " SET "+ _cszCol + "=" + _cszNewVal + " WHERE "+ _cszKey +"="+_cszVal ); MYSQL_RES* pRes = m_sqlBase.Query( strQuery.c_str() ); std::cerr << strQuery.c_str() << std::endl; m_sqlBase.FreeRes( pRes ); }
void BansheePlaylistModel::dropTempTable() { if (m_playlistId >= 0) { // Clear old playlist m_playlistId = -1; QSqlQuery query(m_pTrackCollection->database()); QString strQuery("DROP TABLE IF EXISTS %1"); if (!query.exec(strQuery.arg(m_tempTableName))) { LOG_FAILED_QUERY(query); } } }
// Update the number of auto-DJ-playlist references to each track in the // auto-DJ-crates database. bool AutoDJCratesDAO::updateAutoDjPlaylistReferences() { QSqlQuery oQuery(m_rDatabase); // Rebuild the auto-DJ-playlist reference count. // INSERT OR REPLACE INTO temp_autodj_crates (track_id, craterefs, timesplayed, autodjrefs) SELECT * FROM (SELECT PlaylistTracks.track_id, craterefs, timesplayed, COUNT (*) AS newautodjrefs FROM PlaylistTracks, temp_autodj_crates WHERE PlaylistTracks.playlist_id IN (SELECT id FROM Playlists WHERE hidden = 1) AND PlaylistTracks.track_id = temp_autodj_crates.track_id GROUP BY PlaylistTracks.track_id) WHERE newautodjrefs > 0; QString strHidden; strHidden.setNum(PlaylistDAO::PLHT_AUTO_DJ); QString strQuery(QString ("INSERT OR REPLACE INTO " AUTODJCRATES_TABLE " (" AUTODJCRATESTABLE_TRACKID ", " AUTODJCRATESTABLE_CRATEREFS ", " AUTODJCRATESTABLE_TIMESPLAYED ", " AUTODJCRATESTABLE_AUTODJREFS ")" " SELECT * FROM (SELECT " PLAYLIST_TRACKS_TABLE ".%1, " AUTODJCRATESTABLE_CRATEREFS ", " AUTODJCRATESTABLE_TIMESPLAYED ", COUNT (*) AS new" AUTODJCRATESTABLE_AUTODJREFS " FROM " PLAYLIST_TRACKS_TABLE ", " AUTODJCRATES_TABLE " WHERE " PLAYLIST_TRACKS_TABLE ".%2 IN (SELECT %3 FROM " PLAYLIST_TABLE " WHERE %4 = %5) AND " PLAYLIST_TRACKS_TABLE ".%1 = " AUTODJCRATES_TABLE "." AUTODJCRATESTABLE_TRACKID " GROUP BY " PLAYLIST_TRACKS_TABLE ".%1) WHERE new" AUTODJCRATESTABLE_AUTODJREFS " > 0") .arg(PLAYLISTTRACKSTABLE_TRACKID, // %1 PLAYLISTTRACKSTABLE_PLAYLISTID, // %2 PLAYLISTTABLE_ID, // %3 PLAYLISTTABLE_HIDDEN, // %4 strHidden)); // %5 oQuery.prepare(strQuery); if (!oQuery.exec()) { LOG_FAILED_QUERY(oQuery); return false; } // Incorporate all tracks loaded into decks. // Each track has to be done as a separate database query, in case the same // track is loaded into multiple decks. int iDecks = (int) PlayerManager::numDecks(); for (int i = 0; i < iDecks; ++i) { QString group = PlayerManager::groupForDeck(i); TrackPointer pTrack = PlayerInfo::Instance().getTrackInfo(group); if (pTrack) { int iTrackId = pTrack->getId(); // UPDATE temp_autodj_crates SET autodjrefs = autodjrefs + 1 WHERE track_id IN (:track_id); oQuery.prepare("UPDATE " AUTODJCRATES_TABLE " SET " AUTODJCRATESTABLE_AUTODJREFS " = " AUTODJCRATESTABLE_AUTODJREFS " + 1 WHERE " AUTODJCRATESTABLE_TRACKID " IN (:track_id)"); oQuery.bindValue(":track_id", iTrackId); if (!oQuery.exec()) { LOG_FAILED_QUERY(oQuery); return false; } } } return true; }
// Try to execute an SQL query // Returns ZERO on success UINT CSmartDB::Execute(LPCTSTR pszQuery, UINT *nRecEfected) { #ifdef UNICODE string strQuery = ws2s(pszQuery); #else string strQuery(pszQuery); #endif UINT nRetValue; char *zErrMsg = 0; if (SmartDBExecute (db, strQuery.c_str(), NULL, 0, &zErrMsg) == SQLITE_OK) nRetValue = 0; else { nRetValue = 1; } return nRetValue; }
int main(int argc, char* argv[]) { if (argc < 2) { std::cout << "Usage: this <database name> <query>" << std::endl; std::cout << "If <query> is omitted, database metadata is dumped" << std::endl; return -1; } AMySQLServer server(argv[1]); AString strError; if (!server.init(strError)) { std::cout << strError << std::endl; return -1; } AString strQuery("select * from item where id=2"); ADatabaseObject qr("myquery"); if (!server.executeSQL(qr, strQuery, strError)) { std::cout << strError << std::endl; return -1; } AElement element; AString result; qr.publish(&element); element.asXml(result); std::cout << result << std::endl; std::cout << "Only row 0" << std::endl; result.clear(); const AObjectContainer& ns = qr.getRow(0); std::cout << "id=" << ns.getAs<AString>("id") << " name=" << ns.getAs<AString>("name") << " weight=" << ns.getAs<AString>("creator") << std::endl; return 0; }
void SqlTable::Call( const CMyStr& name, const TVecMyStr& parameters ) { CMyStr parametersWithCommas; for(int i=0; i<parameters.size(); i++) { parametersWithCommas += " \"" + *parameters[i] + "\""; if(i < parameters.size()-1) parametersWithCommas += ","; } CMyStr strQuery( "CALL " + name + "(" + parametersWithCommas + ")"); std::cerr << strQuery.c_str() << std::endl; MYSQL_RES* pRes = m_sqlBase.Query( strQuery.c_str() ); m_sqlBase.FreeRes( pRes ); }
// Create the temporary auto-DJ-crates table. // Done the first time it's used, since the user might not even make // use of this feature. void AutoDJCratesDAO::createAutoDjCratesDatabase() { // If the use of tracks that haven't been played in a while has changed, // then the active-tracks view must be recreated. bool bUseIgnoreTime = (bool) m_pConfig->getValueString( ConfigKey("[Auto DJ]", "UseIgnoreTime"), "0").toInt(); if (m_bAutoDjCratesDbCreated) { if (m_bUseIgnoreTime != bUseIgnoreTime) { // Do all this in a single transaction. ScopedTransaction oTransaction(m_rDatabase); // Get rid of the old active-tracks view. QSqlQuery oQuery(m_rDatabase); oQuery.exec ("DROP VIEW IF EXISTS " AUTODJACTIVETRACKS_TABLE); if (!oQuery.exec()) { LOG_FAILED_QUERY(oQuery); return; } // Create the new active-tracks view. if (!createActiveTracksView (bUseIgnoreTime)) { return; } // Remember the new setting. m_bUseIgnoreTime = bUseIgnoreTime; // Commit these changes. oTransaction.commit(); } } else { m_bUseIgnoreTime = bUseIgnoreTime; } // If this database has already been created, skip this. if (m_bAutoDjCratesDbCreated) { return; } // Do all of this in a single transaction. ScopedTransaction oTransaction(m_rDatabase); // The auto-DJ-crates table contains the track ID, the number of references // to that track ID in all of the auto-DJ crates, the number of times that // track has been played, and the number of references to the track in the // auto-DJ playlist (or in loaded decks). It filters out tracks that have // been deleted from the database (i.e. "hidden" tracks). // Create an empty table. QSqlQuery oQuery(m_rDatabase); // CREATE TEMP TABLE temp_autodj_crates (track_id INTEGER UNIQUE, craterefs INTEGER, timesplayed INTEGER, autodjrefs INTEGER, lastplayed DATETIME); //oQuery.exec ("DROP TABLE IF EXISTS " AUTODJCRATES_TABLE); QString strQuery("CREATE TEMP TABLE " AUTODJCRATES_TABLE " (" AUTODJCRATESTABLE_TRACKID " INTEGER UNIQUE, " AUTODJCRATESTABLE_CRATEREFS " INTEGER, " AUTODJCRATESTABLE_TIMESPLAYED " INTEGER, " AUTODJCRATESTABLE_AUTODJREFS " INTEGER, " AUTODJCRATESTABLE_LASTPLAYED " DATETIME)"); oQuery.prepare(strQuery); if (!oQuery.exec()) { LOG_FAILED_QUERY(oQuery); return; } // Fill out the first three columns. // Supply default values for the last two. // INSERT INTO temp_autodj_crates (track_id, craterefs, timesplayed, autodjrefs, lastplayed) SELECT crate_tracks.track_id, COUNT (*), library.timesplayed, 0, "" FROM crate_tracks, library WHERE crate_tracks.crate_id IN (SELECT id FROM crates WHERE autodj = 1) AND crate_tracks.track_id = library.id AND library.mixxx_deleted = 0 GROUP BY crate_tracks.track_id, library.timesplayed; strQuery = QString("INSERT INTO " AUTODJCRATES_TABLE " (" AUTODJCRATESTABLE_TRACKID ", " AUTODJCRATESTABLE_CRATEREFS ", " AUTODJCRATESTABLE_TIMESPLAYED ", " AUTODJCRATESTABLE_AUTODJREFS ", " AUTODJCRATESTABLE_LASTPLAYED ") SELECT " CRATE_TRACKS_TABLE ".%1 , COUNT (*), " LIBRARY_TABLE ".%2, 0, \"\" FROM " CRATE_TRACKS_TABLE ", " LIBRARY_TABLE " WHERE " CRATE_TRACKS_TABLE ".%4 IN (SELECT %5 FROM " CRATE_TABLE " WHERE %6 = 1) AND " CRATE_TRACKS_TABLE ".%1 = " LIBRARY_TABLE ".%7 AND " LIBRARY_TABLE ".%3 == 0 GROUP BY " CRATE_TRACKS_TABLE ".%1, " LIBRARY_TABLE ".%2") .arg(CRATETRACKSTABLE_TRACKID, // %1 LIBRARYTABLE_TIMESPLAYED, // %2 LIBRARYTABLE_MIXXXDELETED, // %3 CRATETRACKSTABLE_CRATEID, // %4 CRATETABLE_ID, // %5 CRATETABLE_AUTODJ_SOURCE, // %6 LIBRARYTABLE_ID); // %7 oQuery.prepare(strQuery); if (!oQuery.exec()) { LOG_FAILED_QUERY(oQuery); return; } // Fill out the number of auto-DJ-playlist references. if (!updateAutoDjPlaylistReferences()) { return; } // Fill out the last-played date/time. if (!updateLastPlayedDateTime()) { return; } // Create the active-tracks view. //oQuery.exec ("DROP VIEW IF EXISTS " AUTODJACTIVETRACKS_TABLE); if (!createActiveTracksView (m_bUseIgnoreTime)) { return; } // Make a list of the IDs of every set-log playlist. // SELECT id FROM Playlists WHERE hidden = 2; oQuery.prepare(QString("SELECT %1 FROM " PLAYLIST_TABLE " WHERE %2 = %3") .arg(PLAYLISTTABLE_ID, // %1 PLAYLISTTABLE_HIDDEN, // %2 QString::number(PlaylistDAO::PLHT_SET_LOG))); // %3 if (oQuery.exec()) { while (oQuery.next()) m_lstSetLogPlaylistIds.append(oQuery.value(0).toInt()); } else { LOG_FAILED_QUERY(oQuery); return; } // Now the auto-DJ crates database is initialized. // Externally-driven updates to the database from now on are driven by // signals. oTransaction.commit(); // Be notified when a track is modified. // We only care when the number of times it's been played changes. connect(&m_rTrackDAO, SIGNAL(trackDirty(int)), this, SLOT(slotTrackDirty(int))); // Be notified when the status of crates changes. // We only care about the crates labeled as auto-DJ, and tracks added to, // and removed from, such crates. connect(&m_rCrateDAO, SIGNAL(added(int)), this, SLOT(slotCrateAdded(int))); connect(&m_rCrateDAO, SIGNAL(deleted(int)), this, SLOT(slotCrateDeleted(int))); connect(&m_rCrateDAO, SIGNAL(autoDjChanged(int,bool)), this, SLOT(slotCrateAutoDjChanged(int,bool))); connect(&m_rCrateDAO, SIGNAL(trackAdded(int,int)), this, SLOT(slotCrateTrackAdded(int,int))); connect(&m_rCrateDAO, SIGNAL(trackRemoved(int,int)), this, SLOT(slotCrateTrackRemoved(int,int))); // Be notified when playlists are added/removed. // We only care about set-log playlists. connect(&m_rPlaylistDAO, SIGNAL(added(int)), this, SLOT(slotPlaylistAdded(int))); connect(&m_rPlaylistDAO, SIGNAL(deleted(int)), this, SLOT(slotPlaylistDeleted(int))); // Be notified when tracks are added/removed from playlists. // We only care about the auto-DJ playlist and the set-log playlists. connect(&m_rPlaylistDAO, SIGNAL(trackAdded(int,int,int)), this, SLOT(slotPlaylistTrackAdded(int,int,int))); connect(&m_rPlaylistDAO, SIGNAL(trackRemoved(int,int,int)), this, SLOT(slotPlaylistTrackRemoved(int,int,int))); // Be notified when tracks are loaded to, or unloaded from, a deck. // These count as auto-DJ references, i.e. prevent the track from being // selected randomly. connect(&PlayerInfo::Instance(), SIGNAL(trackLoaded(QString,TrackPointer)), this, SLOT(slotPlayerInfoTrackLoaded(QString,TrackPointer))); connect(&PlayerInfo::Instance(), SIGNAL(trackUnloaded(QString,TrackPointer)), this, SLOT(slotPlayerInfoTrackUnloaded(QString,TrackPointer))); // Remember that the auto-DJ-crates database has been created. m_bAutoDjCratesDbCreated = true; }
void HHRImpl::populateResultVector() { char line[500]; int counter = 0; string inFilename(inputFileLocation); inFilename += "/"; inFilename += rootName; inFilename += "/"; inFilename += "/query.hhr"; //cout << inFilename << endl; FILE* inputFile = fopen((char*) inFilename.c_str(), "r"); if (inputFile == NULL) { cout << "input file: " << inFilename << " can't open" << endl; } HHRResult result; while (fgets(line, 500, inputFile) != NULL) { if (strstr(line, ">") != NULL && !result.isFirstStateReached()) { //set first block information char proteinName[7]; char* pos1 = strstr(line, ">"); sscanf(pos1 + 1, "%s", proteinName); string proteinNameStr(proteinName); result.setProteinName(proteinNameStr); while (strstr(line, "Probab=") == NULL) { fgets(line, 500, inputFile); //skip long name } //get probab, E-value, Score, Aligned_cols, Identities, Similarity, Sum_probs pos1 = strstr(line, "="); float probab; sscanf(pos1 + 1, "%f", &probab); result.setProbab(probab); char* pos2 = strstr(pos1 + 1, "="); float eValue; sscanf(pos2 + 1, "%f", &eValue); result.setExpect(eValue); char* pos3 = strstr(pos2 + 1, "="); float score; sscanf(pos3 + 1, "%f", &score); result.setScore(score); char* pos4 = strstr(pos3 + 1, "="); int alignedCols; sscanf(pos4 + 1, "%d", &alignedCols); result.setAlignedCols(alignedCols); char* pos5 = strstr(pos4 + 1, "="); float identities; sscanf(pos5 + 1, "%f", &identities); result.setIdentities(identities); result.setFirstStateReached(true); } if ((strstr(line, "Q ref|") != NULL) && !result.isSecondStateReached()) { //set second block information //get the query int queryStart; char query[100]; int queryEnd; sscanf(line + 17, "%d %s %d", &queryStart, query, &queryEnd); result.setQueryStart(queryStart); string strQuery(query); result.setQuery(strQuery); result.setQueryEnd(queryEnd); //get the Q Consensus fgets(line, 200, inputFile); int QConsensusStart; char QConsensus[100]; int QConsensusEnd; sscanf(line + 17, "%d %s %d", &QConsensusStart, QConsensus, &QConsensusEnd); string strQConsensus(QConsensus); result.setQueryConsensus(strQConsensus); //get alignment fgets(line, 200, inputFile); char alignment[100]; sscanf(line + 17, "%s", alignment); string strAlignment(alignment); result.setAlignment(strAlignment); //get the T Consensus fgets(line, 200, inputFile); int targetStart; char targetConsensus[100]; int targetEnd; sscanf(line + 17, "%d %s %d", &targetStart, targetConsensus, &targetEnd); result.setTargetStart(targetStart); string strTargetConsensus(targetConsensus); result.setTargetConsensus(strTargetConsensus); result.setTargetEnd(targetEnd); //get the Target fgets(line, 200, inputFile); char target[100]; sscanf(line + 17, "%d %s %d", &targetStart, target, &targetEnd); string strTarget(target); result.setTarget(strTarget); //get the TPred fgets(line, 200, inputFile); char tPred[100]; sscanf(line + 17, "%s", tPred); string strTPred(tPred); result.setTargetSsPred(strTPred); //get the TConf fgets(line, 200, inputFile); char tConf[100]; sscanf(line + 17, "%s", tConf); string strTConf(tConf); result.setConfidence(strTConf); result.setSecondStateReached(true); } if ((strstr(line, "Q ref|") != NULL) && result.isSecondStateReached()) { //update second block information, so in this case //quert, alignment and target should be long string //the queryEnd and targetEnd should also be updated //get the query int queryStart; char query[100]; int queryEnd; sscanf(line + 17, "%d %s %d", &queryStart, query, &queryEnd); string additionalQuery(query); string newQuery = result.getQuery(); newQuery += additionalQuery; result.setQuery(newQuery); result.setQueryEnd(queryEnd); //get the Q Consensus fgets(line, 200, inputFile); int QConsensusStart; char QConsensus[100]; int QConsensusEnd; sscanf(line + 17, "%d %s %d", &QConsensusStart, QConsensus, &QConsensusEnd); string additionalQConsensus(QConsensus); string newQConsesus = result.getQueryConsensus(); newQConsesus += additionalQConsensus; result.setQueryConsensus(newQConsesus); //get alignment fgets(line, 200, inputFile); char alignment[100]; sscanf(line + 17, "%s", alignment); string additionalAlignment(alignment); string newAlignment = result.getAlignment(); newAlignment += additionalAlignment; result.setAlignment(newAlignment); //get the T Consensus fgets(line, 200, inputFile); int targetStart; char targetConsensus[100]; int targetEnd; sscanf(line + 17, "%d %s %d", &targetStart, targetConsensus, &targetEnd); string additionalTargetConsensus(targetConsensus); string newTargetConsensus = result.getTargetConsensus(); newTargetConsensus += additionalTargetConsensus; result.setTargetConsensus(newTargetConsensus); result.setTargetEnd(targetEnd); //get the Target fgets(line, 200, inputFile); char target[100]; sscanf(line + 17, "%d %s %d", &targetStart, target, &targetEnd); string additionalTarget(target); string newTarget = result.getTarget(); newTarget += additionalTarget; result.setTarget(newTarget); //get the TPred fgets(line, 200, inputFile); char tPred[100]; sscanf(line + 17, "%s", tPred); string additionalTPred(tPred); string newTPred = result.getTargetSsPred(); newTPred += additionalTPred; result.setTargetSsPred(newTPred); //get the TConf fgets(line, 200, inputFile); char tConf[100]; sscanf(line + 17, "%s", tConf); string additionalTConf(tConf); string newTConf = result.getConfidence(); newTConf += additionalTConf; result.setConfidence(newTConf); } if ((strstr(line, ">") != NULL) && result.isFirstStateReached()) { //first push the result to the vector hhrResultVector.push_back(result); //then update the information set the first state flag //set first block information char proteinName[7]; char* pos1 = strstr(line, ">"); sscanf(pos1 + 1, "%s", proteinName); string proteinNameStr(proteinName); result.setProteinName(proteinNameStr); while (strstr(line, "Probab=") == NULL) { fgets(line, 500, inputFile); //skip long name } //get probab, E-value, Score, Aligned_cols, Identities, Similarity, Sum_probs pos1 = strstr(line, "="); float probab; sscanf(pos1 + 1, "%f", &probab); result.setProbab(probab); char* pos2 = strstr(pos1 + 1, "="); float eValue; sscanf(pos2 + 1, "%f", &eValue); result.setExpect(eValue); char* pos3 = strstr(pos2 + 1, "="); float score; sscanf(pos3 + 1, "%f", &score); result.setScore(score); char* pos4 = strstr(pos3 + 1, "="); int alignedCols; sscanf(pos4 + 1, "%d", &alignedCols); result.setAlignedCols(alignedCols); char* pos5 = strstr(pos4 + 1, "="); float identities; sscanf(pos5 + 1, "%f", &identities); result.setIdentities(identities); result.setFirstStateReached(true); result.setSecondStateReached(false); } } hhrResultVector.push_back(result); fclose(inputFile); }
void HHRNR2Json::convert() { char line[500]; int counter = 0; string inFilename(inputFileLocation); inFilename += inputFilename; FILE* inputFile = fopen((char*) inFilename.c_str(), "r"); if (inputFile == NULL) { cout << "input file: " << inFilename << " can't open" << endl; } HHRNRResult result; while (fgets(line, 200, inputFile) != NULL) { if (strstr(line, ">") != NULL) { counter++; char proteinName[7]; char* pos1 = strstr(line, ">"); sscanf(pos1 + 1, "%s", proteinName); string proteinNameStr(proteinName); result.setProteinName(proteinNameStr); while (strstr(line, "Probab=") == NULL) { fgets(line, 500, inputFile); //skip long name } //get probab, E-value, Score, Aligned_cols, Identities, Similarity, Sum_probs pos1 = strstr(line, "="); float probab; sscanf(pos1 + 1, "%f", &probab); result.setProbab(probab); char* pos2 = strstr(pos1 + 1, "="); float eValue; sscanf(pos2 + 1, "%f", &eValue); result.setExpect(eValue); char* pos3 = strstr(pos2 + 1, "="); float score; sscanf(pos3 + 1, "%f", &score); result.setScore(score); char* pos4 = strstr(pos3 + 1, "="); int alignedCols; sscanf(pos4 + 1, "%d", &alignedCols); result.setAlignedCols(alignedCols); char* pos5 = strstr(pos4 + 1, "="); float identities; sscanf(pos5 + 1, "%f", &identities); result.setIdentities(identities); char* pos6 = strstr(pos5 + 1, "="); float similarity; sscanf(pos6 + 1, "%f", &similarity); result.setSimilarities(similarity); char* pos7 = strstr(pos6 + 1, "="); float sumProbs; sscanf(pos7 + 1, "%f", &sumProbs); result.setSumProbs(sumProbs); fgets(line, 200, inputFile); //blank //get the query fgets(line, 200, inputFile); char query_ss_pred[100]; sscanf(line + 17, "%s", query_ss_pred); string strQuery_ss_pred(query_ss_pred); result.setQuerySsPred(strQuery_ss_pred); fgets(line, 200, inputFile); int queryStart; char query[100]; int queryEnd; sscanf(line + 17, "%d %s %d", &queryStart, query, &queryEnd); result.setQueryStart(queryStart); string strQuery(query); result.setQuery(strQuery); result.setQueryEnd(queryEnd); //get the Q Consensus fgets(line, 200, inputFile); int QConsensusStart; char QConsensus[100]; int QConsensusEnd; sscanf(line + 17, "%d %s %d", &QConsensusStart, QConsensus, &QConsensusEnd); string strQConsensus(QConsensus); result.setQueryConsensus(strQConsensus); //get alignment fgets(line, 200, inputFile); char alignment[100]; sscanf(line + 17, "%s", alignment); string strAlignment(alignment); result.setAlignment(strAlignment); //get the T Consensus fgets(line, 200, inputFile); int targetStart; char targetConsensus[100]; int targetEnd; sscanf(line + 17, "%d %s %d", &targetStart, targetConsensus, &targetEnd); result.setTargetStart(targetStart); string strTargetConsensus(targetConsensus); result.setTargetConsensus(strTargetConsensus); result.setTargetEnd(targetEnd); //get the Target fgets(line, 200, inputFile); char target[100]; sscanf(line + 17, "%d %s %d", &targetStart, target, &targetEnd); string strTarget(target); result.setTarget(strTarget); //get the TDssp fgets(line, 200, inputFile); char tDssp[100]; sscanf(line + 17, "%s", tDssp); string strTDssp(tDssp); result.setTargetSsDssp(strTDssp); //get the TPred fgets(line, 200, inputFile); char tPred[100]; sscanf(line + 17, "%s", tPred); string strTPred(tPred); result.setTargetSsPred(strTPred); counter++; HHRNRResultVector.push_back(result); } } fclose(inputFile); }
void BansheePlaylistModel::setTableModel(int playlistId) { //qDebug() << "BansheePlaylistModel::setTableModel" << this << playlistId; if (m_playlistId == playlistId) { qDebug() << "Already focused on playlist " << playlistId; return; } dropTempTable(); if (playlistId >= 0) { // setup new playlist m_playlistId = playlistId; QSqlQuery query(m_pTrackCollection->database()); QString strQuery("CREATE TEMP TABLE IF NOT EXISTS %1" " (" CLM_TRACK_ID " INTEGER, " CLM_VIEW_ORDER " INTEGER, " CLM_ARTIST " TEXT, " CLM_TITLE " TEXT, " CLM_DURATION " INTEGER, " CLM_URI " TEXT, " CLM_ALBUM " TEXT, " CLM_ALBUM_ARTIST " TEXT, " CLM_YEAR " INTEGER, " CLM_RATING " INTEGER, " CLM_GENRE " TEXT, " CLM_GROUPING " TEXT, " CLM_TRACKNUMBER " INTEGER, " CLM_DATEADDED " INTEGER, " CLM_BPM " INTEGER, " CLM_BITRATE " INTEGER, " CLM_COMMENT " TEXT, " CLM_PLAYCOUNT" INTEGER, " CLM_COMPOSER " TEXT, " CLM_PREVIEW " TEXT)"); if (!query.exec(strQuery.arg(m_tempTableName))) { LOG_FAILED_QUERY(query); } QString strQuery2("INSERT INTO %1" " (" CLM_TRACK_ID ", " CLM_VIEW_ORDER ", " CLM_ARTIST ", " CLM_TITLE ", " CLM_DURATION ", " CLM_URI ", " CLM_ALBUM ", " CLM_ALBUM_ARTIST ", " CLM_YEAR ", " CLM_RATING ", " CLM_GENRE ", " CLM_GROUPING ", " CLM_TRACKNUMBER ", " CLM_DATEADDED ", " CLM_BPM ", " CLM_BITRATE ", " CLM_COMMENT ", " CLM_PLAYCOUNT ", " CLM_COMPOSER ") " "VALUES (:" CLM_TRACK_ID ", :" CLM_VIEW_ORDER ", :" CLM_ARTIST ", :" CLM_TITLE ", :" CLM_DURATION ", :" CLM_URI ", :" CLM_ALBUM ", :" CLM_ALBUM_ARTIST ", :" CLM_YEAR ", :" CLM_RATING ", :" CLM_GENRE ", :" CLM_GROUPING ", :" CLM_TRACKNUMBER ", :" CLM_DATEADDED ", :" CLM_BPM ", :" CLM_BITRATE ", :" CLM_COMMENT ", :" CLM_PLAYCOUNT ", :" CLM_COMPOSER ") "); query.prepare(strQuery2.arg(m_tempTableName)); QList<struct BansheeDbConnection::PlaylistEntry> list = m_pConnection->getPlaylistEntries(playlistId); if (!list.isEmpty()) { beginInsertRows(QModelIndex(), 0, list.size() - 1); foreach (struct BansheeDbConnection::PlaylistEntry entry, list) { query.bindValue(":" CLM_TRACK_ID, entry.trackId); // Note: entry.viewOrder is 0 for all tracks if they have // never been sorted by the user query.bindValue(":" CLM_VIEW_ORDER, entry.viewOrder + 1); query.bindValue(":" CLM_ARTIST, entry.pArtist->name); query.bindValue(":" CLM_TITLE, entry.pTrack->title); query.bindValue(":" CLM_DURATION, entry.pTrack->duration / 1000); query.bindValue(":" CLM_URI, entry.pTrack->uri); query.bindValue(":" CLM_ALBUM, entry.pAlbum->title); query.bindValue(":" CLM_ALBUM_ARTIST, entry.pAlbumArtist->name); query.bindValue(":" CLM_YEAR, entry.pTrack->year); query.bindValue(":" CLM_RATING, entry.pTrack->rating); query.bindValue(":" CLM_GENRE, entry.pTrack->genre); query.bindValue(":" CLM_GROUPING, entry.pTrack->grouping); query.bindValue(":" CLM_TRACKNUMBER, entry.pTrack->tracknumber); QDateTime timeAdded; timeAdded.setTime_t(entry.pTrack->dateadded); query.bindValue(":" CLM_DATEADDED, timeAdded.toString(Qt::ISODate)); query.bindValue(":" CLM_BPM, entry.pTrack->bpm); query.bindValue(":" CLM_BITRATE, entry.pTrack->bitrate); query.bindValue(":" CLM_COMMENT, entry.pTrack->comment); query.bindValue(":" CLM_PLAYCOUNT, entry.pTrack->playcount); query.bindValue(":" CLM_COMPOSER, entry.pTrack->composer); if (!query.exec()) { LOG_FAILED_QUERY(query); } // qDebug() << "-----" << entry.pTrack->title << query.executedQuery(); }