3 Replies Latest reply on May 1, 2002 5:32 PM by 82532

    Generating Trigger DDL using OO4O (OField::GetChunk)

    3542
      WINNT 4.0SP6
      MS Visual C++ 6.0 (using MFC)
      Oracle 8.1.7

      I'm attempting to write some C++ code that will generate the DDL of a trigger using OO4O.

      Here's the code (so far):-

      strSQL.Format("SELECT DESCRIPTION, TRIGGER_BODY FROM ALL_TRIGGERS WHERE OWNER = '%s' AND TRIGGER_NAME = '%s'", strOwner, strName);

      dyn.Open(m_pDatabase->m_database, strSQL);

      int nBuffSize = 65535;

      nSize = dyn.GetFieldSize(0);
      const char *pValue = strValue.GetBuffer(nSize+1);
      dyn.GetFieldValue(0, (char*)pValue, nSize + 1);
      strValue.ReleaseBuffer();
      strText.Format("CREATE OR REPLACE %s %s", pszType, strValue);

      OField fld =      dyn.GetField(1);

      const char *pBuffer = NULL;
      unsigned short nBytesRead = 0;
      long nOffset = 0;
      CString strBuff;

      do
      {
           if (fld.GetChunk(&pBuffer, nOffset, nBuffSize, &nBytesRead) != OSUCCESS)
                break;
                
           if (nBytesRead)
           {
                char *p = strBuff.GetBuffer(nBytesRead);
                memcpy(p, pBuffer, nBytesRead);
                strBuff.ReleaseBuffer();

                strText += strBuff;
                nOffset += nBytesRead;
           }
      }
      while (nBytesRead);

      My problem is that the GetChunk method is failing, although it still returns OSUCCESS.

      If I call OField::GetErrorText() after the GetChunk call I get the error "ROWID must be selected ..". Looking at the documentation this does make sense. That is, to access LONG type field values the ROWID must be accessible.

      In this case there is no ROWID available because we are selecting from a dictionary view (ALL_TRIGGERS). Attempting to "SELECT ROWID FROM ALL_TRIGGERS" results in the error "ORA-01446: cannot select ROWID from view with DISTINCT, GROUP BY, etc.".

      Can anyone out there point me in the right direction to solve this one ?

      Thanks in advance.

      Adrian Capp
      LBS Limited, UK