#include "cetlib/sqlite/ConnectionFactory.h"
#include "cetlib/sqlite/Exception.h"
#include "cetlib/sqlite/Ntuple.h"
#include "cetlib/sqlite/helpers.h"
#include "cetlib/sqlite/select.h"
#include "hep_concurrency/simultaneous_function_spawner.h"
#include "sqlite3.h"
#include <assert.h>
#include <cstring>
#include <functional>
#include <iostream>
#include <vector>
Go to the source code of this file.
int count_rows |
( |
void * |
p, |
|
|
int |
nrows, |
|
|
char ** |
results, |
|
|
char ** |
cnames |
|
) |
| |
Definition at line 62 of file ntuple_t.cc.
64 auto n =
static_cast<int*
>(
p);
66 assert(
strcmp(cnames[0],
"count(*)") == 0);
67 *
n = stoi(results[0]);
int strcmp(const String &s1, const String &s2)
unsigned nrows(sqlite3 *db, std::string const &tablename)
Definition at line 151 of file ntuple_t.cc.
152 const char*
fname{
"no_such_file.db"};
162 test_with_colliding_table<int, double>(*
c, {{
"y",
"txt"}});
163 test_with_colliding_table<int, double>(*
c, {{
"x",
"text"}});
164 test_with_colliding_table<int, int>(*
c, {{
"x",
"txt"}});
165 test_with_colliding_table<int, double, int>(*
c, {{
"x",
"txt",
"z"}});
166 test_with_colliding_table<int>(*
c, {{
"x"}});
177 std::cout <<
"Unknown exception caught\n";
void test_with_new_database(Connection &c)
void test_with_matching_table(Connection &c)
void test_column_constraint(Connection &c)
auto make_connection(std::string const &file_name, PolicyArgs &&...) -> Connection *
void test_file_create(ConnectionFactory &cf)
void test_parallel_filling_table(Connection &c)
void test_filling_table(Connection &c)
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
Definition at line 122 of file ntuple_t.cc.
124 cout <<
"start test_column_constraint\n";
130 cout <<
"end test_column_constraint\n";
bool hasTableWithSchema(sqlite3 *db, std::string const &tablename, std::string expectedSchema)
std::string create_table_ddl(std::string const &tablename, Cols const &...cols)
Definition at line 134 of file ntuple_t.cc.
141 for (std::size_t i = 0; i < 103; ++i) {
142 table.insert(i, 0.5 * i, i * i);
146 cnt <<
select(
"count(*)").from(*
c,
"tab1");
T unique_value(query_result< T > const &r)
auto make_connection(std::string const &file_name, PolicyArgs &&...) -> Connection *
auto select(T const &...t)
Definition at line 72 of file ntuple_t.cc.
74 cout <<
"start test_filling_table\n";
76 constexpr
int nrows{903};
79 for (
int i = 0; i <
nrows; ++i) {
80 nt.insert(i, 1.5 * i);
84 nmatches <<
select(
"count(*)").from(c,
"zz");
87 cout <<
"end test_filling_table\n";
T unique_value(query_result< T > const &r)
auto select(T const &...t)
unsigned nrows(sqlite3 *db, std::string const &tablename)
void test_parallel_filling_table |
( |
Connection & |
c | ) |
|
Definition at line 91 of file ntuple_t.cc.
93 cout <<
"start test_parallel_filling_table\n";
95 constexpr
int nrows_per_thread{100};
96 constexpr
unsigned nthreads{10};
97 string const tablename{
"zz"};
104 std::vector<std::function<void()>> tasks;
105 for (
unsigned i{}; i < nthreads; ++i) {
106 tasks.emplace_back([i, &nt] {
107 for (
unsigned j{}; j < nrows_per_thread; ++j) {
108 auto const j1 = j + i * 100;
109 nt.insert(j1, 1.5 * j1);
113 hep::concurrency::simultaneous_function_spawner sfs{tasks};
116 nmatches <<
select(
"count(*)").from(c, tablename);
117 assert(
unique_value(nmatches) == nrows_per_thread * nthreads);
118 cout <<
"end test_parallel_filling_table\n";
T unique_value(query_result< T > const &r)
auto select(T const &...t)
template<class... ARGS>
void test_with_colliding_table |
( |
Connection & |
c, |
|
|
array< string, sizeof...(ARGS)> const & |
names |
|
) |
| |
Definition at line 44 of file ntuple_t.cc.
47 cout <<
"start test_with_colliding_table\n";
50 Ntuple<ARGS...> xx{
c,
"xx", names};
51 assert(
"Failed throw for mismatched table" ==
nullptr);
56 assert(
"Threw wrong exception for mismatched table" ==
nullptr);
58 cout <<
"end test_with_colliding_table\n";
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition at line 34 of file ntuple_t.cc.
36 cout <<
"start test_with_matching_table\n";
39 std::cout <<
"end test_with_matching_table\n";
Definition at line 25 of file ntuple_t.cc.
27 cout <<
"start test_with_new_database\n";
30 std::cout <<
"end test_with_new_database\n";