Diff
checker
文本
文本
圖像
文檔
Excel
文件夾
Legal
Enterprise
桌面版
定價
登入
下載 Diffchecker 桌面版
比較文本
尋找兩個文字檔案之間的差異
工具
歷史
即時編輯器
摺疊未變更行
關閉換行
檢視
拆分
統一
比對精度
智能
單詞
字符
語法突出顯示
選擇語法
忽略
文字轉換
前往第一個差異
編輯輸入
Diffchecker Desktop
執行Diffchecker最安全的方式。取得Diffchecker桌面應用程式:您的差異永遠不會離開您的電腦!
取得桌面版
Untitled diff
建立於
9 年前
差異永不過期
清除
匯出
分享
解釋
16 刪除
行
總計
刪除
字符
總計
刪除
要繼續使用此功能,請升級到
Diff
checker
Pro
查看價格
70 行
全部複製
53 新增
行
總計
新增
字符
總計
新增
要繼續使用此功能,請升級到
Diff
checker
Pro
查看價格
99 行
全部複製
#include <iostream>
#include <iostream>
#include <memory>
#include <memory>
#include <Wt/Dbo/Dbo.h>
#include <Wt/Dbo/Dbo.h>
#include <Wt/Dbo/backend/Sqlite3.h>
#include <Wt/Dbo/backend/Sqlite3.h>
using namespace std;
using namespace std;
namespace dbo = Wt::Dbo;
namespace dbo = Wt::Dbo;
class EntityA
class EntityA
{
{
public:
public:
string name {"Jef"};
string name {"Jef"};
template<class Action>
template<class Action>
void persist(Action& a)
void persist(Action& a)
{
{
dbo::field(a, name, "name");
dbo::field(a, name, "name");
}
}
};
};
class EntityB
class EntityB
{
{
public:
public:
string name {"Jef Jr."};
string name {"Jef Jr."};
複製
已複製
複製
已複製
dbo::
ptr<EntityA> parent;
static shared_ptr<
dbo::
Session> session;
static void setSession(shared_ptr<dbo::Session> s)
{
session = s;
}
template<class Action>
template<class Action>
void persist(Action& a)
void persist(Action& a)
{
{
dbo::field(a, name, "name");
dbo::field(a, name, "name");
dbo::belongsTo(a, parent, "parent");
dbo::belongsTo(a, parent, "parent");
}
}
複製
已複製
複製
已複製
unique_ptr<EntityA> getParent() const
{
dbo::Transaction t{*session};
return make_unique<EntityA>(*parent);
}
void setParent(dbo::ptr<EntityA> p)
{
parent = p;
}
void setParent(unique_ptr<EntityA> p)
{
parent.reset(move(p));
}
private:
dbo::ptr<EntityA> parent {nullptr};
};
};
複製
已複製
複製
已複製
dbo::ptr<EntityB> getAnyB(
dbo::Session
&
session)
shared_ptr<dbo::Session> EntityB::session = nullptr;
dbo::ptr<EntityB> getAnyB(
shared_ptr<
dbo::Session
>
session)
{
{
複製
已複製
複製
已複製
dbo::Transaction t{
session};
dbo::Transaction t{
*
session};
複製
已複製
複製
已複製
return session
.
find<EntityB>().limit(1);
return session
->
find<EntityB>().limit(1);
}
}
int main()
int main()
{
{
複製
已複製
複製
已複製
dbo::Session
session
;
auto session = make_shared<
dbo::Session
>()
;
複製
已複製
複製
已複製
session
.
setConnection([](){
session
->
setConnection([](){
auto sqlite3 = make_unique<dbo::backend::Sqlite3>(":memory:");
auto sqlite3 = make_unique<dbo::backend::Sqlite3>(":memory:");
sqlite3->setProperty("show-queries", "true");
sqlite3->setProperty("show-queries", "true");
return move(sqlite3);
return move(sqlite3);
}());
}());
複製
已複製
複製
已複製
session
.
mapClass<EntityA>("entity_a");
session
->
mapClass<EntityA>("entity_a");
session
.
mapClass<EntityB>("entity_b");
session
->
mapClass<EntityB>("entity_b");
複製
已複製
複製
已複製
session
.
createTables();
session
->
createTables();
EntityB::setSession(session);
{
{
複製
已複製
複製
已複製
dbo::Transaction t{
session};
dbo::Transaction t{
*
session};
auto b = make_unique<EntityB>();
auto b = make_unique<EntityB>();
複製
已複製
複製
已複製
b->
p
arent
=
session
.
add(make_unique<EntityA>())
;
b->
setP
arent
(
session
.
add(move(b));
session
->
add(make_unique<EntityA>())
)
;
session
->
add(move(b));
}
}
複製
已複製
複製
已複製
//dbo::Transaction t{session}; // This "fixes" the problem, but it's VERY inconvenient
cout << getAnyB(session)->
getP
arent
()
->name;
cout << getAnyB(session)->
p
arent
->name;
// Exception: Dbo load(): no active transaction
return 0;
return 0;
}
}
已保存差異
原始文本
開啟檔案
#include <iostream> #include <memory> #include <Wt/Dbo/Dbo.h> #include <Wt/Dbo/backend/Sqlite3.h> using namespace std; namespace dbo = Wt::Dbo; class EntityA { public: string name {"Jef"}; template<class Action> void persist(Action& a) { dbo::field(a, name, "name"); } }; class EntityB { public: string name {"Jef Jr."}; dbo::ptr<EntityA> parent; template<class Action> void persist(Action& a) { dbo::field(a, name, "name"); dbo::belongsTo(a, parent, "parent"); } }; dbo::ptr<EntityB> getAnyB(dbo::Session& session) { dbo::Transaction t{session}; return session.find<EntityB>().limit(1); } int main() { dbo::Session session; session.setConnection([](){ auto sqlite3 = make_unique<dbo::backend::Sqlite3>(":memory:"); sqlite3->setProperty("show-queries", "true"); return move(sqlite3); }()); session.mapClass<EntityA>("entity_a"); session.mapClass<EntityB>("entity_b"); session.createTables(); { dbo::Transaction t{session}; auto b = make_unique<EntityB>(); b->parent = session.add(make_unique<EntityA>()); session.add(move(b)); } //dbo::Transaction t{session}; // This "fixes" the problem, but it's VERY inconvenient cout << getAnyB(session)->parent->name; // Exception: Dbo load(): no active transaction return 0; }
更改後文本
開啟檔案
#include <iostream> #include <memory> #include <Wt/Dbo/Dbo.h> #include <Wt/Dbo/backend/Sqlite3.h> using namespace std; namespace dbo = Wt::Dbo; class EntityA { public: string name {"Jef"}; template<class Action> void persist(Action& a) { dbo::field(a, name, "name"); } }; class EntityB { public: string name {"Jef Jr."}; static shared_ptr<dbo::Session> session; static void setSession(shared_ptr<dbo::Session> s) { session = s; } template<class Action> void persist(Action& a) { dbo::field(a, name, "name"); dbo::belongsTo(a, parent, "parent"); } unique_ptr<EntityA> getParent() const { dbo::Transaction t{*session}; return make_unique<EntityA>(*parent); } void setParent(dbo::ptr<EntityA> p) { parent = p; } void setParent(unique_ptr<EntityA> p) { parent.reset(move(p)); } private: dbo::ptr<EntityA> parent {nullptr}; }; shared_ptr<dbo::Session> EntityB::session = nullptr; dbo::ptr<EntityB> getAnyB(shared_ptr<dbo::Session> session) { dbo::Transaction t{*session}; return session->find<EntityB>().limit(1); } int main() { auto session = make_shared<dbo::Session>(); session->setConnection([](){ auto sqlite3 = make_unique<dbo::backend::Sqlite3>(":memory:"); sqlite3->setProperty("show-queries", "true"); return move(sqlite3); }()); session->mapClass<EntityA>("entity_a"); session->mapClass<EntityB>("entity_b"); session->createTables(); EntityB::setSession(session); { dbo::Transaction t{*session}; auto b = make_unique<EntityB>(); b->setParent( session->add(make_unique<EntityA>()) ); session->add(move(b)); } cout << getAnyB(session)->getParent()->name; return 0; }
尋找差異