#!/bin/bash
#
#  export.bash - Export Progress Data to MySQL
#
#  pro2myv2
#  Copyright (C) 2006  Scott Auge, Amduus Information Works, Inc.
#
#  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
#
#  Free Software Foundation, Inc.
#  59 Temple Place, Suite 330
#  Boston, MA  02111-1307  USA
#
# $Id: export.bash,v 1.2 2006/07/20 03:57:47 sauge Exp sauge $

##############################################################################
# Get our environment here...                                                #
##############################################################################

export DELETE="no"

. /amduus/pro2myv2/set.bash 

##############################################################################
# No arguments means the user needs a reminder of the arguments              #
##############################################################################

if [ $# -eq 0 ]
then

  echo $0
  echo "Dump progress table into INSERT statements"
  echo 
  echo "-pf          pf for a single database"
  echo "-dlc         DLC to progress installation"
  echo "-table       Name of the table"
  echo
  echo "Example: export.bash -dlc /usr/dlc -pf /db/amduus/client.pf -table customer"
  echo 
  echo "You must connect to only one DB at a time."
  echo 
  
  exit 1

fi

##############################################################################
# Interprete arguments into environmental variables we can use OS-GETENV()   #
# against to communicate the user's intention to the 4GL code.               #
##############################################################################

# If you expect to have spaces in your files and directories given as args,
# you may prefer to use this to prevent word splitting:
# for i in "$1" "$2" "$3" "$4" "$5" "$6" ... "${10}" ...

for i in $@
do

  ########################################################################
  # Handle our argumentless switches                                     #
  ########################################################################

  case $i in

     -delete)
       export DELETE="yes"
       ;;

  esac

  ########################################################################
  # Handle our switches with arguments                                   #
  # This came from Amduus' pro2pgsql - these options are mostly ignored  #
  # in the MySQL version of this stuff.                                  #
  ########################################################################

  case $lastcmd in

     -output)
       export OUTPUTFILE=$i
       ;;

     -pf)
       export PFFILE=$i
       ;;
       
     -dlc)
       export DLC=$i
       ;;       

     -table)
       export TABLE=$i
       ;;     
       
     -where)
       export WHERE=$i
       ;;     
       
     -ini)
       export CONFIGINI=$i
       ;;     
              
  esac

  lastcmd=$i

done

##############################################################################
# Hit the conversion procedure to implement what is requested.               #
##############################################################################

$DLC/bin/_progres -b -pf $PFFILE -p bat_ptmd.p
#$DLC/bin/mpro -pf $PFFILE -p bat_exportsql.p
