Pervasive
Sign in | Join | Help
in

Date conversion function fails after numerous calls

Last post 06-02-2008 3:52 PM by Russ. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 06-02-2008 2:52 PM

    • Russ
    • Not Ranked
    • Joined on 06-02-2008
    • Posts 2

    Date conversion function fails after numerous calls

    We have a legacy product that stores dates in the database in 4 seperate columns (century,year,month,day). I've written a function to convert the columns to a date.  When the function is called numerous times using Pervasive's ADO.Net data provider (version 2.10.1.2 or 3.0)  the function fails with an ArgumentOutOfRangeException: Year, Month, and Day parameters descibe an un-representable DateTime. It appears a stack/memory problem but no way to be sure. I've tried the same function using CAST instead of CONVERT, and a number of other changes, but I still get the error. The function appears below. Any help would be greatly appreciated. I'm running workgroup v9.5 sp2 with the latest hotfix.

    CREATE FUNCTION TO_SQL_DATE(IN :c tinyint, IN :y tinyint, IN :m tinyint, IN :d tinyint) RETURNS DATE

    AS

    BEGIN

    DECLARE :returnDate DATE;

    SET :returnDate = CONVERT(IF(:c = 0 OR :c = 32 OR :m > 12, '0001-01-01', RIGHT(CONVERT(100 + :c, SQL_CHAR), 2) + RIGHT(CONVERT(100 + :y, SQL_CHAR), 2) + '-' + RIGHT(CONVERT(100 + :m, SQL_CHAR), 2) + '-' + RIGHT(CONVERT(100 + :d, SQL_CHAR), 2)), SQL_DATE);

    RETURN (:returnDate);

    END

  • 06-02-2008 3:30 PM In reply to

    Re: Date conversion function fails after numerous calls

     What's "numerous" mean?  Is it 10, 100,1000, or does it vary? 

    I just tried with v10 and ran the function 1000 times with no error.  

    Mirtheil
  • 06-02-2008 3:52 PM In reply to

    • Russ
    • Not Ranked
    • Joined on 06-02-2008
    • Posts 2

    Re: Date conversion function fails after numerous calls

    It is around 150 typically, assuming that the sql statement contains about 12 calls to the function.  The other thing I neglected to include was that connection pooling is enabled and if you try to re-run the same script even after the connection is closed and re-opened if fails immediately (I assume that's because it is re-using the same pooled connection).  Here is a same sql statement

    select
    TO_SQL_DATE(Date1C, Date1Y, Date1M, Date1D) as Date1,
    TO_SQL_DATE(Date2C, Date2Y, Date2M, Date2D) as Date2,
    TO_SQL_DATE(Date3C, Date3Y, Date3M, Date3D) as Date3,
    TO_SQL_DATE(Date4C, Date4Y, Date4M, Date4D) as Date4,
    TO_SQL_DATE(Date5C, Date5Y, Date5M, Date5D) as Date5,
    TO_SQL_DATE(Date6C, Date6Y, Date6M, Date6D) as Date6,
    TO_SQL_DATE(Date7C, Date7Y, Date7M, Date7D) as Date7,
    TO_SQL_DATE(Date8C, Date8Y, Date8M, Date8D) as Date8,
    TO_SQL_DATE(Date9C, Date9Y, Date9M, Date9D) as Date9,
    TO_SQL_DATE(Date10C, Date10Y, Date10M, Date10D) as Date10
    From SomeTable

Page 1 of 1 (3 items)
© 2008 Pervasive Software Inc. All Rights Reserved.