From 03529d414dd9afc3994995f1fdfb9df3c6d53826 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 30 Jan 2012 14:56:36 +0200 Subject: Handle SMALLDATETIME case in SQL Server QDateTime traits implementation --- odb/qt/date-time/mssql/qdate-time-traits.hxx | 38 ++++++++++++++++++---------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/odb/qt/date-time/mssql/qdate-time-traits.hxx b/odb/qt/date-time/mssql/qdate-time-traits.hxx index f64906e..8d421d6 100644 --- a/odb/qt/date-time/mssql/qdate-time-traits.hxx +++ b/odb/qt/date-time/mssql/qdate-time-traits.hxx @@ -60,22 +60,34 @@ namespace odb i.day = static_cast (d.day ()); i.hour = static_cast (t.hour ()); i.minute = static_cast (t.minute ()); - i.second = static_cast (t.second ()); - const unsigned int divider[8] = + // Scale value 8 indicates we are dealing with SMALLDATETIME + // which has the minutes precision. + // + if (s != 8) { - 1000000000, - 100000000, - 10000000, - 1000000, - 100000, - 10000, - 1000, - 100 - }; + i.second = static_cast (t.second ()); + + const unsigned int divider[8] = + { + 1000000000, + 100000000, + 10000000, + 1000000, + 100000, + 10000, + 1000, + 100 + }; - unsigned int ns (static_cast (t.msec ()) * 1000000); - i.fraction = static_cast (ns - ns % divider[s]); + unsigned int ns (static_cast (t.msec ()) * 1000000); + i.fraction = static_cast (ns - ns % divider[s]); + } + else + { + i.second = 0; + i.fraction = 0; + } } } }; -- cgit v1.1