18 #include "SQLamarr/TemporaryTable.h"
25 TemporaryTable::TemporaryTable (
27 const std::string& output_table,
28 const std::vector<std::string>& columns,
29 const std::vector<std::string>& select_statements,
32 : BaseSqlInterface (db)
33 , m_output_table (output_table)
35 , m_select_statements (select_statements)
36 , m_make_persistent (make_persistent)
39 for (
auto& column_name: m_columns)
46 TemporaryTable::TemporaryTable (
48 const std::string& output_table,
49 const std::vector<std::string>& columns,
50 const std::string& select_statement,
53 : BaseSqlInterface (db)
54 , m_output_table (output_table)
56 , m_select_statements ({select_statement})
57 , m_make_persistent (make_persistent)
60 for (
auto& column_name: m_columns)
67 std::string TemporaryTable::compose_create_query()
const
72 if (!m_make_persistent)
75 s <<
"TABLE IF NOT EXISTS "
76 << m_output_table <<
"(";
78 for (
auto c: m_columns)
79 s << c << (c != m_columns.back() ?
", ":
"");
89 std::string TemporaryTable::compose_delete_query()
const
92 s <<
"DELETE FROM " << m_output_table <<
";";
99 std::string TemporaryTable::compose_insert_query(
const std::string& st)
const
102 s <<
"INSERT INTO " << m_output_table <<
" (";
104 for (
auto c: m_columns)
105 s << c << (c != m_columns.back() ?
", ":
"");
116 void TemporaryTable::execute ()
120 sqlite3_stmt* create_output_table = get_statement(
121 "create_output_table", compose_create_query().c_str()
123 exec_stmt(create_output_table);
126 sqlite3_stmt* delete_output_table = get_statement(
127 "delete_output_table", compose_delete_query().c_str()
129 exec_stmt(delete_output_table);
134 for (
auto& stmt: m_select_statements)
136 sprintf(buffer,
"insert_in_output_table_%d", c++);
137 exec_stmt(get_statement(buffer, compose_insert_query(stmt).c_str()));
void validate_token(const std::string &token)
Ensure a token is alphanumeric.
std::unique_ptr< sqlite3, void(*)(sqlite3 *)> SQLite3DB
Unique pointer to the sqlite3 connection.