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
6d92af25
Commit
6d92af25
authored
Jun 07, 2018
by
guanghui.cui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除sqlite依赖
parent
f3e81c8e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
2 additions
and
202 deletions
+2
-202
CMakeLists.txt
+1
-1
src/SQLiteModule.cpp
+0
-160
src/SQLiteModule.h
+0
-40
src/main.cpp
+1
-1
No files found.
CMakeLists.txt
View file @
6d92af25
...
@@ -34,5 +34,5 @@ aux_source_directory(./utility/ DIR_UTILITY)
...
@@ -34,5 +34,5 @@ aux_source_directory(./utility/ DIR_UTILITY)
add_executable
(
${
TARGET_NAME
}
${
DIR_LOGS
}
${
DIR_SRCS
}
${
DIR_UTILITY
}
)
add_executable
(
${
TARGET_NAME
}
${
DIR_LOGS
}
${
DIR_SRCS
}
${
DIR_UTILITY
}
)
# 添加链接库
# 添加链接库
target_link_libraries
(
${
TARGET_NAME
}
pthread
sqlite3
)
target_link_libraries
(
${
TARGET_NAME
}
pthread
)
src/SQLiteModule.cpp
deleted
100644 → 0
View file @
f3e81c8e
#include "SQLiteModule.h"
#include "../utility/utility.h"
#include "../3rdParty/easylogging/easylogging++.h"
#define BUFFER_SIZE 1024
SQLite
::
SQLite
()
{
pDB
=
NULL
;
errMsg
=
NULL
;
}
SQLite
::~
SQLite
()
{
}
bool
SQLite
::
initSQLite
()
{
std
::
string
strDbFileName
;
//*.db name
std
::
string
strPath
=
GetProcDir
();
strPath
.
append
(
"fmdata.db"
);
strDbFileName
=
strPath
;
int
res
=
sqlite3_open
(
strDbFileName
.
c_str
(),
&
pDB
);
LOG
(
INFO
)
<<
"DbFileName:"
<<
strDbFileName
.
c_str
();
if
(
res
!=
SQLITE_OK
)
{
LOG
(
ERROR
)
<<
"open db file failed:"
<<
strDbFileName
.
data
();
return
false
;
}
try
{
_createTable
();
}
catch
(
std
::
exception
&
ex
)
{
LOG
(
ERROR
)
<<
"create table exception:"
<<
ex
.
what
();
return
false
;
}
return
true
;
}
bool
SQLite
::
_createTable
()
{
bool
rlt
=
true
;
std
::
string
strTableName
=
"fmOrderFailed"
;
if
(
!
isTableExist
(
pDB
,
strTableName
)){
char
szCreate
[
1024
]
=
{
0
};
sprintf
(
szCreate
,
"create table %s(id BIGINT NOT NULL,\
msg TEXT,\
logtime TIMESTAMP default (datetime('now', 'localtime')),\
PRIMARY KEY (id))"
,
strTableName
.
c_str
());
if
(
!
_execSql
(
szCreate
)){
exit
(
0
);
}
}
else
{
LOG
(
INFO
)
<<
strTableName
.
data
()
<<
" has exist"
;
}
return
rlt
;
}
void
SQLite
::
closeSQLite
()
{
if
(
pDB
)
sqlite3_close
(
pDB
);
}
bool
SQLite
::
isTableExist
(
sqlite3
*
sqDb
,
std
::
string
strTableName
)
{
char
szQuery
[
1024
]
=
{
0
};
sprintf
(
szQuery
,
"SELECT count(*) FROM sqlite_master WHERE type=
\"
table
\"
AND name=
\"
%s
\"
"
,
strTableName
.
c_str
());
sqlite3_stmt
*
pstmt
;
sqlite3_prepare
(
sqDb
,
szQuery
,
strlen
(
szQuery
),
&
pstmt
,
NULL
);
sqlite3_step
(
pstmt
);
int
count
=
sqlite3_column_int
(
pstmt
,
0
);
sqlite3_finalize
(
pstmt
);
if
(
count
>
0
)
return
true
;
return
false
;
}
int
SQLite
::
isRecordExist
(
std
::
string
strTable
,
std
::
string
strKey
)
{
char
*
lpSql
=
new
char
[
BUFFER_SIZE
];
sprintf
(
lpSql
,
"select * from %s where id = '%s'"
,
strTable
.
c_str
(),
strKey
.
c_str
());
char
**
pResult
;
int
nRow
=
0
;
int
nCol
=
0
;
int
nResult
=
sqlite3_get_table
(
pDB
,
lpSql
,
&
pResult
,
&
nRow
,
&
nCol
,
&
errMsg
);
delete
[]
lpSql
;
if
(
nResult
!=
SQLITE_OK
)
{
LOG
(
ERROR
)
<<
"sqlite3_get_table error:"
<<
errMsg
;
return
-
1
;
}
return
nRow
;
}
bool
SQLite
::
_execSql
(
const
char
*
sql
)
{
bool
rlt
=
true
;
int
res
=
sqlite3_exec
(
pDB
,
sql
,
0
,
0
,
&
errMsg
);
if
(
res
!=
SQLITE_OK
)
{
LOG
(
ERROR
)
<<
"exec sql failed:"
<<
sql
<<
" failed info:"
<<
errMsg
;
rlt
=
false
;
}
return
rlt
;
}
bool
SQLite
::
insert
(
const
char
*
sql
)
{
return
_execSql
(
sql
);
}
bool
SQLite
::
update
(
const
char
*
sql
)
{
return
_execSql
(
sql
);
}
bool
SQLite
::
remove
(
const
char
*
sql
)
{
return
_execSql
(
sql
);
}
std
::
vector
<
orderSendFailedObj
>
vecOrders
;
int
callbackQuery
(
void
*
data
,
int
n_columns
,
char
**
column_values
,
char
**
column_names
)
{
try
{
orderSendFailedObj
order
;
order
.
timestamp
=
atoll
(
column_values
[
0
]);
order
.
order_json
=
column_values
[
1
];
vecOrders
.
push_back
(
order
);
}
catch
(
std
::
exception
&
ex
)
{
LOG
(
ERROR
)
<<
"read data failed:"
<<
ex
.
what
();
return
-
1
;
}
return
0
;
}
void
SQLite
::
query
(
const
char
*
sql
,
std
::
vector
<
orderSendFailedObj
>
&
vecFailedOrders
)
{
vecOrders
.
clear
();
int
rlt
=
sqlite3_exec
(
pDB
,
sql
,
callbackQuery
,
0
,
&
errMsg
);
if
(
rlt
!=
SQLITE_OK
)
{
LOG
(
ERROR
)
<<
"query failed:"
<<
errMsg
;
}
else
{
vecFailedOrders
.
assign
(
vecOrders
.
begin
(),
vecOrders
.
end
());
}
}
src/SQLiteModule.h
deleted
100644 → 0
View file @
f3e81c8e
#ifndef SQLITE_MODULE_H
#define SQLITE_MODULE_H
#include <iostream>
#include <vector>
#include "../base/CommonStruct.h"
#ifdef WIN32
#include "../3rdParty/sqlite3.h"
#else
#include <sqlite3.h>
#endif // WIN32
class
SQLite
{
public
:
SQLite
();
~
SQLite
();
bool
initSQLite
();
void
closeSQLite
();
int
isRecordExist
(
std
::
string
strTable
,
std
::
string
strKey
);
bool
isTableExist
(
sqlite3
*
sqDb
,
std
::
string
strTableName
);
bool
insert
(
const
char
*
sql
);
bool
update
(
const
char
*
sql
);
bool
remove
(
const
char
*
sql
);
void
query
(
const
char
*
sql
,
std
::
vector
<
orderSendFailedObj
>
&
vecFailedOrders
);
private
:
bool
_execSql
(
const
char
*
sql
);
bool
_createTable
();
private
:
sqlite3
*
pDB
;
char
*
errMsg
;
};
#endif
src/main.cpp
View file @
6d92af25
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
INITIALIZE_EASYLOGGINGPP
INITIALIZE_EASYLOGGINGPP
#define VERSION "1.0.4 Beta
2
" //版本号
#define VERSION "1.0.4 Beta
4
" //版本号
std
::
string
g_init_data
;
std
::
string
g_init_data
;
std
::
string
g_init_data_ods_back
;
std
::
string
g_init_data_ods_back
;
...
...
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