[Wt::Dbo] [Postgres] [Wt 3.2.1] Get on Wt::Dbo::Ptr return empty string
Added by Thomas Saquet 11 months ago
Hello,
I use a Postgres database with Wt 3.2.1. I have no problem to get integers from the database, and no problem to modify strings inside the db.
However, i cannot get a string value, it is always empty. Do you think it is a bug or am I doing something wrong ?
{
try
{
Wt::Dbo::Transaction transaction(session);
Wt::Dbo::ptr<AlertTracking> at = session.find<AlertTracking>().where("\"ATR_ID\" = ?").bind(this->alertTrackingId);
if (Utils::checkId<AlertTracking>(at))
{
Wt::log("info") << "ATR_ID : " << at.id();
Wt::log("info") << "ALE_ID : " << at.get()->alert.id();
Wt::log("info") << "ATY_ID : " << at.get()->alert.get()->alertType.id();
Wt::log("info") << "ATY_NAME : " << at.get()->alert->alertType->name;
Wt::Dbo::ptr<AlertType> aty = session.find<AlertType>().where("\"ATY_ID\" = ?").bind(at.get()->alert.get()->alertType.id());
Wt::log("info") << "ATY_NAME 2 : " << aty->name;
Wt::log("info") << "ATY_NAME 3 : " << aty.get()->name;
Wt::log("info") << "version : " << aty.version();
aty.modify()->name = "CHANGE NAME";
}
else
{
Wt::log("error") << "[SMS] Alert tracking not found";
//TODO error behavior
}
}
catch(Wt::Dbo::Exception const& e)
{
Wt::log("error") << e.what();
//TODO : behaviour in error case
return;
}
}
The output i get :
select "ATR_ID", "version", "ATR_DELETE", "ATR_RECEIV_DATE", "ATR_SEND_DATE", "ATR_ACK_EVENT", "ATR_ACK_GW", "ATR_ACK_ID", "ATR_ACK_PORT", "ATR_RECEIVER_SRV", "ATR_SENDER_SRV", "ATR_MEV_MEV_ID", "ATR_ALE_ALE_ID" from "T_ALERT_TRACKING_ATR" where ("ATR_ID" = $1)
[2012-Aug-01 15:12:04.819995] 10135 - [info] "ATR_ID : 1"
[2012-Aug-01 15:12:04.820038] 10135 - [info] "ALE_ID : 1"
select "version", "ALE_NAME", "ALE_DATE", "ALE_DELETE", "ALE_ATY_ATY_ID" from "T_ALERT_ALE" where "ALE_ID" = $1
[2012-Aug-01 15:12:04.820825] 10135 - [info] "ATY_ID : 1"
select "version", "ATY_NAME", "ATY_DELETE" from "T_ALERT_TYPE_ATY" where "ATY_ID" = $1
[2012-Aug-01 15:12:04.821574] 10135 - [info] "ATY_NAME : "
select "ATY_ID", "version", "ATY_NAME", "ATY_DELETE", "ATY_NAME", "ATY_DELETE" from "T_ALERT_TYPE_ATY" where ("ATY_ID" = $1)
[2012-Aug-01 15:12:04.822172] 10135 - [info] "ATY_NAME 2 : "
[2012-Aug-01 15:12:04.822199] 10135 - [info] "ATY_NAME 3 : "
[2012-Aug-01 15:12:04.822212] 10135 - [info] "version : 2"
update "T_ALERT_TYPE_ATY" set "version" = $1, "ATY_NAME" = $2, "ATY_DELETE" = $3 where "ATY_ID" = $4 and "version" = $5
The update at the end works fine.
Thank you in advance for your help.
Replies (3)
RE: [Wt::Dbo] [Postgres] [Wt 3.2.1] Get on Wt::Dbo::Ptr return empty string - Added by Thomas Saquet 11 months ago
Hello,
I found a workaround but i still do not understand the problem. I replaced the attributes of type std::string with attributes of type WString and it works.
There was a second consequence : when I used modify() on a Wt::Dbo::ptr, it generated the update sql statement with null values for strings excepted for the value i wanted to update. As a result, i had a line where all my previous string values are empty, which was not the expected result at all.
RE: [Wt::Dbo] [Postgres] [Wt 3.2.1] Get on Wt::Dbo::Ptr return empty string - Added by Koen Deforche 11 months ago
Hey Thomas,
That is truly odd, std::string and WString are stored almost exactly the same (the latter using UTF-8 encoding).
The test suite runs fine with postgres as a backend (I just checked now to be sure), and tests retrieval of both std::string and WString values (dbo_test1()).
Your second observation is indeed consistent with there something going wrong when reading a std::string. Can you reproduce it in a small test case so that we can see whether it is something that we could reproduce too ?
Regards,
koen
RE: [Wt::Dbo] [Postgres] [Wt 3.2.1] Get on Wt::Dbo::Ptr return empty string - Added by Thomas Saquet 10 months ago
Hello Koen,
After further investigations, trying to write the small test case, i found out that the problem came in fact from a pointer within a map i used to fill all the fields at once. I was looking the wrong place. I think I had a false-positive when it worked with the WString because afterall it was failing too.
Thank you for your help, next time i will run the test case by myself before asking for help.
(1-3/3)