Call function with return value

More
6 years 3 months ago #10729 by cezariusz.marek
cezariusz.marek created the topic: Call function with return value
I'm trying to call function using Command and return parameter. I get either null or crash. Here's sample code (it works with Oracle provider):
	try
	{
		HRESULT hr;
		_ConnectionPtr m_spConn;
		hr = m_spConn.CreateInstance(__uuidof(Connection));
		if (FAILED(hr))
		{
			_com_issue_errorex(hr, NULL, __uuidof(Connection));
		}
		m_spConn->Open("Provider=PGNP", "postgres", "postgres", adConnectUnspecified);

		_CommandPtr m_spCommand;
		hr = m_spCommand.CreateInstance(__uuidof(Command));
		if (FAILED(hr))
		{
			_com_issue_errorex(hr, m_spCommand, __uuidof(m_spCommand));
		}
		m_spCommand->ActiveConnection = m_spConn;
		m_spCommand->CommandText = "vm_global.get_repository_version()";
		_ParameterPtr spPar = m_spCommand->CreateParameter("", adVarChar, adParamReturnValue, 2000);
		m_spCommand->Parameters->Append(spPar);
		//m_spCommand->Execute(NULL, NULL, adCmdStoredProc | adExecuteNoRecords); // returns NULL
		//m_spCommand->Execute(NULL, NULL, adCmdStoredProc); // crash
		//m_spCommand->Execute(NULL, NULL, adCmdUnspecified); // crash
		//m_spCommand->Execute(NULL, NULL, adCmdText); // crash
		m_spCommand->Execute(NULL, NULL, adCmdText | adExecuteNoRecords); // returns NULL
		_variant_t result = spPar->Value;
		AfxMessageBox("Result: " + (_bstr_t) (result.vt == VT_NULL ? "NULL" : result));
	}
	catch (_com_error& e)
	{
		AfxMessageBox("Error message: " + (_bstr_t) e.ErrorMessage() + "\r\nDescription: " + (_bstr_t) e.Description());
	}

Please Log in or Create an account to join the conversation.

More
6 years 3 months ago #10732 by Moderator
Moderator replied the topic: Re: Call function with return value
Could you send definition of the get_repository_version()?

Please Log in or Create an account to join the conversation.

More
6 years 2 months ago #10764 by cezariusz.marek
cezariusz.marek replied the topic: Re: Call function with return value
Yes:
  CREATE OR REPLACE FUNCTION vm_global.get_repository_version()
    RETURNS VARCHAR AS $$
  DECLARE
    sc_repository_version VARCHAR(10) := '2.06.0027';
  BEGIN
      RETURN sc_repository_version;
  END;
  $$ LANGUAGE plpgsql;

Please Log in or Create an account to join the conversation.

Time to create page: 0.088 seconds
Powered by Kunena Forum