bool TSessionSqlObjectStore::store(TSession &session) { TSqlORMapper<TSessionObject> mapper; TCriteria cri(TSessionObject::Id, TSql::Equal, session.id()); TSessionObject so = mapper.findFirst(cri); #ifndef TF_NO_DEBUG { QByteArray badummy; QDataStream dsdmy(&badummy, QIODevice::ReadWrite); dsdmy << *static_cast<const QVariantMap *>(&session); TSession dummy; dsdmy.device()->seek(0); dsdmy >> *static_cast<QVariantMap *>(&dummy); if (dsdmy.status() != QDataStream::Ok) { tSystemError("Failed to store a session into the cookie store. Must set objects that can be serialized."); } } #endif QDataStream ds(&so.data, QIODevice::WriteOnly); ds << *static_cast<const QVariantMap *>(&session); if (ds.status() != QDataStream::Ok) { tSystemError("Failed to store session. Must set objects that can be serialized."); return false; } if (so.isNull()) { so.id = session.id(); return so.create(); } return so.update(); }
bool TSessionSqlObjectStore::store(TSession &session) { TSqlORMapper<TSessionObject> mapper; TCriteria cri(TSessionObject::Id, TSql::Equal, session.id()); TSessionObject so = mapper.findFirst(cri); QDataStream ds(&so.data, QIODevice::WriteOnly); ds << *static_cast<const QVariantHash *>(&session); if (so.isEmpty()) { so.id = session.id(); return so.create(); } return so.update(); }