language-extensions/python/src/PythonExtension.cpp
//-------------------------------------------------------------------------------------------------
// Name: Init
//
// Description:
//  Initialize the python extension. Until registration, nothing is needed here.
//  We call Py_Initialize to initialize python in C++ and allow boost to work
//
// Returns:
//  SQL_SUCCESS on success, else SQL_ERROR
//

Init
Description:
Initialize the python extension. Until registration, nothing is needed here.
We call Py_Initialize to initialize python in C++ and allow boost to work


Init Description : Initialize the python extension . Until registration nothing is needed here . We call Py_Initialize to initialize python in C ++ and allow boost to work
SQLRETURN Init(
	SQLCHAR *extensionParams,
	SQLULEN extensionParamsLength,
	SQLCHAR *extensionPath,
	SQLULEN extensionPathLength,
	SQLCHAR *publicLibraryPath,
	SQLULEN publicLibraryPathLength,
	SQLCHAR *privateLibraryPath,
	SQLULEN privateLibraryPathLength
)
{
	LOG("Init");
	SQLRETURN result = SQL_SUCCESS;
	try
	{
#ifndef _WIN64
		dlopen(x_PythonSoFile.c_str(), RTLD_LAZY | RTLD_GLOBAL);
#endif
		Py_Initialize();
		if (!Py_IsInitialized())
		{
			throw runtime_error("Python did not initialize properly, "
				"check paths and dependencies.");
		}
		bp::numpy::initialize();
		PythonPathSettings::Init(
			extensionParams,
			extensionPath,
			publicLibraryPath,
			privateLibraryPath);
		PythonNamespace::Init();
	}
	catch (const exception &ex)
	{
		result = SQL_ERROR;
		LOG_ERROR(ex.what());
	}
	catch (const bp::error_already_set&)
	{
		result = SQL_ERROR;
		LOG_ERROR("Python error: " + PythonExtensionUtils::ParsePythonException());
	}
	catch (...)
	{
		result = SQL_ERROR;
		LOG_ERROR("Unexpected exception occurred in function Init()");
	}
	return result;
}
SQLRETURN Init ( SQLCHAR * extensionParams , SQLULEN extensionParamsLength , SQLCHAR * extensionPath , SQLULEN extensionPathLength , SQLCHAR * publicLibraryPath , SQLULEN publicLibraryPathLength , SQLCHAR * privateLibraryPath , SQLULEN privateLibraryPathLength ) { LOG ( " " ) ; SQLRETURN result = SQL_SUCCESS ; try { #ifndef _WIN64 dlopen ( x_PythonSoFile . c_str ( ) , RTLD_LAZY | RTLD_GLOBAL ) ; #endif Py_Initialize ( ) ; if ( ! Py_IsInitialized ( ) ) { throw runtime_error ( " " " " ) ; } bp :: numpy :: initialize ( ) ; PythonPathSettings :: Init ( extensionParams , extensionPath , publicLibraryPath , privateLibraryPath ) ; PythonNamespace :: Init ( ) ; } catch ( const exception & ex ) { result = SQL_ERROR ; LOG_ERROR ( ex . what ( ) ) ; } catch ( const bp :: error_already_set & ) { result = SQL_ERROR ; LOG_ERROR ( " " + PythonExtensionUtils :: ParsePythonException ( ) ) ; } catch ( ... ) { result = SQL_ERROR ; LOG_ERROR ( " " ) ; } return result ; }
Name: Init
Description:
Initialize the python extension.
Name : Init Description : Initialize the python extension .
// Preload the python so in Linux so that numpy knows about it.
 // Without this line, the numpy .so cannot find python and will fail to load.
 //
 // Initialize Python using the Python/C API.
 // This allows us to start using Python API and boost functions.
 //
