Skip to content

Commit d2e56e6

Browse files
fredericDelaportehazzik
authored andcommitted
Fix #1362 - Running Unit tests against SQLite fails on datetime/UTC (#1378)
1 parent b1db0b5 commit d2e56e6

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

doc/reference/modules/configuration.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,13 @@ in the parameter binding.</programlisting>
12891289
Set <literal>driver_class</literal> to
12901290
<literal>NHibernate.Driver.SQLite20Driver</literal>
12911291
for System.Data.SQLite provider for .NET 2.0.
1292+
<para>
1293+
Due to
1294+
<ulink url="https://system.data.sqlite.org/index.html/tktview/44a0955ea344a777ffdbcc077831e1adc8b77a36">the
1295+
behavior of System.Data.SQLite</ulink> with <literal>DateTime</literal>, consider using
1296+
<literal>DateTimeFormatString=yyyy-MM-dd HH:mm:ss.FFFFFFF;</literal> in the SQLite
1297+
connection string for preventing undesired time shifts with its default configuration.
1298+
</para>
12921299
</entry>
12931300
</row>
12941301
<row>

src/NHibernate.Config.Templates/SQLite.cfg.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ for your own use before compile tests in VisualStudio.
77
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
88
<session-factory name="NHibernate.Test">
99
<property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>
10+
<!-- DateTimeFormatString allows to prevent storing the fact that written date was having kind UTC,
11+
which dodges the undesirable time conversion to local done on reads by System.Data.SQLite.
12+
See https://system.data.sqlite.org/index.html/tktview/44a0955ea344a777ffdbcc077831e1adc8b77a36
13+
and https://github.com/nhibernate/nhibernate-core/issues/1362 -->
1014
<property name="connection.connection_string">
11-
Data Source=nhibernate.db
15+
Data Source=nhibernate.db;
16+
DateTimeFormatString=yyyy-MM-dd HH:mm:ss.FFFFFFF;
1217
</property>
1318
<property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
1419
</session-factory>
15-
</hibernate-configuration>
20+
</hibernate-configuration>

teamcity.build

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,12 @@
108108

109109
<target name="setup-teamcity-sqlite32">
110110
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.SQLite20Driver" />
111+
<!-- DateTimeFormatString allows to prevent storing the fact that written date was having kind UTC,
112+
which dodges the undesirable time conversion to local done on reads by System.Data.SQLite.
113+
See https://system.data.sqlite.org/index.html/tktview/44a0955ea344a777ffdbcc077831e1adc8b77a36
114+
and https://github.com/nhibernate/nhibernate-core/issues/1362 -->
111115
<property name="nhibernate.dialect" value="NHibernate.Dialect.SQLiteDialect" />
112-
<property name="nhibernate.connection.connection_string" value="Data Source=NHibernate.db" />
116+
<property name="nhibernate.connection.connection_string" value="Data Source=NHibernate.db;DateTimeFormatString=yyyy-MM-dd HH:mm:ss.FFFFFFF;" />
113117
<copy todir="${bin.dir}">
114118
<fileset basedir="${root.dir}/lib/teamcity/sqlite/x86">
115119
<include name="*.dll"/>
@@ -120,8 +124,12 @@
120124
<target name="setup-teamcity-sqlite64">
121125
<property name="nunit-x64" value="true" />
122126
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.SQLite20Driver" />
127+
<!-- DateTimeFormatString allows to prevent storing the fact that written date was having kind UTC,
128+
which dodges the undesirable time conversion to local done on reads by System.Data.SQLite.
129+
See https://system.data.sqlite.org/index.html/tktview/44a0955ea344a777ffdbcc077831e1adc8b77a36
130+
and https://github.com/nhibernate/nhibernate-core/issues/1362 -->
123131
<property name="nhibernate.dialect" value="NHibernate.Dialect.SQLiteDialect" />
124-
<property name="nhibernate.connection.connection_string" value="Data Source=NHibernate.db" />
132+
<property name="nhibernate.connection.connection_string" value="Data Source=NHibernate.db;DateTimeFormatString=yyyy-MM-dd HH:mm:ss.FFFFFFF;" />
125133
<copy todir="${bin.dir}">
126134
<fileset basedir="${root.dir}/lib/teamcity/sqlite/x64">
127135
<include name="*.dll"/>

0 commit comments

Comments
 (0)