i create a class to manage BLOB fields. i tested in SQLITE and FIREBIRD. i think must work in MYSQL
class SqlFieldBlob
: public QObject{
Q_OBJECT
public:
explicit SqlFieldBlob
(QObject *parent
= 0);
bool saveData
(const QString &filename
);
public slots:
void setData
(const QByteArray &byteArray
) { p_byteArray
= byteArray;
} void setFileName
(const QString &filename
);
void setPixmap
(const QPixmap &pixmap
);
private:
};
class SqlFieldBlob : public QObject
{
Q_OBJECT
public:
explicit SqlFieldBlob(QObject *parent = 0);
QByteArray data() { return p_byteArray; }
bool saveData(const QString &filename);
public slots:
void setData(const QByteArray &byteArray) { p_byteArray = byteArray;}
void setFileName(const QString &filename);
void setPixmap(const QPixmap &pixmap);
private:
QByteArray p_byteArray;
};
To copy to clipboard, switch view to plain text mode
and using something like
SqlFieldBlob blob;
blob.setFileName(fileName);
query2.prepare("INSERT INTO files (file_name, file_data) "
"VALUES (:id, :id2)");
query2.bindValue("id", fileName);
query2.bindValue("id2", blob.data());
query2.exec();
SqlFieldBlob blob;
blob.setFileName(fileName);
QSqlQuery query2;
query2.prepare("INSERT INTO files (file_name, file_data) "
"VALUES (:id, :id2)");
query2.bindValue("id", fileName);
query2.bindValue("id2", blob.data());
query2.exec();
To copy to clipboard, switch view to plain text mode
Bookmarks