Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fmp_vip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhenfei.zhang
fmp_vip
Commits
d6ad6b8e
Commit
d6ad6b8e
authored
Feb 12, 2018
by
NitefullWind
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. 添加查询数据库所有内容的测试例。 2. 不使用视图获取最后一个门店信息。
parent
c5eeb0e9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
26 deletions
+42
-26
fmvip/db/database.h
+3
-10
fmvip/db/item.h
+15
-15
tests/autotest/tst_db_query.h
+23
-0
version.h
+1
-1
No files found.
fmvip/db/database.h
View file @
d6ad6b8e
...
@@ -162,24 +162,17 @@ inline std::shared_ptr<odb::database> DBSP() {
...
@@ -162,24 +162,17 @@ inline std::shared_ptr<odb::database> DBSP() {
inline
QSharedPointer
<
StoreInfo
>
GetLastStoreInfo
()
inline
QSharedPointer
<
StoreInfo
>
GetLastStoreInfo
()
{
{
QSharedPointer
<
StoreInfo
>
storeInfoP
(
new
StoreInfo
())
;
QSharedPointer
<
StoreInfo
>
storeInfoP
;
try
{
try
{
odb
::
transaction
t
(
DBSP
()
->
begin
());
odb
::
transaction
t
(
DBSP
()
->
begin
());
odb
::
result
<
StoreInfo
_last
>
sl
(
DBSP
()
->
query
<
StoreInfo_last
>
(
));
odb
::
result
<
StoreInfo
>
sl
(
DBSP
()
->
query
<
StoreInfo
>
(
"order by id desc limit 0,1"
));
if
(
!
sl
.
empty
())
{
if
(
!
sl
.
empty
())
{
storeInfoP
->
setId
(
sl
.
begin
()
->
_id
);
storeInfoP
=
sl
.
begin
().
load
();
storeInfoP
->
setStoreId
(
sl
.
begin
()
->
_storeId
);
storeInfoP
->
setPosId
(
sl
.
begin
()
->
_posId
);
storeInfoP
->
setBusinessDate
(
sl
.
begin
()
->
_businessDate
);
storeInfoP
->
setOperatorId
(
sl
.
begin
()
->
_operatorId
);
}
else
{
storeInfoP
.
clear
();
}
}
t
.
commit
();
t
.
commit
();
}
catch
(
const
odb
::
exception
&
e
)
{
}
catch
(
const
odb
::
exception
&
e
)
{
storeInfoP
.
clear
();
qDebug
()
<<
"Exception: Get last store info: "
<<
e
.
what
();
qDebug
()
<<
"Exception: Get last store info: "
<<
e
.
what
();
}
}
return
storeInfoP
;
return
storeInfoP
;
...
...
fmvip/db/item.h
View file @
d6ad6b8e
...
@@ -221,21 +221,21 @@ private:
...
@@ -221,21 +221,21 @@ private:
QString
_businessDate
;
QString
_businessDate
;
};
};
#pragma db view object(StoreInfo) \
//
#pragma db view object(StoreInfo) \
query((?) + "order by id desc limit 0,1")
//
query((?) + "order by id desc limit 0,1")
struct
StoreInfo_last
//
struct StoreInfo_last
{
//
{
#pragma db column(StoreInfo::_id)
//
#pragma db column(StoreInfo::_id)
unsigned
long
_id
;
//
unsigned long _id;
#pragma db column(StoreInfo::_storeId)
//
#pragma db column(StoreInfo::_storeId)
QString
_storeId
;
//
QString _storeId;
#pragma db column(StoreInfo::_posId)
//
#pragma db column(StoreInfo::_posId)
QString
_posId
;
//
QString _posId;
#pragma db column(StoreInfo::_operatorId)
//
#pragma db column(StoreInfo::_operatorId)
QString
_operatorId
;
//
QString _operatorId;
#pragma db column(StoreInfo::_businessDate)
//
#pragma db column(StoreInfo::_businessDate)
QString
_businessDate
;
//
QString _businessDate;
};
//
};
}
}
...
...
tests/autotest/tst_db_query.h
View file @
d6ad6b8e
...
@@ -43,6 +43,29 @@ TEST_F(TestDBQuery, Load)
...
@@ -43,6 +43,29 @@ TEST_F(TestDBQuery, Load)
}
}
}
}
TEST_F
(
TestDBQuery
,
QueryAll
)
{
try
{
transaction
t
(
DBSP
()
->
begin
());
result
<
Order
>
r
(
DBSP
()
->
query
<
Order
>
());
ASSERT_FALSE
(
r
.
empty
());
QSharedPointer
<
Order
>
firstOrder
=
r
.
begin
().
load
();
EXPECT_EQ
(
firstOrder
->
id
(),
1
);
for
(
result
<
Order
>::
iterator
it
(
r
.
begin
());
it
!=
r
.
end
();
++
it
)
{
EXPECT_NE
(
it
->
orderId
(),
""
);
}
t
.
commit
();
}
catch
(
const
odb
::
exception
&
e
)
{
FAIL
()
<<
"Exception: "
<<
e
.
what
()
<<
std
::
endl
;
}
}
TEST_F
(
TestDBQuery
,
Query
)
TEST_F
(
TestDBQuery
,
Query
)
{
{
try
{
try
{
...
...
version.h
View file @
d6ad6b8e
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_REVISION 0
#define VER_BUILD 5
0
#define VER_BUILD 5
1
//! Convert version numbers to string
//! Convert version numbers to string
#define _STR(S) #S
#define _STR(S) #S
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment