4#include "Stroika/Frameworks/StroikaPreComp.h"
10#include "Stroika/Foundation/Containers/Set.h"
15#include "DirectEmployeesDB.h"
22using namespace Stroika::Foundation::Database;
23using namespace Stroika::Foundation::Database::SQL;
25void Stroika::Samples::SQL::DirectEmployeesDB (
const std::function<
Connection::Ptr ()>& connectionFactory)
37 ORM::ProvisionForVersion (conn, kCurrentVersion_,
38 initializer_list<ORM::TableProvisioner>{
43 c.Exec (
"CREATE TABLE DEPARTMENT(ID INT PRIMARY KEY NOT NULL,"
44 "NAME CHAR (50) NOT NULL"
52 c.Exec (
"CREATE TABLE EMPLOYEES("
53 "ID INT PRIMARY KEY NOT NULL,"
78 Statement addDepartment = conn.
mkStatement (
"INSERT INTO DEPARTMENT (ID, NAME) values (:ID, :NAME);"sv);
79 addDepartment.
Execute (initializer_list<Statement::ParameterDescription>{
81 {
":NAME"sv,
"Washing machines"sv},
84 conn.
mkStatement (
"INSERT INTO EMPLOYEES (ID,NAME,AGE,ADDRESS,SALARY) values (:ID, :NAME, :AGE, :ADDRESS, :SALARY);"sv);
85 addEmployeeStatement.
Execute (initializer_list<Statement::ParameterDescription>{
87 {
":NAME"sv,
"Paul"sv},
89 {
":ADDRESS"sv,
"California"sv},
90 {
":SALARY"sv, 20000.00},
92 addEmployeeStatement.
Execute (initializer_list<Statement::ParameterDescription>{
94 {
":NAME"sv,
"Allen"sv},
96 {
":ADDRESS"sv,
"Texas"sv},
97 {
":SALARY"sv, 15000.00},
99 addEmployeeStatement.
Execute (initializer_list<Statement::ParameterDescription>{
101 {
":NAME",
"Teddy"sv},
103 {
":ADDRESS",
"Norway"sv},
104 {
":SALARY", 20000.00},
106 addEmployeeStatement.
Execute (initializer_list<Statement::ParameterDescription>{
110 {
":ADDRESS",
"Rich-Mond"sv},
111 {
":SALARY", 65000.00},
113 addEmployeeStatement.
Execute (initializer_list<Statement::ParameterDescription>{
115 {
":NAME",
"David"sv},
117 {
":ADDRESS",
"Texas"sv},
118 {
":SALARY", 85000.00},
120 addEmployeeStatement.
Execute (initializer_list<Statement::ParameterDescription>{
124 {
":ADDRESS",
"South-Hall"sv},
125 {
":SALARY", 45000.00},
127 addEmployeeStatement.
Execute (initializer_list<Statement::ParameterDescription>{
129 {
":NAME",
"James"sv},
131 {
":ADDRESS",
"Houston"sv},
132 {
":SALARY", 10000.00},
139 addEmployeeStatement.
Execute (initializer_list<Statement::ParameterDescription>{
140 {
":BAD-ARGUMENT", 7},
141 {
":NAME",
"James"sv},
143 {
":ADDRESS",
"Houston"sv},
144 {
":SALARY", 10000.00},
150 addEmployeeStatement.
Execute (initializer_list<Statement::ParameterDescription>{
152 {
":NAME",
"James"sv},
154 {
":ADDRESS",
"Houston"sv},
155 {
":SALARY", 10000.00},
160 cout <<
"Note good error message: {}"_f(current_exception ()) << endl;
168 Assert ((allNames ==
Set<String>{
"Paul",
"Allen",
"Kim",
"David",
"Mark",
"James",
"Teddy"}));
172 [[maybe_unused]]
double sumSalaryUsingSQL = sumAllSalaries.
GetAllRows (0)[0].As<
double> ();
174 [[maybe_unused]]
double sumSalaryUsingIterableApply =
176 Assert (Math::NearlyEquals (sumSalaryUsingSQL, sumSalaryUsingIterableApply));
#define AssertNotReached()
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
Simple variant-value (case variant union) object, with (variant) basic types analogous to a value in ...
nonvirtual Statement mkStatement(const String &sql)
nonvirtual void Execute()
nonvirtual Sequence< Row > GetAllRows()
call Reset (), and then GetAllRemainingRows () - which always starts current statement with current b...
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.