CREATE TABLE variant ( id serial NOT NULL, variant bytea );
QVariant var = QDateTime::currentDateTime();// QVariant var = 1234567;// QVariant var = 1234.5678;// QVariant var = true; QByteArray arr; QDataStream out(&arr,QIODevice::WriteOnly); out << var; textEdit->append(QString("in = %1").arg(var.toString())); QSqlQuery query(db); query.prepare("INSERT INTO variant(variant) VALUES (:variant)"); query.bindValue(":variant", arr); query.exec(); int id = query.lastInsertId().toInt(); // ------------- query.prepare("select * from variant where id = :id"); query.bindValue(":id", id); query.exec(); query.next(); QSqlRecord rec = query.record(); QByteArray arr2 = query.value(rec.indexOf("variant")).toByteArray(); QDataStream in(&arr2,QIODevice::ReadOnly); QVariant var2 = QVariant(in); textEdit->append(QString("out = %1").arg(var2.toString()));
QVariant var = QDateTime::currentDateTime();// QVariant var = 1234567;// QVariant var = 1234.5678;// QVariant var = true; QByteArray arr; QDataStream out(&arr,QIODevice::WriteOnly); out << var;
textEdit->append(QString("in = %1").arg(QDateTime::currentDateTime().toString())); QSqlQuery query(db); query.prepare("INSERT INTO variant(variant) VALUES (?)"); query.addBindValue(textEdit); query.exec();