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] &&
226 boost::optional<std::int32_t> ig;
227 boost::optional<std::uint32_t> uig;
228 boost::optional<std::int64_t> big;
229 boost::optional<std::uint64_t> ubig;
230 s <<
"SELECT I, UI, BI, UBI from STT;", soci::into(ig),
231 soci::into(uig), soci::into(big), soci::into(ubig);
233 *ig ==
id[0] && *uig == uid[0] && *big == bid[0] &&
252 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
257 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
271 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (r);
276 BEAST_EXPECT(ig ==
id[0] && uig == uid[0] && big == bid[0] &&
289 s <<
"SELECT I, UI, BI, UBI from STT", soci::into (d);
290 BEAST_EXPECT(get<0>(d) ==
id[0] && get<1>(d) == uid[0] &&
291 get<2>(d) == bid[0] && get<3>(d) == ubid[0]);
300 namespace bfs = boost::filesystem;
303 if (bfs::is_regular_file(dbPath))
310 testcase(
"deleteWithSubselect");
317 const char* dbInit[] = {
318 "BEGIN TRANSACTION;",
319 "CREATE TABLE Ledgers ( \
320 LedgerHash CHARACTER(64) PRIMARY KEY, \
321 LedgerSeq BIGINT UNSIGNED \
323 "CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);"};
324 for (
auto const c : dbInit)
330 int const numRows = 16;
334 ledgerIndexes.
reserve(numRows);
335 for (
int i = 0; i < numRows; ++i)
338 if (lh[toIncIndex] ==
'z')
343 s <<
"INSERT INTO Ledgers (LedgerHash, LedgerSeq) VALUES "
345 soci::use(ledgerHashes), soci::use(ledgerIndexes);
348 s <<
"SELECT LedgerSeq FROM Ledgers;", soci::into(ledgersLS);
349 BEAST_EXPECT(ledgersLS.
size() == numRows);
351 namespace bfs = boost::filesystem;
354 if (bfs::is_regular_file(dbPath))