Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
3519c3ce
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3519c3ce
编写于
2月 03, 2016
作者:
A
Alexey Milovidov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dbms: separated mysqlxx::Date and mysqlxx::DateTime [#METR-17973].
上级
48a1fe18
变更
21
隐藏空白更改
内联
并排
Showing
21 changed file
with
121 addition
and
128 deletion
+121
-128
dbms/include/DB/Core/toField.h
dbms/include/DB/Core/toField.h
+2
-2
dbms/include/DB/Dictionaries/MySQLDictionarySource.h
dbms/include/DB/Dictionaries/MySQLDictionarySource.h
+3
-3
dbms/include/DB/IO/ReadHelpers.h
dbms/include/DB/IO/ReadHelpers.h
+12
-12
dbms/include/DB/IO/WriteHelpers.h
dbms/include/DB/IO/WriteHelpers.h
+10
-10
dbms/src/Client/Client.cpp
dbms/src/Client/Client.cpp
+1
-1
dbms/src/IO/tests/operators.cpp
dbms/src/IO/tests/operators.cpp
+2
-2
dbms/src/Interpreters/Quota.cpp
dbms/src/Interpreters/Quota.cpp
+2
-2
dbms/src/Server/OLAPQueryParser.cpp
dbms/src/Server/OLAPQueryParser.cpp
+1
-1
dbms/src/Server/StatusFile.cpp
dbms/src/Server/StatusFile.cpp
+2
-2
dbms/src/Storages/MergeTree/ReplicatedMergeTreeLogEntry.cpp
dbms/src/Storages/MergeTree/ReplicatedMergeTreeLogEntry.cpp
+2
-2
dbms/src/Storages/System/StorageSystemParts.cpp
dbms/src/Storages/System/StorageSystemParts.cpp
+1
-1
dbms/src/Storages/tests/part_name.cpp
dbms/src/Storages/tests/part_name.cpp
+2
-2
libs/libcommon/include/common/LocalDate.h
libs/libcommon/include/common/LocalDate.h
+24
-28
libs/libcommon/include/common/LocalDateTime.h
libs/libcommon/include/common/LocalDateTime.h
+24
-29
libs/libmysqlxx/include/mysqlxx/Connection.h
libs/libmysqlxx/include/mysqlxx/Connection.h
+1
-0
libs/libmysqlxx/include/mysqlxx/Manip.h
libs/libmysqlxx/include/mysqlxx/Manip.h
+13
-13
libs/libmysqlxx/include/mysqlxx/Row.h
libs/libmysqlxx/include/mysqlxx/Row.h
+1
-0
libs/libmysqlxx/include/mysqlxx/Types.h
libs/libmysqlxx/include/mysqlxx/Types.h
+2
-2
libs/libmysqlxx/include/mysqlxx/Value.h
libs/libmysqlxx/include/mysqlxx/Value.h
+11
-11
libs/libmysqlxx/include/mysqlxx/mysqlxx.h
libs/libmysqlxx/include/mysqlxx/mysqlxx.h
+3
-3
libs/libmysqlxx/src/tests/mysqlxx_test.cpp
libs/libmysqlxx/src/tests/mysqlxx_test.cpp
+2
-2
未找到文件。
dbms/include/DB/Core/toField.h
浏览文件 @
3519c3ce
...
...
@@ -16,12 +16,12 @@ inline Field toField(const T & x)
return
Field
(
typename
NearestFieldType
<
T
>::
Type
(
x
));
}
inline
Field
toField
(
const
mysqlxx
::
Date
&
x
)
inline
Field
toField
(
const
Local
Date
&
x
)
{
return
toField
(
static_cast
<
UInt16
>
(
x
.
getDayNum
()));
}
inline
Field
toField
(
const
mysqlxx
::
DateTime
&
x
)
inline
Field
toField
(
const
Local
DateTime
&
x
)
{
return
toField
(
static_cast
<
UInt32
>
(
static_cast
<
time_t
>
(
x
)));
}
...
...
dbms/include/DB/Dictionaries/MySQLDictionarySource.h
浏览文件 @
3519c3ce
...
...
@@ -113,9 +113,9 @@ private:
}
mysqlxx
::
DateTime
getLastModification
()
const
Local
DateTime
getLastModification
()
const
{
mysqlxx
::
DateTime
update_time
{
std
::
time
(
nullptr
)};
Local
DateTime
update_time
{
std
::
time
(
nullptr
)};
if
(
dont_check_update_time
)
return
update_time
;
...
...
@@ -417,7 +417,7 @@ private:
Block
sample_block
;
mutable
mysqlxx
::
PoolWithFailover
pool
;
const
std
::
string
load_all_query
;
mysqlxx
::
DateTime
last_modification
;
Local
DateTime
last_modification
;
};
}
dbms/include/DB/IO/ReadHelpers.h
浏览文件 @
3519c3ce
...
...
@@ -9,8 +9,8 @@
#include <common/Common.h>
#include <common/DateLUT.h>
#include <
mysqlxx/
Date.h>
#include <
mysqlxx/
DateTime.h>
#include <
common/Local
Date.h>
#include <
common/Local
DateTime.h>
#include <DB/Core/Types.h>
#include <DB/Common/Exception.h>
...
...
@@ -429,7 +429,7 @@ inline void readDateText(DayNum_t & date, ReadBuffer & buf)
date
=
DateLUT
::
instance
().
makeDayNum
(
year
,
month
,
day
);
}
inline
void
readDateText
(
mysqlxx
::
Date
&
date
,
ReadBuffer
&
buf
)
inline
void
readDateText
(
Local
Date
&
date
,
ReadBuffer
&
buf
)
{
char
s
[
10
];
size_t
size
=
buf
.
read
(
s
,
10
);
...
...
@@ -491,7 +491,7 @@ inline void readDateTimeText(time_t & datetime, ReadBuffer & buf)
readDateTimeTextFallback
(
datetime
,
buf
);
}
inline
void
readDateTimeText
(
mysqlxx
::
DateTime
&
datetime
,
ReadBuffer
&
buf
)
inline
void
readDateTimeText
(
Local
DateTime
&
datetime
,
ReadBuffer
&
buf
)
{
char
s
[
19
];
size_t
size
=
buf
.
read
(
s
,
19
);
...
...
@@ -527,8 +527,8 @@ inline void readBinary(bool & x, ReadBuffer & buf) { readPODBinary(x, buf); }
inline
void
readBinary
(
uint128
&
x
,
ReadBuffer
&
buf
)
{
readPODBinary
(
x
,
buf
);
}
inline
void
readBinary
(
VisitID_t
&
x
,
ReadBuffer
&
buf
)
{
readPODBinary
(
x
,
buf
);
}
inline
void
readBinary
(
mysqlxx
::
Date
&
x
,
ReadBuffer
&
buf
)
{
readPODBinary
(
x
,
buf
);
}
inline
void
readBinary
(
mysqlxx
::
DateTime
&
x
,
ReadBuffer
&
buf
)
{
readPODBinary
(
x
,
buf
);
}
inline
void
readBinary
(
Local
Date
&
x
,
ReadBuffer
&
buf
)
{
readPODBinary
(
x
,
buf
);
}
inline
void
readBinary
(
Local
DateTime
&
x
,
ReadBuffer
&
buf
)
{
readPODBinary
(
x
,
buf
);
}
/// Общие методы для чтения значения в текстовом виде из tab-separated формата.
...
...
@@ -546,8 +546,8 @@ inline void readText(String & x, ReadBuffer & buf) { readEscapedString(x, buf);
inline
void
readText
(
bool
&
x
,
ReadBuffer
&
buf
)
{
readBoolText
(
x
,
buf
);
}
inline
void
readText
(
VisitID_t
&
x
,
ReadBuffer
&
buf
)
{
readIntText
(
x
,
buf
);
}
inline
void
readText
(
mysqlxx
::
Date
&
x
,
ReadBuffer
&
buf
)
{
readDateText
(
x
,
buf
);
}
inline
void
readText
(
mysqlxx
::
DateTime
&
x
,
ReadBuffer
&
buf
)
{
readDateTimeText
(
x
,
buf
);
}
inline
void
readText
(
Local
Date
&
x
,
ReadBuffer
&
buf
)
{
readDateText
(
x
,
buf
);
}
inline
void
readText
(
Local
DateTime
&
x
,
ReadBuffer
&
buf
)
{
readDateTimeText
(
x
,
buf
);
}
/// Общие методы для чтения значения в текстовом виде, при необходимости, в кавычках.
...
...
@@ -566,14 +566,14 @@ inline void readQuoted(bool & x, ReadBuffer & buf) { readBoolText(x, buf); }
inline
void
readQuoted
(
VisitID_t
&
x
,
ReadBuffer
&
buf
)
{
readIntText
(
x
,
buf
);
}
inline
void
readQuoted
(
mysqlxx
::
Date
&
x
,
ReadBuffer
&
buf
)
inline
void
readQuoted
(
Local
Date
&
x
,
ReadBuffer
&
buf
)
{
assertString
(
"'"
,
buf
);
readDateText
(
x
,
buf
);
assertString
(
"'"
,
buf
);
}
inline
void
readQuoted
(
mysqlxx
::
DateTime
&
x
,
ReadBuffer
&
buf
)
inline
void
readQuoted
(
Local
DateTime
&
x
,
ReadBuffer
&
buf
)
{
assertString
(
"'"
,
buf
);
readDateTimeText
(
x
,
buf
);
...
...
@@ -597,14 +597,14 @@ inline void readDoubleQuoted(bool & x, ReadBuffer & buf) { readBoolText(x, buf
inline
void
readDoubleQuoted
(
VisitID_t
&
x
,
ReadBuffer
&
buf
)
{
readIntText
(
x
,
buf
);
}
inline
void
readDoubleQuoted
(
mysqlxx
::
Date
&
x
,
ReadBuffer
&
buf
)
inline
void
readDoubleQuoted
(
Local
Date
&
x
,
ReadBuffer
&
buf
)
{
assertString
(
"
\"
"
,
buf
);
readDateText
(
x
,
buf
);
assertString
(
"
\"
"
,
buf
);
}
inline
void
readDoubleQuoted
(
mysqlxx
::
DateTime
&
x
,
ReadBuffer
&
buf
)
inline
void
readDoubleQuoted
(
Local
DateTime
&
x
,
ReadBuffer
&
buf
)
{
assertString
(
"
\"
"
,
buf
);
readDateTimeText
(
x
,
buf
);
...
...
dbms/include/DB/IO/WriteHelpers.h
浏览文件 @
3519c3ce
...
...
@@ -393,7 +393,7 @@ inline void writeDateText(DayNum_t date, WriteBuffer & buf)
buf
.
write
(
s
,
10
);
}
inline
void
writeDateText
(
mysqlxx
::
Date
date
,
WriteBuffer
&
buf
)
inline
void
writeDateText
(
Local
Date
date
,
WriteBuffer
&
buf
)
{
char
s
[
10
]
=
{
'0'
,
'0'
,
'0'
,
'0'
,
'-'
,
'0'
,
'0'
,
'-'
,
'0'
,
'0'
};
...
...
@@ -449,7 +449,7 @@ inline void writeDateTimeText(time_t datetime, WriteBuffer & buf)
}
template
<
char
date_delimeter
=
'-'
,
char
time_delimeter
=
':'
>
inline
void
writeDateTimeText
(
mysqlxx
::
DateTime
datetime
,
WriteBuffer
&
buf
)
inline
void
writeDateTimeText
(
Local
DateTime
datetime
,
WriteBuffer
&
buf
)
{
char
s
[
19
]
=
{
'0'
,
'0'
,
'0'
,
'0'
,
date_delimeter
,
'0'
,
'0'
,
date_delimeter
,
'0'
,
'0'
,
' '
,
'0'
,
'0'
,
time_delimeter
,
'0'
,
'0'
,
time_delimeter
,
'0'
,
'0'
};
...
...
@@ -508,8 +508,8 @@ inline void writeBinary(const bool & x, WriteBuffer & buf) { writePODBinary(x,
inline
void
writeBinary
(
const
uint128
&
x
,
WriteBuffer
&
buf
)
{
writePODBinary
(
x
,
buf
);
}
inline
void
writeBinary
(
const
VisitID_t
&
x
,
WriteBuffer
&
buf
)
{
writePODBinary
(
static_cast
<
const
UInt64
&>
(
x
),
buf
);
}
inline
void
writeBinary
(
const
mysqlxx
::
Date
&
x
,
WriteBuffer
&
buf
)
{
writePODBinary
(
x
,
buf
);
}
inline
void
writeBinary
(
const
mysqlxx
::
DateTime
&
x
,
WriteBuffer
&
buf
)
{
writePODBinary
(
x
,
buf
);
}
inline
void
writeBinary
(
const
Local
Date
&
x
,
WriteBuffer
&
buf
)
{
writePODBinary
(
x
,
buf
);
}
inline
void
writeBinary
(
const
Local
DateTime
&
x
,
WriteBuffer
&
buf
)
{
writePODBinary
(
x
,
buf
);
}
/// Методы для вывода значения в текстовом виде для tab-separated формата.
...
...
@@ -531,8 +531,8 @@ inline void writeText(const char * x, WriteBuffer & buf) { writeEscapedString(
inline
void
writeText
(
const
char
*
x
,
size_t
size
,
WriteBuffer
&
buf
)
{
writeEscapedString
(
x
,
size
,
buf
);
}
inline
void
writeText
(
const
VisitID_t
&
x
,
WriteBuffer
&
buf
)
{
writeIntText
(
static_cast
<
const
UInt64
&>
(
x
),
buf
);
}
inline
void
writeText
(
const
mysqlxx
::
Date
&
x
,
WriteBuffer
&
buf
)
{
writeDateText
(
x
,
buf
);
}
inline
void
writeText
(
const
mysqlxx
::
DateTime
&
x
,
WriteBuffer
&
buf
)
{
writeDateTimeText
(
x
,
buf
);
}
inline
void
writeText
(
const
Local
Date
&
x
,
WriteBuffer
&
buf
)
{
writeDateText
(
x
,
buf
);
}
inline
void
writeText
(
const
Local
DateTime
&
x
,
WriteBuffer
&
buf
)
{
writeDateTimeText
(
x
,
buf
);
}
template
<
typename
T
>
inline
void
writeText
(
const
mysqlxx
::
Null
<
T
>
&
x
,
WriteBuffer
&
buf
)
...
...
@@ -563,14 +563,14 @@ inline void writeQuoted(const VisitID_t & x, WriteBuffer & buf)
writeIntText
(
static_cast
<
const
UInt64
&>
(
x
),
buf
);
}
inline
void
writeQuoted
(
const
mysqlxx
::
Date
&
x
,
WriteBuffer
&
buf
)
inline
void
writeQuoted
(
const
Local
Date
&
x
,
WriteBuffer
&
buf
)
{
writeChar
(
'\''
,
buf
);
writeDateText
(
x
,
buf
);
writeChar
(
'\''
,
buf
);
}
inline
void
writeQuoted
(
const
mysqlxx
::
DateTime
&
x
,
WriteBuffer
&
buf
)
inline
void
writeQuoted
(
const
Local
DateTime
&
x
,
WriteBuffer
&
buf
)
{
writeChar
(
'\''
,
buf
);
writeDateTimeText
(
x
,
buf
);
...
...
@@ -606,14 +606,14 @@ inline void writeDoubleQuoted(const VisitID_t & x, WriteBuffer & buf)
writeIntText
(
static_cast
<
const
UInt64
&>
(
x
),
buf
);
}
inline
void
writeDoubleQuoted
(
const
mysqlxx
::
Date
&
x
,
WriteBuffer
&
buf
)
inline
void
writeDoubleQuoted
(
const
Local
Date
&
x
,
WriteBuffer
&
buf
)
{
writeChar
(
'"'
,
buf
);
writeDateText
(
x
,
buf
);
writeChar
(
'"'
,
buf
);
}
inline
void
writeDoubleQuoted
(
const
mysqlxx
::
DateTime
&
x
,
WriteBuffer
&
buf
)
inline
void
writeDoubleQuoted
(
const
Local
DateTime
&
x
,
WriteBuffer
&
buf
)
{
writeChar
(
'"'
,
buf
);
writeDateTimeText
(
x
,
buf
);
...
...
dbms/src/Client/Client.cpp
浏览文件 @
3519c3ce
...
...
@@ -263,7 +263,7 @@ private:
if
(
current_time
%
3
!=
0
)
return
false
;
mysqlxx
::
Date
now
(
current_time
);
Local
Date
now
(
current_time
);
return
(
now
.
month
()
==
12
&&
now
.
day
()
>=
20
)
||
(
now
.
month
()
==
1
&&
now
.
day
()
<=
5
);
}
...
...
dbms/src/IO/tests/operators.cpp
浏览文件 @
3519c3ce
...
...
@@ -13,8 +13,8 @@ int main(int argc, char ** argv)
<<
DB
::
quote
<<
"Hello, world!"
<<
'\n'
<<
DB
::
double_quote
<<
"Hello, world!"
<<
'\n'
<<
DB
::
binary
<<
"Hello, world!"
<<
'\n'
<<
mysqlxx
::
DateTime
(
time
(
0
))
<<
'\n'
<<
mysqlxx
::
Date
(
time
(
0
))
<<
'\n'
<<
Local
DateTime
(
time
(
0
))
<<
'\n'
<<
Local
Date
(
time
(
0
))
<<
'\n'
<<
1234567890123456789UL
<<
'\n'
<<
DB
::
flush
;
}
...
...
dbms/src/Interpreters/Quota.cpp
浏览文件 @
3519c3ce
...
...
@@ -57,7 +57,7 @@ String QuotaForInterval::toString() const
std
::
stringstream
res
;
res
<<
std
::
fixed
<<
std
::
setprecision
(
3
)
<<
"Interval: "
<<
mysqlxx
::
DateTime
(
rounded_time
)
<<
" - "
<<
mysqlxx
::
DateTime
(
rounded_time
+
duration
)
<<
".
\n
"
<<
"Interval: "
<<
LocalDateTime
(
rounded_time
)
<<
" - "
<<
Local
DateTime
(
rounded_time
+
duration
)
<<
".
\n
"
<<
"Queries: "
<<
used
.
queries
<<
".
\n
"
<<
"Errors: "
<<
used
.
errors
<<
".
\n
"
<<
"Result rows: "
<<
used
.
result_rows
<<
".
\n
"
...
...
@@ -129,7 +129,7 @@ void QuotaForInterval::check(size_t max_amount, size_t used_amount, time_t curre
message
<<
" has been exceeded. "
<<
resource_name
<<
": "
<<
used_amount
<<
", max: "
<<
max_amount
<<
". "
<<
"Interval will end at "
<<
mysqlxx
::
DateTime
(
rounded_time
+
duration
)
<<
"."
;
<<
"Interval will end at "
<<
Local
DateTime
(
rounded_time
+
duration
)
<<
"."
;
throw
Exception
(
message
.
str
(),
ErrorCodes
::
QUOTA_EXPIRED
);
}
...
...
dbms/src/Server/OLAPQueryParser.cpp
浏览文件 @
3519c3ce
...
...
@@ -209,7 +209,7 @@ QueryParseResult QueryParser::parse(std::istream & s)
result
.
limit
=
DB
::
parse
<
unsigned
>
(
limit_nodes
->
item
(
0
)
->
innerText
());
LOG_DEBUG
(
log
,
"CounterID: "
<<
result
.
CounterID
<<
", dates: "
<<
mysqlxx
::
Date
(
result
.
date_first
)
<<
" - "
<<
mysqlxx
::
Date
(
result
.
date_last
));
<<
", dates: "
<<
LocalDate
(
result
.
date_first
)
<<
" - "
<<
Local
Date
(
result
.
date_last
));
/// получаем список имён атрибутов
Poco
::
AutoPtr
<
Poco
::
XML
::
NodeList
>
attributes
=
result
.
query
->
getElementsByTagName
(
"attribute"
);
...
...
dbms/src/Server/StatusFile.cpp
浏览文件 @
3519c3ce
...
...
@@ -8,7 +8,7 @@
#include <Poco/File.h>
#include <common/logger_useful.h>
#include <common/Revision.h>
#include <
mysqlxx/
DateTime.h>
#include <
common/Local
DateTime.h>
#include <DB/IO/copyData.h>
#include <DB/IO/ReadBufferFromFile.h>
...
...
@@ -69,7 +69,7 @@ StatusFile::StatusFile(const std::string & path_)
WriteBufferFromFileDescriptor
out
(
fd
,
1024
);
out
<<
"PID: "
<<
getpid
()
<<
"
\n
"
<<
"Started at: "
<<
mysqlxx
::
DateTime
(
time
(
0
))
<<
"
\n
"
<<
"Started at: "
<<
Local
DateTime
(
time
(
0
))
<<
"
\n
"
<<
"Revision: "
<<
Revision
::
get
()
<<
"
\n
"
;
}
}
...
...
dbms/src/Storages/MergeTree/ReplicatedMergeTreeLogEntry.cpp
浏览文件 @
3519c3ce
...
...
@@ -12,7 +12,7 @@ namespace DB
void
ReplicatedMergeTreeLogEntry
::
writeText
(
WriteBuffer
&
out
)
const
{
out
<<
"format version: 3
\n
"
<<
"create_time: "
<<
mysqlxx
::
DateTime
(
create_time
?
create_time
:
time
(
0
))
<<
"
\n
"
<<
"create_time: "
<<
Local
DateTime
(
create_time
?
create_time
:
time
(
0
))
<<
"
\n
"
<<
"source replica: "
<<
source_replica
<<
'\n'
<<
"block_id: "
<<
escape
<<
block_id
<<
'\n'
;
...
...
@@ -68,7 +68,7 @@ void ReplicatedMergeTreeLogEntry::readText(ReadBuffer & in)
if
(
format_version
>=
2
)
{
mysqlxx
::
DateTime
create_time_dt
;
Local
DateTime
create_time_dt
;
in
>>
"create_time: "
>>
create_time_dt
>>
"
\n
"
;
create_time
=
create_time_dt
;
}
...
...
dbms/src/Storages/System/StorageSystemParts.cpp
浏览文件 @
3519c3ce
...
...
@@ -227,7 +227,7 @@ BlockInputStreams StorageSystemParts::read(
table_column
->
insert
(
table
);
engine_column
->
insert
(
engine
);
mysqlxx
::
Date
partition_date
{
part
->
month
};
Local
Date
partition_date
{
part
->
month
};
String
partition
=
toString
(
partition_date
.
year
())
+
(
partition_date
.
month
()
<
10
?
"0"
:
""
)
+
toString
(
partition_date
.
month
());
partition_column
->
insert
(
partition
);
...
...
dbms/src/Storages/tests/part_name.cpp
浏览文件 @
3519c3ce
#include <DB/IO/ReadHelpers.h>
#include <DB/Storages/MergeTree/ActiveDataPartSet.h>
#include <
mysqlxx/
DateTime.h>
#include <
common/Local
DateTime.h>
int
main
(
int
argc
,
char
**
argv
)
...
...
@@ -13,7 +13,7 @@ int main(int argc, char ** argv)
std
::
cerr
<<
name
<<
'\n'
;
time_t
time
=
DateLUT
::
instance
().
YYYYMMDDToDate
(
DB
::
parse
<
UInt32
>
(
name
));
std
::
cerr
<<
mysqlxx
::
DateTime
(
time
)
<<
'\n'
;
std
::
cerr
<<
Local
DateTime
(
time
)
<<
'\n'
;
}
return
0
;
...
...
libs/lib
mysqlxx/include/mysqlxx/
Date.h
→
libs/lib
common/include/common/Local
Date.h
浏览文件 @
3519c3ce
...
...
@@ -2,17 +2,14 @@
#include <string.h>
#include <string>
#include <sstream>
#include <exception>
#include <common/DateLUT.h>
#include <mysqlxx/Exception.h>
namespace
mysqlxx
{
/** Хранит дату в broken-down виде.
* Может быть инициализирован из даты в текстовом виде '2011-01-01' и из time_t.
* Может быть инициализирован из даты в текстовом виде '20110101...
(юза
ются первые 8 символов)
* Может быть инициализирован из даты в текстовом виде '20110101...
(использу
ются первые 8 символов)
* Неявно преобразуется в time_t.
* Сериализуется в ostream в текстовом виде.
* Внимание: преобразование в unix timestamp и обратно производится в текущей тайм-зоне!
...
...
@@ -20,7 +17,7 @@ namespace mysqlxx
*
* packed - для memcmp (из-за того, что m_year - 2 байта, little endian, работает корректно только до 2047 года)
*/
class
__attribute__
((
__packed__
))
Date
class
__attribute__
((
__packed__
))
Local
Date
{
private:
unsigned
short
m_year
;
...
...
@@ -40,14 +37,14 @@ private:
void
init
(
const
char
*
s
,
size_t
length
)
{
if
(
length
<
8
)
throw
Exception
(
"Cannot parse
Date: "
+
std
::
string
(
s
,
length
));
throw
std
::
runtime_error
(
"Cannot parse Local
Date: "
+
std
::
string
(
s
,
length
));
m_year
=
(
s
[
0
]
-
'0'
)
*
1000
+
(
s
[
1
]
-
'0'
)
*
100
+
(
s
[
2
]
-
'0'
)
*
10
+
(
s
[
3
]
-
'0'
);
if
(
s
[
4
]
==
'-'
)
{
if
(
length
<
10
)
throw
Exception
(
"Cannot parse
Date: "
+
std
::
string
(
s
,
length
));
throw
std
::
runtime_error
(
"Cannot parse Local
Date: "
+
std
::
string
(
s
,
length
));
m_month
=
(
s
[
5
]
-
'0'
)
*
10
+
(
s
[
6
]
-
'0'
);
m_day
=
(
s
[
8
]
-
'0'
)
*
10
+
(
s
[
9
]
-
'0'
);
}
...
...
@@ -59,12 +56,12 @@ private:
}
public:
explicit
Date
(
time_t
time
)
explicit
Local
Date
(
time_t
time
)
{
init
(
time
);
}
Date
(
DayNum_t
day_num
)
Local
Date
(
DayNum_t
day_num
)
{
const
auto
&
values
=
DateLUT
::
instance
().
getValues
(
day_num
);
m_year
=
values
.
year
;
...
...
@@ -72,31 +69,31 @@ public:
m_day
=
values
.
day_of_month
;
}
Date
(
unsigned
short
year_
,
unsigned
char
month_
,
unsigned
char
day_
)
Local
Date
(
unsigned
short
year_
,
unsigned
char
month_
,
unsigned
char
day_
)
:
m_year
(
year_
),
m_month
(
month_
),
m_day
(
day_
)
{
}
explicit
Date
(
const
std
::
string
&
s
)
explicit
Local
Date
(
const
std
::
string
&
s
)
{
init
(
s
.
data
(),
s
.
size
());
}
Date
(
const
char
*
data
,
size_t
length
)
Local
Date
(
const
char
*
data
,
size_t
length
)
{
init
(
data
,
length
);
}
Date
()
:
m_year
(
0
),
m_month
(
0
),
m_day
(
0
)
Local
Date
()
:
m_year
(
0
),
m_month
(
0
),
m_day
(
0
)
{
}
Date
(
const
Date
&
x
)
LocalDate
(
const
Local
Date
&
x
)
{
operator
=
(
x
);
}
Date
&
operator
=
(
const
Date
&
x
)
LocalDate
&
operator
=
(
const
Local
Date
&
x
)
{
m_year
=
x
.
m_year
;
m_month
=
x
.
m_month
;
...
...
@@ -105,7 +102,7 @@ public:
return
*
this
;
}
Date
&
operator
=
(
time_t
time
)
Local
Date
&
operator
=
(
time_t
time
)
{
init
(
time
);
return
*
this
;
...
...
@@ -134,36 +131,37 @@ public:
void
month
(
unsigned
char
x
)
{
m_month
=
x
;
}
void
day
(
unsigned
char
x
)
{
m_day
=
x
;
}
bool
operator
<
(
const
Date
&
other
)
const
bool
operator
<
(
const
Local
Date
&
other
)
const
{
return
0
>
memcmp
(
this
,
&
other
,
sizeof
(
*
this
));
}
bool
operator
>
(
const
Date
&
other
)
const
bool
operator
>
(
const
Local
Date
&
other
)
const
{
return
0
<
memcmp
(
this
,
&
other
,
sizeof
(
*
this
));
}
bool
operator
<=
(
const
Date
&
other
)
const
bool
operator
<=
(
const
Local
Date
&
other
)
const
{
return
0
>=
memcmp
(
this
,
&
other
,
sizeof
(
*
this
));
}
bool
operator
>=
(
const
Date
&
other
)
const
bool
operator
>=
(
const
Local
Date
&
other
)
const
{
return
0
<=
memcmp
(
this
,
&
other
,
sizeof
(
*
this
));
}
bool
operator
==
(
const
Date
&
other
)
const
bool
operator
==
(
const
Local
Date
&
other
)
const
{
return
0
==
memcmp
(
this
,
&
other
,
sizeof
(
*
this
));
}
bool
operator
!=
(
const
Date
&
other
)
const
bool
operator
!=
(
const
Local
Date
&
other
)
const
{
return
!
(
*
this
==
other
);
}
/// NOTE Неэффективно.
std
::
string
toString
(
char
separator
=
'-'
)
const
{
std
::
stringstream
ss
;
...
...
@@ -177,19 +175,17 @@ public:
}
};
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
ostr
,
const
Date
&
date
)
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
ostr
,
const
Local
Date
&
date
)
{
return
ostr
<<
date
.
year
()
<<
'-'
<<
(
date
.
month
()
/
10
)
<<
(
date
.
month
()
%
10
)
<<
'-'
<<
(
date
.
day
()
/
10
)
<<
(
date
.
day
()
%
10
);
}
}
namespace
std
{
inline
string
to_string
(
const
mysqlxx
::
Date
&
date
)
inline
string
to_string
(
const
Local
Date
&
date
)
{
return
date
.
toString
();
}
...
...
libs/lib
mysqlxx/include/mysqlxx/
DateTime.h
→
libs/lib
common/include/common/Local
DateTime.h
浏览文件 @
3519c3ce
#pragma once
#include <string>
#include <common/DateLUT.h>
#include <mysqlxx/Date.h>
#include <iomanip>
#include <exception>
#include <common/DateLUT.h>
#include <common/LocalDate.h>
namespace
mysqlxx
{
/** Хранит дату и время в broken-down виде.
* Может быть инициализирован из даты и времени в текстовом виде '2011-01-01 00:00:00' и из time_t.
* Неявно преобразуется в time_t.
...
...
@@ -19,7 +16,7 @@ namespace mysqlxx
*
* packed - для memcmp (из-за того, что m_year - 2 байта, little endian, работает корректно только до 2047 года)
*/
class
__attribute__
((
__packed__
))
DateTime
class
__attribute__
((
__packed__
))
Local
DateTime
{
private:
unsigned
short
m_year
;
...
...
@@ -57,7 +54,7 @@ private:
void
init
(
const
char
*
s
,
size_t
length
)
{
if
(
length
<
19
)
throw
Exception
(
"Cannot parse
DateTime: "
+
std
::
string
(
s
,
length
));
throw
std
::
runtime_error
(
"Cannot parse Local
DateTime: "
+
std
::
string
(
s
,
length
));
m_year
=
(
s
[
0
]
-
'0'
)
*
1000
+
(
s
[
1
]
-
'0'
)
*
100
+
(
s
[
2
]
-
'0'
)
*
10
+
(
s
[
3
]
-
'0'
);
m_month
=
(
s
[
5
]
-
'0'
)
*
10
+
(
s
[
6
]
-
'0'
);
...
...
@@ -69,40 +66,40 @@ private:
}
public:
explicit
DateTime
(
time_t
time
)
explicit
Local
DateTime
(
time_t
time
)
{
init
(
time
);
}
DateTime
(
unsigned
short
year_
,
unsigned
char
month_
,
unsigned
char
day_
,
Local
DateTime
(
unsigned
short
year_
,
unsigned
char
month_
,
unsigned
char
day_
,
unsigned
char
hour_
,
unsigned
char
minute_
,
unsigned
char
second_
)
:
m_year
(
year_
),
m_month
(
month_
),
m_day
(
day_
),
m_hour
(
hour_
),
m_minute
(
minute_
),
m_second
(
second_
)
{
}
explicit
DateTime
(
const
std
::
string
&
s
)
explicit
Local
DateTime
(
const
std
::
string
&
s
)
{
if
(
s
.
size
()
<
19
)
throw
Exception
(
"Cannot parse
DateTime: "
+
s
);
throw
std
::
runtime_error
(
"Cannot parse Local
DateTime: "
+
s
);
init
(
s
.
data
(),
s
.
size
());
}
DateTime
()
:
m_year
(
0
),
m_month
(
0
),
m_day
(
0
),
m_hour
(
0
),
m_minute
(
0
),
m_second
(
0
)
Local
DateTime
()
:
m_year
(
0
),
m_month
(
0
),
m_day
(
0
),
m_hour
(
0
),
m_minute
(
0
),
m_second
(
0
)
{
}
DateTime
(
const
char
*
data
,
size_t
length
)
Local
DateTime
(
const
char
*
data
,
size_t
length
)
{
init
(
data
,
length
);
}
DateTime
(
const
DateTime
&
x
)
LocalDateTime
(
const
Local
DateTime
&
x
)
{
operator
=
(
x
);
}
DateTime
&
operator
=
(
const
DateTime
&
x
)
LocalDateTime
&
operator
=
(
const
Local
DateTime
&
x
)
{
m_year
=
x
.
m_year
;
m_month
=
x
.
m_month
;
...
...
@@ -114,7 +111,7 @@ public:
return
*
this
;
}
DateTime
&
operator
=
(
time_t
time
)
Local
DateTime
&
operator
=
(
time_t
time
)
{
init
(
time
);
return
*
this
;
...
...
@@ -141,42 +138,42 @@ public:
void
minute
(
unsigned
char
x
)
{
m_minute
=
x
;
}
void
second
(
unsigned
char
x
)
{
m_second
=
x
;
}
Date
toDate
()
const
{
return
Date
(
m_year
,
m_month
,
m_day
);
}
LocalDate
toDate
()
const
{
return
Local
Date
(
m_year
,
m_month
,
m_day
);
}
DateTime
toStartOfDate
()
{
return
DateTime
(
m_year
,
m_month
,
m_day
,
0
,
0
,
0
);
}
LocalDateTime
toStartOfDate
()
{
return
Local
DateTime
(
m_year
,
m_month
,
m_day
,
0
,
0
,
0
);
}
bool
operator
<
(
const
DateTime
&
other
)
const
bool
operator
<
(
const
Local
DateTime
&
other
)
const
{
return
0
>
memcmp
(
this
,
&
other
,
sizeof
(
*
this
));
}
bool
operator
>
(
const
DateTime
&
other
)
const
bool
operator
>
(
const
Local
DateTime
&
other
)
const
{
return
0
<
memcmp
(
this
,
&
other
,
sizeof
(
*
this
));
}
bool
operator
<=
(
const
DateTime
&
other
)
const
bool
operator
<=
(
const
Local
DateTime
&
other
)
const
{
return
0
>=
memcmp
(
this
,
&
other
,
sizeof
(
*
this
));
}
bool
operator
>=
(
const
DateTime
&
other
)
const
bool
operator
>=
(
const
Local
DateTime
&
other
)
const
{
return
0
<=
memcmp
(
this
,
&
other
,
sizeof
(
*
this
));
}
bool
operator
==
(
const
DateTime
&
other
)
const
bool
operator
==
(
const
Local
DateTime
&
other
)
const
{
return
0
==
memcmp
(
this
,
&
other
,
sizeof
(
*
this
));
}
bool
operator
!=
(
const
DateTime
&
other
)
const
bool
operator
!=
(
const
Local
DateTime
&
other
)
const
{
return
!
(
*
this
==
other
);
}
};
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
ostr
,
const
DateTime
&
datetime
)
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
ostr
,
const
Local
DateTime
&
datetime
)
{
ostr
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
4
)
<<
datetime
.
year
();
...
...
@@ -189,12 +186,10 @@ inline std::ostream & operator<< (std::ostream & ostr, const DateTime & datetime
return
ostr
;
}
}
namespace
std
{
inline
string
to_string
(
const
mysqlxx
::
DateTime
&
datetime
)
inline
string
to_string
(
const
Local
DateTime
&
datetime
)
{
stringstream
str
;
str
<<
datetime
;
...
...
libs/libmysqlxx/include/mysqlxx/Connection.h
浏览文件 @
3519c3ce
...
...
@@ -7,6 +7,7 @@
#include <common/singleton.h>
#include <mysqlxx/Query.h>
#include <mysqlxx/Exception.h>
#define MYSQLXX_DEFAULT_TIMEOUT 60
#define MYSQLXX_DEFAULT_RW_TIMEOUT 1800
...
...
libs/libmysqlxx/include/mysqlxx/Manip.h
浏览文件 @
3519c3ce
...
...
@@ -54,8 +54,8 @@ struct EscapeManipResult
std
::
ostream
&
operator
<<
(
double
value
)
{
return
ostr
<<
value
;
}
std
::
ostream
&
operator
<<
(
long
long
value
)
{
return
ostr
<<
value
;
}
std
::
ostream
&
operator
<<
(
unsigned
long
long
value
)
{
return
ostr
<<
value
;
}
std
::
ostream
&
operator
<<
(
Date
value
)
{
return
ostr
<<
value
;
}
std
::
ostream
&
operator
<<
(
DateTime
value
)
{
return
ostr
<<
value
;
}
std
::
ostream
&
operator
<<
(
LocalDate
value
)
{
return
ostr
<<
value
;
}
std
::
ostream
&
operator
<<
(
LocalDateTime
value
)
{
return
ostr
<<
value
;
}
std
::
ostream
&
operator
<<
(
const
std
::
string
&
value
)
{
...
...
@@ -102,7 +102,7 @@ struct EscapeManipResult
{
if
(
i
!=
0
)
ostr
<<
'\t'
;
if
(
row
[
i
].
isNull
())
{
ostr
<<
"
\\
N"
;
...
...
@@ -115,7 +115,7 @@ struct EscapeManipResult
return
ostr
;
}
template
<
typename
T
>
std
::
ostream
&
operator
<<
(
const
Null
<
T
>
&
value
)
{
...
...
@@ -123,7 +123,7 @@ struct EscapeManipResult
ostr
<<
"
\\
N"
;
else
*
this
<<
value
.
data
;
return
ostr
;
}
...
...
@@ -181,8 +181,8 @@ public:
std
::
ostream
&
operator
<<
(
double
value
)
{
return
ostr
<<
value
;
}
std
::
ostream
&
operator
<<
(
long
long
value
)
{
return
ostr
<<
value
;
}
std
::
ostream
&
operator
<<
(
unsigned
long
long
value
)
{
return
ostr
<<
value
;
}
std
::
ostream
&
operator
<<
(
Date
value
)
{
return
ostr
<<
'\''
<<
value
<<
'\''
;
}
std
::
ostream
&
operator
<<
(
DateTime
value
)
{
return
ostr
<<
'\''
<<
value
<<
'\''
;
}
std
::
ostream
&
operator
<<
(
LocalDate
value
)
{
return
ostr
<<
'\''
<<
value
<<
'\''
;
}
std
::
ostream
&
operator
<<
(
LocalDateTime
value
)
{
return
ostr
<<
'\''
<<
value
<<
'\''
;
}
std
::
ostream
&
operator
<<
(
const
std
::
string
&
value
)
{
...
...
@@ -201,7 +201,7 @@ public:
ostr
.
put
(
'\''
);
return
ostr
;
}
template
<
typename
T
>
std
::
ostream
&
operator
<<
(
const
Null
<
T
>
&
value
)
{
...
...
@@ -395,19 +395,19 @@ struct UnEscapeManipResult
return
istr
;
}
std
::
istream
&
operator
>>
(
Date
&
value
)
std
::
istream
&
operator
>>
(
Local
Date
&
value
)
{
std
::
string
s
;
(
*
this
)
>>
s
;
value
=
Date
(
s
);
value
=
Local
Date
(
s
);
return
istr
;
}
std
::
istream
&
operator
>>
(
DateTime
&
value
)
std
::
istream
&
operator
>>
(
Local
DateTime
&
value
)
{
std
::
string
s
;
(
*
this
)
>>
s
;
value
=
DateTime
(
s
);
value
=
Local
DateTime
(
s
);
return
istr
;
}
...
...
@@ -499,5 +499,5 @@ inline UnQuoteManipResult operator>> (std::istream & istr, unquote_enum manip)
return
UnQuoteManipResult
(
istr
);
}
}
libs/libmysqlxx/include/mysqlxx/Row.h
浏览文件 @
3519c3ce
...
...
@@ -3,6 +3,7 @@
#include <mysqlxx/Types.h>
#include <mysqlxx/Value.h>
#include <mysqlxx/ResultBase.h>
#include <mysqlxx/Exception.h>
namespace
mysqlxx
...
...
libs/libmysqlxx/include/mysqlxx/Types.h
浏览文件 @
3519c3ce
...
...
@@ -4,8 +4,8 @@
#include <mysql/mysql.h>
#include <Poco/Types.h>
#include <
mysqlxx/
Date.h>
#include <
mysqlxx/
DateTime.h>
#include <
common/Local
Date.h>
#include <
common/Local
DateTime.h>
namespace
mysqlxx
...
...
libs/libmysqlxx/include/mysqlxx/Value.h
浏览文件 @
3519c3ce
...
...
@@ -60,7 +60,7 @@ public:
{
if
(
unlikely
(
isNull
()))
throwException
(
"Value is NULL"
);
return
m_length
>
0
&&
m_data
[
0
]
!=
'0'
;
}
...
...
@@ -69,7 +69,7 @@ public:
{
if
(
unlikely
(
isNull
()))
throwException
(
"Value is NULL"
);
return
readUIntText
(
m_data
,
m_length
);;
}
...
...
@@ -84,20 +84,20 @@ public:
{
if
(
unlikely
(
isNull
()))
throwException
(
"Value is NULL"
);
return
readFloatText
(
m_data
,
m_length
);
}
/// Получить дату-время (из значения вида '2011-01-01 00:00:00').
DateTime
getDateTime
()
const
Local
DateTime
getDateTime
()
const
{
return
DateTime
(
data
(),
size
());
return
Local
DateTime
(
data
(),
size
());
}
/// Получить дату (из значения вида '2011-01-01' или '2011-01-01 00:00:00').
Date
getDate
()
const
Local
Date
getDate
()
const
{
return
Date
(
data
(),
size
());
return
Local
Date
(
data
(),
size
());
}
/// Получить строку.
...
...
@@ -105,7 +105,7 @@ public:
{
if
(
unlikely
(
isNull
()))
throwException
(
"Value is NULL"
);
return
std
::
string
(
m_data
,
m_length
);
}
...
...
@@ -136,7 +136,7 @@ private:
size_t
m_length
;
const
ResultBase
*
res
;
bool
checkDateTime
()
const
{
return
(
m_length
==
10
||
m_length
==
19
)
&&
m_data
[
4
]
==
'-'
&&
m_data
[
7
]
==
'-'
;
...
...
@@ -392,8 +392,8 @@ template <> inline unsigned long long Value::get<unsigned long long >() const {
template
<
>
inline
float
Value
::
get
<
float
>
()
const
{
return
getDouble
();
}
template
<
>
inline
double
Value
::
get
<
double
>
()
const
{
return
getDouble
();
}
template
<
>
inline
std
::
string
Value
::
get
<
std
::
string
>
()
const
{
return
getString
();
}
template
<
>
inline
Date
Value
::
get
<
Date
>
()
const
{
return
getDate
();
}
template
<
>
inline
DateTime
Value
::
get
<
DateTime
>
()
const
{
return
getDateTime
();
}
template
<
>
inline
LocalDate
Value
::
get
<
LocalDate
>
()
const
{
return
getDate
();
}
template
<
>
inline
LocalDateTime
Value
::
get
<
LocalDateTime
>
()
const
{
return
getDateTime
();
}
template
<
>
inline
VisitID_t
Value
::
get
<
VisitID_t
>
()
const
{
return
VisitID_t
(
getUInt
());
}
...
...
libs/libmysqlxx/include/mysqlxx/mysqlxx.h
浏览文件 @
3519c3ce
...
...
@@ -4,8 +4,8 @@
#include <mysqlxx/Transaction.h>
#include <mysqlxx/Manip.h>
#include <mysqlxx/Pool.h>
#include <
mysqlxx/
Date.h>
#include <
mysqlxx/
DateTime.h>
#include <
common/Local
Date.h>
#include <
common/Local
DateTime.h>
#include <mysqlxx/Null.h>
...
...
@@ -63,5 +63,5 @@
* из принципа "всё, что не используется сейчас - не реализовано",
* а также зависит от небольшого количества кода из других мест репозитория Метрики
* (при необходимости, зависимости можно убрать).
* Предполагается, что пользователь сам допишет недостающ
ий функционал
.
* Предполагается, что пользователь сам допишет недостающ
ую функциональность
.
*/
libs/libmysqlxx/src/tests/mysqlxx_test.cpp
浏览文件 @
3519c3ce
...
...
@@ -33,8 +33,8 @@ int main(int argc, char ** argv)
time_t
t1
=
row
[
0
];
time_t
t2
=
row
[
1
];
std
::
cerr
<<
t1
<<
", "
<<
mysqlxx
::
DateTime
(
t1
)
<<
std
::
endl
;
std
::
cerr
<<
t2
<<
", "
<<
mysqlxx
::
DateTime
(
t2
)
<<
std
::
endl
;
std
::
cerr
<<
t1
<<
", "
<<
Local
DateTime
(
t1
)
<<
std
::
endl
;
std
::
cerr
<<
t2
<<
", "
<<
Local
DateTime
(
t2
)
<<
std
::
endl
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录