67 lines
1.2 KiB
C++
67 lines
1.2 KiB
C++
#include "matador/sql/convert.hpp"
|
|
|
|
#include <cstring>
|
|
|
|
namespace matador::sql {
|
|
|
|
void convert(std::string &dest, bool source)
|
|
{
|
|
dest = source ? "true" : "false";
|
|
}
|
|
|
|
void convert(std::string &dest, const char *source)
|
|
{
|
|
dest.assign(source);
|
|
}
|
|
|
|
long long to_long_long(const char *source)
|
|
{
|
|
if (strlen(source) == 0) {
|
|
return{};
|
|
}
|
|
char *end;
|
|
const auto result = strtoll(source, &end, 10);
|
|
if (end == nullptr) {
|
|
// Todo: check error
|
|
throw std::logic_error("couldn't convert value to number");
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
unsigned long long to_unsigned_long_long(const char *source)
|
|
{
|
|
if (strlen(source) == 0) {
|
|
return{};
|
|
}
|
|
char *end;
|
|
const auto result = strtoull(source, &end, 10);
|
|
if (end == nullptr) {
|
|
// Todo: check error
|
|
throw std::logic_error("couldn't convert value to number");
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
long double to_double(const char *source)
|
|
{
|
|
if (strlen(source) == 0) {
|
|
return{};
|
|
}
|
|
char *end;
|
|
const auto result = strtold(source, &end);
|
|
if (end == nullptr) {
|
|
// Todo: check error
|
|
throw std::logic_error("couldn't convert value to number");
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
void convert(utils::blob &dest, const utils::blob &data)
|
|
{
|
|
dest = data;
|
|
}
|
|
|
|
} |