本文整理汇总了C++中QSqlRecord::indexOf方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlRecord::indexOf方法的具体用法?C++ QSqlRecord::indexOf怎么用?C++ QSqlRecord::indexOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlRecord
的用法示例。
在下文中一共展示了QSqlRecord::indexOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadData
bool DataModel::LoadData(){
if(!QSqlDatabase::contains(ConstantsHelper::CONNECTION_NAME)){
return false;
}
QSqlDatabase db = QSqlDatabase::database(ConstantsHelper::CONNECTION_NAME);
QSqlQuery query(db);
qDebug()<<ConstantsHelper::SELECT_ALL_SYSTEMS_QUERY;
if (!query.exec(ConstantsHelper::SELECT_ALL_SYSTEMS_QUERY)){
return false;
};
QSqlRecord rec = query.record();
int id;
QString name;
while(query.next()){
id = query.value(rec.indexOf("ID")).toInt();
name = query.value(rec.indexOf("NAME")).toString();
SpectrumSystem* spSys = new SpectrumSystem(id, name, this);
m_vSpectrSystem.push_back(spSys);
}
return true;
}
示例2: readDb
void MainWindow::readDb()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
/* db.setHostName("localhost");
db.setDatabaseName("technolo");
db.setUserName("root");
db.setPassword("");
*/
db.setDatabaseName(QDir::current().absoluteFilePath("technologybasic.db"));
db.open();
QSqlQuery query1("SELECT * from jos_content order by title;");
QSqlRecord record = query1.record();
while (query1.next())
{
TitleVar << query1.value(record.indexOf("title")).toString();
TextVar << query1.value(record.indexOf("introtext")).toString();
}
QSqlQuery query2("SELECT * from jos_categories");
QSqlRecord record1 = query2.record();
while (query2.next())
{
CatVar << query2.value(record1.indexOf("catalias")).toString();
}
}
示例3: ListNpcClick
void QuestInfo::ListNpcClick()
{
ButtomOpenPClick();
ui.listQuest->clear();
QMessageBox a;
QSqlQuery idNPCquery;
idNPCquery = DB.query("SELECT id FROM questNPC WHERE name = '"+ui.listNpc->currentItem()->text()+"';");
QSqlRecord recIdNpc = idNPCquery.record();
while (idNPCquery.next())
{
idNPC = idNPCquery.value(recIdNpc.indexOf("id")).toInt();
}
QSqlQuery NameQuest = DB.query("SELECT nameQuest FROM quest WHERE idNPC = '"+IntToQStr(idNPC)+"';");
QSqlRecord recNameQuest = NameQuest.record();
while (NameQuest.next())
{
ui.listQuest->addItem(NameQuest.value(recNameQuest.indexOf("nameQuest")).toString());
}
}
示例4: getUser
User MainDataBase::getUser(QString name)
{
if (db.isOpen())
{
QSqlQuery query;
QString strQuery = QString("SELECT * FROM ScrabbleDataBase WHERE name ='%1'").arg(name);
bool result = query.exec(strQuery);
QSqlRecord record = query.record();
assert(result);
while (query.next())
{
int loseCount = query.value(record.indexOf("loseCount")).toInt();
int winCount = query.value(record.indexOf("winCount")).toInt();
int usersCS = query.value(record.indexOf("usersCurrentScore")).toInt();
int botsCS = query.value(record.indexOf("botsCurrentScore")).toInt();
QString board = query.value(record.indexOf("currentBoard")).toString();
string sBoard = "";
for (int i = 0; i < (int)board.size(); ++i)
sBoard += board[i].toLatin1();
return User(name, loseCount, winCount, sBoard, usersCS, botsCS);
}
addUser(name);
return getUser(name);
}
}
示例5: qDebug
QVector<CObject*> CKnowledgeDB::getAllObject()
{
QVector<CObject *> objects;
QSqlQuery query;
QSqlRecord record;
query.prepare("SELECT f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,k FROM object");
if (!query.exec()) {
qDebug() << QString("Failed to obtain the object in DB : ") + m_dataBaseName << "\n"
<< m_dataBase.lastError().text();
return objects;
}
record = query.record();
while (query.next()) {
CObject *obj = new CObject();
for (int i=1; i<=15; ++i) {
QString featureName = QString("f%1").arg(i);
QVariant value = query.value(record.indexOf(featureName));
int testor = getTestor(i);
obj->addFeature(CFactoryFeature::createFeature(i , value, testor));
}
obj->setClass((EClass)query.value(record.indexOf("k")).toInt());
objects.append(obj);
}
return objects;
}
示例6: query
/*!
* \brief Edict2::find Search for a verb in the database, and return its type.
* \param verb The verb in dictionary form (u-form), eg. 食べる, 飲む, 行く, 来る, etc.
* \return The type of the verb if found (See: VerbType::EdictType)
*/
EdictType Edict2::find(QString verb)
{
int result= 0;
if (verbdb.open()) {
//qDebug() << "DB connected";
QSqlQuery query(verbdb);
query.exec("SELECT * FROM tkanji WHERE kanji='" + verb + "';");
QSqlRecord record = query.record();
if (query.next()) {
result = query.value(record.indexOf("idtype")).toInt();
//qDebug() << "Verb kanji found" << result;
}
else
{
query.exec("SELECT * FROM tkana WHERE kana='" + verb + "';");
record = query.record();
if (query.next()) {
result = query.value(record.indexOf("idtype")).toInt();
//qDebug() << "Verb kana found" << result;
}
}
} else {
qDebug() << "DB not connecting";
}
//qDebug() << result;
verbdb.close();
return (EdictType) result;
}
示例7: updateMeeting
void DetailMeeting::updateMeeting()
{
int duration_minute = (meeting_duration->time().hour()*60) + meeting_duration->time().minute();
QDateTime *date_begin_real = new QDateTime(QDate(meeting_dt_begin->date().year(),meeting_dt_begin->date().month(),meeting_dt_begin->date().day()),meeting_dt_begin->time());
QString dt_begin;
dt_begin = QString::number(meeting_dt_begin->date().year()) + "/" + QString::number(meeting_dt_begin->date().month()) + "/" + QString::number(meeting_dt_begin->date().day()) + " " + QString::number(meeting_dt_begin->time().hour()) + ":" + QString::number(meeting_dt_begin->time().minute());
QString dt_end;
dt_end = QString::number(meeting_dt_end->date().year()) + "/" + QString::number(meeting_dt_end->date().month()) + "/" + QString::number(meeting_dt_end->date().day()) + " " + QString::number(meeting_dt_end->time().hour()) + ":" + QString::number(meeting_dt_end->time().minute());
QSqlQuery query;
query.prepare("SELECT * FROM Meeting where room = :room");
query.bindValue(":room", id_room);
query.exec();
QSqlRecord rec = query.record();
while(query.next())
{
QStringList date_begin = query.value(rec.indexOf("date_begin")).toString().split(" ").at(0).split("/");
QStringList time_begin = query.value(rec.indexOf("date_begin")).toString().split(" ").at(1).split(":");
QDate date_begin_edit(date_begin.at(0).toInt(),date_begin.at(1).toInt(),date_begin.at(2).toInt());
QTime time_begin_edit(time_begin.at(0).toInt(),time_begin.at(1).toInt(),0);
QStringList date_end_bis = query.value(rec.indexOf("date_end")).toString().split(" ").at(0).split("/");
QStringList time_end = query.value(rec.indexOf("date_end")).toString().split(" ").at(1).split(":");
QDate date_end_edit(date_end_bis.at(0).toInt(),date_end_bis.at(1).toInt(),date_end_bis.at(2).toInt());
QTime time_end_edit(time_end.at(0).toInt(),time_end.at(1).toInt(),0);
QDateTime datetime_begin(date_begin_edit,time_begin_edit);
QDateTime datetime_end(date_end_edit,time_end_edit);
if(date_begin_real->operator >(datetime_begin) && date_begin_real->operator <(datetime_end))
{
QMessageBox::critical(this, "Salle indisponible", "La salle selectionné est indisponible.");
return;
}
}
query.prepare("SELECT * FROM Meeting where id_meeting = :id_meeting");
query.bindValue(":id_meeting", meeting_id);
query.exec();
rec = query.record();
query.next();
sendEmailUpdateMeeting(meeting_id,dt_begin);
query.prepare("Update Meeting set date_begin = :date_begin , date_end =:date_end , duration = :duration WHERE id = :id_meeting");
query.bindValue(":date_begin", dt_begin);
query.bindValue(":date_end", dt_end);
query.bindValue(":duration", duration_minute);
query.bindValue(":id_meeting", meeting_id);
query.exec();
this->close();
emit notifyRefreshList();
}
示例8: select
void BaseSqlTableModel::select() {
if (!m_bInitialized) {
return;
}
// We should be able to detect when a select() would be a no-op. The DAO's
// do not currently broadcast signals for when common things happen. In the
// future, we can turn this check on and avoid a lot of needless
// select()'s. rryan 9/2011
// if (!m_bDirty) {
// if (sDebug) {
// qDebug() << this << "Skipping non-dirty select()";
// }
// return;
// }
if (sDebug) {
qDebug() << this << "select()";
}
QTime time;
time.start();
QString columns = m_tableColumnsJoined;
QString orderBy = orderByClause();
QString queryString = QString("SELECT %1 FROM %2 %3")
.arg(columns, m_tableName, orderBy);
if (sDebug) {
qDebug() << this << "select() executing:" << queryString;
}
QSqlQuery query(m_database);
// This causes a memory savings since QSqlCachedResult (what QtSQLite uses)
// won't allocate a giant in-memory table that we won't use at all.
query.setForwardOnly(true);
query.prepare(queryString);
if (!query.exec()) {
LOG_FAILED_QUERY(query);
return;
}
// Remove all the rows from the table. We wait to do this until after the
// table query has succeeded. See Bug #1090888.
// TODO(rryan) we could edit the table in place instead of clearing it?
if (m_rowInfo.size() > 0) {
beginRemoveRows(QModelIndex(), 0, m_rowInfo.size()-1);
m_rowInfo.clear();
m_trackIdToRows.clear();
endRemoveRows();
}
QSqlRecord record = query.record();
int idColumn = record.indexOf(m_idColumn);
QLinkedList<int> tableColumnIndices;
foreach (QString column, m_tableColumns) {
Q_ASSERT(record.indexOf(column) == m_tableColumnIndex[column]);
tableColumnIndices.push_back(record.indexOf(column));
}
示例9: query
QList<DataFile *> DataFileGateway::findFromFilePathList(const QStringList &a_file_path_list)
{
Q_ASSERT(!a_file_path_list.isEmpty());
QSqlQuery query(app_database_engine_->appDatabase());
query.prepare("SELECT * FROM " + table_name_ +
" WHERE DATA_FILE_NAME IN ( ':data_file_name_list' )");
query.bindValue(":data_file_name_list",a_file_path_list.join("','"));
query.exec();
QList<DataFile *> data_file_list;
QSqlRecord record = query.record();
int data_file_id_col_num = record.indexOf("DATA_FILE_ID");
int task_id_col_num = record.indexOf("TASK_ID");
int data_file_name_col_num = record.indexOf("DATA_FILE_NAME");
int import_time_col_num = record.indexOf("IMPORT_TIME");
int status_col_num = record.indexOf("STSTUS");
while(query.next())
{
DataFile *a_data_file = new DataFile(this->parent());
//fillFromRecord();
a_data_file->data_file_id = query.value(data_file_id_col_num).toInt();
a_data_file->task_id = query.value(task_id_col_num).toInt();
a_data_file->data_file_name = query.value(data_file_name_col_num).toString();
a_data_file->import_time = query.value(import_time_col_num).toString();
a_data_file->status = query.value(status_col_num).toString();
data_file_list.append(a_data_file);
}
return data_file_list;
}
示例10: constructCrateChildModel
void AutoDJFeature::constructCrateChildModel() {
// Create a crate table-model with a list of crates that have been added
// to the auto-DJ queue (and are visible).
QSqlTableModel crateListTableModel(this, m_pTrackCollection->getDatabase());
crateListTableModel.setTable(CRATE_TABLE);
crateListTableModel.setSort(crateListTableModel.fieldIndex(CRATETABLE_NAME),
Qt::AscendingOrder);
crateListTableModel.setFilter(CRATETABLE_AUTODJ_SOURCE + " = 1 AND " + CRATETABLE_SHOW + " = 1");
crateListTableModel.select();
while (crateListTableModel.canFetchMore()) {
crateListTableModel.fetchMore();
}
QSqlRecord tableModelRecord = crateListTableModel.record();
int nameColumn = tableModelRecord.indexOf(CRATETABLE_NAME);
int idColumn = tableModelRecord.indexOf(CRATETABLE_ID);
// Create a tree-item for each auto-DJ crate.
for (int row = 0; row < crateListTableModel.rowCount(); ++row) {
int id = crateListTableModel.data(
crateListTableModel.index(row, idColumn)).toInt();
QString name = crateListTableModel.data(
crateListTableModel.index(row, nameColumn)).toString();
m_crateList.append(qMakePair(id, name));
// Create the TreeItem for this crate.
TreeItem* item = new TreeItem(name, name, this, m_pCratesTreeItem);
m_pCratesTreeItem->appendChild(item);
}
}
示例11: replaceCacheRecordByServerRecord
QDateTime Database::replaceCacheRecordByServerRecord(const QSqlDatabase& dbCache, const QString& table, const QSqlQuery& queryMaster)
{
QDateTime updated;
QSqlRecord record = queryMaster.record();
int fieldUpdated = record.indexOf("updated");
if (fieldUpdated == -1)
{
fieldUpdated = record.indexOf("created");
}
Q_ASSERT(fieldUpdated > -1);
updated = record.value(fieldUpdated).toDateTime();
int n = record.count();
if (n > 1)
{
QString sql = QString("REPLACE INTO %1 (").arg(table);
bool first = true;
for (int i = 0; i < n; i++)
{
if (first)
first = false;
else
sql += ", ";
sql += record.fieldName(i);
}
sql += ") VALUES (";
first = true;
for (int i = 0; i < n; i++)
{
if (first)
first = false;
else
sql += ", ";
sql += "?";
}
sql += ")";
QSqlQuery queryCache(dbCache);
queryCache.setForwardOnly(true);
queryCache.prepare(sql);
for (int i = 0; i < n; i++)
{
QVariant v(record.value(i));
if (v.type() == QVariant::DateTime)
queryCache.bindValue(i, datetimeToString(v.toDateTime()));
else
queryCache.bindValue(i, v);
}
if (!queryCache.exec())
throw DatabaseException(queryCache);
}
return updated;
}
示例12: qDebug
void Model::DataContainer::loadRegions()
{
#ifdef APP_DEBUG
qDebug() << "========== Start loading regions ... ==========";
#endif
QString sql = "SELECT "
"regionID, regionName "
"FROM mapRegions "
"ORDER BY regionName ASC";
QSqlQuery query;
if (!query.exec(sql)) {
qFatal(qPrintable(tr("SQL error: %s").arg(query.lastError().text())));
}
while (query.next()) {
QSqlRecord rec = query.record();
DataContainer::regions.insert(
query.value(rec.indexOf("regionName")).toString(),
query.value(rec.indexOf("regionID")).toInt());
#ifdef APP_DEBUG
qDebug() << "Loaded region: " << query.value(rec.indexOf("regionName")).toString();
#endif
}
#ifdef APP_DEBUG
qDebug() << "========== End loading regions ==========";
#endif
}
示例13: mixerLoadWork
void WorkLoader::mixerLoadWork(int mixer){
if(mWork >= 0 && mixer >= 0 && (unsigned int)mixer < mNumMixers){
if(mLoaderThreads[mixer]->isRunning()){
qWarning("Mixer %d is currently loading a file", mixer);
return;
}
//build up query
QString fileQueryStr(cFileQueryString);
QString workQueryStr(cWorkInfoQueryString);
QString id;
id.setNum(mWork);
fileQueryStr.append(id);
workQueryStr.append(id);
//execute
mFileQuery.exec(fileQueryStr);
QSqlRecord rec = mFileQuery.record();
int audioFileCol = rec.indexOf("audio_file");
int beatFileCol = rec.indexOf("beat_file");
//if we can grab it
if(mFileQuery.first()){
QString audiobufloc = mFileQuery.value(audioFileCol).toString();
QString beatbufloc = mFileQuery.value(beatFileCol).toString();
//if we're syncing to this mixer then change the sync source
if(mMixerPanelModel->master()->syncSource() == (unsigned int)(mixer + 1))
mMixerPanelModel->master()->setSyncSource(0);
//emit a signal to unload the buffers of this mixer
emit(mixerLoaded(mixer, NULL, NULL));
//reset the mixer channel
mMixerPanelModel->mixerChannels()->at(mixer)->reset();
//use a thread to load the stuff!
mLoaderThreads[mixer]->start(mixer, mWork, audiobufloc, beatbufloc);
//indicate that we're loading
mWorkInfoQuery.exec(workQueryStr);
if(mWorkInfoQuery.first()){
rec = mWorkInfoQuery.record();
int titleCol = rec.indexOf("title");
int artistCol = rec.indexOf("artist");
QString loadingArtist("loading: ");
QString loadingTitle("loading: ");
loadingArtist.append(mWorkInfoQuery.value(artistCol).toString());
loadingTitle.append(mWorkInfoQuery.value(titleCol).toString());
mMixerPanelView->mixerChannels()->at(mixer)->DJMixerWorkInfo()->setArtistText(
loadingArtist);
mMixerPanelView->mixerChannels()->at(mixer)->DJMixerWorkInfo()->setTitleText(
loadingTitle);
mMixerPanelModel->mixerChannels()->at(mixer)->setWork(-1);
}
} else {
//XXX ERROR
}
} else {
//XXX no work selected
}
}
示例14: setWork
void WorkLoader::setWork(unsigned int mixer_index,
int work,
DataJockey::AudioBufferPtr audio_buffer,
DataJockey::BeatBufferPtr beat_buffer){
//build up query
QSqlRecord rec;
QString workQueryStr(cWorkInfoQueryString);
QString id;
id.setNum(work);
workQueryStr.append(id);
emit(mixerLoaded(mixer_index, audio_buffer, beat_buffer));
emit(mixerLoaded(mixer_index, work));
//set the info
mWorkInfoQuery.exec(workQueryStr);
if(mWorkInfoQuery.first()){
rec = mWorkInfoQuery.record();
int titleCol = rec.indexOf("title");
int artistCol = rec.indexOf("artist");
mMixerPanelView->mixerChannels()->at(mixer_index)->DJMixerWorkInfo()->setArtistText(
mWorkInfoQuery.value(artistCol).toString()
);
mMixerPanelView->mixerChannels()->at(mixer_index)->DJMixerWorkInfo()->setTitleText(
mWorkInfoQuery.value(titleCol).toString()
);
mMixerPanelModel->mixerChannels()->at(mixer_index)->setWork(work);
}
}
示例15: CheckRepairStatus
/** \fn DBUtil::CheckRepairStatus(MSqlQuery &query)
* \brief Parse the results of a CHECK TABLE or REPAIR TABLE run.
*
* This function reads the records returned by a CHECK TABLE or REPAIR TABLE
* run and determines the status of the table(s). The query should have
* columns Table, Msg_type, and Msg_text.
*
* The function properly handles multiple records for a single table. If the
* last record for a given table shows a status (Msg_type) of OK (Msg_text),
* the table is considered OK, even if an error or warning appeared before
* (this could be the case, for example, when an empty table is crashed).
*
* \param query An already-executed CHECK TABLE or REPAIR TABLE query whose
* results should be parsed.
* \return A list of names of not-OK (errored or crashed) tables
* \sa DBUtil::CheckTables(const bool, const QString)
* \sa DBUtil::RepairTables(const QStringList)
*/
QStringList DBUtil::CheckRepairStatus(MSqlQuery &query)
{
QStringList tables;
QSqlRecord record = query.record();
int table_index = record.indexOf("Table");
int type_index = record.indexOf("Msg_type");
int text_index = record.indexOf("Msg_text");
QString table, type, text, previous_table;
bool ok = true;
while (query.next())
{
table = query.value(table_index).toString();
type = query.value(type_index).toString();
text = query.value(text_index).toString();
if (table != previous_table)
{
if (!ok)
{
tables.append(previous_table);
ok = true;
}
previous_table = table;
}
// If the final row shows status OK, the table is now good
if ("status" == type.toLower() && "ok" == text.toLower())
ok = true;
else if ("error" == type.toLower() ||
("status" == type.toLower() && "ok" != text.toLower()))
ok = false;
}
// Check the last table in the list
if (!ok)
tables.append(table);
return tables;
}