Call function with return value

  • cezariusz.marek
  • Topic Author
  • Visitor
  • Visitor
9 years 11 months ago #10729 by cezariusz.marek
Call function with return value was created by cezariusz.marek
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):
Code:
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
9 years 11 months ago #10732 by Moderator
Replied by Moderator on 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.

  • cezariusz.marek
  • Topic Author
  • Visitor
  • Visitor
9 years 10 months ago #10764 by cezariusz.marek
Replied by cezariusz.marek on topic Re: Call function with return value
Yes:
Code:
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.156 seconds
Powered by Kunena Forum