Commit 2677ac42 authored by louiz’'s avatar louiz’

Fix compilation (many warnings, and a linkage error) with clang++

parent dac19da4
......@@ -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
......
......@@ -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);
......
......@@ -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 += ", ";
......
......@@ -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>
......
......@@ -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 += ", ";
......
......@@ -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";
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment