Call function with return value

Report PGNP bugs.

Call function with return value

Postby cezariusz.marek » Thu Jan 02, 2014 7:05 am

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: Select all
   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());
   }
cezariusz.marek
 
Posts: 3
Joined: Thu Jan 02, 2014 6:03 am

Re: Call function with return value

Postby Moderator » Sun Jan 05, 2014 9:43 pm

Could you send definition of the get_repository_version()?
User avatar
Moderator
Site Admin
 
Posts: 301
Joined: Wed Oct 29, 2008 11:27 pm

Re: Call function with return value

Postby cezariusz.marek » Mon Jan 13, 2014 12:09 am

Yes:

Code: Select all
  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;
cezariusz.marek
 
Posts: 3
Joined: Thu Jan 02, 2014 6:03 am


Return to Report Bugs

Who is online

Users browsing this forum: No registered users and 1 guest

cron