in language-extensions/python/src/PythonExtension.cpp [610:690]
SQLRETURN InstallExternalLibrary(
SQLGUID setupSessionId,
SQLCHAR *libraryName,
SQLINTEGER libraryNameLength,
SQLCHAR *libraryFile,
SQLINTEGER libraryFileLength,
SQLCHAR *libraryInstallDirectory,
SQLINTEGER libraryInstallDirectoryLength,
SQLCHAR **libraryError,
SQLINTEGER *libraryErrorLength)
{
LOG("InstallExternalLibrary");
SQLRETURN result = SQL_ERROR;
string errorString;
string installDir = string(reinterpret_cast<char *>(libraryInstallDirectory),
libraryInstallDirectoryLength);
installDir = PythonExtensionUtils::NormalizePathString(installDir);
string tempFolder = PythonExtensionUtils::NormalizePathString(
fs::path(installDir).append("tmp").string());
try
{
PythonLibrarySession librarySession = PythonLibrarySession();
librarySession.Init(&setupSessionId);
result = librarySession.InstallLibrary(
tempFolder,
libraryName,
libraryNameLength,
libraryFile,
libraryFileLength,
libraryInstallDirectory,
libraryInstallDirectoryLength);
}
catch (const exception & ex)
{
result = SQL_ERROR;
errorString = string(ex.what());
LOG_ERROR(errorString);
}
catch (const bp::error_already_set &)
{
result = SQL_ERROR;
errorString = PythonExtensionUtils::ParsePythonException();
LOG_ERROR("Python error: " + errorString);
}
catch (...)
{
result = SQL_ERROR;
errorString = "Unexpected exception occurred in function InstallExternalLibrary()";
LOG_ERROR(errorString);
}
// Clean up the temp installation folder
//
if (fs::exists(tempFolder))
{
fs::remove_all(tempFolder);
}
if (!errorString.empty())
{
*libraryErrorLength = errorString.length();
string *pError = new string(errorString);
SQLCHAR *error = const_cast<SQLCHAR*>(reinterpret_cast<const SQLCHAR *>(pError->c_str()));
*libraryError = error;
}
return result;
}