# MYSQlib.ctl: Defines Common Macros for Oracle MySQL # $Id: MYSQlib.ctl,v 1.3 2013/10/30 07:18:24 RDA Exp $ # ARCS: $Header: /home/cvs/cvs/RDA_8/src/scripting/lib/collect/DB/MYSQlib.ctl,v 1.3 2013/10/30 07:18:24 RDA Exp $ # # Change History # 20130610 MSC Improve validation. =head1 NAME DB:MYSQlib - Defines Common Macros for Oracle MySQL =head1 DESCRIPTION This persistent submodule regroups macros that are common to several Oracle MySQL related-modules. The following macros are available: =cut use Buffer # Make the module persistent and share macros keep $KEEP_BLOCK,@SHARE_MACROS var @SHARE_MACROS = ('stat_tree','write_data','write_table','write_variables') =head2 S This macro lists the content of the specified directory recursively. =cut macro stat_tree {var ($dir) = @arg import $TOP keep $TOP if expr('>',statDir('n',$dir),0) write $TOP loop $pth (findDir($dir,'^\.+$','npv')) {next ?testFile('l',$pth) call stat_tree($pth) } } =head2 S This macro returns the MySQL output in a text format. =cut macro write_data {var ($buf,$dat) = @arg import $SECTION,$TOP,%DSC keep $SECTION,$TOP,%DSC var ($key,$flg,$itr) = split('\|',$dat) if !$flg var $SECTION = undef elsif ?$itr var $SECTION = $itr prefix {if ?$SECTION {write '---+ Iteration ',$itr var $SECTION = undef } write $DSC{$key}->[0] write '' } while ?$lin = $buf->get_line write replace($lin,'\\n',"\012",true) if hasOutput(true) {write '' write $TOP } } =head2 S This macro returns the MySQL output in a table format. =cut macro write_table {var ($buf,$dat) = @arg import $SECTION,$TOP,%DSC keep $SECTION,$TOP,%DSC var ($key,$flg,$itr) = split('\|',$dat) if !$flg var $SECTION = undef elsif ?$itr var $SECTION = $itr prefix {if ?$SECTION {write '---+ Iteration ',$itr var $SECTION = undef } write $DSC{$key}->[0] } var $min = $DSC{$key}->[1] while ?$buf->get_line {var $lin = replace(last,'\\n','%BR%',true) var $lin = replace($lin,'\\\\','\',true) var $col = $min decr $col,scalar(@col = split('\t',replace($lin,'\|','|',true))) if expr('>',$col,0) write '|',join(' |',@col),repeat(' |',$col),' |' else write '|',join(' |',@col),' |' } if hasOutput(true) write $TOP } =head2 S This macro returns the MySQL C output in a table format. =cut macro write_variables {var ($buf,$dat) = @arg import $TOP,%DSC,%MYSQL keep $TOP,%DSC,%MYSQL prefix write $DSC{$dat}->[0] while ?$buf->get_line {var ($key,$val) = split('\t',last) if ?$val {var $val = replace($val,'\\n','%BR%',true) var $val = replace($val,'\\\\','\',true) if exists($MYSQL{$key}) var $MYSQL{$key} = $val write '|',$key,' |',replace($val,'\|','|',true),' |' } else write '|',$key,' | |' } if hasOutput(true) write $TOP } =head1 COPYRIGHT NOTICE Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. =head1 TRADEMARK NOTICE Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. =cut