Skip to content

Commit cef3d7c

Browse files
Add configuration option to enable the use of the SmallDateTime datatype in SQL Server. (#986)
(cherry picked from commit 75c9b5b) # Conflicts: # dotnet/src/dotnetframework/GxClasses/Data/GXDataCommon.cs
1 parent 4927088 commit cef3d7c

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
@@ -2714,7 +2714,12 @@ GxDataRecord getDbmsDataRecord(string id, string dbms)
27142714
switch (dbms)
27152715
{
27162716
case "sqlserver":
2717-
return new GxSqlServer();
2717+
GxSqlServer gxSqlServer = new GxSqlServer();
2718+
if (Config.GetValueOf("Connection-" + id + "-UseSmallDateTime", out cfgBuf) && cfgBuf == "1")
2719+
{
2720+
gxSqlServer.UseSmallDateTime();
2721+
}
2722+
return gxSqlServer;
27182723
case "mysql":
27192724
#if NETCORE
27202725
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
@@ -1571,7 +1571,12 @@ public class GxSqlServer : GxDataRecord
15711571
private const int MILLISECONDS_BETWEEN_RETRY_ATTEMPTS=500;
15721572
private const string MULTIPLE_DATAREADERS = "MultipleActiveResultSets";
15731573
private bool multipleDatareadersEnabled;
1574+
private DateTime SqlServer_NullDateTime= SQLSERVER_NULL_DATETIME;
15741575

1576+
internal void UseSmallDateTime()
1577+
{
1578+
SqlServer_NullDateTime = SQLSERVER_NULL_SMALLDATETIME;
1579+
}
15751580
public override int GetCommandTimeout()
15761581
{
15771582
return base.GetCommandTimeout();
@@ -2041,14 +2046,14 @@ public override DateTime Dbms2NetDate(IGxDbCommand cmd, IDataRecord DR, int i)
20412046
public override DateTime Dbms2NetDateTime( DateTime dt, Boolean precision)
20422047
{
20432048
//DBMS MinDate => Genexus null Date
2044-
if (dt.Equals(SQLSERVER_NULL_DATE))
2049+
if (dt.Equals(SqlServer_NullDateTime))
20452050
{
20462051
return DateTimeUtil.NullDate();
20472052
}
20482053

2049-
if (dt.Year==SQLSERVER_NULL_DATE.Year &&
2050-
dt.Month==SQLSERVER_NULL_DATE.Month &&
2051-
dt.Day==SQLSERVER_NULL_DATE.Day)
2054+
if (dt.Year== SqlServer_NullDateTime.Year &&
2055+
dt.Month== SqlServer_NullDateTime.Month &&
2056+
dt.Day== SqlServer_NullDateTime.Day)
20522057
{
20532058

20542059
return new DateTime(
@@ -2064,16 +2069,16 @@ public override Object Net2DbmsDateTime(IDbDataParameter parm, DateTime dt)
20642069
//Genexus null => save DBMS MinDate
20652070
if(dt.Equals(DateTimeUtil.NullDate()))
20662071
{
2067-
return SQLSERVER_NULL_DATE;
2072+
return SqlServer_NullDateTime;
20682073
}
20692074

20702075
//Date < DBMS MinDate => save DBMS MinDate keeping the Time component
2071-
if (dt.CompareTo(SQLSERVER_NULL_DATE)<0)
2076+
if (dt.CompareTo(SqlServer_NullDateTime) <0)
20722077
{
20732078
DateTime aux =
20742079
new DateTime(
2075-
SQLSERVER_NULL_DATE.Year,SQLSERVER_NULL_DATE.Month,
2076-
SQLSERVER_NULL_DATE.Day,dt.Hour,dt.Minute,dt.Second,dt.Millisecond);
2080+
SqlServer_NullDateTime.Year, SqlServer_NullDateTime.Month,
2081+
SqlServer_NullDateTime.Day,dt.Hour,dt.Minute,dt.Second,dt.Millisecond);
20772082

20782083
return aux;
20792084
}
@@ -2088,8 +2093,8 @@ public override string ConcatOp(int pos)
20882093
{
20892094
return ConcatOpValues[pos];
20902095
}
2091-
2092-
static DateTime SQLSERVER_NULL_DATE = new DateTime(1753,1,1) ;
2096+
static DateTime SQLSERVER_NULL_DATETIME = new DateTime(1753,1,1) ;
2097+
static DateTime SQLSERVER_NULL_SMALLDATETIME= new DateTime(1900, 1, 1);
20932098
}
20942099

20952100
public class GxDataReader: IDataReader

0 commit comments

Comments
 (0)