~singpolyma/biboumi

2677ac42e8d2e1cf162fec773a9acb453bef8b9b — louiz’ 6 years ago dac19da
Fix compilation (many warnings, and a linkage error) with clang++
M src/database/count_query.hpp => src/database/count_query.hpp +2 -2
@@ 15,10 15,10 @@ struct CountQuery: public Query
      this->body += std::move(name);
    }

    std::size_t execute(sqlite3* db)
    int64_t execute(sqlite3* db)
    {
      auto statement = this->prepare(db);
      std::size_t res = 0;
      int64_t res = 0;
      if (sqlite3_step(statement.get()) == SQLITE_ROW)
        res = sqlite3_column_int64(statement.get(), 0);
      else

M src/database/database.hpp => src/database/database.hpp +1 -1
@@ 131,7 131,7 @@ class Database
  static void open(const std::string& filename);

  template <typename TableType>
  static std::size_t count(const TableType& table)
  static int64_t count(const TableType& table)
  {
    CountQuery query{table.get_name()};
    return query.execute(Database::db);

M src/database/insert_query.hpp => src/database/insert_query.hpp +3 -3
@@ 31,7 31,7 @@ actual_bind(Statement& statement, std::vector<std::string>&, const std::tuple<T.
  auto&& column = std::get<Id>(columns);
  if (column.value != 0)
    {
      if (sqlite3_bind_int64(statement.get(), N + 1, column.value) != SQLITE_OK)
      if (sqlite3_bind_int64(statement.get(), N + 1, static_cast<sqlite3_int64>(column.value)) != SQLITE_OK)
        log_error("Failed to bind ", column.value, " to id.");
    }
  else if (sqlite3_bind_null(statement.get(), N + 1) != SQLITE_OK)


@@ 110,9 110,9 @@ struct InsertQuery: public Query
  typename std::enable_if<N < sizeof...(T), void>::type
  insert_col_name(const std::tuple<T...>& columns)
  {
    auto value = std::get<N>(columns);
    using ColumnType = typename std::remove_reference<decltype(std::get<N>(columns))>::type;

    this->body += value.name;
    this->body += ColumnType::name;

    if (N < (sizeof...(T) - 1))
      this->body += ", ";

M src/database/row.hpp => src/database/row.hpp +1 -1
@@ 20,7 20,7 @@ update_id(std::tuple<T...>& columns, sqlite3* db)
  log_debug("Found an autoincrement col.");
  auto res = sqlite3_last_insert_rowid(db);
  log_debug("Value is now: ", res);
  column.value = res;
  column.value = static_cast<Id::real_type>(res);
}

template <std::size_t N, typename... T>

M src/database/select_query.hpp => src/database/select_query.hpp +3 -4
@@ 25,7 25,7 @@ extract_row_value(Statement& statement, const int i)
{
  const auto size = sqlite3_column_bytes(statement.get(), i);
  const unsigned char* str = sqlite3_column_text(statement.get(), i);
  std::string result(reinterpret_cast<const char*>(str), size);
  std::string result(reinterpret_cast<const char*>(str), static_cast<std::size_t>(size));
  return result;
}



@@ 62,10 62,9 @@ struct SelectQuery: public Query
    insert_col_name()
    {
      using ColumnsType = std::tuple<T...>;
      ColumnsType tuple{};
      auto value = std::get<N>(tuple);
      using ColumnType = typename std::remove_reference<decltype(std::get<N>(std::declval<ColumnsType>()))>::type;

      this->body += " "s + value.name;
      this->body += " "s + ColumnType::name;

      if (N < (sizeof...(T) - 1))
        this->body += ", ";

M src/database/type_to_sql.cpp => src/database/type_to_sql.cpp +1 -0
@@ 3,5 3,6 @@
template <> const std::string TypeToSQLType<int>::type = "INTEGER";
template <> const std::string TypeToSQLType<std::size_t>::type = "INTEGER";
template <> const std::string TypeToSQLType<long>::type = "INTEGER";
template <> const std::string TypeToSQLType<long long>::type = "INTEGER";
template <> const std::string TypeToSQLType<bool>::type = "INTEGER";
template <> const std::string TypeToSQLType<std::string>::type = "TEXT";

M src/database/type_to_sql.hpp => src/database/type_to_sql.hpp +7 -0
@@ 4,3 4,10 @@

template <typename T>
struct TypeToSQLType { static const std::string type; };

template <> const std::string TypeToSQLType<int>::type;
template <> const std::string TypeToSQLType<std::size_t>::type;
template <> const std::string TypeToSQLType<long>::type;
template <> const std::string TypeToSQLType<long long>::type;
template <> const std::string TypeToSQLType<bool>::type;
template <> const std::string TypeToSQLType<std::string>::type;
\ No newline at end of file