FransBouma/Massive

Massive.Oracle.cs - Inserting Date/Time

AlphaGeek509 opened this issue · 2 comments

What recommendation can you pass my way about inserting/updating a model field that is of Oracle Date datatype?

   [Test]
   public void Insert_AsObject()
   {
       dynamic obj = new ExpandoObject();
       obj.AUTH_QA_DATE = "1/14/2016 12:12";

       var objPrc = new PrintRevControl();
       objPrc.Insert(obj);
       Assert.Greater(obj.ID, 1);
   }

During this execution of the unit test above, I was trying different date combinations but receiving Oracle errors, ORA-01843 Invalid Month and ORA-01861 String Literal. Upon my investigation, I found that my database is running the following format for DATE.

select * from nls_database_parameters where parameter = 'NLS_DATE_FORMAT';
VALUE
-------------
DD-MON-RR

By changing my AUTH_QA_DATE to "14-JAN-16", Massive worked beautifully. However, the data type is needing to be a date time and upon changing the field to "14-JAN-16 22:45", I receive and ORA-01830 Picture Format. Kind of expected by me.

So, I see that this is an issue with how my data is going into Massive. It needs to be scrubbed for the proper format, but using parameterization, how can I get around the adding time format? I read up about people adding TO_DATE(), but that won't work given parameterization and escaping single quotes. I've also read about changing the session format (https://community.oracle.com/thread/1071059?tstart=0) which seems slightly interesting but not a long term viable solution. It would appear that under Massive.Oracle.cs > AddParam is the smartest place to make a change checking for and modifying the param for date, but what insight could you provide me?

Why not store a DateTime value (the .net type) instead? It will end up as a DateTime value in the parameter and ODPNET will convert it for you to Date.

Beautiful! I changed the datatype to TIMESTAMP and took your advice. The unit test worked as described. For the sake of anybody else going back and look at old issues, like me, here's my test.

[Test]
public void Insert_AsObject()
{
    dynamic obj = new ExpandoObject();
    obj.AUTH_QA_TIME_STAMP = DateTime.Now;   //.AddHours(12); //Look for AM/PM changes.

    var objPrc = new PrintRevControl();
    objPrc.Insert(obj);
    Assert.Greater(obj.ID, 1);
    Console.WriteLine(obj.ID);
}