From 2677ac42e8d2e1cf162fec773a9acb453bef8b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 14 Jun 2017 10:31:45 +0200 Subject: Fix compilation (many warnings, and a linkage error) with clang++ --- src/database/count_query.hpp | 4 ++-- src/database/database.hpp | 2 +- src/database/insert_query.hpp | 6 +++--- src/database/row.hpp | 2 +- src/database/select_query.hpp | 7 +++---- src/database/type_to_sql.cpp | 1 + src/database/type_to_sql.hpp | 7 +++++++ 7 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/database/count_query.hpp b/src/database/count_query.hpp index 322ad1b..b7bbf51 100644 --- a/src/database/count_query.hpp +++ b/src/database/count_query.hpp @@ -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 diff --git a/src/database/database.hpp b/src/database/database.hpp index 3a99867..1ad62fc 100644 --- a/src/database/database.hpp +++ b/src/database/database.hpp @@ -131,7 +131,7 @@ class Database static void open(const std::string& filename); template - 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); diff --git a/src/database/insert_query.hpp b/src/database/insert_query.hpp index 1712916..4965fc0 100644 --- a/src/database/insert_query.hpp +++ b/src/database/insert_query.hpp @@ -31,7 +31,7 @@ actual_bind(Statement& statement, std::vector&, const std::tuple(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(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::type insert_col_name(const std::tuple& columns) { - auto value = std::get(columns); + using ColumnType = typename std::remove_reference(columns))>::type; - this->body += value.name; + this->body += ColumnType::name; if (N < (sizeof...(T) - 1)) this->body += ", "; diff --git a/src/database/row.hpp b/src/database/row.hpp index ca686c1..b6887cb 100644 --- a/src/database/row.hpp +++ b/src/database/row.hpp @@ -20,7 +20,7 @@ update_id(std::tuple& 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(res); } template diff --git a/src/database/select_query.hpp b/src/database/select_query.hpp index 80d1424..d0c1d59 100644 --- a/src/database/select_query.hpp +++ b/src/database/select_query.hpp @@ -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(str), size); + std::string result(reinterpret_cast(str), static_cast(size)); return result; } @@ -62,10 +62,9 @@ struct SelectQuery: public Query insert_col_name() { using ColumnsType = std::tuple; - ColumnsType tuple{}; - auto value = std::get(tuple); + using ColumnType = typename std::remove_reference(std::declval()))>::type; - this->body += " "s + value.name; + this->body += " "s + ColumnType::name; if (N < (sizeof...(T) - 1)) this->body += ", "; diff --git a/src/database/type_to_sql.cpp b/src/database/type_to_sql.cpp index 5de012e..0b26185 100644 --- a/src/database/type_to_sql.cpp +++ b/src/database/type_to_sql.cpp @@ -3,5 +3,6 @@ template <> const std::string TypeToSQLType::type = "INTEGER"; template <> const std::string TypeToSQLType::type = "INTEGER"; template <> const std::string TypeToSQLType::type = "INTEGER"; +template <> const std::string TypeToSQLType::type = "INTEGER"; template <> const std::string TypeToSQLType::type = "INTEGER"; template <> const std::string TypeToSQLType::type = "TEXT"; diff --git a/src/database/type_to_sql.hpp b/src/database/type_to_sql.hpp index 5ae03ad..1942268 100644 --- a/src/database/type_to_sql.hpp +++ b/src/database/type_to_sql.hpp @@ -4,3 +4,10 @@ template struct TypeToSQLType { static const std::string type; }; + +template <> const std::string TypeToSQLType::type; +template <> const std::string TypeToSQLType::type; +template <> const std::string TypeToSQLType::type; +template <> const std::string TypeToSQLType::type; +template <> const std::string TypeToSQLType::type; +template <> const std::string TypeToSQLType::type; \ No newline at end of file -- cgit v1.2.3