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.
142 lines
3.7 KiB
142 lines
3.7 KiB
#!/bin/bash |
|
|
|
#----------------------------- |
|
# Shell-Kommando "DOSQL" |
|
#----------------------------- |
|
|
|
#------------------------------------------------------------------- |
|
# Shellvariablen setzen und SQL-Anweisung(en) aus Datei |
|
# in der SuperX-Datenbank ausfuehren. |
|
#------------------------------------------------------------------- |
|
#13.12.07 DQ Freemarker-Parsing auch mandantenfähig |
|
#9.12.06 MB Erweiterung für Freemarker-Parsing |
|
if [ "$1" = "" ] |
|
then echo "Aufruf: DOSQL <Dateiname> <header (true|false)>(optional) <Ausgabedatei> (optional)" |
|
echo " " |
|
echo "Aktion: DOSQL führt die Kommandos in der Datei <Dateiname> aus." |
|
echo "Das Ergebnis kann mit Feldnamen (<header=true>) in eine Datei <Ausgabedatei> ausgegeben werden" |
|
echo " " |
|
exit 0 |
|
fi |
|
#. $SUPERX_DIR/db/bin/SQL_ENV |
|
filename="$1" |
|
header=$2 |
|
outfile=$3 |
|
|
|
fgrep -i -s "freemarker template" $filename > /dev/null |
|
FLAG1=$? |
|
fgrep -i -s "FREEMARKER TEMPLATE" $filename > /dev/null |
|
FLAG2=$? |
|
|
|
orgfilename="$filename" |
|
tmpfilename="$filename"$MANDANTID.tmp$MANDANTENID.sql |
|
if [ $FLAG1 -eq 0 -o $FLAG2 -eq 0 ] |
|
then |
|
rm -f $tmpfilename |
|
|
|
case $JDBC_CLASSPATH in |
|
*freemarker*) |
|
;; |
|
*) |
|
if $CYGWIN; then |
|
MY_PATH=`cygpath --path --windows "$SUPERX_DIR/webserver/tomcat/webapps/superx/WEB-INF/lib/freemarker.jar"` |
|
JDBC_CLASSPATH="$JDBC_CLASSPATH;$MY_PATH" |
|
echo "$JDBC_CLASSPATH" |
|
else |
|
JDBC_CLASSPATH=$JDBC_CLASSPATH:$SUPERX_DIR/webserver/tomcat/webapps/superx/WEB-INF/lib/freemarker.jar |
|
fi |
|
;; |
|
esac |
|
if $CYGWIN; then |
|
tmpfilename=`cygpath --path --windows "$tmpfilename"` |
|
fi |
|
|
|
#Anlegen einer temp. Kopie filename.tmp$MANDANTENID.sql |
|
java -cp $JDBC_CLASSPATH $JAVA_OPTS de.superx.bin.FMParser -dbproperties:$DB_PROPERTIES -in:$filename -out:$tmpfilename |
|
if [ ! -f $tmpfilename ] |
|
then |
|
echo "Error : DOSQL abgebrochen" |
|
exit 1 |
|
fi |
|
|
|
filename="$tmpfilename" |
|
fi |
|
|
|
fgrep -i -s "<xupdate>" $filename > /dev/null |
|
FLAG1=$? |
|
if [ $FLAG1 -eq 0 ] |
|
then |
|
if $CYGWIN; then |
|
filename=`cygpath --path --windows "$filename"` |
|
outfile=`cygpath --path --windows "$outfile"` |
|
CP=".;$JDBC_CLASSPATH;$XML_CLASSPATH" |
|
else |
|
CP=".:$JDBC_CLASSPATH:$XML_CLASSPATH" |
|
fi |
|
if [ "$LANG" != "" ] |
|
then LOCALE="-Duser.language=$LANG" |
|
fi |
|
java $LOCALE -cp $CP $JAVA_OPTS de.superx.bin.Dosql -logger:$LOGGER_PROPERTIES -dbproperties:$DB_PROPERTIES -sqlfile:"$filename" -outFormat:"txt" -delim:$DBDELIMITER -header:$header -outfile:$outfile |
|
|
|
else |
|
case $SX_CLIENT in |
|
|
|
jdbc) |
|
if $CYGWIN; then |
|
filename=`cygpath --path --windows "$filename"` |
|
outfile=`cygpath --path --windows "$outfile"` |
|
CP=".;$JDBC_CLASSPATH;$XML_CLASSPATH" |
|
else |
|
CP=".:$JDBC_CLASSPATH:$XML_CLASSPATH" |
|
fi |
|
if [ "$LANG" != "" ] |
|
then LOCALE="-Duser.language=$LANG" |
|
fi |
|
java $LOCALE -cp $CP $JAVA_OPTS de.superx.bin.Dosql -logger:$LOGGER_PROPERTIES -dbproperties:$DB_PROPERTIES -sqlfile:"$filename" -outFormat:"txt" -delim:$DBDELIMITER -header:$header -outfile:$outfile |
|
|
|
;; |
|
psql) |
|
if [ "$header" != "true" ] |
|
then |
|
tuples_only='-t' |
|
fi |
|
|
|
if [ "$outfile" = "" ] |
|
then |
|
psql --dbname $DBNAME -f $filename $tuples_only |
|
|
|
else |
|
echo "Ergebnis mit Fieldsep $DBDELIMITER klappt mit psql noch nicht" |
|
echo "Bitte benutzen Sie SX_CLIENT=jdbc" |
|
psql --dbname $DBNAME -P fieldsep="$DBDELIMITER" -f $filename $tuples_only -o $outfile |
|
|
|
fi |
|
|
|
;; |
|
dbaccess) |
|
if [ "$header" = "true" ] |
|
then |
|
echo "Mit dbaccess ist kein Export der Feldnamen möglich" |
|
exit 0 |
|
fi |
|
|
|
if [ "$outfile" = "" ] |
|
then |
|
$INF_BIN/dbaccess $DBACCESS_PARAMS $DBNAME $filename |
|
else |
|
$INF_BIN/dbaccess $DBACCESS_PARAMS $DBNAME $filename >$outfile |
|
fi |
|
|
|
;; |
|
hsql) |
|
java -Xmx300M -cp .:$JDBC_CLASSPATH org.hsqldb.util.ScriptTool -database joolap -user admin -password ???? -script $filename |
|
esac |
|
fi |
|
|
|
if [ -f $tmpfilename -a "$FM_DEBUG" == "" ] |
|
then |
|
echo |
|
#Zum Debuggen auskommentieren: |
|
rm -f "$tmpfilename" |
|
fi |
|
|
|
|