blob: dbad1d28db1b1c5d71215f4953c9fae2a0c79ee6 [file] [log] [blame]
Mickey Sweatt7f177902015-06-10 17:20:19 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2015 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#ifndef NDN_UTIL_SQLITE3_STATEMENT_HPP
23#define NDN_UTIL_SQLITE3_STATEMENT_HPP
24
25#include "../encoding/block.hpp"
26#include <string>
27
28struct sqlite3;
29struct sqlite3_stmt;
30
31namespace ndn {
32namespace util {
33
34/**
35 * @brief wrap an SQLite3 prepared statement
36 * @warning This class is implementation detail of ndn-cxx library.
37 */
38class Sqlite3Statement : noncopyable
39{
40public:
41 /**
42 * @brief initialize and prepare Sqlite3 statement
43 * @param database handler to open sqlite3 database
44 * @param statement SQL statement
45 * @throw std::domain_error SQL statement is bad
46 */
47 Sqlite3Statement(sqlite3* database, const std::string& statement);
48
49 /**
50 * @brief finalize the statement
51 */
52 ~Sqlite3Statement();
53
54 /**
55 * @brief bind a string to the statement
56 *
57 * @param index The binding position
58 * @param value The pointer of the binding string
59 * @param value The size of the binding string
60 * @param destructor SQLite3 destructor, e.g., SQLITE_TRANSIENT
61 * @return SQLite result value.
62 */
63 int
64 bind(int index, const char* value, size_t size, void(*destructor)(void*));
65
66 /**
67 * @brief bind a string to the statement
68 *
69 * @param index The binding position
70 * @param value The binding string
71 * @param destructor SQLite3 destructor, e.g., SQLITE_TRANSIENT
72 * @return SQLite result value.
73 */
74 int
75 bind(int index, const std::string& value, void(*destructor)(void*));
76
77 /**
78 * @brief bind a byte blob to the statement
79 *
80 * @param index The binding position
81 * @param value The pointer of the blob
82 * @param value The size of the blob
83 * @param destructor SQLite3 destructor, e.g., SQLITE_TRANSIENT
84 * @return SQLite result value.
85 */
86 int
87 bind(int index, const void* value, size_t size, void(*destructor)(void*));
88
89 /**
90 * @brief bind a byte blob to the statement
91 *
92 * @param index The binding position
93 * @param block The binding block
94 * @param destructor SQLite3 destructor, e.g., SQLITE_TRANSIENT
95 * @return SQLite result value
96 */
97 int
98 bind(int index, const Block& block, void(*destructor)(void*));
99
100 /**
101 * @brief bind an integer to the statement
102 *
103 * @param index The binding position
104 * @param number The binding integer
105 * @return SQLite result value
106 */
107 int
108 bind(int index, int number);
109
110 /**
111 * @brief get a string from @p column.
112 */
113 std::string
114 getString(int column);
115
116 /**
117 * @brief get a block from @p column.
118 */
119 Block
120 getBlock(int column);
121
122 /**
123 * @brief get an integer from @p column.
124 */
125 int
126 getInt(int column);
127
128 /**
129 * @brief get a pointer of byte blob from @p column.
130 */
131 const uint8_t*
132 getBlob(int column);
133
134 /**
135 * @brief get the size of @p column.
136 */
137 int
138 getSize(int column);
139
140 /**
141 * @brief wrapper of sqlite3_step
142 */
143 int
144 step();
145
146 /**
147 * @brief implicitly converts to sqlite3_stmt* to be used in SQLite C API
148 */
149 operator sqlite3_stmt*();
150
151private:
152 sqlite3_stmt* m_stmt;
153};
154
155} // namespace util
156} // namespace ndn
157
158#endif // NDN_UTIL_SQLITE3_STATEMENT_HPP