summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/postgresHandler.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/postgresHandler.cpp b/src/postgresHandler.cpp
index 84776fe..4490dcc 100644
--- a/src/postgresHandler.cpp
+++ b/src/postgresHandler.cpp
@@ -1,6 +1,7 @@
#include "postgresHandler.h"
#include <iostream>
#include <regex>
+#include <stdexcept>
#define INT_INDEX 2
#define STRING_INDEX 3
@@ -22,22 +23,29 @@ void display_query_result(const pqxx::result &t_r) {
}
}
+static const unsigned int
+get_type_of_regex_iterator(std::sregex_iterator t_sregex_it) {
+ std::array<int, 4> types{INT_INDEX, STRING_INDEX, LIST_OF_INT_INDEX,
+ NULL_INDEX};
+ for (const int &type : types) {
+ if ((*t_sregex_it)[type] != "") {
+ return type;
+ }
+ }
+ throw std::invalid_argument("regex iterator input is invalid");
+}
+
void add_cards_to_database(const std::string &t_cards, pqxx::work &t_tx) {
// TODO: to complete
- std::cout << "adding cards..." << std::endl;
std::regex key_regex(
"\"[^\"?]+\":(([0-9]+)|(\"[^\"?]*\")|(\\[[0-9,]*\\])|(null))");
- // (*it)[x] type?
- // for x = 2: integers
- // 3: string
- // 4: list of ints
- // 5: null
-
auto words_begin =
std::sregex_iterator(t_cards.begin(), t_cards.end(), key_regex);
auto words_end = std::sregex_iterator();
+ std::string insert_query; // TODO: complete
for (auto it = words_begin; it != words_end; ++it) {
- std::cout << (*it)[INT_INDEX].str() << std::endl;
+ const unsigned int type_index = get_type_of_regex_iterator(it);
+ std::cout << (*it)[type_index].str() << std::endl;
}
}