~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/sql/drivers/mysql/qsql_mysql.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-10-12 23:14:14 UTC
  • mto: (15.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20061012231414-y2oqbom5dy389os0
Tags: upstream-4.2.0
ImportĀ upstreamĀ versionĀ 4.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
165
165
    case FIELD_TYPE_TINY_BLOB :
166
166
    case FIELD_TYPE_MEDIUM_BLOB :
167
167
    case FIELD_TYPE_LONG_BLOB :
168
 
        type = QVariant::ByteArray;
 
168
        type = (flags & BINARY_FLAG) ? QVariant::ByteArray : QVariant::String;
169
169
        break;
170
170
    default:
171
171
    case FIELD_TYPE_ENUM :
363
363
        mysql_stmt_data_seek(d->stmt, i);
364
364
 
365
365
        if (mysql_stmt_fetch(d->stmt)) {
366
 
            setLastError(qMakeStmtError(QCoreApplication::tr("Unable to fetch data",
367
 
                         "QMYSQLResult"), QSqlError::StatementError, d->stmt));
 
366
            setLastError(qMakeStmtError(QCoreApplication::translate("QMYSQLResult",
 
367
                         "Unable to fetch data"), QSqlError::StatementError, d->stmt));
368
368
            return false;
369
369
        }
370
370
#else
527
527
 
528
528
    const QByteArray encQuery(d->tc->fromUnicode(query));
529
529
    if (mysql_real_query(d->mysql, encQuery.data(), encQuery.length())) {
530
 
        setLastError(qMakeError(QCoreApplication::tr("Unable to execute query", "QMYSQLResult"),
 
530
        setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to execute query"),
531
531
                     QSqlError::StatementError, d));
532
532
        return false;
533
533
    }
534
534
    d->result = mysql_store_result(d->mysql);
535
535
    if (!d->result && mysql_field_count(d->mysql) > 0) {
536
 
        setLastError(qMakeError(QCoreApplication::tr("Unable to store result", "QMYSQLResult"),
 
536
        setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to store result"),
537
537
                    QSqlError::StatementError, d));
538
538
        return false;
539
539
    }
655
655
    if (!d->stmt)
656
656
        d->stmt = mysql_stmt_init(d->mysql);
657
657
    if (!d->stmt) {
658
 
        setLastError(qMakeError(QCoreApplication::tr("Unable to prepare statement", "QMYSQLResult"),
 
658
        setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to prepare statement"),
659
659
                     QSqlError::StatementError, d));
660
660
        return false;
661
661
    }
663
663
    const QByteArray encQuery(d->tc->fromUnicode(query));
664
664
    r = mysql_stmt_prepare(d->stmt, encQuery.constData(), encQuery.length());
665
665
    if (r != 0) {
666
 
        setLastError(qMakeStmtError(QCoreApplication::tr("Unable to prepare statement",
667
 
                        "QMYSQLResult"), QSqlError::StatementError, d->stmt));
 
666
        setLastError(qMakeStmtError(QCoreApplication::translate("QMYSQLResult",
 
667
                     "Unable to prepare statement"), QSqlError::StatementError, d->stmt));
668
668
        cleanup();
669
669
        return false;
670
670
    }
694
694
 
695
695
    r = mysql_stmt_reset(d->stmt);
696
696
    if (r != 0) {
697
 
        setLastError(qMakeStmtError(QCoreApplication::tr("Unable to reset statement",
698
 
                        "QMYSQLResult"), QSqlError::StatementError, d->stmt));
 
697
        setLastError(qMakeStmtError(QCoreApplication::translate("QMYSQLResult",
 
698
                     "Unable to reset statement"), QSqlError::StatementError, d->stmt));
699
699
        return false;
700
700
    }
701
701
 
781
781
 
782
782
        r = mysql_stmt_bind_param(d->stmt, d->outBinds);
783
783
        if (r != 0) {
784
 
            setLastError(qMakeStmtError(QCoreApplication::tr("Unable to bind value",
785
 
                            "QMYSQLResult"), QSqlError::StatementError, d->stmt));
 
784
            setLastError(qMakeStmtError(QCoreApplication::translate("QMYSQLResult",
 
785
                         "Unable to bind value"), QSqlError::StatementError, d->stmt));
786
786
            qDeleteAll(timeVector);
787
787
            return false;
788
788
        }
792
792
    qDeleteAll(timeVector);
793
793
 
794
794
    if (r != 0) {
795
 
        setLastError(qMakeStmtError(QCoreApplication::tr("Unable to execute statement",
796
 
                        "QMYSQLResult"), QSqlError::StatementError, d->stmt));
 
795
        setLastError(qMakeStmtError(QCoreApplication::translate("QMYSQLResult",
 
796
                     "Unable to execute statement"), QSqlError::StatementError, d->stmt));
797
797
        return false;
798
798
    }
799
799
    //if there is meta-data there is also data
806
806
 
807
807
        r = mysql_stmt_bind_result(d->stmt, d->inBinds);
808
808
        if (r != 0) {
809
 
            setLastError(qMakeStmtError(QCoreApplication::tr("Unable to bind outvalues",
810
 
                          "QMYSQLResult"), QSqlError::StatementError, d->stmt));
 
809
            setLastError(qMakeStmtError(QCoreApplication::translate("QMYSQLResult",
 
810
                         "Unable to bind outvalues"), QSqlError::StatementError, d->stmt));
811
811
            return false;
812
812
        }
813
813
        if (d->hasBlobs)
815
815
 
816
816
        r = mysql_stmt_store_result(d->stmt);
817
817
        if (r != 0) {
818
 
            setLastError(qMakeStmtError(QCoreApplication::tr("Unable to store statement results",
819
 
                            "QMYSQLResult"), QSqlError::StatementError, d->stmt));
 
818
            setLastError(qMakeStmtError(QCoreApplication::translate("QMYSQLResult",
 
819
                         "Unable to store statement results"), QSqlError::StatementError, d->stmt));
820
820
            return false;
821
821
        }
822
822
 
827
827
            d->bindBlobs();
828
828
            r = mysql_stmt_bind_result(d->stmt, d->inBinds);
829
829
            if (r != 0) {
830
 
                setLastError(qMakeStmtError(QCoreApplication::tr("Unable to bind outvalues",
831
 
                              "QMYSQLResult"), QSqlError::StatementError, d->stmt));
 
830
                setLastError(qMakeStmtError(QCoreApplication::translate("QMYSQLResult",
 
831
                             "Unable to bind outvalues"), QSqlError::StatementError, d->stmt));
832
832
                return false;
833
833
            }
834
834
        }
970
970
    */
971
971
    unsigned int optionFlags = Q_CLIENT_MULTI_STATEMENTS;
972
972
    const QStringList opts(connOpts.split(QLatin1Char(';'), QString::SkipEmptyParts));
 
973
    QString unixSocket;
973
974
 
974
975
    // extract the real options from the string
975
976
    for (int i = 0; i < opts.count(); ++i) {
976
977
        QString tmp(opts.at(i).simplified());
977
978
        int idx;
978
979
        if ((idx = tmp.indexOf(QLatin1Char('='))) != -1) {
979
 
            QString val(tmp.mid(idx + 1).simplified());
980
 
            if (val == QLatin1String("TRUE") || val == QLatin1String("1"))
 
980
            QString val = tmp.mid(idx + 1).simplified();
 
981
            QString opt = tmp.left(idx).simplified();
 
982
            if (opt == QLatin1String("UNIX_SOCKET"))
 
983
                unixSocket = val;
 
984
            else if (val == QLatin1String("TRUE") || val == QLatin1String("1"))
981
985
                setOptionFlag(optionFlags, tmp.left(idx).simplified());
982
986
            else
983
987
                qWarning("QMYSQLDriver::open: Illegal connect option value '%s'",
998
1002
                               db.isNull() ? static_cast<const char *>(0)
999
1003
                                           : db.toLocal8Bit().constData(),
1000
1004
                               (port > -1) ? port : 0,
1001
 
                               NULL,
 
1005
                               unixSocket.isNull() ? static_cast<const char *>(0)
 
1006
                                           : unixSocket.toLocal8Bit().constData(),
1002
1007
                               optionFlags))
1003
1008
    {
1004
1009
        if (!db.isEmpty() && mysql_select_db(d->mysql, db.toLocal8Bit().constData())) {
1005
 
            setLastError(qMakeError(tr("Unable open database '") + db +
 
1010
            setLastError(qMakeError(tr("Unable to open database '") + db +
1006
1011
                         QLatin1Char('\''), QSqlError::ConnectionError, d));
1007
1012
            mysql_close(d->mysql);
1008
1013
            setOpenError(true);
1015
1020
        setOpenError(true);
1016
1021
        return false;
1017
1022
    }
 
1023
#if MYSQL_VERSION_ID >= 50007
 
1024
    // force the communication to be utf8
 
1025
    mysql_set_character_set(d->mysql, "utf8");
 
1026
#endif
1018
1027
    d->tc = codec(d->mysql);
1019
1028
 
1020
1029
#if MYSQL_VERSION_ID >= 40108
1181
1190
                const QByteArray ba = field.value().toByteArray();
1182
1191
                // buffer has to be at least length*2+1 bytes
1183
1192
                char* buffer = new char[ba.size() * 2 + 1];
1184
 
                int escapedSize = int(mysql_escape_string(buffer, ba.data(), ba.size()));
 
1193
                int escapedSize = int(mysql_real_escape_string(d->mysql, buffer,
 
1194
                                      ba.data(), ba.size()));
1185
1195
                r.reserve(escapedSize + 3);
1186
1196
                r.append(QLatin1Char('\'')).append(d->tc->toUnicode(buffer)).append(QLatin1Char('\''));
1187
1197
                delete[] buffer;