-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathc_sql_test.cpp
More file actions
45 lines (34 loc) · 1.21 KB
/
Copy pathc_sql_test.cpp
File metadata and controls
45 lines (34 loc) · 1.21 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
//
// Created by liuping on 2019/7/21.
//
#include <stdlib.h>
#include <iostream>
#include "c_sql.h"
#include "test/test_sql.h"
using namespace std;
int main(void) {
MYSQL conn;
mysql_init(&conn);
mysql_real_connect(&conn, "127.0.0.1", "root", "", "test", 3306, nullptr, 0);
CSql c_sql(conn);
// 获取所有数据并删除
auto user_info = vg_account::GetUserInfo(&c_sql, {});
for (const auto &item : user_info) {
std::cout << item.DebugString() << "\n";
std::cout << "del user_id:" << item.user_id << " result:"
<< vg_account::DeleteUser(&c_sql, {item.user_id}) << "\n";
}
for (int i = 0; i < 10; i++) {
auto name = "user00" + std::to_string(i);
std::cout << "add user:" << name << " reslut:" << vg_account::AddUser(&c_sql, {name, "passwd_old", 1})
<< "\n";
}
std::cout << "\n----------------\n";
auto user_info1 = vg_account::GetUserInfo(&c_sql, {});
for (const auto &item : user_info1) {
std::cout << item.DebugString() << "\n";
std::cout << "update :" << vg_account::UpdateUserInfoByName(&c_sql, {"passwd_new", 100, item.name}) << "\n";
}
cout << endl;
return EXIT_SUCCESS;
}