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

This commit is contained in:
louiz’
2017-06-14 10:46:44 +02:00
parent dac19da4c7
commit 2677ac42e8
7 changed files with 18 additions and 11 deletions
+2 -2
View File
@@ -15,10 +15,10 @@ struct CountQuery: public Query
this->body += std::move(name); this->body += std::move(name);
} }
std::size_t execute(sqlite3* db) int64_t execute(sqlite3* db)
{ {
auto statement = this->prepare(db); auto statement = this->prepare(db);
std::size_t res = 0; int64_t res = 0;
if (sqlite3_step(statement.get()) == SQLITE_ROW) if (sqlite3_step(statement.get()) == SQLITE_ROW)
res = sqlite3_column_int64(statement.get(), 0); res = sqlite3_column_int64(statement.get(), 0);
else else
+1 -1
View File
@@ -131,7 +131,7 @@ class Database
static void open(const std::string& filename); static void open(const std::string& filename);
template <typename TableType> template <typename TableType>
static std::size_t count(const TableType& table) static int64_t count(const TableType& table)
{ {
CountQuery query{table.get_name()}; CountQuery query{table.get_name()};
return query.execute(Database::db); return query.execute(Database::db);
+3 -3
View File
@@ -31,7 +31,7 @@ actual_bind(Statement& statement, std::vector<std::string>&, const std::tuple<T.
auto&& column = std::get<Id>(columns); auto&& column = std::get<Id>(columns);
if (column.value != 0) 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."); log_error("Failed to bind ", column.value, " to id.");
} }
else if (sqlite3_bind_null(statement.get(), N + 1) != SQLITE_OK) 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 typename std::enable_if<N < sizeof...(T), void>::type
insert_col_name(const std::tuple<T...>& columns) 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)) if (N < (sizeof...(T) - 1))
this->body += ", "; this->body += ", ";
+1 -1
View File
@@ -20,7 +20,7 @@ update_id(std::tuple<T...>& columns, sqlite3* db)
log_debug("Found an autoincrement col."); log_debug("Found an autoincrement col.");
auto res = sqlite3_last_insert_rowid(db); auto res = sqlite3_last_insert_rowid(db);
log_debug("Value is now: ", res); log_debug("Value is now: ", res);
column.value = res; column.value = static_cast<Id::real_type>(res);
} }
template <std::size_t N, typename... T> template <std::size_t N, typename... T>
+3 -4
View File
@@ -25,7 +25,7 @@ extract_row_value(Statement& statement, const int i)
{ {
const auto size = sqlite3_column_bytes(statement.get(), i); const auto size = sqlite3_column_bytes(statement.get(), i);
const unsigned char* str = sqlite3_column_text(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; return result;
} }
@@ -62,10 +62,9 @@ struct SelectQuery: public Query
insert_col_name() insert_col_name()
{ {
using ColumnsType = std::tuple<T...>; using ColumnsType = std::tuple<T...>;
ColumnsType tuple{}; using ColumnType = typename std::remove_reference<decltype(std::get<N>(std::declval<ColumnsType>()))>::type;
auto value = std::get<N>(tuple);
this->body += " "s + value.name; this->body += " "s + ColumnType::name;
if (N < (sizeof...(T) - 1)) if (N < (sizeof...(T) - 1))
this->body += ", "; this->body += ", ";
+1
View File
@@ -3,5 +3,6 @@
template <> const std::string TypeToSQLType<int>::type = "INTEGER"; template <> const std::string TypeToSQLType<int>::type = "INTEGER";
template <> const std::string TypeToSQLType<std::size_t>::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>::type = "INTEGER";
template <> const std::string TypeToSQLType<long long>::type = "INTEGER";
template <> const std::string TypeToSQLType<bool>::type = "INTEGER"; template <> const std::string TypeToSQLType<bool>::type = "INTEGER";
template <> const std::string TypeToSQLType<std::string>::type = "TEXT"; template <> const std::string TypeToSQLType<std::string>::type = "TEXT";
+7
View File
@@ -4,3 +4,10 @@
template <typename T> template <typename T>
struct TypeToSQLType { static const std::string type; }; 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;