You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
2.6 KiB
107 lines
2.6 KiB
#!/bin/bash |
|
|
|
#----------------------------- |
|
# Shell-Kommando "DOQUERY" |
|
#----------------------------- |
|
|
|
#------------------------------------------------------------------- |
|
# Shellvariablen setzen und eingegebene SQL-Anweisung (als Parameter) |
|
# in der SuperX-Datenbank ausfuehren. |
|
#------------------------------------------------------------------- |
|
|
|
|
|
#. $SUPERX_DIR/db/bin/SQL_ENV |
|
if [ "$1" = "" ] |
|
then echo "Aufruf: DOQUERY <sql-Anweisung> <header (true|false)>(optional) <Delimiter>(optional) <Ausgabedatei>(optional) <format (txt|xml)>(optional)" |
|
echo " " |
|
echo "Aktion: DOQUERY führt die <sql-Anweisung> aus." |
|
echo "Das Ergebnis kann mit Feldnamen (<header=true>) oder speziellem Format in eine Datei <Ausgabedatei> ausgegeben werden" |
|
echo " " |
|
exit 0 |
|
fi |
|
|
|
sql=$1 |
|
header=$2 |
|
delim=$3 |
|
|
|
if [ "$delim" != "" ] |
|
then DBDELIMITER="$delim" |
|
fi |
|
filename=$4 |
|
|
|
outformat=$5 |
|
|
|
if [ "$outformat" = "xml" ] |
|
then SX_CLIENT="jdbc" |
|
else |
|
outformat="txt" |
|
fi |
|
|
|
if [ "$LANG" != "" ] |
|
then LOCALE="-Duser.language=$LANG" |
|
fi |
|
if $CYGWIN; then |
|
if [ "$filename" != "" ] |
|
then |
|
filename=`cygpath --path --windows "$filename"` |
|
fi |
|
CP=".;$JDBC_CLASSPATH;$XML_CLASSPATH" |
|
IFX=`cygpath --path --windows "$SUPERX_DIR/db/conf/unldescr_informix_load.xml"` |
|
PG=`cygpath --path --windows "$SUPERX_DIR/db/conf/unldescr_postgres_copy.xml"` |
|
|
|
else |
|
|
|
#outpfad="$filename" |
|
CP=".:$JDBC_CLASSPATH:$XML_CLASSPATH" |
|
IFX="$SUPERX_DIR/db/conf/unldescr_informix_load.xml" |
|
PG="$SUPERX_DIR/db/conf/unldescr_postgres_copy.xml" |
|
|
|
fi |
|
|
|
case $SX_CLIENT in |
|
|
|
jdbc) |
|
java $LOCALE -cp "$CP" $JAVA_OPTS de.superx.bin.Doquery $LOGGER_PROPERTIES $DB_PROPERTIES "$sql" "$outformat" "$DBDELIMITER" $header $filename |
|
|
|
;; |
|
psql) |
|
if [ "$header" != "true" ] |
|
then |
|
tuples_only='-t' |
|
fi |
|
|
|
if [ "$filename" = "" ] |
|
then |
|
#echo "$sql" |
|
psql --dbname $DBNAME -c "$sql" $tuples_only -P fieldsep="$DBDELIMITER" -P pager=off |
|
|
|
else |
|
#Wir benutzen postgres copy nicht mehr, weil die Dateien vom User Postgres erzeugt werden. |
|
#Wenn das trotzdem gewünscht ist, muss dr folgende Passus ent-kommentiert werden |
|
#psql --dbname $DBNAME -P fieldsep="$DBDELIMITER" -c "$sql" $tuples_only -o $filename |
|
java $LOCALE -cp "$CP" $JAVA_OPTS de.superx.bin.Doquery $LOGGER_PROPERTIES $DB_PROPERTIES "$sql" "txt" "$DBDELIMITER" $header $filename |
|
|
|
|
|
fi |
|
|
|
;; |
|
dbaccess) |
|
|
|
tmpfilename="tmp"$MANDANTID.sql |
|
|
|
echo "$sql" >$tmpfilename |
|
|
|
if [ "$filename" = "" ] |
|
then |
|
echo "$INFORMIXDIR/bin/dbaccess $DBNAME" |
|
$INFORMIXDIR/bin/dbaccess $DBACCESS_PARAMS $DBNAME $tmpfilename |
|
else |
|
echo "$INFORMIXDIR/bin/dbaccess $DBNAME" |
|
$INFORMIXDIR/bin/dbaccess $DBACCESS_PARAMS $DBNAME $tmpfilename >$filename 2>&1 |
|
|
|
|
|
fi |
|
rm $tmpfilename |
|
;; |
|
esac |
|
|
|
|