Exemple #1
0
/*!
    Inserts the values \a values into the currently active database table.

    This is a low-level method that operates directly on the database
    and should not be called directly. Use insertRow() and setData()
    to insert values. The model will decide depending on its edit strategy
    when to modify the database.

    Returns true if the values could be inserted, otherwise false.
    Error information can be retrieved with \l lastError().

    \sa lastError(), insertRow(), insertRows()
*/
bool QSqlTableModel::insertRowIntoTable(const QSqlRecord &values)
{
    Q_D(QSqlTableModel);
    QSqlRecord rec = values;
    emit beforeInsert(rec);

    bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries);
    QString stmt = d->db.driver()->sqlStatement(QSqlDriver::InsertStatement, d->tableName,
                                                rec, prepStatement);

    if (stmt.isEmpty()) {
        d->error = QSqlError(QLatin1String("No Fields to update"), QString(),
                                 QSqlError::StatementError);
        return false;
    }

    return d->exec(stmt, prepStatement, rec);
}
Exemple #2
0
bool Q3DataBrowser::insertCurrent()
{
    if (isReadOnly())
        return false;
    QSqlRecord* buf = d->frm.record();
    Q3SqlCursor* cur = d->cur.cursor();
    if (!buf || !cur)
        return false;
    writeFields();
    emit beforeInsert(buf);
    int ar = cur->insert();
    if (!ar || !cur->isActive()) {
        handleError(cur->lastError());
        refresh();
        updateBoundary();
    } else {
        refresh();
        d->cur.findBuffer(cur->primaryIndex());
        updateBoundary();
        cursorChanged(Q3SqlCursor::Insert);
        return true;
    }
    return false;
}