Logo Search packages:      
Sourcecode: qt4-x11 version File versions

bool QSqlQuery::prepare ( const QString query  ) 

Prepares the SQL query query for execution. Returns true if the query is prepared successfully; otherwise returns false.

The query may contain placeholders for binding values. Both Oracle style colon-name (e.g., {:surname}), and ODBC style ({?}) placeholders are supported; but they cannot be mixed in the same query. See the {QSqlQuery examples}{Detailed Description} for examples.

Portability note: Some databases choose to delay preparing a query until it is executed the first time. In this case, preparing a syntactically wrong query succeeds, but every consecutive exec() will fail.

See also:
exec(), bindValue(), addBindValue()

Definition at line 877 of file qsqlquery.cpp.

References QByteArray::constData(), driver(), QString::isEmpty(), isForwardOnly(), QSqlQuery(), setForwardOnly(), and QString::toLocal8Bit().

    if (d->ref != 1) {
        bool fo = isForwardOnly();
        *this = QSqlQuery(driver()->createResult());
    } else {
    if (!driver()) {
        qWarning("QSqlQuery::prepare: no driver");
        return false;
    if (!driver()->isOpen() || driver()->isOpenError()) {
        qWarning("QSqlQuery::prepare: database not open");
        return false;
    if (query.isEmpty()) {
        qWarning("QSqlQuery::prepare: empty query");
        return false;
    qDebug("\n QSqlQuery::prepare: %s", query.toLocal8Bit().constData());
    return d->sqlResult->savePrepare(query);

Generated by  Doxygen 1.6.0   Back to index