language-extensions/python/src/PythonExtension.cpp
//-------------------------------------------------------------------------------------------------
// Name: UninstallExternalLibrary
//
// Description:
//  Uninstalls an external library from the specified directory.
//  We add the directory to the python path, then call pip uninstall in a subprocess.
//  If pip fails for some reason, we try to manually uninstall the package by deleting the
//  top level package folder as well as any dist/egg/.py files that were left behind.
//
// Returns:
//  SQL_SUCCESS on success, else SQL_ERROR
//

UninstallExternalLibrary
Description:
Uninstalls an external library from the specified directory.
We add the directory to the python path, then call pip uninstall in a subprocess.
If pip fails for some reason, we try to manually uninstall the package by deleting the
top level package folder as well as any dist/egg/.py files that were left behind.


UninstallExternalLibrary Description : Uninstalls an external library from the specified directory . We add the directory to the python path then call pip uninstall in a subprocess . If pip fails for some reason we try to manually uninstall the package by deleting the top level package folder as well as any dist / egg / . py files that were left behind .
SQLRETURN UninstallExternalLibrary(
	SQLGUID    setupSessionId,
	SQLCHAR    *libraryName,
	SQLINTEGER libraryNameLength,
	SQLCHAR    *libraryInstallDirectory,
	SQLINTEGER libraryInstallDirectoryLength,
	SQLCHAR    **libraryError,
	SQLINTEGER *libraryErrorLength)
{
	LOG("UninstallExternalLibrary");
	SQLRETURN result = SQL_SUCCESS;
	string errorString;
	try
	{
		PythonLibrarySession librarySession = PythonLibrarySession();
		librarySession.Init(&setupSessionId);
		result = librarySession.UninstallLibrary(
			libraryName,
			libraryNameLength,
			libraryInstallDirectory,
			libraryInstallDirectoryLength);
	}
	catch (const exception & ex)
	{
		result = SQL_ERROR;
		errorString = string(ex.what());
	}
	catch (const bp::error_already_set &)
	{
		result = SQL_ERROR;
		errorString = PythonExtensionUtils::ParsePythonException();
	}
	catch (...)
	{
		result = SQL_ERROR;
		errorString = "Unexpected exception occurred in function UninstallExternalLibrary()";
	}
	if (!errorString.empty())
	{
		LOG_ERROR(errorString);
		result = SQL_ERROR;
		*libraryErrorLength = errorString.length();
		string *pError = new string(errorString);
		SQLCHAR *error = const_cast<SQLCHAR *>(
			reinterpret_cast<const SQLCHAR *>(pError->c_str()));
		*libraryError = error;
	}
	return result;
}
SQLRETURN UninstallExternalLibrary ( SQLGUID setupSessionId , SQLCHAR * libraryName , SQLINTEGER libraryNameLength , SQLCHAR * libraryInstallDirectory , SQLINTEGER libraryInstallDirectoryLength , SQLCHAR * * libraryError , SQLINTEGER * libraryErrorLength ) { LOG ( " " ) ; SQLRETURN result = SQL_SUCCESS ; string errorString ; try { PythonLibrarySession librarySession = PythonLibrarySession ( ) ; librarySession . Init ( & setupSessionId ) ; result = librarySession . UninstallLibrary ( libraryName , libraryNameLength , libraryInstallDirectory , libraryInstallDirectoryLength ) ; } catch ( const exception & ex ) { result = SQL_ERROR ; errorString = string ( ex . what ( ) ) ; } catch ( const bp :: error_already_set & ) { result = SQL_ERROR ; errorString = PythonExtensionUtils :: ParsePythonException ( ) ; } catch ( ... ) { result = SQL_ERROR ; errorString = " " ; } if ( ! errorString . empty ( ) ) { LOG_ERROR ( errorString ) ; result = SQL_ERROR ; * libraryErrorLength = errorString . length ( ) ; string * pError = new string ( errorString ) ; SQLCHAR * error = const_cast < SQLCHAR * > ( reinterpret_cast < const SQLCHAR * > ( pError -> c_str ( ) ) ) ; * libraryError = error ; } return result ; }
Name: UninstallExternalLibrary
Description:
Uninstalls an external library from the specified directory.
Name : UninstallExternalLibrary Description : Uninstalls an external library from the specified directory .