-
Notifications
You must be signed in to change notification settings - Fork 180
/
coral-CORAL_2_3_21-fix-timestamp-frontier.patch
90 lines (88 loc) · 3.75 KB
/
coral-CORAL_2_3_21-fix-timestamp-frontier.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
diff --git a/src/FrontierAccess/src/Statement.cpp b/src/FrontierAccess/src/Statement.cpp
index 861bf10..1e1e110 100644
--- a/src/FrontierAccess/src/Statement.cpp
+++ b/src/FrontierAccess/src/Statement.cpp
@@ -41,66 +41,8 @@ namespace {
if( !timestamp )
throw coral::Exception( "TimestampParser", "timestamp was zero", "coral::TimestampParser::constructor" );
- char t[31];
- // Copy the original timestamp into our buffer
- strncpy(t, timestamp, 30);
- // Temporary variables
- char* pos01 = t;
- char* pos02 = 0;
- // Parse from 2006-1-12.15.47.0.0
-
- // Get the year
- pos02 = strchr( pos01, '-' );
- if( !pos02 )
- throw coral::Exception( "TimestampParser", "error in parsing the year from timestamp [" + std::string(timestamp) + "]", "coral::TimestampParser::constructor" );
-
- *pos02 = 0;
- size_t year = atoi(pos01);
- pos01 = pos02 + 1;
- // Get the month
- pos02 = strchr( pos01, '-' );
- if( !pos02 )
- throw coral::Exception( "TimestampParser", "error in parsing the month from timestamp [" + std::string(timestamp) + "]", "coral::TimestampParser::constructor" );
-
- *pos02 = 0;
- size_t month = atoi(pos01);
- pos01 = pos02 + 1;
- // Get the day
- pos02 = strchr( pos01, '.' );
- if( !pos02 )
- throw coral::Exception( "TimestampParser", "error in parsing the day from timestamp [" + std::string(timestamp) + "]", "coral::TimestampParser::constructor" );
-
- *pos02 = 0;
- size_t day = atoi(pos01);
- pos01 = pos02 + 1;
- // Get the hour
- pos02 = strchr( pos01, '.' );
- if( !pos02 )
- throw coral::Exception( "TimestampParser", "error in parsing the hour from timestamp [" + std::string(timestamp) + "]", "coral::TimestampParser::constructor" );
-
- *pos02 = 0;
- size_t hour = atoi(pos01);
- pos01 = pos02 + 1;
- // Get the minute
- pos02 = strchr( pos01, '.' );
- if( !pos02 )
- throw coral::Exception( "TimestampParser", "error in parsing the minute from timestamp [" + std::string(timestamp) + "]", "coral::TimestampParser::constructor" );
-
- *pos02 = 0;
- size_t minute = atoi(pos01);
- pos01 = pos02 + 1;
- // Get the second
- pos02 = strchr( pos01, '.' );
- if( !pos02 )
- throw coral::Exception( "TimestampParser", "error in parsing the second from timestamp [" + std::string(timestamp) + "]", "coral::TimestampParser::constructor" );
-
- *pos02 = 0;
- size_t second = atoi(pos01);
- pos01 = pos02 + 1;
- // Get the msecond
- size_t msecond = atoi(pos01);
- // Create a new coral time
- m_time = new coral::TimeStamp( year, month, day, hour, minute, second, msecond );
+ // the format supported is: 'YYYY-MM-DD hh:mm:ss'
+ m_time = new coral::TimeStamp( boost::posix_time::time_from_string(std::string(timestamp)));
}
~TimestampParser()
@@ -212,12 +154,11 @@ namespace coral
}
else if( colType == typeid(coral::TimeStamp) )
{
- std::stringstream os;
+ std::ostringstream os;
const coral::TimeStamp& tsVal = iColumn->data<coral::TimeStamp>();
- os << "'"
- << tsVal.year() << "-" << tsVal.month() << "-" << tsVal.day() << " "
- << tsVal.hour() << ":" << tsVal.minute() << ":" << tsVal.second()
- << "." << tsVal.nanosecond() << "'";
+ boost::posix_time::time_facet* facet = new boost::posix_time::time_facet("%Y-%m-%d %H:%M:%S%F");
+ os.imbue(std::locale(os.getloc(), facet));
+ os << "TO_TIMESTAMP('"<<tsVal.time()<<"','YYYY-MM-DD HH24:MI:SS.FF')";
nipp.bindVariable( iColumn->specification().name(), os.str(), m_sqlStatement );
}
else if( colType == typeid(bool) )