usql update

This commit is contained in:
2021-12-19 13:33:47 +01:00
parent 37d0d9b3f5
commit 5c925f2608
23 changed files with 1570 additions and 1124 deletions

View File

@@ -1,4 +1,6 @@
#include "fast_double_parser.h"
#include "settings.h"
#include "exception.h"
#include "ml_date.h"
@@ -9,21 +11,31 @@ std::vector<std::pair<std::string, std::string>> Settings::m_settings =
{ std::make_pair("DATE_FORMAT", "%Y-%m-%d %H:%M:%S"),
std::make_pair("BOOL_TRUE_LITERAL", "Y"),
std::make_pair("BOOL_FALSE_LITERAL", "N"),
std::make_pair("DOUBLE_FORMAT", "%.2f") };
std::make_pair("DOUBLE_FORMAT", "%.2f"),
std::make_pair("USE_INDEXSCAN", "N") };
long Settings::string_to_int(const std::string &intstr) {
return std::stoi(intstr);
long Settings::string_to_long(const std::string &intstr) {
try {
return std::stol(intstr);
} catch (std::invalid_argument &e) {
throw Exception("error parsing as integer: " + intstr);
}
}
std::string Settings::int_to_string(long intval) {
std::string Settings::long_to_string(long intval) {
return std::to_string(intval);
}
double Settings::string_to_double(const std::string &doublestr) {
return std::stod(doublestr); // TODO use fast parsing
double result;
const char * endptr = fast_double_parser::parse_number(doublestr.c_str(), &result);
if (endptr == nullptr) {
throw Exception("error parsing as double: " + doublestr);
}
return result;
}
std::string Settings::double_to_string(double d) {
@@ -47,23 +59,20 @@ std::string Settings::date_to_string(long date) {
}
bool Settings::string_to_bool(const std::string &boolstr) {
if (boolstr=="true" || boolstr == get_setting("BOOL_TRUE_LITERAL"))
bool Settings::string_to_bool(const std::string &value) {
if (value == "true" || value == get_setting("BOOL_TRUE_LITERAL"))
return true;
if (boolstr=="false" || boolstr == get_setting("BOOL_FALSE_LITERAL"))
if (value == "false" || value == get_setting("BOOL_FALSE_LITERAL"))
return false;
throw Exception("string_to_bool, unrecognized value: " + boolstr);
throw Exception("string_to_bool, unrecognized value: " + value);
}
std::string Settings::bool_to_string(bool boolval) {
return boolval ? "true" : "false";
std::string Settings::bool_to_string(bool value) {
return value ? "true" : "false";
}
std::string Settings::get_setting(const std::string &name) {
for(const auto& pair : m_settings) {
if (pair.first == name) return pair.second;
@@ -71,6 +80,10 @@ std::string Settings::get_setting(const std::string &name) {
throw Exception("unsupported setting name: " + name);
}
bool Settings::get_bool_setting(const std::string &name) {
return string_to_bool(get_setting(name));
}
void Settings::set_setting(const std::string &name, const std::string &value) {
for (auto it = begin(m_settings); it != end(m_settings); ++it) {
if (it->first == name) {