void DataManager :: saveArticle(const ArticleItem& articleItem) { qDebug() << "Saving article with title" << articleItem.title(); QSqlQuery selectQuery(db); selectQuery.prepare("SELECT * FROM Articles WHERE url = :url"); selectQuery.bindValue(":url",articleItem.url()); if(!selectQuery.exec()) { qWarning() << "Query failed" << selectQuery.lastError(); } int recCount = 0; while( selectQuery.next() ) { recCount++; } if(recCount > 0 ) { qDebug() << "Already existed, not saving"; return; } QSqlQuery query; query.prepare("INSERT INTO Articles(title,url,points,commentCount,postedAgo,commentsUrl) VALUES(:title,:url,:points,:commentCount,:postedAgo,:commentsUrl)"); query.bindValue(":title",articleItem.title()); query.bindValue(":url",articleItem.url().toString()); query.bindValue(":points",articleItem.points()); query.bindValue(":commentCount",articleItem.commentCount()); query.bindValue(":postedAgo",articleItem.postedAgo()); query.bindValue(":commentsUrl",articleItem.commentsUrl().toString()); if(!query.exec()) { qWarning() << "QUERY FAILED " << query.lastError(); } }
void QTrackerDirectSyncResult::runQuery() { if (statementType() == QSparqlQuery::AskStatement || statementType() == QSparqlQuery::SelectStatement) { selectQuery(); } else if (statementType() == QSparqlQuery::InsertStatement || statementType() == QSparqlQuery::DeleteStatement) { updateQuery(); } }
void SearchEdit::focusInEvent(QFocusEvent *event) { QLineEdit::focusInEvent(event); // Do not change default behaviour when focused with mouse if (event->reason() == Qt::MouseFocusReason) return; selectQuery(); m_focusing = true; }
qint64 HistoryManager::getRecord(const QLatin1String &table, const QVariantHash &values) { const QStringList keys = values.keys(); QStringList placeholders; for (int i = 0; i < keys.count(); ++i) { placeholders.append(QString('?')); } QSqlQuery selectQuery(QSqlDatabase::database(QLatin1String("browsingHistory"))); selectQuery.prepare(QStringLiteral("SELECT \"id\" FROM \"%1\" WHERE \"%2\" = ?;").arg(table).arg(keys.join(QLatin1String("\" = ? AND \"")))); for (int i = 0; i < keys.count(); ++i) { selectQuery.bindValue(i, values[keys.at(i)]); } selectQuery.exec(); if (selectQuery.first()) { return selectQuery.record().field(QLatin1String("id")).value().toLongLong(); } QSqlQuery insertQuery(QSqlDatabase::database(QLatin1String("browsingHistory"))); insertQuery.prepare(QStringLiteral("INSERT INTO \"%1\" (\"%2\") VALUES(%3);").arg(table).arg(keys.join(QLatin1String("\", \""))).arg(placeholders.join(QLatin1String(", ")))); for (int i = 0; i < keys.count(); ++i) { insertQuery.bindValue(i, values[keys.at(i)]); } insertQuery.exec(); return insertQuery.lastInsertId().toULongLong(); }
bool checkConnectivity(ConnectionPtr connection) { // checks to see if this server has connectivity // it does so by finding two servers (from the TestServer table) in other groups, and hence on other carriers // if both of these pings fail then we can assume that it is our connectivity // we can then re-schedule the job // now also used to see if we are down before the end of the check std::string testHost; std::string externalTestHost; std::string externalTestHost1; std::string externalTestHost2; int ourGroup = 0; int testGroup = 0; ResultPtr result; ncc::safe_array<char> selectQuery(1024); bool retVal = true; std::string site; std::string clusterGroup; Trace("checkConnectivity", "CConfig::getServerID()", CConfig::getServerID()); try { #ifdef SHARD_AWARE ConnectionPtr passportShardConnection( new Connection( CConfig::getPassportDbServer(), CConfig::getPassportDbDatabase(), CConfig::getPassportDbUser(), CConfig::getPassportDbPass(), CConfig::getDBRetryTime())); // get the group of this test server snprintf(selectQuery, selectQuery.size(), SQL_SCS_TEST_GROUP_CG3, CConfig::getServerID()); Trace("Issuing query",selectQuery,0); result = passportShardConnection->Query(selectQuery); Trace("Rows:","",result->GetRowCount()); if (result->GetRowCount() > 0) { result->Next(); RowPtr row = result->GetCurrentRow(); ourGroup = row->GetFieldInteger(1); } snprintf(selectQuery, selectQuery.size(), SQL_SCS_RETEST_SERVERS_GROUP_RAND_CG3, SC_SERVER_STATUS_LIVE, ourGroup, 0); Trace("Issuing query",selectQuery,0); result = passportShardConnection->Query(selectQuery); Trace("Rows:","",result->GetRowCount()); #else // get the group of this test server snprintf(selectQuery, selectQuery.size(), SQL_SCS_TEST_GROUP, CConfig::getServerID()); Trace("Issuing query",selectQuery,0); result = connection->Query(selectQuery); Trace("Rows:","",result->GetRowCount()); if (result->GetRowCount() > 0) { result->Next(); RowPtr row = result->GetCurrentRow(); ourGroup = row->GetFieldInteger(1); site = row->GetFieldString(2); clusterGroup = row->GetFieldString(3); } snprintf(selectQuery, selectQuery.size(), SQL_SCS_RETEST_SERVERS_GROUP_RAND, SC_SERVER_STATUS_LIVE, ourGroup, site.c_str(), clusterGroup.c_str()); Trace("Issuing query",selectQuery,0); result = connection->Query(selectQuery); Trace("Rows:","",result->GetRowCount()); #endif int testGroup1 = 0; int testGroup2 = 0; std::string externalTestHost1; std::string externalTestHost2; if (result->GetRowCount() > 0) { while(result->Next()) { RowPtr row = result->GetCurrentRow(); testHost = row->GetFieldString(2); testGroup = row->GetFieldInteger(3); externalTestHost = row->GetFieldString(4); Trace("externalHost",externalTestHost.c_str(),testGroup); if (testGroup1 == 0) { // set this to be the first group to test testGroup1 = testGroup; externalTestHost1 = externalTestHost; } else if (testGroup1 != testGroup) { // different group - use for the second test testGroup2 = testGroup; externalTestHost2 = externalTestHost; // all done now break; } // else must be same group as testGroup1 - ignore it } bool ping1OK = true; bool ping2OK = true; if ((testGroup1 != 0) && (externalTestHost1 != "")) { Trace("Tesing against group 1",externalTestHost1.c_str(),testGroup1); ping1OK = pingSiteAvailable(externalTestHost1); } else { // nothing to test - assume it worked ? Trace("Tesing against group 1","n/a",testGroup1); } if ((testGroup2 != 0) && (externalTestHost2 != "")) { Trace("Tesing against group 2",externalTestHost2.c_str(),testGroup2); ping2OK = pingSiteAvailable(externalTestHost2); } else if ((testGroup1 != 0) && (externalTestHost1 != "")) { // we tested a 'real' #1 - test the one from sc.opt Trace("Tesing against group 2 - sc.opt",CConfig::getPing1Name().c_str(),testGroup2); ping2OK = pingSiteAvailable(CConfig::getPing1Name()); } else { // else nothing to test - assume it worked ? Trace("Tesing against group 2","n/a",testGroup2); } if (!ping1OK && !ping2OK) { // first two have failed // check yahoo if (!pingSiteAvailable(CConfig::getPing1Name())) { retVal = false; } } } } catch (const std::exception& e) { Trace("Exception caught", e.what(), 0); printf("Error: %s\n", e.what()); } return retVal; }
int db::isPacket(void) { return selectQuery(); }