Доступные версии документации

Приложение 11. Пример анализа результатов трансляции хранимой процедуры

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "inter.h"
#include "exlib.h"

#define SIZE 8192


static void    PrintDescErr(TCBL * pCBL, L_LONG  CodErr);
static L_BYTE    Load(L_CHAR * Buf, const L_CHAR * fname, L_LONG  size);
static void    ProcPrintError(TCBL * pCBL);

#ifndef WINCE
int    main(int argc, const char * argv[])
#else
int    excreat()
#endif
  {
  TCBL    CBLconnect;
  L_CHAR    Name_Pass[] = "SYSTEM/MANAGER";
  L_CHAR    Node[] = "        ";
  L_WORD    Priority = 0;
  L_LONG  PrzExe = M_EXCLUSIVE | Q_ENCODE | M_BINARY;
  L_LONG  Err;
  L_CHAR    Buf[SIZE];

  if (argc != 2)
    {
    printf("Usage:ExCreat input_file\n");
    exit(1);
    }

  memset(&CBLconnect,0,sizeof(TCBL));
  Err = LinterOPEN(&CBLconnect, Name_Pass, Node, Priority, PrzExe);
  if (Err != NORMAL)
    ProcPrintError(&CBLconnect);
  printf("Connect to RDBMS Linter\n");

  if (Load(Buf, argv[1], SIZE))
    {
    Err = LinterNotSelect(&CBLconnect, Buf);
    if (Err != NORMAL)
      ProcPrintError(&CBLconnect);
    printf("created/alterd procedure\n");
    }
  else
    printf("can't Load text from file %s", argv[1]);

  printf("End Example\n");

  return 0;
  }

static void    PrintDescErr(TCBL * pCBL, L_LONG  CodErr)
  {
  L_CHAR    Str[256];

  if (NORMAL != LinterGETE(pCBL, CodErr, Str, 255))
    {
    printf("LinterGETE -- Error=%ld\n", pCBL->CodErr);
    exit(1);
    }
  printf("%s", Str);
  }

static void  ProcPrintError(TCBL * pCBL)
  {
  ERRS_DESCR *ErrDesc;
  L_BYTE    Buf[4096];
  L_WORD    Len,
          CntErr,
          i;
  L_WORD    dp;
  L_CHAR    cp[101];
  L_LONG  Err;

  if (pCBL->CodErr != NORMAL)
    {
    printf("Linter Error: %ld\n", pCBL->CodErr);
    if (pCBL->CodErr != Proc_Translation_Error)
      exit(1);
    }
  else
    return;

  Err = LinterGETE(pCBL, Proc_Translation_Error, Buf, sizeof(Buf));
  if (Err != NORMAL)
    {
    printf("ProcPrintError -- Linter error %ld\n", Err);
    exit(1);
    }

  CntErr = *((L_WORD *) Buf);
  ErrDesc = (ERRS_DESCR *) (Buf + sizeof(L_WORD));

  for (i = 0; i < CntErr; i++)
    {
    if (ErrDesc->Row != -1)
      printf("Error in line %ld position %ld: ", 
		   ErrDesc->Row, ErrDesc->Position);
    else
      printf("Error: ");
    switch (ErrDesc->ArgType)
      {
      case PROC_ERR_ARGSHORT:
        dp = *((L_WORD *) (ErrDesc + 1));
        PrintDescErr(pCBL, ErrDesc->CodErr + PROC_ERR_BASE);
        printf(": %d", dp);
        ErrDesc = (ERRS_DESCR *) ((L_WORD *) (ErrDesc + 1) + 1);
        break;
      case PROC_ERR_ARGSTRING:
        Len = *((L_WORD *) (ErrDesc + 1));
        memcpy(cp, (L_WORD *) (ErrDesc + 1) + 1, Len);
        cp[Len] = 0;
        PrintDescErr(pCBL, ErrDesc->CodErr + PROC_ERR_BASE);
        printf(": %s", cp);
        ErrDesc = (ERRS_DESCR *) ((L_BYTE *) (ErrDesc + 1) 
		           + sizeof(L_WORD) + Len);
        break;
      default:
        PrintDescErr(pCBL, ErrDesc->CodErr + PROC_ERR_BASE);
        ErrDesc++;
        }
    printf("\n");
    }
  printf("End Example\n");
  exit(1);
  }
static L_BYTE  Load(L_CHAR * Buf, const L_CHAR * fname, L_LONG  size)
  {
  L_LONG  ret;
  FILE   *file;

  file = fopen(fname, "r");
  if (file == NULL)
    {
    printf("Error: can't open file %s\n", fname);
    exit(1);
    }

  ret = fread(Buf, size, 1, file);
  if (ret > 0)
    ret = feof(file);

  fclose(file);

  if (ret)
    return 0;

  return 1;
  }

Заметили ошибку?
Выделите текст и нажмите Ctrl + Enter