WDateTime fields causing 'infinity' and crashing Wt

Added by Mark Petryk 7 months ago

I have a couple of WDateTime fields in my application, and for whatever reason they are getting set to "infinity" in the back-end database. When this happens, Wt crashes

lastActivity              | timestamp without time zone | 
openedOn | timestamp without time zone |

[2016-Sep-28 16:05:16.372627] 26257 [/staff YA03iw38SlXtYNmC] [error] "Wt: error during event handling: bad lexical cast: source type value could not be interpreted as target"
[2016-Sep-28 16:05:16.372744] 26257 [/staff YA03iw38SlXtYNmC] [error] "Wt: fatal error: bad lexical cast: source type value could not be interpreted as target"

I'm not sure specifically what's happening in my application yet that causing these field values to go this way, but it's pretty fatal.

Any suggestions?

~mark


Replies (3)

RE: WDateTime fields causing 'infinity' and crashing Wt - Added by Mark Petryk 7 months ago

More Details.

from template <class Action> void persist( Action & a )
498 Wt::Dbo::field( a, m_lastActivity, LastActivityFieldDef.field );
500 Wt::Dbo::field( a, m_openedOn, OpenedOnFieldDef.field );
547 Wt::WDateTime m_lastActivity;
551 Wt::WDateTime m_openedOn;

RE: WDateTime fields causing 'infinity' and crashing Wt - Added by Mark Petryk 7 months ago

I've found my issue, I just don't know how to solve it;

1. I have the "m_openedOn" field (or any date-time field) on a WTemplateFormView upon which when I hit 'save' on this form view and read out all the field values and update the WFormModel and then ultimately push all that data back to the back-end database, it is at this time that the back-end database gets a "infinity" value.

The problem is, when I read the data back in the "infinity" value generates the 'bad lexical cast' error on the WDateTime column.

Even when I use a WDateEdit widget, and set the date value to a valid value, it seems to not write the value back to the back-end database.

How do I resolve this? Having a NULL value in a date field shouldn't be a problem, should it? Should it not read/write that NULL value in and out of the back-end and in and out of the WDateTime column? Can I not use a WDateEdit on a column which is of the type WDateTime (mixing of date and time in one column)?

I have used a WLineEdit in place of this WDateEdit for this column and it still seems to generate the error.

~mark

wt-date-edit-wrong-date-format.png - WDateEdit should be MM/DD/YYYY (8.89 KB)

RE: WDateTime fields causing 'infinity' and crashing Wt - Added by Korneel Dumon 7 months ago

Hi Mark,

I'm not sure what can be the problem here. Could you check to see what is actually written to the database (e.g. break in the persist method to check the value before it gets written)?
The value for m_lastActivity can't be null, since it is not a pointer. But can you check if the function WDateTime::isNull returns true? And perhaps also WDateTime::isValid? I'm still just guessing a bit here, but hopefully this clears up the problem.

Korneel

(1-3/3)