Changeset 19124


Ignore:
Timestamp:
08/03/18 13:42:22 (6 years ago)
Author:
tbretz
Message:
Implmented compressed connections.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Database.h

    r14404 r19124  
    44#include <exception>
    55#include <boost/regex.hpp>
     6#include <boost/algorithm/string.hpp>
    67
    78#include <mysql++/mysql++.h>
     
    1415    std::string db;
    1516    int port;
     17    char compression;
    1618
    17     DatabaseName(const std::string &database)
     19    DatabaseName(const std::string &database) : compression(0)
    1820    {
    19         static const boost::regex expr("(([[:word:].-]+)(:(.+))?@)?([[:word:].-]+)(:([[:digit:]]+))?(/([[:word:].-]+))");
     21        static const boost::regex expr("(([[:word:].-]+)(:(.+))?@)?([[:word:].-]+)(:([[:digit:]]+))?(/([[:word:].-]+))(/[+-])?");
    2022
    2123        boost::smatch what;
     
    2325            throw std::runtime_error("Couldn't parse database URI '"+database+"'.");
    2426
    25         if (what.size()!=10)
     27        if (what.size()!=11)
    2628            throw std::runtime_error("Error parsing database URI '"+database+"'.");
    2729
     
    3032        server = what[5];
    3133        db     = what[9];
     34
     35        compression = std::string(what[10])[1];
    3236
    3337        try
     
    5963public:
    6064    Database(const std::string &desc) : DatabaseName(desc),
    61         mysqlpp::Connection(db.c_str(), server.c_str(), user.c_str(), passwd.c_str(), port)
     65        mysqlpp::Connection()
    6266    {
     67        if ((compression!='-' && boost::algorithm::to_lower_copy(server)!="localhost" && server!="127.0.0.1")||
     68            compression=='+')
     69            set_option(new mysqlpp::CompressOption());
     70
     71        // Connect to the database
     72        connect(db.c_str(), server.c_str(), user.c_str(), passwd.c_str(), port);
    6373    }
    6474};
Note: See TracChangeset for help on using the changeset viewer.