Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
familyMart_takeaway
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
guanghui.cui
familyMart_takeaway
Commits
536b74ed
Commit
536b74ed
authored
Mar 09, 2018
by
guanghui.cui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入sqlite相关代码
parent
cd47f584
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
20 deletions
+66
-20
base/CommonStruct.h
+1
-2
src/SQLiteModule.cpp
+17
-17
src/SQLiteModule.h
+3
-1
src/main.cpp
+17
-0
utility/utility.cpp
+17
-0
utility/utility.h
+11
-0
No files found.
base/CommonStruct.h
View file @
536b74ed
...
@@ -204,8 +204,8 @@ struct serverResponseOperationObj
...
@@ -204,8 +204,8 @@ struct serverResponseOperationObj
//订单发送给pos失败结构体
//订单发送给pos失败结构体
struct
orderSendFailedObj
struct
orderSendFailedObj
{
{
long
long
timestamp
=
0
;
//接收到订单时候的时间戳(精确到毫秒)
std
::
string
order_json
;
//订单json字符串
std
::
string
order_json
;
//订单json字符串
unsigned
int
timestamp
=
0
;
//接收到订单时候的时间戳
};
};
#endif
#endif
\ No newline at end of file
src/SQLiteModule.cpp
View file @
536b74ed
...
@@ -49,20 +49,13 @@ bool SQLite::_createTable()
...
@@ -49,20 +49,13 @@ bool SQLite::_createTable()
//第三个参数为callback函数,这里没有用,第四个参数为callback函数
//第三个参数为callback函数,这里没有用,第四个参数为callback函数
//中的第一个参数,第五个为出错信息
//中的第一个参数,第五个为出错信息
bool
rlt
=
true
;
bool
rlt
=
true
;
std
::
string
strTableName
=
"fm
Test
"
;
std
::
string
strTableName
=
"fm
OrderFailed
"
;
if
(
!
isTableExist
(
pDB
,
strTableName
)){
if
(
!
isTableExist
(
pDB
,
strTableName
)){
char
szCreate
[
1024
]
=
{
0
};
char
szCreate
[
1024
]
=
{
0
};
sprintf
(
szCreate
,
"create table %s(fm_id varchar(50) NOT NULL,\
sprintf
(
szCreate
,
"create table %s(id BIGINT NOT NULL,\
statusCode int, \
msg TEXT,\
msg varchar(200),\
prompt bool,\
fm_open_id varchar(50),\
total_amount int,\
paid_total_amount int,\
invoice_amount int,\
incentives_amount int,\
logtime TIMESTAMP default (datetime('now', 'localtime')),\
logtime TIMESTAMP default (datetime('now', 'localtime')),\
PRIMARY KEY (fm_
id))"
,
strTableName
.
c_str
());
PRIMARY KEY (
id))"
,
strTableName
.
c_str
());
if
(
!
_execSql
(
szCreate
)){
if
(
!
_execSql
(
szCreate
)){
//执行失败,退出
//执行失败,退出
exit
(
0
);
exit
(
0
);
...
@@ -99,7 +92,7 @@ bool SQLite::isTableExist(sqlite3 *sqDb, std::string strTableName)
...
@@ -99,7 +92,7 @@ bool SQLite::isTableExist(sqlite3 *sqDb, std::string strTableName)
int
SQLite
::
isRecordExist
(
std
::
string
strTable
,
std
::
string
strKey
)
int
SQLite
::
isRecordExist
(
std
::
string
strTable
,
std
::
string
strKey
)
{
{
char
*
lpSql
=
new
char
[
BUFFER_SIZE
];
char
*
lpSql
=
new
char
[
BUFFER_SIZE
];
sprintf
(
lpSql
,
"select * from %s where
trans_
id = '%s'"
,
strTable
.
c_str
(),
strKey
.
c_str
());
sprintf
(
lpSql
,
"select * from %s where id = '%s'"
,
strTable
.
c_str
(),
strKey
.
c_str
());
char
**
pResult
;
char
**
pResult
;
int
nRow
=
0
;
int
nRow
=
0
;
int
nCol
=
0
;
int
nCol
=
0
;
...
@@ -140,14 +133,16 @@ bool SQLite::remove(const char* sql)
...
@@ -140,14 +133,16 @@ bool SQLite::remove(const char* sql)
return
_execSql
(
sql
);
return
_execSql
(
sql
);
}
}
std
::
vector
<
orderSendFailedObj
>
vecOrders
;
int
callbackQuery
(
void
*
data
,
int
n_columns
,
char
**
column_values
,
char
**
column_names
)
int
callbackQuery
(
void
*
data
,
int
n_columns
,
char
**
column_values
,
char
**
column_names
)
{
{
try
try
{
{
std
::
string
col0
=
column_values
[
0
];
orderSendFailedObj
order
;
std
::
string
col1
=
column_values
[
1
];
order
.
timestamp
=
atoll
(
column_values
[
0
]);
std
::
string
col2
=
column_values
[
2
];
order
.
order_json
=
column_values
[
1
];
LOG
(
INFO
)
<<
"column0:"
<<
col0
<<
" column1:"
<<
col1
<<
" column2:"
<<
col2
;
vecOrders
.
push_back
(
order
);
}
}
catch
(
std
::
exception
&
ex
)
catch
(
std
::
exception
&
ex
)
{
{
...
@@ -158,11 +153,15 @@ int callbackQuery(void* data,int n_columns,char** column_values,char** column_na
...
@@ -158,11 +153,15 @@ int callbackQuery(void* data,int n_columns,char** column_values,char** column_na
return
0
;
return
0
;
}
}
void
SQLite
::
query
(
const
char
*
sql
)
void
SQLite
::
query
(
const
char
*
sql
,
std
::
vector
<
orderSendFailedObj
>
&
vecFailedOrders
)
{
{
vecOrders
.
clear
();
int
rlt
=
sqlite3_exec
(
pDB
,
sql
,
callbackQuery
,
0
,
&
errMsg
);
int
rlt
=
sqlite3_exec
(
pDB
,
sql
,
callbackQuery
,
0
,
&
errMsg
);
if
(
rlt
!=
SQLITE_OK
)
if
(
rlt
!=
SQLITE_OK
)
{
{
LOG
(
ERROR
)
<<
"查询数据执行失败:"
<<
errMsg
;
LOG
(
ERROR
)
<<
"查询数据执行失败:"
<<
errMsg
;
}
}
else
{
vecFailedOrders
.
assign
(
vecOrders
.
begin
(),
vecOrders
.
end
());
}
}
}
\ No newline at end of file
src/SQLiteModule.h
View file @
536b74ed
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
#define SQLITE_MODULE_H
#define SQLITE_MODULE_H
#include <iostream>
#include <iostream>
#include <sqlite3.h>
#include <sqlite3.h>
#include <vector>
#include "../base/CommonStruct.h"
class
SQLite
class
SQLite
{
{
...
@@ -17,7 +19,7 @@ public:
...
@@ -17,7 +19,7 @@ public:
bool
insert
(
const
char
*
sql
);
bool
insert
(
const
char
*
sql
);
bool
update
(
const
char
*
sql
);
bool
update
(
const
char
*
sql
);
bool
remove
(
const
char
*
sql
);
bool
remove
(
const
char
*
sql
);
void
query
(
const
char
*
sql
);
void
query
(
const
char
*
sql
,
std
::
vector
<
orderSendFailedObj
>
&
vecFailedOrders
);
private
:
private
:
bool
_execSql
(
const
char
*
sql
);
bool
_execSql
(
const
char
*
sql
);
bool
_createTable
();
bool
_createTable
();
...
...
src/main.cpp
View file @
536b74ed
...
@@ -145,6 +145,23 @@ int main()
...
@@ -145,6 +145,23 @@ int main()
LOG
(
INFO
)
<<
"---------software start---------"
;
LOG
(
INFO
)
<<
"---------software start---------"
;
// //test sqlite
// orderSendFailedObj orderFailedObj;
// orderFailedObj.timestamp=1111222233334444;
// LOG(INFO)<<"--------- long long---------:"<<orderFailedObj.timestamp;
// SQLite sqlite;
// sqlite.initSQLite();
// sqlite.insert("insert into fmOrderFailed(id,msg) values(122233464555,'asdfdfdfdfdfsdadadafdadfafaf')");
// std::vector<orderSendFailedObj> vecFailedOrders;
// sqlite.query("select * from fmOrderFailed",vecFailedOrders);
// for(auto order:vecFailedOrders){
// LOG(INFO)<<"vector element:"<<order.timestamp;
// }
// LOG(INFO)<<"seconds:"<<timestamp_seconds()<<" mSeconds:"<<timestamps_milliseconds();
// sqlite.closeSQLite();
// return 0;
// 读取配置文件信息
// 读取配置文件信息
std
::
string
strIniPath
(
strBinPath
.
data
());
std
::
string
strIniPath
(
strBinPath
.
data
());
strIniPath
.
append
(
"config.ini"
);
strIniPath
.
append
(
"config.ini"
);
...
...
utility/utility.cpp
View file @
536b74ed
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include <iostream>
#include <iostream>
#include <iconv.h>
#include <iconv.h>
#include <string.h>
#include <string.h>
#include <sys/time.h>
#ifdef WIN32
#ifdef WIN32
#include <Windows.h>
#include <Windows.h>
...
@@ -91,3 +92,18 @@ std::string charset_u2g(const std::string& utf8)
...
@@ -91,3 +92,18 @@ std::string charset_u2g(const std::string& utf8)
//std::cout<<"convert res:"<<i<<std::endl;
//std::cout<<"convert res:"<<i<<std::endl;
return
gb2312
;
return
gb2312
;
}
}
//获取时间戳(毫秒)
long
long
timestamps_milliseconds
()
{
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
return
(
int64_t
)
tv
.
tv_sec
*
1000
+
tv
.
tv_usec
/
1000
;
}
//获取时间戳(秒)
long
long
timestamp_seconds
()
{
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
return
tv
.
tv_sec
;
}
\ No newline at end of file
utility/utility.h
View file @
536b74ed
#ifndef UTILITY_H
#define UTILITY_H
#include <string>
#include <string>
...
@@ -10,3 +12,11 @@ std::string charset_u2g(const std::string& utf8);
...
@@ -10,3 +12,11 @@ std::string charset_u2g(const std::string& utf8);
//GB2312码转为UNICODE码
//GB2312码转为UNICODE码
std
::
string
charset_g2u
(
const
std
::
string
&
gb2312
);
std
::
string
charset_g2u
(
const
std
::
string
&
gb2312
);
//获取时间戳(秒)
long
long
timestamp_seconds
();
//获取时间戳(毫秒)
long
long
timestamps_milliseconds
();
#endif
\ No newline at end of file
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