本文整理汇总了C++中QSqlRecord::isGenerated方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlRecord::isGenerated方法的具体用法?C++ QSqlRecord::isGenerated怎么用?C++ QSqlRecord::isGenerated使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlRecord
的用法示例。
在下文中一共展示了QSqlRecord::isGenerated方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isGenerated
bool QSqlRecordProto::isGenerated(int index) const
{
QSqlRecord *item = qscriptvalue_cast<QSqlRecord*>(thisObject());
if (item)
return item->isGenerated(index);
return false;
}
示例2: exec
bool QSqlTableModelPrivate::exec(const QString &stmt, bool prepStatement,
const QSqlRecord &rec, const QSqlRecord &whereValues)
{
if (stmt.isEmpty())
return false;
// lazy initialization of editQuery
if (editQuery.driver() != db.driver())
editQuery = QSqlQuery(db);
// workaround for In-Process databases - remove all read locks
// from the table to make sure the editQuery succeeds
if (db.driver()->hasFeature(QSqlDriver::SimpleLocking))
const_cast<QSqlResult *>(query.result())->detachFromResultSet();
if (prepStatement) {
if (editQuery.lastQuery() != stmt) {
if (!editQuery.prepare(stmt)) {
error = editQuery.lastError();
return false;
}
}
int i;
for (i = 0; i < rec.count(); ++i) {
if (rec.isGenerated(i) && rec.value(i).type() != QVariant::Invalid)
editQuery.addBindValue(rec.value(i));
}
for (i = 0; i < whereValues.count(); ++i) {
if (whereValues.isGenerated(i))
editQuery.addBindValue(whereValues.value(i));
}
if (!editQuery.exec()) {
error = editQuery.lastError();
return false;
}
} else {
if (!editQuery.exec(stmt)) {
error = editQuery.lastError();
return false;
}
}
return true;
}
示例3: translateFieldNames
/*! \internal
*/
void QSqlRelationalTableModelPrivate::translateFieldNames(QSqlRecord &values) const
{
for (int i = 0; i < values.count(); ++i) {
if (relations.value(i).isValid()) {
QVariant v = values.value(i);
bool gen = values.isGenerated(i);
values.replace(i, baseRec.field(i));
values.setValue(i, v);
values.setGenerated(i, gen);
}
}
}
示例4: setRecord
/*!
Applies \a values to the \a row in the model. The source and
target fields are mapped by field name, not by position in
the record.
Note that the generated flags in \a values are preserved
and determine whether the corresponding fields are used when
changes are submitted to the database. The caller should
remember to set the generated flag to FALSE for fields
where the database is meant to supply the value, such as an
automatically incremented ID.
For edit strategies OnFieldChange and OnRowChange, a row may
receive a change only if no other row has a cached change.
Changes are submitted immediately. Submitted changes are not
reverted upon failure.
Returns \c true if all the values could be set; otherwise returns
false.
\sa record(), editStrategy()
*/
bool QSqlTableModel::setRecord(int row, const QSqlRecord &values)
{
Q_D(QSqlTableModel);
Q_ASSERT_X(row >= 0, "QSqlTableModel::setRecord()", "Cannot set a record to a row less than 0");
if (d->busyInsertingRows)
return false;
if (row >= rowCount())
return false;
if (d->cache.value(row).op() == QSqlTableModelPrivate::Delete)
return false;
if (d->strategy != OnManualSubmit && d->cache.value(row).submitted() && isDirty())
return false;
// Check field names and remember mapping
typedef QMap<int, int> Map;
Map map;
for (int i = 0; i < values.count(); ++i) {
int idx = d->nameToIndex(values.fieldName(i));
if (idx == -1)
return false;
map[i] = idx;
}
QSqlTableModelPrivate::ModifiedRow &mrow = d->cache[row];
if (mrow.op() == QSqlTableModelPrivate::None)
mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update,
QSqlQueryModel::record(row));
Map::const_iterator i = map.constBegin();
const Map::const_iterator e = map.constEnd();
for ( ; i != e; ++i) {
// have to use virtual setData() here rather than mrow.setValue()
EditStrategy strategy = d->strategy;
d->strategy = OnManualSubmit;
QModelIndex cIndex = createIndex(row, i.value());
setData(cIndex, values.value(i.key()));
d->strategy = strategy;
// setData() sets generated to TRUE, but source record should prevail.
if (!values.isGenerated(i.key()))
mrow.recRef().setGenerated(i.value(), false);
}
if (d->strategy != OnManualSubmit)
return submit();
return true;
}
示例5: translateFieldNames
/*! \internal
*/
void QSqlRelationalTableModelPrivate::translateFieldNames(int row, QSqlRecord &values) const
{
Q_Q(const QSqlRelationalTableModel);
for (int i = 0; i < values.count(); ++i) {
int realCol = q->indexInQuery(q->createIndex(row, i)).column();
if (realCol != -1 && relations.value(realCol).isValid()) {
QVariant v = values.value(i);
bool gen = values.isGenerated(i);
values.replace(i, baseRec.field(realCol));
values.setValue(i, v);
values.setGenerated(i, gen);
}
}
}
示例6: record
/*!
\since 5.0
Returns the record at \a row in the model.
If \a row is the index of a valid row, the record
will be populated with values from that row.
If the model is not initialized, an empty record will be
returned.
\sa QSqlRecord::isEmpty()
*/
QSqlRecord QSqlTableModel::record(int row) const
{
Q_D(const QSqlTableModel);
// the query gets the values from virtual data()
QSqlRecord rec = QSqlQueryModel::record(row);
// get generated flags from the cache
const QSqlTableModelPrivate::ModifiedRow mrow = d->cache.value(row);
if (mrow.op() != QSqlTableModelPrivate::None) {
const QSqlRecord crec = mrow.rec();
for (int i = 0, cnt = rec.count(); i < cnt; ++i)
rec.setGenerated(i, crec.isGenerated(i));
}
return rec;
}
示例7: agregarServicio
/*!
\fn MPeluqueria::agregarServicio( QVariant desc, QVariant precio, QVariant fecha, QVariant id_mascota )
*/
bool MPeluqueria::agregarServicio( QVariant desc, QVariant precio, QVariant fecha, QVariant id_mascota )
{
/* if( !mascota.isValid() )
{
qDebug( "Inidce Mascota es invalido" );
return false;
}
QVariant id_mascota = relationModel( 1 )->data( mascota, 0 );
if( id_mascota.isValid() && id_mascota.toInt() <= 0 )
{return false;}*/
QSqlRecord registro = record();
registro.setValue( 1, id_mascota );
registro.setValue( 2, desc );
registro.setValue( 3, precio );
registro.setValue( 4, fecha );
for( int i = 0; i<registro.count(); i++ )
{
qDebug( QString( "Campo: %1, generado? %2, null? %3, valor? |%4|" ).arg( registro.fieldName( i ) ).arg( registro.isGenerated( i ) ).arg( registro.isNull( i ) ).arg( registro.value( i ).toString() ).toLocal8Bit() );
}
if( insertRecord( -1, registro ) )
{
qDebug( "Registro de servicio agregado correctamente" );
return true;
}
else
{
qDebug( "Error al insertar registro de servicio de mascota" );
qDebug( QString( "Detalles: tipo: %1, errno: %2, descripcion: %3" ).arg( lastError().type() ).arg( lastError().number() ).arg( lastError().text() ).toLocal8Bit() );
return false;
}
}