yasser777 / nettiers

Automatically exported from code.google.com/p/nettiers
0 stars 0 forks source link

DateTime columns with ParseDbColDefaultVal use correct syntax? #329

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create Non-PK DateTime column in a DB with a fixed default value 
   (such as '1/1/2000 12:00:00' instead of getdate())
2. Generate with ParseDbColDefaultVal = True
3. Open with Visual Studio and Compile

What is the expected output? What do you see instead?
Expected output is "Compiled", instead I get compiler errors

What version of .netTiers and CodeSmith are you using?
Codesmith 5.1.3r8510
nettiers 2.3 r850 

Please provide any additional information below.
There is no default constructor for a DateTime object that accepts a string as 
a value, only ones with varying numbers of ints.  

Line 3957-3959 of CommonSqlCode.cs reads:
  dateConvert = DateTime.Parse(defaultValue);
  if (defaultValue != null )
    return "new DateTime(\"" + dateConvert.ToString() + "\")";

and I believe this is where the code is generated.  

The simple way is to change to:
    return "new DateTime.Parse(\"" + dateConvert.ToString() + "\")";

but this may cause culture errors (for example, generate netTiers on a en-US 
and compile on a de-DE computer).

I would suggest using something like:
    return "new DateTime.ParseExact(\"" + dateConvert.ToString("yyyy-MM-dd hh:mm:ss", \"yyyy-MM-dd hh:mm:ss\") + "\")";

or use the "new DateTime(int, int, int, int, int, int)" constructor.

Thanks!

Original issue reported on code.google.com by mikiur...@gmail.com on 23 Aug 2010 at 6:18

GoogleCodeExporter commented 9 years ago
My "simple" suggestion has a typo, should be:
  return "DateTime.Parse(\"" + dateConvert.ToString() + "\")";
instead of 
  return "new DateTime.Parse(\"" + dateConvert.ToString() + "\")";

oops :)

Original comment by mikiur...@gmail.com on 23 Aug 2010 at 6:31

GoogleCodeExporter commented 9 years ago
Hello,

Thanks, I'll try and get this into core.

Thanks
-Blake Niemyjski

Original comment by bniemyjski on 21 Sep 2010 at 12:28

GoogleCodeExporter commented 9 years ago
Patch attached and committed in r884. Default values correctly initialised for 
DateTime & Time data types.

Original comment by xk...@yahoo.com on 17 Feb 2011 at 1:47

Attachments:

GoogleCodeExporter commented 9 years ago
Never said thanks, so thanks :)

Original comment by mikiur...@gmail.com on 26 Jul 2011 at 12:08