// Database_Package.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
|
//
|
|
#include <iostream>
|
//#include <mysql.h>
|
#include <winsock2.h>
|
#include "mysql/include/mysql.h"
|
|
#include <memory>
|
#include <string>
|
#include <chrono>
|
#include <fstream>
|
#include "ConnectionPool.h"
|
|
using namespace std;
|
|
/*
|
#define M_MYSQL_DNAME AI_datas
|
#define M_MYSQL_IP 192.168.133.129
|
#define M_MYSQL_PORT 3306
|
#define M_MYSQL_USER root
|
#define M_MYSQL_PASSWD 1
|
#define M_MYSQL_PATH D:\\PROGECT_0214
|
*/
|
|
void testDatabaseConnection()
|
{
|
// 创建连接池对象
|
ConnectionPool* pool = ConnectionPool::getInstance();
|
|
// 从连接池中获取连接
|
shared_ptr<ConnectMysql> conn = pool->getConnection();
|
if (conn == nullptr)
|
{
|
cerr << "未取得数据库连接!" << endl;
|
return;
|
}
|
cout << "连接成功" << endl;
|
|
// 测试更新功能
|
string sql = "INSERT INTO employee_info (employee_name, employee_age, employee_sex, employee_bir, employee_password, employee_email, employee_phone, employee_department)VALUES('朱琛', 20, '男', '1999-09-09', '123456', '123456@123.com', '12345678901', 'asdf')";
|
if (conn->update(sql))
|
{
|
cout << "更新成功!" << endl;
|
}
|
else
|
{
|
cerr << "更新失败!" << endl;
|
}
|
|
// 测试查询功能
|
sql = "SELECT * FROM employee_info";
|
if (conn->query(sql))
|
{
|
cout << "正在查询..." << endl;
|
// 获取查询结果
|
vector<vector<string>> results = conn->getQueryResults();
|
// 处理查询结果
|
for (const auto& row : results)
|
{
|
for (const auto& field : row)
|
{
|
cout << field << "\t";
|
}
|
cout << endl;
|
}
|
}
|
else
|
{
|
cerr << "查询失败!" << endl;
|
}
|
|
// 实现备份功能
|
string backupPath = "D:\\PROGECT_0214\\"; // 备份路径,你可以根据需要修改
|
cout << "开始备份数据库..." << endl;
|
conn->backupCurrentDB(backupPath);
|
cout << "数据库备份完成!" << endl;
|
|
cout << "开始备份表 employee_info..." << endl;
|
conn->backupCurrentTable(backupPath, "employee_info");
|
cout << "表 employee_info 备份完成!" << endl;
|
// 使用shell脚本备份数据库
|
//string backupPath = "D:\\PROGECT_0214\\"; // 备份路径,你可以根据需要修改
|
//cout << "开始使用shell脚本备份数据库..." << endl;
|
//conn->backupCurrentDBUsingShell(backupPath);
|
//cout << "数据库备份完成!" << endl;
|
}
|
|
int main()
|
{
|
testDatabaseConnection();
|
return 0;
|
}
|