You must have a query which includes any TEXT or BLOB type in the column list, that is in the part of the query between SELECT and FROM.
The actual size of the column or its content do not matter - even a TINYTEXT that is empty is enough.
First: Create a table, for example: CREATE TABLE picture ( ID INTEGER AUTO_INCREMENT, IMAGE BLOB, PRIMARY KEY (ID)) ENGINE=Inno DB;2) To read a image to a QByte Array QString file Name = "IMAGE.
JPG"; QImage image(fila Name); LBL_IMAGE-set Pixmap(QPixmap::from Image(image)); // Put image into QLabel object (optional)// load image to bytearray QByte Array ba; QFile f(file Name);if(f.open(QIODevice:: Read Only))// Writing the image into table QSql Database::database().transaction(); QSql Query query; query.prepare( "INSERT INTO picture ( IMAGE ) VALUES (: IMAGE)" ); Value(": IMAGE", ba); query.exec(); if( Error()Valid()) else QSql Database::database().commit();3) Now, recovery the field with the image int idx = 1; // The records ID to recover QSql Database::database().transaction(); QSql Query query; query.prepare("SELECT ID, IMAGE FROM picture WHERE ID=: ID"); Value(": ID", idx); query.exec(); query.next(); if( Error()Valid()) else This example works fine and I use it frequently. On MS Windows the "no DEFAULT" rule is an error, while on other platforms it is often a warning.
Update the Blob 4 times with byte array size of 512KB. Internally the server needs to handle the value as whole and by setting 'max_allowed_packet' admin has 'told' My SQL server not to handle larger values than that.
id=1 Simon Mudd is right, but there are several things that must come together to make this bad:1.
You must have a query that has an EXPLAIN which includes 'using temporary'.
If 'using temporary' is shown in your EXPLAIN plan, then a temporary table is being created either in MEMORY or as My ISAM table on disk.
My SQL prefers MEMORY, but there are situations where it is forced to go to disk.2.