NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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; -*- */
22 #include "sqlite3-statement.hpp"
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.c_str(), -1, &m_stmt, nullptr);
37  if (res != SQLITE_OK)
38  BOOST_THROW_EXCEPTION(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(sqlite3_column_blob(m_stmt, column), sqlite3_column_bytes(m_stmt, column));
82 }
83 
84 int
86 {
87  return sqlite3_column_int(m_stmt, column);
88 }
89 
90 
91 const uint8_t*
93 {
94  return static_cast<const uint8_t*>(sqlite3_column_blob(m_stmt, column));
95 }
96 
97 int
99 {
100  return sqlite3_column_bytes(m_stmt, column);
101 }
102 
103 int
105 {
106  return sqlite3_step(m_stmt);
107 }
108 
109 Sqlite3Statement::operator sqlite3_stmt*()
110 {
111  return m_stmt;
112 }
113 
114 } // namespace util
115 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
int getSize(int column)
get the size of column.
~Sqlite3Statement()
finalize the statement
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
Sqlite3Statement(sqlite3 *database, const std::string &statement)
initialize and prepare Sqlite3 statement
size_t size() const
Definition: block.cpp:504
Block getBlock(int column)
get a block from column.
const uint8_t * getBlob(int column)
get a pointer of byte blob from column.
int bind(int index, const char *value, size_t size, void(*destructor)(void *))
bind a string to the statement
std::string getString(int column)
get a string from column.
int step()
wrapper of sqlite3_step
int getInt(int column)
get an integer from column.
const uint8_t * wire() const
Definition: block.cpp:495