/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2013-2018 Regents of the University of California.
 *
 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
 *
 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
 *
 * You should have received copies of the GNU General Public License and GNU Lesser
 * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
 */

#ifndef NDN_UTIL_SQLITE3_STATEMENT_HPP
#define NDN_UTIL_SQLITE3_STATEMENT_HPP

#include "ndn-cxx/encoding/block.hpp"

struct sqlite3;
struct sqlite3_stmt;

namespace ndn {
namespace util {

/**
 * @brief wrap an SQLite3 prepared statement
 * @warning This class is implementation detail of ndn-cxx library.
 */
class Sqlite3Statement : noncopyable
{
public:
  /**
   * @brief initialize and prepare Sqlite3 statement
   * @param database handler to open sqlite3 database
   * @param statement SQL statement
   * @throw std::domain_error SQL statement is bad
   */
  Sqlite3Statement(sqlite3* database, const std::string& statement);

  /**
   * @brief finalize the statement
   */
  ~Sqlite3Statement();

  /**
   * @brief bind a string to the statement
   *
   * @param index The binding position
   * @param value The pointer of the binding string
   * @param size The size of the binding string
   * @param destructor SQLite3 destructor, e.g., SQLITE_TRANSIENT
   * @return SQLite result value.
   */
  int
  bind(int index, const char* value, size_t size, void(*destructor)(void*));

  /**
   * @brief bind a string to the statement
   *
   * @param index The binding position
   * @param value The binding string
   * @param destructor SQLite3 destructor, e.g., SQLITE_TRANSIENT
   * @return SQLite result value.
   */
  int
  bind(int index, const std::string& value, void(*destructor)(void*));

  /**
   * @brief bind a byte blob to the statement
   *
   * @param index The binding position
   * @param value The pointer of the blob
   * @param size The size of the blob
   * @param destructor SQLite3 destructor, e.g., SQLITE_TRANSIENT
   * @return SQLite result value.
   */
  int
  bind(int index, const void* value, size_t size, void(*destructor)(void*));

  /**
   * @brief bind a byte blob to the statement
   *
   * @param index The binding position
   * @param block The binding block
   * @param destructor SQLite3 destructor, e.g., SQLITE_TRANSIENT
   * @return SQLite result value
   */
  int
  bind(int index, const Block& block, void(*destructor)(void*));

  /**
   * @brief bind an integer to the statement
   *
   * @param index The binding position
   * @param number The binding integer
   * @return SQLite result value
   */
  int
  bind(int index, int number);

  /**
   * @brief get a string from @p column.
   */
  std::string
  getString(int column);

  /**
   * @brief get a block from @p column.
   */
  Block
  getBlock(int column);

  /**
   * @brief get an integer from @p column.
   */
  int
  getInt(int column);

  /**
   * @brief get a pointer of byte blob from @p column.
   */
  const uint8_t*
  getBlob(int column);

  /**
   * @brief get the size of @p column.
   */
  int
  getSize(int column);

  /**
   * @brief wrapper of sqlite3_step
   */
  int
  step();

  /**
   * @brief implicitly converts to sqlite3_stmt* to be used in SQLite C API
   */
  operator sqlite3_stmt*();

private:
  sqlite3_stmt* m_stmt;
};

} // namespace util
} // namespace ndn

#endif // NDN_UTIL_SQLITE3_STATEMENT_HPP
