QFile f(imageFile); if ( !f.open( IO_ReadOnly ) ) { qWarning( "Unable to open data file '%s' - exiting", fileName ); } QByteArray binaryData = f.readAll(); qWarning( "Data size: %d", binaryData.size() ); // create a table with a binary field QSqlQuery q; // insert a BLOB into the table if ( !q.prepare( "INSERT INTO NSI_IMAGE (IMAGE_BYTE, CODE, IMAGE) VALUES (?, ?, ?)" ) ) { qWarning( "Unable to prepare query" ); } q.bindValue( 0, binaryData ); q.bindValue( 1, 1 ); q.bindValue( 2, 1 ); if ( !q.exec() ) { qWarning( "Unable to execute prepared query " ); q.lastError().showMessage(); }
Data size: 296378You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '????IC(O????)W\n?? H??\n??????D??????[????Z\n+??????????Vr????.????n????%????????????A??$<??Bh?~LZi??????\0' at line 1 QMYSQL3: Unable to execute query
QPixmap * pixmap = new QPixmap(imageFile); QByteArray ba; QBuffer buf(ba); buf.open(IO_WriteOnly); pixmap->save(&buf, "PNG"); buf.close(); QSqlQuery insertImage; insertImage.prepare("INSERT INTO NSI_IMAGE (IMAGE_BYTE, CODE, IMAGE) VALUES (:image_byte, :code, :image)"); insertImage.bindValue( ":code", kod ); insertImage.bindValue( ":image_byte", ba); insertImage.bindValue( ":image", ""); insertImage.exec();
QSqlQuery query; query.prepare("INSERT INTO person (id, forename, surname) " "VALUES (?, ?, ?)"); query.bindValue(0, 1001); query.bindValue(1, "Bart"); query.bindValue(2, "Simpson"); query.exec();
QByteArray data;...qDebug() << "hex text:" << QString( data.toHex() );