summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2017-06-14 10:31:45 +0200
committerlouiz’ <louiz@louiz.org>2017-06-14 10:46:44 +0200
commit2677ac42e8d2e1cf162fec773a9acb453bef8b9b (patch)
tree4b51bece4f4dec660e0c48297404a5da51aee4ec
parentdac19da4c791a6c16cde09e61841fd7f6b6268d2 (diff)
downloadbiboumi-2677ac42e8d2e1cf162fec773a9acb453bef8b9b.tar.gz
biboumi-2677ac42e8d2e1cf162fec773a9acb453bef8b9b.tar.bz2
biboumi-2677ac42e8d2e1cf162fec773a9acb453bef8b9b.tar.xz
biboumi-2677ac42e8d2e1cf162fec773a9acb453bef8b9b.zip
Fix compilation (many warnings, and a linkage error) with clang++
-rw-r--r--src/database/count_query.hpp4
-rw-r--r--src/database/database.hpp2
-rw-r--r--src/database/insert_query.hpp6
-rw-r--r--src/database/row.hpp2
-rw-r--r--src/database/select_query.hpp7
-rw-r--r--src/database/type_to_sql.cpp1
-rw-r--r--src/database/type_to_sql.hpp7
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 <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);
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<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 += ", ";
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<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>
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<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 += ", ";
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<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";
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 <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