本文整理汇总了C++中QSqlRecord函数的典型用法代码示例。如果您正苦于以下问题:C++ QSqlRecord函数的具体用法?C++ QSqlRecord怎么用?C++ QSqlRecord使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了QSqlRecord函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeRow
/*!
Deletes the given \a row from the currently active database table.
This is a low-level method that operates directly on the database
and should not be called directly. Use removeRow() or removeRows()
to delete values. The model will decide depending on its edit strategy
when to modify the database.
Returns true if the row was deleted; otherwise returns false.
\sa removeRow(), removeRows()
*/
bool QSqlTableModel::deleteRowFromTable(int row)
{
Q_D(QSqlTableModel);
emit beforeDelete(row);
const QSqlRecord whereValues = d->strategy == OnManualSubmit ? d->cache[row].primaryValues : d->primaryValues(row);
bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries);
QString stmt = d->db.driver()->sqlStatement(QSqlDriver::DeleteStatement,
d->tableName,
QSqlRecord(),
prepStatement);
QString where = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement,
d->tableName,
whereValues,
prepStatement);
if (stmt.isEmpty() || where.isEmpty()) {
d->error = QSqlError(QLatin1String("Unable to delete row"), QString(),
QSqlError::StatementError);
return false;
}
stmt.append(QLatin1Char(' ')).append(where);
return d->exec(stmt, prepStatement, QSqlRecord() /* no new values */, whereValues);
}
示例2: QSqlRecord
QSqlRecord XSqlTableModelProto::record(int row) const
{
XSqlTableModel *item = qscriptvalue_cast<XSqlTableModel*>(thisObject());
if (item)
return item->record(row);
return QSqlRecord();
}
示例3: removeRow
/*!
Deletes the given \a row from the currently active database table.
This is a low-level method that operates directly on the database
and should not be called directly. Use removeRow() or removeRows()
to delete values. The model will decide depending on its edit strategy
when to modify the database.
Returns true if the row was deleted; otherwise returns false.
\sa removeRow(), removeRows()
*/
bool QSqlTableModel::deleteRowFromTable(int row)
{
Q_D(QSqlTableModel);
emit beforeDelete(row);
QSqlRecord rec = d->primaryValues(row);
bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries);
QString stmt = d->db.driver()->sqlStatement(QSqlDriver::DeleteStatement,
d->tableName,
QSqlRecord(),
prepStatement);
QString where = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement,
d->tableName,
rec,
prepStatement);
if (stmt.isEmpty() || where.isEmpty()) {
d->error = QSqlError(QLatin1String("Unable to delete row"), QString(),
QSqlError::StatementError);
return false;
}
stmt.append(QLatin1Char(' ')).append(where);
return d->exec(stmt, prepStatement, rec);
}
示例4: QSqlRecord
QSqlRecord XSqlQueryProto::record() const
{
XSqlQuery *item = qscriptvalue_cast<XSqlQuery*>(thisObject());
if (item)
return item->record();
return QSqlRecord();
}
示例5: agrpAdd
void FormLibraryEditor::agrpAdd()
{
if (modelAgeGroups->insertRecord(-1, QSqlRecord())) {
ui->tableViewAgeGroups->update();
ui->actionAgeGroupCommit->setEnabled(true);
}
}
示例6: QSqlRecord
QSqlRecord SqliteDriver::record2(const QString &tblname) const
{
if (!isOpen() || !dataBase_)
return QSqlRecord();
return recordInfo(tblname).toRecord();
}
示例7: QSqlRecord
QVariant EventColorQSqlQueryModel::data(const QModelIndex &index, int role) const
{
QVariant value = QSqlQueryModel::data(index, role);
if (role == Qt::BackgroundColorRole)
{
int level= QSqlRecord (record(index.row())).value(4).toInt();
switch(level)
{
case 1 : return qVariantFromValue(QColor(0xff,0xca,0x00));
case 2 : return qVariantFromValue(QColor(Qt::red));
case 3 : return qVariantFromValue(QColor(Qt::gray));
case 4 : return qVariantFromValue(QColor(Qt::green));
}
}
if(role==Qt::DisplayRole )
{
if (index.column() == 4)
{
switch(value.toInt())
{
case 0 : return qVariantFromValue(tr("Program"));
case 1 : return qVariantFromValue(tr("Level I"));
case 2 : return qVariantFromValue(tr("Level II"));
case 3 : return qVariantFromValue(tr("Fault"));
case 4 : return qVariantFromValue(tr("Correct"));
}
}
}
return value;
}
示例8: query
QSqlRecord GenericDAO::getRecord(const QSqlDatabase& db, const QString& where, const QVariantList& bindValues) const
{
if (db.isOpen())
{
QSqlQuery query(db);
query.setForwardOnly(true);
QString sql = QString("SELECT * FROM %1 WHERE %2").arg(m_table).arg(where);
query.prepare(sql);
int n = bindValues.size();
for (int i = 0; i < n; i++)
{
query.bindValue(i, bindValues[i]);
}
if (query.exec())
{
if (query.next())
{
return query.record();
}
}
else
DatabaseException(query).displayMessage();
}
return QSqlRecord();
}
示例9: QSqlRecord
QSqlRecord QSQLiteDriver::record(const QString &tblname) const
{
if (!isOpen())
return QSqlRecord();
return recordInfo(tblname).toRecord();
}
示例10: QSqlRecord
QSqlRecord FormFirewallRules::getFirewallRulesetFromShortName(QString shortName)
{
QSqlRecord result = QSqlRecord();
QSqlQuery qry;
QVariant sn(shortName);
qry.prepare(" select id, name, shortname, rules "
" from ruleset "
" where shortname = :shortname");
qry.bindValue(":shortname", sn);
if (qry.exec())
{
if (qry.first())
{
result = qry.record();
}
else
{
qDebug("FormFirewallRules::getFirewallRulesetFromShortName Can't move to first row [%s]",
qry.lastError().text().toAscii().data());
}
}
else
{
qDebug("FormFirewallRules::getFirewallRulesetFromShortName query failed [%s]",
qry.lastError().text().toAscii().data());
}
return result;
}
示例11: QSqlRecord
/* ********************************************************************* */
QSqlRecord BarlowsDataMapper::currentRecord()
{
if (lastRowNumberSelected == -1) {
return QSqlRecord();
} else {
return tableModel->record(lastRowNumberSelected);
}
}
示例12: QSqlRecord
QSqlRecord TargetsDialog::currentRecord()
{
if (lastRowNumberSelected == -1) {
return QSqlRecord();
} else {
return tableModel->record(lastRowNumberSelected);
}
}
示例13: QSqlRecord
void FormLibraryEditor::teamAdd()
{
int row = modelTeams->rowCount();
modelTeams->insertRecord(-1, QSqlRecord());
ui->tableViewTeams->setCurrentIndex(modelTeams->index(row, modelTeams->fieldIndex("label")));
ui->actionTeamCommit->setEnabled(true);
ui->actionDifficultyDelete->setDisabled(true);
}
示例14: isForwardOnly
/*!
Resets the model and sets the data provider to be the given \a
query. Note that the query must be active and must not be
isForwardOnly().
lastError() can be used to retrieve verbose information if there
was an error setting the query.
\sa query(), QSqlQuery::isActive(), QSqlQuery::setForwardOnly(), lastError()
*/
void QSqlQueryModel::setQuery(const QSqlQuery &query)
{
Q_D(QSqlQueryModel);
QSqlRecord newRec = query.record();
bool columnsChanged = (newRec != d->rec);
bool hasQuerySize = query.driver()->hasFeature(QSqlDriver::QuerySize);
bool hasNewData = (newRec != QSqlRecord()) || !query.lastError().isValid();
if (d->colOffsets.size() != newRec.count() || columnsChanged)
d->initColOffsets(newRec.count());
bool mustClearModel = d->bottom.isValid();
if (mustClearModel) {
d->atEnd = true;
beginRemoveRows(QModelIndex(), 0, qMax(d->bottom.row(), 0));
d->bottom = QModelIndex();
}
d->error = QSqlError();
d->query = query;
d->rec = newRec;
if (mustClearModel)
endRemoveRows();
d->atEnd = false;
if (columnsChanged && hasNewData)
reset();
if (!query.isActive() || query.isForwardOnly()) {
d->atEnd = true;
d->bottom = QModelIndex();
if (query.isForwardOnly())
d->error = QSqlError(QLatin1String("Forward-only queries "
"cannot be used in a data model"),
QString(), QSqlError::ConnectionError);
else
d->error = query.lastError();
return;
}
QModelIndex newBottom;
if (hasQuerySize && d->query.size() > 0) {
newBottom = createIndex(d->query.size() - 1, d->rec.count() - 1);
beginInsertRows(QModelIndex(), 0, qMax(0, newBottom.row()));
d->bottom = createIndex(d->query.size() - 1, columnsChanged ? 0 : d->rec.count() - 1);
d->atEnd = true;
endInsertRows();
} else {
newBottom = createIndex(-1, d->rec.count() - 1);
}
d->bottom = newBottom;
queryChange();
// fetchMore does the rowsInserted stuff for incremental models
fetchMore();
}
示例15: entryFromIndex
QSqlRecord LibraryModel::record(const QModelIndex &index)
{
LibraryEntry * item = entryFromIndex(index);
if(item->isDirNode()) {
return QSqlRecord();
} else {
return item->record();
}
}