Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
Samples/SQL/Sources/Main.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Frameworks/StroikaPreComp.h"
5
6#include <cstdlib>
7
8#include "Stroika/Foundation/Database/SQL/ODBC.h"
12
13#include "ComputerNetwork.h"
14#include "DirectEmployeesDB.h"
15#include "ORMEmployeesDB.h"
16#include "ThreadTest.h"
17
18using namespace std;
19
20using namespace Stroika::Foundation;
21
22int main ([[maybe_unused]] int argc, [[maybe_unused]] const char* argv[])
23{
24 using namespace Stroika::Foundation::Database::SQL;
25
26 using namespace Stroika::Samples::SQL;
27
28 {
29#if qStroika_HasComponent_sqlite
30 auto connectionFactory = [=] () {
31 // Use InMemory DB
32 return SQLite::Connection::New (SQLite::Connection::Options{.fInMemoryDB = u"direct-employees-test"});
33 };
34 DirectEmployeesDB (connectionFactory);
35#endif
36 }
37
38 {
39#if qStroika_HasComponent_sqlite
40 auto dbPath = IO::FileSystem::WellKnownLocations::GetTemporary () / "direct-employees-test.db";
41 (void)std::filesystem::remove (dbPath);
42 auto connectionFactory = [=] () {
43 // Same DirectEmployeesDB test, but write to a file so you can explore DB from command-line
44 return SQLite::Connection::New (SQLite::Connection::Options{.fDBPath = dbPath});
45 };
46 DirectEmployeesDB (connectionFactory);
47#endif
48 }
49
50#if qStroika_HasComponent_ODBC
51 {
52 // Note - classes structured so you COULD use SQLite or ODBC transparently, but
53 // the ODBC layer NYI (as of 2021-08-08) so commented out...
54 // @todo change this sample so command-line arg grabs dsn from command-line
55 auto connectionFactory = [=] () { return ODBC::Connection::New (ODBC::Connection::Options{"some-dsn"}); };
56 // NYI - DirectEmployeesDB (connectionFactory);
57 }
58#endif
59
60 {
61#if qStroika_HasComponent_sqlite
62 auto dbPath = IO::FileSystem::WellKnownLocations::GetTemporary () / "threads-test.db";
63 (void)std::filesystem::remove (dbPath);
64 auto connectionFactory = [=] () {
65 // default to 1 second fBusyTimeout for these tests
66 auto conn = SQLite::Connection::New (SQLite::Connection::Options{.fDBPath = dbPath, .fBusyTimeout = 1s});
67 Assert (Math::NearlyEquals (conn.busyTimeout ().As<double> (), 1.0));
68 return conn;
69 };
70 ThreadTest (connectionFactory);
71#endif
72 }
73
74 {
75 // EmployeesDB test, but using C++ objects and ORM mapping layer (and threads)
76#if qStroika_HasComponent_sqlite
77 auto dbPath = IO::FileSystem::WellKnownLocations::GetTemporary () / "orm-employees-test.db";
78 (void)std::filesystem::remove (dbPath);
79 auto connectionFactory = [=] () {
80 // default to 1 second fBusyTimeout for these tests
81 auto conn = SQLite::Connection::New (SQLite::Connection::Options{.fDBPath = dbPath, .fBusyTimeout = 1s});
82 Assert (Math::NearlyEquals (conn.busyTimeout ().As<double> (), 1.0));
83 return conn;
84 };
85 ORMEmployeesDB (connectionFactory);
86#endif
87 }
88
89 {
90#if qStroika_HasComponent_sqlite
91 auto dbPath = IO::FileSystem::WellKnownLocations::GetTemporary () / "computer-network.db";
92 (void)std::filesystem::remove (dbPath);
93 auto connectionFactory = [=] () { return SQLite::Connection::New (SQLite::Connection::Options{.fDBPath = dbPath}); };
94 ComputerNetworksModel (connectionFactory);
95#endif
96 }
97
98 return EXIT_SUCCESS;
99}
STL namespace.