Subject: DUMP database

From: David Allan Finch <[email-masked]>
Date: Tue, 3 Aug 93 20:19:15 BST

The following is some pgperl that will get
the specification of a class and write it in the 
correct format for recreating the class, latter.
This is the start of a larger project to dump
a version of a pg database to be upload after
an upgrade. If there is some intrest I will send
more scripts. A latter version should be product in
C a place with the new release so that a SysAdmin
can dump the present db and move to the new directory 
and upload.

This I do not know about yet is how to get all
the user created databases,classes,types,functions
etc automaticaly. Also it would be nice to figure
out the inheritence of a class as the pgperl below
will flatten the tree and the Top* functionality
will be lost.

----------------8<---------------------------------------------
#!/usr/postgres/bin/pgperl
# This code is non-copyright of David Allan Finch
# and does nothing. If it does then its your
# problem for running it, You have been warned.
# Version 000.001 : 03/Aug/1993

$database	= "quote_history";

&get_types();
&print_types( "hl_1dy_FTSE" );
&print_types( "quote_list" );

exit(0);
sub get_types
	{
	&PQsetdb( "$database" );
	&PQexec( "begin" );

	&PQexec( "retrieve portal tmp ( pg_type.typname, pg_type.oid )" );
	&PQexec( "fetch all in tmp" );

	$p = &PQparray( "tmp" );
	$g = &PQngroups( $p );
	$t = 0;

	for( $k = 0; $k < $g; $k++ )
		{
		$n = &PQntuplesGroup( $p, $k );
		$m = &PQnfieldsGroup( $p, $k );
	
		for( $i = 0; $i < $n; $i++ )
			{
			$name	= &PQgetvalue( $p, $i, 0 );
			$value	= &PQgetvalue( $p, $i, 1 );
			$types{$name}	= $value;
			$types[$value]	= $name;
			}
		}

	&PQexec( "end" );
	&PQfinish();
	}

sub print_types
    {
	local( $class ) = @_;
    &PQsetdb( "$database" );
    &PQexec( "begin" );
 
    &PQexec( "retrieve portal tmp ( $class.all )" );
    &PQexec( "fetch all in tmp" );
 
    $p = &PQparray( "tmp" );
    $g = &PQngroups( $p );
    $t = 0;

	print "create $class ( ";
 
    for( $k = 0; $k < $g; $k++ )
        {
        $n = &PQntuplesGroup( $p, $k );
        $m = &PQnfieldsGroup( $p, $k );
 
        for( $i = 0; $i < $m; $i++ )
            {
		if( $i > 0 )
			{
			print ", ";
			}
			
		$field_name	= &PQfnameGroup( $p, $k, $i );
		$field_type = &PQftype( $p, $k, $i );

		print "$field_name = $types[$field_type]";
            }
        }

	print " )\n";
 
    &PQexec( "end" );
    &PQfinish();
    }
    
--
    /		Sarum Wizard
 /\|/\		All Hail Discordia
 | K |		[email-masked]
 \___/		[email-masked]