UrlTagFixtureClass()
        : SqliteTestFixtureClass(t4p::ResourceSqlSchemaAsset())
        , Finder(DetectorTagSession)
        , SourceDirs()
        , SourceId(0) {
        DetectorTagSession.open(*soci::factory_sqlite3(), ":memory:");
        CreateDatabase(DetectorTagSession, t4p::DetectorSqlSchemaAsset());

        wxFileName tmpDir;
        tmpDir.AssignDir(wxStandardPaths::Get().GetTempDir());
        SourceDirs.push_back(tmpDir);
        std::string stdDir = t4p::WxToChar(tmpDir.GetPathWithSep());

        // create the source
        soci::statement stmt = (DetectorTagSession.prepare << "INSERT INTO sources(directory) VALUES(?)",
                                soci::use(stdDir));
        stmt.execute(true);
        soci::sqlite3_statement_backend* backend = static_cast<soci::sqlite3_statement_backend*>(stmt.get_backend());
        SourceId = sqlite3_last_insert_rowid(backend->session_.conn_);

        AddToDb1("http://localhost/index.php",
                 "/home/user/welcome.php", "WelcomeController", "index");
        AddToDb1("http://localhost/frontend.php",
                 "/home/user/frontend.php", "FrontendController", "action");
    }
LedgerHeaderFrame::pointer
LedgerHeaderFrame::loadBySequence(uint32_t seq, Database& db,
                                  soci::session& sess)
{
    LedgerHeaderFrame::pointer lhf;

    string headerEncoded;
    {
        auto timer = db.getSelectTimer("ledger-header");
        sess << "SELECT data FROM ledgerheaders "
                "WHERE ledgerseq = :s",
            into(headerEncoded), use(seq);
    }
    if (sess.got_data())
    {
        lhf = decodeFromData(headerEncoded);
        uint32_t loadedSeq = lhf->mHeader.ledgerSeq;

        if (loadedSeq != seq)
        {
            throw std::runtime_error(
                fmt::format("Wrong sequence number in ledger header database: "
                            "loaded ledger {} contains {}",
                            seq, loadedSeq));
        }
    }

    return lhf;
}
Exemple #3
0
LedgerHeaderFrame::pointer
LedgerHeaderFrame::loadBySequence(uint32_t seq, Database& db,
                                  soci::session& sess)
{
    LedgerHeaderFrame::pointer lhf;

    string headerEncoded;
    {
        auto timer = db.getSelectTimer("ledger-header");
        sess << "SELECT data FROM ledgerheaders "
                "WHERE ledgerseq = :s",
            into(headerEncoded), use(seq);
    }
    if (sess.got_data())
    {
        lhf = decodeFromData(headerEncoded);

        if (lhf->mHeader.ledgerSeq != seq)
        {
            // wrong sequence number
            lhf.reset();
        }
    }

    return lhf;
}
Exemple #4
0
void open (soci::session& s,
           std::string const& beName,
           std::string const& connectionString)
{
    if (beName == "sqlite")
        s.open(soci::sqlite3, connectionString);
    else
        throw std::runtime_error ("Unsupported soci backend: " + beName);
}
Exemple #5
0
command peer_hit::execute_command(soci::session& db, peer_hit_ptr hit)
{
    try
    {
        log::write("Creating DB entry");

        using soci::use;

        std::string insert = utils::read_whole_file("scripts/insert_script.sql");

        const gregorian::date& d = hit->time.date();
        const posix_time::time_duration& t = hit->time.time_of_day();

        const string& ip = hit->ip.to_string();
        const string& local_ip = utils::get_local_ip();

        const string& guid = utils::obj_to_string(hit->peer_id);
        const string& t_hash = utils::obj_to_string(hit->t_hash);
        const string& p_hash = utils::obj_to_string(hit->p_hash);
        const string& b_hash = utils::obj_to_string(hit->b_hash);

        command cmd = (
                    db.prepare << insert,

                       use(ip,                      "ip"),
                       use(local_ip,                "self_ip"),

                       use((unsigned short)d.year(),"year"),
                       use(d.month().as_number(), 	"month"),
                       use(d.day().as_number(),     "day"),
                       use(t.hours(), 				"hour"),
                       use(t.minutes(),             "minute"),
                       use(t.seconds(), 			"second"),

                       use(guid,				 	"guid"),
                       use(hit->client, 			"client"),

                       use(t_hash,				 	"t_hash"),
                       use(p_hash,				 	"p_hash"),
                       use(b_hash,				 	"b_hash"),

                       use(hit->port,   			"port"),
                       use(hit->local_port,         "self_port"),

                       use(hit->filename,           "filename"),
                       use(hit->path,               "path"),
                       use(hit->filesize,           "filesize"),

                       use(hit->block_size,         "block_size"),
                       use(hit->piece_size,         "piece_size"),

                       use(hit->block,              "block"),
                       use(hit->piece,              "piece"),

                       use(std::string("qbt3.1.9"),      "sig")
                      );

        log::write("Writing DB entry");
        cmd.execute(true);
        log::write("Entry written");

        return cmd;

    }catch(std::exception e){
        log::write(e);
        log::write("Reconnecting");
        db.reconnect();
    }
}
Exemple #6
0
void SociConfig::open (soci::session& s) const
{
    s.open (backendFactory_, connectionString ());
}