Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT, MySQL and BLOB
QtWS25 Last Chance

QT, MySQL and BLOB

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 11.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • dnastaD Offline
    dnastaD Offline
    dnasta
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #2

      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);
      @

      1 Reply Last reply
      0
      • dnastaD Offline
        dnastaD Offline
        dnasta
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Dii
          wrote on last edited by
          #4

          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 ;)

          1 Reply Last reply
          0
          • dnastaD Offline
            dnastaD Offline
            dnasta
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Dii
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                robi
                wrote on last edited by
                #7

                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.....

                robi

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved