blob: ab016e1d4c5922c08bc07b614aa0a586bb7ff0be [file] [log] [blame]
shockjianga5ae48c2014-07-27 23:21:41 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California.
4 *
5 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef NDNS_DB_MGR_CPP
21#define NDNS_DB_MGR_CPP
22
23#include <sqlite3.h>
24#include <iostream>
25
shockjianga5ae48c2014-07-27 23:21:41 -070026namespace ndn {
27namespace ndns {
28
shockjianga5ae48c2014-07-27 23:21:41 -070029class DBMgr
30{
31public:
32 enum m_status
33 {
shockjiang99ad3892014-08-03 14:56:13 -070034 DBConnected, DBClosed, DBError
shockjianga5ae48c2014-07-27 23:21:41 -070035 };
36
37public:
38 DBMgr();
39 virtual ~DBMgr();
40
41 void open();
42 void close();
shockjiang99ad3892014-08-03 14:56:13 -070043 void execute(std::string sql, int (*callback)(void*, int, char**, char**),
44 void * paras);
shockjianga5ae48c2014-07-27 23:21:41 -070045
shockjiang99ad3892014-08-03 14:56:13 -070046 inline void addResultNum()
47 {
shockjianga5ae48c2014-07-27 23:21:41 -070048 m_resultNum += 1;
49 }
shockjiang99ad3892014-08-03 14:56:13 -070050 inline void clearResultNum()
51 {
shockjianga5ae48c2014-07-27 23:21:41 -070052 m_resultNum = 0;
53 }
54
shockjiang99ad3892014-08-03 14:56:13 -070055 const std::string& getDbfile() const
56 {
shockjianga5ae48c2014-07-27 23:21:41 -070057 return m_dbfile;
58 }
59
shockjiang99ad3892014-08-03 14:56:13 -070060 void setDbfile(const std::string& dbfile)
61 {
shockjianga5ae48c2014-07-27 23:21:41 -070062 this->m_dbfile = dbfile;
63 }
64
shockjiang99ad3892014-08-03 14:56:13 -070065 const std::string& getErr() const
66 {
shockjianga5ae48c2014-07-27 23:21:41 -070067 return m_err;
68 }
69
shockjiang99ad3892014-08-03 14:56:13 -070070 void setErr(const std::string& err)
71 {
shockjianga5ae48c2014-07-27 23:21:41 -070072 this->m_err = err;
73 }
74
shockjiang99ad3892014-08-03 14:56:13 -070075 int getReCode() const
76 {
shockjianga5ae48c2014-07-27 23:21:41 -070077 return m_reCode;
78 }
79
shockjiang99ad3892014-08-03 14:56:13 -070080 void setReCode(int reCode)
81 {
shockjianga5ae48c2014-07-27 23:21:41 -070082 this->m_reCode = reCode;
83 }
84
shockjiang99ad3892014-08-03 14:56:13 -070085 m_status getStatus() const
86 {
shockjianga5ae48c2014-07-27 23:21:41 -070087 return m_status;
88 }
89
shockjiang99ad3892014-08-03 14:56:13 -070090 void setStatus(m_status status)
91 {
shockjianga5ae48c2014-07-27 23:21:41 -070092 this->m_status = status;
93 }
94
shockjiang99ad3892014-08-03 14:56:13 -070095 int getResultNum() const
96 {
shockjianga5ae48c2014-07-27 23:21:41 -070097 return m_resultNum;
98 }
99
shockjiang99ad3892014-08-03 14:56:13 -0700100 void setResultNum(int resultNum)
101 {
shockjianga5ae48c2014-07-27 23:21:41 -0700102 m_resultNum = resultNum;
103 }
104
shockjianga5ae48c2014-07-27 23:21:41 -0700105private:
106 std::string m_dbfile;
107 sqlite3 *m_conn;
108 std::string m_err;
109 int m_reCode;
110 m_status m_status;
111 int m_resultNum;
shockjiang99ad3892014-08-03 14:56:13 -0700112};
113//class DBMgr
shockjianga5ae48c2014-07-27 23:21:41 -0700114}//namespace ndns
shockjiang99ad3892014-08-03 14:56:13 -0700115} //namespace ndn
shockjianga5ae48c2014-07-27 23:21:41 -0700116
117#endif