blob: c6445af9221ee8b231b339575c91bf1023f819f9 [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
26
27namespace ndn {
28namespace ndns {
29
30
31class DBMgr
32{
33public:
34 enum m_status
35 {
36 DBConnected,
37 DBClosed,
38 DBError
39 };
40
41public:
42 DBMgr();
43 virtual ~DBMgr();
44
45 void open();
46 void close();
47 void execute(std::string sql,
48 int (*callback)(void*,int,char**,char**), void * paras);
49
50 inline void addResultNum(){
51 m_resultNum += 1;
52 }
53 inline void clearResultNum() {
54 m_resultNum = 0;
55 }
56
57 const std::string& getDbfile() const {
58 return m_dbfile;
59 }
60
61 void setDbfile(const std::string& dbfile) {
62 this->m_dbfile = dbfile;
63 }
64
65 const std::string& getErr() const {
66 return m_err;
67 }
68
69 void setErr(const std::string& err) {
70 this->m_err = err;
71 }
72
73 int getReCode() const {
74 return m_reCode;
75 }
76
77 void setReCode(int reCode) {
78 this->m_reCode = reCode;
79 }
80
81 m_status getStatus() const {
82 return m_status;
83 }
84
85 void setStatus(m_status status) {
86 this->m_status = status;
87 }
88
89 int getResultNum() const {
90 return m_resultNum;
91 }
92
93 void setResultNum(int resultNum) {
94 m_resultNum = resultNum;
95 }
96
97
98private:
99 std::string m_dbfile;
100 sqlite3 *m_conn;
101 std::string m_err;
102 int m_reCode;
103 m_status m_status;
104 int m_resultNum;
105}; //class DBMgr
106}//namespace ndns
107}//namespace ndn
108
109#endif