1//
2// Session.cpp
3//
4// Library: SQL
5// Package: SQLCore
6// Module: Session
7//
8// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/SQL/Session.h"
16#include "Poco/SQL/SessionFactory.h"
17#include "Poco/String.h"
18#include "Poco/URI.h"
19#include <algorithm>
20
21
22namespace Poco {
23namespace SQL {
24
25
26Session::Session(Poco::AutoPtr<SessionImpl> pImpl):
27 _pImpl(pImpl),
28 _statementCreator(pImpl)
29{
30 poco_check_ptr (pImpl.get());
31}
32
33
34Session::Session(const std::string& rConnector,
35 const std::string& connectionString,
36 std::size_t timeout)
37{
38 operator =(SessionFactory::instance().create(rConnector, connectionString, timeout));
39}
40
41
42Session::Session(const std::string& connection,
43 std::size_t timeout)
44{
45 operator =(SessionFactory::instance().create(connection, timeout));
46}
47
48
49Session::Session(const Session& other): _pImpl(other._pImpl),
50 _statementCreator(other._pImpl)
51{
52}
53
54
55Session::Session(Session&& other): _pImpl(other._pImpl),
56 _statementCreator(other._pImpl)
57{
58 other._pImpl = nullptr;
59}
60
61
62Session::~Session()
63{
64 if (_pImpl) _pImpl->putBack();
65}
66
67
68Session& Session::operator = (const Session& other)
69{
70 if (this != &other)
71 {
72 Session tmp(other);
73 swap(tmp);
74 }
75 return *this;
76}
77
78
79Session& Session::operator = (Session&& other)
80{
81 if (this != &other)
82 {
83 _pImpl = other._pImpl;
84 _statementCreator = _pImpl;
85 other._pImpl = nullptr;
86 }
87 return *this;
88}
89
90
91void Session::swap(Session& other)
92{
93 using std::swap;
94 swap(_statementCreator, other._statementCreator);
95 swap(_pImpl, other._pImpl);
96}
97
98
99} } // namespace Poco::SQL
100