本文整理汇总了C++中QSqlRecord::remove方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlRecord::remove方法的具体用法?C++ QSqlRecord::remove怎么用?C++ QSqlRecord::remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlRecord
的用法示例。
在下文中一共展示了QSqlRecord::remove方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: create
/*!
Inserts new record into the database, based on the current properties
of the object.
*/
bool TSqlObject::create()
{
// Sets the values of 'created_at', 'updated_at' or 'modified_at' properties
for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); ++i) {
const char *propName = metaObject()->property(i).name();
QByteArray prop = QByteArray(propName).toLower();
if (prop == CreatedAt || prop == UpdatedAt || prop == ModifiedAt) {
setProperty(propName, QDateTime::currentDateTime());
} else if (prop == LockRevision) {
// Sets the default value of 'revision' property
setProperty(propName, 1); // 1 : default value
} else {
// do nothing
}
}
syncToSqlRecord();
QString autoValName;
QSqlRecord record = *this;
if (autoValueIndex() >= 0) {
autoValName = field(autoValueIndex()).name();
record.remove(autoValueIndex()); // not insert the value of auto-value field
}
QSqlDatabase &database = Tf::currentSqlDatabase(databaseId());
QString ins = database.driver()->sqlStatement(QSqlDriver::InsertStatement, tableName(), record, false);
if (Q_UNLIKELY(ins.isEmpty())) {
sqlError = QSqlError(QLatin1String("No fields to insert"),
QString(), QSqlError::StatementError);
tWarn("SQL statement error, no fields to insert");
return false;
}
TSqlQuery query(database);
bool ret = query.exec(ins);
sqlError = query.lastError();
if (Q_LIKELY(ret)) {
// Gets the last inserted value of auto-value field
if (autoValueIndex() >= 0) {
QVariant lastid = query.lastInsertId();
if (!lastid.isValid() && database.driverName().toUpper() == QLatin1String("QPSQL")) {
// For PostgreSQL without OIDS
ret = query.exec("SELECT LASTVAL()");
sqlError = query.lastError();
if (Q_LIKELY(ret)) {
lastid = query.getNextValue();
}
}
if (lastid.isValid()) {
QObject::setProperty(autoValName.toLatin1().constData(), lastid);
QSqlRecord::setValue(autoValueIndex(), lastid);
}
}
}
return ret;
}
示例2: agregarGasto
/*!
\fn MGasto::agregarGasto( QString descripcion, double costo, QDate Fecha, int categoria )
*/
bool MGasto::agregarGasto( QString descripcion, double costo, QDate Fecha, int categoria )
{
QSqlTableModel::EditStrategy modo = this->editStrategy();
this->setEditStrategy( QSqlTableModel::OnManualSubmit );
QSqlRecord registro = this->record();
registro.setValue( "descripcion", descripcion );
registro.setValue( "costo", costo );
registro.setValue( "fecha", Fecha );
registro.setValue( "id_categoria", categoria );
registro.remove( 0 );
if( this->insertRecord( -1, registro ) == false )
{
qDebug( "Error al insertar registro de gasto" );
qDebug() << "Detalles: tipo: " << lastError().type() << ", errno:" << lastError().number() << ", descripcion: " << lastError().text();
this->setEditStrategy( modo );
return false;
}
else
{
if( submitAll() )
{
qDebug( "Gasto agregado correctamente" );
this->setEditStrategy( modo );
return true;
}
else
{
qDebug( "Error al insertar registro de gasto" );
qDebug() << "Detalles: tipo: " << lastError().type() << ", errno:" << lastError().number() << ", descripcion: " << lastError().text();
this->setEditStrategy( modo );
return false;
}
}
}
示例3: antes_de_insertar
/*!
\fn VDuenos::antes_de_insertar( int row, QSqlRecord & record )
Este metodo llamado antes de insertar los datos de un registro que setea los valores predeterminados.
@param row Numero de registro
@param record Objeto de registro
*/
void VDuenos::antes_de_insertar( int row, QSqlRecord & record )
{
record.remove( 0 );
for( int i = 0; i<record.count(); i++ )
{
record.setValue( i, QVariant( " " ) );
}
}
示例4: agregar
/*!
\fn EVLista::agregar()
Agrega un nuevo registro mediante la vista al modelo
*/
void EVLista::agregar()
{
QSqlRecord registro = modelo->record();
registro.remove( 0 );
if( !modelo->insertRecord( -1, registro ) )
{
qDebug( "Error al insertar el registro" );
qDebug( QString( "Detalles: tipo: %1, errno: %2, descripcion: %3" ).arg( modelo->lastError().type() ).arg( modelo->lastError().number() ).arg( modelo->lastError().text() ).toLocal8Bit() );
}
}
示例5: agregarRecargo
/*!
\fn MRecargos::agregarRecargo()
Agrega un tipo de recargo a la lista de recargos para un servicio.
*/
void MRecargos::agregarRecargo()
{
if( _servicio_actual <= 0 ) {
qDebug( "Error, no hay un id de servicio seteado ( id <= 0 )" );
return;
} else { qDebug( QString( "id_servicio = %1" ).arg( _servicio_actual ).toLocal8Bit() ); }
QSqlRecord registro = this->record();
registro.remove( 0 );
registro.setValue( "id_servicio", _servicio_actual );
registro.setValue( "cant_dias", 1 );
registro.setGenerated( 3, true );
/*for( int i = 0; i < registro.count(); i++ ) {
qDebug( QString( "%1: %2 - %3" ).arg( i ).arg( registro.fieldName( i ) ).arg( registro.value( i ).toString() ).toLocal8Bit() );
}*/
if( !this->insertRecord( -1, registro ) ) {
qDebug( "No se pudo agregar el registro" );
}
}
示例6: validRow
//.........这里部分代码省略.........
record.setValue(index, _poheadid);
XSqlQuery ln;
/*
ln.prepare("SELECT MAX(poitem_linenumber) + 1 AS newln "
"FROM poitem "
"WHERE (poitem_pohead_id=:pohead_id);");
*/
// get the smallest available line number
ln.prepare("SELECT MIN(sequence_value) AS newln "
"FROM sequence "
"WHERE sequence_value NOT IN (SELECT poitem_linenumber "
" FROM poitem"
" WHERE (poitem_pohead_id=:pohead_id));");
ln.bindValue(":pohead_id", _poheadid);
if (record.indexOf("poitem_linenumber") < 0)
{
ln.exec();
if (ln.first())
{
QSqlField field("poitem_linenumber", QVariant::Int);
field.setValue(ln.value("newln"));
record.append(field);
}
else if (ln.lastError().type() != QSqlError::NoError)
{
errormsg = ln.lastError().databaseText();
}
}
else if (record.value("poitem_linenumber").toInt() <= 0)
{
ln.exec();
if (ln.first())
record.setValue("poitem_linenumber", ln.value("newln"));
else if (ln.lastError().type() != QSqlError::NoError)
{
errormsg = ln.lastError().databaseText();
}
}
if (record.value("poitem_id").isNull())
{
XSqlQuery idq("SELECT NEXTVAL('poitem_poitem_id_seq') AS poitem_id;");
if (idq.first())
record.setValue("poitem_id", idq.value("poitem_id"));
else
{
errormsg = idq.lastError().databaseText();
}
}
if (_postatus.isEmpty())
findHeadData();
index = record.indexOf("poitem_status");
if (index < 0)
{
QSqlField field("poitem_status", QVariant::String);
field.setValue(_postatus);
record.append(field);
}
else if (record.field(index).value().toString().isEmpty())
record.setValue(index, _postatus);
if (record.field("poitem_invvenduomratio").value().isNull() &&
record.field("itemsrc_invvendoruomratio").value().isNull())
record.setValue("poitem_invvenduomratio", 1);
else if (record.field("poitem_invvenduomratio").value().isNull())
record.setValue("poitem_invvenduomratio", record.value("itemsrc_invvendoruomratio"));
if (! errormsg.isEmpty())
{
setLastError(QSqlError(QString("PoitemTableModel::validRow() error"),
errormsg, QSqlError::UnknownError));
return false;
}
else if (! warningmsg.isEmpty())
{
if (QMessageBox::question(0, tr("Are you sure you want to continue?"),
warningmsg + tr("<p>Do you wish to Save this Order?"),
QMessageBox::Yes,
QMessageBox::No | QMessageBox::Default) == QMessageBox::No)
return false;
}
record.remove(record.indexOf("earliestdate"));
record.remove(record.indexOf("itemsrc_invvendoruomratio"));
record.remove(record.indexOf("itemsrc_multordqty"));
record.remove(record.indexOf("itemsrc_minordqty"));
record.remove(record.indexOf("expcat_code"));
record.remove(record.indexOf("prj_number"));
record.remove(record.indexOf("extprice"));
record.remove(record.indexOf("warehous_code"));
record.remove(record.indexOf("warehous_id"));
record.remove(record.indexOf("item_number"));
record.remove(record.indexOf("item_id"));
record.remove(record.indexOf("pohead_number"));
return true;
}
示例7: remove
void QSqlRecordProto::remove(int pos)
{
QSqlRecord *item = qscriptvalue_cast<QSqlRecord*>(thisObject());
if (item)
item->remove(pos);
}