root/software/sqlite_poc/main.cc @ 3599f0a5
| 6e4119a4 | David Sorber | #include <iomanip>
|
||
| 88cf406f | David Sorber | #include <iostream>
|
||
#include <tuple>
|
||||
#include "DBManager.h"
|
||||
| 6e4119a4 | David Sorber | // helper function to print a tuple of any size
|
||
template<class Tuple, std::size_t N>
|
||||
struct TuplePrinter {
|
||||
static void print(const Tuple& t)
|
||||
{
|
||||
TuplePrinter<Tuple, N-1>::print(t);
|
||||
std::cout << ", " << std::get<N-1>(t);
|
||||
}
|
||||
};
|
||||
template<class Tuple>
|
||||
struct TuplePrinter<Tuple, 1> {
|
||||
static void print(const Tuple& t)
|
||||
{
|
||||
std::cout << std::get<0>(t);
|
||||
}
|
||||
};
|
||||
template<class... Args>
|
||||
void print(const std::tuple<Args...>& t)
|
||||
{
|
||||
std::cout << "(";
|
||||
TuplePrinter<decltype(t), sizeof...(Args)>::print(t);
|
||||
std::cout << ")\n";
|
||||
}
|
||||
| 88cf406f | David Sorber | int main(int argc, char** argv)
|
||
{
|
||||
std::cout << "SQLite Proof of Concept Exerciser" << std::endl;
|
||||
| 6e4119a4 | David Sorber | // Make a DBManager instance which will connect to our test DB automagically
|
||
| 88cf406f | David Sorber | DBManager db_mgr("database.db");
|
||
| 6e4119a4 | David Sorber | // Make a query
|
||
| 143a60e7 | David Sorber | std::string query("SELECT Number, Words, Float FROM sample;");
|
||
| 88cf406f | David Sorber | |||
| 6e4119a4 | David Sorber | // Execute the query making sure the template params match up with the
|
||
// query params
|
||||
int rc = 0;
|
||||
| 143a60e7 | David Sorber | auto results = db_mgr.execute_query<int64_t, std::string, double>(query, rc);
|
||
| 88cf406f | David Sorber | std::cout << "Return code: " << rc << std::endl;
|
||
| 6e4119a4 | David Sorber | // If we returned successfully, print out the result rows
|
||
if (! rc)
|
||||
{
|
||||
uint32_t row_index = 0;
|
||||
for (auto row : *results)
|
||||
{
|
||||
std::cout << "Row: " << std::setw(4) << row_index << " - ";
|
||||
print(*row);
|
||||
++row_index;
|
||||
| 30f264c2 | David Sorber | delete row;
|
||
| 6e4119a4 | David Sorber | }
|
||
| 30f264c2 | David Sorber | |||
delete results;
|
||||
| 6e4119a4 | David Sorber | }
|
||
| 88cf406f | David Sorber | return 0;
|
||
}
|