#!/bin/bash set -e # All parameters are required. This way, users can't pass empty string as parameter. invalidArgs=0 [ -z "$1" ] && invalidArgs=1 [ -z "$2" ] && invalidArgs=1 [ -z "$3" ] && invalidArgs=1 if [ $invalidArgs -eq 1 ]; then echo Usage: ut_run.sh "project_path" "sql_param_name" "output_file" "scan_path" exit 1 fi # Remove trailing slashes. projectPath=${1%/} sqlParamName=$2 outputFile=$3 scanPath=$4 fullScanPath="$projectPath/$scanPath" if [ ! -d "$fullScanPath" ] || [ -z "$4" ]; then echo "begin" > $outputFile echo " open :$sqlParamName for select null from dual where 1= 0;" >> $outputFile echo "end;" >> $outputFile echo "/" >> $outputFile exit 0 fi echo "declare" > $outputFile echo " l_list ut_varchar2_list := ut_varchar2_list();" >> $outputFile echo "begin" >> $outputFile for f in $(find $fullScanPath/* -type f | sed "s|$projectPath/||"); do echo " l_list.extend; l_list(l_list.last) := '$f';" >> $outputFile done echo " open :$sqlParamName for select * from table(l_list);" >> $outputFile echo "end;" >> $outputFile echo "/" >> $outputFile