NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
sqlite3-statement.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2019 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 
23 
24 #include <sqlite3.h>
25 
26 namespace ndn {
27 namespace util {
28 
30 {
31  sqlite3_finalize(m_stmt);
32 }
33 
34 Sqlite3Statement::Sqlite3Statement(sqlite3* database, const std::string& statement)
35 {
36  int res = sqlite3_prepare_v2(database, statement.data(), -1, &m_stmt, nullptr);
37  if (res != SQLITE_OK)
38  NDN_THROW(std::domain_error("bad SQL statement: " + statement));
39 }
40 
41 int
42 Sqlite3Statement::bind(int index, const char* value, size_t size, void(*destructor)(void*))
43 {
44  return sqlite3_bind_text(m_stmt, index, value, size, destructor);
45 }
46 
47 int
48 Sqlite3Statement::bind(int index, const std::string& value, void(*destructor)(void*))
49 {
50  return sqlite3_bind_text(m_stmt, index, value.c_str(), value.size(), destructor);
51 }
52 
53 int
54 Sqlite3Statement::bind(int index, const void* buf, size_t size, void(*destructor)(void*))
55 {
56  return sqlite3_bind_blob(m_stmt, index, buf, size, destructor);
57 }
58 
59 int
60 Sqlite3Statement::bind(int index, const Block& block, void(*destructor)(void*))
61 {
62  return sqlite3_bind_blob(m_stmt, index, block.wire(), block.size(), destructor);
63 }
64 
65 int
66 Sqlite3Statement::bind(int index, int number)
67 {
68  return sqlite3_bind_int(m_stmt, index, number);
69 }
70 
71 std::string
73 {
74  return std::string(reinterpret_cast<const char*>(sqlite3_column_text(m_stmt, column)),
75  sqlite3_column_bytes(m_stmt, column));
76 }
77 
78 Block
80 {
81  return Block(reinterpret_cast<const uint8_t*>(sqlite3_column_blob(m_stmt, column)),
82  sqlite3_column_bytes(m_stmt, column));
83 }
84 
85 int
87 {
88  return sqlite3_column_int(m_stmt, column);
89 }
90 
91 
92 const uint8_t*
94 {
95  return static_cast<const uint8_t*>(sqlite3_column_blob(m_stmt, column));
96 }
97 
98 int
100 {
101  return sqlite3_column_bytes(m_stmt, column);
102 }
103 
104 int
106 {
107  return sqlite3_step(m_stmt);
108 }
109 
110 Sqlite3Statement::operator sqlite3_stmt*()
111 {
112  return m_stmt;
113 }
114 
115 } // namespace util
116 } // namespace ndn
buf
const uint8_t * buf
Definition: verification-helpers.cpp:47
ndn::util::Sqlite3Statement::step
int step()
wrapper of sqlite3_step
Definition: sqlite3-statement.cpp:105
ndn::util::Sqlite3Statement::getBlob
const uint8_t * getBlob(int column)
get a pointer of byte blob from column.
Definition: sqlite3-statement.cpp:93
ndn::util::Sqlite3Statement::Sqlite3Statement
Sqlite3Statement(sqlite3 *database, const std::string &statement)
initialize and prepare Sqlite3 statement
Definition: sqlite3-statement.cpp:34
ndn::util::Sqlite3Statement::getSize
int getSize(int column)
get the size of column.
Definition: sqlite3-statement.cpp:99
NDN_THROW
#define NDN_THROW(e)
Definition: exception.hpp:61
sqlite3-statement.hpp
ndn::util::Sqlite3Statement::getInt
int getInt(int column)
get an integer from column.
Definition: sqlite3-statement.cpp:86
ndn::Block
Represents a TLV element of NDN packet format.
Definition: block.hpp:43
ndn::Block::size
size_t size() const
Return the size of the encoded wire, i.e.
Definition: block.cpp:290
ndn::util::Sqlite3Statement::getString
std::string getString(int column)
get a string from column.
Definition: sqlite3-statement.cpp:72
ndn::util::Sqlite3Statement::~Sqlite3Statement
~Sqlite3Statement()
finalize the statement
Definition: sqlite3-statement.cpp:29
ndn::util::Sqlite3Statement::bind
int bind(int index, const char *value, size_t size, void(*destructor)(void *))
bind a string to the statement
Definition: sqlite3-statement.cpp:42
ndn::Block::wire
const uint8_t * wire() const
Return a raw pointer to the beginning of the encoded wire.
Definition: block.cpp:281
ndn::util::Sqlite3Statement::getBlock
Block getBlock(int column)
get a block from column.
Definition: sqlite3-statement.cpp:79
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34