[Mono-list] Re: MySQLDataReader.Read Exception

Vincent Daron vdaron@ask.be
09 Jan 2003 22:01:46 +0100


Tanks,

The response is simple: do not use date = 0000-00-00 00:00:00 with
MySQL, use 1900-01-01 instead. ;-)

But the problem is the exception in the DataReader.

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

Is this a standard SQL 92 Select ?

Thanks a lot

Vincent

On Thu, 2003-01-09 at 19:28, Jeremy N. Morgan wrote:
> 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
-- 
Vincent Daron <vdaron@ask.be>
ASK sa