20 #include <ripple/basics/BasicConfig.h>
21 #include <ripple/basics/contract.h>
22 #include <ripple/core/ConfigSections.h>
23 #include <ripple/core/SociDB.h>
24 #include <boost/algorithm/string.hpp>
25 #include <boost/filesystem.hpp>
26 #include <test/jtx/TestSuite.h>
35 boost::filesystem::path
const& dbPath)
37 config.
overwrite(
"sqdb",
"backend",
"sqlite");
38 auto value = dbPath.string();
40 config.
legacy(
"database_path", value);
46 using namespace boost::filesystem;
47 if (!exists(dbPath) || !is_directory(dbPath) || !is_empty(dbPath))
55 using namespace boost::filesystem;
58 create_directory(dbPath);
62 if (!is_directory(dbPath))
65 Throw<std::runtime_error>(
66 "Cannot create directory: " + dbPath.string());
69 static boost::filesystem::path
72 return boost::filesystem::current_path() /
"socidb_test_databases";
100 testcase(
"sqliteFileNames");
104 {{
"peerfinder",
".sqlite"},
107 {
"validators",
".sqlite"}});
109 for (
auto const& i : d)
124 {
"String1",
"String2",
"String3"});
126 auto checkValues = [
this, &stringData, &intData](soci::session& s) {
130 s <<
"SELECT StringData, IntData FROM SociTestTable;",
131 soci::into(stringResult), soci::into(intResult);
133 stringResult.
size() == stringData.
size() &&
134 intResult.
size() == intData.size());
135 for (
int i = 0; i < stringResult.
size(); ++i)
140 stringData.begin(), stringData.end(), stringResult[i]));
143 std::find(intData.begin(), intData.end(), intResult[i]));
144 BEAST_EXPECT(si == ii && si < stringResult.
size());
151 s <<
"CREATE TABLE IF NOT EXISTS SociTestTable ("
152 " Key INTEGER PRIMARY KEY,"
157 s <<
"INSERT INTO SociTestTable (StringData, IntData) VALUES "
158 "(:stringData, :intData);",
159 soci::use(stringData), soci::use(intData);
169 namespace bfs = boost::filesystem;
172 if (bfs::is_regular_file(dbPath))
195 s <<
"DROP TABLE IF EXISTS STT;";
197 s <<
"CREATE TABLE STT ("
199 " UI INTEGER UNSIGNED,"
201 " UBI BIGINT UNSIGNED"
204 s <<
"INSERT INTO STT (I, UI, BI, UBI) VALUES "
205 "(:id, :idu, :bid, :bidu);",
206 soci::use(
id), soci::use(uid), soci::use(bid), soci::use(ubid);
214 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into(ig),
215 soci::into(uig), soci::into(big), soci::into(ubig);
217 ig ==
id[0] && uig == uid[0] && big == bid[0] &&
228 boost::optional<std::int32_t> ig;
232 boost::optional<std::int64_t> big;
233 boost::optional<std::uint64_t> ubig;
234 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into(ig),
235 soci::into(uig), soci::into(big), soci::into(ubig);
237 *ig ==
id[0] && uig == uid[0] && *big == bid[0] &&
256 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
261 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
275 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
280 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
293 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (d);
294 BEAST_EXPECT(get<0>(d) ==
id[0] && get<1>(d) == uid[0] &&
295 get<2>(d) == bid[0] && get<3>(d) == ubid[0]);
304 namespace bfs = boost::filesystem;
307 if (bfs::is_regular_file(dbPath))
314 testcase(
"deleteWithSubselect");
321 const char* dbInit[] = {
322 "BEGIN TRANSACTION;",
323 "CREATE TABLE Ledgers ( \
324 LedgerHash CHARACTER(64) PRIMARY KEY, \
325 LedgerSeq BIGINT UNSIGNED \
327 "CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);"};
328 for (
auto const c : dbInit)
334 int const numRows = 16;
338 ledgerIndexes.
reserve(numRows);
339 for (
int i = 0; i < numRows; ++i)
342 if (lh[toIncIndex] ==
'z')
347 s <<
"INSERT INTO Ledgers (LedgerHash, LedgerSeq) VALUES "
349 soci::use(ledgerHashes), soci::use(ledgerIndexes);
352 s <<
"SELECT LedgerSeq FROM Ledgers;", soci::into(ledgersLS);
353 BEAST_EXPECT(ledgersLS.
size() == numRows);
355 namespace bfs = boost::filesystem;
358 if (bfs::is_regular_file(dbPath))