Update SQLite Wrapper

Remove debug outputs.
Add Error Message handling interfaces.
Add namespace (MiniEngine::SQL).
This commit is contained in:
Kirigaya Kazuto 2017-04-16 18:15:17 +08:00
parent 92f2d9b4af
commit 9ac5f9833a
2 changed files with 32 additions and 4 deletions

View File

@ -2,6 +2,12 @@
#include <cstring> #include <cstring>
#include <cstdio> #include <cstdio>
namespace MiniEngine
{
namespace SQL
{
// private // private
void SQLStatement::_set(sqlite3_stmt* p) void SQLStatement::_set(sqlite3_stmt* p)
{ {
@ -65,8 +71,19 @@ int SQLDB::step(const SQLStatement& Statement)
int SQLDB::exec(const std::string& SQLCommand,SQLCallback callback,void* param) int SQLDB::exec(const std::string& SQLCommand,SQLCallback callback,void* param)
{ {
char* errmsg=nullptr; return sqlite3_exec(_get(),SQLCommand.c_str(),callback,param,&_errmsg);
int ret=sqlite3_exec(_get(),SQLCommand.c_str(),callback,param,&errmsg);
printf("ErrMsg: %s\n",errmsg);
return ret;
} }
const char* SQLDB::getErrorMsg()
{
return _errmsg;
}
void SQLDB::clearError()
{
_errmsg=nullptr;
}
}/// End of namespace MiniEngine::SQL
}/// End of namespace MiniEngine

View File

@ -3,6 +3,12 @@
#include <string> #include <string>
#include <memory> #include <memory>
namespace MiniEngine
{
namespace SQL
{
class SQLStatement class SQLStatement
{ {
public: public:
@ -32,10 +38,15 @@ public:
SQLStatement prepare(const std::string& SQLCommand); SQLStatement prepare(const std::string& SQLCommand);
int step(const SQLStatement& Statement); int step(const SQLStatement& Statement);
int exec(const std::string& SQLCommand,SQLCallback callback,void* param); int exec(const std::string& SQLCommand,SQLCallback callback,void* param);
const char* getErrorMsg();
void clearError();
private: private:
sqlite3* _get(); sqlite3* _get();
void _set(sqlite3*); void _set(sqlite3*);
std::shared_ptr<sqlite3> _db; std::shared_ptr<sqlite3> _db;
char* _errmsg;
}; };
}/// End of namespace MiniEngine::SQL
}/// End of namespace MiniEngine