#ifndef __SFJP_ROAST__db__sqlite3_HPP__
#define __SFJP_ROAST__db__sqlite3_HPP__
-#include "sqlite3.h"
+#include "sqlite3.h" // Require External Library
#include "roast/db/base.hpp"
#define ROAST_DB_SQLITE_MEMORY_DB ":memory:"
class driver : public driver_base
{
+ private:
+ // SQL Select Callback. (in ROW)
+ static int _select_callback(void *p_result,
+ int column_count, char **values, char **colunm_name)
+ {
+ select_result &result = *((select_result*)p_result);
+ select_row rows;
+
+ for(int i=0; i<column_count; i++)
+ {
+ rows.push_back(values[i]);
+ }
+ result.push_back(rows);
+
+ return SQLITE_OK;
+ }
+
protected:
- ::sqlite3 *m_db;
+ ::sqlite3 *m_device;
public:
driver(){
- m_db = NULL;
+ m_device = NULL;
}
virtual ~driver(){
close();
virtual bool open(const char* name)
{
- if( ::sqlite3_open(name, &m_db) != SQLITE_OK )
+ if( ::sqlite3_open(name, &m_device) != SQLITE_OK )
return false; // sqlite3_errmsg(db));
else
return true;
virtual bool close()
{
- if ( m_db != NULL )
- ::sqlite3_close(m_db);
+ if ( m_device != NULL )
+ ::sqlite3_close(m_device);
return true;
}
- //////////////////////////////
+ //////////////////////////////////
+ template <typename _Command>
+ void exec(const &_Command cmd, exec_callback callback)
+ {
+
+ }
+ template <>
+ void exec<const char*>(const char* cmd, exec_callback callback)
+ {
+ bool ret = true;
+
+ char *szErrMsg = NULL;
+ if ( ::sqlite3_exec(m_device, cmd, _select_callback, &result, &szErrMsg) != SQLITE_OK )
+ ret = false;
+
+ if ( szErrMsg != NULL )
+ ::sqlite3_free(szErrMsg);
+
+ return ret;
+ }
};
//////////////////////////////////////////////////////////////////////////////////////