21 #include <ripple/core/ConfigSections.h>
22 #include <ripple/core/SociDB.h>
23 #include <ripple/basics/contract.h>
24 #include <test/jtx/TestSuite.h>
25 #include <ripple/basics/BasicConfig.h>
26 #include <boost/filesystem.hpp>
27 #include <boost/algorithm/string.hpp>
34 boost::filesystem::path
const& dbPath)
36 config.
overwrite (
"sqdb",
"backend",
"sqlite");
37 auto value = dbPath.string ();
39 config.
legacy (
"database_path", value);
44 using namespace boost::filesystem;
45 if (!exists (dbPath) || !is_directory (dbPath) || !is_empty (dbPath))
52 using namespace boost::filesystem;
55 create_directory (dbPath);
59 if (!is_directory (dbPath))
62 Throw<std::runtime_error> (
63 "Cannot create directory: " + dbPath.string ());
68 return boost::filesystem::current_path () /
"socidb_test_databases";
95 testcase (
"sqliteFileNames");
99 {{
"peerfinder",
".sqlite"},
102 {
"validators",
".sqlite"}});
104 for (
auto const& i : d)
108 i.first + i.second));
118 {
"String1",
"String2",
"String3"});
120 auto checkValues = [
this, &stringData, &intData](soci::session& s)
125 s <<
"SELECT StringData, IntData FROM SociTestTable;",
126 soci::into (stringResult), soci::into (intResult);
127 BEAST_EXPECT(stringResult.
size () == stringData.
size () &&
128 intResult.
size () == intData.size ());
129 for (
int i = 0; i < stringResult.
size (); ++i)
137 std::find (intData.begin (), intData.end (), intResult[i]));
138 BEAST_EXPECT(si == ii && si < stringResult.
size ());
145 s <<
"CREATE TABLE IF NOT EXISTS SociTestTable ("
146 " Key INTEGER PRIMARY KEY,"
151 s <<
"INSERT INTO SociTestTable (StringData, IntData) VALUES "
152 "(:stringData, :intData);",
153 soci::use (stringData), soci::use (intData);
163 namespace bfs = boost::filesystem;
166 if (bfs::is_regular_file (dbPath))
167 bfs::remove (dbPath);
188 s <<
"DROP TABLE IF EXISTS STT;";
190 s <<
"CREATE TABLE STT ("
192 " UI INTEGER UNSIGNED,"
194 " UBI BIGINT UNSIGNED"
197 s <<
"INSERT INTO STT (I, UI, BI, UBI) VALUES "
198 "(:id, :idu, :bid, :bidu);",
199 soci::use (
id), soci::use (uid), soci::use (bid),
208 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into (ig),
209 soci::into (uig), soci::into (big), soci::into (ubig);
210 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
219 boost::optional<std::int32_t> ig;
220 boost::optional<std::uint32_t> uig;
221 boost::optional<std::int64_t> big;
222 boost::optional<std::uint64_t> ubig;
223 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into (ig),
224 soci::into (uig), soci::into (big), soci::into (ubig);
225 BEAST_EXPECT(*ig ==
id[0] && *uig == uid[0] && *big == bid[0] &&
243 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
248 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
262 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
267 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
280 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (d);
281 BEAST_EXPECT(get<0>(d) ==
id[0] && get<1>(d) == uid[0] &&
282 get<2>(d) == bid[0] && get<3>(d) == ubid[0]);
291 namespace bfs = boost::filesystem;
294 if (bfs::is_regular_file (dbPath))
295 bfs::remove (dbPath);
300 testcase (
"deleteWithSubselect");
307 const char* dbInit[] = {
308 "BEGIN TRANSACTION;",
309 "CREATE TABLE Ledgers ( \
310 LedgerHash CHARACTER(64) PRIMARY KEY, \
311 LedgerSeq BIGINT UNSIGNED \
313 "CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);"};
314 int dbInitCount =
std::extent<decltype(dbInit)>::value;
315 for (
int i = 0; i < dbInitCount; ++i)
320 memset (lh,
'a', 64);
323 int const numRows = 16;
327 ledgerIndexes.
reserve(numRows);
328 for (
int i = 0; i < numRows; ++i)
331 if (lh[toIncIndex] ==
'z')
336 s <<
"INSERT INTO Ledgers (LedgerHash, LedgerSeq) VALUES "
338 soci::use (ledgerHashes), soci::use (ledgerIndexes);
341 s <<
"SELECT LedgerSeq FROM Ledgers;", soci::into (ledgersLS);
342 BEAST_EXPECT(ledgersLS.
size () == numRows);
344 namespace bfs = boost::filesystem;
347 if (bfs::is_regular_file (dbPath))
348 bfs::remove (dbPath);