//
// Utility.h
//
// $Id: //poco/Main/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Utility.h#2 $
//
// Library: PostgreSQL
// Package: PostgreSQL
// Module:  Utility
//
// Definition of Utility.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
// 
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//


#ifndef PostgreSQL_Utility_INCLUDED
#define PostgreSQL_Utility_INCLUDED

#include "Poco/Data/PostgreSQL/PostgreSQL.h"
#include "Poco/Data/PostgreSQL/SessionHandle.h"

#include "Poco/Data/Session.h"

namespace Poco {
namespace Data {
namespace PostgreSQL {


class PostgreSQL_API Utility
	/// Various utility functions for PostgreSQL.
{
public:

	static std::string serverInfo(SessionHandle* aHandlePtr);
		/// Returns server info.

	static std::string serverInfo(Poco::Data::Session& aSession);
		/// Returns server info.

	static int serverVersion(SessionHandle* aHandlePtr);
		/// Returns server version.

	static int serverVersion(Poco::Data::Session& aSession);
		/// Returns server version.

	static std::string hostInfo(SessionHandle* aHandlePtr);
		/// Returns host info.

	static std::string hostInfo(Poco::Data::Session& aSession);
		/// Returns host info.

	static std::string sessionEncoding(SessionHandle* aHandlePtr);
		/// Returns session encoding.

	static std::string sessionEncoding(Poco::Data::Session& aSession);
		/// Returns session encoding.

	static bool hasMicrosecond() { return true; }
		/// Rturns true if microseconds are suported.

	static SessionHandle* handle(Poco::Data::Session& aSession);
		/// Returns native PostgreSQL handle for the session.
};


//
// inlines
//


inline SessionHandle* Utility::handle(Session& aSession)
{
	return Poco::AnyCast< SessionHandle* >(aSession.getProperty("handle"));
}


} } } // namespace Poco::Data::PostgreSQL


#endif // PostgreSQL_Utility_INCLUDED
