Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QT, MySQL and BLOB



  • Hello

    Please! Help me with this!

    I have QT 2010.05 and MySQL 5.1.50 (with the corresponding sources and libs) on XP.

    I'm trying to insert an image into a BLOB field in a table like this:

    @CREATE TABLE contenido (
    idx_contenido int(11) NOT NULL AUTO_INCREMENT,
    nombre varchar(256) COLLATE latin1_spanish_ci DEFAULT NULL,
    contenido blob,
    PRIMARY KEY (idx_contenido)
    ) ENGINE=InnoDB;@

    compiled the driver for MySQL with these commands:

    cd %QT_DIR%\src\plugins\sqldrivers\mysql
    qmake -o Makefile "INCLUDEPATH+=E:\MySQL51\include" "LIBS+=E:\MySQL51\lib\opt\libmysql.lib" mysql.pro
    nmake

    These commands do not generate any error, qmake generates only three warnings:

    WARNING: (internal):1: Unescaped backslashes are deprecated.
    WARNING: (internal):1: Unescaped backslashes are deprecated.
    WARNING: (internal):1: Unescaped backslashes are deprecated.

    When I run the program generates this error:

    Using unsupported buffer type: 64 (parameter: 1) QMYSQL3: Unable to bind value

    I have this code:

    @class Principal : public QWidget
    {
    Q_OBJECT

    public:
    explicit Principal(QWidget *parent = 0);
    ~Principal();

    private:
    Ui::Principal *ui;

    QSqlDatabase bd;
    

    private slots:
    void on_btnBlob_clicked();
    void on_btnSalir_clicked();
    };

    Principal::Principal(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Principal)
    {
    ui->setupUi(this);

    bd = QSqlDatabase::addDatabase("QMYSQL");
    bd.setHostName("localhost");
    bd.setPort(3306);
    

    }

    void Principal::on_btnBlob_clicked()
    {
    {
    bd.setDatabaseName("pruebasqt");
    bd.setUserName("qt");
    bd.setPassword("qt");

        if (!bd.open())
        {
            QSqlError bderror = bd.lastError();
            ui->text->append(bderror.text());
        }
        bd.close();
    }
    
    QString fileName = "C:/Factura01.jpg";
    
    QByteArray ba;
    QFile f(fileName);
    if(f.open(QIODevice::ReadOnly))
    {
        ba = f.readAll();
        f.close();
    }
    
    QSqlDatabase::database().transaction();
    QSqlQuery query;
    query.prepare("INSERT INTO contenido (nombre, contenido) VALUES (\"Factura01.jpg\", :IMAGE)" );
    query.bindValue(":IMAGE", ba);
    query.exec();
    if( query.lastError().isValid())
    {
        ui->text->append(query.lastError().text());
        QSqlDatabase::database().rollback();
    }
    else
        QSqlDatabase::database().commit();
    
    QSqlDatabase::removeDatabase("pruebasqt");
    

    }@

    Please, helpme.

    Thank you very much for your help

    Regards,

    Dario



  • did this line return true?

    @
    query.prepare("INSERT INTO contenido (nombre, contenido) VALUES ("Factura01.jpg", :IMAGE)" );
    @

    Try this,
    @
    query.prepare("INSERT INTO contenido (nombre, contenido) VALUES (:NAME, :IMAGE)" );
    query.bindValue(":NAME", "Factura01.jpg");
    query.bindValue(":IMAGE", ba);
    @



  • Thanks for reply.

    @

    query.prepare("INSERT INTO contenido (nombre, contenido) VALUES ("Factura01.jpg", :IMAGE)" );

    @

    returns true but...

    @

    query.prepare("INSERT INTO contenido (nombre, contenido) VALUES (:NAME, :IMAGE)" );
    query.bindValue(":NAME", "Factura01.jpg");
    query.bindValue(":IMAGE", ba);

    @

    also generates the same error

    Using unsupported buffer type: 64 (parameter: 1) QMYSQL3: Unable to bind value

    Note that the error says QMYSQL3, indicates that QT are using MySQL 3 driver (which does not support BLOB) although I compile the QT driver with MySQL 5

    Regards,

    Darío



  • Hmmm in line 46, why do you close the database connection? Probably it should be in the if statement starts at line 41. And you should give a 'return;' there too, if the database open is failed. Or am I seeing something wrong?

    BTW, in
    @query.prepare("INSERT INTO contenido (nombre, contenido) VALUES ("Factura01.jpg", :IMAGE)" );@

    You can do it like this, more beautiful without the backslashes:

    @query.prepare("INSERT INTO contenido (nombre, contenido) VALUES ('Factura01.jpg', :IMAGE)" );@

    .. at my opinion ;)



  • Same error with 'Factura01.jpg' and without bd.close(); in line 45



  • I've tried to reproduce your problem, but without any success. I have Qt 4.6.3 and MySQL 5.1.50, though I'm running them on linux. I have no problem with the BLOB type at all. Also "buffer type: 64" doesn't bring up anything in google, except your posts. Very strange.

    I haven't compiled the mysql driver in windows for a very long time, maybe the problem is somewhere there. Sorry I couldn't help.



  • Though i am new in qt platform and also the post has been given by you many days ago,then i can probably give you the solution...here

    don't use backslashes instead of front slashes in "INCLUDEPATH" "LIBS" use like below:
    cd %QTDIR%\src\plugins\sqldrivers\mysql
    qmake "INCLUDEPATH+=C:/MySQL/include" "LIBS+=C:/MYSQL/MySQL Server <version>/lib/opt/libmysql.lib" mysql.pro
    mingw32-make ........
    this will remove this problem
    WARNING: (internal):1: Unescaped backslashes are deprecated.
    WARNING: (internal):1: Unescaped backslashes are deprecated.
    WARNING: (internal):1: Unescaped backslashes are deprecated.

    and you also need to notice that you put correct libmysql.dll from mysql that is u used for build with qt.........if u follow this things you can get rid of this problem.....best of luck
    sorry for my bad english.....


Log in to reply