.ad 8
.bm 8
.fm 4
.bt $Copyright (c) 1995-2004 SAP AG$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $SQL$Project Distributed Database System$vni57c$
.tt 2 $$$
.tt 3 $$$1995-08-01$
***********************************************************
.nf

.nf


    ========== licence begin  GPL
    Copyright (c) 1995-2004 SAP AG

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end

.fo


.fo
.nf
.sp
Module  :
=========
.sp
Purpose :
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :

.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :

.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :

.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : 
.sp
.cp 3
Created : 1995-08-01
.sp
.cp 3
\Version : 1995-08-01
.sp
.cp 3
\Release :      Date :
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification: mpveri (Steuerprogramm fuer multiples Verify)

.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description: chtab ( Check Table aus Tabellenliste )

.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:

.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.oc _/1
.CM -lll-
Code    :
#include <stdio.h>
#include <signal.h>

int 	ErrOpen = 0 ;
FILE 	*Fperr ;
FILE 	*f , *Fprot ;
int	fnumber = 0 ;
int	tot_errs = 0 ;

void cwr () ;
/* PTS 6129 */
void usage () ;

main (argc,argv)  
int	argc ;
char	**argv ;
{
    int		i ;
    int		errcode = 0 ;
    int		silent = 0 ;
    int		connection_down = 0 ;
    char	TabFile [100] ;
    char	PrtFile [100] ;
    char	table [40] ;
    char	line [40] ;

    EXEC SQL BEGIN DECLARE SECTION ;
    char	cmd [100] ;
    EXEC SQL END DECLARE SECTION ;

/* PTS 6129 */
&if $OS = WIN32
    signal ( SIGTERM , (void (__cdecl *)(int)) cwr ) ;
&else
    signal ( SIGTERM , cwr ) ;
&endif
    for (i=1; i < argc ; i++)
    {
        if (argv[i][0] == '-')
            switch (argv[i][1])
            {
/*
                case 'V' : printf ( "%s\n", version) ;
                           break ;
*/
                case 'f' : strcpy ( TabFile , argv [++i] ) ;
			   break ;
                case 's' : fnumber = atoi ( argv [++i] );
			   silent = 1 ;
			   break ;
	        default  : usage () ;
	    }
    }

    if ( ( f = fopen ( TabFile , "r" ) ) == NULL )
    {
	perror ( "Open Input File" ) ;
	return (1) ;
    }

    sprintf ( PrtFile , "chtab%d.prt" , fnumber ) ;

    if ( ( Fprot = fopen ( PrtFile , "w" ) ) == NULL )
    {
	perror ( "Open Protocol File" ) ;
	return (1) ;
    }

    EXEC SQL CONNECT;

    while ( fgets ( line , sizeof line , f ) != NULL )
    {
        sscanf ( line , "%s" , table ) ;
	sprintf ( cmd , "CHECK TABLE \"%s\" NO SAVEPOINT" , table ) ;
        
	if ( !silent ) 
	{
	    printf ( "%s, sqlcode = " , cmd ) ;
            fflush ( stdout ) ;
	}

        EXEC SQL EXECUTE IMMEDIATE :cmd ;

        if ( sqlca.sqlcode ) 
	{
	    errcode = 1 ;
	    print_err ( cmd , sqlca.sqlcode , fnumber ) ; 
	    tot_errs++ ;

	    if ( sqlca.sqlcode == -709 || sqlca.sqlcode == -807 || 
		sqlca.sqlcode == -9807 || sqlca.sqlcode == -821)
	    {
		connection_down = 1 ;
		print_err ( "No connect to database --- cannot continue check",
			-199999 , fnumber ) ; 
		print_err ( "The following tables could not be checked" ,
			-199999 , fnumber ) ;
		print_err ( table , -199999 , fnumber ) ; 
    		while ( fgets ( line , sizeof line , f ) != NULL )
		{
		    tot_errs++ ;
        	    sscanf    ( line , "%s" , table ) ;
		    print_err ( table , -199999 , fnumber ) ; 
		}
	    }
	}
 
	if ( ! silent ) 
	    printf ( "%d\n" , sqlca.sqlcode ) ;

	fprintf ( Fprot , "%s, sqlcode = %d\n" , cmd , sqlca.sqlcode ) ;
	fflush  ( Fprot ) ;

	if ( connection_down )
	    break ;

        EXEC SQL COMMIT ;	
    }

    if ( ! connection_down )
    {
        EXEC SQL FORCE SAVEPOINT ;
        EXEC SQL COMMIT WORK RELEASE ;
    }

    fclose ( f ) ;

    if ( tot_errs == 0 )
    {
	char eline [100] ;
	sprintf ( eline , "Verify-task %d: no errors" , fnumber ) ;
        print_err ( eline , -99999 , fnumber ) ;
    }
    else
    {
	char eline [100] ;
	sprintf ( eline , "Verify-task %d: finished with %d errors" , 
		fnumber , tot_errs ) ;
        print_err ( eline , -99999 , fnumber ) ;
    }

    fclose ( Fprot ) ;
    if ( Fperr ) 
	fclose ( Fperr ) ;

    return ( errcode ) ;
}

print_err ( cmd , errc , fnumber )
char	*cmd ;
{
    char	ErrFile [100] ;
	
    if ( ! ErrOpen ) 
    {
		sprintf ( ErrFile , "chtab%d.err" , fnumber ) ;
		
        if ( ( Fperr = fopen ( ErrFile , "w" ) ) == NULL )
        {
			perror ( "Open Error File" ) ;
			return (1) ;
        }
		
        ErrOpen = 1 ;
    }
	
    if ( errc == -99999 )
    {
        fprintf ( Fperr , "%s\n" , cmd ) ;
		fclose ( Fperr ) ;
    }
    else if ( errc == -199999 )
    {
        fprintf ( Fperr , "%s\n" , cmd ) ;
		fflush  ( Fperr ) ;
    }
    else
    {
        fprintf ( Fperr , "%s : ERR = %d\n" , cmd , errc ) ;
		fflush  ( Fperr ) ;
        fprintf ( stderr , "%s : ERR = %d\n" , cmd , errc ) ;
    }
	return (0) ;
}

void cwr ()
{
    if ( Fprot != (FILE *) 0 )
        fclose ( Fprot ) ;

    EXEC SQL FORCE SAVEPOINT ;

    print_err ( "Killed (CTRL C)" , -99999 , fnumber ) ;

    exit (1) ;
}

void usage () {} 

.CM *-END-* code ----------------------------------------
.sp 2
***********************************************************
*-PRETTY-*  statements    :           0
*-PRETTY-*  lines of code :           0
*-PRETTY-*  lines in file :           0
.pa
