Skip to content

Commit 75c9b5b

Browse files
Add configuration option to enable the use of the SmallDateTime datatype in SQL Server. (#986)
1 parent 4e10eec commit 75c9b5b

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

dotnet/src/dotnetframework/GxClasses/Data/GXDataADO.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,12 @@ GxDataRecord getDbmsDataRecord(string id, string dbms)
27192719
switch (dbms)
27202720
{
27212721
case "sqlserver":
2722-
return new GxSqlServer();
2722+
GxSqlServer gxSqlServer = new GxSqlServer();
2723+
if (Config.GetValueOf("Connection-" + id + "-UseSmallDateTime", out cfgBuf) && cfgBuf == "1")
2724+
{
2725+
gxSqlServer.UseSmallDateTime();
2726+
}
2727+
return gxSqlServer;
27232728
case "mysql":
27242729
#if NETCORE
27252730
return new GxMySqlConnector(id);

dotnet/src/dotnetframework/GxClasses/Data/GXDataCommon.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,12 @@ public class GxSqlServer : GxDataRecord
15991599
private const string INTEGRATED_SECURITY_NO = "no";
16001600
#endif
16011601
private bool multipleDatareadersEnabled;
1602+
private DateTime SqlServer_NullDateTime= SQLSERVER_NULL_DATETIME;
16021603

1604+
internal void UseSmallDateTime()
1605+
{
1606+
SqlServer_NullDateTime = SQLSERVER_NULL_SMALLDATETIME;
1607+
}
16031608
public override int GetCommandTimeout()
16041609
{
16051610
return base.GetCommandTimeout();
@@ -2114,14 +2119,14 @@ public override DateTime Dbms2NetDate(IGxDbCommand cmd, IDataRecord DR, int i)
21142119
public override DateTime Dbms2NetDateTime( DateTime dt, Boolean precision)
21152120
{
21162121
//DBMS MinDate => Genexus null Date
2117-
if (dt.Equals(SQLSERVER_NULL_DATE))
2122+
if (dt.Equals(SqlServer_NullDateTime))
21182123
{
21192124
return DateTimeUtil.NullDate();
21202125
}
21212126

2122-
if (dt.Year==SQLSERVER_NULL_DATE.Year &&
2123-
dt.Month==SQLSERVER_NULL_DATE.Month &&
2124-
dt.Day==SQLSERVER_NULL_DATE.Day)
2127+
if (dt.Year== SqlServer_NullDateTime.Year &&
2128+
dt.Month== SqlServer_NullDateTime.Month &&
2129+
dt.Day== SqlServer_NullDateTime.Day)
21252130
{
21262131

21272132
return new DateTime(
@@ -2137,16 +2142,16 @@ public override Object Net2DbmsDateTime(IDbDataParameter parm, DateTime dt)
21372142
//Genexus null => save DBMS MinDate
21382143
if(dt.Equals(DateTimeUtil.NullDate()))
21392144
{
2140-
return SQLSERVER_NULL_DATE;
2145+
return SqlServer_NullDateTime;
21412146
}
21422147

21432148
//Date < DBMS MinDate => save DBMS MinDate keeping the Time component
2144-
if (dt.CompareTo(SQLSERVER_NULL_DATE)<0)
2149+
if (dt.CompareTo(SqlServer_NullDateTime) <0)
21452150
{
21462151
DateTime aux =
21472152
new DateTime(
2148-
SQLSERVER_NULL_DATE.Year,SQLSERVER_NULL_DATE.Month,
2149-
SQLSERVER_NULL_DATE.Day,dt.Hour,dt.Minute,dt.Second,dt.Millisecond);
2153+
SqlServer_NullDateTime.Year, SqlServer_NullDateTime.Month,
2154+
SqlServer_NullDateTime.Day,dt.Hour,dt.Minute,dt.Second,dt.Millisecond);
21502155

21512156
return aux;
21522157
}
@@ -2161,8 +2166,8 @@ public override string ConcatOp(int pos)
21612166
{
21622167
return ConcatOpValues[pos];
21632168
}
2164-
2165-
static DateTime SQLSERVER_NULL_DATE = new DateTime(1753,1,1) ;
2169+
static DateTime SQLSERVER_NULL_DATETIME = new DateTime(1753,1,1) ;
2170+
static DateTime SQLSERVER_NULL_SMALLDATETIME= new DateTime(1900, 1, 1);
21662171
}
21672172

21682173
public class GxDataReader: IDataReader

0 commit comments

Comments
 (0)