[Mono-list] Re: MySQLDataReader.Read Exception

Jeremy N. Morgan jmorgan@ALAW.ORG
Thu, 9 Jan 2003 10:28:31 -0800


As far as I can tell, the problem appears to be that MySQL doesn't use
an actual date to display an empty string.  MySQL uses 0000-00-00,
unlike the other databases I am familiar with (MS-SQL and Oracle), which
use 1900-01-01, a valid date.  When the MySQLreader gets the 0000-00-00,
it tries to cast it into a datetime value and fails (with 0000-00-00 not
being a valid date).

Try setting your select statement to do an IF(expr1,expr2,expr3) when
returning that field to return a valid date if it encounters an empty
string like:

Select if(date1='', '1900-01-01', date1) as date1 from table1;
 

Not knowing C# very well, I don't know how to fix this in the
MySQLReader code, but my hunch is that the MySQLReader just needs a
datetime '' handler.  If it was based on the SQLDataReader, it probably
doesn't have one because SQLDataReader doesn't need one since it would
only ever get a valid date or null.

Does that help?

Jeremy N. Morgan


-----Original Message-----
From: Rodrigo Moya [mailto:rodrigo@ximian.com] 
Sent: Wednesday, January 08, 2003 4:24 PM
To: Vincent Daron
Cc: mono-list@ximian.com
Subject: [Mono-list] Re: MySQLDataReader.Read Exception


On Wed, 2003-01-08 at 22:03, Vincent Daron wrote:
> hello
> 
> I've got an invalid cast exception in MySQLDataReader.Read() while 
> reading a row containing a DateTime field = 0000-00-00 00:00:00.
> 
> It's less than DateTime.MinValue and I suppose that the problem is the

> same with value bigger than MaxValue.
> 
> Any idea ?
>
not sure what it is, so forwarding to the mono list.

cheers

-- 
Rodrigo Moya <rodrigo@ximian.com>


_______________________________________________
Mono-list maillist  -  Mono-list@ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list