diff --git a/src/all_logs_vtab.hh b/src/all_logs_vtab.hh index 43ce3dd5..d675ede2 100644 --- a/src/all_logs_vtab.hh +++ b/src/all_logs_vtab.hh @@ -45,7 +45,7 @@ public: void get_columns(std::vector &cols) const { cols.emplace_back(this->alv_value_name.get()); cols.emplace_back(this->alv_msg_name.get()); - cols.emplace_back(this->alv_schema_name.get(), SQLITE3_TEXT, nullptr, true); + cols.emplace_back(this->alv_schema_name.get(), SQLITE3_TEXT, "", true); }; void extract(std::shared_ptr lf, diff --git a/src/log_data_table.hh b/src/log_data_table.hh index 6701e60b..a3839ce5 100644 --- a/src/log_data_table.hh +++ b/src/log_data_table.hh @@ -89,7 +89,7 @@ public: dp.parse(); - cols.emplace_back("log_msg_instance", SQLITE_INTEGER, nullptr); + cols.emplace_back("log_msg_instance", SQLITE_INTEGER); for (auto pair_iter = dp.dp_pairs.begin(); pair_iter != dp.dp_pairs.end(); ++pair_iter) { @@ -97,7 +97,7 @@ public: pair_iter->e_sub_elements->front()); std::string colname = cn.add_column(key_str); int sql_type = SQLITE3_TEXT; - const char *collator = NULL; + std::string collator; switch (pair_iter->e_sub_elements->back().value_token()) { case DT_IPV4_ADDRESS: diff --git a/src/log_format.cc b/src/log_format.cc index 0ec22d4e..89548d12 100644 --- a/src/log_format.cc +++ b/src/log_format.cc @@ -1487,7 +1487,7 @@ void external_log_format::build(std::vector &errors) { stable_sort(this->elf_level_pairs.begin(), this->elf_level_pairs.end()); - for (auto vd : this->elf_value_def_order) { + for (auto &vd : this->elf_value_def_order) { std::vector::iterator act_iter; if (!vd->vd_internal && @@ -1874,7 +1874,7 @@ public: cols[vd->vd_column].vc_name = vd->vd_name.get(); cols[vd->vd_column].vc_type = type_pair.first; cols[vd->vd_column].vc_subtype = type_pair.second; - cols[vd->vd_column].vc_collator = vd->vd_collate.c_str(); + cols[vd->vd_column].vc_collator = vd->vd_collate; cols[vd->vd_column].vc_comment = vd->vd_description; } }; diff --git a/src/log_format_impls.cc b/src/log_format_impls.cc index eb3afbdc..bf7ab1a4 100644 --- a/src/log_format_impls.cc +++ b/src/log_format_impls.cc @@ -355,20 +355,19 @@ public: const intern_string_t fd_name; logline_value::kind_t fd_kind; bool fd_identifier; - const char *fd_collator; + std::string fd_collator; int fd_numeric_index; field_def(const intern_string_t name) : fd_name(name), fd_kind(logline_value::VALUE_TEXT), fd_identifier(false), - fd_collator(nullptr), fd_numeric_index(-1) { }; field_def &with_kind(logline_value::kind_t kind, bool identifier = false, - const char *collator = nullptr) { + const std::string &collator = "") { this->fd_kind = kind; this->fd_identifier = identifier; this->fd_collator = collator; diff --git a/src/log_search_table.hh b/src/log_search_table.hh index 2d5730b3..5e013317 100644 --- a/src/log_search_table.hh +++ b/src/log_search_table.hh @@ -62,7 +62,7 @@ public: cols.emplace_back(LOG_MSG_INSTANCE, SQLITE_INTEGER); for (int lpc = 0; lpc < this->lst_regex.get_capture_count(); lpc++) { std::vector::const_iterator iter; - const char *collator = NULL; + std::string collator; std::string cap_re, colname; int sqlite_type = SQLITE3_TEXT; @@ -70,7 +70,7 @@ public: iter = this->lst_regex.cap_begin() + lpc; cap_re = this->lst_regex_string.substr(iter->c_begin, iter->length()); - sqlite_type = guess_type_from_pcre(cap_re, &collator); + sqlite_type = guess_type_from_pcre(cap_re, collator); switch (sqlite_type) { case SQLITE_FLOAT: this->lst_column_types.push_back( @@ -87,7 +87,7 @@ public: } } colname = cn.add_column(this->lst_regex.name_for_capture(lpc)); - cols.push_back(vtab_column(colname, sqlite_type, collator)); + cols.emplace_back(colname, sqlite_type, collator); } }; diff --git a/src/log_vtab_impl.cc b/src/log_vtab_impl.cc index 6aa090de..e01d8983 100644 --- a/src/log_vtab_impl.cc +++ b/src/log_vtab_impl.cc @@ -114,9 +114,8 @@ std::string log_vtab_impl::get_table_statement() colname.in(), type_to_string(iter->vc_type), iter->vc_hidden ? "hidden" : "", - (iter->vc_collator == NULL || - iter->vc_collator[0] == '\0') ? - "BINARY" : iter->vc_collator, + iter->vc_collator.empty() ? + "BINARY" : iter->vc_collator.c_str(), comment.c_str()); oss << coldecl; } diff --git a/src/log_vtab_impl.hh b/src/log_vtab_impl.hh index bfe4d7c0..500d3ae4 100644 --- a/src/log_vtab_impl.hh +++ b/src/log_vtab_impl.hh @@ -76,7 +76,7 @@ public: struct vtab_column { vtab_column(const std::string name = "", int type = SQLITE3_TEXT, - const char *collator = NULL, + const std::string collator = "", bool hidden = false, const std::string comment = "", unsigned int subtype = 0) @@ -90,7 +90,7 @@ public: std::string vc_name; int vc_type; - const char *vc_collator; + std::string vc_collator; bool vc_hidden; std::string vc_comment; int vc_subtype; diff --git a/src/sql_util.cc b/src/sql_util.cc index ddb9ab04..db2abdda 100644 --- a/src/sql_util.cc +++ b/src/sql_util.cc @@ -795,22 +795,22 @@ static struct { const char *collator; const char *sample; } TYPE_TEST_VALUE[] = { - { SQLITE3_TEXT, NULL, "foobar" }, - { SQLITE_INTEGER, NULL, "123" }, - { SQLITE_FLOAT, NULL, "123.0" }, + { SQLITE3_TEXT, "", "foobar" }, + { SQLITE_INTEGER, "", "123" }, + { SQLITE_FLOAT, "", "123.0" }, { SQLITE_TEXT, "ipaddress", "127.0.0.1" }, { SQLITE_NULL } }; -int guess_type_from_pcre(const string &pattern, const char **collator) +int guess_type_from_pcre(const string &pattern, std::string &collator) { try { pcrepp re(pattern.c_str()); vector matches; int retval = SQLITE3_TEXT; - *collator = NULL; + collator.clear(); for (int lpc = 0; TYPE_TEST_VALUE[lpc].sqlite_type != SQLITE_NULL; lpc++) { pcre_context_static<30> pc; pcre_input pi(TYPE_TEST_VALUE[lpc].sample); @@ -823,7 +823,7 @@ int guess_type_from_pcre(const string &pattern, const char **collator) if (matches.size() == 1) { retval = TYPE_TEST_VALUE[matches.front()].sqlite_type; - *collator = TYPE_TEST_VALUE[matches.front()].collator; + collator = TYPE_TEST_VALUE[matches.front()].collator; } return retval; diff --git a/src/sql_util.hh b/src/sql_util.hh index 39280609..7cd7aba8 100644 --- a/src/sql_util.hh +++ b/src/sql_util.hh @@ -99,7 +99,7 @@ void sql_execute_script(sqlite3 *db, const char *script, std::vector &errors); -int guess_type_from_pcre(const std::string &pattern, const char **collator); +int guess_type_from_pcre(const std::string &pattern, std::string &collator); /* XXX figure out how to do this with the template */ void sqlite_close_wrapper(void *mem);