#!/usr/bin/perl
#------------------------------------------------------------------------------
# Copyright (C) 2001 Thomax Kaulmann
#
# 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, 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., 675 Mass Ave, Cambridge, MA 02139, USA.


# this module gives you arrays of all tables of a database
# with the field names of each table as its elements.
# this is in perl style

use DBI;
use lib "/opt/oma/oma-bin";
use OMA;

sub fields {
	my $st;
	$st=$db->prepare("select * from $_[0]");
	$st->execute();
	@names = @{$st->{NAME}};
	$ret = "\@XSQL::$_[0] = (";
	for($i=0;$i<=$#names;$i++) {
		$ret .= " '$names[$i]',";
	}
	chop($ret);
	return "$ret);\n";
}

$db = OMA::opendb();
#$st = $db->prepare("show tables");
$st = $db->prepare("select tablename from pg_tables where not (tablename like 'pg_%' or tablename like 'sql_%')");
$st->execute();
$hash="";
while(@row=$st->fetchrow()) {
	$s = fields($row[0]);
	print $s;
	$hash .= "\$XSQL::dbset{\"$row[0]\"} = \\\@XSQL::$row[0];\n";
}
$st->finish();
print "



$hash

";
