@@ -66,8 +66,8 @@ const std::string SessionImpl::MYSQL_REPEATABLE_READ = "REPEATABLE READ";
6666const std::string SessionImpl::MYSQL_SERIALIZABLE = " SERIALIZABLE" ;
6767
6868
69- SessionImpl::SessionImpl (const std::string& connectionString) :
70- Poco::Data::AbstractSessionImpl<SessionImpl>(toLower(connectionString)),
69+ SessionImpl::SessionImpl (const std::string& connectionString, std:: size_t timeout ) :
70+ Poco::Data::AbstractSessionImpl<SessionImpl>(toLower(connectionString), timeout ),
7171 _handle (0 ),
7272 _connected (false ),
7373 _inTransaction (false )
@@ -76,6 +76,28 @@ SessionImpl::SessionImpl(const std::string& connectionString) :
7676 &SessionImpl::setInsertId,
7777 &SessionImpl::getInsertId);
7878
79+ open ();
80+ }
81+
82+
83+ void SessionImpl::open (const std::string& connect)
84+ {
85+ if (connect != connectionString ())
86+ {
87+ if (isConnected ())
88+ throw InvalidAccessException (" Session already connected" );
89+
90+ if (!connect.empty ())
91+ setConnectionString (connect);
92+ }
93+
94+ poco_assert_dbg (!connectionString ().empty ());
95+
96+ _handle.init ();
97+
98+ unsigned int timeout = static_cast <unsigned int >(getTimeout ());
99+ _handle.options (MYSQL_OPT_CONNECT_TIMEOUT, timeout);
100+
79101 std::map<std::string, std::string> options;
80102
81103 // Default values
@@ -87,17 +109,18 @@ SessionImpl::SessionImpl(const std::string& connectionString) :
87109 options[" compress" ] = " " ;
88110 options[" auto-reconnect" ] = " " ;
89111
90- for (std::string::const_iterator start = connectionString.begin ();;)
112+ const std::string& connString = connectionString ();
113+ for (std::string::const_iterator start = connString.begin ();;)
91114 {
92- std::string::const_iterator finish = std::find (start, connectionString .end (), ' ;' );
115+ std::string::const_iterator finish = std::find (start, connString .end (), ' ;' );
93116 std::string::const_iterator middle = std::find (start, finish, ' =' );
94117
95118 if (middle == finish)
96119 throw MySQLException (" create session: bad connection string format, can not find '='" );
97120
98121 options[copyStripped (start, middle)] = copyStripped (middle + 1 , finish);
99122
100- if ((finish == connectionString .end ()) || (finish + 1 == connectionString .end ())) break ;
123+ if ((finish == connString .end ()) || (finish + 1 == connString .end ())) break ;
101124
102125 start = finish + 1 ;
103126 }
@@ -127,8 +150,7 @@ SessionImpl::SessionImpl(const std::string& connectionString) :
127150 throw MySQLException (" create session: specify correct auto-reconnect option (true or false) or skip it" );
128151
129152 // Real connect
130- _handle.connect (
131- options[" host" ].c_str (),
153+ _handle.connect (options[" host" ].c_str (),
132154 options[" user" ].c_str (),
133155 options[" password" ].c_str (),
134156 options[" db" ].c_str (),
0 commit comments