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;
I 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");
}
Thank you very much for your help
Regards, Dario