sqlite_server/src/litedb.cc

37 lines
660 B
C++
Raw Normal View History

2025-03-13 20:26:17 +08:00
#include <litedb.h>
litedb::litedb(std::string &db_name) : stmt(nullptr), db(nullptr)
{
this->_db_path_name = std::move(db_name);
}
litedb::~litedb()
{
if (this->stmt)
sqlite3_finalize(this->stmt);
if (this->db)
sqlite3_close_v2(this->db);
}
Status litedb::litedb_open()
{
if (this->_db_path_name.empty())
{
return Status::STATUS_INNER_ERR;
}
if (this->db)
{
return Status::STATUS_OK;
}
int ret = sqlite3_open_v2(this->_db_path_name.c_str(), &this->db, 0, nullptr);
if (ret != SQLITE_OK)
{
return Status::STATUS_INNER_ERR;
}
return Status::STATUS_OK;
}