-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsql_warpper_test.cpp
More file actions
65 lines (54 loc) · 2.23 KB
/
sql_warpper_test.cpp
File metadata and controls
65 lines (54 loc) · 2.23 KB
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
// chat_server.cpp
#include "sql_wrapper.h"
int main()
{
sql_wrapper sql_("tcp://127.0.0.1:3306", "root", "111222", "game");
bool ret_ = false;
// 创建
ret_ = sql_.create("create table test (id_ double, name_ varchar(64), password_ varchar(64)); ");
// 添加
ret_ = sql_.insert("insert into test (id_, name_, password_) values (0.1, '0.2', '0.3');"),
// 添加 —> 带参数
ret_ = sql_.insert("insert into test (id_, name_, password_) values (?, ?, ?);",
std::tuple<double, std::string, std::string>(0.11118, "0.2", "0.2"));
// 添加 —> 带参数
ret_ = sql_.insert("insert into test (id_, name_, password_) values (?, ?, ?);",
std::tuple<double, std::string, std::string>(0.8, "0.2", "0.2"));
// 删除
ret_ = sql_.remove("delete from test where id_ = '0.3';");
// 删除 —> 带参数
ret_ = sql_.remove("delete from test where id_ = ?;", std::tuple<std::string>("0.11118"));
// 更新
ret_ = sql_.update("update test set id_ = 0.1, name_ = 'test' where password_ = 0.1;"),
// 更新 —> 带参数
ret_ = sql_.update("update test set id_ = ?, name_ = ? where password_ = ?;",
std::tuple<double, std::string, std::string>(0.2, "humorly", "0.2"));
std::vector<std::tuple<double, std::string, std::string>> user_content_;
// 查询
ret_ = sql_.select("select * from test;",
std::tuple<>(),
std::tuple<std::string, std::string, std::string>("id_", "name_", "password_"),
user_content_);
std::cout << "content:" << std::endl;
for (auto &val : user_content_)
{
std::cout << "id_ = " << std::get<0>(val) << ", ";
std::cout << "name_ = " << std::get<1>(val) << ", ";
std::cout << "password_ = " << std::get<2>(val) << std::endl;
}
// 查询 —> 带参数
user_content_.clear();
ret_ = sql_.select("select id_, name_, password_ from test where password_ = ?;",
std::tuple<std::string>("0.2"),
std::tuple<std::string, std::string, std::string>("id_", "name_", "password_"),
user_content_);
std::cout << "content:" << std::endl;
for (auto &val : user_content_)
{
std::cout << "id_ = " << std::get<0>(val) << ", ";
std::cout << "name_ = " << std::get<1>(val) << ", ";
std::cout << "password_ = " << std::get<2>(val) << std::endl;
}
return 0;
}