Path: blob/main/contrib/kyua/utils/sqlite/statement.hpp
48199 views
// Copyright 2011 The Kyua Authors.1// All rights reserved.2//3// Redistribution and use in source and binary forms, with or without4// modification, are permitted provided that the following conditions are5// met:6//7// * Redistributions of source code must retain the above copyright8// notice, this list of conditions and the following disclaimer.9// * Redistributions in binary form must reproduce the above copyright10// notice, this list of conditions and the following disclaimer in the11// documentation and/or other materials provided with the distribution.12// * Neither the name of Google Inc. nor the names of its contributors13// may be used to endorse or promote products derived from this software14// without specific prior written permission.15//16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2728/// \file utils/sqlite/statement.hpp29/// Wrapper classes and utilities for SQLite statement processing.30///31/// This module contains thin RAII wrappers around the SQLite 3 structures32/// representing statements.3334#if !defined(UTILS_SQLITE_STATEMENT_HPP)35#define UTILS_SQLITE_STATEMENT_HPP3637#include "utils/sqlite/statement_fwd.hpp"3839extern "C" {40#include <stdint.h>41}4243#include <memory>44#include <string>4546#include "utils/sqlite/database_fwd.hpp"4748namespace utils {49namespace sqlite {505152/// Representation of a BLOB.53class blob {54public:55/// Memory representing the contents of the blob, or NULL if empty.56///57/// This memory must remain valid throughout the life of this object, as we58/// do not grab ownership of the memory.59const void* memory;6061/// Number of bytes in memory.62int size;6364/// Constructs a new blob.65///66/// \param memory_ Pointer to the contents of the blob.67/// \param size_ The size of memory_.68blob(const void* memory_, const int size_) :69memory(memory_), size(size_)70{71}72};737475/// Representation of a SQL NULL value.76class null {77};787980/// A RAII model for an SQLite 3 statement.81class statement {82struct impl;8384/// Pointer to the shared internal implementation.85std::shared_ptr< impl > _pimpl;8687statement(database&, void*);88friend class database;8990public:91~statement(void);9293bool step(void);94void step_without_results(void);9596int column_count(void);97std::string column_name(const int);98type column_type(const int);99int column_id(const char*);100101blob column_blob(const int);102double column_double(const int);103int column_int(const int);104int64_t column_int64(const int);105std::string column_text(const int);106int column_bytes(const int);107108blob safe_column_blob(const char*);109double safe_column_double(const char*);110int safe_column_int(const char*);111int64_t safe_column_int64(const char*);112std::string safe_column_text(const char*);113int safe_column_bytes(const char*);114115void reset(void);116117void bind(const int, const blob&);118void bind(const int, const double);119void bind(const int, const int);120void bind(const int, const int64_t);121void bind(const int, const null&);122void bind(const int, const std::string&);123template< class T > void bind(const char*, const T&);124125int bind_parameter_count(void);126int bind_parameter_index(const std::string&);127std::string bind_parameter_name(const int);128129void clear_bindings(void);130};131132133} // namespace sqlite134} // namespace utils135136#endif // !defined(UTILS_SQLITE_STATEMENT_HPP)137138139