Example #1
0
void
SqlPool::add_source(const SqlSource &source)
{
    sources_[source.id()] = source;
    counts_[source.id()] = 0;
    pools_[source.id()] = Pool();
}
Example #2
0
bool
SqlPool::reconnect(SqlConnectionPtr &conn)
{
    const SqlSource source = conn->get_source();
    const String &source_id = source.id();
    put(conn, true); // close now
    LOG(ll_DEBUG, _T("reopening connection") + format_stats(source_id));
    ScopedLock lock(pool_mux_);
    conn = new SqlConnection(source);
    ++counts_[source_id];
    LOG(ll_INFO, _T("reopened connection") + get_stats(source_id));
    return true;
}
Example #3
0
SqlSource Engine::sql_source_from_env(const String &id)
{
    SqlSource src;
    String url = env_cfg(_T("URL"));
    if (!str_empty(url))
        src = SqlSource(url);
    else
        src = SqlSource(_T(""),
            env_cfg(_T("DRIVER"), _T("DEFAULT")),
            env_cfg(_T("DBTYPE")), env_cfg(_T("DB")),
            env_cfg(_T("USER")), env_cfg(_T("PASSWD")));
    if (str_empty(id))
        src[_T("&id")] = src.format();
    else
        src[_T("&id")] = id;
    return src;
}
Example #4
0
void
SOCIConnectionBackend::open(SqlDialect *dialect, const SqlSource &source)
{
    close();
    own_handle_ = true;
    try {
        String driver = source.driver();
        std::string soci_backend = "odbc";
        if (driver == _T("SOCI"))
            soci_backend = soci_convert_dialect(dialect->get_name());
        conn_ = new soci::session(soci_backend, NARROW(source.db()));
#ifdef YB_SOCI_DEBUG
        conn_->set_log_stream(&cerr);
#endif
    }
    catch (const soci::soci_error &e) {
        throw DBError(WIDEN(e.what()));
    }
}
Example #5
0
void
SQLiteConnectionBackend::open(SqlDialect *dialect, const SqlSource &source)
{
    close();
    ScopedLock lock(drv_->conn_mux_);
    own_handle_ = true;
    sqlite3_open(NARROW(source.db()).c_str(), &conn_);
    if (SQLITE_OK != sqlite3_errcode(conn_)) {
        const char *err = sqlite3_errmsg(conn_);
        throw DBError(WIDEN(err));
    }
}
Example #6
0
void
QtSqlConnectionBackend::open(SqlDialect *dialect, const SqlSource &source)
{
    close();
    ScopedLock lock(drv_->conn_mux_);
    own_handle_ = true;
    conn_name_ = dialect->get_name() + _T("_") + source.db()
        + _T("_") + to_string(drv_->seq_);
    ++drv_->seq_;
    String driver = source.driver();
    bool eat_slash = false;
    if (driver == _T("QTSQL"))
    {
        if (dialect->get_name() == _T("MYSQL"))
            driver = _T("QMYSQL");
        else if (dialect->get_name() == _T("POSTGRES"))
            driver = _T("QPSQL");
        else if (dialect->get_name() == _T("ORACLE"))
            driver = _T("QOCI");
        else if (dialect->get_name() == _T("INTERBASE"))
            driver = _T("QIBASE");
        else if (dialect->get_name() == _T("SQLITE"))
            driver = _T("QSQLITE");
        if (dialect->native_driver_eats_slash()
                && !str_empty(source.db())
                && char_code(source.db()[0]) == '/')
            eat_slash = true;
    }
    conn_ = new QSqlDatabase(QSqlDatabase::addDatabase(driver, conn_name_));
    if (eat_slash)
        conn_->setDatabaseName(str_substr(source.db(), 1));
    else
        conn_->setDatabaseName(source.db());
    conn_->setUserName(source.user());
    conn_->setPassword(source.passwd());
    if (source.port() > 0)
        conn_->setPort(source.port());
    if (!str_empty(source.host()))
        conn_->setHostName(source.host());
    String options;
    Strings keys = source.options();
    for (size_t i = 0; i < keys.size(); ++i) {
        if (!str_empty(options))
            options += _T(";");
        options += keys[i] + _T("=") + source[keys[i]];
    }
    if (!str_empty(options))
        conn_->setConnectOptions(options);
    if (!conn_->open())
        throw DBError(conn_->lastError().text());
}
Example #7
0
Sql::Sql(const SqlStatement& stmt, SqlSource& s) {
	cn = s.CreateConnection();
	SetStatement(stmt);
}
Example #8
0
Sql::Sql(SqlSource& s) {
	cn = s.CreateConnection();
}
Example #9
0
void Sql::SetSession(SqlSource& s) {
	Detach();
	cn = s.CreateConnection();
}