This commit is contained in:
zjp
2025-02-28 10:02:30 +08:00
parent bd16fe113b
commit 3f81e4c860
+7 -8
View File
@@ -4,7 +4,7 @@
* @文件版本: V1.0.0
* @创建日期: 2025-02-21 15:16:45
* @简要说明:
* @编辑时间: 2025-02-28 09:55:54
* @编辑时间: 2025-02-28 10:01:15
* @Copyright: 2025 Shenzhen ShenBao Electrical instruments CO.,LTD. All Rights Reserved.
*/
@@ -22,7 +22,7 @@ using namespace std;
#define DBNAME "test.db"
#define FILEBACKUP "/opt/bak/bak.sql"
#define FILEBACKUP_HIS "mv /opt/bak/bak.sql /opt/bak/bak.sql.bak"
#define CMDBACKUP_HIS "mv /opt/bak/bak.sql /opt/bak/bak.sql.bak"
class Database
{
@@ -62,7 +62,7 @@ public:
int nResult = sqlite3_get_table(db, sql.c_str(), pResult, nRow, nCol, &errmsg);
if (nResult != SQLITE_OK)
{
//sqlite3_close(db);
// sqlite3_close(db);
cout << errmsg << " code:" << nResult << endl;
sqlite3_free(errmsg);
return (-1);
@@ -101,7 +101,7 @@ public:
int rtn = -1;
std::cout << "start backup database..." << std::endl;
system(FILEBACKUP_HIS);
system(CMDBACKUP_HIS);
// system("./sqlite shb3104.db '.dump f_param' > /opt/bak.sql");
// system("./sqlite shb3104.db '.dump f_param_def' >> /opt/bak.sql");
@@ -165,6 +165,8 @@ public:
{
int flag_bak = 0;
struct stat statbuf;
char *zErrMsg = 0;
int rc;
if (stat(FILEBACKUP, &statbuf) == 0)
{
@@ -175,10 +177,7 @@ public:
}
DbClose(); // 关闭现有连接
char *zErrMsg = 0;
int rc;
system("sync");
DbOpen(DBNAME);
// 从备份文件中读取SQL命令并执行