Safir SDK Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Columns.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Copyright Saab AB, 2005-2013 (http://safir.sourceforge.net)
4 *
5 * Created by: Jörgen Johansson / stjrjo
6 *
7 *******************************************************************************
8 *
9 * This file is part of Safir SDK Core.
10 *
11 * Safir SDK Core is free software: you can redistribute it and/or modify
12 * it under the terms of version 3 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * Safir SDK Core is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Safir SDK Core. If not, see <http://www.gnu.org/licenses/>.
22 *
23 ******************************************************************************/
24 #if !defined(Safir_Databases_Odbc_Columns_h)
25 #define Safir_Databases_Odbc_Columns_h
26 
28 #include "Safir/Databases/Odbc/Internal/InternalDefs.h"
29 #include "Safir/Databases/Odbc/Internal/Column.h"
30 #include "Safir/Databases/Odbc/Internal/BinaryColumn.h"
31 #include "Safir/Databases/Odbc/Internal/WideStringColumn.h"
32 
34 #include <boost/date_time/posix_time/posix_time.hpp>
36 
37 namespace Safir
38 {
39 namespace Databases
40 {
41 namespace Odbc
42 {
43 
45 // Columns
47 
48 class BooleanColumn : public Internal::Column<SQL_C_BIT, unsigned char>
49 {
50 public:
51  void SetValue(bool bValue);
52  bool GetValue() const;
53 };
54 
55 class TimeColumn : public Internal::Column<SQL_C_TYPE_TIMESTAMP, TIMESTAMP_STRUCT>
56 {
57 public:
58  void SetTimeStamp(const TIMESTAMP_STRUCT & tsTime);
60 
61  const TIMESTAMP_STRUCT & GetTimeStamp() const;
62  TIMESTAMP_STRUCT GetTimeStamp();
64 private:
65  typedef Internal::Column<SQL_C_TYPE_TIMESTAMP, TIMESTAMP_STRUCT> InstantiatedColumn;
66 };
67 
69 
71 
72 typedef Internal::Column<SQL_C_FLOAT, Safir::Dob::Typesystem::Float32> Float32Column;
73 
74 typedef Internal::Column<SQL_C_DOUBLE, Safir::Dob::Typesystem::Float64> Float64Column;
75 
76 typedef Internal::Column<SQL_C_SLONG, Safir::Dob::Typesystem::Int32> Int32Column;
77 
78 typedef Internal::Column<SQL_C_SBIGINT, Safir::Dob::Typesystem::Int64> Int64Column;
79 
81 // Method implementations - BooleanColumn
83 
84 inline void BooleanColumn::SetValue(bool bValue)
85 {
86  Internal::Column<SQL_C_BIT, unsigned char>::SetValue(bValue ? 1 : 0);
87 }
88 
89 inline bool BooleanColumn::GetValue() const
90 {
91  return Internal::Column<SQL_C_BIT, unsigned char>::GetValue() == 1;
92 }
93 
95 // Method implementations - TimeColumn
97 
98 inline void TimeColumn::SetTimeStamp(const TIMESTAMP_STRUCT & tsTime)
99 {
100  InstantiatedColumn::SetValue( tsTime );
101 }
102 
104 {
105  boost::posix_time::ptime pTime;
106  TIMESTAMP_STRUCT value;
107 
108  pTime = Safir::Time::TimeProvider::ToPtime( time );
109  value.year = static_cast<SQLSMALLINT>(pTime.date().year());
110  value.month = static_cast<SQLUSMALLINT>(pTime.date().month());
111  value.day = static_cast<SQLUSMALLINT>(pTime.date().day());
112  value.hour = static_cast<SQLUSMALLINT>(pTime.time_of_day().hours());
113  value.minute = static_cast<SQLUSMALLINT>(pTime.time_of_day().minutes());
114  value.second = static_cast<SQLUSMALLINT>(pTime.time_of_day().seconds());
115  value.fraction = static_cast<SQLUINTEGER>(pTime.time_of_day().fractional_seconds());
116  InstantiatedColumn::SetValue( value );
117 }
118 
119 inline const TIMESTAMP_STRUCT & TimeColumn::GetTimeStamp() const
120 {
121  return InstantiatedColumn::GetValue();
122 }
123 
124 inline TIMESTAMP_STRUCT TimeColumn::GetTimeStamp()
125 {
126  return InstantiatedColumn::GetValue();
127 }
128 
130 {
131  boost::gregorian::date pDate(m_value.year, m_value.month, m_value.day);
132  boost::posix_time::time_duration pTimeDuration(m_value.hour, m_value.minute, m_value.second, m_value.fraction);
133  boost::posix_time::ptime pTime(pDate, pTimeDuration);
134 
135  time = Safir::Time::TimeProvider::ToDouble( pTime );
136 }
137 
138 }; // Odbc
139 
140 }; // Databases
141 
142 }; // Safir
143 
144 #endif // Safir_Databases_Odbc_Columns_h
bool GetValue() const
Definition: Columns.h:89
static boost::posix_time::ptime ToPtime(const Safir::Dob::Typesystem::Si64::Second utcTime)
Get specified UTC time in boost::posix_time::ptime representation.
void SetTimeStamp(const TIMESTAMP_STRUCT &tsTime)
Definition: Columns.h:98
const TIMESTAMP_STRUCT & GetTimeStamp() const
Definition: Columns.h:119
Internal::Column< SQL_C_FLOAT, Safir::Dob::Typesystem::Float32 > Float32Column
Definition: Columns.h:72
static Safir::Dob::Typesystem::Si64::Second ToDouble(const boost::posix_time::ptime &utcTime)
Convert specified UTC time to a Double.
Internal::WideStringColumn WideStringColumn
Definition: Columns.h:70
Definition: Columns.h:55
Float64 Second
64 bit representation of Second.
Definition: Defs.h:198
Internal::BinaryColumn BinaryColumn
Definition: Columns.h:68
void SetValue(Safir::Dob::Typesystem::Si64::Second time)
Definition: Columns.h:103
Internal::Column< SQL_C_SBIGINT, Safir::Dob::Typesystem::Int64 > Int64Column
Definition: Columns.h:78
Internal::Column< SQL_C_DOUBLE, Safir::Dob::Typesystem::Float64 > Float64Column
Definition: Columns.h:74
Internal::Column< SQL_C_SLONG, Safir::Dob::Typesystem::Int32 > Int32Column
Definition: Columns.h:76
void SetValue(bool bValue)
Definition: Columns.h:84
void GetValue(Safir::Dob::Typesystem::Si64::Second &time) const
Definition: Columns.h:129