1 // Copyright 2011 The Kyua Authors.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /// \file utils/sqlite/statement.hpp
30 /// Wrapper classes and utilities for SQLite statement processing.
32 /// This module contains thin RAII wrappers around the SQLite 3 structures
33 /// representing statements.
35 #if !defined(UTILS_SQLITE_STATEMENT_HPP)
36 #define UTILS_SQLITE_STATEMENT_HPP
38 #include "utils/sqlite/statement_fwd.hpp"
47 #include "utils/sqlite/database_fwd.hpp"
53 /// Representation of a BLOB.
56 /// Memory representing the contents of the blob, or NULL if empty.
58 /// This memory must remain valid throughout the life of this object, as we
59 /// do not grab ownership of the memory.
62 /// Number of bytes in memory.
65 /// Constructs a new blob.
67 /// \param memory_ Pointer to the contents of the blob.
68 /// \param size_ The size of memory_.
69 blob(const void* memory_, const int size_) :
70 memory(memory_), size(size_)
76 /// Representation of a SQL NULL value.
81 /// A RAII model for an SQLite 3 statement.
85 /// Pointer to the shared internal implementation.
86 std::shared_ptr< impl > _pimpl;
88 statement(database&, void*);
89 friend class database;
95 void step_without_results(void);
97 int column_count(void);
98 std::string column_name(const int);
99 type column_type(const int);
100 int column_id(const char*);
102 blob column_blob(const int);
103 double column_double(const int);
104 int column_int(const int);
105 int64_t column_int64(const int);
106 std::string column_text(const int);
107 int column_bytes(const int);
109 blob safe_column_blob(const char*);
110 double safe_column_double(const char*);
111 int safe_column_int(const char*);
112 int64_t safe_column_int64(const char*);
113 std::string safe_column_text(const char*);
114 int safe_column_bytes(const char*);
118 void bind(const int, const blob&);
119 void bind(const int, const double);
120 void bind(const int, const int);
121 void bind(const int, const int64_t);
122 void bind(const int, const null&);
123 void bind(const int, const std::string&);
124 template< class T > void bind(const char*, const T&);
126 int bind_parameter_count(void);
127 int bind_parameter_index(const std::string&);
128 std::string bind_parameter_name(const int);
130 void clear_bindings(void);
134 } // namespace sqlite
137 #endif // !defined(UTILS_SQLITE_STATEMENT_HPP)